Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
const culori = require("culori"); let data = require("./user.json"); for (const k in data.schematic) { const item = data.schematic[k]; let match_start = 0; if (typeof item !== 'string') { continue; } else if (item.startsWith('rgb(')) { match_start = 4; } else if (item.startsWith('rgba(')) { match_start = 5; } else { continue; } const parsed = item.substring(match_start, item.length - 1) .replace(/ /g, '') .split(',') .map(v => parseFloat(v)); // 1. Create an sRGB object from the parsed array const srgbColor = { mode: 'rgb', r: parsed[0] / 255, g: parsed[1] / 255, b: parsed[2] / 255, alpha: parsed[3] !== undefined ? parsed[3] : 1 }; // 2. Convert to Oklch space const oklchColor = culori.oklch(srgbColor); // 3. Invert only the Lightness (L) component (range 0.0 - 1.0) oklchColor.l = 1.0 - oklchColor.l; // make everything darker oklchColor.l = Math.max(oklchColor.l * 1.2 - 0.2, 0); // Shift hue // oklchColor.h += 180; // 4. Convert back to sRGB const invertedSrgb = culori.rgb(oklchColor); // 5. Re-scale to 0-255 bounds and format values const r = Math.round(invertedSrgb.r * 255); const g = Math.round(invertedSrgb.g * 255); const b = Math.round(invertedSrgb.b * 255); let stringified; if (parsed.length === 4) { stringified = `rgba(${r},${g},${b},${parsed[3]})`; } else { stringified = `rgb(${r},${g},${b})`; } data.schematic[k] = stringified; } console.log(JSON.stringify(data, null, '\t'));
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)