@stillwind/host 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1410 @@
1
+ import { a as splitTopLevel, c as withAlpha, configurePlugin, darkModeVariant, i as serializeCss, n as identifier, o as utilityBodies, r as selectorRules, resolveConfig, s as utilityRules, t as cssString } from "./configuration-CnrzO-F3.js";
2
+ import { decodeArbitraryValue } from "@stillwind/native";
3
+ import defaultTheme from "tailwindcss/defaultTheme";
4
+ // src/css/plugins/tailwind/data-type.ts
5
+ const NAMED_COLORS = /* @__PURE__ */ new Set([
6
+ "black",
7
+ "silver",
8
+ "gray",
9
+ "white",
10
+ "maroon",
11
+ "red",
12
+ "purple",
13
+ "fuchsia",
14
+ "green",
15
+ "lime",
16
+ "olive",
17
+ "yellow",
18
+ "navy",
19
+ "blue",
20
+ "teal",
21
+ "aqua",
22
+ "aliceblue",
23
+ "antiquewhite",
24
+ "aqua",
25
+ "aquamarine",
26
+ "azure",
27
+ "beige",
28
+ "bisque",
29
+ "black",
30
+ "blanchedalmond",
31
+ "blue",
32
+ "blueviolet",
33
+ "brown",
34
+ "burlywood",
35
+ "cadetblue",
36
+ "chartreuse",
37
+ "chocolate",
38
+ "coral",
39
+ "cornflowerblue",
40
+ "cornsilk",
41
+ "crimson",
42
+ "cyan",
43
+ "darkblue",
44
+ "darkcyan",
45
+ "darkgoldenrod",
46
+ "darkgray",
47
+ "darkgreen",
48
+ "darkgrey",
49
+ "darkkhaki",
50
+ "darkmagenta",
51
+ "darkolivegreen",
52
+ "darkorange",
53
+ "darkorchid",
54
+ "darkred",
55
+ "darksalmon",
56
+ "darkseagreen",
57
+ "darkslateblue",
58
+ "darkslategray",
59
+ "darkslategrey",
60
+ "darkturquoise",
61
+ "darkviolet",
62
+ "deeppink",
63
+ "deepskyblue",
64
+ "dimgray",
65
+ "dimgrey",
66
+ "dodgerblue",
67
+ "firebrick",
68
+ "floralwhite",
69
+ "forestgreen",
70
+ "fuchsia",
71
+ "gainsboro",
72
+ "ghostwhite",
73
+ "gold",
74
+ "goldenrod",
75
+ "gray",
76
+ "green",
77
+ "greenyellow",
78
+ "grey",
79
+ "honeydew",
80
+ "hotpink",
81
+ "indianred",
82
+ "indigo",
83
+ "ivory",
84
+ "khaki",
85
+ "lavender",
86
+ "lavenderblush",
87
+ "lawngreen",
88
+ "lemonchiffon",
89
+ "lightblue",
90
+ "lightcoral",
91
+ "lightcyan",
92
+ "lightgoldenrodyellow",
93
+ "lightgray",
94
+ "lightgreen",
95
+ "lightgrey",
96
+ "lightpink",
97
+ "lightsalmon",
98
+ "lightseagreen",
99
+ "lightskyblue",
100
+ "lightslategray",
101
+ "lightslategrey",
102
+ "lightsteelblue",
103
+ "lightyellow",
104
+ "lime",
105
+ "limegreen",
106
+ "linen",
107
+ "magenta",
108
+ "maroon",
109
+ "mediumaquamarine",
110
+ "mediumblue",
111
+ "mediumorchid",
112
+ "mediumpurple",
113
+ "mediumseagreen",
114
+ "mediumslateblue",
115
+ "mediumspringgreen",
116
+ "mediumturquoise",
117
+ "mediumvioletred",
118
+ "midnightblue",
119
+ "mintcream",
120
+ "mistyrose",
121
+ "moccasin",
122
+ "navajowhite",
123
+ "navy",
124
+ "oldlace",
125
+ "olive",
126
+ "olivedrab",
127
+ "orange",
128
+ "orangered",
129
+ "orchid",
130
+ "palegoldenrod",
131
+ "palegreen",
132
+ "paleturquoise",
133
+ "palevioletred",
134
+ "papayawhip",
135
+ "peachpuff",
136
+ "peru",
137
+ "pink",
138
+ "plum",
139
+ "powderblue",
140
+ "purple",
141
+ "rebeccapurple",
142
+ "red",
143
+ "rosybrown",
144
+ "royalblue",
145
+ "saddlebrown",
146
+ "salmon",
147
+ "sandybrown",
148
+ "seagreen",
149
+ "seashell",
150
+ "sienna",
151
+ "silver",
152
+ "skyblue",
153
+ "slateblue",
154
+ "slategray",
155
+ "slategrey",
156
+ "snow",
157
+ "springgreen",
158
+ "steelblue",
159
+ "tan",
160
+ "teal",
161
+ "thistle",
162
+ "tomato",
163
+ "turquoise",
164
+ "violet",
165
+ "wheat",
166
+ "white",
167
+ "whitesmoke",
168
+ "yellow",
169
+ "yellowgreen",
170
+ "transparent",
171
+ "currentcolor",
172
+ "canvas",
173
+ "canvastext",
174
+ "linktext",
175
+ "visitedtext",
176
+ "activetext",
177
+ "buttonface",
178
+ "buttontext",
179
+ "buttonborder",
180
+ "field",
181
+ "fieldtext",
182
+ "highlight",
183
+ "highlighttext",
184
+ "selecteditem",
185
+ "selecteditemtext",
186
+ "mark",
187
+ "marktext",
188
+ "graytext",
189
+ "accentcolor",
190
+ "accentcolortext"
191
+ ]);
192
+ const IS_COLOR_FN = /^(rgba?|hsla?|hwb|color|(ok)?(lab|lch)|light-dark|color-mix|--alpha)\(/i;
193
+ function isColor(value) {
194
+ return value.startsWith("#") || IS_COLOR_FN.test(value) || NAMED_COLORS.has(value.toLowerCase());
195
+ }
196
+ const MATH_FUNCTIONS = [
197
+ "calc",
198
+ "min",
199
+ "max",
200
+ "clamp",
201
+ "mod",
202
+ "rem",
203
+ "sin",
204
+ "cos",
205
+ "tan",
206
+ "asin",
207
+ "acos",
208
+ "atan",
209
+ "atan2",
210
+ "pow",
211
+ "sqrt",
212
+ "hypot",
213
+ "log",
214
+ "exp",
215
+ "round"
216
+ ];
217
+ function hasMathFn(input) {
218
+ return input.includes("(") && MATH_FUNCTIONS.some((fn) => input.includes(`${fn}(`));
219
+ }
220
+ const checks = {
221
+ color: isColor,
222
+ length: isLength,
223
+ percentage: isPercentage,
224
+ ratio: isFraction,
225
+ number: isNumber,
226
+ integer: isPositiveInteger,
227
+ url: isUrl,
228
+ position: isBackgroundPosition,
229
+ "bg-size": isBackgroundSize,
230
+ "line-width": isLineWidth,
231
+ image: isImage,
232
+ "family-name": isFamilyName,
233
+ "generic-name": isGenericName,
234
+ "absolute-size": isAbsoluteSize,
235
+ "relative-size": isRelativeSize,
236
+ angle: isAngle,
237
+ vector: isVector
238
+ };
239
+ /**
240
+ * Determine the type of `value` using syntax rules from CSS specs.
241
+ *
242
+ * @param value - Decoded arbitrary value without a type hint.
243
+ * @param types - Types of the registration, in its order.
244
+ * @returns The first type that the value has, or null. A `var()` value has no type.
245
+ */
246
+ function inferDataType(value, types) {
247
+ if (value.startsWith("var(")) return null;
248
+ for (const type of types) if (checks[type]?.(value)) return type;
249
+ return null;
250
+ }
251
+ const IS_URL = /^url\(.*\)$/;
252
+ function isUrl(value) {
253
+ return IS_URL.test(value);
254
+ }
255
+ function isLineWidth(value) {
256
+ return splitTopLevel(value, " ").every((value) => isLength(value) || isNumber(value) || value === "thin" || value === "medium" || value === "thick");
257
+ }
258
+ const IS_IMAGE_FN = /^(?:element|image|cross-fade|image-set)\(/;
259
+ const IS_GRADIENT_FN = /^(repeating-)?(conic|linear|radial)-gradient\(/;
260
+ function isImage(value) {
261
+ let count = 0;
262
+ for (const part of splitTopLevel(value, ",")) {
263
+ if (part.startsWith("var(")) continue;
264
+ if (isUrl(part)) {
265
+ count += 1;
266
+ continue;
267
+ }
268
+ if (IS_GRADIENT_FN.test(part)) {
269
+ count += 1;
270
+ continue;
271
+ }
272
+ if (IS_IMAGE_FN.test(part)) {
273
+ count += 1;
274
+ continue;
275
+ }
276
+ return false;
277
+ }
278
+ return count > 0;
279
+ }
280
+ function isGenericName(value) {
281
+ return value === "serif" || value === "sans-serif" || value === "monospace" || value === "cursive" || value === "fantasy" || value === "system-ui" || value === "ui-serif" || value === "ui-sans-serif" || value === "ui-monospace" || value === "ui-rounded" || value === "math" || value === "emoji" || value === "fangsong";
282
+ }
283
+ function isFamilyName(value) {
284
+ let count = 0;
285
+ for (const part of splitTopLevel(value, ",")) {
286
+ const char = part.charCodeAt(0);
287
+ if (char >= 48 && char <= 57) return false;
288
+ if (part.startsWith("var(")) continue;
289
+ count += 1;
290
+ }
291
+ return count > 0;
292
+ }
293
+ function isAbsoluteSize(value) {
294
+ return value === "xx-small" || value === "x-small" || value === "small" || value === "medium" || value === "large" || value === "x-large" || value === "xx-large" || value === "xxx-large";
295
+ }
296
+ function isRelativeSize(value) {
297
+ return value === "larger" || value === "smaller";
298
+ }
299
+ const HAS_NUMBER = /[+-]?\d*\.?\d+(?:[eE][+-]?\d+)?/;
300
+ const IS_NUMBER = new RegExp(`^${HAS_NUMBER.source}$`);
301
+ function isNumber(value) {
302
+ return IS_NUMBER.test(value) || hasMathFn(value);
303
+ }
304
+ const IS_PERCENTAGE = new RegExp(`^${HAS_NUMBER.source}%$`);
305
+ function isPercentage(value) {
306
+ return IS_PERCENTAGE.test(value) || hasMathFn(value);
307
+ }
308
+ const IS_FRACTION = new RegExp(`^${HAS_NUMBER.source}\\s*/\\s*${HAS_NUMBER.source}$`);
309
+ function isFraction(value) {
310
+ return IS_FRACTION.test(value) || hasMathFn(value);
311
+ }
312
+ const IS_LENGTH = new RegExp(`^${HAS_NUMBER.source}(${[
313
+ "cm",
314
+ "mm",
315
+ "Q",
316
+ "in",
317
+ "pc",
318
+ "pt",
319
+ "px",
320
+ "em",
321
+ "ex",
322
+ "ch",
323
+ "rem",
324
+ "lh",
325
+ "rlh",
326
+ "vw",
327
+ "vh",
328
+ "vmin",
329
+ "vmax",
330
+ "vb",
331
+ "vi",
332
+ "svw",
333
+ "svh",
334
+ "lvw",
335
+ "lvh",
336
+ "dvw",
337
+ "dvh",
338
+ "cqw",
339
+ "cqh",
340
+ "cqi",
341
+ "cqb",
342
+ "cqmin",
343
+ "cqmax"
344
+ ].join("|")})$`);
345
+ const IS_LENGTH_FN = /^(--spacing)\(/i;
346
+ function isLength(value) {
347
+ return IS_LENGTH.test(value) || IS_LENGTH_FN.test(value) || hasMathFn(value);
348
+ }
349
+ function isBackgroundPosition(value) {
350
+ let count = 0;
351
+ for (const part of splitTopLevel(value, " ")) {
352
+ if (part === "center" || part === "top" || part === "right" || part === "bottom" || part === "left") {
353
+ count += 1;
354
+ continue;
355
+ }
356
+ if (part.startsWith("var(")) continue;
357
+ if (isLength(part) || isPercentage(part)) {
358
+ count += 1;
359
+ continue;
360
+ }
361
+ return false;
362
+ }
363
+ return count > 0;
364
+ }
365
+ /**
366
+ * Recognizes background-size entries for Tailwind type inference.
367
+ *
368
+ * @param value - CSS value text with comma-separated entries.
369
+ * @returns Whether at least one entry is cover, contain, or one or two size values.
370
+ */
371
+ function isBackgroundSize(value) {
372
+ let count = 0;
373
+ for (const size of splitTopLevel(value, ",")) {
374
+ if (size === "cover" || size === "contain") {
375
+ count += 1;
376
+ continue;
377
+ }
378
+ const values = splitTopLevel(size, " ");
379
+ if (values.length !== 1 && values.length !== 2) return false;
380
+ if (values.every((value) => value === "auto" || isLength(value) || isPercentage(value))) count += 1;
381
+ }
382
+ return count > 0;
383
+ }
384
+ const IS_ANGLE = new RegExp(`^${HAS_NUMBER.source}(${[
385
+ "deg",
386
+ "rad",
387
+ "grad",
388
+ "turn"
389
+ ].join("|")})$`);
390
+ /**
391
+ * Recognizes a number with an angle unit.
392
+ *
393
+ * @param value - CSS text without surrounding whitespace.
394
+ * @returns Whether the number ends with deg, rad, grad, or turn.
395
+ */
396
+ function isAngle(value) {
397
+ return IS_ANGLE.test(value);
398
+ }
399
+ const IS_VECTOR = new RegExp(`^${HAS_NUMBER.source} +${HAS_NUMBER.source} +${HAS_NUMBER.source}$`);
400
+ /**
401
+ * Recognizes the three numbers of a rotate vector.
402
+ *
403
+ * @param value - CSS text without surrounding whitespace.
404
+ * @returns Whether exactly three numbers are separated by spaces.
405
+ */
406
+ function isVector(value) {
407
+ return IS_VECTOR.test(value);
408
+ }
409
+ /**
410
+ * Recognizes integer text used by Tailwind type inference.
411
+ *
412
+ * @param value - Number text without surrounding whitespace.
413
+ * @returns True for zero or a positive integer whose JavaScript number spelling matches value.
414
+ */
415
+ function isPositiveInteger(value) {
416
+ const number = Number(value);
417
+ return Number.isInteger(number) && number >= 0 && String(number) === String(value);
418
+ }
419
+ // src/css/plugins/tailwind/candidates.ts
420
+ /**
421
+ * Runs a `matchUtilities()` or `matchVariant()` callback for each named value and joins the rules
422
+ * that carry its selectors.
423
+ *
424
+ * The compiler collects marker classes from the selectors of callback results that candidates
425
+ * request. The host passes these rules in `@stillwind-marker-source`, so these classes are
426
+ * markers before any candidate requests a value, and the class that a candidate adds does not
427
+ * depend on which module the host compiles first. A value whose callback throws contributes
428
+ * nothing.
429
+ *
430
+ * @param values - Named values of the registration. Keys that start with `__` are skipped, as
431
+ * Tailwind skips them when it lists candidates.
432
+ * @param run - Returns the CSS rules that carry the selectors of the callback's result for one
433
+ * value.
434
+ * @returns The distinct rules, or an empty string when no value has a selector.
435
+ */
436
+ function probeCss(values, run) {
437
+ const rules = /* @__PURE__ */ new Set();
438
+ for (const [key, value] of Object.entries(values ?? {})) {
439
+ if (key.startsWith("__")) continue;
440
+ try {
441
+ for (const rule of run(value)) rules.add(rule);
442
+ } catch {}
443
+ }
444
+ return [...rules].join("");
445
+ }
446
+ /**
447
+ * Whether a candidate or variant belongs to a registered root.
448
+ *
449
+ * @param candidate - Name without a leading `-`.
450
+ * @param root - Registered root, such as `scrollbar`.
451
+ * @returns Whether the name is the root or continues it with `-` or `/`.
452
+ */
453
+ function member(candidate, root) {
454
+ return candidate === root || candidate.startsWith(`${root}-`) || candidate.startsWith(`${root}/`);
455
+ }
456
+ /**
457
+ * Converts a variant definition that a plugin returns into a `@custom-variant` body.
458
+ *
459
+ * @param value - Selector or at-rule string, CSS object, or a list of them.
460
+ * @returns CSS with `@slot`. A string without `@slot` gets one at its innermost block, or a
461
+ * block of its own.
462
+ */
463
+ function variantBody(value) {
464
+ if (Array.isArray(value)) return value.map(variantBody).join("\n");
465
+ if (typeof value !== "string") return serializeCss(value);
466
+ if (value.includes("@slot")) return value;
467
+ if (value.includes("{")) return value.replace("}", "{@slot;}}");
468
+ return `${value}{@slot;}`;
469
+ }
470
+ /**
471
+ * Whether a decoded arbitrary value has no top-level `;` or `}`, which Tailwind rejects.
472
+ *
473
+ * @param value - Decoded value.
474
+ * @returns Whether the value can be used.
475
+ */
476
+ function validArbitrary(value) {
477
+ return splitTopLevel(value, ";").length === 1 && splitTopLevel(value, "}").length === 1;
478
+ }
479
+ /**
480
+ * Parses the value part of a candidate as Tailwind's candidate parser does.
481
+ *
482
+ * @param text - Text after the root and its `-`, such as `4`, `[length:1px]`, or
483
+ * `(length:--size)`.
484
+ * @returns The value, or undefined when Tailwind rejects the candidate.
485
+ */
486
+ function parseValue(text) {
487
+ let inner;
488
+ if (text.startsWith("(") && text.endsWith(")")) {
489
+ const parts = splitTopLevel(text.slice(1, -1), ":");
490
+ const [dataType, variable] = parts.length === 2 ? parts : [null, parts.join(":")];
491
+ if (!variable.startsWith("--") || !validArbitrary(variable)) return;
492
+ inner = dataType === null ? `var(${variable})` : `${dataType}:var(${variable})`;
493
+ } else if (text.startsWith("[") && text.endsWith("]")) inner = text.slice(1, -1);
494
+ else return {
495
+ kind: "named",
496
+ value: text
497
+ };
498
+ let value = decodeArbitraryValue(inner);
499
+ if (!validArbitrary(value)) return;
500
+ let dataType = null;
501
+ const hint = /^([a-z-]*):/.exec(value);
502
+ if (hint) {
503
+ if (!hint[1]) return;
504
+ dataType = hint[1];
505
+ value = value.slice(hint[0].length);
506
+ }
507
+ return value.trim() ? {
508
+ kind: "arbitrary",
509
+ value,
510
+ dataType
511
+ } : void 0;
512
+ }
513
+ /**
514
+ * Parses a `/` modifier as Tailwind's candidate parser does.
515
+ *
516
+ * @param text - Modifier text without the slash.
517
+ * @returns The modifier, or undefined when Tailwind rejects the candidate.
518
+ */
519
+ function parseModifier(text) {
520
+ if (text.startsWith("[") && text.endsWith("]")) {
521
+ const value = decodeArbitraryValue(text.slice(1, -1));
522
+ return validArbitrary(value) && value.trim() ? {
523
+ kind: "arbitrary",
524
+ value,
525
+ dataType: null
526
+ } : void 0;
527
+ }
528
+ if (text.startsWith("(") && text.endsWith(")")) {
529
+ const variable = text.slice(1, -1);
530
+ return variable.startsWith("--") && validArbitrary(variable) ? {
531
+ kind: "arbitrary",
532
+ value: decodeArbitraryValue(`var(${variable})`),
533
+ dataType: null
534
+ } : void 0;
535
+ }
536
+ return text ? {
537
+ kind: "named",
538
+ value: text
539
+ } : void 0;
540
+ }
541
+ /**
542
+ * Runs a `matchUtilities` callback for one candidate as Tailwind's compatibility layer does.
543
+ *
544
+ * @param candidate - Utility key, such as `-probe-[3px]/mirror`.
545
+ * @param registration - Registration whose root, callback, and options apply.
546
+ * @returns The bodies of the callback's targets, undefined when the registration does not apply,
547
+ * and null when an arbitrary value has an invalid modifier, which ends Tailwind's evaluation of
548
+ * later definitions.
549
+ */
550
+ function resolveUtility(candidate, registration) {
551
+ const { name, callback, options } = registration;
552
+ const negative = candidate.startsWith("-");
553
+ const raw = negative ? candidate.slice(1) : candidate;
554
+ if (!member(raw, name) || negative && !options.supportsNegativeValues) return;
555
+ const [stem, ...modifierParts] = splitTopLevel(raw, "/");
556
+ if (modifierParts.length > 1) return;
557
+ const modifierText = modifierParts[0];
558
+ const valueText = stem === name ? void 0 : stem.slice(name.length + 1);
559
+ const parsed = valueText === void 0 ? null : parseValue(valueText);
560
+ const candidateModifier = modifierText === void 0 ? null : parseModifier(modifierText);
561
+ if (parsed === void 0 || candidateModifier === void 0) return;
562
+ const types = Array.isArray(options.type) ? options.type : [options.type ?? "any"];
563
+ if (parsed?.kind === "arbitrary" && types.length > 0 && !types.includes("any")) {
564
+ if (parsed.dataType ? !types.includes(parsed.dataType) : !inferDataType(parsed.value, types)) return;
565
+ }
566
+ const isColor = types.includes("color");
567
+ const values = isColor ? {
568
+ inherit: "inherit",
569
+ transparent: "transparent",
570
+ current: "currentcolor",
571
+ ...options.values
572
+ } : options.values ?? {};
573
+ const fraction = parsed?.kind === "named" && candidateModifier?.kind === "named" ? `${parsed.value}/${candidateModifier.value}` : null;
574
+ let value = null;
575
+ let ignoreModifier = false;
576
+ if (!parsed) value = values.DEFAULT ?? null;
577
+ else if (parsed.kind === "arbitrary") value = parsed.value;
578
+ else if (fraction && Object.hasOwn(values, fraction)) {
579
+ value = values[fraction];
580
+ ignoreModifier = true;
581
+ } else if (Object.hasOwn(values, parsed.value)) value = values[parsed.value];
582
+ else if (typeof values.__BARE_VALUE__ === "function") {
583
+ value = values.__BARE_VALUE__({
584
+ kind: "named",
585
+ value: parsed.value,
586
+ fraction
587
+ }) ?? null;
588
+ ignoreModifier = fraction !== null && typeof value === "string" && value.includes("/");
589
+ }
590
+ if (value === null || value === void 0) return;
591
+ let modifier = null;
592
+ if (candidateModifier) {
593
+ const modifiers = options.modifiers;
594
+ if (modifiers === "any" || candidateModifier.kind === "arbitrary") modifier = candidateModifier.value;
595
+ else if (modifiers && Object.hasOwn(modifiers, candidateModifier.value)) modifier = modifiers[candidateModifier.value];
596
+ else if (isColor && !Number.isNaN(Number(candidateModifier.value))) modifier = `${candidateModifier.value}%`;
597
+ if (modifier === null && !ignoreModifier) return parsed?.kind === "arbitrary" ? null : void 0;
598
+ }
599
+ if (isColor && modifier !== null) value = withAlpha(String(value), modifier);
600
+ if (negative) value = `calc(${String(value)} * -1)`;
601
+ return utilityBodies(callback(value, { modifier }));
602
+ }
603
+ /**
604
+ * Selects the callback arguments of a `matchVariant()` registration for one variant name, as
605
+ * Tailwind's compatibility layer does.
606
+ *
607
+ * The bare root uses the `DEFAULT` value. A named value must be a string in `values`, so
608
+ * `values: { one: 1 }` defines no `name-one` variant. An arbitrary value passes its decoded text.
609
+ *
610
+ * @param candidate - Complete variant name, such as `state-[open]/peer`.
611
+ * @param registration - Registration whose root and values apply.
612
+ * @returns The variant name, value, and modifier, or undefined when the registration has no
613
+ * such value.
614
+ */
615
+ function resolveVariant(candidate, registration) {
616
+ const { name, options } = registration;
617
+ if (!member(candidate, name)) return;
618
+ const [stem, ...modifierParts] = splitTopLevel(candidate, "/");
619
+ if (modifierParts.length > 1) return;
620
+ const valueText = stem === name ? void 0 : stem.slice(name.length + 1);
621
+ const parsed = valueText === void 0 ? null : parseValue(valueText);
622
+ const modifier = modifierParts[0] === void 0 ? null : parseModifier(modifierParts[0]);
623
+ if (parsed === void 0 || modifier === void 0) return;
624
+ const values = options.values;
625
+ let value;
626
+ if (!parsed) {
627
+ if (!values || !("DEFAULT" in values)) return;
628
+ value = values.DEFAULT;
629
+ } else if (parsed.kind === "arbitrary") value = parsed.value;
630
+ else {
631
+ value = values && Object.hasOwn(values, parsed.value) ? values[parsed.value] : void 0;
632
+ if (typeof value !== "string") return;
633
+ }
634
+ return {
635
+ name: candidate,
636
+ value,
637
+ modifier: modifier?.value ?? null
638
+ };
639
+ }
640
+ // src/css/plugins/tailwind/container.ts
641
+ /**
642
+ * Converts the legacy `theme.container` configuration into the `container` utility that
643
+ * Tailwind's compatibility layer adds next to its built-in `container`.
644
+ */
645
+ /**
646
+ * Compares two breakpoint values in ascending order, as Tailwind sorts its `--breakpoint-*`
647
+ * values. Lengths in `px`, `rem`, and `em` compare by size, with `1rem` and `1em` as `16px`.
648
+ * Other values compare as text after every length.
649
+ *
650
+ * @param left - CSS length, such as `40rem`.
651
+ * @param right - CSS length.
652
+ * @returns A negative number when `left` comes first, a positive number when `right` comes
653
+ * first, and zero for equal values.
654
+ */
655
+ function compareBreakpoints(left, right) {
656
+ const a = pixels(left);
657
+ const b = pixels(right);
658
+ if (a !== null && b !== null) return a - b;
659
+ if (a !== null || b !== null) return a === null ? 1 : -1;
660
+ return left < right ? -1 : left > right ? 1 : 0;
661
+ }
662
+ /**
663
+ * Converts a length to pixels.
664
+ *
665
+ * @param value - CSS length.
666
+ * @returns The size in pixels, or null for other values.
667
+ */
668
+ function pixels(value) {
669
+ const match = /^(-?\d*\.?\d+)(px|r?em)$/.exec(value.trim());
670
+ return match ? Number(match[1]) * (match[2] === "px" ? 1 : 16) : null;
671
+ }
672
+ /**
673
+ * Builds the body of the `container` utility for a `theme.container` configuration, as
674
+ * Tailwind's compatibility layer does.
675
+ *
676
+ * `center` adds `margin-inline: auto`. A string `padding`, or the `DEFAULT` of an object, adds
677
+ * `padding-inline`, and the other keys of an object add `padding-inline` from the breakpoint of
678
+ * the same name. `screens` replaces the built-in maximum widths: the smallest breakpoint resets
679
+ * `max-width`, and each screen sets `max-width` to its minimum width. A screen without a
680
+ * minimum width is skipped.
681
+ *
682
+ * @param container - The `theme.container` value.
683
+ * @param breakpoints - Breakpoint values by name, such as `{ sm: "40rem" }`.
684
+ * @returns CSS declarations and rules for an `@utility container` body, or an empty string when
685
+ * the configuration adds nothing.
686
+ */
687
+ function containerUtility(container, breakpoints) {
688
+ if (!container || typeof container !== "object") return "";
689
+ const { center, padding, screens } = container;
690
+ const output = [];
691
+ if (center) output.push("margin-inline:auto;");
692
+ if (typeof padding === "string") output.push(`padding-inline:${padding};`);
693
+ else if (padding && typeof padding === "object" && "DEFAULT" in padding) output.push(`padding-inline:${String(padding.DEFAULT)};`);
694
+ const sorted = Object.entries(breakpoints).sort(([, a], [, b]) => compareBreakpoints(a, b));
695
+ let widths;
696
+ if (screens && typeof screens === "object") {
697
+ widths = /* @__PURE__ */ new Map();
698
+ if (sorted.length) output.push(`@media (width >= ${sorted[0][1]}){max-width:none;}`);
699
+ for (const [name, screen] of Object.entries(screens)) {
700
+ const width = typeof screen === "string" ? screen : screen && typeof screen === "object" && "min" in screen ? String(screen.min) : void 0;
701
+ if (width !== void 0) widths.set(name, [width, `max-width:${width};`]);
702
+ }
703
+ }
704
+ if (padding && typeof padding === "object") {
705
+ const paddings = Object.entries(padding).filter(([name]) => name !== "DEFAULT" && name in breakpoints).sort(([a], [b]) => compareBreakpoints(breakpoints[a], breakpoints[b]));
706
+ for (const [name, value] of paddings) {
707
+ const screen = widths?.get(name);
708
+ if (screen) screen.push(`padding-inline:${String(value)};`);
709
+ else if (!widths) output.push(`@media (width >= ${breakpoints[name]}){padding-inline:${String(value)};}`);
710
+ }
711
+ }
712
+ for (const [width, ...declarations] of widths?.values() ?? []) output.push(`@media (width >= ${width}){${declarations.join("")}}`);
713
+ return output.join("");
714
+ }
715
+ // src/css/plugins/tailwind/theme.ts
716
+ /**
717
+ * Config keys whose `DEFAULT` value is a shared default in the `--default-*` namespace.
718
+ */
719
+ const SPECIAL_DEFAULT_KEYS = {
720
+ borderWidth: "border-width",
721
+ outlineWidth: "outline-width",
722
+ ringColor: "ring-color",
723
+ ringWidth: "ring-width",
724
+ transitionDuration: "transition-duration",
725
+ transitionTimingFunction: "transition-timing-function"
726
+ };
727
+ const IS_VALID_KEY = /^[a-zA-Z0-9-_%/.]+$/;
728
+ /** Tailwind's `ThemeOptions.DEFAULT` flag in `__CSS_VALUES__`. */
729
+ const DEFAULT_OPTION = 4;
730
+ /**
731
+ * Converts a config key path to the name of its CSS theme variable without `--`, as Tailwind does.
732
+ * `fontSize.xs.1.lineHeight` becomes `text-xs--line-height`, and `transitionDuration.DEFAULT`
733
+ * becomes `default-transition-duration`.
734
+ *
735
+ * @param path - Config keys, such as `["colors", "red", "500"]`.
736
+ * @param namespaces - The namespace name of each v3 config key whose namespace has another
737
+ * name, such as `text` for `fontSize`. Other keys use their kebab-case name.
738
+ * @returns The variable name, or null for the legacy container config and for keys with
739
+ * characters that a variable name cannot hold.
740
+ */
741
+ function keyPathToCssProperty(path, namespaces) {
742
+ const special = SPECIAL_DEFAULT_KEYS[path[0]];
743
+ if (special && path[1] === "DEFAULT") return `default-${special}`;
744
+ if (path[0] === "container" || !path.every((part) => IS_VALID_KEY.test(part))) return null;
745
+ return [namespaces[path[0]] ?? path[0], ...path.slice(1)].map((part, index, all) => part === "1" && index !== all.length - 1 ? "" : part).map((part, index) => {
746
+ part = part.replaceAll(".", "_");
747
+ return index === 0 || part.startsWith("-") || part === "lineHeight" ? part.replace(/([a-z])([A-Z])/g, (_, a, b) => `${a}-${b.toLowerCase()}`) : part;
748
+ }).filter((part, index) => part !== "DEFAULT" || index !== path.length - 1).join("-");
749
+ }
750
+ /**
751
+ * Lists the primitive values of a resolved theme config with their key paths, as Tailwind writes
752
+ * them back to CSS: tuples add their extra values under `-key`, and string arrays become a
753
+ * comma-separated list, except that a `fontSize` array is a size and a line height.
754
+ *
755
+ * @param theme - Resolved config sections keyed by config key.
756
+ * @returns Key paths and values in traversal order. Keys that start with `__` are skipped.
757
+ */
758
+ function themeableValues(theme) {
759
+ const result = [];
760
+ /**
761
+ * Adds the primitive values of one config value.
762
+ * @param value - Config value at `path`.
763
+ * @param path - Keys from the section key to `value`.
764
+ */
765
+ const visit = (value, path) => {
766
+ if (typeof value === "string" || typeof value === "number") result.push([path, value]);
767
+ else if (Array.isArray(value) && value.length === 2 && (typeof value[0] === "string" || typeof value[0] === "number") && object(value[1])) {
768
+ result.push([path, value[0]]);
769
+ for (const [key, extra] of Object.entries(value[1])) result.push([[...path, `-${key}`], extra]);
770
+ } else if (Array.isArray(value) && value.every((entry) => typeof entry === "string")) {
771
+ if (path[0] === "fontSize") {
772
+ result.push([path, value[0]]);
773
+ if (value.length >= 2) result.push([[...path, "-line-height"], value[1]]);
774
+ } else result.push([path, value.join(", ")]);
775
+ } else if (object(value)) {
776
+ for (const [key, entry] of Object.entries(value)) if (!key.startsWith("__")) visit(entry, [...path, key]);
777
+ }
778
+ };
779
+ visit(theme, []);
780
+ return result;
781
+ }
782
+ /**
783
+ * Parses a `theme()` path, as Tailwind's `toKeyPath()` does.
784
+ *
785
+ * @param path - Dotted path with optional brackets, such as `colors.red[500]`.
786
+ * @returns The keys, such as `["colors", "red", "500"]`. A bracket keeps dots, so `spacing[1.5]`
787
+ * has the key `1.5`.
788
+ */
789
+ function toKeyPath(path) {
790
+ const keys = [];
791
+ for (const part of splitTopLevel(path, ".")) {
792
+ let index = 0;
793
+ for (;;) {
794
+ const open = part.indexOf("[", index);
795
+ const close = part.indexOf("]", open);
796
+ if (open < 0 || close < 0) break;
797
+ if (open > index) keys.push(part.slice(index, open));
798
+ keys.push(part.slice(open + 1, close));
799
+ index = close + 1;
800
+ }
801
+ if (index < part.length) keys.push(part.slice(index));
802
+ }
803
+ return keys;
804
+ }
805
+ /**
806
+ * Reads a key path from a config object. A missing key joins the next one with `-`, so
807
+ * `colors.red.500` also finds a `red-500` entry.
808
+ *
809
+ * @param value - Config object.
810
+ * @param path - Keys below `value`.
811
+ * @returns The value at the path, or undefined when a key is missing at the end of the path.
812
+ */
813
+ function read(value, path) {
814
+ const keys = [...path];
815
+ for (let index = 0; index < keys.length; index++) {
816
+ const key = keys[index];
817
+ if (!object(value) || !Object.hasOwn(value, key)) {
818
+ if (keys[index + 1] === void 0) return;
819
+ keys[index + 1] = `${key}-${keys[index + 1]}`;
820
+ continue;
821
+ }
822
+ value = value[key];
823
+ }
824
+ return value;
825
+ }
826
+ /**
827
+ * Whether a theme value is a `var()` reference to the variable that it would define.
828
+ *
829
+ * @param name - Variable name without the leading `--`, such as `color-primary`.
830
+ * @param value - Configured value.
831
+ * @returns Whether `value` contains `var(--name)` or `var(--name, ...)`, which makes a declaration
832
+ * of `--name` a cycle.
833
+ */
834
+ function selfReference(name, value) {
835
+ return typeof value === "string" && [...value.matchAll(/var\(\s*--([^\s,)]+)\s*[,)]/g)].some((reference) => reference[1] === name);
836
+ }
837
+ /**
838
+ * Whether a value is a plain object rather than null or an array.
839
+ *
840
+ * @param value - Any value.
841
+ * @returns Whether `value` can hold config keys.
842
+ */
843
+ function object(value) {
844
+ return typeof value === "object" && value !== null && !Array.isArray(value);
845
+ }
846
+ /**
847
+ * Merges configuration objects deeply. Arrays and scalar values replace earlier values.
848
+ *
849
+ * @param target - Object that receives the entries; nested objects are copied before merging.
850
+ * @param source - Entries to merge into `target`.
851
+ * @returns `target`.
852
+ */
853
+ function merge(target, source) {
854
+ for (const [key, value] of Object.entries(source)) target[key] = object(value) && object(target[key]) ? merge({ ...target[key] }, value) : value;
855
+ return target;
856
+ }
857
+ /**
858
+ * Reads one `fontFamily` config entry, as Tailwind's `fontFamily.sans` handling does.
859
+ *
860
+ * @param value - Config entry: a family string, an array of families, or a `[family, settings]`
861
+ * tuple.
862
+ * @param setting - Settings key of a tuple, such as `fontFeatureSettings`, or undefined for the
863
+ * family.
864
+ * @returns The family with array entries joined by `, `, or the tuple's setting. Returns null when
865
+ * the entry does not hold the requested value.
866
+ */
867
+ function fontValue(value, setting) {
868
+ if (Array.isArray(value) && value.length === 2 && object(value[1])) {
869
+ const result = setting === void 0 ? value[0] : value[1][setting];
870
+ return result === void 0 || result === null ? null : String(result);
871
+ }
872
+ if (setting !== void 0) return null;
873
+ if (Array.isArray(value)) return value.join(", ");
874
+ return typeof value === "string" ? value : null;
875
+ }
876
+ /**
877
+ * Resolves plugin theme configuration against the active CSS tokens, as Tailwind's compatibility
878
+ * layer does, and writes the plugins' own configuration back as CSS theme variables.
879
+ *
880
+ * Reads combine three sources: CSS tokens, the plugins' config, and Tailwind's v3 default theme
881
+ * without colors. Ordinary CSS definitions win. Config values win over `@theme default`
882
+ * definitions and over the defaults.
883
+ */
884
+ var PluginTheme = class {
885
+ /** The function passed to plugin handlers and config functions. */
886
+ get;
887
+ /** Active tokens by full name. */
888
+ #tokens;
889
+ /** The namespace name of each v3 config key whose namespace has another name. */
890
+ #namespaces;
891
+ /** Tailwind's compatibility defaults followed by the plugin configs, in plugin order. */
892
+ #layers;
893
+ /** Number of leading layers that are compatibility defaults rather than plugin config. */
894
+ #defaults;
895
+ #sections = /* @__PURE__ */ new Map();
896
+ #resolving = /* @__PURE__ */ new Set();
897
+ /**
898
+ * @param configs - Configs of the plugins and their presets, in registration order.
899
+ * @param tokens - Active CSS theme tokens.
900
+ * @param legacyKeys - The namespaces that v3 config keys read, from the design system.
901
+ */
902
+ constructor(configs, tokens, legacyKeys) {
903
+ this.#tokens = new Map(tokens.map((token) => [token.name, token]));
904
+ this.#namespaces = Object.fromEntries(legacyKeys.map(({ key, namespace }) => [key, namespace]));
905
+ /**
906
+ * Splits a config's `theme` into its replacing and extending parts.
907
+ * @param theme - The `theme` value of a config.
908
+ * @returns The layer, empty for a value that is not an object.
909
+ */
910
+ const layer = (theme) => {
911
+ const { extend, ...rest } = object(theme) ? theme : {};
912
+ return {
913
+ theme: rest,
914
+ extend: object(extend) ? extend : {}
915
+ };
916
+ };
917
+ /**
918
+ * Creates a config function that reads one CSS theme namespace.
919
+ * @param namespace - CSS namespace, such as `color`.
920
+ * @returns A function that returns the namespace's values, or an empty object.
921
+ */
922
+ const fromCss = (namespace) => () => this.get(namespace, {});
923
+ const exposed = (exposure) => Object.fromEntries(legacyKeys.filter((legacy) => legacy.exposure === exposure).map(({ key, namespace }) => [key, fromCss(namespace)]));
924
+ this.#layers = [{
925
+ theme: {
926
+ ...defaultTheme,
927
+ ...exposed("replace")
928
+ },
929
+ extend: {
930
+ ...exposed("extend"),
931
+ transitionDuration: { DEFAULT: this.#tokens.get("--default-transition-duration")?.value ?? null },
932
+ transitionTimingFunction: { DEFAULT: this.#tokens.get("--default-transition-timing-function")?.value ?? null }
933
+ }
934
+ }, ...configs.map((config) => layer(config.theme))];
935
+ this.#defaults = 1;
936
+ /**
937
+ * The theme function of plugins and config functions.
938
+ * @param path - Config path, or undefined for every section.
939
+ * @param fallback - Value for a path that resolves to nothing.
940
+ * @returns The resolved value.
941
+ */
942
+ const get = ((path, fallback) => path === void 0 ? this.#all() : this.#theme(path, fallback));
943
+ get.theme = get;
944
+ this.get = get;
945
+ get.colors = get("colors");
946
+ }
947
+ /**
948
+ * Emits the plugins' own theme configuration, which native utility resolution also needs.
949
+ *
950
+ * @returns A `@stillwind-plugin-theme` block with the configured variables and keyframes, and a
951
+ * `@stillwind-plugin-theme inline` block with the values that refer to their own variable, or an
952
+ * empty string when the plugins configure nothing.
953
+ */
954
+ css() {
955
+ const configured = {};
956
+ const replaced = /* @__PURE__ */ new Set();
957
+ const layers = this.#layers.slice(this.#defaults);
958
+ for (const key of new Set(layers.flatMap(({ theme, extend }) => [...Object.keys(theme), ...Object.keys(extend)]))) {
959
+ if (layers.some(({ theme }) => Object.hasOwn(theme, key))) replaced.add(key);
960
+ configured[key] = this.#resolve(key, layers);
961
+ }
962
+ let declarations = "";
963
+ let inline = "";
964
+ for (const key of replaced) {
965
+ const name = keyPathToCssProperty([key], this.#namespaces);
966
+ if (name) declarations += `--${name}-*:initial;`;
967
+ }
968
+ for (const [path, configuredValue] of themeableValues(configured)) {
969
+ let value = configuredValue;
970
+ if (path[0] === "keyframes") continue;
971
+ if (typeof value === "string") value = value.replaceAll("<alpha-value>", "1");
972
+ if (path[0] === "opacity") {
973
+ const number = typeof value === "string" ? Number.parseFloat(value) : Number(value);
974
+ if (number >= 0 && number <= 1) value = `${number * 100}%`;
975
+ }
976
+ const name = keyPathToCssProperty(path, this.#namespaces);
977
+ if (!name) continue;
978
+ if (selfReference(name, value)) inline += `--${name}:${String(value)};`;
979
+ else declarations += `--${name}:${String(value)};`;
980
+ }
981
+ if (object(configured.fontFamily)) for (const [key, prefix] of [["sans", "default"], ["mono", "default-mono"]]) {
982
+ const entry = configured.fontFamily[key];
983
+ const family = fontValue(entry);
984
+ const token = this.#tokens.get(`--font-${key}`);
985
+ if (family !== null && (!token || token.fallback)) declarations += `--${prefix}-font-family:${family};--${prefix}-font-feature-settings:${fontValue(entry, "fontFeatureSettings") ?? "normal"};--${prefix}-font-variation-settings:${fontValue(entry, "fontVariationSettings") ?? "normal"};`;
986
+ }
987
+ let frames = "";
988
+ if (object(configured.keyframes)) for (const [name, body] of Object.entries(configured.keyframes)) frames += `@keyframes ${name}{${serializeCss(body)}}`;
989
+ return [declarations || frames ? `@stillwind-plugin-theme{${declarations}${frames}}` : "", inline ? `@stillwind-plugin-theme inline{${inline}}` : ""].join("");
990
+ }
991
+ /**
992
+ * Resolves every section, for `config("theme")` and `theme()` without a path.
993
+ *
994
+ * @returns Resolved sections keyed by config key.
995
+ */
996
+ #all() {
997
+ const keys = new Set(this.#layers.flatMap(({ theme, extend }) => [...Object.keys(theme), ...Object.keys(extend)]));
998
+ return Object.fromEntries([...keys].map((key) => [key, this.#section(key)]));
999
+ }
1000
+ /**
1001
+ * Resolves one config section across all layers, once.
1002
+ *
1003
+ * @param key - Config key, such as `colors`.
1004
+ * @returns The resolved section, or undefined when no layer configures it.
1005
+ * @throws If resolving the section reads the section itself.
1006
+ */
1007
+ #section(key) {
1008
+ if (this.#sections.has(key)) return this.#sections.get(key);
1009
+ if (this.#resolving.has(key)) throw new Error(`Circular Tailwind plugin theme reference: ${key}`);
1010
+ this.#resolving.add(key);
1011
+ try {
1012
+ const value = this.#resolve(key, this.#layers);
1013
+ this.#sections.set(key, value);
1014
+ return value;
1015
+ } finally {
1016
+ this.#resolving.delete(key);
1017
+ }
1018
+ }
1019
+ /**
1020
+ * Resolves one section of `layers`: the last `theme` value replaces earlier ones, and every
1021
+ * `extend` value then merges into it. Function values receive the theme function.
1022
+ *
1023
+ * @param key - Config key.
1024
+ * @param layers - Layers to combine, in registration order.
1025
+ * @returns The resolved section, or undefined when no layer configures it.
1026
+ */
1027
+ #resolve(key, layers) {
1028
+ /**
1029
+ * Calls a config function with the theme function.
1030
+ * @param value - Config value or function.
1031
+ * @returns The function's result, or `value` itself.
1032
+ */
1033
+ const evaluate = (value) => typeof value === "function" ? value(this.get) : value;
1034
+ let value;
1035
+ for (const layer of layers) if (Object.hasOwn(layer.theme, key)) value = evaluate(layer.theme[key]);
1036
+ for (const layer of layers) if (Object.hasOwn(layer.extend, key)) {
1037
+ const extension = evaluate(layer.extend[key]);
1038
+ value = object(extension) ? merge({ ...object(value) ? value : {} }, extension) : extension;
1039
+ }
1040
+ return value;
1041
+ }
1042
+ /**
1043
+ * Tailwind's `theme(path, defaultValue)` for plugins.
1044
+ *
1045
+ * @param path - Config path, or a CSS variable name such as `--color-red-500`, with an optional
1046
+ * trailing `/ alpha`.
1047
+ * @param fallback - Value for a path that resolves to nothing.
1048
+ * @returns The resolved value, with the alpha applied to a string value.
1049
+ */
1050
+ #theme(path, fallback) {
1051
+ const slash = path.lastIndexOf("/");
1052
+ const modifier = slash < 0 ? null : path.slice(slash + 1).trim();
1053
+ const keys = toKeyPath(slash < 0 ? path : path.slice(0, slash).trim());
1054
+ const [css, options] = this.#readFromCss(keys);
1055
+ let config = keys[0] === void 0 ? void 0 : read(this.#section(keys[0]), keys.slice(1));
1056
+ if (typeof config === "string") config = config.replace("<alpha-value>", "1");
1057
+ let value;
1058
+ if (css === null) value = config;
1059
+ else if (typeof css !== "object") value = typeof options === "number" && options & DEFAULT_OPTION ? config ?? css : css;
1060
+ else if (object(config) && object(css)) {
1061
+ const copy = merge({}, config);
1062
+ const cssOptions = css.__CSS_VALUES__ ?? {};
1063
+ for (const [key, entry] of Object.entries(css)) {
1064
+ const yields = ((cssOptions[key] ?? 0) & DEFAULT_OPTION) !== 0 && read(copy, key.split("-")) !== void 0;
1065
+ if (key !== "__CSS_VALUES__" && !yields) copy[key] = entry;
1066
+ }
1067
+ value = copy;
1068
+ } else value = object(css) && "DEFAULT" in css ? css.DEFAULT : css;
1069
+ if (modifier && typeof value === "string") value = withAlpha(value, modifier);
1070
+ return value ?? fallback;
1071
+ }
1072
+ /**
1073
+ * Tailwind's `readFromCss()`: the token of a key path, or the namespace's tokens as an object
1074
+ * keyed by suffix with `__CSS_VALUES__` options. `--text-xs--line-height` becomes the tuple
1075
+ * `[size, { lineHeight }]` of `xs`.
1076
+ *
1077
+ * @param path - Config key path, or one CSS variable name.
1078
+ * @returns The value or object, and its options: a number for a value, and an object of
1079
+ * numbers for an object. Null and 0 when no token matches.
1080
+ */
1081
+ #readFromCss(path) {
1082
+ /**
1083
+ * Returns Tailwind's options of a token.
1084
+ * @param token - Active token.
1085
+ * @returns The `DEFAULT` flag for a definition that ordinary definitions override.
1086
+ */
1087
+ const option = (token) => token?.fallback ? DEFAULT_OPTION : 0;
1088
+ if (path.length === 1 && path[0].startsWith("--")) {
1089
+ const token = this.#tokens.get(path[0]);
1090
+ return [token?.value ?? null, option(token)];
1091
+ }
1092
+ const name = keyPathToCssProperty(path, this.#namespaces);
1093
+ if (!name) return [null, 0];
1094
+ const values = /* @__PURE__ */ new Map();
1095
+ const options = /* @__PURE__ */ new Map();
1096
+ const nested = /* @__PURE__ */ new Map();
1097
+ for (const token of this.#tokens.values()) {
1098
+ if (token.name !== `--${name}` && !token.name.startsWith(`--${name}-`)) continue;
1099
+ const key = token.name === `--${name}` ? null : token.name.slice(name.length + 3);
1100
+ if (key === null || !key.includes("--")) {
1101
+ values.set(key, token.value);
1102
+ options.set(key, option(token));
1103
+ continue;
1104
+ }
1105
+ const split = key.indexOf("--");
1106
+ const main = key.slice(0, split) || null;
1107
+ const extra = key.slice(split + 2).replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
1108
+ nested.set(main, {
1109
+ ...nested.get(main),
1110
+ [extra]: [token.value, option(token)]
1111
+ });
1112
+ }
1113
+ if (!values.size && !nested.size) return [null, 0];
1114
+ for (const [key, extra] of nested) {
1115
+ const base = values.get(key);
1116
+ if (typeof base === "string") {
1117
+ values.set(key, [base, Object.fromEntries(Object.entries(extra).map(([k, [v]]) => [k, v]))]);
1118
+ options.set(key, [options.get(key), Object.fromEntries(Object.entries(extra).map(([k, [, o]]) => [k, o]))]);
1119
+ }
1120
+ }
1121
+ const result = Object.fromEntries([...values].map(([key, value]) => [key ?? "DEFAULT", value]));
1122
+ const resultOptions = Object.fromEntries([...options].map(([key, value]) => [key ?? "DEFAULT", value]));
1123
+ if (path.at(-1) === "DEFAULT") return [result.DEFAULT ?? null, resultOptions.DEFAULT ?? 0];
1124
+ if ("DEFAULT" in result && Object.keys(result).length === 1) return [result.DEFAULT, resultOptions.DEFAULT ?? 0];
1125
+ result.__CSS_VALUES__ = resultOptions;
1126
+ return [result, resultOptions];
1127
+ }
1128
+ };
1129
+ // src/css/plugins/tailwind/plugin.ts
1130
+ /**
1131
+ * Executes Tailwind API handlers once and resolves their registered callbacks on demand.
1132
+ *
1133
+ * All handlers share one resolved config and theme, as in Tailwind. Each registration keeps the
1134
+ * index of the `@plugin` statement that registered it, so the CSS of each statement stays at its
1135
+ * own position in the stylesheet. The project's configuration and the settings that apply to
1136
+ * every statement belong to an extra owner, whose CSS {@link TailwindRuntime.settingsCss}
1137
+ * returns.
1138
+ */
1139
+ var TailwindRuntime = class {
1140
+ /** `addUtilities()` and `addComponents()` registrations, as `@utility` rules. */
1141
+ #utilities = [];
1142
+ /** `addVariant()` registrations by name, as `@custom-variant` rules. */
1143
+ #variants = /* @__PURE__ */ new Map();
1144
+ /** Base styles, keyframes, and `@property` rules. */
1145
+ #globals = [];
1146
+ #dynamicUtilities = [];
1147
+ #dynamicVariants = [];
1148
+ /** Requests already resolved, including ones that no registration accepted. */
1149
+ #requests = /* @__PURE__ */ new Set();
1150
+ /** Theme shared by every handler. */
1151
+ #theme;
1152
+ /** Owner whose handler is running, recorded with each registration. */
1153
+ #owner = 0;
1154
+ /**
1155
+ * Number of `@plugin` statements. It is also the owner index of the project's configuration
1156
+ * and of the settings for every statement.
1157
+ */
1158
+ #owners;
1159
+ /**
1160
+ * `@stillwind-plugin-important` statement for the merged `important` setting, or an empty
1161
+ * string when the setting is neither `true` nor a selector.
1162
+ */
1163
+ #important;
1164
+ /**
1165
+ * @param plugins - Configured handlers, one for each `@plugin` statement, in stylesheet order.
1166
+ * @param tokens - Active CSS theme tokens, which the handlers' `theme()` calls read.
1167
+ * @param legacyKeys - The namespaces that v3 config keys read, from the design system.
1168
+ * @param project - Project's Tailwind configuration. Its keys replace the same keys of every
1169
+ * plugin configuration, as the keys of a Tailwind `@config` file do. Its plugins register in
1170
+ * {@link TailwindRuntime.settingsCss}.
1171
+ */
1172
+ constructor(plugins, tokens, legacyKeys, project) {
1173
+ const entries = [];
1174
+ const configs = [];
1175
+ /**
1176
+ * Collects a plugin's presets, config, and nested plugins before the plugin itself.
1177
+ * @param plugin - Configured plugin.
1178
+ * @param owner - Statement whose output receives the plugin's registrations.
1179
+ */
1180
+ const visit = (plugin, owner) => {
1181
+ for (const preset of plugin.config?.presets ?? []) visit({
1182
+ handler: () => {},
1183
+ config: preset
1184
+ }, owner);
1185
+ configs.push(plugin.config ?? {});
1186
+ for (const nested of plugin.config?.plugins ?? []) visit(configurePlugin(nested, []), owner);
1187
+ entries.push([plugin, owner]);
1188
+ };
1189
+ for (const [owner, plugin] of plugins.entries()) visit(plugin, owner);
1190
+ this.#owners = plugins.length;
1191
+ if (project) visit({
1192
+ handler: () => {},
1193
+ config: project
1194
+ }, this.#owners);
1195
+ this.#theme = new PluginTheme(configs, tokens, legacyKeys);
1196
+ const config = resolveConfig(configs);
1197
+ const addUtilities = (css) => utilityRules(css, (name, body) => this.#utilities.push({
1198
+ owner: this.#owner,
1199
+ name,
1200
+ css: `@utility ${identifier(name)}{${body}}`
1201
+ }), (body) => this.#globals.push({
1202
+ owner: this.#owner,
1203
+ css: body
1204
+ }));
1205
+ const matchUtilities = (utilities, options = {}) => {
1206
+ for (const [name, callback] of Object.entries(utilities)) this.#dynamicUtilities.push({
1207
+ owner: this.#owner,
1208
+ name,
1209
+ callback,
1210
+ options,
1211
+ markerSource: probeCss(options.values, (value) => selectorRules(callback(value, { modifier: null }))),
1212
+ results: /* @__PURE__ */ new Map()
1213
+ });
1214
+ };
1215
+ const api = {
1216
+ addBase: (css) => {
1217
+ this.#globals.push({
1218
+ owner: this.#owner,
1219
+ css: `@layer base{${serializeCss(css)}}`
1220
+ });
1221
+ },
1222
+ addUtilities,
1223
+ addComponents: addUtilities,
1224
+ matchUtilities,
1225
+ matchComponents: matchUtilities,
1226
+ addVariant: (name, value) => {
1227
+ const body = variantBody(value);
1228
+ if (!body.includes(":merge(")) {
1229
+ const previous = this.#variants.get(name);
1230
+ this.#variants.set(name, {
1231
+ owner: previous?.owner ?? this.#owner,
1232
+ css: `@custom-variant ${identifier(name)}{${body}}`
1233
+ });
1234
+ }
1235
+ },
1236
+ matchVariant: (name, callback, options = {}) => {
1237
+ try {
1238
+ if (String(callback("a", { modifier: null })).includes(":merge(")) return;
1239
+ } catch {}
1240
+ this.#dynamicVariants.push({
1241
+ owner: this.#owner,
1242
+ name,
1243
+ callback,
1244
+ options,
1245
+ markerSource: probeCss(options.values, (value) => [variantBody(callback(value, { modifier: null }))]),
1246
+ results: /* @__PURE__ */ new Map()
1247
+ });
1248
+ },
1249
+ theme: this.#theme.get,
1250
+ config: (path, fallback) => {
1251
+ if (!path) return {
1252
+ ...config,
1253
+ theme: this.#theme.get()
1254
+ };
1255
+ const [key, ...keys] = toKeyPath(path);
1256
+ if (key === "theme") return keys.length ? this.#theme.get(keys.map((entry) => `[${entry}]`).join(""), fallback) : this.#theme.get();
1257
+ return [key, ...keys].reduce((value, entry) => value && typeof value === "object" ? value[entry] : void 0, config) ?? fallback;
1258
+ },
1259
+ prefix: (className) => className
1260
+ };
1261
+ for (const [plugin, owner] of entries) {
1262
+ this.#owner = owner;
1263
+ plugin.handler(api);
1264
+ }
1265
+ const dark = darkModeVariant(config.darkMode);
1266
+ if (dark) {
1267
+ this.#owner = this.#owners;
1268
+ api.addVariant("dark", dark);
1269
+ }
1270
+ const { important } = config;
1271
+ this.#important = important === true ? "@stillwind-plugin-important;" : typeof important === "string" && important.trim() ? `@stillwind-plugin-important ${important.trim()};` : "";
1272
+ const screens = this.#theme.get("screens");
1273
+ const container = containerUtility(this.#theme.get("container"), Object.fromEntries(Object.entries(screens && typeof screens === "object" ? screens : {}).filter((entry) => entry[0] !== "__CSS_VALUES__" && typeof entry[1] === "string")));
1274
+ if (container) this.#utilities.push({
1275
+ owner: this.#owners,
1276
+ name: "container",
1277
+ css: `@utility container{${container}}`
1278
+ });
1279
+ }
1280
+ /**
1281
+ * Reports whether a compiler discovery request belongs to one of this runtime's callbacks.
1282
+ *
1283
+ * @param candidate - Utility key, or variant name with an `@variant ` prefix.
1284
+ * @returns Whether a `matchUtilities()` or `matchVariant()` root matches it.
1285
+ */
1286
+ accepts(candidate) {
1287
+ if (candidate.startsWith("@variant ")) return this.#dynamicVariants.some(({ name }) => member(candidate.slice(9), name));
1288
+ const value = candidate.replace(/^-/, "");
1289
+ return this.#dynamicUtilities.some(({ name }) => member(value, name));
1290
+ }
1291
+ /**
1292
+ * Runs the callbacks for requests that this runtime has not seen.
1293
+ *
1294
+ * @param candidates - Utility keys, and variant names with an `@variant ` prefix.
1295
+ * @returns Whether the generated CSS of any statement changed.
1296
+ * @throws If a callback fails.
1297
+ */
1298
+ resolve(candidates) {
1299
+ const before = this.#all();
1300
+ for (const candidate of candidates) {
1301
+ if (this.#requests.has(candidate)) continue;
1302
+ this.#requests.add(candidate);
1303
+ if (candidate.startsWith("@variant ")) for (const registration of this.#dynamicVariants) {
1304
+ const variant = resolveVariant(candidate.slice(9), registration);
1305
+ if (variant) registration.results.set(variant.name, {
1306
+ ...variant,
1307
+ body: variantBody(registration.callback(variant.value, { modifier: variant.modifier }))
1308
+ });
1309
+ }
1310
+ else for (const registration of this.#dynamicUtilities) registration.results.set(candidate, resolveUtility(candidate, registration));
1311
+ }
1312
+ return before !== this.#all();
1313
+ }
1314
+ /**
1315
+ * Lists finite utility and variant suggestions without executing dynamic callbacks.
1316
+ *
1317
+ * @returns Static utility names, the named values of dynamic utilities with their modifiers and
1318
+ * negative forms, and variant names with a trailing `:`.
1319
+ */
1320
+ catalog() {
1321
+ const result = [...new Set(this.#utilities.map(({ name }) => name)), ...[...this.#variants.keys()].map((name) => `${name}:`)];
1322
+ for (const { name, options } of this.#dynamicUtilities) {
1323
+ const keys = Object.keys(options.values ?? {}).filter((key) => !key.startsWith("__"));
1324
+ const modifiers = options.modifiers && options.modifiers !== "any" ? Object.keys(options.modifiers) : [];
1325
+ for (const key of keys) {
1326
+ const candidate = key === "DEFAULT" ? name : `${name}-${key}`;
1327
+ result.push(candidate, ...modifiers.map((modifier) => `${candidate}/${modifier}`));
1328
+ if (options.supportsNegativeValues) result.push(`-${candidate}`);
1329
+ }
1330
+ }
1331
+ for (const { name, options } of this.#dynamicVariants) for (const key of Object.keys(options.values ?? {})) result.push(`${key === "DEFAULT" ? name : `${name}-${key}`}:`);
1332
+ return result;
1333
+ }
1334
+ /**
1335
+ * Serializes every statement, for change detection.
1336
+ *
1337
+ * @returns The CSS of all statements in order.
1338
+ */
1339
+ #all() {
1340
+ return Array.from({ length: this.#owners }, (_, owner) => this.css(owner)).join("\n");
1341
+ }
1342
+ /**
1343
+ * Serializes the registrations of one `@plugin` statement in handler order, including sorted
1344
+ * dynamic variants.
1345
+ *
1346
+ * A static utility becomes an ordinary `@utility`. A callback result for one candidate becomes
1347
+ * a `(functional)` `@utility`, so it adds to the built-in and stylesheet definitions of its
1348
+ * root, as Tailwind evaluates every definition of a name. A registration whose types include
1349
+ * `any` and another type is a Tailwind fallback, and a callback that rejects an arbitrary value
1350
+ * with an invalid modifier stops the evaluation of later definitions.
1351
+ *
1352
+ * @param owner - Index of the statement among the configured handlers, or the number of
1353
+ * statements for the settings that {@link TailwindRuntime.settingsCss} describes.
1354
+ * @returns Stillwind CSS for the statement's position.
1355
+ */
1356
+ css(owner) {
1357
+ const output = owner === this.#owners ? [this.#theme.css(), this.#important].filter(Boolean) : [];
1358
+ output.push(...[...this.#globals, ...this.#utilities].filter((entry) => entry.owner === owner).map(({ css }) => css));
1359
+ for (const variant of this.#variants.values()) if (variant.owner === owner) output.push(variant.css);
1360
+ for (const registration of this.#dynamicUtilities) {
1361
+ if (registration.owner !== owner) continue;
1362
+ output.push(`@stillwind-plugin-family utility ${registration.name};`, ...registration.markerSource ? [`@stillwind-marker-source ${cssString(registration.markerSource)};`] : []);
1363
+ const types = Array.isArray(registration.options.type) ? registration.options.type : [registration.options.type ?? "any"];
1364
+ const role = types.length > 1 && types.includes("any") ? "functional, fallback" : "functional";
1365
+ for (const [request, body] of registration.results) {
1366
+ if (body === null) output.push(`@utility ${identifier(request)} (functional, stop){}`);
1367
+ for (const target of body ?? []) output.push(`@utility ${identifier(request)} (${role}){${target}}`);
1368
+ }
1369
+ }
1370
+ for (const registration of this.#dynamicVariants) {
1371
+ if (registration.owner !== owner) continue;
1372
+ output.push(`@stillwind-plugin-family variant ${registration.name};`, ...registration.markerSource ? [`@stillwind-marker-source ${cssString(registration.markerSource)};`] : []);
1373
+ const candidates = [...registration.results.values()];
1374
+ candidates.sort((a, b) => {
1375
+ if (registration.options.sort) return registration.options.sort(a, b);
1376
+ const keys = Object.keys(registration.options.values ?? {});
1377
+ /**
1378
+ * Positions a variant by its value's key in `values`.
1379
+ * @param candidate - Generated variant.
1380
+ * @returns The key's index, or the number of keys for an arbitrary value.
1381
+ */
1382
+ const order = (candidate) => {
1383
+ const [stem] = splitTopLevel(candidate.name, "/");
1384
+ const key = stem === registration.name ? "DEFAULT" : stem.slice(registration.name.length + 1);
1385
+ const index = keys.indexOf(key);
1386
+ return index < 0 ? keys.length : index;
1387
+ };
1388
+ return order(a) - order(b) || (String(a.value) < String(b.value) ? -1 : 1);
1389
+ });
1390
+ for (const candidate of candidates) output.push(`@custom-variant ${identifier(candidate.name)}{${candidate.body}}`);
1391
+ }
1392
+ return output.join("\n");
1393
+ }
1394
+ /**
1395
+ * Serializes the settings that apply to every statement, followed by the registrations of the
1396
+ * project's configuration, in the form that {@link TailwindRuntime.css} describes.
1397
+ *
1398
+ * The settings are the merged theme configuration as a `@stillwind-plugin-theme` block, which
1399
+ * native utility resolution also reads, the `important` setting, the `dark` variant of the
1400
+ * `darkMode` setting, and the `container` utility of `theme.container`.
1401
+ *
1402
+ * @returns Stillwind CSS for the request that follows the root stylesheet.
1403
+ */
1404
+ settingsCss() {
1405
+ return this.css(this.#owners);
1406
+ }
1407
+ };
1408
+ export { TailwindRuntime };
1409
+
1410
+ //# sourceMappingURL=plugin-DvCyhK1k.js.map