@podoba/tokens 0.0.34 → 0.0.35

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": "@podoba/tokens",
3
- "version": "0.0.34",
3
+ "version": "0.0.35",
4
4
  "type": "module",
5
5
  "description": "podoba design tokens — static DTCG tokens.json + generated CSS custom properties. Framework-agnostic.",
6
6
  "repository": {
@@ -19,8 +19,20 @@ function parseBlock(selector: string): Record<string, string> {
19
19
  const m = css.match(new RegExp(`${selector}\\s*\\{([^}]*)\\}`))
20
20
  if (!m) throw new Error(`selector ${selector} not found in variables.css`)
21
21
  const vars: Record<string, string> = {}
22
- for (const [, name, hex] of m[1].matchAll(/--color-([a-z0-9-]+):\s*(#[0-9a-fA-F]{6})\b/g)) {
23
- vars[name] = hex
22
+ // EVERY `--color-*` declaration is captured, whatever its value shape, and an
23
+ // unrecognised one is a hard error. Matching a narrow value pattern instead
24
+ // drops the token from `vars` with no signal — and for a token that appears
25
+ // only as a DARK override, the pair then silently re-tests the inherited LIGHT
26
+ // value and reports a fiction. That is the failure this harness exists to
27
+ // prevent, so it must not be able to happen to the harness itself.
28
+ for (const [, name, raw] of m[1].matchAll(/--color-([a-z0-9-]+):\s*([^;]+);/g)) {
29
+ const value = raw.trim()
30
+ if (!/^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$/.test(value)) {
31
+ throw new Error(
32
+ `--color-${name} in ${selector} is \`${value}\` — this harness only understands 6- or 8-digit hex. Teach it that form (and how to composite it) before the token lands.`,
33
+ )
34
+ }
35
+ vars[name] = value
24
36
  }
25
37
  return vars
26
38
  }
@@ -46,6 +58,20 @@ function luminance([r, g, b]: Rgb): number {
46
58
  return 0.2126 * lr + 0.7152 * lg + 0.0722 * lb
47
59
  }
48
60
 
61
+ /**
62
+ * A static pair only means something for an OPAQUE value: a translucent token's
63
+ * effective colour depends on whatever it is composited over, which is a property
64
+ * of the layout, not of the token. Fail loudly rather than measure a fiction.
65
+ */
66
+ function opaque(name: string, hex: string): string {
67
+ if (hex.length !== 7) {
68
+ throw new Error(
69
+ `token ${name} is translucent (${hex}) — its effective colour depends on what it composites over, so it cannot be an operand of a static pair`,
70
+ )
71
+ }
72
+ return hex
73
+ }
74
+
49
75
  function ratio(fgHex: string, bgHex: string): number {
50
76
  const [a, b] = [luminance(rgb(fgHex)), luminance(rgb(bgHex))]
51
77
  return (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05)
@@ -66,14 +92,24 @@ const SOLID_PAIRS: Array<[fg: string, bg: string]> = [
66
92
  ['fg-on-brand', 'accent-yellow'],
67
93
  // flipping inverted surface × flipping inverted ink (Badge dark, Tile dark)
68
94
  ['fg-inverted', 'surface-inverted'],
69
- // grey Badge (fg-muted on surface-muted was ~3.7:1 — below AA for caption text)
95
+ // grey Badge — full `fg` ink. #19 lifted `fg-muted` on `surface-muted` from 3.64:1
96
+ // to 4.96:1, so the pair is no longer disqualified, but a Badge is caption-size and
97
+ // keeps the stronger ink; this pair is what that choice is asserted against.
70
98
  ['fg', 'surface-muted'],
71
99
  // general body-copy sanity
72
100
  ['fg', 'surface'],
73
- // NOT listed: ['fg-muted', 'surface'] — #7d786f on #ffffff measures ~4.39:1,
74
- // just under AA, despite the token's "AA-compliant grey on white" description.
75
- // Pre-existing, system-wide, and owned by the upstream token source — tracked
76
- // as its own issue; add the pair here once the value is corrected.
101
+ // #19: `fg-muted` was #7d786f, which cleared NONE of its own surfaces (4.39:1 on
102
+ // white, 4.06:1 on surface-card, 3.64:1 on surface-muted) while its description
103
+ // called itself "AA-compliant grey on white". The upstream token source darkened
104
+ // it to #67635b; these four pairs are the ones that value was tuned against, and
105
+ // the binding one is `border`/`surface-muted` (#eceae1), not white.
106
+ ['fg-muted', 'surface'],
107
+ ['fg-muted', 'surface-card'],
108
+ ['fg-muted', 'surface-muted'],
109
+ // NOT listed: ['fg-muted', 'border'] — in light `border` IS #eceae1, so the pair
110
+ // is numerically identical to the line above, and in dark it is a translucent
111
+ // #ffffff1a hairline that `opaque()` rejects. `bg-border` is only ever a 1px rule
112
+ // in this repo (separator.tsx, dropdown-menu.tsx), never a text background.
77
113
  ]
78
114
 
79
115
  /** Alpha-blended muted tones used by Tile (`/60` dark, `/70` teal/yellow). */
@@ -82,6 +118,17 @@ const BLENDED_PAIRS: Array<[fg: string, alpha: number, bg: string]> = [
82
118
  ['fg-on-brand', 0.7, 'brand-secondary'],
83
119
  ['fg-on-brand', 0.7, 'brand-green'],
84
120
  ['fg-on-brand', 0.7, 'accent-yellow'],
121
+ // Button's inactive (disabled / pending) label: it softens the INK over the
122
+ // variant's own surface rather than fading the whole control, so every ink ×
123
+ // surface combination it can land on has to hold AA on its own.
124
+ // `primary` — inverted ink on the brand fill, kept so a submitting CTA stays
125
+ // brand-coloured.
126
+ ['fg-inverted', 0.7, 'brand-primary'],
127
+ // `secondary` (surface-card), `destructive` (surface-muted) and `ghost`, which
128
+ // is transparent and therefore inherits whichever surface it sits on.
129
+ ['fg', 0.6, 'surface-card'],
130
+ ['fg', 0.6, 'surface-muted'],
131
+ ['fg', 0.6, 'surface'],
85
132
  ]
86
133
 
87
134
  for (const [themeName, tokens] of Object.entries(THEMES)) {
@@ -89,11 +136,19 @@ for (const [themeName, tokens] of Object.entries(THEMES)) {
89
136
  test.each(SOLID_PAIRS)('%s on %s ≥ 4.5:1', (fg, bg) => {
90
137
  expect(tokens[fg]).toBeDefined()
91
138
  expect(tokens[bg]).toBeDefined()
92
- expect(ratio(tokens[fg], tokens[bg])).toBeGreaterThanOrEqual(4.5)
139
+ expect(ratio(opaque(fg, tokens[fg]), opaque(bg, tokens[bg]))).toBeGreaterThanOrEqual(4.5)
93
140
  })
94
141
 
95
142
  test.each(BLENDED_PAIRS)('%s at %d over %s ≥ 4.5:1', (fg, alpha, bg) => {
96
- expect(ratio(blend(tokens[fg], alpha, tokens[bg]), tokens[bg])).toBeGreaterThanOrEqual(4.5)
143
+ expect(tokens[fg]).toBeDefined()
144
+ expect(tokens[bg]).toBeDefined()
145
+
146
+ // `blend()` applies the alpha ITSELF, so both operands must be opaque here
147
+ // for the same reason they must be in the solid test — `rgb()` slices bytes
148
+ // 1–7 and would silently discard a token's own alpha channel.
149
+ const [inkHex, bgHex] = [opaque(fg, tokens[fg]), opaque(bg, tokens[bg])]
150
+
151
+ expect(ratio(blend(inkHex, alpha, bgHex), bgHex)).toBeGreaterThanOrEqual(4.5)
97
152
  })
98
153
  })
99
154
  }
package/src/tokens.json CHANGED
@@ -451,8 +451,8 @@
451
451
  },
452
452
  "muted": {
453
453
  "$type": "color",
454
- "$value": "#7d786f",
455
- "$description": "Foreground muted — secondary/body text (AA-compliant grey on white). Dark: gs neutral-200 #aba89c. NOTE: gs de-emphasized DECORATIVE text (e.g. dashboard greeting) uses a lighter grey (#b3b3b3 = fg-subtle territory) — that is a per-component token choice, not this value.",
454
+ "$value": "#67635b",
455
+ "$description": "Foreground muted — secondary/body text. Light #67635b clears the 4.5:1 normal-text floor (WCAG 2.1 AA, accessibility.md) on EVERY light surface it is paired with: 5.98:1 on surface #ffffff, 5.53:1 on surface.card #f7f6f2, 4.96:1 on surface.muted AND border #eceae1. The previous value #7d786f cleared NONE of them (4.39:1 / 4.06:1 / 3.64:1) while this very description claimed it was an \"AA-compliant grey on white\" — it missed white by 0.11. The binding surface is #eceae1, not white: its AA ceiling is L* 44.7 where white allows L* 49.9, so a value tuned to white alone still fails the panel-strong surface and the step-indicator track. Same warm-grey hue as before (~40°, ~6% sat), 8.5 L* points darker (50.6 → 42.1). Still reads as SECONDARY, not body: 3.25:1 away from fg #0d0d0d (L* 3.6) and further clear of the decorative fg.subtle #b3b3b3 (L* 72.9) than the old value was. Dark: gs neutral-200 #aba89c, unchanged and already compliant (6.52:1 on surface #242423, 5.30:1 on surface.muted #333333); --color-border is a translucent hairline on dark, so that pair is composite-dependent and not asserted. NOTE: gs de-emphasized DECORATIVE text (e.g. dashboard greeting) uses a lighter grey (#b3b3b3 = fg-subtle territory) — that is a per-component token choice, not this value.",
456
456
  "$extensions": {
457
457
  "graphicstandard": {
458
458
  "family": "color",
@@ -464,7 +464,7 @@
464
464
  "themeKey": "light",
465
465
  "online": {
466
466
  "colorSpace": "hex",
467
- "hex": "#7d786f"
467
+ "hex": "#67635b"
468
468
  }
469
469
  },
470
470
  {
package/src/variables.css CHANGED
@@ -20,7 +20,7 @@
20
20
  --color-danger-light: #fee2e2;
21
21
  --color-fg: #0d0d0d;
22
22
  --color-fg-inverted: #ffffff;
23
- --color-fg-muted: #7d786f;
23
+ --color-fg-muted: #67635b;
24
24
  --color-fg-on-brand: #0d0d0d;
25
25
  --color-fg-subtle: #b3b3b3;
26
26
  --color-fg-workflow-muted: #858585;