@nyt87/tokens 0.0.0-stage → 0.1.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 NYT87
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,36 @@
1
- # Temporary Holding Version
1
+ # @nyt87/tokens
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Shared design tokens for all projects, as CSS custom properties. Source of truth: `src/tokens.mjs`. Rules: `DESIGN.md`. Visual check: the docs site (`npm run dev` at the repo root).
4
+
5
+ ```
6
+ npm run build # dist/tokens.css + dist/tokens.json
7
+ npm test # WCAG contrast for every theme and accent
8
+ ```
9
+
10
+ ## Adopting in a project
11
+ 1. Link it: `pnpm add ../design-system` (or `npm i ../design-system`).
12
+ 2. Import once at the app root, before the app CSS: `@import "@nyt87/tokens/tokens.css";`
13
+ 3. Replace local colour, radius and font variables with the shared names. Rename map for existing projects:
14
+
15
+ | Shared | bongsu | opentrack-viewer | gori |
16
+ |---|---|---|---|
17
+ | `--bg` | `--bg` | `--bg` | `--color-background` |
18
+ | `--bg-raised` | `--card` | `--bg-raised` | `--color-card` |
19
+ | `--bg-sunken` | – | `--bg-sunken` | `--color-muted` |
20
+ | `--fg` | `--fg` | `--text` | `--color-foreground` |
21
+ | `--fg-muted` | `--muted` | `--text-muted` | `--color-muted-foreground` |
22
+ | `--border` | `--line` | `--border` | `--color-border` |
23
+ | `--border-strong` | – | – | `--color-input-border` |
24
+ | `--accent-ink` | `--accent-ink` | `--accent` (text uses) | `--color-accent-text` |
25
+ | `--link` | – | – | – (new: Console Teal) |
26
+ | `--danger` | `--bad` | `--error` | `--color-destructive` |
27
+ | `--on-status` | `--on-warn` | – | – |
28
+
29
+ Next steps once adopted in two or more projects: extract duplicated components into `@nyt87/ui`.
30
+
31
+ ## Custom themes
32
+ ```js
33
+ import { defineTheme, checkTheme } from '@nyt87/tokens/theme';
34
+ const { css, failures } = defineTheme({ name: 'acme', light: { accent: '#0a5ad4' }, dark: { accent: '#5aa2ff', 'on-accent': '#08111c' } });
35
+ ```
36
+ Add `css` to the app and set `<html data-accent="acme">`. `failures` lists any pair below WCAG. Fonts are not bundled in the CSS: load Space Grotesk, Manrope and JetBrains Mono yourself (the docs site self-hosts them with `@fontsource-variable/*`); the stacks fall back to system fonts.
@@ -0,0 +1,36 @@
1
+ /* GENERATED from src/themes.mjs by scripts/build.mjs. Do not edit. */
2
+ :root[data-accent='gori'] {
3
+ --bg: #ffffff;
4
+ --bg-raised: #f8fafc;
5
+ --bg-sunken: #f1f5f9;
6
+ --fg: #0f172a;
7
+ --fg-muted: #475569;
8
+ --border: #e2e8f0;
9
+ --border-strong: #64748b;
10
+ --warn: #b45309;
11
+ --shadow: rgb(15 23 42 / 0.12);
12
+ }
13
+ @media (prefers-color-scheme: dark) {
14
+ :root[data-accent='gori']:not([data-theme='light']) {
15
+ --bg: #020617;
16
+ --bg-raised: #0e1223;
17
+ --bg-sunken: #1a1e2f;
18
+ --fg: #f8fafc;
19
+ --fg-muted: #94a3b8;
20
+ --border: #334155;
21
+ --border-strong: #64748b;
22
+ --warn: #f59e0b;
23
+ --shadow: rgb(0 0 0 / 0.45);
24
+ }
25
+ }
26
+ :root[data-accent='gori'][data-theme='dark'] {
27
+ --bg: #020617;
28
+ --bg-raised: #0e1223;
29
+ --bg-sunken: #1a1e2f;
30
+ --fg: #f8fafc;
31
+ --fg-muted: #94a3b8;
32
+ --border: #334155;
33
+ --border-strong: #64748b;
34
+ --warn: #f59e0b;
35
+ --shadow: rgb(0 0 0 / 0.45);
36
+ }
@@ -0,0 +1,159 @@
1
+ /* GENERATED by scripts/build.mjs from src/tokens.mjs. Do not edit. */
2
+ :root {
3
+ --font-heading: 'Space Grotesk', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
4
+ --font-sans: 'Manrope', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
5
+ --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
6
+ --weight-heading: 500;
7
+ --tracking-heading: -0.03em;
8
+ --text-xs: 0.75rem;
9
+ --text-sm: 0.875rem;
10
+ --text-md: 1rem;
11
+ --text-lg: 1.125rem;
12
+ --text-xl: 1.25rem;
13
+ --text-2xl: 1.5rem;
14
+ --text-3xl: 1.875rem;
15
+ --text-4xl: 2.25rem;
16
+ --leading-tight: 1.1;
17
+ --leading-normal: 1.6;
18
+ --space-1: 0.25rem;
19
+ --space-2: 0.5rem;
20
+ --space-3: 0.75rem;
21
+ --space-4: 1rem;
22
+ --space-5: 1.5rem;
23
+ --space-6: 2rem;
24
+ --space-7: 3rem;
25
+ --space-8: 4rem;
26
+ --radius-sm: 8px;
27
+ --radius-md: 12px;
28
+ --radius-lg: 18px;
29
+ --radius-full: 9999px;
30
+ --shadow-sm: 0 1px 2px var(--shadow);
31
+ --shadow-md: 0 8px 24px var(--shadow);
32
+ --duration-fast: 120ms;
33
+ --duration-base: 200ms;
34
+ --ease: cubic-bezier(0.2, 0, 0, 1);
35
+ --tap-min: 44px;
36
+ --nav-height: 4.5rem;
37
+ --max-width: 70rem;
38
+ --page-gutter: clamp(1rem, 3vw, 1.5rem);
39
+ --bg: #fdfbf8;
40
+ --bg-raised: #ffffff;
41
+ --bg-sunken: #f6f1eb;
42
+ --fg: #191511;
43
+ --fg-muted: #5e574f;
44
+ --border: #cfc9c4;
45
+ --border-strong: #857d75;
46
+ --accent: #be4500;
47
+ --on-accent: #ffffff;
48
+ --accent-ink: #b34200;
49
+ --link: #16707b;
50
+ --ok: #15803d;
51
+ --warn: #9a4a07;
52
+ --danger: #b91c1c;
53
+ --on-status: #ffffff;
54
+ --ring: #b34200;
55
+ --scrim: rgb(25 21 17 / 0.4);
56
+ --shadow: rgb(36 24 12 / 0.12);
57
+ --series-1: #86198f;
58
+ --series-2: #7c2d12;
59
+ --series-3: #0f766e;
60
+ --series-4: #6b6a0a;
61
+ --series-5: #334155;
62
+ color-scheme: light;
63
+ }
64
+ @media (prefers-color-scheme: dark) {
65
+ :root:not([data-theme='light']) {
66
+ --bg: #0e1216;
67
+ --bg-raised: #191d22;
68
+ --bg-sunken: #090c0f;
69
+ --fg: #efebe4;
70
+ --fg-muted: #b9b3aa;
71
+ --border: #424850;
72
+ --border-strong: #6b727a;
73
+ --accent: #be4500;
74
+ --on-accent: #ffffff;
75
+ --accent-ink: #f88f4f;
76
+ --link: #65c1cf;
77
+ --ok: #4ade80;
78
+ --warn: #fbbf24;
79
+ --danger: #f87171;
80
+ --on-status: #0e1216;
81
+ --ring: #f47f46;
82
+ --scrim: rgb(0 0 0 / 0.6);
83
+ --shadow: rgb(0 0 0 / 0.5);
84
+ --series-1: #f0abfc;
85
+ --series-2: #d99a6c;
86
+ --series-3: #5eead4;
87
+ --series-4: #bef264;
88
+ --series-5: #cbd5e1;
89
+ color-scheme: dark;
90
+ }
91
+ }
92
+ :root[data-theme='dark'] {
93
+ --bg: #0e1216;
94
+ --bg-raised: #191d22;
95
+ --bg-sunken: #090c0f;
96
+ --fg: #efebe4;
97
+ --fg-muted: #b9b3aa;
98
+ --border: #424850;
99
+ --border-strong: #6b727a;
100
+ --accent: #be4500;
101
+ --on-accent: #ffffff;
102
+ --accent-ink: #f88f4f;
103
+ --link: #65c1cf;
104
+ --ok: #4ade80;
105
+ --warn: #fbbf24;
106
+ --danger: #f87171;
107
+ --on-status: #0e1216;
108
+ --ring: #f47f46;
109
+ --scrim: rgb(0 0 0 / 0.6);
110
+ --shadow: rgb(0 0 0 / 0.5);
111
+ --series-1: #f0abfc;
112
+ --series-2: #d99a6c;
113
+ --series-3: #5eead4;
114
+ --series-4: #bef264;
115
+ --series-5: #cbd5e1;
116
+ color-scheme: dark;
117
+ }
118
+
119
+ :root[data-accent='green'] {
120
+ --accent: #15803d;
121
+ --on-accent: #ffffff;
122
+ --accent-ink: #166534;
123
+ --ring: #166534;
124
+ }
125
+ @media (prefers-color-scheme: dark) {
126
+ :root[data-accent='green']:not([data-theme='light']) {
127
+ --accent: #22c55e;
128
+ --on-accent: #052e16;
129
+ --accent-ink: #4ade80;
130
+ --ring: #4ade80;
131
+ }
132
+ }
133
+ :root[data-accent='green'][data-theme='dark'] {
134
+ --accent: #22c55e;
135
+ --on-accent: #052e16;
136
+ --accent-ink: #4ade80;
137
+ --ring: #4ade80;
138
+ }
139
+
140
+ :root[data-accent='blue'] {
141
+ --accent: #1668c4;
142
+ --on-accent: #ffffff;
143
+ --accent-ink: #1668c4;
144
+ --ring: #1668c4;
145
+ }
146
+ @media (prefers-color-scheme: dark) {
147
+ :root[data-accent='blue']:not([data-theme='light']) {
148
+ --accent: #4aa3ff;
149
+ --on-accent: #08111c;
150
+ --accent-ink: #4aa3ff;
151
+ --ring: #4aa3ff;
152
+ }
153
+ }
154
+ :root[data-accent='blue'][data-theme='dark'] {
155
+ --accent: #4aa3ff;
156
+ --on-accent: #08111c;
157
+ --accent-ink: #4aa3ff;
158
+ --ring: #4aa3ff;
159
+ }
@@ -0,0 +1,122 @@
1
+ {
2
+ "color": {
3
+ "light": {
4
+ "bg": "#fdfbf8",
5
+ "bg-raised": "#ffffff",
6
+ "bg-sunken": "#f6f1eb",
7
+ "fg": "#191511",
8
+ "fg-muted": "#5e574f",
9
+ "border": "#cfc9c4",
10
+ "border-strong": "#857d75",
11
+ "accent": "#be4500",
12
+ "on-accent": "#ffffff",
13
+ "accent-ink": "#b34200",
14
+ "link": "#16707b",
15
+ "ok": "#15803d",
16
+ "warn": "#9a4a07",
17
+ "danger": "#b91c1c",
18
+ "on-status": "#ffffff",
19
+ "ring": "#b34200",
20
+ "scrim": "rgb(25 21 17 / 0.4)",
21
+ "shadow": "rgb(36 24 12 / 0.12)",
22
+ "series-1": "#86198f",
23
+ "series-2": "#7c2d12",
24
+ "series-3": "#0f766e",
25
+ "series-4": "#6b6a0a",
26
+ "series-5": "#334155"
27
+ },
28
+ "dark": {
29
+ "bg": "#0e1216",
30
+ "bg-raised": "#191d22",
31
+ "bg-sunken": "#090c0f",
32
+ "fg": "#efebe4",
33
+ "fg-muted": "#b9b3aa",
34
+ "border": "#424850",
35
+ "border-strong": "#6b727a",
36
+ "accent": "#be4500",
37
+ "on-accent": "#ffffff",
38
+ "accent-ink": "#f88f4f",
39
+ "link": "#65c1cf",
40
+ "ok": "#4ade80",
41
+ "warn": "#fbbf24",
42
+ "danger": "#f87171",
43
+ "on-status": "#0e1216",
44
+ "ring": "#f47f46",
45
+ "scrim": "rgb(0 0 0 / 0.6)",
46
+ "shadow": "rgb(0 0 0 / 0.5)",
47
+ "series-1": "#f0abfc",
48
+ "series-2": "#d99a6c",
49
+ "series-3": "#5eead4",
50
+ "series-4": "#bef264",
51
+ "series-5": "#cbd5e1"
52
+ }
53
+ },
54
+ "accents": {
55
+ "green": {
56
+ "light": {
57
+ "accent": "#15803d",
58
+ "on-accent": "#ffffff",
59
+ "accent-ink": "#166534",
60
+ "ring": "#166534"
61
+ },
62
+ "dark": {
63
+ "accent": "#22c55e",
64
+ "on-accent": "#052e16",
65
+ "accent-ink": "#4ade80",
66
+ "ring": "#4ade80"
67
+ }
68
+ },
69
+ "blue": {
70
+ "light": {
71
+ "accent": "#1668c4",
72
+ "on-accent": "#ffffff",
73
+ "accent-ink": "#1668c4",
74
+ "ring": "#1668c4"
75
+ },
76
+ "dark": {
77
+ "accent": "#4aa3ff",
78
+ "on-accent": "#08111c",
79
+ "accent-ink": "#4aa3ff",
80
+ "ring": "#4aa3ff"
81
+ }
82
+ }
83
+ },
84
+ "base": {
85
+ "font-heading": "'Space Grotesk', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif",
86
+ "font-sans": "'Manrope', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif",
87
+ "font-mono": "'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",
88
+ "weight-heading": "500",
89
+ "tracking-heading": "-0.03em",
90
+ "text-xs": "0.75rem",
91
+ "text-sm": "0.875rem",
92
+ "text-md": "1rem",
93
+ "text-lg": "1.125rem",
94
+ "text-xl": "1.25rem",
95
+ "text-2xl": "1.5rem",
96
+ "text-3xl": "1.875rem",
97
+ "text-4xl": "2.25rem",
98
+ "leading-tight": "1.1",
99
+ "leading-normal": "1.6",
100
+ "space-1": "0.25rem",
101
+ "space-2": "0.5rem",
102
+ "space-3": "0.75rem",
103
+ "space-4": "1rem",
104
+ "space-5": "1.5rem",
105
+ "space-6": "2rem",
106
+ "space-7": "3rem",
107
+ "space-8": "4rem",
108
+ "radius-sm": "8px",
109
+ "radius-md": "12px",
110
+ "radius-lg": "18px",
111
+ "radius-full": "9999px",
112
+ "shadow-sm": "0 1px 2px var(--shadow)",
113
+ "shadow-md": "0 8px 24px var(--shadow)",
114
+ "duration-fast": "120ms",
115
+ "duration-base": "200ms",
116
+ "ease": "cubic-bezier(0.2, 0, 0, 1)",
117
+ "tap-min": "44px",
118
+ "nav-height": "4.5rem",
119
+ "max-width": "70rem",
120
+ "page-gutter": "clamp(1rem, 3vw, 1.5rem)"
121
+ }
122
+ }
package/package.json CHANGED
@@ -1,6 +1,44 @@
1
1
  {
2
2
  "name": "@nyt87/tokens",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.2",
4
+ "description": "Shared design tokens (CSS custom properties) for all projects",
5
+ "type": "module",
6
+ "files": [
7
+ "dist",
8
+ "src"
9
+ ],
10
+ "exports": {
11
+ "./tokens.css": "./dist/tokens.css",
12
+ "./tokens.json": "./dist/tokens.json",
13
+ "./theme": {
14
+ "types": "./src/theme.d.ts",
15
+ "default": "./src/theme.mjs"
16
+ },
17
+ "./tokens.mjs": {
18
+ "types": "./src/tokens.d.ts",
19
+ "default": "./src/tokens.mjs"
20
+ },
21
+ "./themes": {
22
+ "types": "./src/themes.d.ts",
23
+ "default": "./src/themes.mjs"
24
+ },
25
+ "./themes/*.css": "./dist/themes/*.css"
26
+ },
27
+ "scripts": {
28
+ "build": "node scripts/build.mjs",
29
+ "test": "node --test \"test/*.test.mjs\"",
30
+ "prepack": "node scripts/build.mjs"
31
+ },
32
+ "license": "MIT",
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/NYT87/design-system.git",
36
+ "directory": "packages/tokens"
37
+ },
38
+ "publishConfig": {
39
+ "registry": "https://npm.pkg.github.com"
40
+ },
41
+ "sideEffects": [
42
+ "**/*.css"
43
+ ]
44
+ }
package/src/theme.d.ts ADDED
@@ -0,0 +1,38 @@
1
+ import type { color as Color } from './tokens.mjs';
2
+
3
+ /** Every colour token. A test keeps this list equal to the tokens in tokens.mjs. */
4
+ export type ColorToken =
5
+ | 'bg'
6
+ | 'bg-raised'
7
+ | 'bg-sunken'
8
+ | 'fg'
9
+ | 'fg-muted'
10
+ | 'border'
11
+ | 'border-strong'
12
+ | 'accent'
13
+ | 'on-accent'
14
+ | 'accent-ink'
15
+ | 'link'
16
+ | 'ok'
17
+ | 'warn'
18
+ | 'danger'
19
+ | 'on-status'
20
+ | 'ring'
21
+ | 'scrim'
22
+ | 'shadow'
23
+ | 'series-1'
24
+ | 'series-2'
25
+ | 'series-3'
26
+ | 'series-4'
27
+ | 'series-5';
28
+ export type ColorOverrides = Partial<Record<ColorToken, string>>;
29
+ export interface ThemeOverrides { light?: ColorOverrides; dark?: ColorOverrides }
30
+ export interface ContrastFailure { mode: 'light' | 'dark'; fg: ColorToken; bg: ColorToken; ratio: number; min: number; fgColor: string; bgColor: string }
31
+
32
+ export const COLOR_TOKENS: ColorToken[];
33
+ export const RULES: Array<[ColorToken, ColorToken, number]>;
34
+ export function themeCss(selector: string, theme?: ThemeOverrides, options?: { on?: 'root' | 'scope' }): string;
35
+ export function contrast(a: string, b: string): number | null;
36
+ export function checkTheme(theme?: ThemeOverrides, preset?: typeof Color): ContrastFailure[];
37
+ export function assertKnownTokens(overrides: ThemeOverrides): void;
38
+ export function defineTheme(options: ThemeOverrides & { name: string; attribute?: string }): { css: string; failures: ContrastFailure[] };
package/src/theme.mjs ADDED
@@ -0,0 +1,99 @@
1
+ // Custom themes: generate CSS for any subset of colour tokens, and check it still meets WCAG.
2
+ // Pure JS with no dependencies, so it runs in Node (build scripts, tests) and in the browser (<ds-theme-scope>, theme builder).
3
+ import { color } from './tokens.mjs';
4
+
5
+ export const COLOR_TOKENS = Object.keys(color.light);
6
+
7
+ const decl = (obj, indent) => Object.entries(obj).map(([k, v]) => `${indent}--${k}: ${v};`).join('\n');
8
+ const block = (selector, obj, indent = '') => `${indent}${selector} {\n${decl(obj, indent + ' ')}\n${indent}}`;
9
+
10
+ /**
11
+ * CSS that applies `light` and `dark` overrides. Pass only the tokens you change; the rest keep their base values.
12
+ * Dark follows the OS unless data-theme="light" is forced on <html>, and applies unconditionally for data-theme="dark",
13
+ * the same rules as the base tokens.
14
+ * on: 'root' -> `selector` matches <html> itself, e.g. ":root[data-accent='acme']"
15
+ * on: 'scope' -> `selector` matches an element inside the page, e.g. ".acme-theme" (what <ds-theme-scope> uses)
16
+ */
17
+ export function themeCss(selector, { light = {}, dark = {} } = {}, { on = 'root' } = {}) {
18
+ const osDark = on === 'root' ? `${selector}:not([data-theme='light'])` : `:root:not([data-theme='light']) ${selector}`;
19
+ const forcedDark = on === 'root' ? `${selector}[data-theme='dark']` : `:root[data-theme='dark'] ${selector}`;
20
+ const parts = [];
21
+ if (Object.keys(light).length) parts.push(block(selector, light));
22
+ if (Object.keys(dark).length) {
23
+ parts.push(`@media (prefers-color-scheme: dark) {\n${block(osDark, dark, ' ')}\n}`);
24
+ parts.push(block(forcedDark, dark));
25
+ }
26
+ return parts.join('\n');
27
+ }
28
+
29
+ // ---- contrast ----
30
+ const hex = (c) => {
31
+ const m = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(c.trim());
32
+ if (!m) return null;
33
+ const h = m[1].length === 3 ? [...m[1]].map((x) => x + x).join('') : m[1];
34
+ return [0, 2, 4].map((i) => parseInt(h.slice(i, i + 2), 16));
35
+ };
36
+ const lum = ([r, g, b]) => {
37
+ const [R, G, B] = [r, g, b].map((v) => v / 255).map((c) => (c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4));
38
+ return 0.2126 * R + 0.7152 * G + 0.0722 * B;
39
+ };
40
+ /** WCAG contrast ratio of two #rrggbb colours, or null if either is not a hex colour. */
41
+ export function contrast(a, b) {
42
+ const x = hex(a), y = hex(b);
43
+ if (!x || !y) return null;
44
+ const [hi, lo] = [lum(x), lum(y)].sort((p, q) => q - p);
45
+ return (hi + 0.05) / (lo + 0.05);
46
+ }
47
+
48
+ /** [foreground, background, minimum ratio, what it is]. The rules every theme must satisfy. */
49
+ export const RULES = [
50
+ ['fg', 'bg', 4.5], ['fg', 'bg-raised', 4.5], ['fg', 'bg-sunken', 4.5],
51
+ ['fg-muted', 'bg', 4.5], ['fg-muted', 'bg-raised', 4.5], ['fg-muted', 'bg-sunken', 4.5],
52
+ ['accent-ink', 'bg', 4.5], ['accent-ink', 'bg-raised', 4.5], ['accent-ink', 'bg-sunken', 4.5],
53
+ ['link', 'bg', 4.5], ['link', 'bg-raised', 4.5], ['link', 'bg-sunken', 4.5],
54
+ ['on-accent', 'accent', 4.5],
55
+ ['ok', 'bg', 4.5], ['ok', 'bg-raised', 4.5],
56
+ ['warn', 'bg', 4.5], ['warn', 'bg-raised', 4.5],
57
+ ['danger', 'bg', 4.5], ['danger', 'bg-raised', 4.5],
58
+ ['on-status', 'ok', 4.5], ['on-status', 'warn', 4.5], ['on-status', 'danger', 4.5],
59
+ ['border-strong', 'bg', 3], ['border-strong', 'bg-raised', 3],
60
+ ['ring', 'bg', 3], ['ring', 'bg-raised', 3], ['ring', 'bg-sunken', 3],
61
+ ['accent', 'bg', 3], ['accent', 'bg-raised', 3],
62
+ ...[1, 2, 3, 4, 5].map((n) => [`series-${n}`, 'bg-raised', 3]),
63
+ ];
64
+
65
+ /**
66
+ * Check a theme (partial overrides allowed, merged over the base) for both modes.
67
+ * Returns the failing pairs: [] means the theme is accessible. Colours that are not #hex are skipped (cannot be measured).
68
+ */
69
+ export function checkTheme({ light = {}, dark = {} } = {}, preset = color) {
70
+ const failures = [];
71
+ for (const [mode, over] of [['light', light], ['dark', dark]]) {
72
+ const t = { ...preset[mode], ...over };
73
+ for (const [fg, bg, min] of RULES) {
74
+ const r = contrast(t[fg], t[bg]);
75
+ if (r !== null && r < min) failures.push({ mode, fg, bg, ratio: Math.round(r * 100) / 100, min, fgColor: t[fg], bgColor: t[bg] });
76
+ }
77
+ }
78
+ return failures;
79
+ }
80
+
81
+ /** Throws if `overrides` use a token name that does not exist (catches typos like "accnet"). */
82
+ export function assertKnownTokens(overrides) {
83
+ for (const mode of ['light', 'dark']) for (const k of Object.keys(overrides[mode] ?? {})) {
84
+ if (!COLOR_TOKENS.includes(k)) throw new Error(`Unknown colour token "${k}" in ${mode}. Known: ${COLOR_TOKENS.join(', ')}`);
85
+ }
86
+ }
87
+
88
+ /**
89
+ * One call for a custom theme: validates names, checks contrast, returns the CSS and any failures.
90
+ * const { css, failures } = defineTheme({ name: 'acme', light: { accent: '#0a6cff' }, dark: { accent: '#5aa2ff' } });
91
+ * Apply with <html data-accent="acme"> after adding the css to your page.
92
+ */
93
+ export function defineTheme({ name, attribute = 'accent', light = {}, dark = {} }) {
94
+ assertKnownTokens({ light, dark });
95
+ return {
96
+ css: themeCss(`:root[data-${attribute}='${name}']`, { light, dark }),
97
+ failures: checkTheme({ light, dark }),
98
+ };
99
+ }
@@ -0,0 +1,4 @@
1
+ import type { ThemeOverrides } from './theme.js';
2
+ export interface NamedTheme extends ThemeOverrides { name: string }
3
+ export const gori: NamedTheme;
4
+ export const themes: Record<string, NamedTheme>;
package/src/themes.mjs ADDED
@@ -0,0 +1,22 @@
1
+ // Named product themes shared across nyt87 products. Each is a set of token overrides applied with <html data-accent="name">.
2
+ // The accent family is deliberately not overridden: buttons, links and the focus ring stay nyt87 orange.
3
+ // scripts/build.mjs emits dist/themes/<name>.css for each one and fails if a pair drops below WCAG contrast.
4
+
5
+ /** Gori: slate neutrals, dark first. Green stays for success states (--ok). */
6
+ export const gori = {
7
+ name: 'gori',
8
+ dark: {
9
+ bg: '#020617', 'bg-raised': '#0e1223', 'bg-sunken': '#1a1e2f',
10
+ fg: '#f8fafc', 'fg-muted': '#94a3b8',
11
+ border: '#334155', 'border-strong': '#64748b',
12
+ warn: '#f59e0b', shadow: 'rgb(0 0 0 / 0.45)',
13
+ },
14
+ light: {
15
+ bg: '#ffffff', 'bg-raised': '#f8fafc', 'bg-sunken': '#f1f5f9',
16
+ fg: '#0f172a', 'fg-muted': '#475569',
17
+ border: '#e2e8f0', 'border-strong': '#64748b',
18
+ warn: '#b45309', shadow: 'rgb(15 23 42 / 0.12)',
19
+ },
20
+ };
21
+
22
+ export const themes = { gori };
@@ -0,0 +1,3 @@
1
+ export const color: { light: Record<string, string>; dark: Record<string, string> };
2
+ export const accents: Record<string, { light: Record<string, string>; dark: Record<string, string> }>;
3
+ export const base: Record<string, string>;
package/src/tokens.mjs ADDED
@@ -0,0 +1,110 @@
1
+ // Single source of truth. `npm run build` turns this into dist/tokens.css and dist/tokens.json.
2
+ // Base identity: the nyt87 brand (docs/brand-guidelines.md on the company site): Signal Orange, Console Teal, warm neutrals.
3
+ // The light page background is a warm white (#fdfbf8) rather than the company site's parchment (#faf4ee).
4
+ // Every colour has a light and a dark value. Names are semantic (what it is for), never literal (orange-500).
5
+
6
+ export const color = {
7
+ light: {
8
+ bg: '#fdfbf8', // page (warm white)
9
+ 'bg-raised': '#ffffff', // cards, panels, popovers
10
+ 'bg-sunken': '#f6f1eb', // wells, code blocks, hover rows
11
+ fg: '#191511',
12
+ 'fg-muted': '#5e574f', // secondary text
13
+ border: '#cfc9c4', // decorative dividers
14
+ 'border-strong': '#857d75', // inputs, anything whose edge must be seen (>= 3:1)
15
+ accent: '#be4500', // fill of primary actions (Signal Orange)
16
+ 'on-accent': '#ffffff',
17
+ 'accent-ink': '#b34200', // accent used as text, markers, selected state
18
+ link: '#16707b', // text links (Console Teal)
19
+ ok: '#15803d',
20
+ warn: '#9a4a07',
21
+ danger: '#b91c1c',
22
+ 'on-status': '#ffffff', // text on a solid ok/warn/danger fill
23
+ ring: '#b34200', // focus ring, >= 3:1 on every surface
24
+ scrim: 'rgb(25 21 17 / 0.4)',
25
+ shadow: 'rgb(36 24 12 / 0.12)',
26
+ 'series-1': '#86198f',
27
+ 'series-2': '#7c2d12',
28
+ 'series-3': '#0f766e',
29
+ 'series-4': '#6b6a0a',
30
+ 'series-5': '#334155',
31
+ },
32
+ dark: {
33
+ bg: '#0e1216',
34
+ 'bg-raised': '#191d22',
35
+ 'bg-sunken': '#090c0f',
36
+ fg: '#efebe4',
37
+ 'fg-muted': '#b9b3aa',
38
+ border: '#424850',
39
+ 'border-strong': '#6b727a',
40
+ accent: '#be4500',
41
+ 'on-accent': '#ffffff',
42
+ 'accent-ink': '#f88f4f',
43
+ link: '#65c1cf',
44
+ ok: '#4ade80',
45
+ warn: '#fbbf24',
46
+ danger: '#f87171',
47
+ 'on-status': '#0e1216',
48
+ ring: '#f47f46',
49
+ scrim: 'rgb(0 0 0 / 0.6)',
50
+ shadow: 'rgb(0 0 0 / 0.5)',
51
+ 'series-1': '#f0abfc',
52
+ 'series-2': '#d99a6c',
53
+ 'series-3': '#5eead4',
54
+ 'series-4': '#bef264',
55
+ 'series-5': '#cbd5e1',
56
+ },
57
+ };
58
+
59
+ // Built-in presets, selected with <html data-accent="green">. They only override what they list.
60
+ // Custom ones: see theme.mjs (defineTheme) and the Theming page of the docs.
61
+ export const accents = {
62
+ green: {
63
+ light: { accent: '#15803d', 'on-accent': '#ffffff', 'accent-ink': '#166534', ring: '#166534' },
64
+ dark: { accent: '#22c55e', 'on-accent': '#052e16', 'accent-ink': '#4ade80', ring: '#4ade80' },
65
+ },
66
+ blue: {
67
+ light: { accent: '#1668c4', 'on-accent': '#ffffff', 'accent-ink': '#1668c4', ring: '#1668c4' },
68
+ dark: { accent: '#4aa3ff', 'on-accent': '#08111c', 'accent-ink': '#4aa3ff', ring: '#4aa3ff' },
69
+ },
70
+ };
71
+
72
+ // Theme-independent tokens.
73
+ export const base = {
74
+ 'font-heading': "'Space Grotesk', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif",
75
+ 'font-sans': "'Manrope', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif",
76
+ 'font-mono': "'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",
77
+ 'weight-heading': '500',
78
+ 'tracking-heading': '-0.03em',
79
+ 'text-xs': '0.75rem',
80
+ 'text-sm': '0.875rem',
81
+ 'text-md': '1rem',
82
+ 'text-lg': '1.125rem',
83
+ 'text-xl': '1.25rem',
84
+ 'text-2xl': '1.5rem',
85
+ 'text-3xl': '1.875rem',
86
+ 'text-4xl': '2.25rem',
87
+ 'leading-tight': '1.1',
88
+ 'leading-normal': '1.6',
89
+ 'space-1': '0.25rem',
90
+ 'space-2': '0.5rem',
91
+ 'space-3': '0.75rem',
92
+ 'space-4': '1rem',
93
+ 'space-5': '1.5rem',
94
+ 'space-6': '2rem',
95
+ 'space-7': '3rem',
96
+ 'space-8': '4rem',
97
+ 'radius-sm': '8px',
98
+ 'radius-md': '12px',
99
+ 'radius-lg': '18px',
100
+ 'radius-full': '9999px',
101
+ 'shadow-sm': '0 1px 2px var(--shadow)',
102
+ 'shadow-md': '0 8px 24px var(--shadow)',
103
+ 'duration-fast': '120ms',
104
+ 'duration-base': '200ms',
105
+ ease: 'cubic-bezier(0.2, 0, 0, 1)',
106
+ 'tap-min': '44px',
107
+ 'nav-height': '4.5rem',
108
+ 'max-width': '70rem',
109
+ 'page-gutter': 'clamp(1rem, 3vw, 1.5rem)',
110
+ };