@kabmo-labs/kabmo 0.21.0 → 0.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kabmo-labs/kabmo",
3
- "version": "0.21.0",
3
+ "version": "0.21.1",
4
4
  "description": "Web console and diagnostic workbench for AI coding agents — Elysia + Preact on Bun.",
5
5
  "license": "MIT",
6
6
  "author": "Wijanarko Putra Rajeb <wijanarko.rajeb@gmail.com>",
@@ -83,31 +83,43 @@ describe('the icon paint stylesheet', () => {
83
83
  expect(css).toContain('[data-tool-row] [data-plugin-mark] { --plugin-color: var(--theme-ink); }');
84
84
  });
85
85
 
86
- test('a muted ink icon takes its hue, muted toward the ink rather than faded out', () => {
86
+ test('a muted ink icon keeps its hue and only loses CHROMA', () => {
87
87
  // `text-ink/60` is a WEIGHT. It is (0,1,0) and the hue rules are (0,0,0), so
88
88
  // the mute won and every muted icon stayed ink in the colour mode — the
89
89
  // reported "icon di setting modal kenapa gk full color".
90
- expect(css).toContain('[data-icon-style="color"] svg.lucide:not(.project-accent-mark)[class*="text-ink/60"] { color: color-mix(in srgb,');
91
- expect(css).toContain('[data-icon-style="color"] svg.lucide:not(.project-accent-mark)[class~="text-ink"] { color: var(--icon-tone, hsl(var(--icon-hue');
92
- // Mixed toward the INK, never toward transparency: a hue at 40% alpha is
93
- // 1.56:1 against its surface, worse than the `text-ink/40` it replaces.
90
+ //
91
+ // The weight multiplies CHROMA and leaves LIGHTNESS alone. Mixing toward the
92
+ // ink also darkens, which is the opposite of a mute: measured, a muted
93
+ // settings icon read 7.48:1 where the active one read 3.96:1 and the
94
+ // monochrome ink it replaced read 4.74:1 — darker than both, which is the
95
+ // "masih kusam di light mode" report.
96
+ // `[class~=…]`, never `[class*=…]`: a substring match also fires on the
97
+ // VARIANT token — `text-ink/50 group-hover:text-ink/80` matched both, so the
98
+ // resting icon was painted at its hover weight (measured on the composer's
99
+ // target picker, `Folder` computed the `/80` paint while not hovered).
100
+ expect(css).toContain('[data-icon-style="color"] svg.lucide:not(.project-accent-mark)[class~="text-ink/60"] { --icon-paint: oklch(from var(--icon-color) l calc(c * 0.6) h); }');
101
+ expect(css).toContain('[data-icon-style="color"] svg.lucide:not(.project-accent-mark)[class~="text-ink"] { --icon-paint: var(--icon-color); }');
102
+ expect(css).not.toContain('[class*="text-ink/');
103
+ // Never toward transparency: a hue at 40% alpha is 1.56:1 against its
104
+ // surface, worse than the `text-ink/40` it replaces.
94
105
  const muted = css.split('\n').find((line) => line.includes('text-ink/40"')) ?? '';
95
- expect(muted).toContain('var(--theme-ink)');
106
+ expect(muted).toContain('oklch(from');
96
107
  expect(muted).not.toContain('transparent');
108
+ expect(muted).not.toContain('var(--theme-ink)');
97
109
  });
98
110
 
99
111
  test('the project accent survives the dark ink weights', () => {
100
112
  // Each folder mark carries the user's OWN colour as `--project-accent`, and
101
113
  // the call sites also write `text-ink/70`. The dark weight selector is
102
- // `[data-icon-style="color"][data-theme-variant="dark"] svg.lucide[class*="text-ink/70"]`
114
+ // `[data-icon-style="color"][data-theme-variant="dark"] svg.lucide[class~="text-ink/70"]`
103
115
  // = (0,4,1) — one ELEMENT above
104
116
  // `:root[data-icon-style="color"] .project-accent-mark` = (0,4,0) — so on a
105
117
  // dark theme every folder icon came out the same hue and light looked fine.
106
118
  // "A weight does not apply to the user's own colour" is the fix; out-specifying
107
119
  // it would be a tie waiting for the next attribute.
108
- expect(css).toContain('[data-icon-style="color"] svg.lucide:not(.project-accent-mark)[class*="text-ink/70"]');
120
+ expect(css).toContain('[data-icon-style="color"] svg.lucide:not(.project-accent-mark)[class~="text-ink/70"]');
109
121
  expect(css).toContain(
110
- '[data-icon-style="color"][data-theme-variant="dark"] svg.lucide:not(.project-accent-mark)[class*="text-ink/70"]',
122
+ '[data-icon-style="color"][data-theme-variant="dark"] svg.lucide:not(.project-accent-mark)[class~="text-ink/70"]',
111
123
  );
112
124
  expect(css).toContain(':root[data-icon-style="color"] .project-accent-mark { color: var(--project-accent); }');
113
125
  // Every weight rule, not just the one probed by hand: a single step that
@@ -132,9 +144,13 @@ describe('the icon paint stylesheet', () => {
132
144
  }
133
145
  });
134
146
 
135
- test('the base hue rule paints a custom-property hsl(), per variant', () => {
136
- expect(css).toContain(':where(svg.lucide) { color: hsl(var(--icon-hue,');
137
- expect(css).toContain(':where([data-icon-style="color"][data-theme-variant="dark"]) :where(svg.lucide) { color: hsl(var(--icon-hue,');
147
+ test('the base hue rule states --icon-color, per variant, and one rule paints it', () => {
148
+ expect(css).toContain(':where(svg.lucide) { --icon-color: var(--icon-tone, hsl(var(--icon-hue,');
149
+ expect(css).toContain(':where([data-icon-style="color"][data-theme-variant="dark"]) :where(svg.lucide) { --icon-color: hsl(var(--icon-hue,');
150
+ // ONE `color:` statement, derived from the two custom properties. Stating it
151
+ // per source instead made the weight rules fight them on specificity, and a
152
+ // signal token could be overwritten by winning that race.
153
+ expect(css).toContain('[data-icon-style="color"] :is(svg.lucide, svg[data-provider], svg[data-file-brand]) { --icon-paint: var(--icon-color); color: var(--icon-paint); }');
138
154
  });
139
155
 
140
156
  test('one hue statement per generated row', () => {
@@ -146,7 +162,7 @@ describe('the icon paint stylesheet', () => {
146
162
  test('every signal row paints its palette token, after the hue rows', () => {
147
163
  const hueIndex = css.indexOf('--icon-hue');
148
164
  for (const { className, role } of ICON_TINT_ROWS) {
149
- const needle = `:where(svg.${className}) { color: ${ICON_TINT_TOKENS[role]}; }`;
165
+ const needle = `:where(svg.${className}) { --icon-color: ${ICON_TINT_TOKENS[role]}; }`;
150
166
  expect(css).toContain(needle);
151
167
  expect(css.indexOf(needle), `${className} must follow the hue rules`).toBeGreaterThan(hueIndex);
152
168
  }
@@ -155,16 +171,16 @@ describe('the icon paint stylesheet', () => {
155
171
  test('every provider row paints both variants', () => {
156
172
  for (const [name, entry] of Object.entries(BRAND_COLORS)) {
157
173
  const selector = `svg[data-provider="${name}"]`;
158
- expect(css).toContain(`:where(${selector}) { color: ${entry.light}; }`);
159
- expect(css).toContain(`color: ${entry.dark ?? 'var(--theme-ink)'}; }`);
174
+ expect(css).toContain(`:where(${selector}) { --icon-color: ${entry.light}; }`);
175
+ expect(css).toContain(`--icon-color: ${entry.dark ?? 'var(--theme-ink)'}; }`);
160
176
  }
161
177
  });
162
178
 
163
179
  test('every file-brand row paints both variants', () => {
164
180
  for (const [name, entry] of Object.entries(FILE_BRAND_COLORS)) {
165
181
  const selector = `svg[data-file-brand="${name}"]`;
166
- expect(css).toContain(`:where(${selector}) { color: ${entry.light}; }`);
167
- expect(css).toContain(`color: ${entry.dark ?? 'var(--theme-ink)'}; }`);
182
+ expect(css).toContain(`:where(${selector}) { --icon-color: ${entry.light}; }`);
183
+ expect(css).toContain(`--icon-color: ${entry.dark ?? 'var(--theme-ink)'}; }`);
168
184
  }
169
185
  });
170
186
 
@@ -213,10 +229,15 @@ describe('the icon paint stylesheet', () => {
213
229
  // mid-tone ink (`#586e75`, `#93a1a1`), where no hue at any lightness clears
214
230
  // 3:1. The surface already declares `text-canvas`/`text-paper`, and the
215
231
  // palette guarantees that pair, so the icon inherits it.
216
- expect(css).toContain(':where([data-icon-style="color"]) :where(.bg-ink) :where(svg.lucide) { color: currentColor; }');
232
+ // (0,2,1) with an explicit `color`, not `:where()`: it has to TIE with the
233
+ // paint rule and win on order, and it cannot feed `currentColor` back into
234
+ // `--icon-color` — that is a cycle on the property computing `color`.
235
+ expect(css).toContain('[data-icon-style="color"] .bg-ink svg.lucide { color: currentColor; }');
217
236
  expect(css).toContain(':where([data-icon-style="color"]) :where(.bg-ink) :where([data-plugin-mark]) { --plugin-color: currentColor; }');
218
237
  // Same zero specificity as the base rules, so it has to come AFTER them.
219
- expect(css.indexOf(':where(.bg-ink) :where(svg.lucide)')).toBeGreaterThan(css.indexOf(':where(svg.lucide) { color: hsl(var(--icon-hue'));
238
+ expect(css.indexOf('.bg-ink svg.lucide { color: currentColor; }')).toBeGreaterThan(
239
+ css.indexOf('[data-icon-style="color"] :is(svg.lucide, svg[data-provider]'),
240
+ );
220
241
  });
221
242
 
222
243
  test('a plugin manifest colour wins over the hashed hue', () => {
@@ -233,3 +254,60 @@ describe('the icon paint stylesheet', () => {
233
254
  expect(iconPaintStyleSheet()).toBe(css);
234
255
  });
235
256
  });
257
+
258
+ describe('the ink weight selectors', () => {
259
+ // Only the rules that read a WEIGHT: the paint rule also sets `--icon-paint`
260
+ // (from `--icon-color`, unconditionally), and it is not a weight.
261
+ const weightRules = css.split('\n').filter((line) => line.includes('--icon-paint:') && line.includes('text-ink'));
262
+
263
+ test('a weight matches one class TOKEN, never a substring', () => {
264
+ // `[class*=…]` also fires on the VARIANT token: `text-ink/50
265
+ // group-hover:text-ink/80` matched both `/50` and `/80`, so the resting icon
266
+ // was painted at its HOVER weight — measured on the composer's target
267
+ // picker, `Folder` computed the `/80` paint while the pointer was elsewhere.
268
+ expect(weightRules.length).toBeGreaterThan(0);
269
+ for (const rule of weightRules) {
270
+ expect(rule, rule.slice(0, 90)).toContain('[class~="');
271
+ expect(rule, rule.slice(0, 90)).not.toContain('[class*="text-ink');
272
+ }
273
+ });
274
+
275
+ test('a hover weight is stated as a pseudo-class, in the right DOM order', () => {
276
+ // Two independent failures live here. ORDER: `.group` is an ancestor while
277
+ // `[data-icon-style]` sits on `<html>`, so `.group:hover` has to come AFTER
278
+ // the mode gate — written before it, the selector demands a descendant that
279
+ // carries the attribute and never matches (measured: `group-hover` had no
280
+ // effect at all). SPECIFICITY: the variant must outrank the resting rule, so
281
+ // an icon that is muted at rest and bright on hover really does brighten.
282
+ const groupRule = weightRules.find((line) => line.includes('[class~="group-hover:text-ink/80"]')) ?? '';
283
+ expect(groupRule).toMatch(/^\[data-icon-style="color"\] \.group:hover svg\.lucide/);
284
+
285
+ const hoverRule = weightRules.find((line) => line.includes('[class~="hover:text-ink/70"]')) ?? '';
286
+ expect(hoverRule).toMatch(/^\[data-icon-style="color"\] svg\.lucide.*\]:hover \{/);
287
+
288
+ // The resting rule for the same class must exist too, or the selector is a
289
+ // hover-only paint and the icon changes colour the moment the pointer moves.
290
+ expect(weightRules.some((line) => line.includes('[class~="text-ink/50"]') && !line.includes('hover'))).toBe(true);
291
+ });
292
+
293
+ test('the weight scales chroma, and never mixes toward the ink', () => {
294
+ // Mixing toward `var(--theme-ink)` desaturates AND darkens, and darkening is
295
+ // the opposite of a mute: a muted settings icon measured 7.48:1 where the
296
+ // active one read 3.96:1. Multiplying chroma leaves the solved lightness —
297
+ // and therefore the legibility — alone.
298
+ const stepped = weightRules.filter((line) => /text-ink\/\d+"\]/.test(line));
299
+ expect(stepped.length).toBeGreaterThan(0);
300
+ for (const rule of stepped) {
301
+ expect(rule, rule.slice(0, 90)).toContain('oklch(from var(--icon-color) l calc(c *');
302
+ expect(rule, rule.slice(0, 90)).not.toContain('var(--theme-ink)');
303
+ expect(rule, rule.slice(0, 90)).not.toContain('color-mix(');
304
+ }
305
+ });
306
+
307
+ test('every weight is gated on the colour mode and skips the project accent', () => {
308
+ for (const rule of weightRules) {
309
+ expect(rule.startsWith('[data-icon-style="color"]'), rule.slice(0, 80)).toBe(true);
310
+ expect(rule, rule.slice(0, 80)).toContain(':not(.project-accent-mark)');
311
+ }
312
+ });
313
+ });
@@ -47,6 +47,7 @@
47
47
 
48
48
  import { BRAND_COLORS } from '@/shared/lib/models/provider/brand-color';
49
49
  import { panelMarkRules } from '@/shared/lib/icons/icon-paint-panel';
50
+ import { inkWeightRules } from '@/shared/lib/icons/icon-paint-weight';
50
51
  import { FILE_BRAND_COLORS } from '@/shared/lib/icons/file-brand-color';
51
52
  import {
52
53
  DEFAULT_ICON_HUE,
@@ -63,16 +64,21 @@ export const ICON_PAINT_STYLE_ELEMENT_ID = 'omp-icon-paint';
63
64
  /** Both rules for one brand, since a brand colour has two values. */
64
65
  function brandRules(selector: string, light: string, dark: string | null): string[] {
65
66
  return [
66
- `:where([data-icon-style="color"]) :where(${selector}) { color: ${light}; }`,
67
- `:where([data-icon-style="color"][data-theme-variant="dark"]) :where(${selector}) { color: ${dark ?? 'var(--theme-ink)'}; }`,
67
+ `:where([data-icon-style="color"]) :where(${selector}) { --icon-color: ${light}; }`,
68
+ `:where([data-icon-style="color"][data-theme-variant="dark"]) :where(${selector}) { --icon-color: ${dark ?? 'var(--theme-ink)'}; }`,
68
69
  ];
69
70
  }
70
71
 
71
72
  /** The hue a functional glyph is painted with, per variant. */
72
73
  function hueRules(): string[] {
73
74
  const rules = [
74
- `:where([data-icon-style="color"]) :where(svg.lucide) { color: ${iconHuePaint('light')}; }`,
75
- `:where([data-icon-style="color"][data-theme-variant="dark"]) :where(svg.lucide) { color: ${iconHuePaint('dark')}; }`,
75
+ // `--icon-paint`, not `color`: WHICH colour an icon is and HOW LOUD it is are
76
+ // two decisions, and stating them as one `color` makes them compete on
77
+ // specificity. The weight rules below multiply the chroma of whatever this
78
+ // resolves to, so they cannot overwrite a signal token by winning a cascade
79
+ // race (which is exactly what they did — see `inkWeightRules`).
80
+ `:where([data-icon-style="color"]) :where(svg.lucide) { --icon-color: ${iconHuePaint('light')}; }`,
81
+ `:where([data-icon-style="color"][data-theme-variant="dark"]) :where(svg.lucide) { --icon-color: ${iconHuePaint('dark')}; }`,
76
82
  ];
77
83
  for (const { className, hue } of ICON_HUE_ROWS) {
78
84
  rules.push(`:where([data-icon-style="color"]) :where(svg.${className}) { --icon-hue: ${hue}; --icon-tone: ${iconTone(hue)}; }`);
@@ -80,6 +86,42 @@ function hueRules(): string[] {
80
86
  return rules;
81
87
  }
82
88
 
89
+ /**
90
+ * The paint itself. Stated ONCE, after the sources above, so every rule that
91
+ * decides a colour only has to set `--icon-color`.
92
+ *
93
+ * `color` rather than a second fallback inside each source: it is the one
94
+ * property a caller can also set (`text-ink/60`), and this block is gated, so an
95
+ * icon outside the colour mode keeps the author's class.
96
+ *
97
+ * **The selector covers all three icon families, not just `.lucide`.** Provider
98
+ * and file-type marks are their own `<svg>` and carry no `lucide` class, so a
99
+ * `.lucide`-only paint rule left them inheriting their parent's text colour —
100
+ * measured, a brand mark computed `oklab(0.523 -0.022 -0.018 / 0.8)` (its row's
101
+ * muted ink) while its `--icon-color` held the brand hex. `:is()` costs nothing:
102
+ * each argument is (0,1,1), so the whole selector stays (0,2,1) and still beats
103
+ * a single utility.
104
+ */
105
+ function paintRules(): string[] {
106
+ return [
107
+ // `--icon-paint` is derived from `--icon-color`, which every source above
108
+ // sets. The indirection is what lets a WEIGHT rule (see `inkWeightRules`)
109
+ // transform the colour without knowing which source produced it — a signal
110
+ // token, a solved tone, a brand hex or a panel's own colour all flow through
111
+ // the same two lines.
112
+ //
113
+ // NOT `:where()` on this one, unlike every other rule in the sheet. The
114
+ // subject is the `color` property, which the call sites also set — a utility
115
+ // like `text-ink/60` is (0,1,0) — so a zero-specificity statement lost the
116
+ // mode entirely and every muted icon stayed monochrome ink (measured in the
117
+ // settings modal: `--icon-paint` computed to the tone, and `color` still
118
+ // resolved to `oklab(… / 0.6)`). (0,2,1) beats a single utility, and the
119
+ // rules that must still override it — a panel mark, a tool card, an inverted
120
+ // surface, the project accent — are stated after this one with more weight.
121
+ `[data-icon-style="color"] :is(svg.lucide, svg[data-provider], svg[data-file-brand]) { --icon-paint: var(--icon-color); color: var(--icon-paint); }`,
122
+ ];
123
+ }
124
+
83
125
  /**
84
126
  * MONOCHROME: an icon takes the ink of the text beside it.
85
127
  *
@@ -183,7 +225,12 @@ function projectAccentRules(): string[] {
183
225
  */
184
226
  function invertedSurfaceRules(): string[] {
185
227
  return [
186
- ':where([data-icon-style="color"]) :where(.bg-ink) :where(svg.lucide) { color: currentColor; }',
228
+ // Stated at (0,2,1) to TIE with `paintRules` and win on order — `:where()`
229
+ // would be (0,0,0) and lose to it, which is the whole reason this rule
230
+ // exists. It sets `color` directly rather than `--icon-color`, because
231
+ // `currentColor` resolves FROM `color`: feeding it back into the property
232
+ // that computes `color` is a cycle the browser drops.
233
+ '[data-icon-style="color"] .bg-ink svg.lucide { color: currentColor; }',
187
234
  ':where([data-icon-style="color"]) :where(.bg-ink) :where([data-plugin-mark]) { --plugin-color: currentColor; }',
188
235
  ];
189
236
  }
@@ -203,52 +250,11 @@ function pluginMarkRules(): string[] {
203
250
  ];
204
251
  }
205
252
 
206
- /**
207
- * `text-ink/60` is a WEIGHT, not a colour choice.
208
- *
209
- * The settings sidebar, the composer toolbar and a few hundred other call sites
210
- * write `text-ink/40`-`/80` to mute an icon. That is "the ink, quieter" — the
211
- * caller did not pick a colour — but a utility class is (0,1,0) and the hue
212
- * rules are `:where()` (0,0,0), so the mute won and every muted icon stayed ink
213
- * in the colour mode ("icon di setting modal kenapa gk full color").
214
- *
215
- * The mute is reproduced by mixing toward the INK, not toward transparency. Two
216
- * reasons, both measured. Transparency is the wrong lever for a graphic: a hue at
217
- * 40% alpha is 1.56:1 (light) / 1.77:1 (dark) against its surface, while the
218
- * `text-ink/40` it replaces was already only 1.71 / 2.05 — so the colour mode
219
- * would have made every muted icon less legible than before. Mixing toward the
220
- * ink instead keeps the same "mostly ink, quieter" reading AND lands at 3.89:1
221
- * worst case across every palette (`hue 80% + ink 20%`), 4.65:1 at the muted end.
222
- *
223
- * Specificity `svg.lucide[class*=…]` (0,2,1) beats the utility (0,1,0) on its
224
- * own; the `!` is not needed and is not used anywhere in this sheet.
225
- */
226
- function inkWeightRules(): string[] {
227
- const steps = [25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90];
228
- const rules: string[] = [];
229
- for (const variant of ['light', 'dark'] as const) {
230
- const gate = variant === 'dark'
231
- ? '[data-icon-style="color"][data-theme-variant="dark"]'
232
- : '[data-icon-style="color"]';
233
- const paint = iconHuePaint(variant);
234
- // The un-suffixed `text-ink` is the full-strength ink.
235
- rules.push(`${gate} svg.lucide:not(.project-accent-mark)[class~="text-ink"] { color: ${paint}; }`);
236
- for (const step of steps) {
237
- // `NN%` of hue over the ink: the caller's mute survives as "mostly ink",
238
- // and the hue is what the mode added.
239
- rules.push(
240
- `${gate} svg.lucide:not(.project-accent-mark)[class*="text-ink/${step}"] { color: color-mix(in srgb, ${paint} ${step}%, var(--theme-ink)); }`,
241
- );
242
- }
243
- }
244
- return rules;
245
- }
246
-
247
253
  /** The signal colours, which beat the hue because they are stated after it. */
248
254
  function signalRules(): string[] {
249
255
  return ICON_TINT_ROWS.map(
250
256
  ({ className, role }) =>
251
- `:where([data-icon-style="color"]) :where(svg.${className}) { color: ${ICON_TINT_TOKENS[role]}; }`,
257
+ `:where([data-icon-style="color"]) :where(svg.${className}) { --icon-color: ${ICON_TINT_TOKENS[role]}; }`,
252
258
  );
253
259
  }
254
260
 
@@ -263,10 +269,13 @@ export function iconPaintStyleSheet(): string {
263
269
  '@layer theme, base, components, utilities;',
264
270
  '@layer utilities {',
265
271
  ...hueRules(),
266
- ...inkWeightRules(),
267
- ...panelMarkRules(),
268
272
  ...signalRules(),
269
273
  ...pluginMarkRules(),
274
+ // Every `--icon-color` source is stated above this line; the paint and the
275
+ // weight that SCALES it are stated below, in that order.
276
+ ...paintRules(),
277
+ ...inkWeightRules(),
278
+ ...panelMarkRules(),
270
279
  // Last: same specificity as everything above, so order is what makes an
271
280
  // inverted surface win over the paper-tuned paint.
272
281
  ...invertedSurfaceRules(),
@@ -0,0 +1,123 @@
1
+ /**
2
+ * @license
3
+ * SPDX-License-Identifier: MIT
4
+ */
5
+
6
+ /**
7
+ * `text-ink/60` is a WEIGHT, not a colour choice — and a weight means LESS
8
+ * COLOUR, not a darker colour.
9
+ *
10
+ * Split out of `icon-paint-css.ts` so both files stay readable, not because the
11
+ * rules are independent: they are the family that sheet concatenates, and they
12
+ * are stated AFTER `paintRules` because they transform what it resolves.
13
+ *
14
+ * The settings sidebar, the composer toolbar and a few hundred other call sites
15
+ * write `text-ink/40`-`/80` to mute an icon. That is "the ink, quieter": the
16
+ * caller chose a weight, not a colour. A utility class is (0,1,0) and the hue
17
+ * rules are `:where()` (0,0,0), so the mute won and every muted icon stayed ink
18
+ * in the colour mode ("icon di setting modal kenapa gk full color").
19
+ *
20
+ * ## The bug this replaces
21
+ *
22
+ * The first answer mixed the hue toward `var(--theme-ink)`. That does two things
23
+ * at once — it desaturates AND darkens — and darkening is the opposite of what a
24
+ * mute means. Measured on the settings sidebar (hue 250, `#736aec` on `paper`'s
25
+ * `#faf8f3`): the pure tone reads **3.96:1**, `text-ink/60` monochrome reads
26
+ * **4.74:1**, and the old rule painted **7.48:1** — a muted icon DARKER than the
27
+ * active one beside it, and darker than the monochrome ink it replaced. That is
28
+ * the "icon di modal setting masih kusam di light mode" report: not a shortage of
29
+ * chroma but a colour pushed to a weight it was never meant to have. Over all 36
30
+ * hues and all 32 light palettes the old rule moved mean contrast 4.37 → 9.46 as
31
+ * the weight got quieter, while monochrome moved 9.17 → 1.60.
32
+ *
33
+ * ## The rule now
34
+ *
35
+ * Multiply the CHROMA by the weight and leave LIGHTNESS alone: `60%` of a hue's
36
+ * chroma is the same hue, quieter, at the legibility the tone was solved for.
37
+ * Measured over the same matrix: contrast holds at **3.87 mean / 3.07 min** from
38
+ * `text-ink/90` down to `/25` (the tone's own 3.91), while chroma falls 0.146 →
39
+ * 0.040 — the icon recedes by losing colour rather than by going dark. Dark
40
+ * behaves the same way (3.83 mean, 3.02 min), because the transform never reads
41
+ * the variant.
42
+ *
43
+ * ## Two facts about the SELECTOR, both measured
44
+ *
45
+ * **1. `[class~=…]`, never `[class*=…]`.** A substring match also fires on the
46
+ * VARIANT token: `text-ink/50 group-hover:text-ink/80` matched both `/50` and
47
+ * `/80`, so the resting icon was painted at its HOVER weight — measured in the
48
+ * composer's target picker, `Folder` computed `oklch(… 0.151 320)` (the `/80`
49
+ * paint) while it was not hovered. `~=` compares one whitespace-separated word,
50
+ * and `group-hover:text-ink/80` is not the word `text-ink/80`, so the base
51
+ * weight is the only one that applies at rest.
52
+ *
53
+ * **2. The variants are stated explicitly.** With the base weights matching
54
+ * exactly, `hover:text-ink/70` and `group-hover:text-ink/80` would otherwise be
55
+ * ignored entirely (the paint rule sets `color` on the `svg` itself, so
56
+ * inheritance from the hovered parent cannot reach it). Each variant is
57
+ * re-stated against its own pseudo-class, which also gives it the higher
58
+ * specificity the tie needs.
59
+ *
60
+ * ## And it no longer eats a signal
61
+ *
62
+ * The rule is stated against `--icon-color`, not against a hue formula, so a
63
+ * signal glyph (`--icon-color: var(--theme-warning)`) keeps its token and is
64
+ * merely quieted — measured, `Bell` under `text-ink/60` used to paint
65
+ * `rgb(26,53,80)`, the warning orange replaced by the hashed hue path. Now it
66
+ * paints warning at 60% chroma (`oklch(0.553 0.104 38.4)`).
67
+ *
68
+ * `oklch(from …)` is relative colour syntax: it reads the source in OKLCH and
69
+ * rewrites one channel, which is the only CSS way to say "same colour, less of
70
+ * it". Supported in every engine this app targets (Chromium 119+, Safari 16.4+,
71
+ * WebKitGTK 2.42+); an engine that lacks it IGNORES the declaration and keeps
72
+ * the full-strength paint, so the failure is an unmuted icon, never a missing
73
+ * one.
74
+ */
75
+
76
+ /** The steps call sites actually use, plus the neighbours a new one may reach for. */
77
+ const WEIGHT_STEPS = [20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90];
78
+
79
+ /** The weight at `step/100`, or the untouched colour. */
80
+ function paintAt(step: number | null): string {
81
+ return step === null ? 'var(--icon-color)' : `oklch(from var(--icon-color) l calc(c * ${step / 100}) h)`;
82
+ }
83
+
84
+ /** Every variant prefix that carries a `text-ink` weight somewhere in this app. */
85
+ const VARIANTS = ['hover', 'group-hover'] as const;
86
+
87
+ /**
88
+ * `selector` and the weight it paints. `prefix` is empty for the resting state.
89
+ *
90
+ * DOM order matters: `.group` is an ANCESTOR of the icon while
91
+ * `[data-icon-style]` sits on `<html>`, so the group has to come AFTER the mode
92
+ * gate. Stated the other way round (`group:hover [data-icon-style="color"] …`)
93
+ * the selector demands a descendant carrying the attribute and never matches —
94
+ * measured, `group-hover:text-ink/80` had no effect at all.
95
+ *
96
+ * The order this returns is the order the rules are emitted in, and it matters:
97
+ * a variant has strictly higher specificity than the base, so a hover weight
98
+ * always wins over the resting one, whatever order the two landed in the sheet.
99
+ */
100
+ function weightRule(variant: (typeof VARIANTS)[number] | null, step: number | null, dark: boolean): string {
101
+ const mode = dark ? '[data-icon-style="color"][data-theme-variant="dark"]' : '[data-icon-style="color"]';
102
+ const token = variant ? `${variant}:text-ink` : 'text-ink';
103
+ const suffix = step === null ? '' : `/${step}`;
104
+ // `.group:hover` for the shared-parent variant, `svg:hover` for the direct one.
105
+ const scope = variant === 'group-hover' ? '.group:hover ' : '';
106
+ const pseudo = variant === 'hover' ? ':hover' : '';
107
+ return `${mode} ${scope}svg.lucide:not(.project-accent-mark)[class~="${token}${suffix}"]${pseudo} { --icon-paint: ${paintAt(step)}; }`;
108
+ }
109
+
110
+ export function inkWeightRules(): string[] {
111
+ const rules: string[] = [];
112
+ for (const dark of [false, true]) {
113
+ // The un-suffixed `text-ink` is the full-strength ink, and its variants are
114
+ // "the caller wants full ink back" — the same paint, no step.
115
+ rules.push(weightRule(null, null, dark));
116
+ for (const variant of VARIANTS) rules.push(weightRule(variant, null, dark));
117
+ for (const step of WEIGHT_STEPS) rules.push(weightRule(null, step, dark));
118
+ for (const step of WEIGHT_STEPS) {
119
+ for (const variant of VARIANTS) rules.push(weightRule(variant, step, dark));
120
+ }
121
+ }
122
+ return rules;
123
+ }