@styleframe/core 3.2.0 → 3.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/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @styleframe/core
2
2
 
3
+ ## 3.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#203](https://github.com/styleframe-dev/styleframe/pull/203) [`c314dbc`](https://github.com/styleframe-dev/styleframe/commit/c314dbc78872df38efe72d7931faf86afce5ffcc) Thanks [@alexgrozav](https://github.com/alexgrozav)! - Track variable references in `root._usage.variables` for future transpiler optimizations
8
+ - Add `_usage: { variables: Set<string> }` to `Root` type and initialize in `createRoot()`
9
+ - Record variable names whenever `ref()` is called or `@`-prefixed syntax is resolved
10
+
11
+ ## 3.3.0
12
+
13
+ ### Minor Changes
14
+
15
+ - [#164](https://github.com/styleframe-dev/styleframe/pull/164) [`efd99f7`](https://github.com/styleframe-dev/styleframe/commit/efd99f70a30f9a42c6e1793ed777b1565fb47a82) Thanks [@alexgrozav](https://github.com/alexgrozav)! - Add className support for compound variants in recipes
16
+ - Add optional `className` field to compound variants, appended to output when conditions match
17
+ - Make `css` optional on compound variants, allowing className-only compound variants
18
+
19
+ ### Patch Changes
20
+
21
+ - [#175](https://github.com/styleframe-dev/styleframe/pull/175) [`b506ea5`](https://github.com/styleframe-dev/styleframe/commit/b506ea5c3c36fa24fea19a69ee3fef7035397dda) Thanks [@alexgrozav](https://github.com/alexgrozav)! - Add Skeleton recipe with pulse animation and supporting utilities
22
+ - Add `useSkeletonRecipe` with size (`xs`, `sm`, `md`, `lg`, `xl`) and rounded (`true`, `false`) variants, pulse animation, and dark mode support
23
+ - Add granular animation utilities: `useAnimationNameUtility`, `useAnimationDurationUtility`, `useAnimationTimingFunctionUtility`, `useAnimationIterationCountUtility`
24
+ - Switch `useWidthUtility` and `useHeightUtility` to `createUseSpacingUtility` for `@N` multiplier support
25
+ - Add compound keyframe selector support in core engine (e.g. `"0%, 100%"`)
26
+ - Add Skeleton storybook component, grid previews, and stories
27
+ - Add Skeleton documentation page
28
+
3
29
  ## 3.2.0
4
30
 
5
31
  ### Minor Changes
@@ -433,7 +433,8 @@ export declare type Recipe<Name extends string = string, Variants extends Varian
433
433
  match: {
434
434
  [K in keyof Variants]?: keyof Variants[K] & string;
435
435
  };
436
- css: VariantDeclarationsBlock;
436
+ css?: VariantDeclarationsBlock;
437
+ className?: string;
437
438
  }>;
438
439
  _runtime?: RecipeRuntime<Variants>;
439
440
  _exportName?: string;
@@ -454,6 +455,7 @@ export declare type RecipeRuntime<Variants extends VariantsBase = VariantsBase>
454
455
  [K in keyof Variants]?: keyof Variants[K] & string;
455
456
  };
456
457
  css?: RuntimeVariantDeclarationsBlock;
458
+ className?: string;
457
459
  }>;
458
460
  };
459
461
 
@@ -485,6 +487,9 @@ export declare type Root = {
485
487
  children: ContainerChild[];
486
488
  themes: Theme[];
487
489
  _registry: Map<string, Container | Root | Theme>;
490
+ _usage: {
491
+ variables: Set<string>;
492
+ };
488
493
  };
489
494
 
490
495
  export declare type RuntimeModifierDeclarationsBlock = Record<string, PrimitiveTokenValue>;
@@ -1,56 +1,56 @@
1
- function $(e) {
1
+ function x(e) {
2
2
  return typeof e == "object" && e !== null;
3
3
  }
4
4
  function g(e, t) {
5
- return $(e) && "type" in e && e.type === t;
5
+ return x(e) && "type" in e && e.type === t;
6
6
  }
7
- function H(e) {
7
+ function L(e) {
8
8
  return g(e, "variable");
9
9
  }
10
- function A(e) {
10
+ function b(e) {
11
11
  return g(e, "reference");
12
12
  }
13
- function _e(e) {
13
+ function Fe(e) {
14
14
  return g(e, "selector");
15
15
  }
16
16
  function te(e) {
17
17
  return g(e, "at-rule");
18
18
  }
19
- function Oe(e) {
19
+ function Ne(e) {
20
20
  return g(e, "utility");
21
21
  }
22
22
  function ne(e) {
23
23
  return g(e, "modifier");
24
24
  }
25
- function N(e) {
25
+ function T(e) {
26
26
  return g(e, "css");
27
27
  }
28
28
  function Se(e) {
29
29
  return g(e, "theme");
30
30
  }
31
- function M(e) {
31
+ function $(e) {
32
32
  return g(e, "root");
33
33
  }
34
- function Te(e) {
34
+ function Oe(e) {
35
35
  return g(e, "recipe");
36
36
  }
37
37
  function re(e) {
38
38
  return typeof e == "string" || typeof e == "number" || typeof e == "boolean" || e === null;
39
39
  }
40
40
  function B(e) {
41
- return re(e) || A(e) || N(e) || Array.isArray(e) && e.every(B);
41
+ return re(e) || b(e) || T(e) || Array.isArray(e) && e.every(B);
42
42
  }
43
- function Ne(e) {
44
- return $(e) && "id" in e && "children" in e && "declarations" in e && "variables" in e;
43
+ function Te(e) {
44
+ return x(e) && "id" in e && "children" in e && "declarations" in e && "variables" in e;
45
45
  }
46
- function L(e) {
47
- return $(e) && "children" in e && "declarations" in e && "variables" in e;
46
+ function G(e) {
47
+ return x(e) && "children" in e && "declarations" in e && "variables" in e;
48
48
  }
49
49
  function ie(e) {
50
50
  return typeof e == "string" && e.startsWith("@");
51
51
  }
52
52
  function Be(e) {
53
- return $(e) && "id" in e && "root" in e && "variable" in e && "selector" in e && "recipe" in e && typeof e.id == "string" && M(e.root);
53
+ return x(e) && "id" in e && "root" in e && "variable" in e && "selector" in e && "recipe" in e && typeof e.id == "string" && $(e.root);
54
54
  }
55
55
  function se(e) {
56
56
  let t = 5381;
@@ -58,7 +58,7 @@ function se(e) {
58
58
  t = (t << 5) + t + e.charCodeAt(r) & 4294967295;
59
59
  return (t >>> 0).toString(16).padStart(7, "0").slice(0, 7);
60
60
  }
61
- function G(e) {
61
+ function z(e) {
62
62
  const t = typeof e == "function" ? { replacer: e } : e ?? {}, { replacer: r = (o) => o, namespace: n } = t, s = Array.isArray(n) ? n : n ? [n] : [];
63
63
  return (o) => {
64
64
  let i = o, f;
@@ -71,7 +71,7 @@ function G(e) {
71
71
  type: "reference",
72
72
  name: l
73
73
  };
74
- } else if (A(i)) {
74
+ } else if (b(i)) {
75
75
  let c = i.name;
76
76
  for (const a of s)
77
77
  if (c.startsWith(`${a}.`)) {
@@ -96,13 +96,16 @@ const Pe = ({
96
96
  ...r,
97
97
  e,
98
98
  ...t === "default" ? [] : [t]
99
- ].filter(Boolean).join(":")}`, _ = /@([\w.-]+)/g;
100
- function z(e) {
99
+ ].filter(Boolean).join(":")}`, F = /@([\w.-]+)/g;
100
+ function P(e) {
101
101
  const t = [];
102
102
  let r = 0, n;
103
- for (_.lastIndex = 0; (n = _.exec(e)) !== null; )
104
- t.push(e.slice(r, n.index)), t.push({ type: "reference", name: n[1] }), r = _.lastIndex;
105
- return t.push(e.slice(r)), t;
103
+ for (F.lastIndex = 0; (n = F.exec(e)) !== null; ) {
104
+ const o = e.slice(r, n.index);
105
+ o !== "" && t.push(o), t.push({ type: "reference", name: n[1] }), r = F.lastIndex;
106
+ }
107
+ const s = e.slice(r);
108
+ return s !== "" && t.push(s), t;
106
109
  }
107
110
  function oe(e, t, r) {
108
111
  let n = t;
@@ -122,23 +125,28 @@ function ce(e, t, r) {
122
125
  `[styleframe] Variable "${e}" is not defined. Check that the variable exists before referencing it with "@${e}".`
123
126
  );
124
127
  }
125
- function C(e, t) {
128
+ function I(e, t) {
126
129
  return function(n) {
127
130
  if (typeof n != "string" || !n.includes("@"))
128
131
  return n;
129
132
  if (ie(n) && /^@[\w.-]+$/.test(n)) {
130
133
  const i = n.slice(1);
131
- return ce(i, e, t), { type: "reference", name: i };
134
+ return ce(i, e, t), t._usage.variables.add(i), { type: "reference", name: i };
132
135
  }
133
- const s = z(n);
134
- return s.some((i) => A(i)) ? { type: "css", value: s } : n;
136
+ const s = P(n);
137
+ if (s.some((i) => b(i))) {
138
+ for (const i of s)
139
+ b(i) && t._usage.variables.add(i.name);
140
+ return { type: "css", value: s };
141
+ }
142
+ return n;
135
143
  };
136
144
  }
137
145
  function q(e, t) {
138
146
  return function(n, s) {
139
- const o = C(e, t), i = s != null ? o(s) : s;
140
- if (H(n))
141
- return {
147
+ const o = I(e, t), i = s != null ? o(s) : s;
148
+ if (L(n))
149
+ return t._usage.variables.add(n.name), {
142
150
  type: "reference",
143
151
  name: n.name,
144
152
  fallback: i
@@ -147,7 +155,7 @@ function q(e, t) {
147
155
  throw new Error(
148
156
  `[styleframe] ref() received ${String(n)}. This usually means you're referencing a variable that doesn't exist.`
149
157
  );
150
- return {
158
+ return t._usage.variables.add(n), {
151
159
  type: "reference",
152
160
  name: n,
153
161
  fallback: i
@@ -160,9 +168,9 @@ function fe(e, t) {
160
168
  return {
161
169
  type: "css",
162
170
  value: s.reduce((f, c, a) => {
163
- if (f.push(...z(c)), a < o.length) {
171
+ if (f.push(...P(c)), a < o.length) {
164
172
  const l = o[a];
165
- H(l) ? f.push(r(l)) : te(l) ? f.push(l.rule) : f.push(l);
173
+ L(l) ? f.push(r(l)) : te(l) ? f.push(l.rule) : typeof l == "string" && l.includes("@") ? f.push(...P(l)) : f.push(l);
166
174
  }
167
175
  return f;
168
176
  }, [])
@@ -310,8 +318,8 @@ function ue(e) {
310
318
  return t.pop(), r.pop(), a;
311
319
  }
312
320
  }
313
- const k = ae();
314
- function b(e, t = 8) {
321
+ const M = ae();
322
+ function A(e, t = 8) {
315
323
  const r = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
316
324
  let n = "";
317
325
  for (let s = 0; s < t; s++) {
@@ -340,32 +348,32 @@ function le(e, t) {
340
348
  throw new Error(`Modifier "${t}" not found`);
341
349
  return r;
342
350
  }
343
- function O(e, t) {
351
+ function N(e, t) {
344
352
  if (e === t) return !0;
345
353
  if (typeof e != typeof t) return !1;
346
354
  if (e === null || t === null) return e === t;
347
355
  if (typeof e != "object" || typeof t != "object") return !1;
348
356
  if (Array.isArray(e) && Array.isArray(t))
349
- return e.length !== t.length ? !1 : e.every((r, n) => O(r, t[n]));
357
+ return e.length !== t.length ? !1 : e.every((r, n) => N(r, t[n]));
350
358
  if ("type" in e && "type" in t) {
351
359
  if (e.type !== t.type) return !1;
352
- if (A(e) && A(t))
353
- return e.name === t.name && O(e.fallback, t.fallback);
354
- if (N(e) && N(t))
355
- return O(e.value, t.value);
360
+ if (b(e) && b(t))
361
+ return e.name === t.name && N(e.fallback, t.fallback);
362
+ if (T(e) && T(t))
363
+ return N(e.value, t.value);
356
364
  }
357
365
  return !1;
358
366
  }
359
367
  const X = "__licenseRequired";
360
368
  function de(e) {
361
- P(e) || Object.defineProperty(e, X, {
369
+ U(e) || Object.defineProperty(e, X, {
362
370
  value: !0,
363
371
  writable: !1,
364
372
  configurable: !1,
365
373
  enumerable: !0
366
374
  });
367
375
  }
368
- function P(e) {
376
+ function U(e) {
369
377
  return Object.prototype.hasOwnProperty.call(e, X);
370
378
  }
371
379
  function ye(e, t) {
@@ -393,7 +401,7 @@ function pe(e, t) {
393
401
  }
394
402
  function Y(e, t) {
395
403
  return Object.keys(e).reduce(
396
- (r, n) => (n === "variables" ? r.variables = ye(e.variables, t.variables) : n === "declarations" ? r.declarations = { ...e.declarations, ...t.declarations } : n === "themes" && M(r) && M(e) && M(t) ? r.themes = pe(e.themes, t.themes) : Array.isArray(e[n]) && (r[n] = e[n].concat(
404
+ (r, n) => (n === "variables" ? r.variables = ye(e.variables, t.variables) : n === "declarations" ? r.declarations = { ...e.declarations, ...t.declarations } : n === "themes" && $(r) && $(e) && $(t) ? r.themes = pe(e.themes, t.themes) : Array.isArray(e[n]) && (r[n] = e[n].concat(
397
405
  t[n]
398
406
  )), r),
399
407
  {
@@ -402,14 +410,14 @@ function Y(e, t) {
402
410
  }
403
411
  );
404
412
  }
405
- function U(e, t) {
413
+ function D(e, t) {
406
414
  for (const r of e)
407
- "id" in r && typeof r.id == "string" && (t._registry.set(r.id, r), "children" in r && U(r.children, t));
415
+ "id" in r && typeof r.id == "string" && (t._registry.set(r.id, r), "children" in r && D(r.children, t));
408
416
  }
409
417
  function me(e) {
410
- e._registry = /* @__PURE__ */ new Map(), e._registry.set(e.id, e), U(e.children, e);
418
+ e._registry = /* @__PURE__ */ new Map(), e._registry.set(e.id, e), D(e.children, e);
411
419
  for (const t of e.themes)
412
- e._registry.set(t.id, t), U(t.children, e);
420
+ e._registry.set(t.id, t), D(t.children, e);
413
421
  }
414
422
  function Ke(e, ...t) {
415
423
  return t.reduce((r, n) => {
@@ -417,14 +425,14 @@ function Ke(e, ...t) {
417
425
  ...r,
418
426
  root: Y(r.root, n.root)
419
427
  };
420
- return me(s.root), (P(r) || P(n)) && de(s), s;
428
+ return me(s.root), (U(r) || U(n)) && de(s), s;
421
429
  }, e);
422
430
  }
423
- function I(e, t) {
431
+ function K(e, t) {
424
432
  return function(n, s, o) {
425
433
  const i = {
426
434
  type: "at-rule",
427
- id: b("ar-"),
435
+ id: A("ar-"),
428
436
  parentId: e.id,
429
437
  identifier: n,
430
438
  rule: s,
@@ -433,8 +441,8 @@ function I(e, t) {
433
441
  children: []
434
442
  };
435
443
  t._registry.set(i.id, i);
436
- const f = w(i, t);
437
- return typeof o == "function" ? i.declarations = o(f) ?? {} : L(o) ? (i.variables = o.variables, i.declarations = o.declarations, i.children = o.children) : o && (i.declarations = o), x(
444
+ const f = v(i, t);
445
+ return typeof o == "function" ? i.declarations = o(f) ?? {} : G(o) ? (i.variables = o.variables, i.declarations = o.declarations, i.children = o.children) : o && (i.declarations = o), _(
438
446
  i.declarations,
439
447
  f,
440
448
  i,
@@ -443,13 +451,13 @@ function I(e, t) {
443
451
  };
444
452
  }
445
453
  function he(e, t) {
446
- const r = I(e, t);
454
+ const r = K(e, t);
447
455
  return function(s, o) {
448
456
  return r("media", s, o);
449
457
  };
450
458
  }
451
459
  function ge(e, t) {
452
- const r = I(e, t);
460
+ const r = K(e, t);
453
461
  return function(s, o) {
454
462
  return r("keyframes", s, o);
455
463
  };
@@ -458,7 +466,7 @@ function be(e, t) {
458
466
  return function(n, s) {
459
467
  const o = {
460
468
  type: "selector",
461
- id: b("sel-"),
469
+ id: A("sel-"),
462
470
  parentId: e.id,
463
471
  query: n,
464
472
  declarations: {},
@@ -466,8 +474,8 @@ function be(e, t) {
466
474
  children: []
467
475
  };
468
476
  t._registry.set(o.id, o);
469
- const i = w(o, t);
470
- return typeof s == "function" ? o.declarations = s(i) ?? {} : L(s) ? (o.variables = s.variables, o.declarations = s.declarations, o.children = s.children) : o.declarations = s, x(
477
+ const i = v(o, t);
478
+ return typeof s == "function" ? o.declarations = s(i) ?? {} : G(s) ? (o.variables = s.variables, o.declarations = s.declarations, o.children = s.children) : o.declarations = s, _(
471
479
  o.declarations,
472
480
  i,
473
481
  o,
@@ -479,7 +487,7 @@ function Ae(e, t) {
479
487
  return function(n, s, o = {
480
488
  default: !1
481
489
  }) {
482
- const i = typeof n == "string" ? n : n.name, c = C(e, t)(s), a = e.variables.find(
490
+ const i = typeof n == "string" ? n : n.name, c = I(e, t)(s), a = e.variables.find(
483
491
  (u) => u.name === i
484
492
  );
485
493
  if (o.default && a)
@@ -488,7 +496,7 @@ function Ae(e, t) {
488
496
  return a.value = c, a;
489
497
  const l = {
490
498
  type: "variable",
491
- id: b("var-"),
499
+ id: A("var-"),
492
500
  parentId: e.id,
493
501
  name: i,
494
502
  value: c
@@ -496,8 +504,8 @@ function Ae(e, t) {
496
504
  return e.variables.push(l), l;
497
505
  };
498
506
  }
499
- function w(e, t) {
500
- const r = Ae(e, t), n = be(e, t), s = I(e, t), o = ge(t, t), i = he(e, t), f = q(t, t), c = fe(t, t);
507
+ function v(e, t) {
508
+ const r = Ae(e, t), n = be(e, t), s = K(e, t), o = ge(t, t), i = he(e, t), f = q(t, t), c = fe(t, t);
501
509
  return {
502
510
  variable: r,
503
511
  selector: n,
@@ -508,7 +516,7 @@ function w(e, t) {
508
516
  css: c
509
517
  };
510
518
  }
511
- function x(e, t, r, n) {
519
+ function _(e, t, r, n) {
512
520
  for (const o in e)
513
521
  if (o.startsWith("@")) {
514
522
  const i = e[o];
@@ -516,11 +524,11 @@ function x(e, t, r, n) {
516
524
  const f = o.replace(/^@(\w+).*/, "$1"), c = o.replace(`@${f}`, "").trim();
517
525
  t.atRule(f, c, i), delete e[o];
518
526
  }
519
- } else if (/^[.&:]/.test(o) || /^\d+%$/.test(o) || o === "from" || o === "to") {
527
+ } else if (/^[.&:]/.test(o) || /^(\d+%|from|to)(\s*,\s*(\d+%|from|to))*$/.test(o)) {
520
528
  const i = e[o];
521
529
  typeof i == "object" && (t.selector(o, i), delete e[o]);
522
530
  }
523
- const s = C(r, n);
531
+ const s = I(r, n);
524
532
  for (const o in e) {
525
533
  const i = e[o];
526
534
  if (B(i)) {
@@ -530,10 +538,10 @@ function x(e, t, r, n) {
530
538
  }
531
539
  return e;
532
540
  }
533
- function we(e, t, r) {
541
+ function ve(e, t, r) {
534
542
  const n = {
535
543
  ...e,
536
- id: b("ut-"),
544
+ id: A("ut-"),
537
545
  parentId: e.parentId,
538
546
  declarations: { ...e.declarations },
539
547
  variables: [...e.variables],
@@ -542,20 +550,20 @@ function we(e, t, r) {
542
550
  };
543
551
  if (t._registry.set(n.id, n), r.size > 0) {
544
552
  const s = [...r.values()];
545
- let o = k(e.declarations);
553
+ let o = M(e.declarations);
546
554
  n.declarations = {}, n.variables = [], n.children = [];
547
555
  for (let f = s.length - 1; f >= 0; f--) {
548
- const c = w(n, t), a = s[f]?.factory({
556
+ const c = v(n, t), a = s[f]?.factory({
549
557
  ...c,
550
- declarations: k(o),
551
- variables: k(e.variables),
552
- children: k(e.children)
558
+ declarations: M(o),
559
+ variables: M(e.variables),
560
+ children: M(e.children)
553
561
  });
554
562
  a && (o = a);
555
563
  }
556
564
  n.declarations = o;
557
- const i = w(n, t);
558
- x(
565
+ const i = v(n, t);
566
+ _(
559
567
  n.declarations,
560
568
  i,
561
569
  n,
@@ -564,7 +572,7 @@ function we(e, t, r) {
564
572
  }
565
573
  return n;
566
574
  }
567
- function ve(e, t) {
575
+ function we(e, t) {
568
576
  return function(n, s) {
569
577
  const o = {
570
578
  type: "modifier",
@@ -577,7 +585,7 @@ function ve(e, t) {
577
585
  function je() {
578
586
  const e = {
579
587
  type: "root",
580
- id: b("rt-"),
588
+ id: A("rt-"),
581
589
  declarations: {},
582
590
  utilities: [],
583
591
  modifiers: [],
@@ -585,12 +593,15 @@ function je() {
585
593
  variables: [],
586
594
  children: [],
587
595
  themes: [],
588
- _registry: /* @__PURE__ */ new Map()
596
+ _registry: /* @__PURE__ */ new Map(),
597
+ _usage: {
598
+ variables: /* @__PURE__ */ new Set()
599
+ }
589
600
  };
590
601
  return e._registry.set(e.id, e), e;
591
602
  }
592
603
  function Ve(e, t) {
593
- const r = G({ namespace: e });
604
+ const r = z({ namespace: e });
594
605
  return (n) => {
595
606
  if (typeof n == "string" && n[0] === "@") {
596
607
  const s = n.slice(1), o = e.find(
@@ -605,7 +616,7 @@ function Ve(e, t) {
605
616
  name: s
606
617
  }
607
618
  };
608
- } else
619
+ } else {
609
620
  for (const i of e) {
610
621
  const f = `${i}.${s}`;
611
622
  if (t.variables.some((c) => c.name === f))
@@ -616,6 +627,14 @@ function Ve(e, t) {
616
627
  }
617
628
  };
618
629
  }
630
+ if (t.variables.some((i) => i.name === s))
631
+ return {
632
+ [s]: {
633
+ type: "reference",
634
+ name: s
635
+ }
636
+ };
637
+ }
619
638
  return r(n);
620
639
  }
621
640
  return r(n);
@@ -645,7 +664,7 @@ function ke(e, t) {
645
664
  name: n,
646
665
  factory: s,
647
666
  values: [],
648
- autogenerate: o.autogenerate ?? (Array.isArray(o.namespace) ? Ve(o.namespace, t) : G(
667
+ autogenerate: o.autogenerate ?? (Array.isArray(o.namespace) ? Ve(o.namespace, t) : z(
649
668
  o.namespace ? { namespace: o.namespace } : void 0
650
669
  )),
651
670
  namespace: o.namespace,
@@ -667,29 +686,32 @@ function ke(e, t) {
667
686
  const m = d.slice(1);
668
687
  !Array.isArray(l) && m in l && (y = l[m]);
669
688
  }
670
- if (f.namespace && A(d))
689
+ if (f.namespace && b(d))
671
690
  if (t.variables.some((m) => m.name === d.name))
672
691
  y = d;
673
692
  else {
674
693
  const m = Array.isArray(f.namespace) ? f.namespace : [f.namespace];
675
- let R = !1;
676
- for (const E of m) {
677
- const v = `${E}.${u}`;
678
- if (v !== d.name && t.variables.some((V) => V.name === v)) {
694
+ let k = !1;
695
+ for (const V of m) {
696
+ const w = `${V}.${u}`;
697
+ if (w !== d.name && t.variables.some((R) => R.name === w)) {
679
698
  y = {
680
699
  type: "reference",
681
- name: v
682
- }, R = !0;
700
+ name: w
701
+ }, k = !0;
683
702
  break;
684
703
  }
685
704
  }
686
- R || (y = u);
705
+ k || (t.variables.some((V) => V.name === u) ? y = {
706
+ type: "reference",
707
+ name: u
708
+ } : y = u);
687
709
  }
688
710
  const p = f.values.find(
689
711
  (m) => m.key === u && m.modifiers.length === 0
690
712
  ), h = {
691
713
  type: "utility",
692
- id: b("ut-"),
714
+ id: A("ut-"),
693
715
  parentId: e.id,
694
716
  name: n,
695
717
  value: u,
@@ -699,16 +721,16 @@ function ke(e, t) {
699
721
  modifiers: []
700
722
  };
701
723
  t._registry.set(h.id, h);
702
- const K = w(
724
+ const W = v(
703
725
  h,
704
726
  t
705
727
  );
706
728
  if (h.declarations = s({
707
- ...K,
729
+ ...W,
708
730
  value: y
709
- }) ?? {}, x(
731
+ }) ?? {}, _(
710
732
  h.declarations,
711
- K,
733
+ W,
712
734
  h,
713
735
  t
714
736
  ), p || (f.values.push({
@@ -717,19 +739,19 @@ function ke(e, t) {
717
739
  modifiers: []
718
740
  }), e.children.push(h)), a && a.length > 0)
719
741
  for (const m of a) {
720
- const R = Array.isArray(m) ? m : [m], E = Re(R);
721
- for (const v of E) {
722
- const V = [...v.keys()];
742
+ const k = Array.isArray(m) ? m : [m], V = Re(k);
743
+ for (const w of V) {
744
+ const R = [...w.keys()];
723
745
  f.values.find(
724
- (F) => F.key === u && F.modifiers.length === V.length && F.modifiers.every(
725
- (Q, ee) => Q === V[ee]
746
+ (E) => E.key === u && E.modifiers.length === R.length && E.modifiers.every(
747
+ (Q, ee) => Q === R[ee]
726
748
  )
727
749
  ) || (f.values.push({
728
750
  key: u,
729
751
  value: y,
730
- modifiers: V
752
+ modifiers: R
731
753
  }), e.children.push(
732
- we(h, t, v)
754
+ ve(h, t, w)
733
755
  ));
734
756
  }
735
757
  }
@@ -743,7 +765,7 @@ function Me(e, t) {
743
765
  return function(n, s) {
744
766
  const o = t.themes.find((c) => c.name === n), i = o ?? {
745
767
  type: "theme",
746
- id: b("th-"),
768
+ id: A("th-"),
747
769
  parentId: t.id,
748
770
  name: n,
749
771
  declarations: {},
@@ -751,7 +773,7 @@ function Me(e, t) {
751
773
  children: []
752
774
  };
753
775
  o || (t._registry.set(i.id, i), t.themes.push(i));
754
- const f = w(i, t);
776
+ const f = v(i, t);
755
777
  return s && s(f), i;
756
778
  };
757
779
  }
@@ -761,10 +783,10 @@ function $e(e, t) {
761
783
  type: "recipe",
762
784
  ...n
763
785
  };
764
- return s._runtime = xe(s, t), Ee(s, t), t.recipes.push(s), s;
786
+ return s._runtime = xe(s, t), _e(s, t), t.recipes.push(s), s;
765
787
  };
766
788
  }
767
- function W(e, t) {
789
+ function H(e, t) {
768
790
  const r = e.autogenerate(t);
769
791
  return Object.keys(r)[0] ?? "default";
770
792
  }
@@ -774,12 +796,12 @@ function S(e, t) {
774
796
  if (Z(s)) {
775
797
  const o = {};
776
798
  for (const [i, f] of Object.entries(s)) {
777
- const c = D(t, i);
799
+ const c = C(t, i);
778
800
  if (!c)
779
801
  throw new Error(
780
802
  `[styleframe] Utility "${i}" not found in registry. Make sure the utility is registered before using it in a recipe.`
781
803
  );
782
- o[i] = W(
804
+ o[i] = H(
783
805
  c,
784
806
  f
785
807
  );
@@ -788,12 +810,12 @@ function S(e, t) {
788
810
  } else if (typeof s == "boolean")
789
811
  r[n] = s;
790
812
  else {
791
- const o = D(t, n);
813
+ const o = C(t, n);
792
814
  if (!o)
793
815
  throw new Error(
794
816
  `[styleframe] Utility "${n}" not found in registry. Make sure the utility is registered before using it in a recipe.`
795
817
  );
796
- r[n] = W(o, s);
818
+ r[n] = H(o, s);
797
819
  }
798
820
  return r;
799
821
  }
@@ -816,16 +838,17 @@ function xe(e, t) {
816
838
  }
817
839
  return e.defaultVariants && (r.defaultVariants = { ...e.defaultVariants }), e.compoundVariants && (r.compoundVariants = e.compoundVariants.map((n) => ({
818
840
  match: { ...n.match },
819
- css: S(n.css, t)
841
+ ...n.css ? { css: S(n.css, t) } : {},
842
+ ...n.className ? { className: n.className } : {}
820
843
  }))), r;
821
844
  }
822
845
  function Z(e) {
823
- return !A(e) && typeof e == "object" && e !== null;
846
+ return !b(e) && typeof e == "object" && e !== null;
824
847
  }
825
848
  function J(e) {
826
849
  return e.startsWith("&::") ? e.slice(3) : e.startsWith("&:") ? e.slice(2) : e;
827
850
  }
828
- function T(e, t) {
851
+ function O(e, t) {
829
852
  const r = (n, s, o) => {
830
853
  let i = t.get(n);
831
854
  i || (i = [], t.set(n, i)), i.push({ value: s, modifiers: o });
@@ -838,28 +861,28 @@ function T(e, t) {
838
861
  } else
839
862
  r(n, s, []);
840
863
  }
841
- function D(e, t) {
864
+ function C(e, t) {
842
865
  const r = e.utilities.find((s) => s.name === t);
843
866
  if (r)
844
867
  return r;
845
868
  const n = t.replace(/[A-Z]/g, (s) => `-${s.toLowerCase()}`);
846
869
  return e.utilities.find((s) => s.name === n);
847
870
  }
848
- function Ee(e, t) {
871
+ function _e(e, t) {
849
872
  const r = /* @__PURE__ */ new Map();
850
- if (e.base && T(e.base, r), e.variants)
873
+ if (e.base && O(e.base, r), e.variants)
851
874
  for (const s of Object.values(e.variants))
852
875
  for (const o of Object.values(s))
853
- T(
876
+ O(
854
877
  o,
855
878
  r
856
879
  );
857
880
  if (e.compoundVariants)
858
881
  for (const s of e.compoundVariants)
859
- s.css && T(s.css, r);
882
+ s.css && O(s.css, r);
860
883
  const n = /* @__PURE__ */ new Map();
861
884
  for (const [s, o] of r) {
862
- const i = D(t, s);
885
+ const i = C(t, s);
863
886
  if (!i)
864
887
  throw new Error(
865
888
  `[styleframe] Utility "${s}" not found in registry. Make sure the utility is registered before using it in a recipe.`
@@ -886,7 +909,7 @@ function Ee(e, t) {
886
909
  }
887
910
  }
888
911
  function We(e) {
889
- const t = b("sf-"), r = je(), n = { ...e }, s = ke(r, r), o = ve(r, r), i = $e(r, r), f = Me(r, r), { variable: c, selector: a, atRule: l, keyframes: u, media: d, ref: y, css: p } = w(r, r);
912
+ const t = A("sf-"), r = je(), n = { ...e }, s = ke(r, r), o = we(r, r), i = $e(r, r), f = Me(r, r), { variable: c, selector: a, atRule: l, keyframes: u, media: d, ref: y, css: p } = v(r, r);
890
913
  return {
891
914
  id: t,
892
915
  root: r,
@@ -905,16 +928,16 @@ function We(e) {
905
928
  };
906
929
  }
907
930
  export {
908
- we as applyModifiers,
931
+ ve as applyModifiers,
909
932
  Ue as capitalizeFirst,
910
933
  De as classNameToCssSelector,
911
- I as createAtRuleFunction,
934
+ K as createAtRuleFunction,
912
935
  fe as createCssFunction,
913
- w as createDeclarationsCallbackContext,
936
+ v as createDeclarationsCallbackContext,
914
937
  ge as createKeyframesFunction,
915
938
  he as createMediaFunction,
916
- ve as createModifierFunction,
917
- C as createPropertyValueResolver,
939
+ we as createModifierFunction,
940
+ I as createPropertyValueResolver,
918
941
  $e as createRecipeFunction,
919
942
  q as createRefFunction,
920
943
  je as createRoot,
@@ -922,44 +945,44 @@ export {
922
945
  Me as createThemeFunction,
923
946
  ke as createUtilityFunction,
924
947
  Ae as createVariableFunction,
925
- k as deepClone,
948
+ M as deepClone,
926
949
  Pe as defaultUtilitySelectorFn,
927
950
  oe as findVariableInScope,
928
- b as generateRandomId,
951
+ A as generateRandomId,
929
952
  xe as generateRecipeRuntime,
930
953
  le as getModifier,
931
954
  Ie as getUtility,
932
955
  Ce as getVariable,
933
956
  se as hashValue,
934
957
  te as isAtRule,
935
- N as isCSS,
936
- Ne as isContainer,
937
- L as isContainerInput,
958
+ T as isCSS,
959
+ Te as isContainer,
960
+ G as isContainerInput,
938
961
  ie as isKeyReferenceValue,
939
962
  ne as isModifier,
940
- $ as isObject,
963
+ x as isObject,
941
964
  re as isPrimitiveTokenValue,
942
- Te as isRecipe,
943
- A as isRef,
944
- M as isRoot,
945
- _e as isSelector,
965
+ Oe as isRecipe,
966
+ b as isRef,
967
+ $ as isRoot,
968
+ Fe as isSelector,
946
969
  Be as isStyleframe,
947
970
  Se as isTheme,
948
971
  g as isToken,
949
- O as isTokenEqual,
972
+ N as isTokenEqual,
950
973
  B as isTokenValue,
951
- Oe as isUtility,
952
- H as isVariable,
974
+ Ne as isUtility,
975
+ L as isVariable,
953
976
  Ke as merge,
954
977
  Y as mergeContainers,
955
978
  pe as mergeThemesArray,
956
979
  ye as mergeVariablesArray,
957
- z as parseAtReferences,
958
- x as parseDeclarationsBlock,
959
- Ee as processRecipeUtilities,
980
+ P as parseAtReferences,
981
+ _ as parseDeclarationsBlock,
982
+ _e as processRecipeUtilities,
960
983
  me as rebuildRegistry,
961
984
  ae as rfdc,
962
985
  We as styleframe,
963
- G as transformUtilityKey,
986
+ z as transformUtilityKey,
964
987
  ce as validateReference
965
988
  };
@@ -1 +1 @@
1
- (function(u,A){typeof exports=="object"&&typeof module<"u"?A(exports):typeof define=="function"&&define.amd?define(["exports"],A):(u=typeof globalThis<"u"?globalThis:u||self,A(u.styleframe={}))})(this,(function(u){"use strict";function A(e){return typeof e=="object"&&e!==null}function g(e,t){return A(e)&&"type"in e&&e.type===t}function U(e){return g(e,"variable")}function w(e){return g(e,"reference")}function ke(e){return g(e,"selector")}function Y(e){return g(e,"at-rule")}function Me(e){return g(e,"utility")}function Z(e){return g(e,"modifier")}function T(e){return g(e,"css")}function Fe(e){return g(e,"theme")}function k(e){return g(e,"root")}function $e(e){return g(e,"recipe")}function J(e){return typeof e=="string"||typeof e=="number"||typeof e=="boolean"||e===null}function S(e){return J(e)||w(e)||T(e)||Array.isArray(e)&&e.every(S)}function Te(e){return A(e)&&"id"in e&&"children"in e&&"declarations"in e&&"variables"in e}function N(e){return A(e)&&"children"in e&&"declarations"in e&&"variables"in e}function Q(e){return typeof e=="string"&&e.startsWith("@")}function Se(e){return A(e)&&"id"in e&&"root"in e&&"variable"in e&&"selector"in e&&"recipe"in e&&typeof e.id=="string"&&k(e.root)}function x(e){let t=5381;for(let r=0;r<e.length;r++)t=(t<<5)+t+e.charCodeAt(r)&4294967295;return(t>>>0).toString(16).padStart(7,"0").slice(0,7)}function P(e){const t=typeof e=="function"?{replacer:e}:e??{},{replacer:r=c=>c,namespace:n}=t,s=Array.isArray(n)?n:n?[n]:[];return c=>{let i=c,a;if(typeof i=="string"&&i[0]==="@"){const o=i.slice(1),f=s.find(y=>o===y||o.startsWith(`${y}.`));let d,l;f?(d=o,l=o.startsWith(`${f}.`)?o.slice(f.length+1):o):s.length>0?(d=`${s[0]}.${o}`,l=o):(d=o,l=o),a=r(l),i={type:"reference",name:d}}else if(w(i)){let o=i.name;for(const f of s)if(o.startsWith(`${f}.`)){o=o.slice(f.length+1);break}a=r(o)}else{const o=String(c).trim();/\s/.test(o)?a=x(o):a=`[${o}]`}return{[a]:i}}}const Ee=({name:e,value:t,modifiers:r})=>`_${[...r,e,...t==="default"?[]:[t]].filter(Boolean).join(":")}`,B=/@([\w.-]+)/g;function D(e){const t=[];let r=0,n;for(B.lastIndex=0;(n=B.exec(e))!==null;)t.push(e.slice(r,n.index)),t.push({type:"reference",name:n[1]}),r=B.lastIndex;return t.push(e.slice(r)),t}function ee(e,t,r){let n=t;for(;n;){if(n.variables.some(s=>s.name===e))return!0;if(n.parentId)n=r._registry.get(n.parentId);else break}return!1}function te(e,t,r){if(!ee(e,t,r))throw new Error(`[styleframe] Variable "${e}" is not defined. Check that the variable exists before referencing it with "@${e}".`)}function E(e,t){return function(n){if(typeof n!="string"||!n.includes("@"))return n;if(Q(n)&&/^@[\w.-]+$/.test(n)){const i=n.slice(1);return te(i,e,t),{type:"reference",name:i}}const s=D(n);return s.some(i=>w(i))?{type:"css",value:s}:n}}function I(e,t){return function(n,s){const c=E(e,t),i=s!=null?c(s):s;if(U(n))return{type:"reference",name:n.name,fallback:i};if(n==null)throw new Error(`[styleframe] ref() received ${String(n)}. This usually means you're referencing a variable that doesn't exist.`);return{type:"reference",name:n,fallback:i}}}function ne(e,t){const r=I(e,t);return function(s,...c){return{type:"css",value:s.reduce((a,o,f)=>{if(a.push(...D(o)),f<c.length){const d=c[f];U(d)?a.push(r(d)):Y(d)?a.push(d.rule):a.push(d)}return a},[])}}}function _e(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Oe(e){return`.${e.replace(/[[\].#()%,:/]/g,"\\$&")}`}function R(e){if(e instanceof Buffer)return Buffer.from(e);const t=e.constructor;return new t(e.buffer.slice(0),e.byteOffset,e.byteLength/e.BYTES_PER_ELEMENT||1)}function re(e){if(e=e||{},e.circular)return Ce(e);const t=new Map;if(t.set(Date,i=>new Date(i)),t.set(Map,(i,a)=>new Map(n(Array.from(i),a))),t.set(Set,(i,a)=>new Set(n(Array.from(i),a))),e.constructorHandlers)for(const i of e.constructorHandlers)t.set(i[0],i[1]);let r;return e.proto?c:s;function n(i,a){const o=Object.keys(i),f=Array.from({length:o.length});for(let d=0;d<o.length;d++){const l=o[d],y=i[l];typeof y!="object"||y===null?f[l]=y:y.constructor!==Object&&(r=t.get(y.constructor))?f[l]=r(y,a):ArrayBuffer.isView(y)?f[l]=R(y):f[l]=a(y)}return f}function s(i){if(typeof i!="object"||i===null)return i;if(Array.isArray(i))return n(i,s);if(i.constructor!==Object&&(r=t.get(i.constructor)))return r(i,s);const a={};for(const o in i){if(Object.hasOwnProperty.call(i,o)===!1)continue;const f=i[o];typeof f!="object"||f===null?a[o]=f:f.constructor!==Object&&(r=t.get(f.constructor))?a[o]=r(f,s):ArrayBuffer.isView(f)?a[o]=R(f):a[o]=s(f)}return a}function c(i){if(typeof i!="object"||i===null)return i;if(Array.isArray(i))return n(i,c);if(i.constructor!==Object&&(r=t.get(i.constructor)))return r(i,c);const a={};for(const o in i){const f=i[o];typeof f!="object"||f===null?a[o]=f:f.constructor!==Object&&(r=t.get(f.constructor))?a[o]=r(f,c):ArrayBuffer.isView(f)?a[o]=R(f):a[o]=c(f)}return a}}function Ce(e){const t=[],r=[],n=new Map;if(n.set(Date,o=>new Date(o)),n.set(Map,(o,f)=>new Map(c(Array.from(o),f))),n.set(Set,(o,f)=>new Set(c(Array.from(o),f))),e.constructorHandlers)for(const o of e.constructorHandlers)n.set(o[0],o[1]);let s;return e.proto?a:i;function c(o,f){const d=Object.keys(o),l=Array.from({length:d.length});for(let y=0;y<d.length;y++){const m=d[y],h=o[m];if(typeof h!="object"||h===null)l[m]=h;else if(h.constructor!==Object&&(s=n.get(h.constructor)))l[m]=s(h,f);else if(ArrayBuffer.isView(h))l[m]=R(h);else{const b=t.indexOf(h);b!==-1?l[m]=r[b]:l[m]=f(h)}}return l}function i(o){if(typeof o!="object"||o===null)return o;if(Array.isArray(o))return c(o,i);if(o.constructor!==Object&&(s=n.get(o.constructor)))return s(o,i);const f={};t.push(o),r.push(f);for(const d in o){if(Object.hasOwnProperty.call(o,d)===!1)continue;const l=o[d];if(typeof l!="object"||l===null)f[d]=l;else if(l.constructor!==Object&&(s=n.get(l.constructor)))f[d]=s(l,i);else if(ArrayBuffer.isView(l))f[d]=R(l);else{const y=t.indexOf(l);y!==-1?f[d]=r[y]:f[d]=i(l)}}return t.pop(),r.pop(),f}function a(o){if(typeof o!="object"||o===null)return o;if(Array.isArray(o))return c(o,a);if(o.constructor!==Object&&(s=n.get(o.constructor)))return s(o,a);const f={};t.push(o),r.push(f);for(const d in o){const l=o[d];if(typeof l!="object"||l===null)f[d]=l;else if(l.constructor!==Object&&(s=n.get(l.constructor)))f[d]=s(l,a);else if(ArrayBuffer.isView(l))f[d]=R(l);else{const y=t.indexOf(l);y!==-1?f[d]=r[y]:f[d]=a(l)}}return t.pop(),r.pop(),f}}const M=re();function v(e,t=8){const r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let n="";for(let s=0;s<t;s++){const c=Math.floor(Math.random()*r.length);n+=r[c]}return e?`${e}${n}`:n}function Ue(e,t){const r=e.variables.find(n=>n.name===t);if(!r)throw new Error(`Variable "${t}" not found`);return r}function Ne(e,t){const r=e.utilities.find(n=>n.name===t);if(!r)throw new Error(`Utility "${t}" not found`);return r}function ie(e,t){const r=e.modifiers.find(n=>n.key.includes(t));if(!r)throw new Error(`Modifier "${t}" not found`);return r}function _(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(e===null||t===null)return e===t;if(typeof e!="object"||typeof t!="object")return!1;if(Array.isArray(e)&&Array.isArray(t))return e.length!==t.length?!1:e.every((r,n)=>_(r,t[n]));if("type"in e&&"type"in t){if(e.type!==t.type)return!1;if(w(e)&&w(t))return e.name===t.name&&_(e.fallback,t.fallback);if(T(e)&&T(t))return _(e.value,t.value)}return!1}const se="__licenseRequired";function Pe(e){K(e)||Object.defineProperty(e,se,{value:!0,writable:!1,configurable:!1,enumerable:!0})}function K(e){return Object.prototype.hasOwnProperty.call(e,se)}function ce(e,t){const r=[...e];for(const n of t){const s=r.find(c=>c.name===n.name);s?s.value=n.value:r.push(n)}return r}function oe(e,t){const r=[...e];for(const n of t){const s=r.find(c=>c.name===n.name);s?Object.assign(s,W(s,n)):r.push(n)}return r}function W(e,t){return Object.keys(e).reduce((r,n)=>(n==="variables"?r.variables=ce(e.variables,t.variables):n==="declarations"?r.declarations={...e.declarations,...t.declarations}:n==="themes"&&k(r)&&k(e)&&k(t)?r.themes=oe(e.themes,t.themes):Array.isArray(e[n])&&(r[n]=e[n].concat(t[n])),r),{...e,...t})}function H(e,t){for(const r of e)"id"in r&&typeof r.id=="string"&&(t._registry.set(r.id,r),"children"in r&&H(r.children,t))}function ae(e){e._registry=new Map,e._registry.set(e.id,e),H(e.children,e);for(const t of e.themes)e._registry.set(t.id,t),H(t.children,e)}function Be(e,...t){return t.reduce((r,n)=>{const s={...r,root:W(r.root,n.root)};return ae(s.root),(K(r)||K(n))&&Pe(s),s},e)}function O(e,t){return function(n,s,c){const i={type:"at-rule",id:v("ar-"),parentId:e.id,identifier:n,rule:s,declarations:{},variables:[],children:[]};t._registry.set(i.id,i);const a=V(i,t);return typeof c=="function"?i.declarations=c(a)??{}:N(c)?(i.variables=c.variables,i.declarations=c.declarations,i.children=c.children):c&&(i.declarations=c),F(i.declarations,a,i,t),e.children.push(i),i}}function fe(e,t){const r=O(e,t);return function(s,c){return r("media",s,c)}}function ue(e,t){const r=O(e,t);return function(s,c){return r("keyframes",s,c)}}function le(e,t){return function(n,s){const c={type:"selector",id:v("sel-"),parentId:e.id,query:n,declarations:{},variables:[],children:[]};t._registry.set(c.id,c);const i=V(c,t);return typeof s=="function"?c.declarations=s(i)??{}:N(s)?(c.variables=s.variables,c.declarations=s.declarations,c.children=s.children):c.declarations=s,F(c.declarations,i,c,t),e.children.push(c),c}}function de(e,t){return function(n,s,c={default:!1}){const i=typeof n=="string"?n:n.name,o=E(e,t)(s),f=e.variables.find(l=>l.name===i);if(c.default&&f)return f;if(f)return f.value=o,f;const d={type:"variable",id:v("var-"),parentId:e.id,name:i,value:o};return e.variables.push(d),d}}function V(e,t){const r=de(e,t),n=le(e,t),s=O(e,t),c=ue(t,t),i=fe(e,t),a=I(t,t),o=ne(t,t);return{variable:r,selector:n,keyframes:c,atRule:s,media:i,ref:a,css:o}}function F(e,t,r,n){for(const c in e)if(c.startsWith("@")){const i=e[c];if(typeof i=="object"&&i!==null&&!S(i)){const a=c.replace(/^@(\w+).*/,"$1"),o=c.replace(`@${a}`,"").trim();t.atRule(a,o,i),delete e[c]}}else if(/^[.&:]/.test(c)||/^\d+%$/.test(c)||c==="from"||c==="to"){const i=e[c];typeof i=="object"&&(t.selector(c,i),delete e[c])}const s=E(r,n);for(const c in e){const i=e[c];if(S(i)){const a=s(i);a!==i&&(e[c]=a)}}return e}function ye(e,t,r){const n={...e,id:v("ut-"),parentId:e.parentId,declarations:{...e.declarations},variables:[...e.variables],children:[...e.children],modifiers:[...r.keys()]};if(t._registry.set(n.id,n),r.size>0){const s=[...r.values()];let c=M(e.declarations);n.declarations={},n.variables=[],n.children=[];for(let a=s.length-1;a>=0;a--){const o=V(n,t),f=s[a]?.factory({...o,declarations:M(c),variables:M(e.variables),children:M(e.children)});f&&(c=f)}n.declarations=c;const i=V(n,t);F(n.declarations,i,n,t)}return n}function me(e,t){return function(n,s){const c={type:"modifier",key:Array.isArray(n)?n:[n],factory:s};return t.modifiers.push(c),c}}function he(){const e={type:"root",id:v("rt-"),declarations:{},utilities:[],modifiers:[],recipes:[],variables:[],children:[],themes:[],_registry:new Map};return e._registry.set(e.id,e),e}function De(e,t){const r=P({namespace:e});return n=>{if(typeof n=="string"&&n[0]==="@"){const s=n.slice(1),c=e.find(i=>s===i||s.startsWith(`${i}.`));if(c){const i=s.slice(c.length+1)||s;if(t.variables.some(a=>a.name===s))return{[i]:{type:"reference",name:s}}}else for(const i of e){const a=`${i}.${s}`;if(t.variables.some(o=>o.name===a))return{[s]:{type:"reference",name:a}}}return r(n)}return r(n)}}function Ie(e){let t=[new Map];for(const r of e){if(!Z(r))continue;const n=[];for(const s of r.key)for(const c of t){const i=new Map(c);i.set(s,r),n.push(i)}t=n}return t.filter(r=>r.size>0)}function pe(e,t){return function(n,s,c={}){const i=t.utilities.find(o=>o.name===n);if(i)return i.create;const a={type:"utility",name:n,factory:s,values:[],autogenerate:c.autogenerate??(Array.isArray(c.namespace)?De(c.namespace,t):P(c.namespace?{namespace:c.namespace}:void 0)),namespace:c.namespace,create:(o,f=[])=>{let d=o;if(Array.isArray(o)){d={};for(const l of o){const y=a.autogenerate(l);d={...d,...y}}}for(const[l,y]of Object.entries(d)){let m=y;if(typeof y=="string"&&y[0]==="@"){const p=y.slice(1);!Array.isArray(d)&&p in d&&(m=d[p])}if(a.namespace&&w(y))if(t.variables.some(p=>p.name===y.name))m=y;else{const p=Array.isArray(a.namespace)?a.namespace:[a.namespace];let C=!1;for(const q of p){const j=`${q}.${l}`;if(j!==y.name&&t.variables.some($=>$.name===j)){m={type:"reference",name:j},C=!0;break}}C||(m=l)}const h=a.values.find(p=>p.key===l&&p.modifiers.length===0),b={type:"utility",id:v("ut-"),parentId:e.id,name:n,value:l,declarations:{},variables:[],children:[],modifiers:[]};t._registry.set(b.id,b);const je=V(b,t);if(b.declarations=s({...je,value:m})??{},F(b.declarations,je,b,t),h||(a.values.push({key:l,value:m,modifiers:[]}),e.children.push(b)),f&&f.length>0)for(const p of f){const C=Array.isArray(p)?p:[p],q=Ie(C);for(const j of q){const $=[...j.keys()];a.values.find(X=>X.key===l&&X.modifiers.length===$.length&&X.modifiers.every((We,He)=>We===$[He]))||(a.values.push({key:l,value:m,modifiers:$}),e.children.push(ye(b,t,j)))}}}}};return t.utilities.push(a),a.create}}function ge(e,t){return function(n,s){const c=t.themes.find(o=>o.name===n),i=c??{type:"theme",id:v("th-"),parentId:t.id,name:n,declarations:{},variables:[],children:[]};c||(t._registry.set(i.id,i),t.themes.push(i));const a=V(i,t);return s&&s(a),i}}function be(e,t){return function(n){const s={type:"recipe",...n};return s._runtime=ve(s,t),Re(s,t),t.recipes.push(s),s}}function Ae(e,t){const r=e.autogenerate(t);return Object.keys(r)[0]??"default"}function L(e,t){const r={};for(const[n,s]of Object.entries(e))if(we(s)){const c={};for(const[i,a]of Object.entries(s)){const o=G(t,i);if(!o)throw new Error(`[styleframe] Utility "${i}" not found in registry. Make sure the utility is registered before using it in a recipe.`);c[i]=Ae(o,a)}r[Ve(n)]=c}else if(typeof s=="boolean")r[n]=s;else{const c=G(t,n);if(!c)throw new Error(`[styleframe] Utility "${n}" not found in registry. Make sure the utility is registered before using it in a recipe.`);r[n]=Ae(c,s)}return r}function ve(e,t){const r={};if(e.base&&(r.base=L(e.base,t)),e.variants){const n={};for(const[s,c]of Object.entries(e.variants)){const i={};for(const[a,o]of Object.entries(c))o==null?i[a]=null:i[a]=L(o,t);n[s]=i}r.variants=n}return e.defaultVariants&&(r.defaultVariants={...e.defaultVariants}),e.compoundVariants&&(r.compoundVariants=e.compoundVariants.map(n=>({match:{...n.match},css:L(n.css,t)}))),r}function we(e){return!w(e)&&typeof e=="object"&&e!==null}function Ve(e){return e.startsWith("&::")?e.slice(3):e.startsWith("&:")?e.slice(2):e}function z(e,t){const r=(n,s,c)=>{let i=t.get(n);i||(i=[],t.set(n,i)),i.push({value:s,modifiers:c})};for(const[n,s]of Object.entries(e))if(we(s)){const c=Ve(n).split(":");for(const[i,a]of Object.entries(s))r(i,a,c)}else r(n,s,[])}function G(e,t){const r=e.utilities.find(s=>s.name===t);if(r)return r;const n=t.replace(/[A-Z]/g,s=>`-${s.toLowerCase()}`);return e.utilities.find(s=>s.name===n)}function Re(e,t){const r=new Map;if(e.base&&z(e.base,r),e.variants)for(const s of Object.values(e.variants))for(const c of Object.values(s))z(c,r);if(e.compoundVariants)for(const s of e.compoundVariants)s.css&&z(s.css,r);const n=new Map;for(const[s,c]of r){const i=G(t,s);if(!i)throw new Error(`[styleframe] Utility "${s}" not found in registry. Make sure the utility is registered before using it in a recipe.`);for(const a of c){const o=[];for(const f of a.modifiers){if(!n.has(f))try{n.set(f,ie(t,f))}catch{throw new Error(`[styleframe] Modifier "${f}" not found in registry. Make sure the modifier is registered before using it in a recipe.`)}const d=n.get(f);d&&o.push(d)}i.create([a.value],o.length>0?o.length>1?[o]:o:void 0)}}}function Ke(e){const t=v("sf-"),r=he(),n={...e},s=pe(r,r),c=me(r,r),i=be(r,r),a=ge(r,r),{variable:o,selector:f,atRule:d,keyframes:l,media:y,ref:m,css:h}=V(r,r);return{id:t,root:r,variable:o,selector:f,utility:s,modifier:c,recipe:i,theme:a,atRule:d,keyframes:l,media:y,ref:m,css:h,options:n}}u.applyModifiers=ye,u.capitalizeFirst=_e,u.classNameToCssSelector=Oe,u.createAtRuleFunction=O,u.createCssFunction=ne,u.createDeclarationsCallbackContext=V,u.createKeyframesFunction=ue,u.createMediaFunction=fe,u.createModifierFunction=me,u.createPropertyValueResolver=E,u.createRecipeFunction=be,u.createRefFunction=I,u.createRoot=he,u.createSelectorFunction=le,u.createThemeFunction=ge,u.createUtilityFunction=pe,u.createVariableFunction=de,u.deepClone=M,u.defaultUtilitySelectorFn=Ee,u.findVariableInScope=ee,u.generateRandomId=v,u.generateRecipeRuntime=ve,u.getModifier=ie,u.getUtility=Ne,u.getVariable=Ue,u.hashValue=x,u.isAtRule=Y,u.isCSS=T,u.isContainer=Te,u.isContainerInput=N,u.isKeyReferenceValue=Q,u.isModifier=Z,u.isObject=A,u.isPrimitiveTokenValue=J,u.isRecipe=$e,u.isRef=w,u.isRoot=k,u.isSelector=ke,u.isStyleframe=Se,u.isTheme=Fe,u.isToken=g,u.isTokenEqual=_,u.isTokenValue=S,u.isUtility=Me,u.isVariable=U,u.merge=Be,u.mergeContainers=W,u.mergeThemesArray=oe,u.mergeVariablesArray=ce,u.parseAtReferences=D,u.parseDeclarationsBlock=F,u.processRecipeUtilities=Re,u.rebuildRegistry=ae,u.rfdc=re,u.styleframe=Ke,u.transformUtilityKey=P,u.validateReference=te,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(u,A){typeof exports=="object"&&typeof module<"u"?A(exports):typeof define=="function"&&define.amd?define(["exports"],A):(u=typeof globalThis<"u"?globalThis:u||self,A(u.styleframe={}))})(this,(function(u){"use strict";function A(e){return typeof e=="object"&&e!==null}function g(e,t){return A(e)&&"type"in e&&e.type===t}function P(e){return g(e,"variable")}function v(e){return g(e,"reference")}function ke(e){return g(e,"selector")}function Y(e){return g(e,"at-rule")}function Me(e){return g(e,"utility")}function Z(e){return g(e,"modifier")}function T(e){return g(e,"css")}function Fe(e){return g(e,"theme")}function k(e){return g(e,"root")}function $e(e){return g(e,"recipe")}function J(e){return typeof e=="string"||typeof e=="number"||typeof e=="boolean"||e===null}function _(e){return J(e)||v(e)||T(e)||Array.isArray(e)&&e.every(_)}function Se(e){return A(e)&&"id"in e&&"children"in e&&"declarations"in e&&"variables"in e}function B(e){return A(e)&&"children"in e&&"declarations"in e&&"variables"in e}function Q(e){return typeof e=="string"&&e.startsWith("@")}function Te(e){return A(e)&&"id"in e&&"root"in e&&"variable"in e&&"selector"in e&&"recipe"in e&&typeof e.id=="string"&&k(e.root)}function x(e){let t=5381;for(let r=0;r<e.length;r++)t=(t<<5)+t+e.charCodeAt(r)&4294967295;return(t>>>0).toString(16).padStart(7,"0").slice(0,7)}function D(e){const t=typeof e=="function"?{replacer:e}:e??{},{replacer:r=c=>c,namespace:n}=t,s=Array.isArray(n)?n:n?[n]:[];return c=>{let i=c,a;if(typeof i=="string"&&i[0]==="@"){const o=i.slice(1),f=s.find(y=>o===y||o.startsWith(`${y}.`));let d,l;f?(d=o,l=o.startsWith(`${f}.`)?o.slice(f.length+1):o):s.length>0?(d=`${s[0]}.${o}`,l=o):(d=o,l=o),a=r(l),i={type:"reference",name:d}}else if(v(i)){let o=i.name;for(const f of s)if(o.startsWith(`${f}.`)){o=o.slice(f.length+1);break}a=r(o)}else{const o=String(c).trim();/\s/.test(o)?a=x(o):a=`[${o}]`}return{[a]:i}}}const _e=({name:e,value:t,modifiers:r})=>`_${[...r,e,...t==="default"?[]:[t]].filter(Boolean).join(":")}`,I=/@([\w.-]+)/g;function E(e){const t=[];let r=0,n;for(I.lastIndex=0;(n=I.exec(e))!==null;){const c=e.slice(r,n.index);c!==""&&t.push(c),t.push({type:"reference",name:n[1]}),r=I.lastIndex}const s=e.slice(r);return s!==""&&t.push(s),t}function ee(e,t,r){let n=t;for(;n;){if(n.variables.some(s=>s.name===e))return!0;if(n.parentId)n=r._registry.get(n.parentId);else break}return!1}function te(e,t,r){if(!ee(e,t,r))throw new Error(`[styleframe] Variable "${e}" is not defined. Check that the variable exists before referencing it with "@${e}".`)}function N(e,t){return function(n){if(typeof n!="string"||!n.includes("@"))return n;if(Q(n)&&/^@[\w.-]+$/.test(n)){const i=n.slice(1);return te(i,e,t),t._usage.variables.add(i),{type:"reference",name:i}}const s=E(n);if(s.some(i=>v(i))){for(const i of s)v(i)&&t._usage.variables.add(i.name);return{type:"css",value:s}}return n}}function K(e,t){return function(n,s){const c=N(e,t),i=s!=null?c(s):s;if(P(n))return t._usage.variables.add(n.name),{type:"reference",name:n.name,fallback:i};if(n==null)throw new Error(`[styleframe] ref() received ${String(n)}. This usually means you're referencing a variable that doesn't exist.`);return t._usage.variables.add(n),{type:"reference",name:n,fallback:i}}}function ne(e,t){const r=K(e,t);return function(s,...c){return{type:"css",value:s.reduce((a,o,f)=>{if(a.push(...E(o)),f<c.length){const d=c[f];P(d)?a.push(r(d)):Y(d)?a.push(d.rule):typeof d=="string"&&d.includes("@")?a.push(...E(d)):a.push(d)}return a},[])}}}function Ee(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Ne(e){return`.${e.replace(/[[\].#()%,:/]/g,"\\$&")}`}function R(e){if(e instanceof Buffer)return Buffer.from(e);const t=e.constructor;return new t(e.buffer.slice(0),e.byteOffset,e.byteLength/e.BYTES_PER_ELEMENT||1)}function re(e){if(e=e||{},e.circular)return Oe(e);const t=new Map;if(t.set(Date,i=>new Date(i)),t.set(Map,(i,a)=>new Map(n(Array.from(i),a))),t.set(Set,(i,a)=>new Set(n(Array.from(i),a))),e.constructorHandlers)for(const i of e.constructorHandlers)t.set(i[0],i[1]);let r;return e.proto?c:s;function n(i,a){const o=Object.keys(i),f=Array.from({length:o.length});for(let d=0;d<o.length;d++){const l=o[d],y=i[l];typeof y!="object"||y===null?f[l]=y:y.constructor!==Object&&(r=t.get(y.constructor))?f[l]=r(y,a):ArrayBuffer.isView(y)?f[l]=R(y):f[l]=a(y)}return f}function s(i){if(typeof i!="object"||i===null)return i;if(Array.isArray(i))return n(i,s);if(i.constructor!==Object&&(r=t.get(i.constructor)))return r(i,s);const a={};for(const o in i){if(Object.hasOwnProperty.call(i,o)===!1)continue;const f=i[o];typeof f!="object"||f===null?a[o]=f:f.constructor!==Object&&(r=t.get(f.constructor))?a[o]=r(f,s):ArrayBuffer.isView(f)?a[o]=R(f):a[o]=s(f)}return a}function c(i){if(typeof i!="object"||i===null)return i;if(Array.isArray(i))return n(i,c);if(i.constructor!==Object&&(r=t.get(i.constructor)))return r(i,c);const a={};for(const o in i){const f=i[o];typeof f!="object"||f===null?a[o]=f:f.constructor!==Object&&(r=t.get(f.constructor))?a[o]=r(f,c):ArrayBuffer.isView(f)?a[o]=R(f):a[o]=c(f)}return a}}function Oe(e){const t=[],r=[],n=new Map;if(n.set(Date,o=>new Date(o)),n.set(Map,(o,f)=>new Map(c(Array.from(o),f))),n.set(Set,(o,f)=>new Set(c(Array.from(o),f))),e.constructorHandlers)for(const o of e.constructorHandlers)n.set(o[0],o[1]);let s;return e.proto?a:i;function c(o,f){const d=Object.keys(o),l=Array.from({length:d.length});for(let y=0;y<d.length;y++){const m=d[y],h=o[m];if(typeof h!="object"||h===null)l[m]=h;else if(h.constructor!==Object&&(s=n.get(h.constructor)))l[m]=s(h,f);else if(ArrayBuffer.isView(h))l[m]=R(h);else{const b=t.indexOf(h);b!==-1?l[m]=r[b]:l[m]=f(h)}}return l}function i(o){if(typeof o!="object"||o===null)return o;if(Array.isArray(o))return c(o,i);if(o.constructor!==Object&&(s=n.get(o.constructor)))return s(o,i);const f={};t.push(o),r.push(f);for(const d in o){if(Object.hasOwnProperty.call(o,d)===!1)continue;const l=o[d];if(typeof l!="object"||l===null)f[d]=l;else if(l.constructor!==Object&&(s=n.get(l.constructor)))f[d]=s(l,i);else if(ArrayBuffer.isView(l))f[d]=R(l);else{const y=t.indexOf(l);y!==-1?f[d]=r[y]:f[d]=i(l)}}return t.pop(),r.pop(),f}function a(o){if(typeof o!="object"||o===null)return o;if(Array.isArray(o))return c(o,a);if(o.constructor!==Object&&(s=n.get(o.constructor)))return s(o,a);const f={};t.push(o),r.push(f);for(const d in o){const l=o[d];if(typeof l!="object"||l===null)f[d]=l;else if(l.constructor!==Object&&(s=n.get(l.constructor)))f[d]=s(l,a);else if(ArrayBuffer.isView(l))f[d]=R(l);else{const y=t.indexOf(l);y!==-1?f[d]=r[y]:f[d]=a(l)}}return t.pop(),r.pop(),f}}const M=re();function w(e,t=8){const r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let n="";for(let s=0;s<t;s++){const c=Math.floor(Math.random()*r.length);n+=r[c]}return e?`${e}${n}`:n}function Ce(e,t){const r=e.variables.find(n=>n.name===t);if(!r)throw new Error(`Variable "${t}" not found`);return r}function Ue(e,t){const r=e.utilities.find(n=>n.name===t);if(!r)throw new Error(`Utility "${t}" not found`);return r}function ie(e,t){const r=e.modifiers.find(n=>n.key.includes(t));if(!r)throw new Error(`Modifier "${t}" not found`);return r}function O(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(e===null||t===null)return e===t;if(typeof e!="object"||typeof t!="object")return!1;if(Array.isArray(e)&&Array.isArray(t))return e.length!==t.length?!1:e.every((r,n)=>O(r,t[n]));if("type"in e&&"type"in t){if(e.type!==t.type)return!1;if(v(e)&&v(t))return e.name===t.name&&O(e.fallback,t.fallback);if(T(e)&&T(t))return O(e.value,t.value)}return!1}const se="__licenseRequired";function Pe(e){W(e)||Object.defineProperty(e,se,{value:!0,writable:!1,configurable:!1,enumerable:!0})}function W(e){return Object.prototype.hasOwnProperty.call(e,se)}function ce(e,t){const r=[...e];for(const n of t){const s=r.find(c=>c.name===n.name);s?s.value=n.value:r.push(n)}return r}function oe(e,t){const r=[...e];for(const n of t){const s=r.find(c=>c.name===n.name);s?Object.assign(s,H(s,n)):r.push(n)}return r}function H(e,t){return Object.keys(e).reduce((r,n)=>(n==="variables"?r.variables=ce(e.variables,t.variables):n==="declarations"?r.declarations={...e.declarations,...t.declarations}:n==="themes"&&k(r)&&k(e)&&k(t)?r.themes=oe(e.themes,t.themes):Array.isArray(e[n])&&(r[n]=e[n].concat(t[n])),r),{...e,...t})}function L(e,t){for(const r of e)"id"in r&&typeof r.id=="string"&&(t._registry.set(r.id,r),"children"in r&&L(r.children,t))}function ae(e){e._registry=new Map,e._registry.set(e.id,e),L(e.children,e);for(const t of e.themes)e._registry.set(t.id,t),L(t.children,e)}function Be(e,...t){return t.reduce((r,n)=>{const s={...r,root:H(r.root,n.root)};return ae(s.root),(W(r)||W(n))&&Pe(s),s},e)}function C(e,t){return function(n,s,c){const i={type:"at-rule",id:w("ar-"),parentId:e.id,identifier:n,rule:s,declarations:{},variables:[],children:[]};t._registry.set(i.id,i);const a=V(i,t);return typeof c=="function"?i.declarations=c(a)??{}:B(c)?(i.variables=c.variables,i.declarations=c.declarations,i.children=c.children):c&&(i.declarations=c),F(i.declarations,a,i,t),e.children.push(i),i}}function fe(e,t){const r=C(e,t);return function(s,c){return r("media",s,c)}}function ue(e,t){const r=C(e,t);return function(s,c){return r("keyframes",s,c)}}function le(e,t){return function(n,s){const c={type:"selector",id:w("sel-"),parentId:e.id,query:n,declarations:{},variables:[],children:[]};t._registry.set(c.id,c);const i=V(c,t);return typeof s=="function"?c.declarations=s(i)??{}:B(s)?(c.variables=s.variables,c.declarations=s.declarations,c.children=s.children):c.declarations=s,F(c.declarations,i,c,t),e.children.push(c),c}}function de(e,t){return function(n,s,c={default:!1}){const i=typeof n=="string"?n:n.name,o=N(e,t)(s),f=e.variables.find(l=>l.name===i);if(c.default&&f)return f;if(f)return f.value=o,f;const d={type:"variable",id:w("var-"),parentId:e.id,name:i,value:o};return e.variables.push(d),d}}function V(e,t){const r=de(e,t),n=le(e,t),s=C(e,t),c=ue(t,t),i=fe(e,t),a=K(t,t),o=ne(t,t);return{variable:r,selector:n,keyframes:c,atRule:s,media:i,ref:a,css:o}}function F(e,t,r,n){for(const c in e)if(c.startsWith("@")){const i=e[c];if(typeof i=="object"&&i!==null&&!_(i)){const a=c.replace(/^@(\w+).*/,"$1"),o=c.replace(`@${a}`,"").trim();t.atRule(a,o,i),delete e[c]}}else if(/^[.&:]/.test(c)||/^(\d+%|from|to)(\s*,\s*(\d+%|from|to))*$/.test(c)){const i=e[c];typeof i=="object"&&(t.selector(c,i),delete e[c])}const s=N(r,n);for(const c in e){const i=e[c];if(_(i)){const a=s(i);a!==i&&(e[c]=a)}}return e}function ye(e,t,r){const n={...e,id:w("ut-"),parentId:e.parentId,declarations:{...e.declarations},variables:[...e.variables],children:[...e.children],modifiers:[...r.keys()]};if(t._registry.set(n.id,n),r.size>0){const s=[...r.values()];let c=M(e.declarations);n.declarations={},n.variables=[],n.children=[];for(let a=s.length-1;a>=0;a--){const o=V(n,t),f=s[a]?.factory({...o,declarations:M(c),variables:M(e.variables),children:M(e.children)});f&&(c=f)}n.declarations=c;const i=V(n,t);F(n.declarations,i,n,t)}return n}function me(e,t){return function(n,s){const c={type:"modifier",key:Array.isArray(n)?n:[n],factory:s};return t.modifiers.push(c),c}}function he(){const e={type:"root",id:w("rt-"),declarations:{},utilities:[],modifiers:[],recipes:[],variables:[],children:[],themes:[],_registry:new Map,_usage:{variables:new Set}};return e._registry.set(e.id,e),e}function De(e,t){const r=D({namespace:e});return n=>{if(typeof n=="string"&&n[0]==="@"){const s=n.slice(1),c=e.find(i=>s===i||s.startsWith(`${i}.`));if(c){const i=s.slice(c.length+1)||s;if(t.variables.some(a=>a.name===s))return{[i]:{type:"reference",name:s}}}else{for(const i of e){const a=`${i}.${s}`;if(t.variables.some(o=>o.name===a))return{[s]:{type:"reference",name:a}}}if(t.variables.some(i=>i.name===s))return{[s]:{type:"reference",name:s}}}return r(n)}return r(n)}}function Ie(e){let t=[new Map];for(const r of e){if(!Z(r))continue;const n=[];for(const s of r.key)for(const c of t){const i=new Map(c);i.set(s,r),n.push(i)}t=n}return t.filter(r=>r.size>0)}function pe(e,t){return function(n,s,c={}){const i=t.utilities.find(o=>o.name===n);if(i)return i.create;const a={type:"utility",name:n,factory:s,values:[],autogenerate:c.autogenerate??(Array.isArray(c.namespace)?De(c.namespace,t):D(c.namespace?{namespace:c.namespace}:void 0)),namespace:c.namespace,create:(o,f=[])=>{let d=o;if(Array.isArray(o)){d={};for(const l of o){const y=a.autogenerate(l);d={...d,...y}}}for(const[l,y]of Object.entries(d)){let m=y;if(typeof y=="string"&&y[0]==="@"){const p=y.slice(1);!Array.isArray(d)&&p in d&&(m=d[p])}if(a.namespace&&v(y))if(t.variables.some(p=>p.name===y.name))m=y;else{const p=Array.isArray(a.namespace)?a.namespace:[a.namespace];let U=!1;for(const $ of p){const j=`${$}.${l}`;if(j!==y.name&&t.variables.some(S=>S.name===j)){m={type:"reference",name:j},U=!0;break}}U||(t.variables.some($=>$.name===l)?m={type:"reference",name:l}:m=l)}const h=a.values.find(p=>p.key===l&&p.modifiers.length===0),b={type:"utility",id:w("ut-"),parentId:e.id,name:n,value:l,declarations:{},variables:[],children:[],modifiers:[]};t._registry.set(b.id,b);const je=V(b,t);if(b.declarations=s({...je,value:m})??{},F(b.declarations,je,b,t),h||(a.values.push({key:l,value:m,modifiers:[]}),e.children.push(b)),f&&f.length>0)for(const p of f){const U=Array.isArray(p)?p:[p],$=Ie(U);for(const j of $){const S=[...j.keys()];a.values.find(X=>X.key===l&&X.modifiers.length===S.length&&X.modifiers.every((We,He)=>We===S[He]))||(a.values.push({key:l,value:m,modifiers:S}),e.children.push(ye(b,t,j)))}}}}};return t.utilities.push(a),a.create}}function ge(e,t){return function(n,s){const c=t.themes.find(o=>o.name===n),i=c??{type:"theme",id:w("th-"),parentId:t.id,name:n,declarations:{},variables:[],children:[]};c||(t._registry.set(i.id,i),t.themes.push(i));const a=V(i,t);return s&&s(a),i}}function be(e,t){return function(n){const s={type:"recipe",...n};return s._runtime=ve(s,t),Re(s,t),t.recipes.push(s),s}}function Ae(e,t){const r=e.autogenerate(t);return Object.keys(r)[0]??"default"}function z(e,t){const r={};for(const[n,s]of Object.entries(e))if(we(s)){const c={};for(const[i,a]of Object.entries(s)){const o=q(t,i);if(!o)throw new Error(`[styleframe] Utility "${i}" not found in registry. Make sure the utility is registered before using it in a recipe.`);c[i]=Ae(o,a)}r[Ve(n)]=c}else if(typeof s=="boolean")r[n]=s;else{const c=q(t,n);if(!c)throw new Error(`[styleframe] Utility "${n}" not found in registry. Make sure the utility is registered before using it in a recipe.`);r[n]=Ae(c,s)}return r}function ve(e,t){const r={};if(e.base&&(r.base=z(e.base,t)),e.variants){const n={};for(const[s,c]of Object.entries(e.variants)){const i={};for(const[a,o]of Object.entries(c))o==null?i[a]=null:i[a]=z(o,t);n[s]=i}r.variants=n}return e.defaultVariants&&(r.defaultVariants={...e.defaultVariants}),e.compoundVariants&&(r.compoundVariants=e.compoundVariants.map(n=>({match:{...n.match},...n.css?{css:z(n.css,t)}:{},...n.className?{className:n.className}:{}}))),r}function we(e){return!v(e)&&typeof e=="object"&&e!==null}function Ve(e){return e.startsWith("&::")?e.slice(3):e.startsWith("&:")?e.slice(2):e}function G(e,t){const r=(n,s,c)=>{let i=t.get(n);i||(i=[],t.set(n,i)),i.push({value:s,modifiers:c})};for(const[n,s]of Object.entries(e))if(we(s)){const c=Ve(n).split(":");for(const[i,a]of Object.entries(s))r(i,a,c)}else r(n,s,[])}function q(e,t){const r=e.utilities.find(s=>s.name===t);if(r)return r;const n=t.replace(/[A-Z]/g,s=>`-${s.toLowerCase()}`);return e.utilities.find(s=>s.name===n)}function Re(e,t){const r=new Map;if(e.base&&G(e.base,r),e.variants)for(const s of Object.values(e.variants))for(const c of Object.values(s))G(c,r);if(e.compoundVariants)for(const s of e.compoundVariants)s.css&&G(s.css,r);const n=new Map;for(const[s,c]of r){const i=q(t,s);if(!i)throw new Error(`[styleframe] Utility "${s}" not found in registry. Make sure the utility is registered before using it in a recipe.`);for(const a of c){const o=[];for(const f of a.modifiers){if(!n.has(f))try{n.set(f,ie(t,f))}catch{throw new Error(`[styleframe] Modifier "${f}" not found in registry. Make sure the modifier is registered before using it in a recipe.`)}const d=n.get(f);d&&o.push(d)}i.create([a.value],o.length>0?o.length>1?[o]:o:void 0)}}}function Ke(e){const t=w("sf-"),r=he(),n={...e},s=pe(r,r),c=me(r,r),i=be(r,r),a=ge(r,r),{variable:o,selector:f,atRule:d,keyframes:l,media:y,ref:m,css:h}=V(r,r);return{id:t,root:r,variable:o,selector:f,utility:s,modifier:c,recipe:i,theme:a,atRule:d,keyframes:l,media:y,ref:m,css:h,options:n}}u.applyModifiers=ye,u.capitalizeFirst=Ee,u.classNameToCssSelector=Ne,u.createAtRuleFunction=C,u.createCssFunction=ne,u.createDeclarationsCallbackContext=V,u.createKeyframesFunction=ue,u.createMediaFunction=fe,u.createModifierFunction=me,u.createPropertyValueResolver=N,u.createRecipeFunction=be,u.createRefFunction=K,u.createRoot=he,u.createSelectorFunction=le,u.createThemeFunction=ge,u.createUtilityFunction=pe,u.createVariableFunction=de,u.deepClone=M,u.defaultUtilitySelectorFn=_e,u.findVariableInScope=ee,u.generateRandomId=w,u.generateRecipeRuntime=ve,u.getModifier=ie,u.getUtility=Ue,u.getVariable=Ce,u.hashValue=x,u.isAtRule=Y,u.isCSS=T,u.isContainer=Se,u.isContainerInput=B,u.isKeyReferenceValue=Q,u.isModifier=Z,u.isObject=A,u.isPrimitiveTokenValue=J,u.isRecipe=$e,u.isRef=v,u.isRoot=k,u.isSelector=ke,u.isStyleframe=Te,u.isTheme=Fe,u.isToken=g,u.isTokenEqual=O,u.isTokenValue=_,u.isUtility=Me,u.isVariable=P,u.merge=Be,u.mergeContainers=H,u.mergeThemesArray=oe,u.mergeVariablesArray=ce,u.parseAtReferences=E,u.parseDeclarationsBlock=F,u.processRecipeUtilities=Re,u.rebuildRegistry=ae,u.rfdc=re,u.styleframe=Ke,u.transformUtilityKey=D,u.validateReference=te,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@styleframe/core",
3
- "version": "3.2.0",
3
+ "version": "3.4.0",
4
4
  "type": "module",
5
5
  "types": "./dist/styleframe.d.ts",
6
6
  "module": "./dist/styleframe.js",