@podoba/tokens 0.0.27 → 0.0.29

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.27",
3
+ "version": "0.0.29",
4
4
  "type": "module",
5
5
  "description": "podoba design tokens — static DTCG tokens.json + generated CSS custom properties. Framework-agnostic.",
6
6
  "repository": {
@@ -0,0 +1,108 @@
1
+ /// <reference types="bun" />
2
+
3
+ import { describe, expect, test } from 'bun:test'
4
+
5
+ /**
6
+ * WCAG 2.1 contrast regression over the generated token values — the static
7
+ * equivalent of an axe `color-contrast` pass, run for BOTH themes.
8
+ *
9
+ * Guards the pairing rule behind issues #13/#14/#15: every surface ships with a
10
+ * semantic foreground that stays AA-safe when the theme flips. FIXED light
11
+ * surfaces (brand-secondary, brand-green, accent-yellow) pair with the stable
12
+ * `fg-on-brand` ink; the theme-flipping `surface-inverted` pairs with the
13
+ * equally flipping `fg-inverted`.
14
+ */
15
+
16
+ const css = await Bun.file(new URL('./variables.css', import.meta.url)).text()
17
+
18
+ function parseBlock(selector: string): Record<string, string> {
19
+ const m = css.match(new RegExp(`${selector}\\s*\\{([^}]*)\\}`))
20
+ if (!m) throw new Error(`selector ${selector} not found in variables.css`)
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
24
+ }
25
+ return vars
26
+ }
27
+
28
+ const light = parseBlock(':root')
29
+ // The dark block only lists overrides — unlisted tokens keep their light value.
30
+ const dark = { ...light, ...parseBlock('\\[data-theme="dark"\\]') }
31
+ const THEMES = { light, dark } as const
32
+
33
+ type Rgb = [number, number, number]
34
+
35
+ const rgb = (hex: string): Rgb => [
36
+ parseInt(hex.slice(1, 3), 16),
37
+ parseInt(hex.slice(3, 5), 16),
38
+ parseInt(hex.slice(5, 7), 16),
39
+ ]
40
+
41
+ function luminance([r, g, b]: Rgb): number {
42
+ const [lr, lg, lb] = [r, g, b].map((c) => {
43
+ const s = c / 255
44
+ return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4
45
+ })
46
+ return 0.2126 * lr + 0.7152 * lg + 0.0722 * lb
47
+ }
48
+
49
+ function ratio(fgHex: string, bgHex: string): number {
50
+ const [a, b] = [luminance(rgb(fgHex)), luminance(rgb(bgHex))]
51
+ return (Math.max(a, b) + 0.05) / (Math.min(a, b) + 0.05)
52
+ }
53
+
54
+ /** Foreground at `alpha` composited over the surface (Tailwind `/60`-style tones). */
55
+ const blend = (fgHex: string, alpha: number, bgHex: string): string =>
56
+ '#' +
57
+ rgb(fgHex)
58
+ .map((c, i) => Math.round(alpha * c + (1 - alpha) * rgb(bgHex)[i]).toString(16).padStart(2, '0'))
59
+ .join('')
60
+
61
+ /** [foreground token, surface token] pairs that must hold ≥4.5:1 (normal text). */
62
+ const SOLID_PAIRS: Array<[fg: string, bg: string]> = [
63
+ // fixed light brand/accent surfaces × the stable on-brand ink (CtaPill, Badge, Tile teal/yellow)
64
+ ['fg-on-brand', 'brand-secondary'],
65
+ ['fg-on-brand', 'brand-green'],
66
+ ['fg-on-brand', 'accent-yellow'],
67
+ // flipping inverted surface × flipping inverted ink (Badge dark, Tile dark)
68
+ ['fg-inverted', 'surface-inverted'],
69
+ // grey Badge (fg-muted on surface-muted was ~3.7:1 — below AA for caption text)
70
+ ['fg', 'surface-muted'],
71
+ // general body-copy sanity
72
+ ['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.
77
+ ]
78
+
79
+ /** Alpha-blended muted tones used by Tile (`/60` dark, `/70` teal/yellow). */
80
+ const BLENDED_PAIRS: Array<[fg: string, alpha: number, bg: string]> = [
81
+ ['fg-inverted', 0.6, 'surface-inverted'],
82
+ ['fg-on-brand', 0.7, 'brand-secondary'],
83
+ ['fg-on-brand', 0.7, 'brand-green'],
84
+ ['fg-on-brand', 0.7, 'accent-yellow'],
85
+ ]
86
+
87
+ for (const [themeName, tokens] of Object.entries(THEMES)) {
88
+ describe(`${themeName} theme`, () => {
89
+ test.each(SOLID_PAIRS)('%s on %s ≥ 4.5:1', (fg, bg) => {
90
+ expect(tokens[fg]).toBeDefined()
91
+ expect(tokens[bg]).toBeDefined()
92
+ expect(ratio(tokens[fg], tokens[bg])).toBeGreaterThanOrEqual(4.5)
93
+ })
94
+
95
+ 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)
97
+ })
98
+ })
99
+ }
100
+
101
+ describe('fg-on-brand stability', () => {
102
+ test('is the same ink in both themes — the surfaces it pairs with never flip', () => {
103
+ expect(dark['fg-on-brand']).toBe(light['fg-on-brand'])
104
+ expect(dark['brand-secondary']).toBe(light['brand-secondary'])
105
+ expect(dark['brand-green']).toBe(light['brand-green'])
106
+ expect(dark['accent-yellow']).toBe(light['accent-yellow'])
107
+ })
108
+ })
package/src/tokens.json CHANGED
@@ -479,6 +479,29 @@
479
479
  }
480
480
  }
481
481
  },
482
+ "on-brand": {
483
+ "$type": "color",
484
+ "$value": "#0d0d0d",
485
+ "$description": "Foreground on brand — ink paired with the FIXED light brand/accent surfaces (brand-secondary, brand-green, accent-yellow). Those surfaces do not flip with the theme, so this stays brand black in both themes (they'd fail AA under a theme-flipping fg).",
486
+ "$extensions": {
487
+ "graphicstandard": {
488
+ "family": "color",
489
+ "layer": "semantic",
490
+ "value": {
491
+ "kind": "color",
492
+ "value": [
493
+ {
494
+ "themeKey": "light",
495
+ "online": {
496
+ "colorSpace": "hex",
497
+ "hex": "#0d0d0d"
498
+ }
499
+ }
500
+ ]
501
+ }
502
+ }
503
+ }
504
+ },
482
505
  "subtle": {
483
506
  "$type": "color",
484
507
  "$value": "#b3b3b3",
package/src/variables.css CHANGED
@@ -21,6 +21,7 @@
21
21
  --color-fg: #0d0d0d;
22
22
  --color-fg-inverted: #ffffff;
23
23
  --color-fg-muted: #7d786f;
24
+ --color-fg-on-brand: #0d0d0d;
24
25
  --color-fg-subtle: #b3b3b3;
25
26
  --color-neutral-300: #b3b3b3;
26
27
  --color-neutral-600: #333333;