@weasel-js/theme 1.5.2 → 1.6.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/README.md +39 -1
- package/dist/{chunk-XFCWYN2L.js → chunk-4EIPTWJA.js} +914 -60
- package/dist/chunk-4EIPTWJA.js.map +1 -0
- package/dist/chunk-C3S4A65R.js +557 -0
- package/dist/chunk-C3S4A65R.js.map +1 -0
- package/dist/chunk-EINHFDWI.js +12 -0
- package/dist/chunk-EINHFDWI.js.map +1 -0
- package/dist/colorMode-CoklZomJ.d.ts +12 -0
- package/dist/{resolveTheme-CF8i5IHy.d.ts → definition-DLdTdFWs.d.ts} +584 -51
- package/dist/engine.d.ts +76 -8
- package/dist/engine.js +183 -427
- package/dist/engine.js.map +1 -1
- package/dist/faces.css +19 -0
- package/dist/fonts.css +4 -18
- package/dist/index.d.ts +49 -5
- package/dist/index.js +172 -20
- package/dist/index.js.map +1 -1
- package/dist/react.d.ts +50 -6
- package/dist/react.js +68 -6
- package/dist/react.js.map +1 -1
- package/dist/tokens.css +103 -1
- package/fonts/README.md +5 -6
- package/package.json +4 -3
- package/dist/chunk-LL2ERJPZ.js +0 -175
- package/dist/chunk-LL2ERJPZ.js.map +0 -1
- package/dist/chunk-PJMTWM34.js +0 -6
- package/dist/chunk-PJMTWM34.js.map +0 -1
- package/dist/chunk-XFCWYN2L.js.map +0 -1
- package/dist/theme-DAZcQi_L.d.ts +0 -191
package/dist/tokens.css
CHANGED
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
/* Midnight blue-violet. Deep and saturated; anchors primary actions on light and dark surfaces alike. */
|
|
19
19
|
--wzl-accent-base: #2e1f7a;
|
|
20
20
|
--wzl-accent-strong: #5841b8;
|
|
21
|
+
--wzl-secondary-soft: #704e09;
|
|
22
|
+
--wzl-secondary-base: #dc9d15;
|
|
23
|
+
--wzl-secondary-strong: #f1cb8d;
|
|
21
24
|
/* First of ten categorical spot colors for plotting, status and data viz. Take them in sequence: the order is farthest-point over hue, so the first N are as separated as N colors can be (first three 87° apart, all ten 32°). Mode-invariant on purpose — a series keeps its color when the mode flips, which is why they are tuned for a dark surface and clear only 1.5:1 on a light one. */
|
|
22
25
|
--wzl-swatch-fuchsia: #f641f7;
|
|
23
26
|
--wzl-swatch-green: #48e628;
|
|
@@ -60,10 +63,55 @@
|
|
|
60
63
|
--wzl-border-strong: var(--wzl-gray-400);
|
|
61
64
|
/* Accent for foreground use — text, icons, selected labels drawn on a surface. accent is a fill; the midnight base is too dim to read as text on dark surfaces. */
|
|
62
65
|
--wzl-accent-fg: var(--wzl-accent-strong);
|
|
66
|
+
/* Secondary accent for foreground use: a second voice beside the accent, such as a value the panel derived rather than one the user set. Picked from the ramp so it clears 4.5:1 on the surface in both modes. */
|
|
67
|
+
--wzl-secondary-fg: var(--wzl-secondary-base);
|
|
63
68
|
/* Text drawn on a filled foreground-colored element (e.g. a slider thumb). Flips with the mode, so it is a semantic, not an alias to a primitive. */
|
|
64
69
|
--wzl-fg-inverse: var(--wzl-gray-900);
|
|
65
70
|
/* Elevation. Always darker than any surface — never derived from fg, which is near-white on dark. */
|
|
66
71
|
--wzl-shadow: rgba(0, 0, 0, 0.6);
|
|
72
|
+
/* Fill of a PropertyPanel. */
|
|
73
|
+
--wzl-panel-surface: var(--wzl-surface-raised);
|
|
74
|
+
--wzl-panel-border-color: var(--wzl-border);
|
|
75
|
+
--wzl-panel-border-style: solid;
|
|
76
|
+
--wzl-panel-border-width: 1px;
|
|
77
|
+
--wzl-panel-radius: var(--wzl-radius-lg);
|
|
78
|
+
/* A panel’s padding when no density sets one. */
|
|
79
|
+
--wzl-panel-pad: 14px 16px;
|
|
80
|
+
--wzl-panel-blur: var(--wzl-glass-blur);
|
|
81
|
+
/* How much of a panel’s tone mixes into its surface. */
|
|
82
|
+
--wzl-panel-tone-mix: 14%;
|
|
83
|
+
--wzl-panel-title-font: var(--wzl-font-display);
|
|
84
|
+
--wzl-panel-title-weight: var(--wzl-font-weight-light);
|
|
85
|
+
--wzl-panel-title-size: var(--wzl-font-size-lg);
|
|
86
|
+
--wzl-panel-title-case: none;
|
|
87
|
+
--wzl-panel-title-tracking: 0.01em;
|
|
88
|
+
--wzl-panel-title-color: var(--wzl-fg);
|
|
89
|
+
--wzl-panel-title-inset: 0;
|
|
90
|
+
--wzl-stance-scope-border-width: 0;
|
|
91
|
+
--wzl-stance-scope-radius: 8px;
|
|
92
|
+
--wzl-stance-scope-tone-mix: 22%;
|
|
93
|
+
--wzl-stance-scope-nested-radius: 6px;
|
|
94
|
+
/* A scope panel inside another sits back into it. */
|
|
95
|
+
--wzl-stance-scope-nested-surface: var(--wzl-surface);
|
|
96
|
+
--wzl-stance-aside-surface: transparent;
|
|
97
|
+
--wzl-stance-aside-border-color: var(--wzl-line-subtle);
|
|
98
|
+
--wzl-stance-aside-blur: 0px;
|
|
99
|
+
--wzl-stance-aside-title-color: var(--wzl-fg-subtle);
|
|
100
|
+
--wzl-stance-advanced-title-color: var(--wzl-fg-subtle);
|
|
101
|
+
--wzl-stance-debug-border-style: dashed;
|
|
102
|
+
--wzl-stance-debug-title-font: var(--wzl-font-mono);
|
|
103
|
+
--wzl-stance-debug-title-case: none;
|
|
104
|
+
--wzl-stance-danger-tone: var(--wzl-danger);
|
|
105
|
+
--wzl-stance-danger-border-color: var(--wzl-danger);
|
|
106
|
+
--wzl-stance-danger-title-color: var(--wzl-danger);
|
|
107
|
+
--wzl-stance-notice-tone: var(--wzl-accent);
|
|
108
|
+
--wzl-stance-notice-tone-mix: 8%;
|
|
109
|
+
--wzl-stance-important-border-color: var(--wzl-accent-fg);
|
|
110
|
+
--wzl-stance-important-title-color: var(--wzl-accent-fg);
|
|
111
|
+
--wzl-stance-preview-pad: 0;
|
|
112
|
+
--wzl-stance-preview-title-size: var(--wzl-font-size-xs);
|
|
113
|
+
--wzl-stance-preview-title-case: none;
|
|
114
|
+
--wzl-stance-preview-title-inset: 6px 10px 0;
|
|
67
115
|
--wzl-danger-base: #d94a3f;
|
|
68
116
|
--wzl-warning-base: #d99a3f;
|
|
69
117
|
--wzl-success-base: #2ec27e;
|
|
@@ -78,6 +126,8 @@
|
|
|
78
126
|
--wzl-curve-color: var(--wzl-accent-strong);
|
|
79
127
|
--wzl-accent: var(--wzl-accent-base);
|
|
80
128
|
--wzl-accent-hover: var(--wzl-accent-strong);
|
|
129
|
+
/* Honey amber in dark mode and teal in light, where a darkened amber reads as brown. A fill; use secondary-fg for text. */
|
|
130
|
+
--wzl-secondary: var(--wzl-secondary-base);
|
|
81
131
|
--wzl-danger: var(--wzl-danger-base);
|
|
82
132
|
--wzl-warning: var(--wzl-warning-base);
|
|
83
133
|
--wzl-success: var(--wzl-success-base);
|
|
@@ -98,7 +148,7 @@
|
|
|
98
148
|
--wzl-line-width: 2px;
|
|
99
149
|
/* Drawn data curves. Heavier than structural lines so data reads as primary content. */
|
|
100
150
|
--wzl-curve-width: 3px;
|
|
101
|
-
/* Height of a horizontal toolbar strip (
|
|
151
|
+
/* Height of a horizontal toolbar strip (ButtonBar, OptionsBar, ToolOptionsBar). Taller than control-h so the controls inside a strip are not flush with its edges. */
|
|
102
152
|
--wzl-tb-height: 28px;
|
|
103
153
|
/* Height of the smallest interactive control -- a stepper, a keycap, a swatch button in a dense row. The rank below control-h-sm. */
|
|
104
154
|
--wzl-control-h-xs: 18px;
|
|
@@ -122,6 +172,16 @@
|
|
|
122
172
|
--wzl-handle-size-sm: 7px;
|
|
123
173
|
/* A handle that is a category of its own rather than one of a row — a curve's endpoint. Larger so it separates from the handles it sits in line with. */
|
|
124
174
|
--wzl-handle-size-lg: 10px;
|
|
175
|
+
/* One square of the transparency checker drawn under a paint that is empty, mixed or translucent. Paint it as repeating-conic-gradient(var(--wzl-checker-a) 0% 25%, var(--wzl-checker-b) 0% 50%) 50% / var(--wzl-checker-size) var(--wzl-checker-size). */
|
|
176
|
+
--wzl-checker-a: var(--wzl-border);
|
|
177
|
+
/* The other square of the transparency checker. */
|
|
178
|
+
--wzl-checker-b: var(--wzl-surface);
|
|
179
|
+
/* Edge of one repeat of the transparency checker: two squares by two. */
|
|
180
|
+
--wzl-checker-size: 8px;
|
|
181
|
+
/* Ground of a canvas app's workspace — the area around the document page. */
|
|
182
|
+
--wzl-workspace-surface: var(--wzl-surface-sunken);
|
|
183
|
+
/* Marks drawn over workspace-surface, such as its diagonal stripes, so the page reads as the thing on top. */
|
|
184
|
+
--wzl-workspace-line: var(--wzl-line-subtle);
|
|
125
185
|
/* Horizontal padding inside a boxed field. Pairs with --wzl-field-h, which is a container override and has no :root default. */
|
|
126
186
|
--wzl-field-pad-x: 8px;
|
|
127
187
|
/* Backdrop blur radius for frosted surfaces. Pairs with glass-tint. */
|
|
@@ -174,6 +234,9 @@
|
|
|
174
234
|
[data-wzl-theme='weasel'][data-wzl-mode='dark'],
|
|
175
235
|
[data-wzl-mode='dark'] {
|
|
176
236
|
color-scheme: dark;
|
|
237
|
+
--wzl-secondary-soft: #704e09;
|
|
238
|
+
--wzl-secondary-base: #dc9d15;
|
|
239
|
+
--wzl-secondary-strong: #f1cb8d;
|
|
177
240
|
--wzl-surface: var(--wzl-gray-800);
|
|
178
241
|
--wzl-surface-raised: var(--wzl-gray-700);
|
|
179
242
|
--wzl-surface-sunken: var(--wzl-gray-900);
|
|
@@ -185,16 +248,34 @@
|
|
|
185
248
|
--wzl-accent-fg: var(--wzl-accent-strong);
|
|
186
249
|
--wzl-fg-inverse: var(--wzl-gray-900);
|
|
187
250
|
--wzl-shadow: rgba(0, 0, 0, 0.6);
|
|
251
|
+
--wzl-secondary-fg: var(--wzl-secondary-base);
|
|
252
|
+
--wzl-panel-surface: var(--wzl-surface-raised);
|
|
253
|
+
--wzl-panel-border-color: var(--wzl-border);
|
|
254
|
+
--wzl-panel-title-color: var(--wzl-fg);
|
|
255
|
+
--wzl-stance-scope-nested-surface: var(--wzl-surface);
|
|
256
|
+
--wzl-stance-aside-border-color: var(--wzl-line-subtle);
|
|
257
|
+
--wzl-stance-aside-title-color: var(--wzl-fg-subtle);
|
|
258
|
+
--wzl-stance-advanced-title-color: var(--wzl-fg-subtle);
|
|
259
|
+
--wzl-stance-important-border-color: var(--wzl-accent-fg);
|
|
260
|
+
--wzl-stance-important-title-color: var(--wzl-accent-fg);
|
|
188
261
|
--wzl-line-subtle: color-mix(in srgb, var(--wzl-fg) 10%, transparent);
|
|
189
262
|
--wzl-line: color-mix(in srgb, var(--wzl-fg) 20%, transparent);
|
|
190
263
|
--wzl-line-strong: color-mix(in srgb, var(--wzl-fg) 40%, transparent);
|
|
264
|
+
--wzl-secondary: var(--wzl-secondary-base);
|
|
191
265
|
--wzl-surface-hover: color-mix(in srgb, var(--wzl-fg) 10%, transparent);
|
|
192
266
|
--wzl-surface-pressed: color-mix(in srgb, var(--wzl-fg) 18%, transparent);
|
|
267
|
+
--wzl-checker-a: var(--wzl-border);
|
|
268
|
+
--wzl-checker-b: var(--wzl-surface);
|
|
269
|
+
--wzl-workspace-surface: var(--wzl-surface-sunken);
|
|
270
|
+
--wzl-workspace-line: var(--wzl-line-subtle);
|
|
193
271
|
}
|
|
194
272
|
|
|
195
273
|
[data-wzl-theme='weasel'][data-wzl-mode='light'],
|
|
196
274
|
[data-wzl-mode='light'] {
|
|
197
275
|
color-scheme: light;
|
|
276
|
+
--wzl-secondary-soft: #016458;
|
|
277
|
+
--wzl-secondary-base: #3ee1cb;
|
|
278
|
+
--wzl-secondary-strong: #94e3d5;
|
|
198
279
|
--wzl-surface: var(--wzl-gray-50);
|
|
199
280
|
--wzl-surface-raised: var(--wzl-gray-100);
|
|
200
281
|
--wzl-surface-sunken: var(--wzl-gray-200);
|
|
@@ -206,11 +287,26 @@
|
|
|
206
287
|
--wzl-accent-fg: var(--wzl-accent-base);
|
|
207
288
|
--wzl-fg-inverse: var(--wzl-gray-50);
|
|
208
289
|
--wzl-shadow: rgba(0, 0, 0, 0.18);
|
|
290
|
+
--wzl-secondary-fg: var(--wzl-secondary-soft);
|
|
291
|
+
--wzl-panel-surface: var(--wzl-surface-raised);
|
|
292
|
+
--wzl-panel-border-color: var(--wzl-border);
|
|
293
|
+
--wzl-panel-title-color: var(--wzl-fg);
|
|
294
|
+
--wzl-stance-scope-nested-surface: var(--wzl-surface);
|
|
295
|
+
--wzl-stance-aside-border-color: var(--wzl-line-subtle);
|
|
296
|
+
--wzl-stance-aside-title-color: var(--wzl-fg-subtle);
|
|
297
|
+
--wzl-stance-advanced-title-color: var(--wzl-fg-subtle);
|
|
298
|
+
--wzl-stance-important-border-color: var(--wzl-accent-fg);
|
|
299
|
+
--wzl-stance-important-title-color: var(--wzl-accent-fg);
|
|
209
300
|
--wzl-line-subtle: color-mix(in srgb, var(--wzl-fg) 10%, transparent);
|
|
210
301
|
--wzl-line: color-mix(in srgb, var(--wzl-fg) 20%, transparent);
|
|
211
302
|
--wzl-line-strong: color-mix(in srgb, var(--wzl-fg) 40%, transparent);
|
|
303
|
+
--wzl-secondary: var(--wzl-secondary-base);
|
|
212
304
|
--wzl-surface-hover: color-mix(in srgb, var(--wzl-fg) 10%, transparent);
|
|
213
305
|
--wzl-surface-pressed: color-mix(in srgb, var(--wzl-fg) 18%, transparent);
|
|
306
|
+
--wzl-checker-a: var(--wzl-border);
|
|
307
|
+
--wzl-checker-b: var(--wzl-surface);
|
|
308
|
+
--wzl-workspace-surface: var(--wzl-surface-sunken);
|
|
309
|
+
--wzl-workspace-line: var(--wzl-line-subtle);
|
|
214
310
|
}
|
|
215
311
|
|
|
216
312
|
[data-wzl-theme='weasel'][data-wzl-density='compact'],
|
|
@@ -226,6 +322,8 @@
|
|
|
226
322
|
--wzl-control-h-sm: 18px;
|
|
227
323
|
--wzl-control-h: 20px;
|
|
228
324
|
--wzl-icon-button-size: 20px;
|
|
325
|
+
--wzl-panel-title-size: var(--wzl-font-size-lg);
|
|
326
|
+
--wzl-stance-preview-title-size: var(--wzl-font-size-xs);
|
|
229
327
|
--wzl-font-size: var(--wzl-font-size-md);
|
|
230
328
|
}
|
|
231
329
|
|
|
@@ -242,6 +340,8 @@
|
|
|
242
340
|
--wzl-control-h-sm: 20px;
|
|
243
341
|
--wzl-control-h: 24px;
|
|
244
342
|
--wzl-icon-button-size: 22px;
|
|
343
|
+
--wzl-panel-title-size: var(--wzl-font-size-lg);
|
|
344
|
+
--wzl-stance-preview-title-size: var(--wzl-font-size-xs);
|
|
245
345
|
--wzl-font-size: var(--wzl-font-size-md);
|
|
246
346
|
}
|
|
247
347
|
|
|
@@ -258,5 +358,7 @@
|
|
|
258
358
|
--wzl-control-h-sm: 24px;
|
|
259
359
|
--wzl-control-h: 28px;
|
|
260
360
|
--wzl-icon-button-size: 26px;
|
|
361
|
+
--wzl-panel-title-size: var(--wzl-font-size-lg);
|
|
362
|
+
--wzl-stance-preview-title-size: var(--wzl-font-size-xs);
|
|
261
363
|
--wzl-font-size: var(--wzl-font-size-md);
|
|
262
364
|
}
|
package/fonts/README.md
CHANGED
|
@@ -8,11 +8,11 @@ third-party host at runtime.
|
|
|
8
8
|
| `oswald-latin-variable.woff2` | `--wzl-font-ui`, `--wzl-font-display` | condensed UI/display face, variable `wght 200–700` |
|
|
9
9
|
| `inter-latin.woff2` | `--wzl-font-body` | body/prose face, weight 400 |
|
|
10
10
|
|
|
11
|
-
Loading them is opt-in: `import '@weasel-js/theme/fonts.css'
|
|
12
|
-
|
|
11
|
+
Loading them is opt-in: `import '@weasel-js/theme/fonts.css'`, or
|
|
12
|
+
`faces.css` for the `@font-face` rules without the `:root` font. Skip both and
|
|
13
|
+
the token font stacks fall back to `system-ui`.
|
|
13
14
|
|
|
14
|
-
**Not opt-in through labkit.** `@weasel-js/labkit` concatenates
|
|
15
|
-
`@font-face` rules into its one `dist/styles.css` and copies both `.woff2`
|
|
15
|
+
**Not opt-in through labkit.** `@weasel-js/labkit` concatenates `faces.css` into its one `dist/styles.css` and copies both `.woff2`
|
|
16
16
|
files to `dist/fonts/`, so a lab renders in them without importing anything
|
|
17
17
|
here. Renaming or dropping a face changes what a consumer's text looks like
|
|
18
18
|
with no error anywhere.
|
|
@@ -32,8 +32,7 @@ python3 -m venv /tmp/fontvenv
|
|
|
32
32
|
|
|
33
33
|
Upstream `fonts/variable/Oswald[wght].ttf` from
|
|
34
34
|
https://github.com/googlefonts/OswaldFont, subset to the Google Fonts `latin`
|
|
35
|
-
range plus
|
|
36
|
-
(`U+0304`, `U+0308`, `U+0329`):
|
|
35
|
+
range plus three combining marks (`U+0304`, `U+0308`, `U+0329`):
|
|
37
36
|
|
|
38
37
|
```sh
|
|
39
38
|
/tmp/fontvenv/bin/pyftsubset "Oswald[wght].ttf" \
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weasel-js/theme",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "Design tokens shared by weasel-ui and weasel-hud — CSS variables + a parallel TS export.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -25,10 +25,11 @@
|
|
|
25
25
|
},
|
|
26
26
|
"./tokens.css": "./dist/tokens.css",
|
|
27
27
|
"./fonts.css": "./dist/fonts.css",
|
|
28
|
+
"./faces.css": "./dist/faces.css",
|
|
28
29
|
"./package.json": "./package.json"
|
|
29
30
|
},
|
|
30
31
|
"dependencies": {
|
|
31
|
-
"@weasel-js/paint": "1.
|
|
32
|
+
"@weasel-js/paint": "1.6.1"
|
|
32
33
|
},
|
|
33
34
|
"peerDependencies": {
|
|
34
35
|
"react": ">=18"
|
|
@@ -60,7 +61,7 @@
|
|
|
60
61
|
],
|
|
61
62
|
"scripts": {
|
|
62
63
|
"gen:tokens": "tsx scripts/build-tokens.ts",
|
|
63
|
-
"build": "npm run gen:tokens && tsup && cp src/generated/tokens.css dist/tokens.css && cp src/fonts.css
|
|
64
|
+
"build": "npm run gen:tokens && tsup && cp src/generated/tokens.css dist/tokens.css && cp src/fonts.css src/faces.css dist/"
|
|
64
65
|
},
|
|
65
66
|
"publishConfig": {
|
|
66
67
|
"access": "public",
|
package/dist/chunk-LL2ERJPZ.js
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
// src/axes.ts
|
|
2
|
-
function isByAxis(v) {
|
|
3
|
-
return typeof v === "object" && v !== null && !Array.isArray(v) && typeof v.by === "string";
|
|
4
|
-
}
|
|
5
|
-
function fullSelection(axes, selection = {}) {
|
|
6
|
-
const out = {};
|
|
7
|
-
for (const [name, def] of Object.entries(axes)) {
|
|
8
|
-
const v = selection[name];
|
|
9
|
-
out[name] = v !== void 0 && v in def.values ? v : def.default;
|
|
10
|
-
}
|
|
11
|
-
return out;
|
|
12
|
-
}
|
|
13
|
-
function mergeAxes(parent, child) {
|
|
14
|
-
const out = { ...parent };
|
|
15
|
-
for (const [name, def] of Object.entries(child)) {
|
|
16
|
-
out[name] = { ...def, values: { ...parent[name]?.values, ...def.values } };
|
|
17
|
-
}
|
|
18
|
-
return out;
|
|
19
|
-
}
|
|
20
|
-
function enumerateSelections(axes) {
|
|
21
|
-
let out = [{}];
|
|
22
|
-
for (const [name, def] of Object.entries(axes)) {
|
|
23
|
-
out = out.flatMap((s) => Object.keys(def.values).map((v) => ({ ...s, [name]: v })));
|
|
24
|
-
}
|
|
25
|
-
return out;
|
|
26
|
-
}
|
|
27
|
-
function selectionKey(axes, selection) {
|
|
28
|
-
const full = fullSelection(axes, selection);
|
|
29
|
-
return Object.keys(axes).map((a) => `${a}=${full[a]}`).join(",");
|
|
30
|
-
}
|
|
31
|
-
function pick(v, selection) {
|
|
32
|
-
let cur = v;
|
|
33
|
-
while (isByAxis(cur)) {
|
|
34
|
-
const axis = cur.by;
|
|
35
|
-
const value = selection[axis];
|
|
36
|
-
if (value === void 0 || value === "by" || !(value in cur)) return { ok: false, axis, value: value ?? "" };
|
|
37
|
-
cur = cur[value];
|
|
38
|
-
}
|
|
39
|
-
return { ok: true, value: cur };
|
|
40
|
-
}
|
|
41
|
-
function pickAll(record, selection) {
|
|
42
|
-
const out = {};
|
|
43
|
-
for (const [name, v] of Object.entries(record)) {
|
|
44
|
-
const picked = pick(v, selection);
|
|
45
|
-
if (picked.ok) out[name] = picked.value;
|
|
46
|
-
}
|
|
47
|
-
return out;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// src/dtcg/value.ts
|
|
51
|
-
function fontStack(value) {
|
|
52
|
-
return value.map((f) => typeof f === "string" && /\s/.test(f) ? `'${f}'` : String(f)).join(", ");
|
|
53
|
-
}
|
|
54
|
-
function serializeTokenValue(type, value) {
|
|
55
|
-
if (Array.isArray(value)) {
|
|
56
|
-
if (type === "cubicBezier") return `cubic-bezier(${value.join(", ")})`;
|
|
57
|
-
if (type === "fontFamily") return fontStack(value);
|
|
58
|
-
return value.join(", ");
|
|
59
|
-
}
|
|
60
|
-
return String(value);
|
|
61
|
-
}
|
|
62
|
-
var BEZIER = /^cubic-bezier\(\s*([^)]*)\)$/i;
|
|
63
|
-
function parseTokenValue(type, text) {
|
|
64
|
-
const raw = text.trim();
|
|
65
|
-
if (type === "cubicBezier") {
|
|
66
|
-
const inner = BEZIER.exec(raw)?.[1] ?? raw;
|
|
67
|
-
const parts = inner.split(",").map((p) => Number(p.trim()));
|
|
68
|
-
return parts.length === 4 && parts.every((n) => Number.isFinite(n)) ? parts : raw;
|
|
69
|
-
}
|
|
70
|
-
if (type === "fontFamily") {
|
|
71
|
-
const families = raw.split(",").map((f) => f.trim().replace(/^['"]|['"]$/g, "").trim()).filter((f) => f !== "");
|
|
72
|
-
return families.length > 0 ? families : raw;
|
|
73
|
-
}
|
|
74
|
-
return raw;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// src/dtcg/color.ts
|
|
78
|
-
function withAlpha(color, alpha) {
|
|
79
|
-
const rgba = parseRgba(color.trim());
|
|
80
|
-
if (!rgba) return `color-mix(in srgb, ${color.trim()} ${round(alpha * 100, 4)}%, transparent)`;
|
|
81
|
-
const [r, g, b, a] = rgba;
|
|
82
|
-
return `rgba(${r}, ${g}, ${b}, ${round(a * alpha, 3)})`;
|
|
83
|
-
}
|
|
84
|
-
function round(n, places) {
|
|
85
|
-
return Number(n.toFixed(places));
|
|
86
|
-
}
|
|
87
|
-
function parseRgba(s) {
|
|
88
|
-
if (s.toLowerCase() === "transparent") return [0, 0, 0, 0];
|
|
89
|
-
return parseHex(s) ?? parseRgbFn(s);
|
|
90
|
-
}
|
|
91
|
-
function parseHex(s) {
|
|
92
|
-
const m = /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(s);
|
|
93
|
-
if (!m) return null;
|
|
94
|
-
const body = m[1];
|
|
95
|
-
const full = body.length <= 4 ? body.replace(/./g, (c) => c + c) : body;
|
|
96
|
-
const byte = (i) => Number.parseInt(full.slice(i, i + 2), 16);
|
|
97
|
-
return [byte(0), byte(2), byte(4), full.length === 8 ? byte(6) / 255 : 1];
|
|
98
|
-
}
|
|
99
|
-
function parseRgbFn(s) {
|
|
100
|
-
const m = /^rgba?\(([^()]*)\)$/i.exec(s);
|
|
101
|
-
if (!m) return null;
|
|
102
|
-
const [channels, alphaPart, extra] = m[1].split("/");
|
|
103
|
-
if (extra !== void 0) return null;
|
|
104
|
-
const parts = channels.trim().split(/\s*,\s*|\s+/);
|
|
105
|
-
if (alphaPart !== void 0) parts.push(alphaPart.trim());
|
|
106
|
-
if (parts.length !== 3 && parts.length !== 4) return null;
|
|
107
|
-
const channel = (p) => p.endsWith("%") ? Number.parseFloat(p) / 100 * 255 : Number(p);
|
|
108
|
-
const alpha = (p) => p.endsWith("%") ? Number.parseFloat(p) / 100 : Number(p);
|
|
109
|
-
const [r, g, b] = parts.slice(0, 3).map(channel);
|
|
110
|
-
const a = parts[3] === void 0 ? 1 : alpha(parts[3]);
|
|
111
|
-
if (![r, g, b, a].every(Number.isFinite)) return null;
|
|
112
|
-
return [Math.round(r), Math.round(g), Math.round(b), a];
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// src/dtcg/resolve.ts
|
|
116
|
-
var REF = /^\{([^}]+)\}$/;
|
|
117
|
-
function refTarget(value) {
|
|
118
|
-
if (typeof value !== "string") return null;
|
|
119
|
-
const m = REF.exec(value.trim());
|
|
120
|
-
if (!m) return null;
|
|
121
|
-
const path = m[1];
|
|
122
|
-
const dot = path.indexOf(".");
|
|
123
|
-
return dot === -1 ? path : path.slice(dot + 1);
|
|
124
|
-
}
|
|
125
|
-
function resolveTokens(tokens) {
|
|
126
|
-
const out = {};
|
|
127
|
-
const inProgress = /* @__PURE__ */ new Set();
|
|
128
|
-
const resolveOne = (name) => {
|
|
129
|
-
const cached = out[name];
|
|
130
|
-
if (cached !== void 0) return cached;
|
|
131
|
-
const token = tokens[name];
|
|
132
|
-
if (!token) throw new Error(`Unknown token "${name}"`);
|
|
133
|
-
if (inProgress.has(name)) {
|
|
134
|
-
throw new Error(`Reference cycle at token "${name}" (${[...inProgress].join(" \u2192 ")})`);
|
|
135
|
-
}
|
|
136
|
-
inProgress.add(name);
|
|
137
|
-
const target = refTarget(token.value);
|
|
138
|
-
let value;
|
|
139
|
-
if (target === null) {
|
|
140
|
-
value = serializeTokenValue(token.type, token.value);
|
|
141
|
-
} else if (!tokens[target]) {
|
|
142
|
-
throw new Error(`Token "${name}" references "${target}", which is not defined`);
|
|
143
|
-
} else {
|
|
144
|
-
value = resolveOne(target);
|
|
145
|
-
}
|
|
146
|
-
if (token.alpha !== void 0) value = withAlpha(value, token.alpha);
|
|
147
|
-
inProgress.delete(name);
|
|
148
|
-
out[name] = value;
|
|
149
|
-
return value;
|
|
150
|
-
};
|
|
151
|
-
for (const name of Object.keys(tokens)) resolveOne(name);
|
|
152
|
-
return out;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// src/resolveTheme.ts
|
|
156
|
-
function themeChain(theme) {
|
|
157
|
-
const out = [];
|
|
158
|
-
for (let t = theme; t; t = t.extends) out.unshift(t);
|
|
159
|
-
return out;
|
|
160
|
-
}
|
|
161
|
-
function themeAxes(theme) {
|
|
162
|
-
return themeChain(theme).reduce((axes, t) => mergeAxes(axes, t.axes), {});
|
|
163
|
-
}
|
|
164
|
-
function resolveTheme(theme, selection = {}) {
|
|
165
|
-
const sel = fullSelection(themeAxes(theme), selection);
|
|
166
|
-
let merged = {};
|
|
167
|
-
for (const t of themeChain(theme)) merged = { ...merged, ...pickAll(t.tokens, sel) };
|
|
168
|
-
const out = {};
|
|
169
|
-
for (const [name, value] of Object.entries(resolveTokens(merged))) out[`--wzl-${name}`] = value;
|
|
170
|
-
return out;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export { enumerateSelections, fullSelection, isByAxis, mergeAxes, parseTokenValue, pick, pickAll, resolveTheme, resolveTokens, selectionKey, serializeTokenValue, themeAxes };
|
|
174
|
-
//# sourceMappingURL=chunk-LL2ERJPZ.js.map
|
|
175
|
-
//# sourceMappingURL=chunk-LL2ERJPZ.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/axes.ts","../src/dtcg/value.ts","../src/dtcg/color.ts","../src/dtcg/resolve.ts","../src/resolveTheme.ts"],"names":[],"mappings":";AA0BO,SAAS,SAAS,CAAA,EAAkC;AACzD,EAAA,OAAO,OAAO,CAAA,KAAM,QAAA,IAAY,CAAA,KAAM,IAAA,IAAQ,CAAC,KAAA,CAAM,OAAA,CAAQ,CAAC,CAAA,IAAK,OAAQ,CAAA,CAAuB,EAAA,KAAO,QAAA;AAC3G;AAGO,SAAS,aAAA,CAAc,IAAA,EAAgB,SAAA,GAAuB,EAAC,EAAc;AAClF,EAAA,MAAM,MAA8B,EAAC;AACrC,EAAA,KAAA,MAAW,CAAC,IAAA,EAAM,GAAG,KAAK,MAAA,CAAO,OAAA,CAAQ,IAAI,CAAA,EAAG;AAC9C,IAAA,MAAM,CAAA,GAAI,UAAU,IAAI,CAAA;AACxB,IAAA,GAAA,CAAI,IAAI,IAAI,CAAA,KAAM,MAAA,IAAa,KAAK,GAAA,CAAI,MAAA,GAAS,IAAI,GAAA,CAAI,OAAA;AAAA,EAC3D;A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vD,EAAA,OAAO,GAAA;AACT;;;AC9CO,SAAS,WAAW,KAAA,EAAuB;AAChD,EAAA,MAAM,MAAe,EAAC;AACtB,EAAA,KAAA,IAAS,CAAA,GAAkB,OAAO,CAAA,EAAG,CAAA,GAAI,EAAE,OAAA,EAAS,GAAA,CAAI,QAAQ,CAAC,CAAA;AACjE,EAAA,OAAO,GAAA;AACT;AAGO,SAAS,UAAU,KAAA,EAAwB;AAChD,EAAA,OAAO,UAAA,CAAW,KAAK,CAAA,CAAE,MAAA,CAAiB,CAAC,IAAA,EAAM,CAAA,KAAM,SAAA,CAAU,IAAA,EAAM,CAAA,CAAE,IAAI,CAAA,EAAG,EAAE,CAAA;AACpF;AASO,SAAS,YAAA,CAAa,KAAA,EAAc,SAAA,GAAuB,EAAC,EAAkB;AACnF,EAAA,MAAM,GAAA,GAAM,aAAA,CAAc,SAAA,CAAU,KAAK,GAAG,SAAS,CAAA;AACrD,EAAA,IAAI,SAAqB,EAAC;AAC1B,EAAA,KAAA,MAAW,CAAA,IAAK,UAAA,CAAW,KAAK,CAAA,EAAG,MAAA,GAAS,EAAE,GAAG,MAAA,EAAQ,GAAG,OAAA,CAAQ,CAAA,CAAE,MAAA,EAAQ,GAAG,CAAA,EAAE;AACnF,EAAA,MAAM,MAA8B,EAAC;AACrC,EAAA,KAAA,MAAW,CAAC,IAAA,EAAM,KAAK,CAAA,IAAK,OAAO,OAAA,CAAQ,aAAA,CAAc,MAAM,CAAC,CAAA,EAAG,GAAA,CAAI,CAAA,MAAA,EAAS,IAAI,EAAE,CAAA,GAAI,KAAA;AAC1F,EAAA,OAAO,GAAA;AACT","file":"chunk-LL2ERJPZ.js","sourcesContent":["/** One value of an axis. `scheme` becomes `color-scheme` in that value's CSS blocks. */\nexport interface AxisValue {\n readonly scheme?: 'dark' | 'light';\n}\n\nexport interface AxisDef {\n readonly default: string;\n readonly values: Readonly<Record<string, AxisValue>>;\n}\n\n/** Key order is declaration order, which selectors and selection keys follow. */\nexport type AxisDefs = Readonly<Record<string, AxisDef>>;\n\n/** A partial choice of axis values, e.g. `{ mode: 'light' }`. */\nexport type Selection = Readonly<Record<string, string>>;\n\n/** `{ by: 'mode', dark: …, light: … }`: a value that differs per axis value. */\nexport interface ByAxis<T> {\n readonly by: string;\n readonly [axisValue: string]: Varying<T> | string;\n}\n\nexport type Varying<T> = T | ByAxis<T>;\n\nexport type Picked<T> = { ok: true; value: T } | { ok: false; axis: string; value: string };\n\nexport function isByAxis(v: unknown): v is ByAxis<unknown> {\n return typeof v === 'object' && v !== null && !Array.isArray(v) && typeof (v as { by?: unknown }).by === 'string';\n}\n\n/** Every axis given a known value; anything missing or unknown takes its default. */\nexport function fullSelection(axes: AxisDefs, selection: Selection = {}): Selection {\n const out: Record<string, string> = {};\n for (const [name, def] of Object.entries(axes)) {\n const v = selection[name];\n out[name] = v !== undefined && v in def.values ? v : def.default;\n }\n return out;\n}\n\n/** A child's axes over its parent's: an axis both declare keeps both sets of values, the child's entries and default winning. */\nexport function mergeAxes(parent: AxisDefs, child: AxisDefs): AxisDefs {\n const out: Record<string, AxisDef> = { ...parent };\n for (const [name, def] of Object.entries(child)) {\n out[name] = { ...def, values: { ...parent[name]?.values, ...def.values } };\n }\n return out;\n}\n\nexport function enumerateSelections(axes: AxisDefs): Selection[] {\n let out: Record<string, string>[] = [{}];\n for (const [name, def] of Object.entries(axes)) {\n out = out.flatMap((s) => Object.keys(def.values).map((v) => ({ ...s, [name]: v })));\n }\n return out;\n}\n\n/** `mode=dark,density=compact`, axes in declaration order. */\nexport function selectionKey(axes: AxisDefs, selection: Selection): string {\n const full = fullSelection(axes, selection);\n return Object.keys(axes).map((a) => `${a}=${full[a]}`).join(',');\n}\n\nexport function pick<T>(v: Varying<T>, selection: Selection): Picked<T> {\n let cur: unknown = v;\n while (isByAxis(cur)) {\n const axis = cur.by;\n const value = selection[axis];\n if (value === undefined || value === 'by' || !(value in cur)) return { ok: false, axis, value: value ?? '' };\n cur = cur[value];\n }\n return { ok: true, value: cur as T };\n}\n\n/** Every entry of a varying record that has a value for this selection, in record order. */\nexport function pickAll<T>(record: Readonly<Record<string, Varying<T>>>, selection: Selection): Record<string, T> {\n const out: Record<string, T> = {};\n for (const [name, v] of Object.entries(record)) {\n const picked = pick(v, selection);\n if (picked.ok) out[name] = picked.value;\n }\n return out;\n}\n","import type { TokenValue } from './types';\n\n/**\n * Quote family names containing whitespace; leave everything else bare.\n * Generic keywords (`sans-serif`) and hyphen-prefixed identifiers\n * (`-apple-system`) break if quoted, and neither contains a space.\n */\nfunction fontStack(value: readonly (string | number)[]): string {\n return value.map((f) => (typeof f === 'string' && /\\s/.test(f) ? `'${f}'` : String(f))).join(', ');\n}\n\n/**\n * A token's value as CSS renders it. A DTCG value is not always a string: a\n * `fontFamily` is a list of names and a `cubicBezier` is four numbers, and both\n * have a spelling that belongs in a stylesheet rather than in JSON.\n */\nexport function serializeTokenValue(type: string, value: TokenValue): string {\n if (Array.isArray(value)) {\n if (type === 'cubicBezier') return `cubic-bezier(${value.join(', ')})`;\n if (type === 'fontFamily') return fontStack(value);\n return value.join(', ');\n }\n return String(value);\n}\n\nconst BEZIER = /^cubic-bezier\\(\\s*([^)]*)\\)$/i;\n\n/**\n * The inverse of {@link serializeTokenValue}: text a person edited, back in the\n * shape a definition stores. Text that does not parse for its type is kept as\n * text rather than thrown away, so a half-typed value stays editable.\n */\nexport function parseTokenValue(type: string, text: string): TokenValue {\n const raw = text.trim();\n if (type === 'cubicBezier') {\n const inner = BEZIER.exec(raw)?.[1] ?? raw;\n const parts = inner.split(',').map((p) => Number(p.trim()));\n return parts.length === 4 && parts.every((n) => Number.isFinite(n)) ? parts : raw;\n }\n if (type === 'fontFamily') {\n const families = raw\n .split(',')\n .map((f) => f.trim().replace(/^['\"]|['\"]$/g, '').trim())\n .filter((f) => f !== '');\n return families.length > 0 ? families : raw;\n }\n return raw;\n}\n","/**\n * A resolved color at `alpha`, multiplied into any alpha it already carries. The\n * JS side of the alpha extension; the CSS side emits `color-mix()` instead so DOM\n * chrome keeps tracking a downstream override of the referenced token.\n *\n * Hex and `rgb()`/`rgba()` become an `rgba()` literal. Anything else — a named\n * color, `hsl()`, `oklch()`, a `var()` — becomes the same `color-mix()` the CSS\n * side writes, which the browser resolves.\n */\nexport function withAlpha(color: string, alpha: number): string {\n const rgba = parseRgba(color.trim());\n if (!rgba) return `color-mix(in srgb, ${color.trim()} ${round(alpha * 100, 4)}%, transparent)`;\n const [r, g, b, a] = rgba;\n return `rgba(${r}, ${g}, ${b}, ${round(a * alpha, 3)})`;\n}\n\ntype Rgba = [number, number, number, number];\n\nfunction round(n: number, places: number): number {\n return Number(n.toFixed(places));\n}\n\nfunction parseRgba(s: string): Rgba | null {\n if (s.toLowerCase() === 'transparent') return [0, 0, 0, 0];\n return parseHex(s) ?? parseRgbFn(s);\n}\n\nfunction parseHex(s: string): Rgba | null {\n const m = /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(s);\n if (!m) return null;\n const body = m[1];\n const full = body.length <= 4 ? body.replace(/./g, (c) => c + c) : body;\n const byte = (i: number) => Number.parseInt(full.slice(i, i + 2), 16);\n return [byte(0), byte(2), byte(4), full.length === 8 ? byte(6) / 255 : 1];\n}\n\nfunction parseRgbFn(s: string): Rgba | null {\n const m = /^rgba?\\(([^()]*)\\)$/i.exec(s);\n if (!m) return null;\n const [channels, alphaPart, extra] = m[1].split('/');\n if (extra !== undefined) return null;\n const parts = channels.trim().split(/\\s*,\\s*|\\s+/);\n if (alphaPart !== undefined) parts.push(alphaPart.trim());\n if (parts.length !== 3 && parts.length !== 4) return null;\n\n const channel = (p: string) => (p.endsWith('%') ? (Number.parseFloat(p) / 100) * 255 : Number(p));\n const alpha = (p: string) => (p.endsWith('%') ? Number.parseFloat(p) / 100 : Number(p));\n const [r, g, b] = parts.slice(0, 3).map(channel);\n const a = parts[3] === undefined ? 1 : alpha(parts[3]);\n if (![r, g, b, a].every(Number.isFinite)) return null;\n return [Math.round(r), Math.round(g), Math.round(b), a];\n}\n","import { withAlpha } from './color';\nimport type { FlatTokens, ResolvedTokenMap, TokenValue } from './types';\nimport { serializeTokenValue } from './value';\n\n/** `{color.gray-100}` → `gray-100`. The type group is dropped, per the naming rule. */\nconst REF = /^\\{([^}]+)\\}$/;\n\nfunction refTarget(value: TokenValue): string | null {\n if (typeof value !== 'string') return null;\n const m = REF.exec(value.trim());\n if (!m) return null;\n const path = m[1];\n const dot = path.indexOf('.');\n return dot === -1 ? path : path.slice(dot + 1);\n}\n\n/**\n * Resolve flat tokens to final CSS-ready strings.\n *\n * Merge modes before calling: this function has no notion of modes, only of a\n * complete token set.\n */\nexport function resolveTokens(tokens: FlatTokens): ResolvedTokenMap {\n const out: ResolvedTokenMap = {};\n const inProgress = new Set<string>();\n\n const resolveOne = (name: string): string => {\n const cached = out[name];\n if (cached !== undefined) return cached;\n\n const token = tokens[name];\n if (!token) throw new Error(`Unknown token \"${name}\"`);\n\n if (inProgress.has(name)) {\n throw new Error(`Reference cycle at token \"${name}\" (${[...inProgress].join(' → ')})`);\n }\n inProgress.add(name);\n\n const target = refTarget(token.value);\n let value: string;\n if (target === null) {\n value = serializeTokenValue(token.type, token.value);\n } else if (!tokens[target]) {\n throw new Error(`Token \"${name}\" references \"${target}\", which is not defined`);\n } else {\n value = resolveOne(target);\n }\n\n if (token.alpha !== undefined) value = withAlpha(value, token.alpha);\n\n inProgress.delete(name);\n out[name] = value;\n return value;\n };\n\n for (const name of Object.keys(tokens)) resolveOne(name);\n return out;\n}\n\n/** Merge a mode's tokens over the mode-invariant set. Later wins. */\nexport function mergeTokens(base: FlatTokens, mode: FlatTokens): FlatTokens {\n return { ...base, ...mode };\n}\n","import { fullSelection, mergeAxes, pickAll, type AxisDefs, type Selection } from './axes';\nimport { resolveTokens } from './dtcg/resolve';\nimport type { FlatTokens } from './dtcg/types';\nimport type { TokenName } from './generated/themes';\nimport type { Theme } from './theme';\n\n/** The output of `resolveTheme`: every token of a theme, for one selection, keyed\n * by CSS custom-property name and flattened to a final CSS value. */\nexport type ResolvedTheme = Readonly<Record<TokenName, string>>;\n\n/** Root-first, so the leaf theme's tokens land last. */\nexport function themeChain(theme: Theme): Theme[] {\n const out: Theme[] = [];\n for (let t: Theme | null = theme; t; t = t.extends) out.unshift(t);\n return out;\n}\n\n/** Every axis the chain declares. An axis declared more than once keeps every value; a descendant's value entries and default win. */\nexport function themeAxes(theme: Theme): AxisDefs {\n return themeChain(theme).reduce<AxisDefs>((axes, t) => mergeAxes(axes, t.axes), {});\n}\n\n/**\n * Merge the extends chain at a selection, resolve every alias, and key the\n * result by CSS custom-property name. A missing or unknown axis value takes the\n * axis default.\n *\n * Pure — no DOM. An unresolvable reference throws rather than falling back.\n */\nexport function resolveTheme(theme: Theme, selection: Selection = {}): ResolvedTheme {\n const sel = fullSelection(themeAxes(theme), selection);\n let merged: FlatTokens = {};\n for (const t of themeChain(theme)) merged = { ...merged, ...pickAll(t.tokens, sel) };\n const out: Record<string, string> = {};\n for (const [name, value] of Object.entries(resolveTokens(merged))) out[`--wzl-${name}`] = value;\n return out as ResolvedTheme;\n}\n"]}
|
package/dist/chunk-PJMTWM34.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/dtcg/types.ts"],"names":[],"mappings":";AACO,IAAM,SAAA,GAAY","file":"chunk-PJMTWM34.js","sourcesContent":["/** The one `$extensions` key this kit defines. */\nexport const ALPHA_EXT = 'com.weasel.alpha';\n\nexport type TokenValue = string | number | readonly (string | number)[];\n\n/**\n * A single design token as authored, before aliases are resolved: a DTCG-shaped\n * `{ type, value }` pair where `value` may still be a `{ref}` to another token.\n */\nexport interface RawToken {\n readonly type: string;\n readonly value: TokenValue;\n /** Render the referenced color at this alpha, 0–1. */\n readonly alpha?: number | undefined;\n readonly description?: string | undefined;\n}\n\n/** A token graph flattened to one level, keyed by token name (no `--wzl-`\n * prefix). Still unresolved — see `ResolvedTokenMap` for the output side. */\nexport type FlatTokens = Record<string, RawToken>;\n\n/** A resolved theme: every token name mapped to its final CSS-ready string.\n * Named ...Map, not ...Tokens, to stay distinct from hud's public `ResolvedTokens`. */\nexport type ResolvedTokenMap = Record<string, string>;\n"]}
|