@styleframe/core 3.1.0 → 3.2.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,17 @@
1
1
  # @styleframe/core
2
2
 
3
+ ## 3.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#155](https://github.com/styleframe-dev/styleframe/pull/155) [`cc4f170`](https://github.com/styleframe-dev/styleframe/commit/cc4f170c56ad2e246b94ab4d64b7f6c3097c7223) Thanks [@alexgrozav](https://github.com/alexgrozav)! - Refactor recipes, improve modifier at-rule support, and forward variables through modifier factories
8
+ - Refactor recipes and utilities with improved color theming composables
9
+ - Add at-rule support for modifiers (e.g. media preference modifiers)
10
+ - Forward variables and children through all modifier factory functions
11
+ - Restructure docs for components, utilities, and modifiers into composable subdirectories
12
+ - Add Button composable recipe documentation
13
+ - Update plugin scanner for improved recipe handling
14
+
3
15
  ## 3.1.0
4
16
 
5
17
  ### Minor Changes
@@ -36,8 +36,6 @@ export declare function classNameToCssSelector(className: string): string;
36
36
  */
37
37
  declare type CloneFunction<T = any> = (obj: T) => T;
38
38
 
39
- export declare function combineKeys(groups: string[][]): string[][];
40
-
41
39
  declare type ConstructorHandler<T = any> = (obj: T, fn: CloneFunction) => T;
42
40
 
43
41
  declare type ConstructorHandlerTuple<T = any> = [
@@ -57,7 +55,7 @@ export declare type ContainerChild = Variable | Selector | AtRule | Utility;
57
55
 
58
56
  export declare type ContainerInput = Pick<Container, "declarations" | "variables" | "children">;
59
57
 
60
- export declare function createAtRuleFunction(parent: Container, root: Root): (identifier: string, rule: string, declarationsOrCallback?: DeclarationsBlock | DeclarationsCallback) => AtRule;
58
+ export declare function createAtRuleFunction(parent: Container, root: Root): (identifier: string, rule: string, declarationsOrCallback?: DeclarationsBlock | ContainerInput | DeclarationsCallback) => AtRule;
61
59
 
62
60
  export declare function createCssFunction(_parent: Container, _root: Root): (strings: TemplateStringsArray, ...interpolations: (TokenValue | Variable | AtRule)[]) => CSS_2;
63
61
 
@@ -65,7 +63,7 @@ export declare function createDeclarationsCallbackContext(parent: Container, roo
65
63
 
66
64
  export declare function createKeyframesFunction(parent: Container, root: Root): (name: string, declarations: Record<string, DeclarationsBlock>) => AtRule;
67
65
 
68
- export declare function createMediaFunction(parent: Container, root: Root): (query: string, declarationsOrCallback?: DeclarationsBlock | DeclarationsCallback) => AtRule;
66
+ export declare function createMediaFunction(parent: Container, root: Root): (query: string, declarationsOrCallback?: DeclarationsBlock | ContainerInput | DeclarationsCallback) => AtRule;
69
67
 
70
68
  export declare function createModifierFunction(_parent: Container, root: Root): <Key extends string>(key: Key | Key[], factory: ModifierFactory["factory"]) => ModifierFactory;
71
69
 
@@ -260,7 +258,7 @@ declare type CSSValueWithReference<T> = T extends string | number | undefined ?
260
258
  export declare type DeclarationsBlock = {
261
259
  [K in keyof Properties]: CSSValueWithReference<Properties[K]>;
262
260
  } & {
263
- [key: string]: CSSValueWithReference<Properties[keyof Properties]> | DeclarationsBlock;
261
+ [key: string]: CSSValueWithReference<Properties[keyof Properties]> | DeclarationsBlock | ContainerInput;
264
262
  };
265
263
 
266
264
  export declare type DeclarationsCallback<Context extends DeclarationsCallbackContext = DeclarationsCallbackContext> = (context: Context) => DeclarationsBlock | void;
@@ -583,7 +581,7 @@ export declare type UtilityCallbackFn = DeclarationsCallback<DeclarationsCallbac
583
581
  value: TokenValue;
584
582
  }>;
585
583
 
586
- export declare type UtilityCreatorFn = (values: Record<string, TokenValue> | TokenValue[], modifiers?: ModifierFactory[]) => void;
584
+ export declare type UtilityCreatorFn = (values: Record<string, TokenValue> | TokenValue[], modifiers?: (ModifierFactory | ModifierFactory[])[]) => void;
587
585
 
588
586
  export declare type UtilityFactory<Name extends string = string> = {
589
587
  type: "utility";
@@ -1,64 +1,64 @@
1
- function M(e) {
1
+ function $(e) {
2
2
  return typeof e == "object" && e !== null;
3
3
  }
4
- function b(e, t) {
5
- return M(e) && "type" in e && e.type === t;
4
+ function g(e, t) {
5
+ return $(e) && "type" in e && e.type === t;
6
6
  }
7
- function G(e) {
8
- return b(e, "variable");
7
+ function H(e) {
8
+ return g(e, "variable");
9
9
  }
10
- function j(e) {
11
- return b(e, "reference");
10
+ function A(e) {
11
+ return g(e, "reference");
12
12
  }
13
- function Fe(e) {
14
- return b(e, "selector");
13
+ function _e(e) {
14
+ return g(e, "selector");
15
15
  }
16
16
  function te(e) {
17
- return b(e, "at-rule");
17
+ return g(e, "at-rule");
18
18
  }
19
- function _e(e) {
20
- return b(e, "utility");
19
+ function Oe(e) {
20
+ return g(e, "utility");
21
21
  }
22
22
  function ne(e) {
23
- return b(e, "modifier");
23
+ return g(e, "modifier");
24
24
  }
25
25
  function N(e) {
26
- return b(e, "css");
26
+ return g(e, "css");
27
27
  }
28
28
  function Se(e) {
29
- return b(e, "theme");
29
+ return g(e, "theme");
30
30
  }
31
- function $(e) {
32
- return b(e, "root");
31
+ function M(e) {
32
+ return g(e, "root");
33
33
  }
34
34
  function Te(e) {
35
- return b(e, "recipe");
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) || j(e) || N(e) || Array.isArray(e) && e.every(B);
41
+ return re(e) || A(e) || N(e) || Array.isArray(e) && e.every(B);
42
42
  }
43
- function Ce(e) {
44
- return M(e) && "id" in e && "children" in e && "declarations" in e && "variables" in e;
43
+ function Ne(e) {
44
+ return $(e) && "id" in e && "children" in e && "declarations" in e && "variables" in e;
45
45
  }
46
- function ie(e) {
47
- return M(e) && "children" in e && "declarations" in e && "variables" in e;
46
+ function L(e) {
47
+ return $(e) && "children" in e && "declarations" in e && "variables" in e;
48
48
  }
49
- function se(e) {
49
+ function ie(e) {
50
50
  return typeof e == "string" && e.startsWith("@");
51
51
  }
52
- function Ne(e) {
53
- return M(e) && "id" in e && "root" in e && "variable" in e && "selector" in e && "recipe" in e && typeof e.id == "string" && $(e.root);
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);
54
54
  }
55
- function oe(e) {
55
+ function se(e) {
56
56
  let t = 5381;
57
57
  for (let r = 0; r < e.length; r++)
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 q(e) {
61
+ function G(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 q(e) {
71
71
  type: "reference",
72
72
  name: l
73
73
  };
74
- } else if (j(i)) {
74
+ } else if (A(i)) {
75
75
  let c = i.name;
76
76
  for (const a of s)
77
77
  if (c.startsWith(`${a}.`)) {
@@ -81,14 +81,14 @@ function q(e) {
81
81
  f = r(c);
82
82
  } else {
83
83
  const c = String(o).trim();
84
- /\s/.test(c) ? f = oe(c) : f = `[${c}]`;
84
+ /\s/.test(c) ? f = se(c) : f = `[${c}]`;
85
85
  }
86
86
  return {
87
87
  [f]: i
88
88
  };
89
89
  };
90
90
  }
91
- const Be = ({
91
+ const Pe = ({
92
92
  name: e,
93
93
  value: t,
94
94
  modifiers: r
@@ -104,7 +104,7 @@ function z(e) {
104
104
  t.push(e.slice(r, n.index)), t.push({ type: "reference", name: n[1] }), r = _.lastIndex;
105
105
  return t.push(e.slice(r)), t;
106
106
  }
107
- function ce(e, t, r) {
107
+ function oe(e, t, r) {
108
108
  let n = t;
109
109
  for (; n; ) {
110
110
  if (n.variables.some((s) => s.name === e))
@@ -116,28 +116,28 @@ function ce(e, t, r) {
116
116
  }
117
117
  return !1;
118
118
  }
119
- function fe(e, t, r) {
120
- if (!ce(e, t, r))
119
+ function ce(e, t, r) {
120
+ if (!oe(e, t, r))
121
121
  throw new Error(
122
122
  `[styleframe] Variable "${e}" is not defined. Check that the variable exists before referencing it with "@${e}".`
123
123
  );
124
124
  }
125
- function I(e, t) {
125
+ function C(e, t) {
126
126
  return function(n) {
127
127
  if (typeof n != "string" || !n.includes("@"))
128
128
  return n;
129
- if (se(n) && /^@[\w.-]+$/.test(n)) {
129
+ if (ie(n) && /^@[\w.-]+$/.test(n)) {
130
130
  const i = n.slice(1);
131
- return fe(i, e, t), { type: "reference", name: i };
131
+ return ce(i, e, t), { type: "reference", name: i };
132
132
  }
133
133
  const s = z(n);
134
- return s.some((i) => j(i)) ? { type: "css", value: s } : n;
134
+ return s.some((i) => A(i)) ? { type: "css", value: s } : n;
135
135
  };
136
136
  }
137
- function X(e, t) {
137
+ function q(e, t) {
138
138
  return function(n, s) {
139
- const o = I(e, t), i = s != null ? o(s) : s;
140
- if (G(n))
139
+ const o = C(e, t), i = s != null ? o(s) : s;
140
+ if (H(n))
141
141
  return {
142
142
  type: "reference",
143
143
  name: n.name,
@@ -154,28 +154,28 @@ function X(e, t) {
154
154
  };
155
155
  };
156
156
  }
157
- function ae(e, t) {
158
- const r = X(e, t);
157
+ function fe(e, t) {
158
+ const r = q(e, t);
159
159
  return function(s, ...o) {
160
160
  return {
161
161
  type: "css",
162
162
  value: s.reduce((f, c, a) => {
163
163
  if (f.push(...z(c)), a < o.length) {
164
164
  const l = o[a];
165
- G(l) ? f.push(r(l)) : te(l) ? f.push(l.rule) : f.push(l);
165
+ H(l) ? f.push(r(l)) : te(l) ? f.push(l.rule) : f.push(l);
166
166
  }
167
167
  return f;
168
168
  }, [])
169
169
  };
170
170
  };
171
171
  }
172
- function Pe(e) {
172
+ function Ue(e) {
173
173
  return e.charAt(0).toUpperCase() + e.slice(1);
174
174
  }
175
- function Ke(e) {
175
+ function De(e) {
176
176
  return `.${e.replace(/[[\].#()%,:/]/g, "\\$&")}`;
177
177
  }
178
- function v(e) {
178
+ function j(e) {
179
179
  if (e instanceof Buffer)
180
180
  return Buffer.from(e);
181
181
  const t = e.constructor;
@@ -185,9 +185,9 @@ function v(e) {
185
185
  e.byteLength / e.BYTES_PER_ELEMENT || 1
186
186
  );
187
187
  }
188
- function ue(e) {
188
+ function ae(e) {
189
189
  if (e = e || {}, e.circular)
190
- return le(e);
190
+ return ue(e);
191
191
  const t = /* @__PURE__ */ new Map();
192
192
  if (t.set(Date, (i) => new Date(i)), t.set(
193
193
  Map,
@@ -204,7 +204,7 @@ function ue(e) {
204
204
  const c = Object.keys(i), a = Array.from({ length: c.length });
205
205
  for (let l = 0; l < c.length; l++) {
206
206
  const u = c[l], d = i[u];
207
- 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] = v(d) : a[u] = f(d);
207
+ 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
208
  }
209
209
  return a;
210
210
  }
@@ -217,7 +217,7 @@ function ue(e) {
217
217
  for (const c in i) {
218
218
  if (Object.hasOwnProperty.call(i, c) === !1) continue;
219
219
  const a = i[c];
220
- typeof a != "object" || a === null ? f[c] = a : a.constructor !== Object && (r = t.get(a.constructor)) ? f[c] = r(a, s) : ArrayBuffer.isView(a) ? f[c] = v(a) : f[c] = s(a);
220
+ typeof a != "object" || a === null ? f[c] = a : a.constructor !== Object && (r = t.get(a.constructor)) ? f[c] = r(a, s) : ArrayBuffer.isView(a) ? f[c] = j(a) : f[c] = s(a);
221
221
  }
222
222
  return f;
223
223
  }
@@ -229,12 +229,12 @@ function ue(e) {
229
229
  const f = {};
230
230
  for (const c in i) {
231
231
  const a = i[c];
232
- typeof a != "object" || a === null ? f[c] = a : a.constructor !== Object && (r = t.get(a.constructor)) ? f[c] = r(a, o) : ArrayBuffer.isView(a) ? f[c] = v(a) : f[c] = o(a);
232
+ typeof a != "object" || a === null ? f[c] = a : a.constructor !== Object && (r = t.get(a.constructor)) ? f[c] = r(a, o) : ArrayBuffer.isView(a) ? f[c] = j(a) : f[c] = o(a);
233
233
  }
234
234
  return f;
235
235
  }
236
236
  }
237
- function le(e) {
237
+ function ue(e) {
238
238
  const t = [], r = [], n = /* @__PURE__ */ new Map();
239
239
  if (n.set(Date, (c) => new Date(c)), n.set(
240
240
  Map,
@@ -250,16 +250,16 @@ function le(e) {
250
250
  function o(c, a) {
251
251
  const l = Object.keys(c), u = Array.from({ length: l.length });
252
252
  for (let d = 0; d < l.length; d++) {
253
- const y = l[d], m = c[y];
254
- if (typeof m != "object" || m === null)
255
- u[y] = m;
256
- else if (m.constructor !== Object && (s = n.get(m.constructor)))
257
- u[y] = s(m, a);
258
- else if (ArrayBuffer.isView(m))
259
- u[y] = v(m);
253
+ const y = l[d], p = c[y];
254
+ if (typeof p != "object" || p === null)
255
+ u[y] = p;
256
+ else if (p.constructor !== Object && (s = n.get(p.constructor)))
257
+ u[y] = s(p, a);
258
+ else if (ArrayBuffer.isView(p))
259
+ u[y] = j(p);
260
260
  else {
261
- const p = t.indexOf(m);
262
- p !== -1 ? u[y] = r[p] : u[y] = a(m);
261
+ const h = t.indexOf(p);
262
+ h !== -1 ? u[y] = r[h] : u[y] = a(p);
263
263
  }
264
264
  }
265
265
  return u;
@@ -279,7 +279,7 @@ function le(e) {
279
279
  else if (u.constructor !== Object && (s = n.get(u.constructor)))
280
280
  a[l] = s(u, i);
281
281
  else if (ArrayBuffer.isView(u))
282
- a[l] = v(u);
282
+ a[l] = j(u);
283
283
  else {
284
284
  const d = t.indexOf(u);
285
285
  d !== -1 ? a[l] = r[d] : a[l] = i(u);
@@ -301,7 +301,7 @@ function le(e) {
301
301
  else if (u.constructor !== Object && (s = n.get(u.constructor)))
302
302
  a[l] = s(u, f);
303
303
  else if (ArrayBuffer.isView(u))
304
- a[l] = v(u);
304
+ a[l] = j(u);
305
305
  else {
306
306
  const d = t.indexOf(u);
307
307
  d !== -1 ? a[l] = r[d] : a[l] = f(u);
@@ -310,8 +310,8 @@ function le(e) {
310
310
  return t.pop(), r.pop(), a;
311
311
  }
312
312
  }
313
- const R = ue();
314
- function w(e, t = 8) {
313
+ const k = ae();
314
+ function b(e, t = 8) {
315
315
  const r = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
316
316
  let n = "";
317
317
  for (let s = 0; s < t; s++) {
@@ -320,7 +320,7 @@ function w(e, t = 8) {
320
320
  }
321
321
  return e ? `${e}${n}` : n;
322
322
  }
323
- function Ue(e, t) {
323
+ function Ce(e, t) {
324
324
  const r = e.variables.find((n) => n.name === t);
325
325
  if (!r)
326
326
  throw new Error(`Variable "${t}" not found`);
@@ -332,7 +332,7 @@ function Ie(e, t) {
332
332
  throw new Error(`Utility "${t}" not found`);
333
333
  return r;
334
334
  }
335
- function de(e, t) {
335
+ function le(e, t) {
336
336
  const r = e.modifiers.find(
337
337
  (n) => n.key.includes(t)
338
338
  );
@@ -340,25 +340,25 @@ function de(e, t) {
340
340
  throw new Error(`Modifier "${t}" not found`);
341
341
  return r;
342
342
  }
343
- function S(e, t) {
343
+ function O(e, t) {
344
344
  if (e === t) return !0;
345
345
  if (typeof e != typeof t) return !1;
346
346
  if (e === null || t === null) return e === t;
347
347
  if (typeof e != "object" || typeof t != "object") return !1;
348
348
  if (Array.isArray(e) && Array.isArray(t))
349
- return e.length !== t.length ? !1 : e.every((r, n) => S(r, t[n]));
349
+ return e.length !== t.length ? !1 : e.every((r, n) => O(r, t[n]));
350
350
  if ("type" in e && "type" in t) {
351
351
  if (e.type !== t.type) return !1;
352
- if (j(e) && j(t))
353
- return e.name === t.name && S(e.fallback, t.fallback);
352
+ if (A(e) && A(t))
353
+ return e.name === t.name && O(e.fallback, t.fallback);
354
354
  if (N(e) && N(t))
355
- return S(e.value, t.value);
355
+ return O(e.value, t.value);
356
356
  }
357
357
  return !1;
358
358
  }
359
- const Y = "__licenseRequired";
360
- function ye(e) {
361
- P(e) || Object.defineProperty(e, Y, {
359
+ const X = "__licenseRequired";
360
+ function de(e) {
361
+ P(e) || Object.defineProperty(e, X, {
362
362
  value: !0,
363
363
  writable: !1,
364
364
  configurable: !1,
@@ -366,9 +366,9 @@ function ye(e) {
366
366
  });
367
367
  }
368
368
  function P(e) {
369
- return Object.prototype.hasOwnProperty.call(e, Y);
369
+ return Object.prototype.hasOwnProperty.call(e, X);
370
370
  }
371
- function me(e, t) {
371
+ function ye(e, t) {
372
372
  const r = [...e];
373
373
  for (const n of t) {
374
374
  const s = r.find(
@@ -386,14 +386,14 @@ function pe(e, t) {
386
386
  );
387
387
  s ? Object.assign(
388
388
  s,
389
- Z(s, n)
389
+ Y(s, n)
390
390
  ) : r.push(n);
391
391
  }
392
392
  return r;
393
393
  }
394
- function Z(e, t) {
394
+ function Y(e, t) {
395
395
  return Object.keys(e).reduce(
396
- (r, n) => (n === "variables" ? r.variables = me(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(
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(
397
397
  t[n]
398
398
  )), r),
399
399
  {
@@ -402,29 +402,29 @@ function Z(e, t) {
402
402
  }
403
403
  );
404
404
  }
405
- function K(e, t) {
405
+ function U(e, t) {
406
406
  for (const r of e)
407
- "id" in r && typeof r.id == "string" && (t._registry.set(r.id, r), "children" in r && K(r.children, t));
407
+ "id" in r && typeof r.id == "string" && (t._registry.set(r.id, r), "children" in r && U(r.children, t));
408
408
  }
409
- function he(e) {
410
- e._registry = /* @__PURE__ */ new Map(), e._registry.set(e.id, e), K(e.children, e);
409
+ function me(e) {
410
+ e._registry = /* @__PURE__ */ new Map(), e._registry.set(e.id, e), U(e.children, e);
411
411
  for (const t of e.themes)
412
- e._registry.set(t.id, t), K(t.children, e);
412
+ e._registry.set(t.id, t), U(t.children, e);
413
413
  }
414
- function De(e, ...t) {
414
+ function Ke(e, ...t) {
415
415
  return t.reduce((r, n) => {
416
416
  const s = {
417
417
  ...r,
418
- root: Z(r.root, n.root)
418
+ root: Y(r.root, n.root)
419
419
  };
420
- return he(s.root), (P(r) || P(n)) && ye(s), s;
420
+ return me(s.root), (P(r) || P(n)) && de(s), s;
421
421
  }, e);
422
422
  }
423
- function D(e, t) {
423
+ function I(e, t) {
424
424
  return function(n, s, o) {
425
425
  const i = {
426
426
  type: "at-rule",
427
- id: w("ar-"),
427
+ id: b("ar-"),
428
428
  parentId: e.id,
429
429
  identifier: n,
430
430
  rule: s,
@@ -433,8 +433,8 @@ function D(e, t) {
433
433
  children: []
434
434
  };
435
435
  t._registry.set(i.id, i);
436
- const f = V(i, t);
437
- return typeof o == "function" ? i.declarations = o(f) ?? {} : o && (i.declarations = o), x(
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(
438
438
  i.declarations,
439
439
  f,
440
440
  i,
@@ -442,23 +442,23 @@ function D(e, t) {
442
442
  ), e.children.push(i), i;
443
443
  };
444
444
  }
445
- function ge(e, t) {
446
- const r = D(e, t);
445
+ function he(e, t) {
446
+ const r = I(e, t);
447
447
  return function(s, o) {
448
448
  return r("media", s, o);
449
449
  };
450
450
  }
451
- function be(e, t) {
452
- const r = D(e, t);
451
+ function ge(e, t) {
452
+ const r = I(e, t);
453
453
  return function(s, o) {
454
454
  return r("keyframes", s, o);
455
455
  };
456
456
  }
457
- function Ae(e, t) {
457
+ function be(e, t) {
458
458
  return function(n, s) {
459
459
  const o = {
460
460
  type: "selector",
461
- id: w("sel-"),
461
+ id: b("sel-"),
462
462
  parentId: e.id,
463
463
  query: n,
464
464
  declarations: {},
@@ -466,8 +466,8 @@ function Ae(e, t) {
466
466
  children: []
467
467
  };
468
468
  t._registry.set(o.id, o);
469
- const i = V(o, t);
470
- return typeof s == "function" ? o.declarations = s(i) ?? {} : ie(s) ? (o.variables = s.variables, o.declarations = s.declarations, o.children = s.children) : o.declarations = s, x(
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(
471
471
  o.declarations,
472
472
  i,
473
473
  o,
@@ -475,11 +475,11 @@ function Ae(e, t) {
475
475
  ), e.children.push(o), o;
476
476
  };
477
477
  }
478
- function we(e, t) {
478
+ function Ae(e, t) {
479
479
  return function(n, s, o = {
480
480
  default: !1
481
481
  }) {
482
- const i = typeof n == "string" ? n : n.name, c = I(e, t)(s), a = e.variables.find(
482
+ const i = typeof n == "string" ? n : n.name, c = C(e, t)(s), a = e.variables.find(
483
483
  (u) => u.name === i
484
484
  );
485
485
  if (o.default && a)
@@ -488,7 +488,7 @@ function we(e, t) {
488
488
  return a.value = c, a;
489
489
  const l = {
490
490
  type: "variable",
491
- id: w("var-"),
491
+ id: b("var-"),
492
492
  parentId: e.id,
493
493
  name: i,
494
494
  value: c
@@ -496,8 +496,8 @@ function we(e, t) {
496
496
  return e.variables.push(l), l;
497
497
  };
498
498
  }
499
- function V(e, t) {
500
- const r = we(e, t), n = Ae(e, t), s = D(e, t), o = be(t, t), i = ge(e, t), f = X(t, t), c = ae(t, t);
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);
501
501
  return {
502
502
  variable: r,
503
503
  selector: n,
@@ -520,7 +520,7 @@ function x(e, t, r, n) {
520
520
  const i = e[o];
521
521
  typeof i == "object" && (t.selector(o, i), delete e[o]);
522
522
  }
523
- const s = I(r, n);
523
+ const s = C(r, n);
524
524
  for (const o in e) {
525
525
  const i = e[o];
526
526
  if (B(i)) {
@@ -530,55 +530,41 @@ function x(e, t, r, n) {
530
530
  }
531
531
  return e;
532
532
  }
533
- function je(e) {
534
- const t = [];
535
- function r(n, s) {
536
- s.length > 0 && t.push([...s].sort());
537
- for (let o = n; o < e.length; o++) {
538
- const i = e[o];
539
- if (i)
540
- if (i.length === 1 && i[0])
541
- r(o + 1, [...s, i[0]]);
542
- else
543
- for (const f of i)
544
- r(o + 1, [...s, f]);
545
- }
546
- }
547
- return r(0, []), t.sort((n, s) => n.length !== s.length ? n.length - s.length : n.join(",").localeCompare(s.join(",")));
548
- }
549
- function ve(e, t, r) {
533
+ function we(e, t, r) {
550
534
  const n = {
551
535
  ...e,
552
- id: w("ut-"),
536
+ id: b("ut-"),
553
537
  parentId: e.parentId,
554
538
  declarations: { ...e.declarations },
555
539
  variables: [...e.variables],
556
540
  children: [...e.children],
557
541
  modifiers: [...r.keys()]
558
542
  };
559
- t._registry.set(n.id, n);
560
- const s = V(n, t);
561
- if (r.size > 0) {
562
- const o = R(e.declarations);
563
- let i = !1;
564
- for (const f of r.values()) {
565
- const c = f.factory({
566
- ...s,
567
- declarations: R(o),
568
- variables: R(n.variables),
569
- children: R(n.children)
543
+ if (t._registry.set(n.id, n), r.size > 0) {
544
+ const s = [...r.values()];
545
+ let o = k(e.declarations);
546
+ n.declarations = {}, n.variables = [], n.children = [];
547
+ for (let f = s.length - 1; f >= 0; f--) {
548
+ const c = w(n, t), a = s[f]?.factory({
549
+ ...c,
550
+ declarations: k(o),
551
+ variables: k(e.variables),
552
+ children: k(e.children)
570
553
  });
571
- c && (i || (n.declarations = {}, i = !0), Object.assign(n.declarations, c), x(
572
- n.declarations,
573
- s,
574
- n,
575
- t
576
- ));
554
+ a && (o = a);
577
555
  }
556
+ n.declarations = o;
557
+ const i = w(n, t);
558
+ x(
559
+ n.declarations,
560
+ i,
561
+ n,
562
+ t
563
+ );
578
564
  }
579
565
  return n;
580
566
  }
581
- function Ve(e, t) {
567
+ function ve(e, t) {
582
568
  return function(n, s) {
583
569
  const o = {
584
570
  type: "modifier",
@@ -588,10 +574,10 @@ function Ve(e, t) {
588
574
  return t.modifiers.push(o), o;
589
575
  };
590
576
  }
591
- function ke() {
577
+ function je() {
592
578
  const e = {
593
579
  type: "root",
594
- id: w("rt-"),
580
+ id: b("rt-"),
595
581
  declarations: {},
596
582
  utilities: [],
597
583
  modifiers: [],
@@ -603,8 +589,8 @@ function ke() {
603
589
  };
604
590
  return e._registry.set(e.id, e), e;
605
591
  }
606
- function Re(e, t) {
607
- const r = q({ namespace: e });
592
+ function Ve(e, t) {
593
+ const r = G({ namespace: e });
608
594
  return (n) => {
609
595
  if (typeof n == "string" && n[0] === "@") {
610
596
  const s = n.slice(1), o = e.find(
@@ -635,7 +621,21 @@ function Re(e, t) {
635
621
  return r(n);
636
622
  };
637
623
  }
638
- function $e(e, t) {
624
+ function Re(e) {
625
+ let t = [/* @__PURE__ */ new Map()];
626
+ for (const r of e) {
627
+ if (!ne(r)) continue;
628
+ const n = [];
629
+ for (const s of r.key)
630
+ for (const o of t) {
631
+ const i = new Map(o);
632
+ i.set(s, r), n.push(i);
633
+ }
634
+ t = n;
635
+ }
636
+ return t.filter((r) => r.size > 0);
637
+ }
638
+ function ke(e, t) {
639
639
  return function(n, s, o = {}) {
640
640
  const i = t.utilities.find((c) => c.name === n);
641
641
  if (i)
@@ -645,7 +645,7 @@ function $e(e, t) {
645
645
  name: n,
646
646
  factory: s,
647
647
  values: [],
648
- autogenerate: o.autogenerate ?? (Array.isArray(o.namespace) ? Re(o.namespace, t) : q(
648
+ autogenerate: o.autogenerate ?? (Array.isArray(o.namespace) ? Ve(o.namespace, t) : G(
649
649
  o.namespace ? { namespace: o.namespace } : void 0
650
650
  )),
651
651
  namespace: o.namespace,
@@ -664,32 +664,32 @@ function $e(e, t) {
664
664
  for (const [u, d] of Object.entries(l)) {
665
665
  let y = d;
666
666
  if (typeof d == "string" && d[0] === "@") {
667
- const h = d.slice(1);
668
- !Array.isArray(l) && h in l && (y = l[h]);
667
+ const m = d.slice(1);
668
+ !Array.isArray(l) && m in l && (y = l[m]);
669
669
  }
670
- if (f.namespace && j(d))
671
- if (t.variables.some((h) => h.name === d.name))
670
+ if (f.namespace && A(d))
671
+ if (t.variables.some((m) => m.name === d.name))
672
672
  y = d;
673
673
  else {
674
- const h = Array.isArray(f.namespace) ? f.namespace : [f.namespace];
675
- let E = !1;
676
- for (const O of h) {
677
- const g = `${O}.${u}`;
678
- if (g !== d.name && t.variables.some((A) => A.name === g)) {
674
+ 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)) {
679
679
  y = {
680
680
  type: "reference",
681
- name: g
682
- }, E = !0;
681
+ name: v
682
+ }, R = !0;
683
683
  break;
684
684
  }
685
685
  }
686
- E || (y = u);
686
+ R || (y = u);
687
687
  }
688
- const m = f.values.find(
689
- (h) => h.key === u && h.modifiers.length === 0
690
- ), p = {
688
+ const p = f.values.find(
689
+ (m) => m.key === u && m.modifiers.length === 0
690
+ ), h = {
691
691
  type: "utility",
692
- id: w("ut-"),
692
+ id: b("ut-"),
693
693
  parentId: e.id,
694
694
  name: n,
695
695
  value: u,
@@ -698,42 +698,41 @@ function $e(e, t) {
698
698
  children: [],
699
699
  modifiers: []
700
700
  };
701
- t._registry.set(p.id, p);
702
- const W = V(
703
- p,
701
+ t._registry.set(h.id, h);
702
+ const K = w(
703
+ h,
704
704
  t
705
705
  );
706
- if (p.declarations = s({
707
- ...W,
706
+ if (h.declarations = s({
707
+ ...K,
708
708
  value: y
709
709
  }) ?? {}, x(
710
- p.declarations,
711
- W,
712
- p,
710
+ h.declarations,
711
+ K,
712
+ h,
713
713
  t
714
- ), m || (f.values.push({
714
+ ), p || (f.values.push({
715
715
  key: u,
716
716
  value: y,
717
717
  modifiers: []
718
- }), e.children.push(p)), a && a.length > 0) {
719
- const h = a.map((g) => g.key), O = je(h).filter((g) => !f.values.find(
720
- (A) => A.key === u && A.modifiers.length === g.length && A.modifiers.every((k) => g.includes(k))
721
- )).reduce((g, A) => {
722
- const k = /* @__PURE__ */ new Map();
723
- for (const H of A) {
724
- const F = a.find(
725
- (ee) => ee.key.includes(H)
726
- );
727
- F && ne(F) && k.set(H, F);
718
+ }), e.children.push(h)), a && a.length > 0)
719
+ 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()];
723
+ f.values.find(
724
+ (F) => F.key === u && F.modifiers.length === V.length && F.modifiers.every(
725
+ (Q, ee) => Q === V[ee]
726
+ )
727
+ ) || (f.values.push({
728
+ key: u,
729
+ value: y,
730
+ modifiers: V
731
+ }), e.children.push(
732
+ we(h, t, v)
733
+ ));
728
734
  }
729
- return f.values.push({
730
- key: u,
731
- value: y,
732
- modifiers: A
733
- }), g.push(ve(p, t, k)), g;
734
- }, []);
735
- e.children.push(...O);
736
- }
735
+ }
737
736
  }
738
737
  }
739
738
  };
@@ -744,7 +743,7 @@ function Me(e, t) {
744
743
  return function(n, s) {
745
744
  const o = t.themes.find((c) => c.name === n), i = o ?? {
746
745
  type: "theme",
747
- id: w("th-"),
746
+ id: b("th-"),
748
747
  parentId: t.id,
749
748
  name: n,
750
749
  declarations: {},
@@ -752,62 +751,62 @@ function Me(e, t) {
752
751
  children: []
753
752
  };
754
753
  o || (t._registry.set(i.id, i), t.themes.push(i));
755
- const f = V(i, t);
754
+ const f = w(i, t);
756
755
  return s && s(f), i;
757
756
  };
758
757
  }
759
- function xe(e, t) {
758
+ function $e(e, t) {
760
759
  return function(n) {
761
760
  const s = {
762
761
  type: "recipe",
763
762
  ...n
764
763
  };
765
- return s._runtime = Ee(s, t), Oe(s, t), t.recipes.push(s), s;
764
+ return s._runtime = xe(s, t), Ee(s, t), t.recipes.push(s), s;
766
765
  };
767
766
  }
768
- function L(e, t) {
767
+ function W(e, t) {
769
768
  const r = e.autogenerate(t);
770
769
  return Object.keys(r)[0] ?? "default";
771
770
  }
772
- function T(e, t) {
771
+ function S(e, t) {
773
772
  const r = {};
774
773
  for (const [n, s] of Object.entries(e))
775
- if (J(s)) {
774
+ if (Z(s)) {
776
775
  const o = {};
777
776
  for (const [i, f] of Object.entries(s)) {
778
- const c = U(t, i);
777
+ const c = D(t, i);
779
778
  if (!c)
780
779
  throw new Error(
781
780
  `[styleframe] Utility "${i}" not found in registry. Make sure the utility is registered before using it in a recipe.`
782
781
  );
783
- o[i] = L(
782
+ o[i] = W(
784
783
  c,
785
784
  f
786
785
  );
787
786
  }
788
- r[Q(n)] = o;
787
+ r[J(n)] = o;
789
788
  } else if (typeof s == "boolean")
790
789
  r[n] = s;
791
790
  else {
792
- const o = U(t, n);
791
+ const o = D(t, n);
793
792
  if (!o)
794
793
  throw new Error(
795
794
  `[styleframe] Utility "${n}" not found in registry. Make sure the utility is registered before using it in a recipe.`
796
795
  );
797
- r[n] = L(o, s);
796
+ r[n] = W(o, s);
798
797
  }
799
798
  return r;
800
799
  }
801
- function Ee(e, t) {
800
+ function xe(e, t) {
802
801
  const r = {};
803
- if (e.base && (r.base = T(e.base, t)), e.variants) {
802
+ if (e.base && (r.base = S(e.base, t)), e.variants) {
804
803
  const n = {};
805
804
  for (const [s, o] of Object.entries(e.variants)) {
806
805
  const i = {};
807
806
  for (const [f, c] of Object.entries(
808
807
  o
809
808
  ))
810
- c == null ? i[f] = null : i[f] = T(
809
+ c == null ? i[f] = null : i[f] = S(
811
810
  c,
812
811
  t
813
812
  );
@@ -817,50 +816,50 @@ function Ee(e, t) {
817
816
  }
818
817
  return e.defaultVariants && (r.defaultVariants = { ...e.defaultVariants }), e.compoundVariants && (r.compoundVariants = e.compoundVariants.map((n) => ({
819
818
  match: { ...n.match },
820
- css: T(n.css, t)
819
+ css: S(n.css, t)
821
820
  }))), r;
822
821
  }
823
- function J(e) {
824
- return !j(e) && typeof e == "object" && e !== null;
822
+ function Z(e) {
823
+ return !A(e) && typeof e == "object" && e !== null;
825
824
  }
826
- function Q(e) {
825
+ function J(e) {
827
826
  return e.startsWith("&::") ? e.slice(3) : e.startsWith("&:") ? e.slice(2) : e;
828
827
  }
829
- function C(e, t) {
828
+ function T(e, t) {
830
829
  const r = (n, s, o) => {
831
830
  let i = t.get(n);
832
831
  i || (i = [], t.set(n, i)), i.push({ value: s, modifiers: o });
833
832
  };
834
833
  for (const [n, s] of Object.entries(e))
835
- if (J(s)) {
836
- const o = Q(n).split(":");
834
+ if (Z(s)) {
835
+ const o = J(n).split(":");
837
836
  for (const [i, f] of Object.entries(s))
838
837
  r(i, f, o);
839
838
  } else
840
839
  r(n, s, []);
841
840
  }
842
- function U(e, t) {
841
+ function D(e, t) {
843
842
  const r = e.utilities.find((s) => s.name === t);
844
843
  if (r)
845
844
  return r;
846
845
  const n = t.replace(/[A-Z]/g, (s) => `-${s.toLowerCase()}`);
847
846
  return e.utilities.find((s) => s.name === n);
848
847
  }
849
- function Oe(e, t) {
848
+ function Ee(e, t) {
850
849
  const r = /* @__PURE__ */ new Map();
851
- if (e.base && C(e.base, r), e.variants)
850
+ if (e.base && T(e.base, r), e.variants)
852
851
  for (const s of Object.values(e.variants))
853
852
  for (const o of Object.values(s))
854
- C(
853
+ T(
855
854
  o,
856
855
  r
857
856
  );
858
857
  if (e.compoundVariants)
859
858
  for (const s of e.compoundVariants)
860
- s.css && C(s.css, r);
859
+ s.css && T(s.css, r);
861
860
  const n = /* @__PURE__ */ new Map();
862
861
  for (const [s, o] of r) {
863
- const i = U(t, s);
862
+ const i = D(t, s);
864
863
  if (!i)
865
864
  throw new Error(
866
865
  `[styleframe] Utility "${s}" not found in registry. Make sure the utility is registered before using it in a recipe.`
@@ -870,7 +869,7 @@ function Oe(e, t) {
870
869
  for (const a of f.modifiers) {
871
870
  if (!n.has(a))
872
871
  try {
873
- n.set(a, de(t, a));
872
+ n.set(a, le(t, a));
874
873
  } catch {
875
874
  throw new Error(
876
875
  `[styleframe] Modifier "${a}" not found in registry. Make sure the modifier is registered before using it in a recipe.`
@@ -881,13 +880,13 @@ function Oe(e, t) {
881
880
  }
882
881
  i.create(
883
882
  [f.value],
884
- c.length > 0 ? c : void 0
883
+ c.length > 0 ? c.length > 1 ? [c] : c : void 0
885
884
  );
886
885
  }
887
886
  }
888
887
  }
889
888
  function We(e) {
890
- const t = w("sf-"), r = ke(), n = { ...e }, s = $e(r, r), o = Ve(r, r), i = xe(r, r), f = Me(r, r), { variable: c, selector: a, atRule: l, keyframes: u, media: d, ref: y, css: m } = V(r, r);
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);
891
890
  return {
892
891
  id: t,
893
892
  root: r,
@@ -901,67 +900,66 @@ function We(e) {
901
900
  keyframes: u,
902
901
  media: d,
903
902
  ref: y,
904
- css: m,
903
+ css: p,
905
904
  options: n
906
905
  };
907
906
  }
908
907
  export {
909
- ve as applyModifiers,
910
- Pe as capitalizeFirst,
911
- Ke as classNameToCssSelector,
912
- je as combineKeys,
913
- D as createAtRuleFunction,
914
- ae as createCssFunction,
915
- V as createDeclarationsCallbackContext,
916
- be as createKeyframesFunction,
917
- ge as createMediaFunction,
918
- Ve as createModifierFunction,
919
- I as createPropertyValueResolver,
920
- xe as createRecipeFunction,
921
- X as createRefFunction,
922
- ke as createRoot,
923
- Ae as createSelectorFunction,
908
+ we as applyModifiers,
909
+ Ue as capitalizeFirst,
910
+ De as classNameToCssSelector,
911
+ I as createAtRuleFunction,
912
+ fe as createCssFunction,
913
+ w as createDeclarationsCallbackContext,
914
+ ge as createKeyframesFunction,
915
+ he as createMediaFunction,
916
+ ve as createModifierFunction,
917
+ C as createPropertyValueResolver,
918
+ $e as createRecipeFunction,
919
+ q as createRefFunction,
920
+ je as createRoot,
921
+ be as createSelectorFunction,
924
922
  Me as createThemeFunction,
925
- $e as createUtilityFunction,
926
- we as createVariableFunction,
927
- R as deepClone,
928
- Be as defaultUtilitySelectorFn,
929
- ce as findVariableInScope,
930
- w as generateRandomId,
931
- Ee as generateRecipeRuntime,
932
- de as getModifier,
923
+ ke as createUtilityFunction,
924
+ Ae as createVariableFunction,
925
+ k as deepClone,
926
+ Pe as defaultUtilitySelectorFn,
927
+ oe as findVariableInScope,
928
+ b as generateRandomId,
929
+ xe as generateRecipeRuntime,
930
+ le as getModifier,
933
931
  Ie as getUtility,
934
- Ue as getVariable,
935
- oe as hashValue,
932
+ Ce as getVariable,
933
+ se as hashValue,
936
934
  te as isAtRule,
937
935
  N as isCSS,
938
- Ce as isContainer,
939
- ie as isContainerInput,
940
- se as isKeyReferenceValue,
936
+ Ne as isContainer,
937
+ L as isContainerInput,
938
+ ie as isKeyReferenceValue,
941
939
  ne as isModifier,
942
- M as isObject,
940
+ $ as isObject,
943
941
  re as isPrimitiveTokenValue,
944
942
  Te as isRecipe,
945
- j as isRef,
946
- $ as isRoot,
947
- Fe as isSelector,
948
- Ne as isStyleframe,
943
+ A as isRef,
944
+ M as isRoot,
945
+ _e as isSelector,
946
+ Be as isStyleframe,
949
947
  Se as isTheme,
950
- b as isToken,
951
- S as isTokenEqual,
948
+ g as isToken,
949
+ O as isTokenEqual,
952
950
  B as isTokenValue,
953
- _e as isUtility,
954
- G as isVariable,
955
- De as merge,
956
- Z as mergeContainers,
951
+ Oe as isUtility,
952
+ H as isVariable,
953
+ Ke as merge,
954
+ Y as mergeContainers,
957
955
  pe as mergeThemesArray,
958
- me as mergeVariablesArray,
956
+ ye as mergeVariablesArray,
959
957
  z as parseAtReferences,
960
958
  x as parseDeclarationsBlock,
961
- Oe as processRecipeUtilities,
962
- he as rebuildRegistry,
963
- ue as rfdc,
959
+ Ee as processRecipeUtilities,
960
+ me as rebuildRegistry,
961
+ ae as rfdc,
964
962
  We as styleframe,
965
- q as transformUtilityKey,
966
- fe as validateReference
963
+ G as transformUtilityKey,
964
+ ce as validateReference
967
965
  };
@@ -1 +1 @@
1
- (function(u,V){typeof exports=="object"&&typeof module<"u"?V(exports):typeof define=="function"&&define.amd?define(["exports"],V):(u=typeof globalThis<"u"?globalThis:u||self,V(u.styleframe={}))})(this,(function(u){"use strict";function V(e){return typeof e=="object"&&e!==null}function g(e,t){return V(e)&&"type"in e&&e.type===t}function U(e){return g(e,"variable")}function v(e){return g(e,"reference")}function $e(e){return g(e,"selector")}function Y(e){return g(e,"at-rule")}function Te(e){return g(e,"utility")}function Z(e){return g(e,"modifier")}function T(e){return g(e,"css")}function Se(e){return g(e,"theme")}function F(e){return g(e,"root")}function Ce(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)||v(e)||T(e)||Array.isArray(e)&&e.every(S)}function Ee(e){return V(e)&&"id"in e&&"children"in e&&"declarations"in e&&"variables"in e}function Q(e){return V(e)&&"children"in e&&"declarations"in e&&"variables"in e}function x(e){return typeof e=="string"&&e.startsWith("@")}function Oe(e){return V(e)&&"id"in e&&"root"in e&&"variable"in e&&"selector"in e&&"recipe"in e&&typeof e.id=="string"&&F(e.root)}function ee(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 K(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=ee(o):a=`[${o}]`}return{[a]:i}}}const _e=({name:e,value:t,modifiers:r})=>`_${[...r,e,...t==="default"?[]:[t]].filter(Boolean).join(":")}`,N=/@([\w.-]+)/g;function P(e){const t=[];let r=0,n;for(N.lastIndex=0;(n=N.exec(e))!==null;)t.push(e.slice(r,n.index)),t.push({type:"reference",name:n[1]}),r=N.lastIndex;return t.push(e.slice(r)),t}function te(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 ne(e,t,r){if(!te(e,t,r))throw new Error(`[styleframe] Variable "${e}" is not defined. Check that the variable exists before referencing it with "@${e}".`)}function C(e,t){return function(n){if(typeof n!="string"||!n.includes("@"))return n;if(x(n)&&/^@[\w.-]+$/.test(n)){const i=n.slice(1);return ne(i,e,t),{type:"reference",name:i}}const s=P(n);return s.some(i=>v(i))?{type:"css",value:s}:n}}function B(e,t){return function(n,s){const c=C(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 re(e,t){const r=B(e,t);return function(s,...c){return{type:"css",value:s.reduce((a,o,f)=>{if(a.push(...P(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 Ue(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Ke(e){return`.${e.replace(/[[\].#()%,:/]/g,"\\$&")}`}function k(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 ie(e){if(e=e||{},e.circular)return Ne(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]=k(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]=k(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]=k(f):a[o]=c(f)}return a}}function Ne(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]=k(h);else{const p=t.indexOf(h);p!==-1?l[m]=r[p]: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]=k(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]=k(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=ie();function j(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 Pe(e,t){const r=e.variables.find(n=>n.name===t);if(!r)throw new Error(`Variable "${t}" not found`);return r}function Be(e,t){const r=e.utilities.find(n=>n.name===t);if(!r)throw new Error(`Utility "${t}" not found`);return r}function se(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(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)=>E(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&&E(e.fallback,t.fallback);if(T(e)&&T(t))return E(e.value,t.value)}return!1}const ce="__licenseRequired";function Ie(e){I(e)||Object.defineProperty(e,ce,{value:!0,writable:!1,configurable:!1,enumerable:!0})}function I(e){return Object.prototype.hasOwnProperty.call(e,ce)}function oe(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 ae(e,t){const r=[...e];for(const n of t){const s=r.find(c=>c.name===n.name);s?Object.assign(s,D(s,n)):r.push(n)}return r}function D(e,t){return Object.keys(e).reduce((r,n)=>(n==="variables"?r.variables=oe(e.variables,t.variables):n==="declarations"?r.declarations={...e.declarations,...t.declarations}:n==="themes"&&F(r)&&F(e)&&F(t)?r.themes=ae(e.themes,t.themes):Array.isArray(e[n])&&(r[n]=e[n].concat(t[n])),r),{...e,...t})}function W(e,t){for(const r of e)"id"in r&&typeof r.id=="string"&&(t._registry.set(r.id,r),"children"in r&&W(r.children,t))}function fe(e){e._registry=new Map,e._registry.set(e.id,e),W(e.children,e);for(const t of e.themes)e._registry.set(t.id,t),W(t.children,e)}function De(e,...t){return t.reduce((r,n)=>{const s={...r,root:D(r.root,n.root)};return fe(s.root),(I(r)||I(n))&&Ie(s),s},e)}function O(e,t){return function(n,s,c){const i={type:"at-rule",id:j("ar-"),parentId:e.id,identifier:n,rule:s,declarations:{},variables:[],children:[]};t._registry.set(i.id,i);const a=R(i,t);return typeof c=="function"?i.declarations=c(a)??{}:c&&(i.declarations=c),$(i.declarations,a,i,t),e.children.push(i),i}}function ue(e,t){const r=O(e,t);return function(s,c){return r("media",s,c)}}function le(e,t){const r=O(e,t);return function(s,c){return r("keyframes",s,c)}}function de(e,t){return function(n,s){const c={type:"selector",id:j("sel-"),parentId:e.id,query:n,declarations:{},variables:[],children:[]};t._registry.set(c.id,c);const i=R(c,t);return typeof s=="function"?c.declarations=s(i)??{}:Q(s)?(c.variables=s.variables,c.declarations=s.declarations,c.children=s.children):c.declarations=s,$(c.declarations,i,c,t),e.children.push(c),c}}function ye(e,t){return function(n,s,c={default:!1}){const i=typeof n=="string"?n:n.name,o=C(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:j("var-"),parentId:e.id,name:i,value:o};return e.variables.push(d),d}}function R(e,t){const r=ye(e,t),n=de(e,t),s=O(e,t),c=le(t,t),i=ue(e,t),a=B(t,t),o=re(t,t);return{variable:r,selector:n,keyframes:c,atRule:s,media:i,ref:a,css:o}}function $(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=C(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 me(e){const t=[];function r(n,s){s.length>0&&t.push([...s].sort());for(let c=n;c<e.length;c++){const i=e[c];if(i)if(i.length===1&&i[0])r(c+1,[...s,i[0]]);else for(const a of i)r(c+1,[...s,a])}}return r(0,[]),t.sort((n,s)=>n.length!==s.length?n.length-s.length:n.join(",").localeCompare(s.join(",")))}function he(e,t,r){const n={...e,id:j("ut-"),parentId:e.parentId,declarations:{...e.declarations},variables:[...e.variables],children:[...e.children],modifiers:[...r.keys()]};t._registry.set(n.id,n);const s=R(n,t);if(r.size>0){const c=M(e.declarations);let i=!1;for(const a of r.values()){const o=a.factory({...s,declarations:M(c),variables:M(n.variables),children:M(n.children)});o&&(i||(n.declarations={},i=!0),Object.assign(n.declarations,o),$(n.declarations,s,n,t))}}return n}function ge(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 pe(){const e={type:"root",id:j("rt-"),declarations:{},utilities:[],modifiers:[],recipes:[],variables:[],children:[],themes:[],_registry:new Map};return e._registry.set(e.id,e),e}function We(e,t){const r=K({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 be(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)?We(c.namespace,t):K(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 b=y.slice(1);!Array.isArray(d)&&b in d&&(m=d[b])}if(a.namespace&&v(y))if(t.variables.some(b=>b.name===y.name))m=y;else{const b=Array.isArray(a.namespace)?a.namespace:[a.namespace];let z=!1;for(const G of b){const A=`${G}.${l}`;if(A!==y.name&&t.variables.some(w=>w.name===A)){m={type:"reference",name:A},z=!0;break}}z||(m=l)}const h=a.values.find(b=>b.key===l&&b.modifiers.length===0),p={type:"utility",id:j("ut-"),parentId:e.id,name:n,value:l,declarations:{},variables:[],children:[],modifiers:[]};t._registry.set(p.id,p);const Fe=R(p,t);if(p.declarations=s({...Fe,value:m})??{},$(p.declarations,Fe,p,t),h||(a.values.push({key:l,value:m,modifiers:[]}),e.children.push(p)),f&&f.length>0){const b=f.map(A=>A.key),G=me(b).filter(A=>!a.values.find(w=>w.key===l&&w.modifiers.length===A.length&&w.modifiers.every(_=>A.includes(_)))).reduce((A,w)=>{const _=new Map;for(const Me of w){const X=f.find(Le=>Le.key.includes(Me));X&&Z(X)&&_.set(Me,X)}return a.values.push({key:l,value:m,modifiers:w}),A.push(he(p,t,_)),A},[]);e.children.push(...G)}}}};return t.utilities.push(a),a.create}}function Ae(e,t){return function(n,s){const c=t.themes.find(o=>o.name===n),i=c??{type:"theme",id:j("th-"),parentId:t.id,name:n,declarations:{},variables:[],children:[]};c||(t._registry.set(i.id,i),t.themes.push(i));const a=R(i,t);return s&&s(a),i}}function Ve(e,t){return function(n){const s={type:"recipe",...n};return s._runtime=ve(s,t),ke(s,t),t.recipes.push(s),s}}function je(e,t){const r=e.autogenerate(t);return Object.keys(r)[0]??"default"}function H(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]=je(o,a)}r[Re(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]=je(c,s)}return r}function ve(e,t){const r={};if(e.base&&(r.base=H(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]=H(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:H(n.css,t)}))),r}function we(e){return!v(e)&&typeof e=="object"&&e!==null}function Re(e){return e.startsWith("&::")?e.slice(3):e.startsWith("&:")?e.slice(2):e}function L(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=Re(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 ke(e,t){const r=new Map;if(e.base&&L(e.base,r),e.variants)for(const s of Object.values(e.variants))for(const c of Object.values(s))L(c,r);if(e.compoundVariants)for(const s of e.compoundVariants)s.css&&L(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,se(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:void 0)}}}function He(e){const t=j("sf-"),r=pe(),n={...e},s=be(r,r),c=ge(r,r),i=Ve(r,r),a=Ae(r,r),{variable:o,selector:f,atRule:d,keyframes:l,media:y,ref:m,css:h}=R(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=he,u.capitalizeFirst=Ue,u.classNameToCssSelector=Ke,u.combineKeys=me,u.createAtRuleFunction=O,u.createCssFunction=re,u.createDeclarationsCallbackContext=R,u.createKeyframesFunction=le,u.createMediaFunction=ue,u.createModifierFunction=ge,u.createPropertyValueResolver=C,u.createRecipeFunction=Ve,u.createRefFunction=B,u.createRoot=pe,u.createSelectorFunction=de,u.createThemeFunction=Ae,u.createUtilityFunction=be,u.createVariableFunction=ye,u.deepClone=M,u.defaultUtilitySelectorFn=_e,u.findVariableInScope=te,u.generateRandomId=j,u.generateRecipeRuntime=ve,u.getModifier=se,u.getUtility=Be,u.getVariable=Pe,u.hashValue=ee,u.isAtRule=Y,u.isCSS=T,u.isContainer=Ee,u.isContainerInput=Q,u.isKeyReferenceValue=x,u.isModifier=Z,u.isObject=V,u.isPrimitiveTokenValue=J,u.isRecipe=Ce,u.isRef=v,u.isRoot=F,u.isSelector=$e,u.isStyleframe=Oe,u.isTheme=Se,u.isToken=g,u.isTokenEqual=E,u.isTokenValue=S,u.isUtility=Te,u.isVariable=U,u.merge=De,u.mergeContainers=D,u.mergeThemesArray=ae,u.mergeVariablesArray=oe,u.parseAtReferences=P,u.parseDeclarationsBlock=$,u.processRecipeUtilities=ke,u.rebuildRegistry=fe,u.rfdc=ie,u.styleframe=He,u.transformUtilityKey=K,u.validateReference=ne,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 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"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@styleframe/core",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "type": "module",
5
5
  "types": "./dist/styleframe.d.ts",
6
6
  "module": "./dist/styleframe.js",