@hussmartinez/ui 0.2.0 → 0.4.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/dist/index.js ADDED
@@ -0,0 +1,1609 @@
1
+ import { a as uiMessages, i as warnInDevelopment, n as cssWriterOf, o as UiError, r as registerTheme, t as isThemePair } from "./shared/pair-DLVFV6vU.js";
2
+ // src/tokens/base.ts
3
+ var baseValues = {
4
+ "gray-50": "oklch(0.985 0.008 260)",
5
+ "gray-100": "oklch(0.965 0.008 260)",
6
+ "gray-200": "oklch(0.925 0.009 260)",
7
+ "gray-300": "oklch(0.87 0.011 260)",
8
+ "gray-400": "oklch(0.78 0.012 260)",
9
+ "gray-500": "oklch(0.68 0.012 260)",
10
+ "gray-600": "oklch(0.585 0.012 260)",
11
+ "gray-700": "oklch(0.5 0.012 260)",
12
+ "gray-800": "oklch(0.42 0.011 260)",
13
+ "gray-900": "oklch(0.34 0.01 260)",
14
+ "gray-950": "oklch(0.26 0.01 260)",
15
+ "blue-50": "oklch(0.985 0.024 258)",
16
+ "blue-100": "oklch(0.965 0.05 258)",
17
+ "blue-200": "oklch(0.925 0.09 258)",
18
+ "blue-300": "oklch(0.87 0.14 258)",
19
+ "blue-400": "oklch(0.78 0.18 258)",
20
+ "blue-500": "oklch(0.68 0.2 258)",
21
+ "blue-600": "oklch(0.585 0.2 258)",
22
+ "blue-700": "oklch(0.5 0.184 258)",
23
+ "blue-800": "oklch(0.42 0.16 258)",
24
+ "blue-900": "oklch(0.34 0.13 258)",
25
+ "blue-950": "oklch(0.26 0.1 258)",
26
+ "red-50": "oklch(0.985 0.025 25)",
27
+ "red-100": "oklch(0.965 0.052 25)",
28
+ "red-200": "oklch(0.925 0.095 25)",
29
+ "red-300": "oklch(0.87 0.147 25)",
30
+ "red-400": "oklch(0.78 0.189 25)",
31
+ "red-500": "oklch(0.68 0.21 25)",
32
+ "red-600": "oklch(0.585 0.21 25)",
33
+ "red-700": "oklch(0.5 0.193 25)",
34
+ "red-800": "oklch(0.42 0.168 25)",
35
+ "red-900": "oklch(0.34 0.137 25)",
36
+ "red-950": "oklch(0.26 0.105 25)",
37
+ "green-50": "oklch(0.985 0.02 150)",
38
+ "green-100": "oklch(0.965 0.043 150)",
39
+ "green-200": "oklch(0.925 0.077 150)",
40
+ "green-300": "oklch(0.87 0.119 150)",
41
+ "green-400": "oklch(0.78 0.153 150)",
42
+ "green-500": "oklch(0.68 0.17 150)",
43
+ "green-600": "oklch(0.585 0.17 150)",
44
+ "green-700": "oklch(0.5 0.156 150)",
45
+ "green-800": "oklch(0.42 0.136 150)",
46
+ "green-900": "oklch(0.34 0.111 150)",
47
+ "green-950": "oklch(0.26 0.085 150)",
48
+ "amber-50": "oklch(0.985 0.02 70)",
49
+ "amber-100": "oklch(0.965 0.043 70)",
50
+ "amber-200": "oklch(0.925 0.077 70)",
51
+ "amber-300": "oklch(0.87 0.119 70)",
52
+ "amber-400": "oklch(0.78 0.153 70)",
53
+ "amber-500": "oklch(0.68 0.17 70)",
54
+ "amber-600": "oklch(0.585 0.17 70)",
55
+ "amber-700": "oklch(0.5 0.156 70)",
56
+ "amber-800": "oklch(0.42 0.136 70)",
57
+ "amber-900": "oklch(0.34 0.111 70)",
58
+ "amber-950": "oklch(0.26 0.085 70)",
59
+ white: "oklch(1 0 0)",
60
+ black: "oklch(0 0 0)",
61
+ "space-1": "0.25rem",
62
+ "space-2": "0.5rem",
63
+ "space-3": "0.75rem",
64
+ "space-4": "1rem",
65
+ "space-5": "1.25rem",
66
+ "space-6": "1.5rem",
67
+ "space-7": "2rem",
68
+ "space-8": "2.5rem",
69
+ "space-9": "3rem",
70
+ "space-10": "4rem",
71
+ "space-11": "5rem",
72
+ "space-12": "6rem",
73
+ "radius-none": "0",
74
+ "radius-sm": "0.25rem",
75
+ "radius-md": "0.375rem",
76
+ "radius-lg": "0.5rem",
77
+ "radius-full": "9999px",
78
+ "border-width-1": "1px",
79
+ "border-width-2": "2px",
80
+ "font-sans": "system-ui, -apple-system, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif",
81
+ "font-mono": "ui-monospace, \"SF Mono\", Menlo, Consolas, \"Liberation Mono\", monospace",
82
+ "font-size-1": "0.75rem",
83
+ "font-size-2": "0.8125rem",
84
+ "font-size-3": "0.875rem",
85
+ "font-size-4": "1rem",
86
+ "font-size-5": "1.125rem",
87
+ "font-size-6": "1.25rem",
88
+ "font-size-7": "1.5rem",
89
+ "font-weight-400": "400",
90
+ "font-weight-500": "500",
91
+ "font-weight-600": "600",
92
+ "font-weight-700": "700",
93
+ "leading-tight": "1.25",
94
+ "leading-normal": "1.5",
95
+ "leading-relaxed": "1.75",
96
+ "duration-fast": "100ms",
97
+ "duration-normal": "200ms",
98
+ "duration-slow": "300ms",
99
+ "easing-standard": "cubic-bezier(0.2, 0, 0, 1)",
100
+ "easing-decelerate": "cubic-bezier(0, 0, 0, 1)",
101
+ "easing-accelerate": "cubic-bezier(0.3, 0, 1, 1)"
102
+ };
103
+ // src/tokens/contrast.ts
104
+ var TEXT = 4.5;
105
+ var NON_TEXT = 3;
106
+ var SURFACES = [
107
+ "color-bg",
108
+ "color-surface",
109
+ "color-surface-raised"
110
+ ];
111
+ function buildPairs() {
112
+ const pairs = [];
113
+ const needs = (foreground, backgrounds, minimum) => {
114
+ for (const background of backgrounds) pairs.push({
115
+ foreground,
116
+ background,
117
+ minimum
118
+ });
119
+ };
120
+ needs("color-text", [...SURFACES, "color-surface-sunken"], TEXT);
121
+ needs("color-text-muted", SURFACES, TEXT);
122
+ needs("color-accent-text", SURFACES, TEXT);
123
+ needs("color-danger-text", [...SURFACES, "color-danger-subtle"], TEXT);
124
+ needs("color-warning-text", [...SURFACES, "color-warning-subtle"], TEXT);
125
+ needs("color-success-text", [...SURFACES, "color-success-subtle"], TEXT);
126
+ needs("color-text", [
127
+ "color-control",
128
+ "color-control-hover",
129
+ "color-control-active"
130
+ ], TEXT);
131
+ needs("color-text", ["color-accent-subtle"], TEXT);
132
+ needs("color-on-accent", [
133
+ "color-accent",
134
+ "color-accent-hover",
135
+ "color-accent-active"
136
+ ], TEXT);
137
+ needs("color-on-danger", ["color-danger", "color-danger-hover"], TEXT);
138
+ needs("color-on-warning", ["color-warning"], TEXT);
139
+ needs("color-on-success", ["color-success"], TEXT);
140
+ needs("color-border-strong", SURFACES, NON_TEXT);
141
+ needs("color-accent", SURFACES, NON_TEXT);
142
+ needs("color-accent", ["color-surface-sunken"], NON_TEXT);
143
+ needs("focus-ring-color", SURFACES, NON_TEXT);
144
+ return Object.freeze(pairs);
145
+ }
146
+ var contrastPairs = /* @__PURE__ */ buildPairs();
147
+ // src/theme/css-value.ts
148
+ var CssValueError = class extends Error {
149
+ name = "CssValueError";
150
+ };
151
+ var MAX_LENGTH = 1e3;
152
+ var MAX_DEPTH = 8;
153
+ function union(...parts) {
154
+ return new Set(parts.flatMap((part) => [...part]));
155
+ }
156
+ var COLOR_FUNCTIONS = /* @__PURE__ */ new Set([
157
+ "rgb",
158
+ "rgba",
159
+ "hsl",
160
+ "hsla",
161
+ "hwb",
162
+ "lab",
163
+ "lch",
164
+ "oklab",
165
+ "oklch",
166
+ "color",
167
+ "color-mix",
168
+ "light-dark"
169
+ ]);
170
+ var MATH_FUNCTIONS = /* @__PURE__ */ new Set([
171
+ "calc",
172
+ "min",
173
+ "max",
174
+ "clamp"
175
+ ]);
176
+ var EASING_FUNCTIONS = /* @__PURE__ */ new Set([
177
+ "cubic-bezier",
178
+ "steps",
179
+ "linear"
180
+ ]);
181
+ var FUNCTIONS = /* @__PURE__ */ union(COLOR_FUNCTIONS, MATH_FUNCTIONS, EASING_FUNCTIONS, ["var"]);
182
+ var LENGTH_UNITS = /* @__PURE__ */ new Set([
183
+ "px",
184
+ "rem",
185
+ "em",
186
+ "ch",
187
+ "ex",
188
+ "lh",
189
+ "%",
190
+ "vw",
191
+ "vh",
192
+ "vmin",
193
+ "vmax",
194
+ "cqw",
195
+ "cqh",
196
+ "cqi",
197
+ "cqb"
198
+ ]);
199
+ var TIME_UNITS = /* @__PURE__ */ new Set(["ms", "s"]);
200
+ var NUMBER_UNITS = /* @__PURE__ */ union(LENGTH_UNITS, TIME_UNITS, [
201
+ "deg",
202
+ "turn",
203
+ "rad",
204
+ "grad",
205
+ ""
206
+ ]);
207
+ var HM_PROPERTY = /^--hm-[a-z0-9]+(?:-[a-z0-9]+)*$/;
208
+ var IDENT = /^-?[A-Za-z_][A-Za-z0-9_-]*/;
209
+ var NUMBER = /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?/;
210
+ var UNIT = /^(?:[A-Za-z]+|%)/;
211
+ var HASH = /^#[0-9A-Fa-f]+/;
212
+ var STRING_CONTENT = /^[A-Za-z0-9 _.-]*$/;
213
+ var Parser = class {
214
+ index = 0;
215
+ input;
216
+ constructor(input) {
217
+ this.input = input;
218
+ }
219
+ parse() {
220
+ const groups = this.sequence(0, false);
221
+ if (this.index < this.input.length) throw new CssValueError(`unexpected "${this.input.charAt(this.index)}"`);
222
+ return groups;
223
+ }
224
+ sequence(depth, inFunction) {
225
+ const groups = [];
226
+ let current = [];
227
+ const flush = () => {
228
+ if (current.length > 0) {
229
+ groups.push(current);
230
+ current = [];
231
+ }
232
+ };
233
+ while (this.index < this.input.length) {
234
+ const rest = this.input.slice(this.index);
235
+ const char = rest.charAt(0);
236
+ if (/^\s/.test(char)) {
237
+ this.index += (/^\s+/.exec(rest)?.[0] ?? " ").length;
238
+ flush();
239
+ continue;
240
+ }
241
+ if (char === ")") {
242
+ if (!inFunction) throw new CssValueError("unbalanced \")\"");
243
+ flush();
244
+ return groups;
245
+ }
246
+ if (char === ",") {
247
+ flush();
248
+ groups.push([{ kind: "comma" }]);
249
+ this.index += 1;
250
+ continue;
251
+ }
252
+ if (char === "/") {
253
+ if (rest.startsWith("/*")) throw new CssValueError("comments aren't allowed");
254
+ flush();
255
+ groups.push([{ kind: "slash" }]);
256
+ this.index += 1;
257
+ continue;
258
+ }
259
+ if (char === "*" || (char === "+" || char === "-") && /^[+-]\s/.test(rest)) {
260
+ if (!inFunction) throw new CssValueError(`"${char}" is only allowed inside calc()`);
261
+ flush();
262
+ groups.push([{
263
+ kind: "operator",
264
+ value: char
265
+ }]);
266
+ this.index += 1;
267
+ continue;
268
+ }
269
+ if (char === "\"" || char === "'") {
270
+ current.push(this.string(char));
271
+ continue;
272
+ }
273
+ if (char === "#") {
274
+ const hash = HASH.exec(rest)?.[0];
275
+ if (!hash || ![
276
+ 4,
277
+ 5,
278
+ 7,
279
+ 9
280
+ ].includes(hash.length)) throw new CssValueError("hex colours have 3, 4, 6 or 8 digits");
281
+ current.push({
282
+ kind: "hash",
283
+ value: hash.toLowerCase()
284
+ });
285
+ this.index += hash.length;
286
+ continue;
287
+ }
288
+ const number = NUMBER.exec(rest)?.[0];
289
+ if (number) {
290
+ this.index += number.length;
291
+ const unit = UNIT.exec(this.input.slice(this.index))?.[0] ?? "";
292
+ if (!NUMBER_UNITS.has(unit.toLowerCase())) throw new CssValueError(`the unit "${unit}" isn't allowed`);
293
+ this.index += unit.length;
294
+ current.push({
295
+ kind: "number",
296
+ value: Number(number),
297
+ unit: unit.toLowerCase()
298
+ });
299
+ continue;
300
+ }
301
+ if (rest.startsWith("--")) {
302
+ const name = /^--[A-Za-z0-9_-]*/.exec(rest)?.[0] ?? "--";
303
+ if (!HM_PROPERTY.test(name)) throw new CssValueError(`only --hm-* custom properties can be referenced, not "${name}"`);
304
+ current.push({
305
+ kind: "ident",
306
+ value: name
307
+ });
308
+ this.index += name.length;
309
+ continue;
310
+ }
311
+ const ident = IDENT.exec(rest)?.[0];
312
+ if (ident) {
313
+ this.index += ident.length;
314
+ if (this.input.charAt(this.index) === "(") current.push(this.function(ident.toLowerCase(), depth));
315
+ else current.push({
316
+ kind: "ident",
317
+ value: ident.toLowerCase()
318
+ });
319
+ continue;
320
+ }
321
+ throw new CssValueError(`the character "${char}" isn't allowed`);
322
+ }
323
+ if (inFunction) throw new CssValueError("unbalanced \"(\"");
324
+ flush();
325
+ return groups;
326
+ }
327
+ function(name, depth) {
328
+ if (!FUNCTIONS.has(name)) throw new CssValueError(`the function "${name}()" isn't allowed`);
329
+ if (depth >= MAX_DEPTH) throw new CssValueError("functions are nested too deeply");
330
+ this.index += 1;
331
+ const args = this.sequence(depth + 1, true).flat();
332
+ this.index += 1;
333
+ if (name === "var") {
334
+ const [property, comma] = args;
335
+ if (property?.kind !== "ident" || !HM_PROPERTY.test(property.value)) throw new CssValueError("var() must name a --hm-* custom property");
336
+ if (args.length > 1 && comma?.kind !== "comma") throw new CssValueError("var() takes a property name and an optional fallback");
337
+ }
338
+ return {
339
+ kind: "function",
340
+ name,
341
+ args
342
+ };
343
+ }
344
+ string(quote) {
345
+ const end = this.input.indexOf(quote, this.index + 1);
346
+ if (end === -1) throw new CssValueError("unterminated string");
347
+ const value = this.input.slice(this.index + 1, end);
348
+ if (!STRING_CONTENT.test(value)) throw new CssValueError("strings may only contain letters, digits, spaces, _ . and -");
349
+ this.index = end + 1;
350
+ return {
351
+ kind: "string",
352
+ value
353
+ };
354
+ }
355
+ };
356
+ function serializeNode(node) {
357
+ switch (node.kind) {
358
+ case "ident": return node.value;
359
+ case "number": return `${node.value}${node.unit}`;
360
+ case "hash": return node.value;
361
+ case "string": return `"${node.value}"`;
362
+ case "comma": return ",";
363
+ case "slash": return "/";
364
+ case "operator": return node.value;
365
+ case "function": return `${node.name}(${serializeNodes(node.args)})`;
366
+ }
367
+ }
368
+ function serializeNodes(nodes) {
369
+ let css = "";
370
+ nodes.forEach((node, index) => {
371
+ if (node.kind === "comma") {
372
+ css += ",";
373
+ return;
374
+ }
375
+ if (index > 0) css += " ";
376
+ css += serializeNode(node);
377
+ });
378
+ return css;
379
+ }
380
+ function parseValue(input) {
381
+ if (typeof input !== "string") throw new CssValueError("values must be strings");
382
+ const trimmed = input.trim();
383
+ if (trimmed.length === 0) throw new CssValueError("the value is empty");
384
+ if (trimmed.length > MAX_LENGTH) throw new CssValueError(`the value is longer than ${MAX_LENGTH} characters`);
385
+ const nodes = new Parser(trimmed).parse().flat();
386
+ return {
387
+ nodes,
388
+ css: serializeNodes(nodes)
389
+ };
390
+ }
391
+ var isVar = (node) => node.kind === "function" && node.name === "var";
392
+ var isMath = (node) => node.kind === "function" && MATH_FUNCTIONS.has(node.name);
393
+ function isColor(node) {
394
+ if (isVar(node) || node.kind === "hash") return true;
395
+ if (node.kind === "function") return COLOR_FUNCTIONS.has(node.name);
396
+ return node.kind === "ident" && [
397
+ "transparent",
398
+ "currentcolor",
399
+ "black",
400
+ "white"
401
+ ].includes(node.value);
402
+ }
403
+ function isLength(node) {
404
+ if (isVar(node) || isMath(node)) return true;
405
+ return node.kind === "number" && (LENGTH_UNITS.has(node.unit) || node.unit === "" && node.value === 0);
406
+ }
407
+ function isPlainNumber(node, integer = false) {
408
+ if (isVar(node) || isMath(node)) return true;
409
+ return node.kind === "number" && node.unit === "" && (!integer || Number.isInteger(node.value));
410
+ }
411
+ function splitByComma(nodes) {
412
+ const lists = [[]];
413
+ for (const node of nodes) if (node.kind === "comma") lists.push([]);
414
+ else lists[lists.length - 1]?.push(node);
415
+ return lists;
416
+ }
417
+ var OUTLINE_STYLES = /* @__PURE__ */ new Set([
418
+ "solid",
419
+ "dashed",
420
+ "dotted",
421
+ "double",
422
+ "auto",
423
+ "none"
424
+ ]);
425
+ var EASING_KEYWORDS = /* @__PURE__ */ new Set([
426
+ "linear",
427
+ "ease",
428
+ "ease-in",
429
+ "ease-out",
430
+ "ease-in-out",
431
+ "step-start",
432
+ "step-end"
433
+ ]);
434
+ var typeCheckers = {
435
+ color: (nodes) => nodes.length === 1 && isColor(nodes[0]),
436
+ length: (nodes) => nodes.length === 1 && isLength(nodes[0]),
437
+ duration: (nodes) => {
438
+ const [node] = nodes;
439
+ return nodes.length === 1 && node !== void 0 && (isVar(node) || isMath(node) || node.kind === "number" && TIME_UNITS.has(node.unit));
440
+ },
441
+ easing: (nodes) => {
442
+ const [node] = nodes;
443
+ if (nodes.length !== 1 || node === void 0) return false;
444
+ if (node.kind === "ident") return EASING_KEYWORDS.has(node.value);
445
+ return isVar(node) || node.kind === "function" && EASING_FUNCTIONS.has(node.name);
446
+ },
447
+ number: (nodes) => nodes.length === 1 && isPlainNumber(nodes[0]),
448
+ integer: (nodes) => nodes.length === 1 && isPlainNumber(nodes[0], true),
449
+ "font-weight": (nodes) => {
450
+ const [node] = nodes;
451
+ if (nodes.length !== 1 || node === void 0) return false;
452
+ if (node.kind === "ident") return node.value === "normal" || node.value === "bold";
453
+ return isVar(node) || node.kind === "number" && node.unit === "" && node.value >= 1 && node.value <= 1e3;
454
+ },
455
+ "font-family": (nodes) => splitByComma(nodes).every((family) => family.length > 0 && (family.every((node) => node.kind === "ident") || family.length === 1 && (family[0]?.kind === "string" || isVar(family[0])))),
456
+ shadow: (nodes) => {
457
+ if (nodes.length === 1 && nodes[0]?.kind === "ident" && nodes[0].value === "none") return true;
458
+ return splitByComma(nodes).every((layer) => {
459
+ const lengths = layer.filter((node) => isLength(node) && !isVar(node)).length;
460
+ const vars = layer.filter(isVar).length;
461
+ const colors = layer.filter((node) => !isVar(node) && isColor(node)).length;
462
+ const inset = layer.filter((node) => node.kind === "ident" && node.value === "inset").length;
463
+ return layer.length === lengths + vars + colors + inset && colors <= 1 && inset <= 1 && (vars > 0 || lengths >= 2 && lengths <= 4);
464
+ });
465
+ },
466
+ outline: (nodes) => nodes.length >= 1 && nodes.length <= 3 && nodes.every((node) => isLength(node) || isColor(node) || node.kind === "ident" && OUTLINE_STYLES.has(node.value)),
467
+ "color-scheme": (nodes) => nodes.length === 1 && nodes[0]?.kind === "ident" && (nodes[0].value === "light" || nodes[0].value === "dark")
468
+ };
469
+ function validateValue(input, type) {
470
+ const parsed = parseValue(input);
471
+ if (type && !typeCheckers[type](parsed.nodes)) throw new CssValueError(`"${parsed.css}" isn't a valid ${type} value`);
472
+ return parsed.css;
473
+ }
474
+ // src/theme/color.ts
475
+ var clamp = (value) => Math.min(1, Math.max(0, value));
476
+ function channel(node, scale) {
477
+ if (node?.kind !== "number") return;
478
+ if (node.unit === "%") return node.value / 100 * scale;
479
+ return node.unit === "" ? node.value : void 0;
480
+ }
481
+ function hue(node) {
482
+ if (node?.kind !== "number") return;
483
+ switch (node.unit) {
484
+ case "":
485
+ case "deg": return node.value;
486
+ case "turn": return node.value * 360;
487
+ case "rad": return node.value * 180 / Math.PI;
488
+ case "grad": return node.value * .9;
489
+ default: return;
490
+ }
491
+ }
492
+ function functionArguments(args) {
493
+ const values = args.filter((node) => node.kind !== "comma");
494
+ const slash = values.findIndex((node) => node.kind === "slash");
495
+ const channels = slash === -1 ? values.slice(0, 3) : values.slice(0, slash);
496
+ const alphaNode = slash === -1 ? values[3] : values[slash + 1];
497
+ return {
498
+ channels,
499
+ alpha: alphaNode ? channel(alphaNode, 1) : 1
500
+ };
501
+ }
502
+ function fromHex(hex) {
503
+ const digits = hex.slice(1);
504
+ const full = digits.length <= 4 ? [...digits].map((digit) => digit + digit).join("") : digits;
505
+ const byte = (index) => Number.parseInt(full.slice(index, index + 2), 16) / 255;
506
+ return {
507
+ r: byte(0),
508
+ g: byte(2),
509
+ b: byte(4),
510
+ alpha: full.length === 8 ? byte(6) : 1
511
+ };
512
+ }
513
+ function fromHsl(h, s, l, alpha) {
514
+ const f = (n) => {
515
+ const k = (n + h / 30) % 12;
516
+ return l - s * Math.min(l, 1 - l) * Math.max(-1, Math.min(k - 3, 9 - k, 1));
517
+ };
518
+ return {
519
+ r: f(0),
520
+ g: f(8),
521
+ b: f(4),
522
+ alpha
523
+ };
524
+ }
525
+ var toGamma = (linear) => linear <= .0031308 ? 12.92 * linear : 1.055 * linear ** (1 / 2.4) - .055;
526
+ var toLinear = (gamma) => gamma <= .04045 ? gamma / 12.92 : ((gamma + .055) / 1.055) ** 2.4;
527
+ function fromOklab(l, a, b, alpha) {
528
+ const l_ = (l + .3963377774 * a + .2158037573 * b) ** 3;
529
+ const m_ = (l - .1055613458 * a - .0638541728 * b) ** 3;
530
+ const s_ = (l - .0894841775 * a - 1.291485548 * b) ** 3;
531
+ return {
532
+ r: toGamma(clamp(4.0767416621 * l_ - 3.3077115913 * m_ + .2309699292 * s_)),
533
+ g: toGamma(clamp(-1.2684380046 * l_ + 2.6097574011 * m_ - .3413193965 * s_)),
534
+ b: toGamma(clamp(-.0041960863 * l_ - .7034186147 * m_ + 1.707614701 * s_)),
535
+ alpha
536
+ };
537
+ }
538
+ function fromFunction(name, args) {
539
+ const { channels, alpha } = functionArguments(args);
540
+ if (alpha === void 0 || channels.length !== 3) return;
541
+ const [first, second, third] = channels;
542
+ switch (name) {
543
+ case "rgb":
544
+ case "rgba": {
545
+ const [r, g, b] = [
546
+ first,
547
+ second,
548
+ third
549
+ ].map((node) => channel(node, 255));
550
+ if (r === void 0 || g === void 0 || b === void 0) return;
551
+ return {
552
+ r: clamp(r / 255),
553
+ g: clamp(g / 255),
554
+ b: clamp(b / 255),
555
+ alpha: clamp(alpha)
556
+ };
557
+ }
558
+ case "hsl":
559
+ case "hsla": {
560
+ const h = hue(first);
561
+ const s = channel(second, 100);
562
+ const l = channel(third, 100);
563
+ if (h === void 0 || s === void 0 || l === void 0) return;
564
+ return fromHsl((h % 360 + 360) % 360, clamp(s / 100), clamp(l / 100), clamp(alpha));
565
+ }
566
+ case "oklch": {
567
+ const l = channel(first, 1);
568
+ const c = channel(second, .4);
569
+ const h = hue(third);
570
+ if (l === void 0 || c === void 0 || h === void 0) return;
571
+ const radians = h * Math.PI / 180;
572
+ return fromOklab(l, c * Math.cos(radians), c * Math.sin(radians), clamp(alpha));
573
+ }
574
+ case "oklab": {
575
+ const l = channel(first, 1);
576
+ const a = channel(second, .4);
577
+ const b = channel(third, .4);
578
+ if (l === void 0 || a === void 0 || b === void 0) return;
579
+ return fromOklab(l, a, b, clamp(alpha));
580
+ }
581
+ default: return;
582
+ }
583
+ }
584
+ function resolveColor(value, lookup, depth = 0) {
585
+ if (depth > 16) return;
586
+ let nodes;
587
+ try {
588
+ nodes = parseValue(value).nodes;
589
+ } catch {
590
+ return;
591
+ }
592
+ const [node] = nodes;
593
+ if (nodes.length !== 1 || node === void 0) return;
594
+ switch (node.kind) {
595
+ case "hash": return fromHex(node.value);
596
+ case "ident": return node.value === "white" ? {
597
+ r: 1,
598
+ g: 1,
599
+ b: 1,
600
+ alpha: 1
601
+ } : node.value === "black" ? {
602
+ r: 0,
603
+ g: 0,
604
+ b: 0,
605
+ alpha: 1
606
+ } : void 0;
607
+ case "function":
608
+ if (node.name === "var") {
609
+ const [property] = node.args;
610
+ const referenced = property?.kind === "ident" ? lookup(property.value.slice(5)) : void 0;
611
+ return referenced === void 0 ? void 0 : resolveColor(referenced, lookup, depth + 1);
612
+ }
613
+ return fromFunction(node.name, node.args);
614
+ default: return;
615
+ }
616
+ }
617
+ function composite(top, bottom) {
618
+ const mix = (a, b) => a * top.alpha + b * (1 - top.alpha);
619
+ return {
620
+ r: mix(top.r, bottom.r),
621
+ g: mix(top.g, bottom.g),
622
+ b: mix(top.b, bottom.b),
623
+ alpha: 1
624
+ };
625
+ }
626
+ function relativeLuminance(color) {
627
+ return .2126 * toLinear(color.r) + .7152 * toLinear(color.g) + .0722 * toLinear(color.b);
628
+ }
629
+ function contrastRatio(foreground, background) {
630
+ if (background.alpha < 1) return;
631
+ const front = foreground.alpha < 1 ? composite(foreground, background) : foreground;
632
+ const lighter = Math.max(relativeLuminance(front), relativeLuminance(background));
633
+ const darker = Math.min(relativeLuminance(front), relativeLuminance(background));
634
+ return (lighter + .05) / (darker + .05);
635
+ }
636
+ // src/theme/contrast-check.ts
637
+ function checkContrast(theme) {
638
+ const lookup = (token) => theme.tokens[token] ?? baseValues[token];
639
+ const failures = [];
640
+ const unchecked = [];
641
+ for (const { foreground, background, minimum } of contrastPairs) {
642
+ const front = lookup(foreground);
643
+ const back = lookup(background);
644
+ const frontColor = front === void 0 ? void 0 : resolveColor(front, lookup);
645
+ const backColor = back === void 0 ? void 0 : resolveColor(back, lookup);
646
+ const ratio = frontColor && backColor ? contrastRatio(frontColor, backColor) : void 0;
647
+ if (ratio === void 0) unchecked.push({
648
+ foreground,
649
+ background
650
+ });
651
+ else if (ratio < minimum) failures.push({
652
+ foreground,
653
+ background,
654
+ ratio: Math.round(ratio * 100) / 100,
655
+ minimum
656
+ });
657
+ }
658
+ return {
659
+ failures,
660
+ unchecked
661
+ };
662
+ }
663
+ // src/tokens/definitions.ts
664
+ var HUES = [
665
+ "gray",
666
+ "blue",
667
+ "red",
668
+ "green",
669
+ "amber"
670
+ ];
671
+ var STEPS = [
672
+ 50,
673
+ 100,
674
+ 200,
675
+ 300,
676
+ 400,
677
+ 500,
678
+ 600,
679
+ 700,
680
+ 800,
681
+ 900,
682
+ 950
683
+ ];
684
+ var semantic = {
685
+ "color-scheme": {
686
+ category: "color",
687
+ type: "color-scheme"
688
+ },
689
+ "color-bg": {
690
+ category: "color",
691
+ type: "color"
692
+ },
693
+ "color-surface": {
694
+ category: "color",
695
+ type: "color"
696
+ },
697
+ "color-surface-raised": {
698
+ category: "color",
699
+ type: "color"
700
+ },
701
+ "color-surface-sunken": {
702
+ category: "color",
703
+ type: "color"
704
+ },
705
+ "color-overlay": {
706
+ category: "color",
707
+ type: "color"
708
+ },
709
+ "color-text": {
710
+ category: "color",
711
+ type: "color"
712
+ },
713
+ "color-text-muted": {
714
+ category: "color",
715
+ type: "color"
716
+ },
717
+ "color-text-disabled": {
718
+ category: "color",
719
+ type: "color"
720
+ },
721
+ "color-border": {
722
+ category: "color",
723
+ type: "color"
724
+ },
725
+ "color-border-strong": {
726
+ category: "color",
727
+ type: "color"
728
+ },
729
+ "color-control": {
730
+ category: "color",
731
+ type: "color"
732
+ },
733
+ "color-control-hover": {
734
+ category: "color",
735
+ type: "color"
736
+ },
737
+ "color-control-active": {
738
+ category: "color",
739
+ type: "color"
740
+ },
741
+ "color-accent": {
742
+ category: "color",
743
+ type: "color"
744
+ },
745
+ "color-accent-hover": {
746
+ category: "color",
747
+ type: "color"
748
+ },
749
+ "color-accent-active": {
750
+ category: "color",
751
+ type: "color"
752
+ },
753
+ "color-on-accent": {
754
+ category: "color",
755
+ type: "color"
756
+ },
757
+ "color-accent-subtle": {
758
+ category: "color",
759
+ type: "color"
760
+ },
761
+ "color-accent-text": {
762
+ category: "color",
763
+ type: "color"
764
+ },
765
+ "color-danger": {
766
+ category: "color",
767
+ type: "color"
768
+ },
769
+ "color-danger-hover": {
770
+ category: "color",
771
+ type: "color"
772
+ },
773
+ "color-on-danger": {
774
+ category: "color",
775
+ type: "color"
776
+ },
777
+ "color-danger-subtle": {
778
+ category: "color",
779
+ type: "color"
780
+ },
781
+ "color-danger-text": {
782
+ category: "color",
783
+ type: "color"
784
+ },
785
+ "color-warning": {
786
+ category: "color",
787
+ type: "color"
788
+ },
789
+ "color-on-warning": {
790
+ category: "color",
791
+ type: "color"
792
+ },
793
+ "color-warning-subtle": {
794
+ category: "color",
795
+ type: "color"
796
+ },
797
+ "color-warning-text": {
798
+ category: "color",
799
+ type: "color"
800
+ },
801
+ "color-success": {
802
+ category: "color",
803
+ type: "color"
804
+ },
805
+ "color-on-success": {
806
+ category: "color",
807
+ type: "color"
808
+ },
809
+ "color-success-subtle": {
810
+ category: "color",
811
+ type: "color"
812
+ },
813
+ "color-success-text": {
814
+ category: "color",
815
+ type: "color"
816
+ },
817
+ "focus-ring-color": {
818
+ category: "focus",
819
+ type: "color"
820
+ },
821
+ "focus-ring-width": {
822
+ category: "focus",
823
+ type: "length"
824
+ },
825
+ "focus-ring-offset": {
826
+ category: "focus",
827
+ type: "length"
828
+ },
829
+ "focus-ring": {
830
+ category: "focus",
831
+ type: "outline"
832
+ },
833
+ "font-family": {
834
+ category: "typography",
835
+ type: "font-family"
836
+ },
837
+ "font-family-mono": {
838
+ category: "typography",
839
+ type: "font-family"
840
+ },
841
+ "font-size-small": {
842
+ category: "typography",
843
+ type: "length"
844
+ },
845
+ "font-size-body": {
846
+ category: "typography",
847
+ type: "length"
848
+ },
849
+ "font-size-title": {
850
+ category: "typography",
851
+ type: "length"
852
+ },
853
+ "font-weight-regular": {
854
+ category: "typography",
855
+ type: "font-weight"
856
+ },
857
+ "font-weight-strong": {
858
+ category: "typography",
859
+ type: "font-weight"
860
+ },
861
+ "line-height-body": {
862
+ category: "typography",
863
+ type: "number"
864
+ },
865
+ "line-height-tight": {
866
+ category: "typography",
867
+ type: "number"
868
+ },
869
+ "letter-spacing": {
870
+ category: "typography",
871
+ type: "length"
872
+ },
873
+ "control-height": {
874
+ category: "size",
875
+ type: "length",
876
+ density: true
877
+ },
878
+ "control-height-small": {
879
+ category: "size",
880
+ type: "length",
881
+ density: true
882
+ },
883
+ "control-padding-x": {
884
+ category: "space",
885
+ type: "length",
886
+ density: true
887
+ },
888
+ "control-gap": {
889
+ category: "space",
890
+ type: "length",
891
+ density: true
892
+ },
893
+ "icon-size": {
894
+ category: "size",
895
+ type: "length",
896
+ density: true
897
+ },
898
+ "target-size": {
899
+ category: "size",
900
+ type: "length",
901
+ density: true
902
+ },
903
+ "gap-tight": {
904
+ category: "space",
905
+ type: "length",
906
+ density: true
907
+ },
908
+ "gap-normal": {
909
+ category: "space",
910
+ type: "length",
911
+ density: true
912
+ },
913
+ "gap-loose": {
914
+ category: "space",
915
+ type: "length",
916
+ density: true
917
+ },
918
+ "inset-tight": {
919
+ category: "space",
920
+ type: "length",
921
+ density: true
922
+ },
923
+ "inset-normal": {
924
+ category: "space",
925
+ type: "length",
926
+ density: true
927
+ },
928
+ "inset-loose": {
929
+ category: "space",
930
+ type: "length",
931
+ density: true
932
+ },
933
+ "surface-width-small": {
934
+ category: "size",
935
+ type: "length"
936
+ },
937
+ "surface-width-medium": {
938
+ category: "size",
939
+ type: "length"
940
+ },
941
+ "surface-width-large": {
942
+ category: "size",
943
+ type: "length"
944
+ },
945
+ "track-size": {
946
+ category: "size",
947
+ type: "length"
948
+ },
949
+ "radius-control": {
950
+ category: "shape",
951
+ type: "length"
952
+ },
953
+ "radius-surface": {
954
+ category: "shape",
955
+ type: "length"
956
+ },
957
+ "radius-round": {
958
+ category: "shape",
959
+ type: "length"
960
+ },
961
+ "border-width": {
962
+ category: "shape",
963
+ type: "length"
964
+ },
965
+ "shadow-raised": {
966
+ category: "shadow",
967
+ type: "shadow"
968
+ },
969
+ "shadow-overlay": {
970
+ category: "shadow",
971
+ type: "shadow"
972
+ },
973
+ "motion-duration-feedback": {
974
+ category: "motion",
975
+ type: "duration"
976
+ },
977
+ "motion-duration-enter": {
978
+ category: "motion",
979
+ type: "duration"
980
+ },
981
+ "motion-duration-exit": {
982
+ category: "motion",
983
+ type: "duration"
984
+ },
985
+ "motion-easing-standard": {
986
+ category: "motion",
987
+ type: "easing"
988
+ },
989
+ "motion-easing-enter": {
990
+ category: "motion",
991
+ type: "easing"
992
+ },
993
+ "motion-easing-exit": {
994
+ category: "motion",
995
+ type: "easing"
996
+ },
997
+ "motion-duration-loop": {
998
+ category: "motion",
999
+ type: "duration"
1000
+ },
1001
+ "motion-easing-loop": {
1002
+ category: "motion",
1003
+ type: "easing"
1004
+ },
1005
+ "z-raised": {
1006
+ category: "z-index",
1007
+ type: "integer"
1008
+ },
1009
+ "z-sticky": {
1010
+ category: "z-index",
1011
+ type: "integer"
1012
+ },
1013
+ "z-overlay": {
1014
+ category: "z-index",
1015
+ type: "integer"
1016
+ },
1017
+ "opacity-disabled": {
1018
+ category: "opacity",
1019
+ type: "number"
1020
+ }
1021
+ };
1022
+ var component = {
1023
+ "button-height": { fallback: "control-height" },
1024
+ "button-small-height": { fallback: "control-height-small" },
1025
+ "button-padding-x": { fallback: "control-padding-x" },
1026
+ "button-gap": { fallback: "control-gap" },
1027
+ "button-icon-size": { fallback: "icon-size" },
1028
+ "button-radius": { fallback: "radius-control" },
1029
+ "button-font-weight": { fallback: "font-weight-strong" },
1030
+ "button-bg": { fallback: "color-control" },
1031
+ "button-bg-hover": { fallback: "color-control-hover" },
1032
+ "button-bg-active": { fallback: "color-control-active" },
1033
+ "button-fg": { fallback: "color-text" },
1034
+ "button-border-color": { fallback: "color-border-strong" },
1035
+ "button-primary-bg": { fallback: "color-accent" },
1036
+ "button-primary-bg-hover": { fallback: "color-accent-hover" },
1037
+ "button-primary-bg-active": { fallback: "color-accent-active" },
1038
+ "button-primary-fg": { fallback: "color-on-accent" },
1039
+ "button-quiet-bg-hover": { fallback: "color-control-hover" },
1040
+ "button-quiet-bg-active": { fallback: "color-control-active" },
1041
+ "button-danger-bg": { fallback: "color-danger" },
1042
+ "button-danger-bg-hover": { fallback: "color-danger-hover" },
1043
+ "button-danger-fg": { fallback: "color-on-danger" },
1044
+ "button-pressed-bg": { fallback: "color-accent-subtle" },
1045
+ "button-pressed-border-color": { fallback: "color-accent" },
1046
+ "button-pressed-fg": { fallback: "color-text" },
1047
+ "toolbar-bg": { fallback: "color-surface" },
1048
+ "toolbar-border-color": { fallback: "color-border" },
1049
+ "toolbar-radius": { fallback: "radius-surface" },
1050
+ "toolbar-padding": { fallback: "inset-tight" },
1051
+ "toolbar-gap": { fallback: "gap-tight" },
1052
+ "toolbar-group-gap": { fallback: "gap-tight" },
1053
+ "toolbar-separator-color": { fallback: "color-border" },
1054
+ "segmented-control-height": { fallback: "control-height" },
1055
+ "segmented-control-small-height": { fallback: "control-height-small" },
1056
+ "segmented-control-padding": { fallback: "gap-tight" },
1057
+ "segmented-control-gap": { fallback: "gap-tight" },
1058
+ "segmented-control-radius": { fallback: "radius-control" },
1059
+ "segmented-control-bg": { fallback: "color-surface-sunken" },
1060
+ "segmented-control-border-color": { fallback: "color-border-strong" },
1061
+ "segmented-control-option-padding-x": { fallback: "control-padding-x" },
1062
+ "segmented-control-option-fg": { fallback: "color-text" },
1063
+ "segmented-control-option-bg-hover": { fallback: "color-control-hover" },
1064
+ "segmented-control-option-checked-bg": { fallback: "color-surface-raised" },
1065
+ "segmented-control-option-checked-fg": { fallback: "color-text" },
1066
+ "segmented-control-option-checked-border-color": { fallback: "color-border-strong" },
1067
+ "dialog-bg": { fallback: "color-surface-raised" },
1068
+ "dialog-fg": { fallback: "color-text" },
1069
+ "dialog-border-color": { fallback: "color-border" },
1070
+ "dialog-radius": { fallback: "radius-surface" },
1071
+ "dialog-shadow": { fallback: "shadow-overlay" },
1072
+ "dialog-padding": { fallback: "inset-loose" },
1073
+ "dialog-gap": { fallback: "gap-loose" },
1074
+ "dialog-backdrop": { fallback: "color-overlay" },
1075
+ "dialog-title-font-size": { fallback: "font-size-title" },
1076
+ "dialog-small-width": { fallback: "surface-width-small" },
1077
+ "dialog-width": { fallback: "surface-width-medium" },
1078
+ "dialog-large-width": { fallback: "surface-width-large" },
1079
+ "spinner-size": { fallback: "icon-size" },
1080
+ "spinner-thickness": { fallback: "focus-ring-width" },
1081
+ "spinner-color": { fallback: "color-accent" },
1082
+ "spinner-track-color": { fallback: "color-border" },
1083
+ "spinner-duration": { fallback: "motion-duration-loop" },
1084
+ "progress-height": { fallback: "track-size" },
1085
+ "progress-radius": { fallback: "radius-round" },
1086
+ "progress-track-color": { fallback: "color-surface-sunken" },
1087
+ "progress-fill-color": { fallback: "color-accent" },
1088
+ "progress-duration": { fallback: "motion-duration-loop" },
1089
+ "slider-track-size": { fallback: "track-size" },
1090
+ "slider-track-color": { fallback: "color-border-strong" },
1091
+ "slider-radius": { fallback: "radius-round" },
1092
+ "slider-thumb-size": { fallback: "icon-size" },
1093
+ "slider-thumb-color": { fallback: "color-accent" },
1094
+ "slider-thumb-color-hover": { fallback: "color-accent-hover" },
1095
+ "slider-thumb-color-active": { fallback: "color-accent-active" },
1096
+ "field-gap": { fallback: "gap-tight" },
1097
+ "field-label-fg": { fallback: "color-text" },
1098
+ "field-label-font-weight": { fallback: "font-weight-strong" },
1099
+ "field-description-fg": { fallback: "color-text-muted" },
1100
+ "field-error-fg": { fallback: "color-danger-text" },
1101
+ "field-message-font-size": { fallback: "font-size-small" },
1102
+ "number-field-height": { fallback: "control-height" },
1103
+ "number-field-padding-x": { fallback: "control-padding-x" },
1104
+ "number-field-radius": { fallback: "radius-control" },
1105
+ "number-field-bg": { fallback: "color-surface" },
1106
+ "number-field-fg": { fallback: "color-text" },
1107
+ "number-field-border-color": { fallback: "color-border-strong" },
1108
+ "number-field-invalid-border-color": { fallback: "color-danger-text" },
1109
+ "file-drop-zone-gap": { fallback: "gap-normal" },
1110
+ "file-drop-zone-padding": { fallback: "inset-loose" },
1111
+ "file-drop-zone-radius": { fallback: "radius-surface" },
1112
+ "file-drop-zone-border-color": { fallback: "color-border-strong" },
1113
+ "file-drop-zone-dragging-border-color": { fallback: "color-accent" },
1114
+ "file-drop-zone-dragging-bg": { fallback: "color-accent-subtle" },
1115
+ "file-drop-zone-hint-fg": { fallback: "color-text-muted" }
1116
+ };
1117
+ function baseDefinitions() {
1118
+ const list = [];
1119
+ const add = (name, category, type) => {
1120
+ list.push({
1121
+ name,
1122
+ level: "base",
1123
+ category,
1124
+ type,
1125
+ density: false
1126
+ });
1127
+ };
1128
+ for (const hue of HUES) for (const step of STEPS) add(`${hue}-${step}`, "color", "color");
1129
+ add("white", "color", "color");
1130
+ add("black", "color", "color");
1131
+ for (let step = 1; step <= 12; step++) add(`space-${step}`, "space", "length");
1132
+ for (const size of [
1133
+ "none",
1134
+ "sm",
1135
+ "md",
1136
+ "lg",
1137
+ "full"
1138
+ ]) add(`radius-${size}`, "shape", "length");
1139
+ add("border-width-1", "shape", "length");
1140
+ add("border-width-2", "shape", "length");
1141
+ add("font-sans", "typography", "font-family");
1142
+ add("font-mono", "typography", "font-family");
1143
+ for (let step = 1; step <= 7; step++) add(`font-size-${step}`, "typography", "length");
1144
+ for (const weight of [
1145
+ 400,
1146
+ 500,
1147
+ 600,
1148
+ 700
1149
+ ]) add(`font-weight-${weight}`, "typography", "font-weight");
1150
+ for (const leading of [
1151
+ "tight",
1152
+ "normal",
1153
+ "relaxed"
1154
+ ]) add(`leading-${leading}`, "typography", "number");
1155
+ for (const speed of [
1156
+ "fast",
1157
+ "normal",
1158
+ "slow"
1159
+ ]) add(`duration-${speed}`, "motion", "duration");
1160
+ for (const easing of [
1161
+ "standard",
1162
+ "decelerate",
1163
+ "accelerate"
1164
+ ]) add(`easing-${easing}`, "motion", "easing");
1165
+ return list;
1166
+ }
1167
+ function semanticDefinitions() {
1168
+ return Object.entries(semantic).map(([name, spec]) => ({
1169
+ name,
1170
+ level: "semantic",
1171
+ category: spec.category,
1172
+ type: spec.type,
1173
+ density: "density" in spec
1174
+ }));
1175
+ }
1176
+ var tokens = /* @__PURE__ */ allDefinitions();
1177
+ function allDefinitions() {
1178
+ const semanticList = semanticDefinitions();
1179
+ return Object.freeze([
1180
+ ...baseDefinitions(),
1181
+ ...semanticList,
1182
+ ...componentDefinitions(semanticList)
1183
+ ].map((definition) => Object.freeze(definition)));
1184
+ }
1185
+ function componentDefinitions(semanticList) {
1186
+ const byFallback = new Map(semanticList.map((definition) => [definition.name, definition]));
1187
+ return Object.entries(component).map(([name, spec]) => {
1188
+ const fallback = byFallback.get(spec.fallback);
1189
+ return {
1190
+ name,
1191
+ level: "component",
1192
+ category: fallback.category,
1193
+ type: fallback.type,
1194
+ density: false,
1195
+ fallback: spec.fallback
1196
+ };
1197
+ });
1198
+ }
1199
+ var tokensByName = /* @__PURE__ */ byName(tokens);
1200
+ function byName(list) {
1201
+ return new Map(list.map((definition) => [definition.name, definition]));
1202
+ }
1203
+ var densityTokenNames = /* @__PURE__ */ densityNames();
1204
+ function densityNames() {
1205
+ return tokens.filter((definition) => definition.density).map((definition) => definition.name);
1206
+ }
1207
+ // src/tokens/themes.ts
1208
+ var shared = {
1209
+ "focus-ring-width": "2px",
1210
+ "focus-ring-offset": "2px",
1211
+ "focus-ring": "var(--hm-focus-ring-width) solid var(--hm-focus-ring-color)",
1212
+ "font-family": "var(--hm-font-sans)",
1213
+ "font-family-mono": "var(--hm-font-mono)",
1214
+ "font-size-small": "var(--hm-font-size-2)",
1215
+ "font-size-body": "var(--hm-font-size-3)",
1216
+ "font-size-title": "var(--hm-font-size-6)",
1217
+ "font-weight-regular": "var(--hm-font-weight-400)",
1218
+ "font-weight-strong": "var(--hm-font-weight-600)",
1219
+ "line-height-body": "var(--hm-leading-normal)",
1220
+ "line-height-tight": "var(--hm-leading-tight)",
1221
+ "letter-spacing": "0",
1222
+ "radius-control": "var(--hm-radius-md)",
1223
+ "radius-surface": "var(--hm-radius-lg)",
1224
+ "radius-round": "var(--hm-radius-full)",
1225
+ "border-width": "var(--hm-border-width-1)",
1226
+ "motion-duration-feedback": "var(--hm-duration-fast)",
1227
+ "motion-duration-enter": "var(--hm-duration-normal)",
1228
+ "motion-duration-exit": "var(--hm-duration-fast)",
1229
+ "motion-easing-standard": "var(--hm-easing-standard)",
1230
+ "motion-easing-enter": "var(--hm-easing-decelerate)",
1231
+ "motion-easing-exit": "var(--hm-easing-accelerate)",
1232
+ "z-raised": "1",
1233
+ "z-sticky": "10",
1234
+ "z-overlay": "100",
1235
+ "opacity-disabled": "0.5",
1236
+ "surface-width-small": "24rem",
1237
+ "surface-width-medium": "32rem",
1238
+ "surface-width-large": "48rem",
1239
+ "track-size": "0.375rem",
1240
+ "motion-duration-loop": "1s",
1241
+ "motion-easing-loop": "linear"
1242
+ };
1243
+ function withShared(values) {
1244
+ return {
1245
+ ...shared,
1246
+ ...values
1247
+ };
1248
+ }
1249
+ var lightValues = /* @__PURE__ */ withShared({
1250
+ "color-scheme": "light",
1251
+ "color-bg": "var(--hm-white)",
1252
+ "color-surface": "var(--hm-gray-50)",
1253
+ "color-surface-raised": "var(--hm-white)",
1254
+ "color-surface-sunken": "var(--hm-gray-100)",
1255
+ "color-overlay": "oklch(0.26 0.01 260 / 0.5)",
1256
+ "color-text": "var(--hm-gray-900)",
1257
+ "color-text-muted": "var(--hm-gray-700)",
1258
+ "color-text-disabled": "var(--hm-gray-400)",
1259
+ "color-border": "var(--hm-gray-200)",
1260
+ "color-border-strong": "var(--hm-gray-600)",
1261
+ "color-control": "var(--hm-gray-100)",
1262
+ "color-control-hover": "var(--hm-gray-200)",
1263
+ "color-control-active": "var(--hm-gray-300)",
1264
+ "color-accent": "var(--hm-blue-700)",
1265
+ "color-accent-hover": "var(--hm-blue-800)",
1266
+ "color-accent-active": "var(--hm-blue-900)",
1267
+ "color-on-accent": "var(--hm-white)",
1268
+ "color-accent-subtle": "var(--hm-blue-100)",
1269
+ "color-accent-text": "var(--hm-blue-700)",
1270
+ "color-danger": "var(--hm-red-600)",
1271
+ "color-danger-hover": "var(--hm-red-700)",
1272
+ "color-on-danger": "var(--hm-white)",
1273
+ "color-danger-subtle": "var(--hm-red-100)",
1274
+ "color-danger-text": "var(--hm-red-700)",
1275
+ "color-warning": "var(--hm-amber-400)",
1276
+ "color-on-warning": "var(--hm-gray-950)",
1277
+ "color-warning-subtle": "var(--hm-amber-100)",
1278
+ "color-warning-text": "var(--hm-amber-800)",
1279
+ "color-success": "var(--hm-green-700)",
1280
+ "color-on-success": "var(--hm-white)",
1281
+ "color-success-subtle": "var(--hm-green-100)",
1282
+ "color-success-text": "var(--hm-green-700)",
1283
+ "focus-ring-color": "var(--hm-blue-700)",
1284
+ "shadow-raised": "0 1px 2px oklch(0 0 0 / 0.06), 0 4px 12px oklch(0 0 0 / 0.08)",
1285
+ "shadow-overlay": "0 8px 24px oklch(0 0 0 / 0.12), 0 24px 48px oklch(0 0 0 / 0.12)"
1286
+ });
1287
+ var darkValues = /* @__PURE__ */ withShared({
1288
+ "color-scheme": "dark",
1289
+ "color-bg": "var(--hm-gray-950)",
1290
+ "color-surface": "var(--hm-gray-900)",
1291
+ "color-surface-raised": "var(--hm-gray-800)",
1292
+ "color-surface-sunken": "var(--hm-black)",
1293
+ "color-overlay": "oklch(0 0 0 / 0.6)",
1294
+ "color-text": "var(--hm-gray-50)",
1295
+ "color-text-muted": "var(--hm-gray-300)",
1296
+ "color-text-disabled": "var(--hm-gray-600)",
1297
+ "color-border": "var(--hm-gray-800)",
1298
+ "color-border-strong": "var(--hm-gray-400)",
1299
+ "color-control": "var(--hm-gray-800)",
1300
+ "color-control-hover": "var(--hm-gray-700)",
1301
+ "color-control-active": "var(--hm-gray-900)",
1302
+ "color-accent": "var(--hm-blue-400)",
1303
+ "color-accent-hover": "var(--hm-blue-300)",
1304
+ "color-accent-active": "var(--hm-blue-200)",
1305
+ "color-on-accent": "var(--hm-gray-950)",
1306
+ "color-accent-subtle": "var(--hm-blue-900)",
1307
+ "color-accent-text": "var(--hm-blue-300)",
1308
+ "color-danger": "var(--hm-red-400)",
1309
+ "color-danger-hover": "var(--hm-red-300)",
1310
+ "color-on-danger": "var(--hm-gray-950)",
1311
+ "color-danger-subtle": "var(--hm-red-950)",
1312
+ "color-danger-text": "var(--hm-red-300)",
1313
+ "color-warning": "var(--hm-amber-400)",
1314
+ "color-on-warning": "var(--hm-gray-950)",
1315
+ "color-warning-subtle": "var(--hm-amber-950)",
1316
+ "color-warning-text": "var(--hm-amber-300)",
1317
+ "color-success": "var(--hm-green-400)",
1318
+ "color-on-success": "var(--hm-gray-950)",
1319
+ "color-success-subtle": "var(--hm-green-950)",
1320
+ "color-success-text": "var(--hm-green-300)",
1321
+ "focus-ring-color": "var(--hm-blue-400)",
1322
+ "shadow-raised": "0 1px 2px oklch(0 0 0 / 0.4), 0 4px 12px oklch(0 0 0 / 0.4)",
1323
+ "shadow-overlay": "0 8px 24px oklch(0 0 0 / 0.5), 0 24px 48px oklch(0 0 0 / 0.5)"
1324
+ });
1325
+ var comfortableValues = {
1326
+ "control-height": "2rem",
1327
+ "control-height-small": "1.5rem",
1328
+ "control-padding-x": "var(--hm-space-3)",
1329
+ "control-gap": "var(--hm-space-2)",
1330
+ "icon-size": "1.25rem",
1331
+ "target-size": "1.5rem",
1332
+ "gap-tight": "var(--hm-space-1)",
1333
+ "gap-normal": "var(--hm-space-2)",
1334
+ "gap-loose": "var(--hm-space-4)",
1335
+ "inset-tight": "var(--hm-space-2)",
1336
+ "inset-normal": "var(--hm-space-3)",
1337
+ "inset-loose": "var(--hm-space-5)"
1338
+ };
1339
+ var compactValues = {
1340
+ "control-height": "1.75rem",
1341
+ "control-padding-x": "var(--hm-space-2)",
1342
+ "control-gap": "var(--hm-space-1)",
1343
+ "icon-size": "1rem",
1344
+ "gap-tight": "0.125rem",
1345
+ "gap-normal": "var(--hm-space-1)",
1346
+ "gap-loose": "var(--hm-space-3)",
1347
+ "inset-tight": "var(--hm-space-1)",
1348
+ "inset-normal": "var(--hm-space-2)",
1349
+ "inset-loose": "var(--hm-space-4)"
1350
+ };
1351
+ var coarsePointerValues = {
1352
+ "control-height": "2.75rem",
1353
+ "control-height-small": "2.75rem",
1354
+ "target-size": "2.75rem"
1355
+ };
1356
+ // src/theme/css-writer.ts
1357
+ var DENSITY_TOKENS$1 = /* @__PURE__ */ new Set(densityTokenNames);
1358
+ var TOKEN_ORDER = /* @__PURE__ */ tokenOrder();
1359
+ function tokenOrder() {
1360
+ return new Map(tokens.map((definition, index) => [definition.name, index]));
1361
+ }
1362
+ var MAX_SELECTOR_LENGTH = 500;
1363
+ var LAYER_ORDER = "@layer hm.tokens, hm.base, hm.components, hm.sdk;\n@layer hm.tokens.default, hm.tokens.theme;";
1364
+ var SELECTOR_CHARACTERS = /^[A-Za-z0-9\s_\-.#:[\]="'()*>+~,|^$]+$/;
1365
+ function invalidSelector(selector, reason) {
1366
+ return new UiError("INVALID_THEME_SELECTOR", `The selector "${selector.slice(0, 200)}" can't be used: ${reason}.`, { details: {
1367
+ selector: selector.slice(0, 200),
1368
+ reason
1369
+ } });
1370
+ }
1371
+ function validateSelector(selector) {
1372
+ if (typeof selector !== "string") throw invalidSelector(String(selector), "selectors must be strings");
1373
+ const trimmed = selector.trim().replace(/\s+/g, " ");
1374
+ if (trimmed.length === 0 || trimmed.length > MAX_SELECTOR_LENGTH) throw invalidSelector(selector, `selectors must have 1 to ${MAX_SELECTOR_LENGTH} characters`);
1375
+ if (!SELECTOR_CHARACTERS.test(trimmed)) throw invalidSelector(selector, "it contains a character that isn't allowed");
1376
+ const stack = [];
1377
+ let quote;
1378
+ for (const char of trimmed) {
1379
+ if (quote) {
1380
+ if (char === quote) quote = void 0;
1381
+ else if (!/[A-Za-z0-9 _.:-]/.test(char)) throw invalidSelector(selector, "quoted values may only contain letters, digits, spaces, _ . : and -");
1382
+ continue;
1383
+ }
1384
+ if (char === "\"" || char === "'") {
1385
+ if (stack.at(-1) !== "[") throw invalidSelector(selector, "quotes are only allowed in attribute selectors");
1386
+ quote = char;
1387
+ } else if (char === "(" || char === "[") stack.push(char);
1388
+ else if (char === ")" || char === "]") {
1389
+ if (stack.pop() !== (char === ")" ? "(" : "[")) throw invalidSelector(selector, "brackets aren't balanced");
1390
+ }
1391
+ }
1392
+ if (quote || stack.length > 0) throw invalidSelector(selector, "brackets or quotes aren't balanced");
1393
+ return trimmed;
1394
+ }
1395
+ function byTokenOrder(a, b) {
1396
+ return (TOKEN_ORDER.get(a) ?? Number.MAX_SAFE_INTEGER) - (TOKEN_ORDER.get(b) ?? Number.MAX_SAFE_INTEGER) || (a < b ? -1 : a > b ? 1 : 0);
1397
+ }
1398
+ var LINE_WIDTH = 100;
1399
+ function declaration(indent, name, value) {
1400
+ const line = `${indent}--hm-${name}: ${value};`;
1401
+ return line.length <= LINE_WIDTH ? line : `${indent}--hm-${name}:\n${indent} ${value};`;
1402
+ }
1403
+ function renderBlocks(blocks, indent) {
1404
+ return blocks.filter((block) => Object.keys(block.values).length > 0).map((block) => {
1405
+ const inner = block.media ? `${indent} ` : indent;
1406
+ const declarations = Object.keys(block.values).sort(byTokenOrder).map((name) => declaration(`${inner} `, name, block.values[name])).join("\n");
1407
+ const rule = `${inner}${block.selectors.join(`,\n${inner}`)} {\n${declarations}\n${inner}}`;
1408
+ return block.media ? `${indent}@media ${block.media} {\n${rule}\n${indent}}` : rule;
1409
+ }).join("\n\n");
1410
+ }
1411
+ function splitTokens(values) {
1412
+ const scheme = {};
1413
+ const density = {};
1414
+ for (const [name, value] of Object.entries(values)) (DENSITY_TOKENS$1.has(name) ? density : scheme)[name] = value;
1415
+ return {
1416
+ scheme,
1417
+ density
1418
+ };
1419
+ }
1420
+ function themeBlocks(root, light, dark) {
1421
+ const lightTokens = splitTokens(light.tokens);
1422
+ const density = [
1423
+ {
1424
+ selectors: [root, "[data-hm-density=\"comfortable\"]"],
1425
+ values: lightTokens.density
1426
+ },
1427
+ {
1428
+ selectors: [`${root}[data-hm-density="compact"]`, "[data-hm-density=\"compact\"]"],
1429
+ values: light.compact
1430
+ },
1431
+ {
1432
+ media: "(pointer: coarse)",
1433
+ selectors: [
1434
+ root,
1435
+ `${root}[data-hm-density]`,
1436
+ "[data-hm-density]"
1437
+ ],
1438
+ values: light.coarsePointer
1439
+ }
1440
+ ];
1441
+ if (!dark) return [{
1442
+ selectors: [root],
1443
+ values: lightTokens.scheme
1444
+ }, ...density];
1445
+ const darkTokens = splitTokens(dark.tokens).scheme;
1446
+ return [
1447
+ {
1448
+ selectors: [
1449
+ root,
1450
+ "[data-hm-theme=\"light\"]",
1451
+ "[data-hm-theme=\"system\"]"
1452
+ ],
1453
+ values: lightTokens.scheme
1454
+ },
1455
+ {
1456
+ media: "(prefers-color-scheme: dark)",
1457
+ selectors: [root, "[data-hm-theme=\"system\"]"],
1458
+ values: darkTokens
1459
+ },
1460
+ {
1461
+ selectors: [`${root}[data-hm-theme="light"]`, "[data-hm-theme=\"light\"]"],
1462
+ values: lightTokens.scheme
1463
+ },
1464
+ {
1465
+ selectors: [`${root}[data-hm-theme="dark"]`, "[data-hm-theme=\"dark\"]"],
1466
+ values: darkTokens
1467
+ },
1468
+ ...density
1469
+ ];
1470
+ }
1471
+ function writeThemeCss(light, dark, selector) {
1472
+ const css = `${LAYER_ORDER}\n\n@layer hm.tokens.theme {\n @scope (${validateSelector(selector)}) {\n${renderBlocks(themeBlocks(":scope", light, dark), " ")}\n }\n}\n`;
1473
+ if (css.includes("<")) throw new UiError("INVALID_THEME_TOKEN", "The theme produced unsafe CSS.", { details: {
1474
+ token: "theme",
1475
+ value: "",
1476
+ reason: "the CSS contains <"
1477
+ } });
1478
+ return css;
1479
+ }
1480
+ // src/theme/create-theme.ts
1481
+ var COMPONENT_TOKEN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)+$/;
1482
+ var DENSITY_TOKENS = /* @__PURE__ */ new Set(densityTokenNames);
1483
+ var REQUIRED_TOKENS = /* @__PURE__ */ requiredTokens();
1484
+ function requiredTokens() {
1485
+ return tokens.filter((definition) => definition.level === "semantic" && definition.name !== "color-scheme").map((definition) => definition.name);
1486
+ }
1487
+ function invalidToken(token, value, reason) {
1488
+ const shown = typeof value === "string" ? value.slice(0, 200) : typeof value;
1489
+ return new UiError("INVALID_THEME_TOKEN", `The theme token "${token}" can't be used: ${reason}.`, { details: {
1490
+ token,
1491
+ value: shown,
1492
+ reason
1493
+ } });
1494
+ }
1495
+ function isPlainObject(value) {
1496
+ if (typeof value !== "object" || value === null) return false;
1497
+ const prototype = Object.getPrototypeOf(value);
1498
+ return prototype === Object.prototype || prototype === null;
1499
+ }
1500
+ function validateTokens(input, where, allowed) {
1501
+ if (input === void 0) return {};
1502
+ if (!isPlainObject(input)) throw invalidToken(where, input, `${where} must be a plain object`);
1503
+ const output = {};
1504
+ for (const [name, value] of Object.entries(input)) {
1505
+ const definition = tokensByName.get(name);
1506
+ if (name === "color-scheme") throw invalidToken(name, value, "set the colour scheme with the colorScheme option");
1507
+ if (allowed && !allowed.has(name)) throw invalidToken(name, value, `only density tokens can be set in ${where}`);
1508
+ if (!definition && !COMPONENT_TOKEN.test(name)) throw invalidToken(name, value, "it isn't a token name");
1509
+ if (typeof value !== "string") throw invalidToken(name, value, "values must be strings");
1510
+ try {
1511
+ output[name] = validateValue(value, definition?.type);
1512
+ } catch (error) {
1513
+ if (error instanceof CssValueError) throw invalidToken(name, value, error.message);
1514
+ throw error;
1515
+ }
1516
+ }
1517
+ return output;
1518
+ }
1519
+ function freeze(theme) {
1520
+ Object.freeze(theme.tokens);
1521
+ Object.freeze(theme.compact);
1522
+ Object.freeze(theme.coarsePointer);
1523
+ Object.freeze(theme);
1524
+ registerTheme(theme, writeThemeCss);
1525
+ return theme;
1526
+ }
1527
+ function builtInTheme(colorScheme, values) {
1528
+ return freeze({
1529
+ colorScheme,
1530
+ tokens: {
1531
+ ...baseValues,
1532
+ ...values,
1533
+ ...comfortableValues
1534
+ },
1535
+ compact: { ...compactValues },
1536
+ coarsePointer: { ...coarsePointerValues }
1537
+ });
1538
+ }
1539
+ var lightTheme = /* @__PURE__ */ builtInTheme("light", lightValues);
1540
+ var darkTheme = /* @__PURE__ */ builtInTheme("dark", darkValues);
1541
+ function warnAboutContrast(theme) {
1542
+ const { failures, unchecked } = checkContrast(theme);
1543
+ if (failures.length > 0) {
1544
+ const list = failures.map((f) => `${f.foreground} on ${f.background}: ${f.ratio}:1, needs ${f.minimum}:1`).join("; ");
1545
+ if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") warnInDevelopment(`This theme is below WCAG 2.2 AA contrast. ${list}.`);
1546
+ }
1547
+ if (unchecked.length > 0) {
1548
+ const list = unchecked.map((u) => `${u.foreground} on ${u.background}`).join("; ");
1549
+ if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") warnInDevelopment(`These colour pairs couldn't be checked for contrast, so check them by hand: ${list}.`);
1550
+ }
1551
+ }
1552
+ function resolveParent(parent) {
1553
+ if (parent === void 0) return;
1554
+ if (parent === "light") return lightTheme;
1555
+ if (parent === "dark") return darkTheme;
1556
+ return toTheme(parent);
1557
+ }
1558
+ function createTheme(input) {
1559
+ if (!isPlainObject(input)) throw invalidToken("theme", input, "createTheme takes an options object");
1560
+ const parent = resolveParent(input.extends);
1561
+ const own = validateTokens(input.tokens, "tokens");
1562
+ if (!parent) {
1563
+ const missing = REQUIRED_TOKENS.filter((name) => !(name in own));
1564
+ if (missing.length > 0) throw invalidToken(missing[0], void 0, `a theme without "extends" needs every semantic token; missing ${missing.join(", ")}`);
1565
+ }
1566
+ const colorScheme = input.colorScheme ?? parent?.colorScheme ?? "light";
1567
+ if (colorScheme !== "light" && colorScheme !== "dark") throw invalidToken("color-scheme", colorScheme, "colorScheme must be \"light\" or \"dark\"");
1568
+ const theme = freeze({
1569
+ colorScheme,
1570
+ tokens: {
1571
+ ...parent?.tokens,
1572
+ ...own,
1573
+ "color-scheme": colorScheme
1574
+ },
1575
+ compact: {
1576
+ ...parent?.compact ?? {},
1577
+ ...validateTokens(input.density?.compact, "density.compact", DENSITY_TOKENS)
1578
+ },
1579
+ coarsePointer: {
1580
+ ...parent?.coarsePointer ?? coarsePointerValues,
1581
+ ...validateTokens(input.coarsePointer, "coarsePointer", DENSITY_TOKENS)
1582
+ }
1583
+ });
1584
+ if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") warnAboutContrast(theme);
1585
+ return theme;
1586
+ }
1587
+ function toTheme(value) {
1588
+ if (cssWriterOf(value)) return value;
1589
+ if (!isPlainObject(value) || !isPlainObject(value["tokens"])) throw invalidToken("theme", value, "expected a theme from createTheme");
1590
+ const scheme = value["colorScheme"];
1591
+ const { "color-scheme": _ignored, ...tokenValues } = value["tokens"];
1592
+ const compact = value["compact"];
1593
+ const coarsePointer = value["coarsePointer"];
1594
+ return createTheme({
1595
+ extends: void 0,
1596
+ colorScheme: scheme === "dark" ? "dark" : "light",
1597
+ tokens: tokenValues,
1598
+ ...isPlainObject(compact) ? { density: { compact } } : {},
1599
+ ...isPlainObject(coarsePointer) ? { coarsePointer } : {}
1600
+ });
1601
+ }
1602
+ // src/theme/theme-to-css.ts
1603
+ function themeToCss(theme, selector = ":root") {
1604
+ const isPair = typeof theme === "object" && theme !== null && isThemePair(theme);
1605
+ return writeThemeCss(toTheme(isPair ? theme.light : theme), isPair ? toTheme(theme.dark) : void 0, selector);
1606
+ }
1607
+ export { UiError, checkContrast, contrastPairs, createTheme, darkTheme, lightTheme, themeToCss, tokens, uiMessages };
1608
+
1609
+ //# sourceMappingURL=index.js.map