SHARE
    TWEET
    ferrybig

    KiCad dark mode generator

    Aug 13th, 2026
    1,698
    0
    Never
    Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
    1. const culori = require("culori");
    2. let data = require("./user.json");
    3. for (const k in data.schematic) {
    4. const item = data.schematic[k];
    5. let match_start = 0;
    6. if (typeof item !== 'string') {
    7. continue;
    8. } else if (item.startsWith('rgb(')) {
    9. match_start = 4;
    10. } else if (item.startsWith('rgba(')) {
    11. match_start = 5;
    12. } else {
    13. continue;
    14. }
    15. const parsed = item.substring(match_start, item.length - 1)
    16. .replace(/ /g, '')
    17. .split(',')
    18. .map(v => parseFloat(v));
    19. // 1. Create an sRGB object from the parsed array
    20. const srgbColor = {
    21. mode: 'rgb',
    22. r: parsed[0] / 255,
    23. g: parsed[1] / 255,
    24. b: parsed[2] / 255,
    25. alpha: parsed[3] !== undefined ? parsed[3] : 1
    26. };
    27. // 2. Convert to Oklch space
    28. const oklchColor = culori.oklch(srgbColor);
    29. // 3. Invert only the Lightness (L) component (range 0.0 - 1.0)
    30. oklchColor.l = 1.0 - oklchColor.l;
    31. // make everything darker
    32. oklchColor.l = Math.max(oklchColor.l * 1.2 - 0.2, 0);
    33. // Shift hue
    34. // oklchColor.h += 180;
    35. // 4. Convert back to sRGB
    36. const invertedSrgb = culori.rgb(oklchColor);
    37. // 5. Re-scale to 0-255 bounds and format values
    38. const r = Math.round(invertedSrgb.r * 255);
    39. const g = Math.round(invertedSrgb.g * 255);
    40. const b = Math.round(invertedSrgb.b * 255);
    41. let stringified;
    42. if (parsed.length === 4) {
    43. stringified = `rgba(${r},${g},${b},${parsed[3]})`;
    44. } else {
    45. stringified = `rgb(${r},${g},${b})`;
    46. }
    47. data.schematic[k] = stringified;
    48. }
    49. console.log(JSON.stringify(data, null, '\t'));
    Advertisement
    Public Pastes
    We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
    Not a member of Pastebin yet?
    Sign Up, it unlocks many cool features!

    AltStyle によって変換されたページ (->オリジナル) /