@zhin.js/console-ui 1.0.0 → 1.1.0
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/CHANGELOG.md +45 -0
- package/README.md +118 -11
- package/audit/index.mjs +21 -0
- package/audit/layout-audit.mjs +492 -0
- package/audit/mount-page.jsx +90 -0
- package/audit/plugin-pages.mjs +186 -0
- package/dist/components/BrandMark.d.ts +16 -0
- package/dist/components/BrandMark.js +21 -0
- package/dist/components/InfoHint.js +2 -1
- package/dist/components/PageHeader.d.ts +9 -2
- package/dist/components/PageHeader.js +6 -3
- package/dist/components/PageShell.d.ts +18 -3
- package/dist/components/PageShell.js +5 -3
- package/dist/components/RefreshControl.d.ts +6 -1
- package/dist/components/RefreshControl.js +9 -6
- package/dist/components/StatCard.d.ts +19 -5
- package/dist/components/StatCard.js +36 -10
- package/dist/components/StatusBadge.d.ts +14 -0
- package/dist/components/StatusBadge.js +19 -0
- package/dist/components/actions.d.ts +53 -0
- package/dist/components/actions.js +50 -0
- package/dist/components/code.d.ts +11 -0
- package/dist/components/code.js +10 -0
- package/dist/components/confirm-dialog.js +3 -2
- package/dist/components/content-blocks.d.ts +141 -0
- package/dist/components/content-blocks.js +77 -0
- package/dist/components/empty-illustrations.d.ts +15 -0
- package/dist/components/empty-illustrations.js +36 -0
- package/dist/components/empty-state.d.ts +23 -3
- package/dist/components/empty-state.js +36 -8
- package/dist/components/error-alert.js +2 -1
- package/dist/components/icon.d.ts +11 -0
- package/dist/components/icon.js +8 -0
- package/dist/components/layout.d.ts +38 -0
- package/dist/components/layout.js +28 -0
- package/dist/components/page-chrome.d.ts +12 -0
- package/dist/components/page-chrome.js +6 -5
- package/dist/components/ui/accordion.js +3 -2
- package/dist/components/ui/alert.js +5 -5
- package/dist/components/ui/badge.js +10 -9
- package/dist/components/ui/button.d.ts +10 -1
- package/dist/components/ui/button.js +26 -11
- package/dist/components/ui/card.d.ts +6 -0
- package/dist/components/ui/card.js +5 -4
- package/dist/components/ui/checkbox.js +2 -1
- package/dist/components/ui/control-variant.d.ts +10 -0
- package/dist/components/ui/control-variant.js +6 -0
- package/dist/components/ui/date-field-model.d.ts +39 -0
- package/dist/components/ui/date-field-model.js +105 -0
- package/dist/components/ui/date-field.d.ts +33 -0
- package/dist/components/ui/date-field.js +161 -0
- package/dist/components/ui/dialog.js +7 -6
- package/dist/components/ui/dropdown-menu.js +6 -5
- package/dist/components/ui/input.d.ts +6 -1
- package/dist/components/ui/input.js +3 -2
- package/dist/components/ui/list-item-button.js +1 -1
- package/dist/components/ui/popover.js +1 -1
- package/dist/components/ui/radio-group.js +1 -1
- package/dist/components/ui/scroll-area.js +1 -1
- package/dist/components/ui/searchable-select.d.ts +3 -0
- package/dist/components/ui/searchable-select.js +4 -3
- package/dist/components/ui/select.d.ts +7 -1
- package/dist/components/ui/select.js +7 -5
- package/dist/components/ui/sheet.js +4 -3
- package/dist/components/ui/skeleton.js +1 -1
- package/dist/components/ui/switch.js +1 -1
- package/dist/components/ui/table.d.ts +11 -0
- package/dist/components/ui/table.js +37 -6
- package/dist/components/ui/tabs.js +3 -3
- package/dist/components/ui/textarea.d.ts +6 -1
- package/dist/components/ui/textarea.js +3 -2
- package/dist/components/ui/tooltip.js +1 -1
- package/dist/components/use-container-width.d.ts +13 -0
- package/dist/components/use-container-width.js +30 -0
- package/dist/custom-media.css +13 -0
- package/dist/exports.json +41 -1
- package/dist/i18n/messages.d.ts +20 -1
- package/dist/i18n/messages.js +40 -2
- package/dist/index.d.ts +12 -0
- package/dist/index.js +11 -0
- package/dist/scale.json +643 -0
- package/dist/styles.css +1919 -836
- package/dist/theme.css +469 -0
- package/dist/tokens.css +434 -123
- package/dist/version.js +1 -1
- package/lint/eslint-plugin.mjs +128 -0
- package/lint/stylelint-config.mjs +43 -0
- package/lint/stylelint-plugin.mjs +195 -0
- package/lint/tailwind-classes.mjs +121 -0
- package/package.json +33 -3
- package/tokens/color.mjs +104 -0
- package/tokens/colors.css +220 -0
- package/tokens/generate.mjs +288 -0
- package/tokens/scale.mjs +137 -0
- package/tokens/tokens.mjs +362 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @zhin.js/console-ui — color tokens (light / dark / palettes). Hand-written source, defined only
|
|
3
|
+
* here; tokens/generate.mjs copies it into the generated tokens.css. Palette colors unchanged from
|
|
4
|
+
* P1a (D22: colors and component shapes follow the current Console). The roles that do not follow
|
|
5
|
+
* the palette — brand, signal fill / text, chart-1…8 — are defined in tokens/tokens.mjs (`color`,
|
|
6
|
+
* zhinjs/console#125); the older names below (`--destructive`, `--success`, `--warning`, `--info`,
|
|
7
|
+
* `--chart-*`, `--ring`) now point at them and are redeclared on `.dark` so they resolve there.
|
|
8
|
+
* Dark mode follows the `.dark` class on an ancestor (the Console puts it on <html>); palettes
|
|
9
|
+
* follow `data-palette` on <html>.
|
|
10
|
+
*/
|
|
11
|
+
@layer base {
|
|
12
|
+
:root {
|
|
13
|
+
/* ── Palette inputs (overridden per palette below) ── */
|
|
14
|
+
--palette-hue: 214;
|
|
15
|
+
/* Neutral surfaces: just enough hue to feel related, not colored. */
|
|
16
|
+
--palette-surface-chroma: 14%;
|
|
17
|
+
--palette-dark-surface-chroma: 12%;
|
|
18
|
+
--palette-ink-chroma: 34%;
|
|
19
|
+
--palette-brand-saturation: 88%;
|
|
20
|
+
--palette-brand-lightness: 44%;
|
|
21
|
+
--palette-dark-brand-saturation: 96%;
|
|
22
|
+
--palette-dark-brand-lightness: 66%;
|
|
23
|
+
/* Soft tints used for primary actions, selection and the outgoing chat bubble. */
|
|
24
|
+
--palette-tint-saturation: 100%;
|
|
25
|
+
--palette-tint-lightness: 95.5%;
|
|
26
|
+
--palette-dark-tint-saturation: 42%;
|
|
27
|
+
--palette-dark-tint-lightness: 17%;
|
|
28
|
+
--surface-chroma: var(--palette-surface-chroma);
|
|
29
|
+
|
|
30
|
+
--background: var(--palette-hue) var(--surface-chroma) 95.4%;
|
|
31
|
+
--foreground: var(--palette-hue) var(--palette-ink-chroma) 12%;
|
|
32
|
+
--card: 0 0% 100%;
|
|
33
|
+
--card-foreground: var(--foreground);
|
|
34
|
+
--popover: var(--card);
|
|
35
|
+
--popover-foreground: var(--foreground);
|
|
36
|
+
--primary: var(--palette-hue) var(--palette-brand-saturation) var(--palette-brand-lightness);
|
|
37
|
+
--primary-foreground: 0 0% 100%;
|
|
38
|
+
--primary-action: var(--palette-hue) var(--palette-tint-saturation) var(--palette-tint-lightness);
|
|
39
|
+
--primary-action-foreground: var(--primary);
|
|
40
|
+
--primary-action-border: var(--palette-hue) var(--palette-brand-saturation) 78%;
|
|
41
|
+
--secondary: var(--palette-hue) var(--surface-chroma) 97.2%;
|
|
42
|
+
--secondary-foreground: var(--foreground);
|
|
43
|
+
--muted: var(--secondary);
|
|
44
|
+
--muted-foreground: var(--palette-hue) var(--surface-chroma) 39%;
|
|
45
|
+
--accent: var(--palette-hue) var(--surface-chroma) 93.2%;
|
|
46
|
+
--accent-foreground: var(--foreground);
|
|
47
|
+
--selected: var(--primary-action);
|
|
48
|
+
--selected-foreground: var(--primary);
|
|
49
|
+
--border: var(--palette-hue) var(--surface-chroma) 90.5%;
|
|
50
|
+
--border-strong: var(--palette-hue) var(--surface-chroma) 84%;
|
|
51
|
+
--input: var(--palette-hue) var(--surface-chroma) 51%;
|
|
52
|
+
--ring: var(--console-brand-text);
|
|
53
|
+
--sidebar: var(--card);
|
|
54
|
+
--sidebar-foreground: var(--palette-hue) var(--surface-chroma) 30%;
|
|
55
|
+
--sidebar-primary: var(--primary);
|
|
56
|
+
--sidebar-primary-foreground: var(--primary-foreground);
|
|
57
|
+
--sidebar-accent: var(--accent);
|
|
58
|
+
--sidebar-accent-foreground: var(--accent-foreground);
|
|
59
|
+
--sidebar-border: var(--border);
|
|
60
|
+
--sidebar-ring: var(--ring);
|
|
61
|
+
--im-shell-bg: var(--card);
|
|
62
|
+
--im-list-bg: var(--card);
|
|
63
|
+
--im-list-surface: var(--card);
|
|
64
|
+
--im-chat-bg: var(--secondary);
|
|
65
|
+
--im-chat-wash: var(--accent);
|
|
66
|
+
--im-line: var(--border);
|
|
67
|
+
--im-shadow: 222 30% 12%;
|
|
68
|
+
--im-bubble-in: var(--card);
|
|
69
|
+
--im-bubble-out: var(--primary-action);
|
|
70
|
+
--im-bubble-out-fg: var(--foreground);
|
|
71
|
+
--im-date-bg: var(--card);
|
|
72
|
+
--im-date-fg: var(--muted-foreground);
|
|
73
|
+
--im-at: var(--primary);
|
|
74
|
+
--im-row-hover: var(--palette-hue) var(--surface-chroma) 96%;
|
|
75
|
+
--im-row-active: var(--primary-action);
|
|
76
|
+
--im-row-active-fg: var(--foreground);
|
|
77
|
+
--im-row-active-muted: var(--muted-foreground);
|
|
78
|
+
--im-unread: var(--primary);
|
|
79
|
+
--destructive: var(--console-signal-danger-text);
|
|
80
|
+
--success: var(--console-signal-success-text);
|
|
81
|
+
--info: var(--console-signal-info-text);
|
|
82
|
+
--warning: var(--console-signal-warning-text);
|
|
83
|
+
--destructive-foreground: 0 0% 100%;
|
|
84
|
+
--success-foreground: 0 0% 100%;
|
|
85
|
+
--info-foreground: 0 0% 100%;
|
|
86
|
+
--warning-foreground: 0 0% 100%;
|
|
87
|
+
--status-info: var(--info);
|
|
88
|
+
--status-success: var(--success);
|
|
89
|
+
--status-warning: var(--warning);
|
|
90
|
+
--status-danger: var(--destructive);
|
|
91
|
+
--chart-1: var(--console-chart-1);
|
|
92
|
+
--chart-2: var(--console-chart-2);
|
|
93
|
+
--chart-3: var(--console-chart-3);
|
|
94
|
+
--chart-4: var(--console-chart-4);
|
|
95
|
+
--chart-5: var(--console-chart-5);
|
|
96
|
+
--chart-6: var(--console-chart-6);
|
|
97
|
+
--chart-7: var(--console-chart-7);
|
|
98
|
+
--chart-8: var(--console-chart-8);
|
|
99
|
+
--chart-other: var(--console-chart-other);
|
|
100
|
+
color-scheme: light;
|
|
101
|
+
}
|
|
102
|
+
/* Fresh palettes: brighter hues; their tints are slightly warmer so selection still reads. */
|
|
103
|
+
:root[data-palette="sky"] {
|
|
104
|
+
--palette-hue: 200;
|
|
105
|
+
--palette-brand-saturation: 92%;
|
|
106
|
+
--palette-brand-lightness: 34%;
|
|
107
|
+
--palette-dark-brand-saturation: 70%;
|
|
108
|
+
--palette-dark-brand-lightness: 68%;
|
|
109
|
+
}
|
|
110
|
+
:root[data-palette="peach"] {
|
|
111
|
+
--palette-hue: 12;
|
|
112
|
+
--palette-brand-saturation: 78%;
|
|
113
|
+
--palette-brand-lightness: 40%;
|
|
114
|
+
--palette-tint-saturation: 90%;
|
|
115
|
+
--palette-dark-brand-saturation: 76%;
|
|
116
|
+
--palette-dark-brand-lightness: 72%;
|
|
117
|
+
}
|
|
118
|
+
:root[data-palette="sunny"] {
|
|
119
|
+
--palette-hue: 38;
|
|
120
|
+
--palette-brand-saturation: 92%;
|
|
121
|
+
--palette-brand-lightness: 30%;
|
|
122
|
+
--palette-tint-saturation: 92%;
|
|
123
|
+
--palette-tint-lightness: 93.5%;
|
|
124
|
+
--palette-dark-brand-saturation: 82%;
|
|
125
|
+
--palette-dark-brand-lightness: 64%;
|
|
126
|
+
}
|
|
127
|
+
:root[data-palette="mint"] {
|
|
128
|
+
--palette-hue: 162;
|
|
129
|
+
--palette-brand-saturation: 76%;
|
|
130
|
+
--palette-brand-lightness: 27%;
|
|
131
|
+
--palette-tint-saturation: 64%;
|
|
132
|
+
--palette-tint-lightness: 94%;
|
|
133
|
+
--palette-dark-brand-saturation: 56%;
|
|
134
|
+
--palette-dark-brand-lightness: 62%;
|
|
135
|
+
}
|
|
136
|
+
/* Calm palettes. */
|
|
137
|
+
:root[data-palette="forest"] {
|
|
138
|
+
--palette-hue: 158;
|
|
139
|
+
--palette-brand-saturation: 44%;
|
|
140
|
+
--palette-brand-lightness: 32%;
|
|
141
|
+
--palette-tint-saturation: 38%;
|
|
142
|
+
--palette-tint-lightness: 94.5%;
|
|
143
|
+
--palette-dark-brand-saturation: 40%;
|
|
144
|
+
--palette-dark-brand-lightness: 66%;
|
|
145
|
+
--palette-dark-tint-saturation: 24%;
|
|
146
|
+
}
|
|
147
|
+
:root[data-palette="ocean"] {
|
|
148
|
+
--palette-hue: 214;
|
|
149
|
+
}
|
|
150
|
+
:root[data-palette="plum"] {
|
|
151
|
+
--palette-hue: 274;
|
|
152
|
+
--palette-brand-saturation: 36%;
|
|
153
|
+
--palette-brand-lightness: 44%;
|
|
154
|
+
--palette-tint-saturation: 48%;
|
|
155
|
+
--palette-dark-brand-saturation: 44%;
|
|
156
|
+
--palette-dark-brand-lightness: 76%;
|
|
157
|
+
--palette-dark-tint-saturation: 24%;
|
|
158
|
+
}
|
|
159
|
+
:root[data-palette="graphite"] {
|
|
160
|
+
--palette-hue: 0;
|
|
161
|
+
--palette-surface-chroma: 0%;
|
|
162
|
+
--palette-dark-surface-chroma: 0%;
|
|
163
|
+
--palette-ink-chroma: 0%;
|
|
164
|
+
--palette-brand-saturation: 0%;
|
|
165
|
+
--palette-brand-lightness: 24%;
|
|
166
|
+
--palette-tint-saturation: 0%;
|
|
167
|
+
--palette-tint-lightness: 93%;
|
|
168
|
+
--palette-dark-brand-saturation: 0%;
|
|
169
|
+
--palette-dark-brand-lightness: 86%;
|
|
170
|
+
--palette-dark-tint-saturation: 0%;
|
|
171
|
+
--palette-dark-tint-lightness: 20%;
|
|
172
|
+
}
|
|
173
|
+
.dark {
|
|
174
|
+
--surface-chroma: var(--palette-dark-surface-chroma);
|
|
175
|
+
--background: var(--palette-hue) var(--surface-chroma) 5%;
|
|
176
|
+
--foreground: var(--palette-hue) var(--surface-chroma) 94.5%;
|
|
177
|
+
--card: var(--palette-hue) var(--surface-chroma) 8.6%;
|
|
178
|
+
--popover: var(--palette-hue) var(--surface-chroma) 10.5%;
|
|
179
|
+
--primary: var(--palette-hue) var(--palette-dark-brand-saturation) var(--palette-dark-brand-lightness);
|
|
180
|
+
--primary-foreground: var(--palette-hue) 40% 9%;
|
|
181
|
+
--primary-action: var(--palette-hue) var(--palette-dark-tint-saturation) var(--palette-dark-tint-lightness);
|
|
182
|
+
--primary-action-foreground: var(--primary);
|
|
183
|
+
--primary-action-border: var(--palette-hue) var(--palette-dark-tint-saturation) 34%;
|
|
184
|
+
--secondary: var(--palette-hue) var(--surface-chroma) 12.2%;
|
|
185
|
+
--secondary-foreground: var(--foreground);
|
|
186
|
+
--muted-foreground: var(--palette-hue) var(--surface-chroma) 64%;
|
|
187
|
+
--accent: var(--palette-hue) var(--surface-chroma) 15.5%;
|
|
188
|
+
--accent-foreground: var(--foreground);
|
|
189
|
+
--border: var(--palette-hue) var(--surface-chroma) 16%;
|
|
190
|
+
--border-strong: var(--palette-hue) var(--surface-chroma) 22%;
|
|
191
|
+
--input: var(--palette-hue) var(--surface-chroma) 44%;
|
|
192
|
+
--ring: var(--console-brand-text);
|
|
193
|
+
--sidebar: var(--card);
|
|
194
|
+
--sidebar-foreground: var(--palette-hue) var(--surface-chroma) 76%;
|
|
195
|
+
--im-chat-bg: var(--palette-hue) var(--surface-chroma) 6.6%;
|
|
196
|
+
--im-line: var(--border);
|
|
197
|
+
--im-shadow: 0 0% 0%;
|
|
198
|
+
--im-bubble-in: var(--secondary);
|
|
199
|
+
--im-bubble-out: var(--primary-action);
|
|
200
|
+
--im-row-hover: var(--palette-hue) var(--surface-chroma) 12%;
|
|
201
|
+
--destructive: var(--console-signal-danger-text);
|
|
202
|
+
--success: var(--console-signal-success-text);
|
|
203
|
+
--info: var(--console-signal-info-text);
|
|
204
|
+
--warning: var(--console-signal-warning-text);
|
|
205
|
+
--destructive-foreground: 0 0% 10%;
|
|
206
|
+
--success-foreground: 0 0% 10%;
|
|
207
|
+
--info-foreground: 0 0% 10%;
|
|
208
|
+
--warning-foreground: 0 0% 10%;
|
|
209
|
+
--chart-1: var(--console-chart-1);
|
|
210
|
+
--chart-2: var(--console-chart-2);
|
|
211
|
+
--chart-3: var(--console-chart-3);
|
|
212
|
+
--chart-4: var(--console-chart-4);
|
|
213
|
+
--chart-5: var(--console-chart-5);
|
|
214
|
+
--chart-6: var(--console-chart-6);
|
|
215
|
+
--chart-7: var(--console-chart-7);
|
|
216
|
+
--chart-8: var(--console-chart-8);
|
|
217
|
+
--chart-other: var(--console-chart-other);
|
|
218
|
+
color-scheme: dark;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Generates the token artifacts of @zhin.js/console-ui from tokens/tokens.mjs (ADR 0063 D17).
|
|
4
|
+
*
|
|
5
|
+
* node tokens/generate.mjs write client/styles/generated/*
|
|
6
|
+
* node tokens/generate.mjs --check fail when a generated file is out of date (CI, tests)
|
|
7
|
+
*
|
|
8
|
+
* Generated files carry a "do not edit" header; edit tokens/tokens.mjs or tokens/colors.css.
|
|
9
|
+
*/
|
|
10
|
+
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
11
|
+
import { dirname, join, resolve } from 'node:path';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
|
+
import {
|
|
14
|
+
PREFIX,
|
|
15
|
+
baseTierVariables,
|
|
16
|
+
buildScale,
|
|
17
|
+
containerRanges,
|
|
18
|
+
customMedia,
|
|
19
|
+
resolveSemanticValue,
|
|
20
|
+
sizingValues,
|
|
21
|
+
tokens,
|
|
22
|
+
} from './scale.mjs';
|
|
23
|
+
|
|
24
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
25
|
+
const packageRoot = resolve(here, '..');
|
|
26
|
+
export const GENERATED_DIR = join(packageRoot, 'client/styles/generated');
|
|
27
|
+
|
|
28
|
+
const HEADER = (what) => `/*
|
|
29
|
+
* GENERATED by @zhin.js/console-ui tokens/generate.mjs from tokens/tokens.mjs — do not edit.
|
|
30
|
+
* ${what}
|
|
31
|
+
*/
|
|
32
|
+
`;
|
|
33
|
+
|
|
34
|
+
const decl = (name, value, indent = ' ') => `${indent}${name}: ${value};`;
|
|
35
|
+
|
|
36
|
+
/** Aliases (deprecated names) whose target is `name` (without prefix). */
|
|
37
|
+
function aliasesOf(name) {
|
|
38
|
+
const out = Object.entries(tokens.aliases).filter(([, target]) => target === name).map(([alias]) => `${PREFIX}${alias}`);
|
|
39
|
+
out.push(...Object.entries(tokens.bareAliases).filter(([, target]) => target === name).map(([alias]) => alias));
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function semanticDeclarations(size, filter, indent) {
|
|
44
|
+
const lines = [];
|
|
45
|
+
for (const [name, spec] of Object.entries(tokens.semantic)) {
|
|
46
|
+
if (!filter(spec)) continue;
|
|
47
|
+
const value = resolveSemanticValue(spec[size]);
|
|
48
|
+
lines.push(decl(`${PREFIX}${name}`, value, indent));
|
|
49
|
+
for (const alias of aliasesOf(name)) lines.push(decl(alias, `var(${PREFIX}${name})`, indent));
|
|
50
|
+
}
|
|
51
|
+
return lines;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function tokensCss() {
|
|
55
|
+
const colors = readFileSync(join(here, 'colors.css'), 'utf8').trim();
|
|
56
|
+
const base = baseTierVariables();
|
|
57
|
+
const baseLines = [];
|
|
58
|
+
for (const [name, value] of Object.entries(base)) {
|
|
59
|
+
baseLines.push(decl(`${PREFIX}${name}`, value));
|
|
60
|
+
for (const alias of aliasesOf(name)) baseLines.push(decl(alias, `var(${PREFIX}${name})`));
|
|
61
|
+
}
|
|
62
|
+
const darkLines = [
|
|
63
|
+
...Object.entries(tokens.elevation.dark).map(([name, value]) => decl(`${PREFIX}elevation-${name.slice(2)}`, value)),
|
|
64
|
+
...Object.entries(tokens.miscDark).map(([name, value]) => decl(`${PREFIX}${name}`, value)),
|
|
65
|
+
...Object.entries(tokens.color.dark).map(([name, value]) => decl(`${PREFIX}${name}`, value)),
|
|
66
|
+
];
|
|
67
|
+
const viewport = (spec) => spec.scope === 'viewport';
|
|
68
|
+
const container = (spec) => spec.scope !== 'viewport';
|
|
69
|
+
const all = () => true;
|
|
70
|
+
const compositeLines = Object.entries(tokens.composite).map(([name, value]) => decl(`${PREFIX}${name}`, value));
|
|
71
|
+
const { sm, lg } = tokens.breakpoints;
|
|
72
|
+
const ranges = containerRanges();
|
|
73
|
+
const inner = (lines) => lines.map((line) => ` ${line}`).join('\n');
|
|
74
|
+
|
|
75
|
+
return `${HEADER('Three tiers (D16): base scale, semantic tokens, and the semantic value per width.')}
|
|
76
|
+
${colors}
|
|
77
|
+
|
|
78
|
+
/* Tier 1 — base scale. Redeclared on .dark so a dark subtree resolves its own values. */
|
|
79
|
+
@layer base {
|
|
80
|
+
:root, .dark {
|
|
81
|
+
${baseLines.join('\n')}
|
|
82
|
+
}
|
|
83
|
+
.dark {
|
|
84
|
+
${darkLines.join('\n')}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/*
|
|
89
|
+
* Tiers 2 + 3 — semantic tokens per width. Every token gets its viewport value on :root (the
|
|
90
|
+
* outermost container; overlays are portaled there); container-scoped tokens are then set again
|
|
91
|
+
* on the child of each \`.console-cq\` container from that container's width (D18), so a narrow
|
|
92
|
+
* card on a wide screen still gets the narrow values. Children inherit them, so a component can
|
|
93
|
+
* still override a token for its own subtree.
|
|
94
|
+
*/
|
|
95
|
+
@layer base {
|
|
96
|
+
:root, .dark {
|
|
97
|
+
${semanticDeclarations('base', all, ' ').join('\n')}
|
|
98
|
+
${compositeLines.join('\n')}
|
|
99
|
+
}
|
|
100
|
+
@media (min-width: ${sm}) {
|
|
101
|
+
:root, .dark {
|
|
102
|
+
${semanticDeclarations('sm', all, ' ').join('\n')}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
@media (min-width: ${lg}) {
|
|
106
|
+
:root, .dark {
|
|
107
|
+
${semanticDeclarations('lg', all, ' ').join('\n')}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.console-cq {
|
|
112
|
+
container: console / inline-size;
|
|
113
|
+
}
|
|
114
|
+
@container console ${ranges.base} {
|
|
115
|
+
:where(.console-cq) > :where(*) {
|
|
116
|
+
${inner(semanticDeclarations('base', container, ' '))}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
@container console ${ranges.sm} {
|
|
120
|
+
:where(.console-cq) > :where(*) {
|
|
121
|
+
${inner(semanticDeclarations('sm', container, ' '))}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
@container console ${ranges.lg} {
|
|
125
|
+
:where(.console-cq) > :where(*) {
|
|
126
|
+
${inner(semanticDeclarations('lg', container, ' '))}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
`.replace(/\n{3,}/gu, '\n\n');
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const THEME_COLORS = [
|
|
134
|
+
'border', 'input', 'ring', 'background', 'foreground',
|
|
135
|
+
['primary', ['DEFAULT', 'foreground']],
|
|
136
|
+
['primary-action', ['DEFAULT', 'foreground', 'border']],
|
|
137
|
+
['secondary', ['DEFAULT', 'foreground']],
|
|
138
|
+
['destructive', ['DEFAULT', 'foreground']],
|
|
139
|
+
['muted', ['DEFAULT', 'foreground']],
|
|
140
|
+
['accent', ['DEFAULT', 'foreground']],
|
|
141
|
+
['success', ['DEFAULT', 'foreground']],
|
|
142
|
+
['warning', ['DEFAULT', 'foreground']],
|
|
143
|
+
['info', ['DEFAULT', 'foreground']],
|
|
144
|
+
['popover', ['DEFAULT', 'foreground']],
|
|
145
|
+
['card', ['DEFAULT', 'foreground']],
|
|
146
|
+
['selected', ['DEFAULT', 'foreground']],
|
|
147
|
+
['sidebar', ['DEFAULT', 'foreground', 'primary', 'primary-foreground', 'accent', 'accent-foreground', 'border', 'ring']],
|
|
148
|
+
];
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Color roles that do not follow the palette (tokens.color): `bg-brand`, `text-brand-foreground`,
|
|
152
|
+
* `bg-signal-danger-fill`, `text-signal-warning-text`, `fill-chart-1`, …
|
|
153
|
+
*/
|
|
154
|
+
function roleColorLines() {
|
|
155
|
+
return Object.keys(tokens.color.light).map((name) => decl(`--color-${name}`, `hsl(var(${PREFIX}${name}))`, ' '));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function colorLines() {
|
|
159
|
+
const lines = [];
|
|
160
|
+
for (const entry of THEME_COLORS) {
|
|
161
|
+
if (typeof entry === 'string') {
|
|
162
|
+
lines.push(decl(`--color-${entry}`, `hsl(var(--${entry}))`, ' '));
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
const [name, shades] = entry;
|
|
166
|
+
for (const shade of shades) {
|
|
167
|
+
const variable = shade === 'DEFAULT' ? name : `${name}-${shade}`;
|
|
168
|
+
lines.push(decl(`--color-${variable}`, `hsl(var(--${variable}))`, ' '));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return lines;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function themeCss() {
|
|
175
|
+
const lines = [];
|
|
176
|
+
const add = (name, value) => lines.push(decl(name, value, ' '));
|
|
177
|
+
add('--spacing-0', '0rem');
|
|
178
|
+
for (const [name, { tailwind }] of Object.entries(tokens.space)) add(`--spacing-${tailwind}`, `var(${PREFIX}${name})`);
|
|
179
|
+
const sizes = sizingValues();
|
|
180
|
+
for (const namespace of ['width', 'height', 'size', 'min-width', 'max-width', 'inset', 'translate', 'flex-basis']) {
|
|
181
|
+
for (const [key, value] of Object.entries(sizes)) add(`--${namespace}-${key.replace('.', '\\.')}`, value);
|
|
182
|
+
}
|
|
183
|
+
for (const name of Object.keys(tokens.text)) {
|
|
184
|
+
add(`--text-${name}`, `var(${PREFIX}text-${name})`);
|
|
185
|
+
add(`--text-${name}--line-height`, `var(${PREFIX}leading-${name})`);
|
|
186
|
+
}
|
|
187
|
+
for (const name of Object.keys(tokens.weight)) add(`--font-weight-${name}`, `var(${PREFIX}weight-${name})`);
|
|
188
|
+
for (const name of Object.keys(tokens.radius)) add(`--radius-${name.slice(2)}`, `var(${PREFIX}radius-${name.slice(2)})`);
|
|
189
|
+
for (const [name, spec] of Object.entries(tokens.semantic)) {
|
|
190
|
+
if (spec.kind === 'radius') add(`--radius-${name.replace(/-radius$/u, '')}`, `var(${PREFIX}${name})`);
|
|
191
|
+
}
|
|
192
|
+
for (const name of ['1', '2', '3']) add(`--shadow-e${name}`, `var(${PREFIX}elevation-${name})`);
|
|
193
|
+
for (const [name, spec] of Object.entries(tokens.semantic)) {
|
|
194
|
+
if (spec.kind === 'elevation') add(`--shadow-${name.replace(/-elevation$/u, '')}`, `var(${PREFIX}${name})`);
|
|
195
|
+
}
|
|
196
|
+
add('--font-sans', `var(${PREFIX}font-sans)`);
|
|
197
|
+
add('--font-mono', `var(${PREFIX}font-mono)`);
|
|
198
|
+
lines.push(...colorLines(), ...roleColorLines());
|
|
199
|
+
// Every `transition-*` utility uses motion-fast and the one easing curve (zhinjs/console#125).
|
|
200
|
+
add('--default-transition-duration', `var(${PREFIX}motion-fast)`);
|
|
201
|
+
add('--default-transition-timing-function', `var(${PREFIX}ease-out)`);
|
|
202
|
+
add('--animate-accordion-down', `accordion-down var(${PREFIX}motion-base) var(${PREFIX}ease-out)`);
|
|
203
|
+
add('--animate-accordion-up', `accordion-up var(${PREFIX}motion-base) var(${PREFIX}ease-out)`);
|
|
204
|
+
|
|
205
|
+
return `${HEADER('Tailwind 4 theme (D17): only on-scale keys. Import after `@import "tailwindcss"`.')}
|
|
206
|
+
/*
|
|
207
|
+
* Defaults are cleared, then only the scale is offered:
|
|
208
|
+
* p-* / m-* / gap-* / space-* 0, px, 1, 2, 3, 4, 6, 8, 12, 16 (= space-1 … space-8)
|
|
209
|
+
* w / h / size / inset / min / max / translate / basis Tailwind's numeric keys + control, control-compact, touch, badge
|
|
210
|
+
* text-* ${Object.keys(tokens.text).join(', ')}
|
|
211
|
+
* font-* ${Object.keys(tokens.weight).join(', ')}
|
|
212
|
+
* rounded-* 0–4, full + semantic (control, card, badge, popover, dialog, …)
|
|
213
|
+
* shadow-* e1–e3 + semantic (card, card-hover, popover, dialog)
|
|
214
|
+
* breakpoints ${Object.entries(tokens.breakpoints).map(([name, value]) => `${name} ${value}`).join(', ')}
|
|
215
|
+
* Arbitrary values (p-[…]) are not blocked here; the ESLint rules of @zhin.js/console-ui/eslint are.
|
|
216
|
+
*/
|
|
217
|
+
@theme {
|
|
218
|
+
--spacing: initial;
|
|
219
|
+
--spacing-*: initial;
|
|
220
|
+
--text-*: initial;
|
|
221
|
+
--font-weight-*: initial;
|
|
222
|
+
--radius-*: initial;
|
|
223
|
+
--shadow-*: initial;
|
|
224
|
+
--inset-shadow-*: initial;
|
|
225
|
+
--drop-shadow-*: initial;
|
|
226
|
+
--text-shadow-*: initial;
|
|
227
|
+
--breakpoint-*: initial;
|
|
228
|
+
--color-*: initial;
|
|
229
|
+
${Object.entries(tokens.breakpoints).map(([name, value]) => decl(`--breakpoint-${name}`, value, ' ')).join('\n')}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
@theme inline {
|
|
233
|
+
${lines.join('\n')}
|
|
234
|
+
|
|
235
|
+
@keyframes accordion-down {
|
|
236
|
+
from { height: 0; }
|
|
237
|
+
to { height: var(--radix-accordion-content-height); }
|
|
238
|
+
}
|
|
239
|
+
@keyframes accordion-up {
|
|
240
|
+
from { height: var(--radix-accordion-content-height); }
|
|
241
|
+
to { height: 0; }
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
@custom-variant dark (&:where(.dark, .dark *));
|
|
246
|
+
`;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export function customMediaCss() {
|
|
250
|
+
return `${HEADER('Breakpoints for the global shell (D16): `@media (--console-sm)`. Needs postcss-custom-media (or Lightning CSS drafts.customMedia).')}
|
|
251
|
+
${Object.entries(customMedia()).map(([name, query]) => `@custom-media ${name} ${query};`).join('\n')}
|
|
252
|
+
`;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export function scaleJson() {
|
|
256
|
+
return `${JSON.stringify(buildScale(), null, 2)}\n`;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export const OUTPUTS = {
|
|
260
|
+
'tokens.css': tokensCss,
|
|
261
|
+
'theme.css': themeCss,
|
|
262
|
+
'custom-media.css': customMediaCss,
|
|
263
|
+
'scale.json': scaleJson,
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
export function generate({ check = false } = {}) {
|
|
267
|
+
const stale = [];
|
|
268
|
+
mkdirSync(GENERATED_DIR, { recursive: true });
|
|
269
|
+
for (const [file, render] of Object.entries(OUTPUTS)) {
|
|
270
|
+
const path = join(GENERATED_DIR, file);
|
|
271
|
+
const content = render();
|
|
272
|
+
let current = null;
|
|
273
|
+
try { current = readFileSync(path, 'utf8'); } catch { /* missing */ }
|
|
274
|
+
if (current === content) continue;
|
|
275
|
+
if (check) stale.push(file);
|
|
276
|
+
else writeFileSync(path, content);
|
|
277
|
+
}
|
|
278
|
+
return stale;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
282
|
+
const check = process.argv.includes('--check');
|
|
283
|
+
const stale = generate({ check });
|
|
284
|
+
if (stale.length) {
|
|
285
|
+
console.error(`client/styles/generated is out of date (${stale.join(', ')}): run \`node tokens/generate.mjs\` in packages/console/ui.`);
|
|
286
|
+
process.exit(1);
|
|
287
|
+
}
|
|
288
|
+
}
|
package/tokens/scale.mjs
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The allowed-value lists derived from tokens/tokens.mjs (ADR 0063 D17). One derivation shared by
|
|
3
|
+
* the generator (which writes it as scale.json), the stylelint plugin, the ESLint plugin,
|
|
4
|
+
* `zhin plugin check` and the Playwright layout audit, so they can never disagree.
|
|
5
|
+
*
|
|
6
|
+
* Published as `@zhin.js/console-ui/scale` (this module) and `@zhin.js/console-ui/scale.json`.
|
|
7
|
+
*/
|
|
8
|
+
import * as tokens from './tokens.mjs';
|
|
9
|
+
|
|
10
|
+
/** CSS variable prefix of every Console token. */
|
|
11
|
+
export const PREFIX = '--console-';
|
|
12
|
+
|
|
13
|
+
/** Tier-1 short names → CSS variable names (`space-3` → `--console-space-3`). */
|
|
14
|
+
export function tierOneVariable(name) {
|
|
15
|
+
if (/^space-[1-8]$/u.test(name)) return `${PREFIX}${name}`;
|
|
16
|
+
const radius = /^r-(\d|full)$/u.exec(name);
|
|
17
|
+
if (radius) return `${PREFIX}radius-${radius[1]}`;
|
|
18
|
+
const elevation = /^e-(\d)$/u.exec(name);
|
|
19
|
+
if (elevation) return `${PREFIX}elevation-${elevation[1]}`;
|
|
20
|
+
if (name === 'hairline' || name === 'focus') return `${PREFIX}border-${name}`;
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Replaces tier-1 short names inside a semantic value by `var(--console-…)`. */
|
|
25
|
+
export function resolveSemanticValue(value) {
|
|
26
|
+
return value.replace(/\b(?:space-[1-8]|r-(?:\d|full)|e-\d|hairline|focus)\b/gu, (name) => `var(${tierOneVariable(name)})`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const remOf = (key) => (key === '0' ? '0rem' : `${Number(key) * 0.25}rem`);
|
|
30
|
+
|
|
31
|
+
/** Base-tier variables (name → value), light theme. */
|
|
32
|
+
export function baseTierVariables() {
|
|
33
|
+
const out = {};
|
|
34
|
+
for (const [name, { size, leading }] of Object.entries(tokens.text)) {
|
|
35
|
+
out[`text-${name}`] = size;
|
|
36
|
+
out[`leading-${name}`] = leading;
|
|
37
|
+
}
|
|
38
|
+
for (const [name, value] of Object.entries(tokens.weight)) out[`weight-${name}`] = value;
|
|
39
|
+
for (const [name, { value }] of Object.entries(tokens.space)) out[name] = value;
|
|
40
|
+
for (const [name, value] of Object.entries(tokens.radius)) out[`radius-${name.slice(2)}`] = value;
|
|
41
|
+
for (const [name, value] of Object.entries(tokens.border)) out[`border-${name}`] = value;
|
|
42
|
+
for (const [name, value] of Object.entries(tokens.elevation.light)) out[`elevation-${name.slice(2)}`] = value;
|
|
43
|
+
for (const [name, value] of Object.entries(tokens.breakpoints)) out[`bp-${name}`] = value;
|
|
44
|
+
for (const [name, value] of Object.entries(tokens.contentWidth)) out[`content-${name}`] = value;
|
|
45
|
+
out['touch-target'] = tokens.touchTarget;
|
|
46
|
+
Object.assign(out, tokens.misc, tokens.motion, tokens.color.light, tokens.deprecated);
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Media query params allowed in the shell (D16, D20): the breakpoints, both directions, plus user preferences. */
|
|
51
|
+
export function allowedMediaParams() {
|
|
52
|
+
const params = [];
|
|
53
|
+
for (const value of Object.values(tokens.breakpoints)) {
|
|
54
|
+
params.push(`(min-width: ${value})`, `(width >= ${value})`, `(width < ${value})`);
|
|
55
|
+
}
|
|
56
|
+
params.push(
|
|
57
|
+
'(prefers-reduced-motion: reduce)',
|
|
58
|
+
'(prefers-reduced-motion: no-preference)',
|
|
59
|
+
'(prefers-color-scheme: dark)',
|
|
60
|
+
'(prefers-color-scheme: light)',
|
|
61
|
+
'(prefers-contrast: more)',
|
|
62
|
+
'(forced-colors: active)',
|
|
63
|
+
'(hover: hover)',
|
|
64
|
+
'(pointer: coarse)',
|
|
65
|
+
'print',
|
|
66
|
+
);
|
|
67
|
+
return params;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** `@custom-media` names generated for the shell. */
|
|
71
|
+
export function customMedia() {
|
|
72
|
+
const out = {};
|
|
73
|
+
for (const [name, value] of Object.entries(tokens.breakpoints)) {
|
|
74
|
+
out[`--console-${name}`] = `(min-width: ${value})`;
|
|
75
|
+
out[`--console-below-${name}`] = `(width < ${value})`;
|
|
76
|
+
}
|
|
77
|
+
return out;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Container query ranges used by the generated by-size rules. */
|
|
81
|
+
export function containerRanges() {
|
|
82
|
+
const { sm, lg } = tokens.breakpoints;
|
|
83
|
+
return {
|
|
84
|
+
base: `(width < ${sm})`,
|
|
85
|
+
sm: `(${sm} <= width < ${lg})`,
|
|
86
|
+
lg: `(width >= ${lg})`,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function buildScale() {
|
|
91
|
+
const semanticNames = Object.keys(tokens.semantic);
|
|
92
|
+
const radiusSemantic = semanticNames.filter((name) => tokens.semantic[name].kind === 'radius');
|
|
93
|
+
const elevationSemantic = semanticNames.filter((name) => tokens.semantic[name].kind === 'elevation');
|
|
94
|
+
return {
|
|
95
|
+
$comment: 'Generated from @zhin.js/console-ui tokens/tokens.mjs by tokens/generate.mjs (ADR 0063 D17). Do not edit.',
|
|
96
|
+
breakpoints: tokens.breakpoints,
|
|
97
|
+
text: Object.fromEntries(Object.entries(tokens.text).map(([name, { size }]) => [name, size])),
|
|
98
|
+
weight: tokens.weight,
|
|
99
|
+
space: tokens.space,
|
|
100
|
+
radius: tokens.radius,
|
|
101
|
+
border: tokens.border,
|
|
102
|
+
elevation: Object.keys(tokens.elevation.light),
|
|
103
|
+
contentWidth: tokens.contentWidth,
|
|
104
|
+
touchTarget: tokens.touchTarget,
|
|
105
|
+
semantic: tokens.semantic,
|
|
106
|
+
tailwind: {
|
|
107
|
+
/** `p-*`, `m-*`, `gap-*`, `space-*`: only these keys (D17). */
|
|
108
|
+
spacingKeys: ['0', 'px', ...Object.values(tokens.space).map((entry) => entry.tailwind)],
|
|
109
|
+
/** `w-*`, `h-*`, `size-*`, `inset-*`, `min-*`, `max-*`, `translate-*`, `basis-*`. */
|
|
110
|
+
sizingKeys: [...tokens.sizingKeys, ...Object.keys(tokens.semanticSizes)],
|
|
111
|
+
radiusKeys: ['none', '0', '1', '2', '3', '4', 'full', ...radiusSemantic.map((name) => name.replace(/-radius$/u, ''))],
|
|
112
|
+
shadowKeys: ['none', 'e1', 'e2', 'e3', ...elevationSemantic.map((name) => name.replace(/-elevation$/u, ''))],
|
|
113
|
+
textKeys: Object.keys(tokens.text),
|
|
114
|
+
fontWeightKeys: Object.keys(tokens.weight),
|
|
115
|
+
breakpointKeys: Object.keys(tokens.breakpoints),
|
|
116
|
+
borderWidthKeys: ['0', 'px', 'hairline', 'focus'],
|
|
117
|
+
},
|
|
118
|
+
css: {
|
|
119
|
+
baseTokens: Object.keys(baseTierVariables()).map((name) => `${PREFIX}${name}`),
|
|
120
|
+
semanticTokens: [...semanticNames, ...Object.keys(tokens.composite)].map((name) => `${PREFIX}${name}`),
|
|
121
|
+
aliasTokens: [...Object.keys(tokens.aliases).map((name) => `${PREFIX}${name}`), ...Object.keys(tokens.bareAliases)],
|
|
122
|
+
customMedia: customMedia(),
|
|
123
|
+
mediaParams: allowedMediaParams(),
|
|
124
|
+
containerParams: [...new Set([...Object.values(containerRanges()), ...Object.values(tokens.breakpoints).flatMap((value) => [`(min-width: ${value})`, `(width >= ${value})`, `(width < ${value})`])])],
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Sizing key → value for the Tailwind theme. */
|
|
130
|
+
export function sizingValues() {
|
|
131
|
+
return Object.fromEntries([
|
|
132
|
+
...tokens.sizingKeys.map((key) => [key, remOf(key)]),
|
|
133
|
+
...Object.entries(tokens.semanticSizes),
|
|
134
|
+
]);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export { tokens };
|