@styleframe/core 3.3.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,13 @@
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
+
3
11
  ## 3.3.0
4
12
 
5
13
  ### Minor Changes
@@ -487,6 +487,9 @@ export declare type Root = {
487
487
  children: ContainerChild[];
488
488
  themes: Theme[];
489
489
  _registry: Map<string, Container | Root | Theme>;
490
+ _usage: {
491
+ variables: Set<string>;
492
+ };
490
493
  };
491
494
 
492
495
  export declare type RuntimeModifierDeclarationsBlock = Record<string, PrimitiveTokenValue>;
@@ -4,13 +4,13 @@ function x(e) {
4
4
  function g(e, t) {
5
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) {
@@ -25,25 +25,25 @@ function ne(e) {
25
25
  function T(e) {
26
26
  return g(e, "css");
27
27
  }
28
- function Oe(e) {
28
+ function Se(e) {
29
29
  return g(e, "theme");
30
30
  }
31
31
  function $(e) {
32
32
  return g(e, "root");
33
33
  }
34
- function Se(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) || T(e) || Array.isArray(e) && e.every(B);
41
+ return re(e) || b(e) || T(e) || Array.isArray(e) && e.every(B);
42
42
  }
43
43
  function Te(e) {
44
44
  return x(e) && "id" in e && "children" in e && "declarations" in e && "variables" in e;
45
45
  }
46
- function L(e) {
46
+ function G(e) {
47
47
  return x(e) && "children" in e && "declarations" in e && "variables" in e;
48
48
  }
49
49
  function ie(e) {
@@ -58,20 +58,20 @@ 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;
65
65
  if (typeof i == "string" && i[0] === "@") {
66
66
  const c = i.slice(1), a = s.find(
67
- (y) => c === y || c.startsWith(`${y}.`)
67
+ (d) => c === d || c.startsWith(`${d}.`)
68
68
  );
69
69
  let l, u;
70
70
  a ? (l = c, u = c.startsWith(`${a}.`) ? c.slice(a.length + 1) : c) : s.length > 0 ? (l = `${s[0]}.${c}`, u = c) : (l = c, u = c), f = r(u), i = {
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 };
135
+ }
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 };
132
141
  }
133
- const s = z(n);
134
- return s.some((i) => A(i)) ? { type: "css", value: s } : n;
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
  }, [])
@@ -203,8 +211,8 @@ function ae(e) {
203
211
  function n(i, f) {
204
212
  const c = Object.keys(i), a = Array.from({ length: c.length });
205
213
  for (let l = 0; l < c.length; l++) {
206
- const u = c[l], y = i[u];
207
- typeof y != "object" || y === null ? a[u] = y : y.constructor !== Object && (r = t.get(y.constructor)) ? a[u] = r(y, f) : ArrayBuffer.isView(y) ? a[u] = j(y) : a[u] = f(y);
214
+ const u = c[l], d = i[u];
215
+ typeof d != "object" || d === null ? a[u] = d : d.constructor !== Object && (r = t.get(d.constructor)) ? a[u] = r(d, f) : ArrayBuffer.isView(d) ? a[u] = j(d) : a[u] = f(d);
208
216
  }
209
217
  return a;
210
218
  }
@@ -249,17 +257,17 @@ function ue(e) {
249
257
  return e.proto ? f : i;
250
258
  function o(c, a) {
251
259
  const l = Object.keys(c), u = Array.from({ length: l.length });
252
- for (let y = 0; y < l.length; y++) {
253
- const d = l[y], m = c[d];
254
- if (typeof m != "object" || m === null)
255
- u[d] = m;
256
- else if (m.constructor !== Object && (s = n.get(m.constructor)))
257
- u[d] = s(m, a);
258
- else if (ArrayBuffer.isView(m))
259
- u[d] = j(m);
260
+ for (let d = 0; d < l.length; d++) {
261
+ const y = l[d], p = c[y];
262
+ if (typeof p != "object" || p === null)
263
+ u[y] = p;
264
+ else if (p.constructor !== Object && (s = n.get(p.constructor)))
265
+ u[y] = s(p, a);
266
+ else if (ArrayBuffer.isView(p))
267
+ u[y] = j(p);
260
268
  else {
261
- const h = t.indexOf(m);
262
- h !== -1 ? u[d] = r[h] : u[d] = a(m);
269
+ const h = t.indexOf(p);
270
+ h !== -1 ? u[y] = r[h] : u[y] = a(p);
263
271
  }
264
272
  }
265
273
  return u;
@@ -281,8 +289,8 @@ function ue(e) {
281
289
  else if (ArrayBuffer.isView(u))
282
290
  a[l] = j(u);
283
291
  else {
284
- const y = t.indexOf(u);
285
- y !== -1 ? a[l] = r[y] : a[l] = i(u);
292
+ const d = t.indexOf(u);
293
+ d !== -1 ? a[l] = r[d] : a[l] = i(u);
286
294
  }
287
295
  }
288
296
  return t.pop(), r.pop(), a;
@@ -303,15 +311,15 @@ function ue(e) {
303
311
  else if (ArrayBuffer.isView(u))
304
312
  a[l] = j(u);
305
313
  else {
306
- const y = t.indexOf(u);
307
- y !== -1 ? a[l] = r[y] : a[l] = f(u);
314
+ const d = t.indexOf(u);
315
+ d !== -1 ? a[l] = r[d] : a[l] = f(u);
308
316
  }
309
317
  }
310
318
  return t.pop(), r.pop(), a;
311
319
  }
312
320
  }
313
321
  const M = ae();
314
- function b(e, t = 8) {
322
+ function A(e, t = 8) {
315
323
  const r = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
316
324
  let n = "";
317
325
  for (let s = 0; s < t; s++) {
@@ -349,7 +357,7 @@ function N(e, t) {
349
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))
360
+ if (b(e) && b(t))
353
361
  return e.name === t.name && N(e.fallback, t.fallback);
354
362
  if (T(e) && T(t))
355
363
  return N(e.value, t.value);
@@ -357,18 +365,18 @@ function N(e, t) {
357
365
  return !1;
358
366
  }
359
367
  const X = "__licenseRequired";
360
- function ye(e) {
361
- P(e) || Object.defineProperty(e, X, {
368
+ function de(e) {
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
- function de(e, t) {
379
+ function ye(e, t) {
372
380
  const r = [...e];
373
381
  for (const n of t) {
374
382
  const s = r.find(
@@ -378,7 +386,7 @@ function de(e, t) {
378
386
  }
379
387
  return r;
380
388
  }
381
- function me(e, t) {
389
+ function pe(e, t) {
382
390
  const r = [...e];
383
391
  for (const n of t) {
384
392
  const s = r.find(
@@ -393,7 +401,7 @@ function me(e, t) {
393
401
  }
394
402
  function Y(e, t) {
395
403
  return Object.keys(e).reduce(
396
- (r, n) => (n === "variables" ? r.variables = de(e.variables, t.variables) : n === "declarations" ? r.declarations = { ...e.declarations, ...t.declarations } : n === "themes" && $(r) && $(e) && $(t) ? r.themes = me(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
- function pe(e) {
410
- e._registry = /* @__PURE__ */ new Map(), e._registry.set(e.id, e), U(e.children, e);
417
+ function me(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 pe(s.root), (P(r) || P(n)) && ye(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,
@@ -434,7 +442,7 @@ function I(e, t) {
434
442
  };
435
443
  t._registry.set(i.id, i);
436
444
  const f = v(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), E(
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: {},
@@ -467,7 +475,7 @@ function be(e, t) {
467
475
  };
468
476
  t._registry.set(o.id, o);
469
477
  const i = v(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, E(
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
@@ -497,7 +505,7 @@ function Ae(e, t) {
497
505
  };
498
506
  }
499
507
  function v(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);
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 v(e, t) {
508
516
  css: c
509
517
  };
510
518
  }
511
- function E(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];
@@ -520,7 +528,7 @@ function E(e, t, r, n) {
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)) {
@@ -533,7 +541,7 @@ function E(e, t, r, n) {
533
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],
@@ -555,7 +563,7 @@ function ve(e, t, r) {
555
563
  }
556
564
  n.declarations = o;
557
565
  const i = v(n, t);
558
- E(
566
+ _(
559
567
  n.declarations,
560
568
  i,
561
569
  n,
@@ -577,7 +585,7 @@ function we(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(
@@ -653,7 +664,7 @@ function ke(e, t) {
653
664
  name: n,
654
665
  factory: s,
655
666
  values: [],
656
- 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(
657
668
  o.namespace ? { namespace: o.namespace } : void 0
658
669
  )),
659
670
  namespace: o.namespace,
@@ -662,45 +673,45 @@ function ke(e, t) {
662
673
  if (Array.isArray(c)) {
663
674
  l = {};
664
675
  for (const u of c) {
665
- const y = f.autogenerate(u);
676
+ const d = f.autogenerate(u);
666
677
  l = {
667
678
  ...l,
668
- ...y
679
+ ...d
669
680
  };
670
681
  }
671
682
  }
672
- for (const [u, y] of Object.entries(l)) {
673
- let d = y;
674
- if (typeof y == "string" && y[0] === "@") {
675
- const p = y.slice(1);
676
- !Array.isArray(l) && p in l && (d = l[p]);
683
+ for (const [u, d] of Object.entries(l)) {
684
+ let y = d;
685
+ if (typeof d == "string" && d[0] === "@") {
686
+ const m = d.slice(1);
687
+ !Array.isArray(l) && m in l && (y = l[m]);
677
688
  }
678
- if (f.namespace && A(y))
679
- if (t.variables.some((p) => p.name === y.name))
680
- d = y;
689
+ if (f.namespace && b(d))
690
+ if (t.variables.some((m) => m.name === d.name))
691
+ y = d;
681
692
  else {
682
- const p = Array.isArray(f.namespace) ? f.namespace : [f.namespace];
693
+ const m = Array.isArray(f.namespace) ? f.namespace : [f.namespace];
683
694
  let k = !1;
684
- for (const V of p) {
695
+ for (const V of m) {
685
696
  const w = `${V}.${u}`;
686
- if (w !== y.name && t.variables.some((R) => R.name === w)) {
687
- d = {
697
+ if (w !== d.name && t.variables.some((R) => R.name === w)) {
698
+ y = {
688
699
  type: "reference",
689
700
  name: w
690
701
  }, k = !0;
691
702
  break;
692
703
  }
693
704
  }
694
- k || (t.variables.some((V) => V.name === u) ? d = {
705
+ k || (t.variables.some((V) => V.name === u) ? y = {
695
706
  type: "reference",
696
707
  name: u
697
- } : d = u);
708
+ } : y = u);
698
709
  }
699
- const m = f.values.find(
700
- (p) => p.key === u && p.modifiers.length === 0
710
+ const p = f.values.find(
711
+ (m) => m.key === u && m.modifiers.length === 0
701
712
  ), h = {
702
713
  type: "utility",
703
- id: b("ut-"),
714
+ id: A("ut-"),
704
715
  parentId: e.id,
705
716
  name: n,
706
717
  value: u,
@@ -710,34 +721,34 @@ function ke(e, t) {
710
721
  modifiers: []
711
722
  };
712
723
  t._registry.set(h.id, h);
713
- const K = v(
724
+ const W = v(
714
725
  h,
715
726
  t
716
727
  );
717
728
  if (h.declarations = s({
718
- ...K,
719
- value: d
720
- }) ?? {}, E(
729
+ ...W,
730
+ value: y
731
+ }) ?? {}, _(
721
732
  h.declarations,
722
- K,
733
+ W,
723
734
  h,
724
735
  t
725
- ), m || (f.values.push({
736
+ ), p || (f.values.push({
726
737
  key: u,
727
- value: d,
738
+ value: y,
728
739
  modifiers: []
729
740
  }), e.children.push(h)), a && a.length > 0)
730
- for (const p of a) {
731
- const k = Array.isArray(p) ? p : [p], V = Re(k);
741
+ for (const m of a) {
742
+ const k = Array.isArray(m) ? m : [m], V = Re(k);
732
743
  for (const w of V) {
733
744
  const R = [...w.keys()];
734
745
  f.values.find(
735
- (F) => F.key === u && F.modifiers.length === R.length && F.modifiers.every(
746
+ (E) => E.key === u && E.modifiers.length === R.length && E.modifiers.every(
736
747
  (Q, ee) => Q === R[ee]
737
748
  )
738
749
  ) || (f.values.push({
739
750
  key: u,
740
- value: d,
751
+ value: y,
741
752
  modifiers: R
742
753
  }), e.children.push(
743
754
  ve(h, t, w)
@@ -754,7 +765,7 @@ function Me(e, t) {
754
765
  return function(n, s) {
755
766
  const o = t.themes.find((c) => c.name === n), i = o ?? {
756
767
  type: "theme",
757
- id: b("th-"),
768
+ id: A("th-"),
758
769
  parentId: t.id,
759
770
  name: n,
760
771
  declarations: {},
@@ -772,25 +783,25 @@ function $e(e, t) {
772
783
  type: "recipe",
773
784
  ...n
774
785
  };
775
- 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;
776
787
  };
777
788
  }
778
- function W(e, t) {
789
+ function H(e, t) {
779
790
  const r = e.autogenerate(t);
780
791
  return Object.keys(r)[0] ?? "default";
781
792
  }
782
- function O(e, t) {
793
+ function S(e, t) {
783
794
  const r = {};
784
795
  for (const [n, s] of Object.entries(e))
785
796
  if (Z(s)) {
786
797
  const o = {};
787
798
  for (const [i, f] of Object.entries(s)) {
788
- const c = D(t, i);
799
+ const c = C(t, i);
789
800
  if (!c)
790
801
  throw new Error(
791
802
  `[styleframe] Utility "${i}" not found in registry. Make sure the utility is registered before using it in a recipe.`
792
803
  );
793
- o[i] = W(
804
+ o[i] = H(
794
805
  c,
795
806
  f
796
807
  );
@@ -799,25 +810,25 @@ function O(e, t) {
799
810
  } else if (typeof s == "boolean")
800
811
  r[n] = s;
801
812
  else {
802
- const o = D(t, n);
813
+ const o = C(t, n);
803
814
  if (!o)
804
815
  throw new Error(
805
816
  `[styleframe] Utility "${n}" not found in registry. Make sure the utility is registered before using it in a recipe.`
806
817
  );
807
- r[n] = W(o, s);
818
+ r[n] = H(o, s);
808
819
  }
809
820
  return r;
810
821
  }
811
822
  function xe(e, t) {
812
823
  const r = {};
813
- if (e.base && (r.base = O(e.base, t)), e.variants) {
824
+ if (e.base && (r.base = S(e.base, t)), e.variants) {
814
825
  const n = {};
815
826
  for (const [s, o] of Object.entries(e.variants)) {
816
827
  const i = {};
817
828
  for (const [f, c] of Object.entries(
818
829
  o
819
830
  ))
820
- c == null ? i[f] = null : i[f] = O(
831
+ c == null ? i[f] = null : i[f] = S(
821
832
  c,
822
833
  t
823
834
  );
@@ -827,17 +838,17 @@ function xe(e, t) {
827
838
  }
828
839
  return e.defaultVariants && (r.defaultVariants = { ...e.defaultVariants }), e.compoundVariants && (r.compoundVariants = e.compoundVariants.map((n) => ({
829
840
  match: { ...n.match },
830
- ...n.css ? { css: O(n.css, t) } : {},
841
+ ...n.css ? { css: S(n.css, t) } : {},
831
842
  ...n.className ? { className: n.className } : {}
832
843
  }))), r;
833
844
  }
834
845
  function Z(e) {
835
- return !A(e) && typeof e == "object" && e !== null;
846
+ return !b(e) && typeof e == "object" && e !== null;
836
847
  }
837
848
  function J(e) {
838
849
  return e.startsWith("&::") ? e.slice(3) : e.startsWith("&:") ? e.slice(2) : e;
839
850
  }
840
- function S(e, t) {
851
+ function O(e, t) {
841
852
  const r = (n, s, o) => {
842
853
  let i = t.get(n);
843
854
  i || (i = [], t.set(n, i)), i.push({ value: s, modifiers: o });
@@ -850,28 +861,28 @@ function S(e, t) {
850
861
  } else
851
862
  r(n, s, []);
852
863
  }
853
- function D(e, t) {
864
+ function C(e, t) {
854
865
  const r = e.utilities.find((s) => s.name === t);
855
866
  if (r)
856
867
  return r;
857
868
  const n = t.replace(/[A-Z]/g, (s) => `-${s.toLowerCase()}`);
858
869
  return e.utilities.find((s) => s.name === n);
859
870
  }
860
- function Ee(e, t) {
871
+ function _e(e, t) {
861
872
  const r = /* @__PURE__ */ new Map();
862
- if (e.base && S(e.base, r), e.variants)
873
+ if (e.base && O(e.base, r), e.variants)
863
874
  for (const s of Object.values(e.variants))
864
875
  for (const o of Object.values(s))
865
- S(
876
+ O(
866
877
  o,
867
878
  r
868
879
  );
869
880
  if (e.compoundVariants)
870
881
  for (const s of e.compoundVariants)
871
- s.css && S(s.css, r);
882
+ s.css && O(s.css, r);
872
883
  const n = /* @__PURE__ */ new Map();
873
884
  for (const [s, o] of r) {
874
- const i = D(t, s);
885
+ const i = C(t, s);
875
886
  if (!i)
876
887
  throw new Error(
877
888
  `[styleframe] Utility "${s}" not found in registry. Make sure the utility is registered before using it in a recipe.`
@@ -898,7 +909,7 @@ function Ee(e, t) {
898
909
  }
899
910
  }
900
911
  function We(e) {
901
- const t = b("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: y, ref: d, css: m } = v(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);
902
913
  return {
903
914
  id: t,
904
915
  root: r,
@@ -910,9 +921,9 @@ function We(e) {
910
921
  theme: f,
911
922
  atRule: l,
912
923
  keyframes: u,
913
- media: y,
914
- ref: d,
915
- css: m,
924
+ media: d,
925
+ ref: y,
926
+ css: p,
916
927
  options: n
917
928
  };
918
929
  }
@@ -920,13 +931,13 @@ export {
920
931
  ve as applyModifiers,
921
932
  Ue as capitalizeFirst,
922
933
  De as classNameToCssSelector,
923
- I as createAtRuleFunction,
934
+ K as createAtRuleFunction,
924
935
  fe as createCssFunction,
925
936
  v as createDeclarationsCallbackContext,
926
937
  ge as createKeyframesFunction,
927
938
  he as createMediaFunction,
928
939
  we as createModifierFunction,
929
- C as createPropertyValueResolver,
940
+ I as createPropertyValueResolver,
930
941
  $e as createRecipeFunction,
931
942
  q as createRefFunction,
932
943
  je as createRoot,
@@ -937,7 +948,7 @@ export {
937
948
  M as deepClone,
938
949
  Pe as defaultUtilitySelectorFn,
939
950
  oe as findVariableInScope,
940
- b as generateRandomId,
951
+ A as generateRandomId,
941
952
  xe as generateRecipeRuntime,
942
953
  le as getModifier,
943
954
  Ie as getUtility,
@@ -946,32 +957,32 @@ export {
946
957
  te as isAtRule,
947
958
  T as isCSS,
948
959
  Te as isContainer,
949
- L as isContainerInput,
960
+ G as isContainerInput,
950
961
  ie as isKeyReferenceValue,
951
962
  ne as isModifier,
952
963
  x as isObject,
953
964
  re as isPrimitiveTokenValue,
954
- Se as isRecipe,
955
- A as isRef,
965
+ Oe as isRecipe,
966
+ b as isRef,
956
967
  $ as isRoot,
957
- _e as isSelector,
968
+ Fe as isSelector,
958
969
  Be as isStyleframe,
959
- Oe as isTheme,
970
+ Se as isTheme,
960
971
  g as isToken,
961
972
  N as isTokenEqual,
962
973
  B as isTokenValue,
963
974
  Ne as isUtility,
964
- H as isVariable,
975
+ L as isVariable,
965
976
  Ke as merge,
966
977
  Y as mergeContainers,
967
- me as mergeThemesArray,
968
- de as mergeVariablesArray,
969
- z as parseAtReferences,
970
- E as parseDeclarationsBlock,
971
- Ee as processRecipeUtilities,
972
- pe as rebuildRegistry,
978
+ pe as mergeThemesArray,
979
+ ye as mergeVariablesArray,
980
+ P as parseAtReferences,
981
+ _ as parseDeclarationsBlock,
982
+ _e as processRecipeUtilities,
983
+ me as rebuildRegistry,
973
984
  ae as rfdc,
974
985
  We as styleframe,
975
- G as transformUtilityKey,
986
+ z as transformUtilityKey,
976
987
  ce as validateReference
977
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 S(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(e){return J(e)||w(e)||S(e)||Array.isArray(e)&&e.every(E)}function Te(e){return A(e)&&"id"in e&&"children"in e&&"declarations"in e&&"variables"in e}function P(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 B(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(":")}`,D=/@([\w.-]+)/g;function I(e){const t=[];let r=0,n;for(D.lastIndex=0;(n=D.exec(e))!==null;)t.push(e.slice(r,n.index)),t.push({type:"reference",name:n[1]}),r=D.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 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),{type:"reference",name:i}}const s=I(n);return s.some(i=>w(i))?{type:"css",value:s}:n}}function K(e,t){return function(n,s){const c=N(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=K(e,t);return function(s,...c){return{type:"css",value:s.reduce((a,o,f)=>{if(a.push(...I(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 Ne(e){return e.charAt(0).toUpperCase()+e.slice(1)}function _e(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 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 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 _(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(S(e)&&S(t))return _(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 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)??{}:P(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)??{}:P(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: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=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&&!E(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(E(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=B({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):B(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 $ of p){const j=`${$}.${l}`;if(j!==y.name&&t.variables.some(T=>T.name===j)){m={type:"reference",name:j},C=!0;break}}C||(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: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],$=Ie(C);for(const j of $){const T=[...j.keys()];a.values.find(X=>X.key===l&&X.modifiers.length===T.length&&X.modifiers.every((We,He)=>We===T[He]))||(a.values.push({key:l,value:m,modifiers:T}),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 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!w(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=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=Ne,u.classNameToCssSelector=_e,u.createAtRuleFunction=O,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=Ee,u.findVariableInScope=ee,u.generateRandomId=v,u.generateRecipeRuntime=ve,u.getModifier=ie,u.getUtility=Ue,u.getVariable=Ce,u.hashValue=x,u.isAtRule=Y,u.isCSS=S,u.isContainer=Te,u.isContainerInput=P,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=E,u.isUtility=Me,u.isVariable=U,u.merge=Be,u.mergeContainers=H,u.mergeThemesArray=oe,u.mergeVariablesArray=ce,u.parseAtReferences=I,u.parseDeclarationsBlock=F,u.processRecipeUtilities=Re,u.rebuildRegistry=ae,u.rfdc=re,u.styleframe=Ke,u.transformUtilityKey=B,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.3.0",
3
+ "version": "3.4.0",
4
4
  "type": "module",
5
5
  "types": "./dist/styleframe.d.ts",
6
6
  "module": "./dist/styleframe.js",