ferrybig

KiCad dark mode generator

Aug 13th, 2026
16,117
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.  
  4. for (const k in data.schematic) {
  5.     const item = data.schematic[k];
  6.     let match_start = 0;
  7.  
  8.     if (typeof item !== 'string') {
  9.         continue;
  10.     } else if (item.startsWith('rgb(')) {
  11.         match_start = 4;
  12.     } else if (item.startsWith('rgba(')) {
  13.         match_start = 5;
  14.     } else {
  15.         continue;
  16.     }
  17.  
  18.     const parsed = item.substring(match_start, item.length - 1)
  19.         .replace(/ /g, '')
  20.         .split(',')
  21.         .map(v => parseFloat(v));
  22.  
  23.     // 1. Create an sRGB object from the parsed array
  24.     const srgbColor = {
  25.         mode: 'rgb',
  26.         r: parsed[0] / 255,
  27.         g: parsed[1] / 255,
  28.         b: parsed[2] / 255,
  29.         alpha: parsed[3] !== undefined ? parsed[3] : 1
  30.     };
  31.  
  32.     // 2. Convert to Oklch space
  33.     const oklchColor = culori.oklch(srgbColor);
  34.  
  35.     // 3. Invert only the Lightness (L) component (range 0.0 - 1.0)
  36.     oklchColor.l = 1.0 - oklchColor.l;
  37.  
  38.         // make everything darker
  39.         oklchColor.l = Math.max(oklchColor.l * 1.2 - 0.2, 0);
  40.  
  41.         // Shift hue
  42.         // oklchColor.h += 180;
  43.  
  44.     // 4. Convert back to sRGB
  45.     const invertedSrgb = culori.rgb(oklchColor);
  46.  
  47.     // 5. Re-scale to 0-255 bounds and format values
  48.     const r = Math.round(invertedSrgb.r * 255);
  49.     const g = Math.round(invertedSrgb.g * 255);
  50.     const b = Math.round(invertedSrgb.b * 255);
  51.    
  52.     let stringified;
  53.     if (parsed.length === 4) {
  54.         stringified = `rgba(${r},${g},${b},${parsed[3]})`;
  55.     } else {
  56.         stringified = `rgb(${r},${g},${b})`;
  57.     }
  58.  
  59.     data.schematic[k] = stringified;
  60. }
  61.  
  62. console.log(JSON.stringify(data, null, '\t'));
  63.  
Advertisement