@styleframe/core 2.6.0 → 3.0.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,18 @@
1
1
  # @styleframe/core
2
2
 
3
+ ## 3.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#117](https://github.com/styleframe-dev/styleframe/pull/117) [`ffe6764`](https://github.com/styleframe-dev/styleframe/commit/ffe6764a2e6c84d5b3cfdf431bf11f17a3f3f118) Thanks [@alexgrozav](https://github.com/alexgrozav)! - Introduce global Styleframe single-instance architecture. Extension files (`*.styleframe.ts`) now share the same instance created in `styleframe.config.ts` instead of creating independent instances. This is a breaking change that affects how styles are imported and composed across files.
8
+
9
+ ### Minor Changes
10
+
11
+ - [#81](https://github.com/styleframe-dev/styleframe/pull/81) [`266f961`](https://github.com/styleframe-dev/styleframe/commit/266f96143e9ffb47e0e6326d0e5e7cc9d974ab83) Thanks [@alexgrozav](https://github.com/alexgrozav)! - Add @-prefixed string reference shorthand and fix keyframes object API
12
+ - Add `@`-prefixed string reference shorthand for inline token references in declarations (e.g., `"@color.primary"`)
13
+ - Fix keyframes object API outputting `[object Object]` by parsing percentage, `from`, and `to` keys as nested selectors
14
+ - Prevent namespace double-prepending for `@`-prefixed values in utilities and defaults
15
+
3
16
  ## 2.6.0
4
17
 
5
18
  ### Minor Changes
@@ -222,6 +222,7 @@ export declare function createThemeFunction(_parent: Container, root: Root): (na
222
222
 
223
223
  export declare function createUtilityFunction(parent: Container, root: Root): <Name extends string>(name: Name, factory: UtilityCallbackFn, options?: {
224
224
  autogenerate?: UtilityAutogenerateFn;
225
+ namespace?: string | string[];
225
226
  }) => UtilityCreatorFn;
226
227
 
227
228
  export declare function createVariableFunction(parent: Container, _root: Root): <Name extends string>(nameOrInstance: Name | Variable<Name>, value: TokenValue, options?: {
@@ -301,6 +302,8 @@ export declare function isRoot(value: unknown): value is Root;
301
302
 
302
303
  export declare function isSelector(value: unknown): value is Selector;
303
304
 
305
+ export declare function isStyleframe(value: unknown): value is Styleframe;
306
+
304
307
  export declare function isTheme(value: unknown): value is Theme;
305
308
 
306
309
  /**
@@ -499,7 +502,14 @@ export declare type TokenType = Variable["type"] | Reference["type"] | Selector[
499
502
 
500
503
  export declare type TokenValue = PrimitiveTokenValue | Reference | CSS_2 | Array<PrimitiveTokenValue | Reference | CSS_2>;
501
504
 
502
- export declare function transformUtilityKey(replacer?: (key: string) => string): (value: TokenValue) => Record<string, TokenValue>;
505
+ export declare function transformUtilityKey(replacerOrOptions?: ((key: string) => string) | TransformUtilityKeyOptions): (value: TokenValue) => Record<string, TokenValue>;
506
+
507
+ export declare interface TransformUtilityKeyOptions {
508
+ /** Transforms the key used in the utility class name */
509
+ replacer?: (key: string) => string;
510
+ /** Namespace prepended to the reference name (e.g., "spacing" makes "@sm" resolve to ref("spacing.sm")) */
511
+ namespace?: string | string[];
512
+ }
503
513
 
504
514
  export declare type Utility<Name extends string = string> = {
505
515
  type: "utility";
@@ -529,6 +539,7 @@ export declare type UtilityFactory<Name extends string = string> = {
529
539
  modifiers: string[];
530
540
  }>;
531
541
  autogenerate: UtilityAutogenerateFn;
542
+ namespace?: string | string[];
532
543
  create: UtilityCreatorFn;
533
544
  };
534
545
 
@@ -1,99 +1,115 @@
1
- function S(e) {
1
+ function C(e) {
2
2
  return typeof e == "object" && e !== null;
3
3
  }
4
- function p(e, r) {
5
- return S(e) && "type" in e && e.type === r;
4
+ function h(e, r) {
5
+ return C(e) && "type" in e && e.type === r;
6
6
  }
7
- function L(e) {
8
- return p(e, "variable");
9
- }
10
- function A(e) {
11
- return p(e, "reference");
7
+ function G(e) {
8
+ return h(e, "variable");
12
9
  }
13
- function be(e) {
14
- return p(e, "selector");
10
+ function j(e) {
11
+ return h(e, "reference");
15
12
  }
16
- function ge(e) {
17
- return p(e, "at-rule");
13
+ function Ae(e) {
14
+ return h(e, "selector");
18
15
  }
19
16
  function je(e) {
20
- return p(e, "utility");
17
+ return h(e, "at-rule");
21
18
  }
22
- function q(e) {
23
- return p(e, "modifier");
19
+ function ve(e) {
20
+ return h(e, "utility");
24
21
  }
25
- function E(e) {
26
- return p(e, "css");
22
+ function I(e) {
23
+ return h(e, "modifier");
27
24
  }
28
- function ve(e) {
29
- return p(e, "theme");
25
+ function T(e) {
26
+ return h(e, "css");
30
27
  }
31
- function O(e) {
32
- return p(e, "root");
28
+ function we(e) {
29
+ return h(e, "theme");
33
30
  }
34
- function Ae(e) {
35
- return p(e, "recipe");
31
+ function V(e) {
32
+ return h(e, "root");
36
33
  }
37
- function G(e) {
34
+ function ke(e) {
35
+ return h(e, "recipe");
36
+ }
37
+ function z(e) {
38
38
  return typeof e == "string" || typeof e == "number" || typeof e == "boolean" || e === null;
39
39
  }
40
- function $(e) {
41
- return G(e) || A(e) || E(e) || Array.isArray(e) && e.every($);
40
+ function D(e) {
41
+ return z(e) || j(e) || T(e) || Array.isArray(e) && e.every(D);
42
42
  }
43
- function I(e) {
44
- return S(e) && "children" in e && "declarations" in e && "variables" in e;
45
- }
46
- function z(e = (r) => r) {
47
- return (r) => {
48
- let n = r, t;
49
- if (typeof n == "string" && n[0] === "@") {
50
- const i = n.slice(1);
51
- t = e(i), n = {
43
+ function Y(e) {
44
+ return C(e) && "children" in e && "declarations" in e && "variables" in e;
45
+ }
46
+ function Ve(e) {
47
+ return C(e) && "id" in e && "root" in e && "variable" in e && "selector" in e && "recipe" in e && typeof e.id == "string" && V(e.root);
48
+ }
49
+ function P(e) {
50
+ const r = typeof e == "function" ? { replacer: e } : e ?? {}, { replacer: n = (c) => c, namespace: t } = r, i = Array.isArray(t) ? t : t ? [t] : [];
51
+ return (c) => {
52
+ let s = c, a;
53
+ if (typeof s == "string" && s[0] === "@") {
54
+ const o = s.slice(1), f = i.find(
55
+ (y) => o === y || o.startsWith(`${y}.`)
56
+ );
57
+ let l, u;
58
+ f ? (l = o, u = o.startsWith(`${f}.`) ? o.slice(f.length + 1) : o) : i.length > 0 ? (l = `${i[0]}.${o}`, u = o) : (l = o, u = o), a = n(u), s = {
52
59
  type: "reference",
53
- name: i
60
+ name: l
54
61
  };
55
- } else A(n) ? t = e(n.name) : t = `[${r}]`;
62
+ } else if (j(s)) {
63
+ let o = s.name;
64
+ for (const f of i)
65
+ if (o.startsWith(`${f}.`)) {
66
+ o = o.slice(f.length + 1);
67
+ break;
68
+ }
69
+ a = n(o);
70
+ } else
71
+ a = `[${c}]`;
56
72
  return {
57
- [t]: n
73
+ [a]: s
58
74
  };
59
75
  };
60
76
  }
61
- function W(e, r) {
77
+ function Z(e, r) {
62
78
  return function(t, ...i) {
63
79
  return {
64
80
  type: "css",
65
- value: t.reduce((o, u, s) => (o.push(u), s < i.length && o.push(i[s]), o), [])
81
+ value: t.reduce((s, a, o) => (s.push(a), o < i.length && s.push(i[o]), s), [])
66
82
  };
67
83
  };
68
84
  }
69
- function C(e, r) {
85
+ function K(e, r) {
70
86
  return function(t, i, c) {
71
- const o = {
87
+ const s = {
72
88
  type: "at-rule",
73
89
  identifier: t,
74
90
  rule: i,
75
91
  declarations: {},
76
92
  variables: [],
77
93
  children: []
78
- }, u = v(o, r);
79
- return typeof c == "function" ? o.declarations = c(u) ?? {} : c && (o.declarations = c), V(o.declarations, u), e.children.push(o), o;
94
+ }, a = v(s, r);
95
+ return typeof c == "function" ? s.declarations = c(a) ?? {} : c && (s.declarations = c), R(s.declarations, a), e.children.push(s), s;
80
96
  };
81
97
  }
82
- function Y(e, r) {
83
- const n = C(e, r);
98
+ function J(e, r) {
99
+ const n = K(e, r);
84
100
  return function(i, c) {
85
101
  return n("media", i, c);
86
102
  };
87
103
  }
88
- function Z(e, r) {
89
- const n = C(e, r);
104
+ function Q(e, r) {
105
+ const n = K(e, r);
90
106
  return function(i, c) {
91
107
  return n("keyframes", i, c);
92
108
  };
93
109
  }
94
- function J(e, r) {
110
+ function X(e, r) {
95
111
  return function(t, i) {
96
- return L(t) ? {
112
+ return G(t) ? {
97
113
  type: "reference",
98
114
  name: t.name,
99
115
  fallback: i
@@ -104,7 +120,7 @@ function J(e, r) {
104
120
  };
105
121
  };
106
122
  }
107
- function Q(e, r) {
123
+ function ee(e, r) {
108
124
  return function(t, i) {
109
125
  const c = {
110
126
  type: "selector",
@@ -112,59 +128,63 @@ function Q(e, r) {
112
128
  declarations: {},
113
129
  variables: [],
114
130
  children: []
115
- }, o = v(c, r);
116
- return typeof i == "function" ? c.declarations = i(o) ?? {} : I(i) ? (c.variables = i.variables, c.declarations = i.declarations, c.children = i.children) : c.declarations = i, V(c.declarations, o), e.children.push(c), c;
131
+ }, s = v(c, r);
132
+ return typeof i == "function" ? c.declarations = i(s) ?? {} : Y(i) ? (c.variables = i.variables, c.declarations = i.declarations, c.children = i.children) : c.declarations = i, R(c.declarations, s), e.children.push(c), c;
117
133
  };
118
134
  }
119
- function X(e, r) {
135
+ function te(e, r) {
120
136
  return function(t, i, c = {
121
137
  default: !1
122
138
  }) {
123
- const o = typeof t == "string" ? t : t.name, u = e.variables.find(
124
- (f) => f.name === o
139
+ const s = typeof t == "string" ? t : t.name, a = e.variables.find(
140
+ (f) => f.name === s
125
141
  );
126
- if (c.default && u)
127
- return u;
128
- if (u)
129
- return u.value = i, u;
130
- const s = {
142
+ if (c.default && a)
143
+ return a;
144
+ if (a)
145
+ return a.value = i, a;
146
+ const o = {
131
147
  type: "variable",
132
- name: o,
148
+ name: s,
133
149
  value: i
134
150
  };
135
- return e.variables.push(s), s;
151
+ return e.variables.push(o), o;
136
152
  };
137
153
  }
138
154
  function v(e, r) {
139
- const n = X(e), t = Q(e, r), i = C(e, r), c = Z(r, r), o = Y(e, r), u = J(), s = W();
155
+ const n = te(e), t = ee(e, r), i = K(e, r), c = Q(r, r), s = J(e, r), a = X(), o = Z();
140
156
  return {
141
157
  variable: n,
142
158
  selector: t,
143
159
  keyframes: c,
144
160
  atRule: i,
145
- media: o,
146
- ref: u,
147
- css: s
161
+ media: s,
162
+ ref: a,
163
+ css: o
148
164
  };
149
165
  }
150
- function V(e, r) {
166
+ function R(e, r) {
151
167
  for (const n in e)
152
168
  if (n.startsWith("@")) {
153
169
  const t = e[n];
154
- if (typeof t == "object" && t !== null && !$(t)) {
170
+ if (typeof t == "object" && t !== null && !D(t)) {
155
171
  const i = n.replace(/^@(\w+).*/, "$1"), c = n.replace(`@${i}`, "").trim();
156
172
  r.atRule(i, c, t), delete e[n];
157
173
  }
158
- } else if (/^[.&:]/.test(n)) {
174
+ } else if (/^[.&:]/.test(n) || /^\d+%$/.test(n) || n === "from" || n === "to") {
159
175
  const t = e[n];
160
176
  typeof t == "object" && (r.selector(n, t), delete e[n]);
161
177
  }
178
+ for (const n in e) {
179
+ const t = e[n];
180
+ typeof t == "string" && t[0] === "@" && (e[n] = r.ref(t.slice(1)));
181
+ }
162
182
  return e;
163
183
  }
164
- function we(e) {
184
+ function Re(e) {
165
185
  return e.charAt(0).toUpperCase() + e.slice(1);
166
186
  }
167
- function j(e) {
187
+ function A(e) {
168
188
  if (e instanceof Buffer)
169
189
  return Buffer.from(e);
170
190
  const r = e.constructor;
@@ -174,133 +194,133 @@ function j(e) {
174
194
  e.byteLength / e.BYTES_PER_ELEMENT || 1
175
195
  );
176
196
  }
177
- function ee(e) {
197
+ function ne(e) {
178
198
  if (e = e || {}, e.circular)
179
- return te(e);
199
+ return re(e);
180
200
  const r = /* @__PURE__ */ new Map();
181
- if (r.set(Date, (o) => new Date(o)), r.set(
201
+ if (r.set(Date, (s) => new Date(s)), r.set(
182
202
  Map,
183
- (o, u) => new Map(t(Array.from(o), u))
203
+ (s, a) => new Map(t(Array.from(s), a))
184
204
  ), r.set(
185
205
  Set,
186
- (o, u) => new Set(t(Array.from(o), u))
206
+ (s, a) => new Set(t(Array.from(s), a))
187
207
  ), e.constructorHandlers)
188
- for (const o of e.constructorHandlers)
189
- r.set(o[0], o[1]);
208
+ for (const s of e.constructorHandlers)
209
+ r.set(s[0], s[1]);
190
210
  let n;
191
211
  return e.proto ? c : i;
192
- function t(o, u) {
193
- const s = Object.keys(o), f = Array.from({ length: s.length });
194
- for (let l = 0; l < s.length; l++) {
195
- const a = s[l], y = o[a];
196
- typeof y != "object" || y === null ? f[a] = y : y.constructor !== Object && (n = r.get(y.constructor)) ? f[a] = n(y, u) : ArrayBuffer.isView(y) ? f[a] = j(y) : f[a] = u(y);
212
+ function t(s, a) {
213
+ const o = Object.keys(s), f = Array.from({ length: o.length });
214
+ for (let l = 0; l < o.length; l++) {
215
+ const u = o[l], y = s[u];
216
+ typeof y != "object" || y === null ? f[u] = y : y.constructor !== Object && (n = r.get(y.constructor)) ? f[u] = n(y, a) : ArrayBuffer.isView(y) ? f[u] = A(y) : f[u] = a(y);
197
217
  }
198
218
  return f;
199
219
  }
200
- function i(o) {
201
- if (typeof o != "object" || o === null) return o;
202
- if (Array.isArray(o)) return t(o, i);
203
- if (o.constructor !== Object && (n = r.get(o.constructor)))
204
- return n(o, i);
205
- const u = {};
206
- for (const s in o) {
207
- if (Object.hasOwnProperty.call(o, s) === !1) continue;
208
- const f = o[s];
209
- typeof f != "object" || f === null ? u[s] = f : f.constructor !== Object && (n = r.get(f.constructor)) ? u[s] = n(f, i) : ArrayBuffer.isView(f) ? u[s] = j(f) : u[s] = i(f);
220
+ function i(s) {
221
+ if (typeof s != "object" || s === null) return s;
222
+ if (Array.isArray(s)) return t(s, i);
223
+ if (s.constructor !== Object && (n = r.get(s.constructor)))
224
+ return n(s, i);
225
+ const a = {};
226
+ for (const o in s) {
227
+ if (Object.hasOwnProperty.call(s, o) === !1) continue;
228
+ const f = s[o];
229
+ typeof f != "object" || f === null ? a[o] = f : f.constructor !== Object && (n = r.get(f.constructor)) ? a[o] = n(f, i) : ArrayBuffer.isView(f) ? a[o] = A(f) : a[o] = i(f);
210
230
  }
211
- return u;
231
+ return a;
212
232
  }
213
- function c(o) {
214
- if (typeof o != "object" || o === null) return o;
215
- if (Array.isArray(o)) return t(o, c);
216
- if (o.constructor !== Object && (n = r.get(o.constructor)))
217
- return n(o, c);
218
- const u = {};
219
- for (const s in o) {
220
- const f = o[s];
221
- typeof f != "object" || f === null ? u[s] = f : f.constructor !== Object && (n = r.get(f.constructor)) ? u[s] = n(f, c) : ArrayBuffer.isView(f) ? u[s] = j(f) : u[s] = c(f);
233
+ function c(s) {
234
+ if (typeof s != "object" || s === null) return s;
235
+ if (Array.isArray(s)) return t(s, c);
236
+ if (s.constructor !== Object && (n = r.get(s.constructor)))
237
+ return n(s, c);
238
+ const a = {};
239
+ for (const o in s) {
240
+ const f = s[o];
241
+ typeof f != "object" || f === null ? a[o] = f : f.constructor !== Object && (n = r.get(f.constructor)) ? a[o] = n(f, c) : ArrayBuffer.isView(f) ? a[o] = A(f) : a[o] = c(f);
222
242
  }
223
- return u;
243
+ return a;
224
244
  }
225
245
  }
226
- function te(e) {
246
+ function re(e) {
227
247
  const r = [], n = [], t = /* @__PURE__ */ new Map();
228
- if (t.set(Date, (s) => new Date(s)), t.set(
248
+ if (t.set(Date, (o) => new Date(o)), t.set(
229
249
  Map,
230
- (s, f) => new Map(c(Array.from(s), f))
250
+ (o, f) => new Map(c(Array.from(o), f))
231
251
  ), t.set(
232
252
  Set,
233
- (s, f) => new Set(c(Array.from(s), f))
253
+ (o, f) => new Set(c(Array.from(o), f))
234
254
  ), e.constructorHandlers)
235
- for (const s of e.constructorHandlers)
236
- t.set(s[0], s[1]);
255
+ for (const o of e.constructorHandlers)
256
+ t.set(o[0], o[1]);
237
257
  let i;
238
- return e.proto ? u : o;
239
- function c(s, f) {
240
- const l = Object.keys(s), a = Array.from({ length: l.length });
258
+ return e.proto ? a : s;
259
+ function c(o, f) {
260
+ const l = Object.keys(o), u = Array.from({ length: l.length });
241
261
  for (let y = 0; y < l.length; y++) {
242
- const m = l[y], d = s[m];
262
+ const p = l[y], d = o[p];
243
263
  if (typeof d != "object" || d === null)
244
- a[m] = d;
264
+ u[p] = d;
245
265
  else if (d.constructor !== Object && (i = t.get(d.constructor)))
246
- a[m] = i(d, f);
266
+ u[p] = i(d, f);
247
267
  else if (ArrayBuffer.isView(d))
248
- a[m] = j(d);
268
+ u[p] = A(d);
249
269
  else {
250
- const h = r.indexOf(d);
251
- h !== -1 ? a[m] = n[h] : a[m] = f(d);
270
+ const w = r.indexOf(d);
271
+ w !== -1 ? u[p] = n[w] : u[p] = f(d);
252
272
  }
253
273
  }
254
- return a;
274
+ return u;
255
275
  }
256
- function o(s) {
257
- if (typeof s != "object" || s === null) return s;
258
- if (Array.isArray(s)) return c(s, o);
259
- if (s.constructor !== Object && (i = t.get(s.constructor)))
260
- return i(s, o);
276
+ function s(o) {
277
+ if (typeof o != "object" || o === null) return o;
278
+ if (Array.isArray(o)) return c(o, s);
279
+ if (o.constructor !== Object && (i = t.get(o.constructor)))
280
+ return i(o, s);
261
281
  const f = {};
262
- r.push(s), n.push(f);
263
- for (const l in s) {
264
- if (Object.hasOwnProperty.call(s, l) === !1) continue;
265
- const a = s[l];
266
- if (typeof a != "object" || a === null)
267
- f[l] = a;
268
- else if (a.constructor !== Object && (i = t.get(a.constructor)))
269
- f[l] = i(a, o);
270
- else if (ArrayBuffer.isView(a))
271
- f[l] = j(a);
282
+ r.push(o), n.push(f);
283
+ for (const l in o) {
284
+ if (Object.hasOwnProperty.call(o, l) === !1) continue;
285
+ const u = o[l];
286
+ if (typeof u != "object" || u === null)
287
+ f[l] = u;
288
+ else if (u.constructor !== Object && (i = t.get(u.constructor)))
289
+ f[l] = i(u, s);
290
+ else if (ArrayBuffer.isView(u))
291
+ f[l] = A(u);
272
292
  else {
273
- const y = r.indexOf(a);
274
- y !== -1 ? f[l] = n[y] : f[l] = o(a);
293
+ const y = r.indexOf(u);
294
+ y !== -1 ? f[l] = n[y] : f[l] = s(u);
275
295
  }
276
296
  }
277
297
  return r.pop(), n.pop(), f;
278
298
  }
279
- function u(s) {
280
- if (typeof s != "object" || s === null) return s;
281
- if (Array.isArray(s)) return c(s, u);
282
- if (s.constructor !== Object && (i = t.get(s.constructor)))
283
- return i(s, u);
299
+ function a(o) {
300
+ if (typeof o != "object" || o === null) return o;
301
+ if (Array.isArray(o)) return c(o, a);
302
+ if (o.constructor !== Object && (i = t.get(o.constructor)))
303
+ return i(o, a);
284
304
  const f = {};
285
- r.push(s), n.push(f);
286
- for (const l in s) {
287
- const a = s[l];
288
- if (typeof a != "object" || a === null)
289
- f[l] = a;
290
- else if (a.constructor !== Object && (i = t.get(a.constructor)))
291
- f[l] = i(a, u);
292
- else if (ArrayBuffer.isView(a))
293
- f[l] = j(a);
305
+ r.push(o), n.push(f);
306
+ for (const l in o) {
307
+ const u = o[l];
308
+ if (typeof u != "object" || u === null)
309
+ f[l] = u;
310
+ else if (u.constructor !== Object && (i = t.get(u.constructor)))
311
+ f[l] = i(u, a);
312
+ else if (ArrayBuffer.isView(u))
313
+ f[l] = A(u);
294
314
  else {
295
- const y = r.indexOf(a);
296
- y !== -1 ? f[l] = n[y] : f[l] = u(a);
315
+ const y = r.indexOf(u);
316
+ y !== -1 ? f[l] = n[y] : f[l] = a(u);
297
317
  }
298
318
  }
299
319
  return r.pop(), n.pop(), f;
300
320
  }
301
321
  }
302
- const R = ee();
303
- function ne(e, r = 8) {
322
+ const F = ne();
323
+ function ie(e, r = 8) {
304
324
  const n = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
305
325
  let t = "";
306
326
  for (let i = 0; i < r; i++) {
@@ -309,19 +329,19 @@ function ne(e, r = 8) {
309
329
  }
310
330
  return e ? `${e}${t}` : t;
311
331
  }
312
- function Ve(e, r) {
332
+ function $e(e, r) {
313
333
  const n = e.variables.find((t) => t.name === r);
314
334
  if (!n)
315
335
  throw new Error(`Variable "${r}" not found`);
316
336
  return n;
317
337
  }
318
- function ke(e, r) {
338
+ function Oe(e, r) {
319
339
  const n = e.utilities.find((t) => t.name === r);
320
340
  if (!n)
321
341
  throw new Error(`Utility "${r}" not found`);
322
342
  return n;
323
343
  }
324
- function re(e, r) {
344
+ function se(e, r) {
325
345
  const n = e.modifiers.find(
326
346
  (t) => t.key.includes(r)
327
347
  );
@@ -329,25 +349,25 @@ function re(e, r) {
329
349
  throw new Error(`Modifier "${r}" not found`);
330
350
  return n;
331
351
  }
332
- function M(e, r) {
352
+ function N(e, r) {
333
353
  if (e === r) return !0;
334
354
  if (typeof e != typeof r) return !1;
335
355
  if (e === null || r === null) return e === r;
336
356
  if (typeof e != "object" || typeof r != "object") return !1;
337
357
  if (Array.isArray(e) && Array.isArray(r))
338
- return e.length !== r.length ? !1 : e.every((n, t) => M(n, r[t]));
358
+ return e.length !== r.length ? !1 : e.every((n, t) => N(n, r[t]));
339
359
  if ("type" in e && "type" in r) {
340
360
  if (e.type !== r.type) return !1;
341
- if (A(e) && A(r))
342
- return e.name === r.name && M(e.fallback, r.fallback);
343
- if (E(e) && E(r))
344
- return M(e.value, r.value);
361
+ if (j(e) && j(r))
362
+ return e.name === r.name && N(e.fallback, r.fallback);
363
+ if (T(e) && T(r))
364
+ return N(e.value, r.value);
345
365
  }
346
366
  return !1;
347
367
  }
348
- const D = "__licenseRequired";
349
- function ie(e) {
350
- B(e) || Object.defineProperty(e, D, {
368
+ const H = "__licenseRequired";
369
+ function oe(e) {
370
+ B(e) || Object.defineProperty(e, H, {
351
371
  value: !0,
352
372
  writable: !1,
353
373
  configurable: !1,
@@ -355,9 +375,9 @@ function ie(e) {
355
375
  });
356
376
  }
357
377
  function B(e) {
358
- return Object.prototype.hasOwnProperty.call(e, D);
378
+ return Object.prototype.hasOwnProperty.call(e, H);
359
379
  }
360
- function oe(e, r) {
380
+ function ce(e, r) {
361
381
  const n = [...e];
362
382
  for (const t of r) {
363
383
  const i = n.find(
@@ -367,7 +387,7 @@ function oe(e, r) {
367
387
  }
368
388
  return n;
369
389
  }
370
- function se(e, r) {
390
+ function fe(e, r) {
371
391
  const n = [...e];
372
392
  for (const t of r) {
373
393
  const i = n.find(
@@ -375,14 +395,14 @@ function se(e, r) {
375
395
  );
376
396
  i ? Object.assign(
377
397
  i,
378
- U(i, t)
398
+ W(i, t)
379
399
  ) : n.push(t);
380
400
  }
381
401
  return n;
382
402
  }
383
- function U(e, r) {
403
+ function W(e, r) {
384
404
  return Object.keys(e).reduce(
385
- (n, t) => (t === "variables" ? n.variables = oe(e.variables, r.variables) : t === "declarations" ? n.declarations = { ...e.declarations, ...r.declarations } : t === "themes" && O(n) && O(e) && O(r) ? n.themes = se(e.themes, r.themes) : Array.isArray(e[t]) && (n[t] = e[t].concat(
405
+ (n, t) => (t === "variables" ? n.variables = ce(e.variables, r.variables) : t === "declarations" ? n.declarations = { ...e.declarations, ...r.declarations } : t === "themes" && V(n) && V(e) && V(r) ? n.themes = fe(e.themes, r.themes) : Array.isArray(e[t]) && (n[t] = e[t].concat(
386
406
  r[t]
387
407
  )), n),
388
408
  {
@@ -391,32 +411,32 @@ function U(e, r) {
391
411
  }
392
412
  );
393
413
  }
394
- function Oe(e, ...r) {
414
+ function Me(e, ...r) {
395
415
  return r.reduce((n, t) => {
396
416
  const i = {
397
417
  ...n,
398
- root: U(n.root, t.root)
418
+ root: W(n.root, t.root)
399
419
  };
400
- return (B(n) || B(t)) && ie(i), i;
420
+ return (B(n) || B(t)) && oe(i), i;
401
421
  }, e);
402
422
  }
403
- function ce(e) {
423
+ function ae(e) {
404
424
  const r = [];
405
425
  function n(t, i) {
406
426
  i.length > 0 && r.push([...i].sort());
407
427
  for (let c = t; c < e.length; c++) {
408
- const o = e[c];
409
- if (o)
410
- if (o.length === 1 && o[0])
411
- n(c + 1, [...i, o[0]]);
428
+ const s = e[c];
429
+ if (s)
430
+ if (s.length === 1 && s[0])
431
+ n(c + 1, [...i, s[0]]);
412
432
  else
413
- for (const u of o)
414
- n(c + 1, [...i, u]);
433
+ for (const a of s)
434
+ n(c + 1, [...i, a]);
415
435
  }
416
436
  }
417
437
  return n(0, []), r.sort((t, i) => t.length !== i.length ? t.length - i.length : t.join(",").localeCompare(i.join(",")));
418
438
  }
419
- function fe(e, r, n) {
439
+ function ue(e, r, n) {
420
440
  const t = {
421
441
  ...e,
422
442
  modifiers: [...n.keys()]
@@ -424,13 +444,13 @@ function fe(e, r, n) {
424
444
  for (const c of n.values())
425
445
  c.factory({
426
446
  ...i,
427
- declarations: R(t.declarations),
428
- variables: R(t.variables),
429
- children: R(t.children)
430
- }), V(t.declarations, i);
447
+ declarations: F(t.declarations),
448
+ variables: F(t.variables),
449
+ children: F(t.children)
450
+ }), R(t.declarations, i);
431
451
  return t;
432
452
  }
433
- function ue(e, r) {
453
+ function le(e, r) {
434
454
  return function(t, i) {
435
455
  const c = {
436
456
  type: "modifier",
@@ -440,7 +460,7 @@ function ue(e, r) {
440
460
  return r.modifiers.push(c), c;
441
461
  };
442
462
  }
443
- function ae() {
463
+ function ye() {
444
464
  return {
445
465
  type: "root",
446
466
  declarations: {},
@@ -452,30 +472,84 @@ function ae() {
452
472
  themes: []
453
473
  };
454
474
  }
455
- function le(e, r) {
475
+ function de(e, r) {
476
+ const n = P({ namespace: e });
477
+ return (t) => {
478
+ if (typeof t == "string" && t[0] === "@") {
479
+ const i = t.slice(1), c = e.find(
480
+ (s) => i === s || i.startsWith(`${s}.`)
481
+ );
482
+ if (c) {
483
+ const s = i.slice(c.length + 1) || i;
484
+ if (r.variables.some((a) => a.name === i))
485
+ return {
486
+ [s]: {
487
+ type: "reference",
488
+ name: i
489
+ }
490
+ };
491
+ } else
492
+ for (const s of e) {
493
+ const a = `${s}.${i}`;
494
+ if (r.variables.some((o) => o.name === a))
495
+ return {
496
+ [i]: {
497
+ type: "reference",
498
+ name: a
499
+ }
500
+ };
501
+ }
502
+ return n(t);
503
+ }
504
+ return n(t);
505
+ };
506
+ }
507
+ function me(e, r) {
456
508
  return function(t, i, c = {}) {
457
- const o = {
509
+ const s = {
458
510
  type: "utility",
459
511
  name: t,
460
512
  factory: i,
461
513
  values: [],
462
- autogenerate: c.autogenerate ?? z(),
463
- create: (u, s = []) => {
464
- let f = u;
465
- if (Array.isArray(u)) {
514
+ autogenerate: c.autogenerate ?? (Array.isArray(c.namespace) ? de(c.namespace, r) : P(
515
+ c.namespace ? { namespace: c.namespace } : void 0
516
+ )),
517
+ namespace: c.namespace,
518
+ create: (a, o = []) => {
519
+ let f = a;
520
+ if (Array.isArray(a)) {
466
521
  f = {};
467
- for (const l of u) {
468
- const a = o.autogenerate(l);
522
+ for (const l of a) {
523
+ const u = s.autogenerate(l);
469
524
  f = {
470
525
  ...f,
471
- ...a
526
+ ...u
472
527
  };
473
528
  }
474
529
  }
475
- for (const [l, a] of Object.entries(f)) {
476
- const y = o.values.find(
477
- (h) => h.key === l && h.modifiers.length === 0
478
- ), m = {
530
+ for (const [l, u] of Object.entries(f)) {
531
+ let y = u;
532
+ if (s.namespace && j(u))
533
+ if (r.variables.some((g) => g.name === u.name))
534
+ y = u;
535
+ else {
536
+ const g = Array.isArray(s.namespace) ? s.namespace : [s.namespace];
537
+ let $ = !1;
538
+ for (const O of g) {
539
+ const m = `${O}.${l}`;
540
+ if (m !== u.name && r.variables.some((b) => b.name === m)) {
541
+ y = {
542
+ type: "reference",
543
+ name: m
544
+ }, $ = !0;
545
+ break;
546
+ }
547
+ }
548
+ $ || (y = l);
549
+ }
550
+ const p = s.values.find(
551
+ (g) => g.key === l && g.modifiers.length === 0
552
+ ), d = {
479
553
  type: "utility",
480
554
  name: t,
481
555
  value: l,
@@ -483,242 +557,247 @@ function le(e, r) {
483
557
  variables: [],
484
558
  children: [],
485
559
  modifiers: []
486
- }, d = v(
487
- m,
560
+ }, w = v(
561
+ d,
488
562
  r
489
563
  );
490
- if (m.declarations = i({
491
- ...d,
492
- value: a
493
- }) ?? {}, V(m.declarations, d), y || (o.values.push({
564
+ if (d.declarations = i({
565
+ ...w,
566
+ value: y
567
+ }) ?? {}, R(d.declarations, w), p || (s.values.push({
494
568
  key: l,
495
- value: a,
569
+ value: y,
496
570
  modifiers: []
497
- }), e.children.push(m)), s && s.length > 0) {
498
- const h = s.map((b) => b.key), H = ce(h).filter((b) => !o.values.find(
499
- (g) => g.key === l && g.modifiers.length === b.length && g.modifiers.every((w) => b.includes(w))
500
- )).reduce((b, g) => {
501
- const w = /* @__PURE__ */ new Map();
502
- for (const K of g) {
503
- const k = s.find(
504
- (N) => N.key.includes(K)
571
+ }), e.children.push(d)), o && o.length > 0) {
572
+ const g = o.map((m) => m.key), O = ae(g).filter((m) => !s.values.find(
573
+ (b) => b.key === l && b.modifiers.length === m.length && b.modifiers.every((k) => m.includes(k))
574
+ )).reduce((m, b) => {
575
+ const k = /* @__PURE__ */ new Map();
576
+ for (const U of b) {
577
+ const M = o.find(
578
+ (q) => q.key.includes(U)
505
579
  );
506
- k && q(k) && w.set(K, k);
580
+ M && I(M) && k.set(U, M);
507
581
  }
508
- return o.values.push({
582
+ return s.values.push({
509
583
  key: l,
510
- value: a,
511
- modifiers: g
512
- }), b.push(fe(m, r, w)), b;
584
+ value: y,
585
+ modifiers: b
586
+ }), m.push(ue(d, r, k)), m;
513
587
  }, []);
514
- e.children.push(...H);
588
+ e.children.push(...O);
515
589
  }
516
590
  }
517
591
  }
518
592
  };
519
- return r.utilities.push(o), o.create;
593
+ return r.utilities.push(s), s.create;
520
594
  };
521
595
  }
522
- function ye(e, r) {
596
+ function pe(e, r) {
523
597
  return function(t, i) {
524
- const c = r.themes.find((s) => s.name === t), o = c ?? {
598
+ const c = r.themes.find((o) => o.name === t), s = c ?? {
525
599
  type: "theme",
526
600
  name: t,
527
601
  declarations: {},
528
602
  variables: [],
529
603
  children: []
530
604
  };
531
- c || r.themes.push(o);
532
- const u = v(o, r);
533
- return i && i(u), o;
605
+ c || r.themes.push(s);
606
+ const a = v(s, r);
607
+ return i && i(a), s;
534
608
  };
535
609
  }
536
- function de(e, r) {
610
+ function he(e, r) {
537
611
  return function(t) {
538
612
  const i = {
539
613
  type: "recipe",
540
614
  ...t
541
615
  };
542
- return i._runtime = me(i, r), pe(i, r), r.recipes.push(i), i;
616
+ return i._runtime = ge(i, r), be(i, r), r.recipes.push(i), i;
543
617
  };
544
618
  }
545
619
  function _(e, r) {
546
620
  const n = e.autogenerate(r);
547
621
  return Object.keys(n)[0] ?? "default";
548
622
  }
549
- function F(e, r) {
623
+ function x(e, r) {
550
624
  const n = {};
551
625
  for (const [t, i] of Object.entries(e))
552
- if (P(i)) {
626
+ if (L(i)) {
553
627
  const c = {};
554
- for (const [o, u] of Object.entries(i)) {
555
- const s = T(r, o);
556
- s && (c[o] = _(
557
- s,
558
- u
559
- ));
628
+ for (const [s, a] of Object.entries(i)) {
629
+ const o = S(r, s);
630
+ o ? c[s] = _(
631
+ o,
632
+ a
633
+ ) : console.warn(
634
+ `[styleframe] Utility "${s}" not found in registry. Skipping runtime generation for this declaration.`
635
+ );
560
636
  }
561
637
  n[t] = c;
562
638
  } else if (typeof i == "boolean")
563
639
  n[t] = i;
564
640
  else {
565
- const c = T(r, t);
566
- c && (n[t] = _(c, i));
641
+ const c = S(r, t);
642
+ c ? n[t] = _(c, i) : console.warn(
643
+ `[styleframe] Utility "${t}" not found in registry. Skipping runtime generation for this declaration.`
644
+ );
567
645
  }
568
646
  return n;
569
647
  }
570
- function me(e, r) {
648
+ function ge(e, r) {
571
649
  const n = {};
572
- if (e.base && (n.base = F(e.base, r)), e.variants) {
650
+ if (e.base && (n.base = x(e.base, r)), e.variants) {
573
651
  const t = {};
574
652
  for (const [i, c] of Object.entries(e.variants)) {
575
- const o = {};
576
- for (const [u, s] of Object.entries(
653
+ const s = {};
654
+ for (const [a, o] of Object.entries(
577
655
  c
578
656
  ))
579
- s == null ? o[u] = null : o[u] = F(
580
- s,
657
+ o == null ? s[a] = null : s[a] = x(
658
+ o,
581
659
  r
582
660
  );
583
- t[i] = o;
661
+ t[i] = s;
584
662
  }
585
663
  n.variants = t;
586
664
  }
587
665
  return e.defaultVariants && (n.defaultVariants = { ...e.defaultVariants }), e.compoundVariants && (n.compoundVariants = e.compoundVariants.map((t) => ({
588
666
  match: { ...t.match },
589
- css: F(t.css, r)
667
+ css: x(t.css, r)
590
668
  }))), n;
591
669
  }
592
- function P(e) {
593
- return !A(e) && typeof e == "object" && e !== null;
670
+ function L(e) {
671
+ return !j(e) && typeof e == "object" && e !== null;
594
672
  }
595
- function x(e, r) {
673
+ function E(e, r) {
596
674
  const n = (t, i, c) => {
597
- let o = r.get(t);
598
- o || (o = [], r.set(t, o)), o.push({ value: i, modifiers: c });
675
+ let s = r.get(t);
676
+ s || (s = [], r.set(t, s)), s.push({ value: i, modifiers: c });
599
677
  };
600
678
  for (const [t, i] of Object.entries(e))
601
- if (P(i)) {
679
+ if (L(i)) {
602
680
  const c = t.split(":");
603
- for (const [o, u] of Object.entries(i))
604
- n(o, u, c);
681
+ for (const [s, a] of Object.entries(i))
682
+ n(s, a, c);
605
683
  } else
606
684
  n(t, i, []);
607
685
  }
608
- function T(e, r) {
686
+ function S(e, r) {
609
687
  const n = e.utilities.find((i) => i.name === r);
610
688
  if (n)
611
689
  return n;
612
690
  const t = r.replace(/[A-Z]/g, (i) => `-${i.toLowerCase()}`);
613
691
  return e.utilities.find((i) => i.name === t);
614
692
  }
615
- function pe(e, r) {
693
+ function be(e, r) {
616
694
  const n = /* @__PURE__ */ new Map();
617
- if (e.base && x(e.base, n), e.variants)
695
+ if (e.base && E(e.base, n), e.variants)
618
696
  for (const i of Object.values(e.variants))
619
697
  for (const c of Object.values(i))
620
- x(
698
+ E(
621
699
  c,
622
700
  n
623
701
  );
624
702
  if (e.compoundVariants)
625
703
  for (const i of e.compoundVariants)
626
- i.css && x(i.css, n);
704
+ i.css && E(i.css, n);
627
705
  const t = /* @__PURE__ */ new Map();
628
706
  for (const [i, c] of n) {
629
- const o = T(r, i);
630
- if (!o) {
707
+ const s = S(r, i);
708
+ if (!s) {
631
709
  console.warn(
632
710
  `[styleframe] Utility "${i}" not found in registry. Skipping.`
633
711
  );
634
712
  continue;
635
713
  }
636
- for (const u of c) {
637
- const s = [];
638
- for (const f of u.modifiers) {
714
+ for (const a of c) {
715
+ const o = [];
716
+ for (const f of a.modifiers) {
639
717
  if (!t.has(f))
640
718
  try {
641
- t.set(f, re(r, f));
719
+ t.set(f, se(r, f));
642
720
  } catch {
643
721
  console.warn(
644
722
  `[styleframe] Modifier "${f}" not found in registry. Skipping modifier for utility "${i}".`
645
723
  ), t.set(f, null);
646
724
  }
647
725
  const l = t.get(f);
648
- l && s.push(l);
726
+ l && o.push(l);
649
727
  }
650
- o.create(
651
- [u.value],
652
- s.length > 0 ? s : void 0
728
+ s.create(
729
+ [a.value],
730
+ o.length > 0 ? o : void 0
653
731
  );
654
732
  }
655
733
  }
656
734
  }
657
- function Re(e) {
658
- const r = ne("sf-"), n = ae(), t = { ...e }, i = le(n, n), c = ue(n, n), o = de(n, n), u = ye(n, n), { variable: s, selector: f, atRule: l, keyframes: a, media: y, ref: m, css: d } = v(n, n);
735
+ function Fe(e) {
736
+ const r = ie("sf-"), n = ye(), t = { ...e }, i = me(n, n), c = le(n, n), s = he(n, n), a = pe(n, n), { variable: o, selector: f, atRule: l, keyframes: u, media: y, ref: p, css: d } = v(n, n);
659
737
  return {
660
738
  id: r,
661
739
  root: n,
662
- variable: s,
740
+ variable: o,
663
741
  selector: f,
664
742
  utility: i,
665
743
  modifier: c,
666
- recipe: o,
667
- theme: u,
744
+ recipe: s,
745
+ theme: a,
668
746
  atRule: l,
669
- keyframes: a,
747
+ keyframes: u,
670
748
  media: y,
671
- ref: m,
749
+ ref: p,
672
750
  css: d,
673
751
  options: t
674
752
  };
675
753
  }
676
754
  export {
677
- fe as applyModifiers,
678
- we as capitalizeFirst,
679
- ce as combineKeys,
680
- C as createAtRuleFunction,
681
- W as createCssFunction,
755
+ ue as applyModifiers,
756
+ Re as capitalizeFirst,
757
+ ae as combineKeys,
758
+ K as createAtRuleFunction,
759
+ Z as createCssFunction,
682
760
  v as createDeclarationsCallbackContext,
683
- Z as createKeyframesFunction,
684
- Y as createMediaFunction,
685
- ue as createModifierFunction,
686
- de as createRecipeFunction,
687
- J as createRefFunction,
688
- ae as createRoot,
689
- Q as createSelectorFunction,
690
- ye as createThemeFunction,
691
- le as createUtilityFunction,
692
- X as createVariableFunction,
693
- R as deepClone,
694
- ne as generateRandomId,
695
- me as generateRecipeRuntime,
696
- re as getModifier,
697
- ke as getUtility,
698
- Ve as getVariable,
699
- ge as isAtRule,
700
- E as isCSS,
701
- I as isContainer,
702
- q as isModifier,
703
- S as isObject,
704
- G as isPrimitiveTokenValue,
705
- Ae as isRecipe,
706
- A as isRef,
707
- O as isRoot,
708
- be as isSelector,
709
- ve as isTheme,
710
- p as isToken,
711
- M as isTokenEqual,
712
- $ as isTokenValue,
713
- je as isUtility,
714
- L as isVariable,
715
- Oe as merge,
716
- U as mergeContainers,
717
- se as mergeThemesArray,
718
- oe as mergeVariablesArray,
719
- V as parseDeclarationsBlock,
720
- pe as processRecipeUtilities,
721
- ee as rfdc,
722
- Re as styleframe,
723
- z as transformUtilityKey
761
+ Q as createKeyframesFunction,
762
+ J as createMediaFunction,
763
+ le as createModifierFunction,
764
+ he as createRecipeFunction,
765
+ X as createRefFunction,
766
+ ye as createRoot,
767
+ ee as createSelectorFunction,
768
+ pe as createThemeFunction,
769
+ me as createUtilityFunction,
770
+ te as createVariableFunction,
771
+ F as deepClone,
772
+ ie as generateRandomId,
773
+ ge as generateRecipeRuntime,
774
+ se as getModifier,
775
+ Oe as getUtility,
776
+ $e as getVariable,
777
+ je as isAtRule,
778
+ T as isCSS,
779
+ Y as isContainer,
780
+ I as isModifier,
781
+ C as isObject,
782
+ z as isPrimitiveTokenValue,
783
+ ke as isRecipe,
784
+ j as isRef,
785
+ V as isRoot,
786
+ Ae as isSelector,
787
+ Ve as isStyleframe,
788
+ we as isTheme,
789
+ h as isToken,
790
+ N as isTokenEqual,
791
+ D as isTokenValue,
792
+ ve as isUtility,
793
+ G as isVariable,
794
+ Me as merge,
795
+ W as mergeContainers,
796
+ fe as mergeThemesArray,
797
+ ce as mergeVariablesArray,
798
+ R as parseDeclarationsBlock,
799
+ be as processRecipeUtilities,
800
+ ne as rfdc,
801
+ Fe as styleframe,
802
+ P as transformUtilityKey
724
803
  };
@@ -1 +1 @@
1
- (function(a,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(a=typeof globalThis<"u"?globalThis:a||self,b(a.styleframe={}))})(this,(function(a){"use strict";function b(e){return typeof e=="object"&&e!==null}function p(e,r){return b(e)&&"type"in e&&e.type===r}function $(e){return p(e,"variable")}function A(e){return p(e,"reference")}function de(e){return p(e,"selector")}function me(e){return p(e,"at-rule")}function he(e){return p(e,"utility")}function P(e){return p(e,"modifier")}function k(e){return p(e,"css")}function pe(e){return p(e,"theme")}function F(e){return p(e,"root")}function be(e){return p(e,"recipe")}function H(e){return typeof e=="string"||typeof e=="number"||typeof e=="boolean"||e===null}function S(e){return H(e)||A(e)||k(e)||Array.isArray(e)&&e.every(S)}function N(e){return b(e)&&"children"in e&&"declarations"in e&&"variables"in e}function q(e=r=>r){return r=>{let n=r,t;if(typeof n=="string"&&n[0]==="@"){const i=n.slice(1);t=e(i),n={type:"reference",name:i}}else A(n)?t=e(n.name):t=`[${r}]`;return{[t]:n}}}function I(e,r){return function(t,...i){return{type:"css",value:t.reduce((o,u,s)=>(o.push(u),s<i.length&&o.push(i[s]),o),[])}}}function O(e,r){return function(t,i,c){const o={type:"at-rule",identifier:t,rule:i,declarations:{},variables:[],children:[]},u=g(o,r);return typeof c=="function"?o.declarations=c(u)??{}:c&&(o.declarations=c),w(o.declarations,u),e.children.push(o),o}}function L(e,r){const n=O(e,r);return function(i,c){return n("media",i,c)}}function z(e,r){const n=O(e,r);return function(i,c){return n("keyframes",i,c)}}function G(e,r){return function(t,i){return $(t)?{type:"reference",name:t.name,fallback:i}:{type:"reference",name:t,fallback:i}}}function W(e,r){return function(t,i){const c={type:"selector",query:t,declarations:{},variables:[],children:[]},o=g(c,r);return typeof i=="function"?c.declarations=i(o)??{}:N(i)?(c.variables=i.variables,c.declarations=i.declarations,c.children=i.children):c.declarations=i,w(c.declarations,o),e.children.push(c),c}}function Y(e,r){return function(t,i,c={default:!1}){const o=typeof t=="string"?t:t.name,u=e.variables.find(f=>f.name===o);if(c.default&&u)return u;if(u)return u.value=i,u;const s={type:"variable",name:o,value:i};return e.variables.push(s),s}}function g(e,r){const n=Y(e),t=W(e,r),i=O(e,r),c=z(r,r),o=L(e,r),u=G(),s=I();return{variable:n,selector:t,keyframes:c,atRule:i,media:o,ref:u,css:s}}function w(e,r){for(const n in e)if(n.startsWith("@")){const t=e[n];if(typeof t=="object"&&t!==null&&!S(t)){const i=n.replace(/^@(\w+).*/,"$1"),c=n.replace(`@${i}`,"").trim();r.atRule(i,c,t),delete e[n]}}else if(/^[.&:]/.test(n)){const t=e[n];typeof t=="object"&&(r.selector(n,t),delete e[n])}return e}function ge(e){return e.charAt(0).toUpperCase()+e.slice(1)}function R(e){if(e instanceof Buffer)return Buffer.from(e);const r=e.constructor;return new r(e.buffer.slice(0),e.byteOffset,e.byteLength/e.BYTES_PER_ELEMENT||1)}function Z(e){if(e=e||{},e.circular)return je(e);const r=new Map;if(r.set(Date,o=>new Date(o)),r.set(Map,(o,u)=>new Map(t(Array.from(o),u))),r.set(Set,(o,u)=>new Set(t(Array.from(o),u))),e.constructorHandlers)for(const o of e.constructorHandlers)r.set(o[0],o[1]);let n;return e.proto?c:i;function t(o,u){const s=Object.keys(o),f=Array.from({length:s.length});for(let y=0;y<s.length;y++){const l=s[y],d=o[l];typeof d!="object"||d===null?f[l]=d:d.constructor!==Object&&(n=r.get(d.constructor))?f[l]=n(d,u):ArrayBuffer.isView(d)?f[l]=R(d):f[l]=u(d)}return f}function i(o){if(typeof o!="object"||o===null)return o;if(Array.isArray(o))return t(o,i);if(o.constructor!==Object&&(n=r.get(o.constructor)))return n(o,i);const u={};for(const s in o){if(Object.hasOwnProperty.call(o,s)===!1)continue;const f=o[s];typeof f!="object"||f===null?u[s]=f:f.constructor!==Object&&(n=r.get(f.constructor))?u[s]=n(f,i):ArrayBuffer.isView(f)?u[s]=R(f):u[s]=i(f)}return u}function c(o){if(typeof o!="object"||o===null)return o;if(Array.isArray(o))return t(o,c);if(o.constructor!==Object&&(n=r.get(o.constructor)))return n(o,c);const u={};for(const s in o){const f=o[s];typeof f!="object"||f===null?u[s]=f:f.constructor!==Object&&(n=r.get(f.constructor))?u[s]=n(f,c):ArrayBuffer.isView(f)?u[s]=R(f):u[s]=c(f)}return u}}function je(e){const r=[],n=[],t=new Map;if(t.set(Date,s=>new Date(s)),t.set(Map,(s,f)=>new Map(c(Array.from(s),f))),t.set(Set,(s,f)=>new Set(c(Array.from(s),f))),e.constructorHandlers)for(const s of e.constructorHandlers)t.set(s[0],s[1]);let i;return e.proto?u:o;function c(s,f){const y=Object.keys(s),l=Array.from({length:y.length});for(let d=0;d<y.length;d++){const h=y[d],m=s[h];if(typeof m!="object"||m===null)l[h]=m;else if(m.constructor!==Object&&(i=t.get(m.constructor)))l[h]=i(m,f);else if(ArrayBuffer.isView(m))l[h]=R(m);else{const j=r.indexOf(m);j!==-1?l[h]=n[j]:l[h]=f(m)}}return l}function o(s){if(typeof s!="object"||s===null)return s;if(Array.isArray(s))return c(s,o);if(s.constructor!==Object&&(i=t.get(s.constructor)))return i(s,o);const f={};r.push(s),n.push(f);for(const y in s){if(Object.hasOwnProperty.call(s,y)===!1)continue;const l=s[y];if(typeof l!="object"||l===null)f[y]=l;else if(l.constructor!==Object&&(i=t.get(l.constructor)))f[y]=i(l,o);else if(ArrayBuffer.isView(l))f[y]=R(l);else{const d=r.indexOf(l);d!==-1?f[y]=n[d]:f[y]=o(l)}}return r.pop(),n.pop(),f}function u(s){if(typeof s!="object"||s===null)return s;if(Array.isArray(s))return c(s,u);if(s.constructor!==Object&&(i=t.get(s.constructor)))return i(s,u);const f={};r.push(s),n.push(f);for(const y in s){const l=s[y];if(typeof l!="object"||l===null)f[y]=l;else if(l.constructor!==Object&&(i=t.get(l.constructor)))f[y]=i(l,u);else if(ArrayBuffer.isView(l))f[y]=R(l);else{const d=r.indexOf(l);d!==-1?f[y]=n[d]:f[y]=u(l)}}return r.pop(),n.pop(),f}}const M=Z();function J(e,r=8){const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let t="";for(let i=0;i<r;i++){const c=Math.floor(Math.random()*n.length);t+=n[c]}return e?`${e}${t}`:t}function ve(e,r){const n=e.variables.find(t=>t.name===r);if(!n)throw new Error(`Variable "${r}" not found`);return n}function Ae(e,r){const n=e.utilities.find(t=>t.name===r);if(!n)throw new Error(`Utility "${r}" not found`);return n}function Q(e,r){const n=e.modifiers.find(t=>t.key.includes(r));if(!n)throw new Error(`Modifier "${r}" not found`);return n}function T(e,r){if(e===r)return!0;if(typeof e!=typeof r)return!1;if(e===null||r===null)return e===r;if(typeof e!="object"||typeof r!="object")return!1;if(Array.isArray(e)&&Array.isArray(r))return e.length!==r.length?!1:e.every((n,t)=>T(n,r[t]));if("type"in e&&"type"in r){if(e.type!==r.type)return!1;if(A(e)&&A(r))return e.name===r.name&&T(e.fallback,r.fallback);if(k(e)&&k(r))return T(e.value,r.value)}return!1}const X="__licenseRequired";function Re(e){E(e)||Object.defineProperty(e,X,{value:!0,writable:!1,configurable:!1,enumerable:!0})}function E(e){return Object.prototype.hasOwnProperty.call(e,X)}function x(e,r){const n=[...e];for(const t of r){const i=n.find(c=>c.name===t.name);i?i.value=t.value:n.push(t)}return n}function ee(e,r){const n=[...e];for(const t of r){const i=n.find(c=>c.name===t.name);i?Object.assign(i,B(i,t)):n.push(t)}return n}function B(e,r){return Object.keys(e).reduce((n,t)=>(t==="variables"?n.variables=x(e.variables,r.variables):t==="declarations"?n.declarations={...e.declarations,...r.declarations}:t==="themes"&&F(n)&&F(e)&&F(r)?n.themes=ee(e.themes,r.themes):Array.isArray(e[t])&&(n[t]=e[t].concat(r[t])),n),{...e,...r})}function Ve(e,...r){return r.reduce((n,t)=>{const i={...n,root:B(n.root,t.root)};return(E(n)||E(t))&&Re(i),i},e)}function te(e){const r=[];function n(t,i){i.length>0&&r.push([...i].sort());for(let c=t;c<e.length;c++){const o=e[c];if(o)if(o.length===1&&o[0])n(c+1,[...i,o[0]]);else for(const u of o)n(c+1,[...i,u])}}return n(0,[]),r.sort((t,i)=>t.length!==i.length?t.length-i.length:t.join(",").localeCompare(i.join(",")))}function ne(e,r,n){const t={...e,modifiers:[...n.keys()]},i=g(t,r);for(const c of n.values())c.factory({...i,declarations:M(t.declarations),variables:M(t.variables),children:M(t.children)}),w(t.declarations,i);return t}function re(e,r){return function(t,i){const c={type:"modifier",key:Array.isArray(t)?t:[t],factory:i};return r.modifiers.push(c),c}}function ie(){return{type:"root",declarations:{},utilities:[],modifiers:[],recipes:[],variables:[],children:[],themes:[]}}function oe(e,r){return function(t,i,c={}){const o={type:"utility",name:t,factory:i,values:[],autogenerate:c.autogenerate??q(),create:(u,s=[])=>{let f=u;if(Array.isArray(u)){f={};for(const y of u){const l=o.autogenerate(y);f={...f,...l}}}for(const[y,l]of Object.entries(f)){const d=o.values.find(j=>j.key===y&&j.modifiers.length===0),h={type:"utility",name:t,value:y,declarations:{},variables:[],children:[],modifiers:[]},m=g(h,r);if(h.declarations=i({...m,value:l})??{},w(h.declarations,m),d||(o.values.push({key:y,value:l,modifiers:[]}),e.children.push(h)),s&&s.length>0){const j=s.map(v=>v.key),ke=te(j).filter(v=>!o.values.find(V=>V.key===y&&V.modifiers.length===v.length&&V.modifiers.every(C=>v.includes(C)))).reduce((v,V)=>{const C=new Map;for(const ye of V){const _=s.find(Fe=>Fe.key.includes(ye));_&&P(_)&&C.set(ye,_)}return o.values.push({key:y,value:l,modifiers:V}),v.push(ne(h,r,C)),v},[]);e.children.push(...ke)}}}};return r.utilities.push(o),o.create}}function se(e,r){return function(t,i){const c=r.themes.find(s=>s.name===t),o=c??{type:"theme",name:t,declarations:{},variables:[],children:[]};c||r.themes.push(o);const u=g(o,r);return i&&i(u),o}}function ce(e,r){return function(t){const i={type:"recipe",...t};return i._runtime=ue(i,r),le(i,r),r.recipes.push(i),i}}function fe(e,r){const n=e.autogenerate(r);return Object.keys(n)[0]??"default"}function K(e,r){const n={};for(const[t,i]of Object.entries(e))if(ae(i)){const c={};for(const[o,u]of Object.entries(i)){const s=D(r,o);s&&(c[o]=fe(s,u))}n[t]=c}else if(typeof i=="boolean")n[t]=i;else{const c=D(r,t);c&&(n[t]=fe(c,i))}return n}function ue(e,r){const n={};if(e.base&&(n.base=K(e.base,r)),e.variants){const t={};for(const[i,c]of Object.entries(e.variants)){const o={};for(const[u,s]of Object.entries(c))s==null?o[u]=null:o[u]=K(s,r);t[i]=o}n.variants=t}return e.defaultVariants&&(n.defaultVariants={...e.defaultVariants}),e.compoundVariants&&(n.compoundVariants=e.compoundVariants.map(t=>({match:{...t.match},css:K(t.css,r)}))),n}function ae(e){return!A(e)&&typeof e=="object"&&e!==null}function U(e,r){const n=(t,i,c)=>{let o=r.get(t);o||(o=[],r.set(t,o)),o.push({value:i,modifiers:c})};for(const[t,i]of Object.entries(e))if(ae(i)){const c=t.split(":");for(const[o,u]of Object.entries(i))n(o,u,c)}else n(t,i,[])}function D(e,r){const n=e.utilities.find(i=>i.name===r);if(n)return n;const t=r.replace(/[A-Z]/g,i=>`-${i.toLowerCase()}`);return e.utilities.find(i=>i.name===t)}function le(e,r){const n=new Map;if(e.base&&U(e.base,n),e.variants)for(const i of Object.values(e.variants))for(const c of Object.values(i))U(c,n);if(e.compoundVariants)for(const i of e.compoundVariants)i.css&&U(i.css,n);const t=new Map;for(const[i,c]of n){const o=D(r,i);if(!o){console.warn(`[styleframe] Utility "${i}" not found in registry. Skipping.`);continue}for(const u of c){const s=[];for(const f of u.modifiers){if(!t.has(f))try{t.set(f,Q(r,f))}catch{console.warn(`[styleframe] Modifier "${f}" not found in registry. Skipping modifier for utility "${i}".`),t.set(f,null)}const y=t.get(f);y&&s.push(y)}o.create([u.value],s.length>0?s:void 0)}}}function we(e){const r=J("sf-"),n=ie(),t={...e},i=oe(n,n),c=re(n,n),o=ce(n,n),u=se(n,n),{variable:s,selector:f,atRule:y,keyframes:l,media:d,ref:h,css:m}=g(n,n);return{id:r,root:n,variable:s,selector:f,utility:i,modifier:c,recipe:o,theme:u,atRule:y,keyframes:l,media:d,ref:h,css:m,options:t}}a.applyModifiers=ne,a.capitalizeFirst=ge,a.combineKeys=te,a.createAtRuleFunction=O,a.createCssFunction=I,a.createDeclarationsCallbackContext=g,a.createKeyframesFunction=z,a.createMediaFunction=L,a.createModifierFunction=re,a.createRecipeFunction=ce,a.createRefFunction=G,a.createRoot=ie,a.createSelectorFunction=W,a.createThemeFunction=se,a.createUtilityFunction=oe,a.createVariableFunction=Y,a.deepClone=M,a.generateRandomId=J,a.generateRecipeRuntime=ue,a.getModifier=Q,a.getUtility=Ae,a.getVariable=ve,a.isAtRule=me,a.isCSS=k,a.isContainer=N,a.isModifier=P,a.isObject=b,a.isPrimitiveTokenValue=H,a.isRecipe=be,a.isRef=A,a.isRoot=F,a.isSelector=de,a.isTheme=pe,a.isToken=p,a.isTokenEqual=T,a.isTokenValue=S,a.isUtility=he,a.isVariable=$,a.merge=Ve,a.mergeContainers=B,a.mergeThemesArray=ee,a.mergeVariablesArray=x,a.parseDeclarationsBlock=w,a.processRecipeUtilities=le,a.rfdc=Z,a.styleframe=we,a.transformUtilityKey=q,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(u,b){typeof exports=="object"&&typeof module<"u"?b(exports):typeof define=="function"&&define.amd?define(["exports"],b):(u=typeof globalThis<"u"?globalThis:u||self,b(u.styleframe={}))})(this,(function(u){"use strict";function b(e){return typeof e=="object"&&e!==null}function h(e,r){return b(e)&&"type"in e&&e.type===r}function W(e){return h(e,"variable")}function v(e){return h(e,"reference")}function pe(e){return h(e,"selector")}function ge(e){return h(e,"at-rule")}function be(e){return h(e,"utility")}function q(e){return h(e,"modifier")}function M(e){return h(e,"css")}function Ae(e){return h(e,"theme")}function R(e){return h(e,"root")}function je(e){return h(e,"recipe")}function I(e){return typeof e=="string"||typeof e=="number"||typeof e=="boolean"||e===null}function C(e){return I(e)||v(e)||M(e)||Array.isArray(e)&&e.every(C)}function L(e){return b(e)&&"children"in e&&"declarations"in e&&"variables"in e}function ve(e){return b(e)&&"id"in e&&"root"in e&&"variable"in e&&"selector"in e&&"recipe"in e&&typeof e.id=="string"&&R(e.root)}function U(e){const r=typeof e=="function"?{replacer:e}:e??{},{replacer:n=c=>c,namespace:t}=r,i=Array.isArray(t)?t:t?[t]:[];return c=>{let s=c,a;if(typeof s=="string"&&s[0]==="@"){const o=s.slice(1),f=i.find(d=>o===d||o.startsWith(`${d}.`));let y,l;f?(y=o,l=o.startsWith(`${f}.`)?o.slice(f.length+1):o):i.length>0?(y=`${i[0]}.${o}`,l=o):(y=o,l=o),a=n(l),s={type:"reference",name:y}}else if(v(s)){let o=s.name;for(const f of i)if(o.startsWith(`${f}.`)){o=o.slice(f.length+1);break}a=n(o)}else a=`[${c}]`;return{[a]:s}}}function z(e,r){return function(t,...i){return{type:"css",value:t.reduce((s,a,o)=>(s.push(a),o<i.length&&s.push(i[o]),s),[])}}}function T(e,r){return function(t,i,c){const s={type:"at-rule",identifier:t,rule:i,declarations:{},variables:[],children:[]},a=k(s,r);return typeof c=="function"?s.declarations=c(a)??{}:c&&(s.declarations=c),V(s.declarations,a),e.children.push(s),s}}function G(e,r){const n=T(e,r);return function(i,c){return n("media",i,c)}}function Y(e,r){const n=T(e,r);return function(i,c){return n("keyframes",i,c)}}function Z(e,r){return function(t,i){return W(t)?{type:"reference",name:t.name,fallback:i}:{type:"reference",name:t,fallback:i}}}function J(e,r){return function(t,i){const c={type:"selector",query:t,declarations:{},variables:[],children:[]},s=k(c,r);return typeof i=="function"?c.declarations=i(s)??{}:L(i)?(c.variables=i.variables,c.declarations=i.declarations,c.children=i.children):c.declarations=i,V(c.declarations,s),e.children.push(c),c}}function Q(e,r){return function(t,i,c={default:!1}){const s=typeof t=="string"?t:t.name,a=e.variables.find(f=>f.name===s);if(c.default&&a)return a;if(a)return a.value=i,a;const o={type:"variable",name:s,value:i};return e.variables.push(o),o}}function k(e,r){const n=Q(e),t=J(e,r),i=T(e,r),c=Y(r,r),s=G(e,r),a=Z(),o=z();return{variable:n,selector:t,keyframes:c,atRule:i,media:s,ref:a,css:o}}function V(e,r){for(const n in e)if(n.startsWith("@")){const t=e[n];if(typeof t=="object"&&t!==null&&!C(t)){const i=n.replace(/^@(\w+).*/,"$1"),c=n.replace(`@${i}`,"").trim();r.atRule(i,c,t),delete e[n]}}else if(/^[.&:]/.test(n)||/^\d+%$/.test(n)||n==="from"||n==="to"){const t=e[n];typeof t=="object"&&(r.selector(n,t),delete e[n])}for(const n in e){const t=e[n];typeof t=="string"&&t[0]==="@"&&(e[n]=r.ref(t.slice(1)))}return e}function ke(e){return e.charAt(0).toUpperCase()+e.slice(1)}function w(e){if(e instanceof Buffer)return Buffer.from(e);const r=e.constructor;return new r(e.buffer.slice(0),e.byteOffset,e.byteLength/e.BYTES_PER_ELEMENT||1)}function X(e){if(e=e||{},e.circular)return we(e);const r=new Map;if(r.set(Date,s=>new Date(s)),r.set(Map,(s,a)=>new Map(t(Array.from(s),a))),r.set(Set,(s,a)=>new Set(t(Array.from(s),a))),e.constructorHandlers)for(const s of e.constructorHandlers)r.set(s[0],s[1]);let n;return e.proto?c:i;function t(s,a){const o=Object.keys(s),f=Array.from({length:o.length});for(let y=0;y<o.length;y++){const l=o[y],d=s[l];typeof d!="object"||d===null?f[l]=d:d.constructor!==Object&&(n=r.get(d.constructor))?f[l]=n(d,a):ArrayBuffer.isView(d)?f[l]=w(d):f[l]=a(d)}return f}function i(s){if(typeof s!="object"||s===null)return s;if(Array.isArray(s))return t(s,i);if(s.constructor!==Object&&(n=r.get(s.constructor)))return n(s,i);const a={};for(const o in s){if(Object.hasOwnProperty.call(s,o)===!1)continue;const f=s[o];typeof f!="object"||f===null?a[o]=f:f.constructor!==Object&&(n=r.get(f.constructor))?a[o]=n(f,i):ArrayBuffer.isView(f)?a[o]=w(f):a[o]=i(f)}return a}function c(s){if(typeof s!="object"||s===null)return s;if(Array.isArray(s))return t(s,c);if(s.constructor!==Object&&(n=r.get(s.constructor)))return n(s,c);const a={};for(const o in s){const f=s[o];typeof f!="object"||f===null?a[o]=f:f.constructor!==Object&&(n=r.get(f.constructor))?a[o]=n(f,c):ArrayBuffer.isView(f)?a[o]=w(f):a[o]=c(f)}return a}}function we(e){const r=[],n=[],t=new Map;if(t.set(Date,o=>new Date(o)),t.set(Map,(o,f)=>new Map(c(Array.from(o),f))),t.set(Set,(o,f)=>new Set(c(Array.from(o),f))),e.constructorHandlers)for(const o of e.constructorHandlers)t.set(o[0],o[1]);let i;return e.proto?a:s;function c(o,f){const y=Object.keys(o),l=Array.from({length:y.length});for(let d=0;d<y.length;d++){const g=y[d],m=o[g];if(typeof m!="object"||m===null)l[g]=m;else if(m.constructor!==Object&&(i=t.get(m.constructor)))l[g]=i(m,f);else if(ArrayBuffer.isView(m))l[g]=w(m);else{const F=r.indexOf(m);F!==-1?l[g]=n[F]:l[g]=f(m)}}return l}function s(o){if(typeof o!="object"||o===null)return o;if(Array.isArray(o))return c(o,s);if(o.constructor!==Object&&(i=t.get(o.constructor)))return i(o,s);const f={};r.push(o),n.push(f);for(const y in o){if(Object.hasOwnProperty.call(o,y)===!1)continue;const l=o[y];if(typeof l!="object"||l===null)f[y]=l;else if(l.constructor!==Object&&(i=t.get(l.constructor)))f[y]=i(l,s);else if(ArrayBuffer.isView(l))f[y]=w(l);else{const d=r.indexOf(l);d!==-1?f[y]=n[d]:f[y]=s(l)}}return r.pop(),n.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&&(i=t.get(o.constructor)))return i(o,a);const f={};r.push(o),n.push(f);for(const y in o){const l=o[y];if(typeof l!="object"||l===null)f[y]=l;else if(l.constructor!==Object&&(i=t.get(l.constructor)))f[y]=i(l,a);else if(ArrayBuffer.isView(l))f[y]=w(l);else{const d=r.indexOf(l);d!==-1?f[y]=n[d]:f[y]=a(l)}}return r.pop(),n.pop(),f}}const O=X();function x(e,r=8){const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let t="";for(let i=0;i<r;i++){const c=Math.floor(Math.random()*n.length);t+=n[c]}return e?`${e}${t}`:t}function Re(e,r){const n=e.variables.find(t=>t.name===r);if(!n)throw new Error(`Variable "${r}" not found`);return n}function Ve(e,r){const n=e.utilities.find(t=>t.name===r);if(!n)throw new Error(`Utility "${r}" not found`);return n}function ee(e,r){const n=e.modifiers.find(t=>t.key.includes(r));if(!n)throw new Error(`Modifier "${r}" not found`);return n}function $(e,r){if(e===r)return!0;if(typeof e!=typeof r)return!1;if(e===null||r===null)return e===r;if(typeof e!="object"||typeof r!="object")return!1;if(Array.isArray(e)&&Array.isArray(r))return e.length!==r.length?!1:e.every((n,t)=>$(n,r[t]));if("type"in e&&"type"in r){if(e.type!==r.type)return!1;if(v(e)&&v(r))return e.name===r.name&&$(e.fallback,r.fallback);if(M(e)&&M(r))return $(e.value,r.value)}return!1}const te="__licenseRequired";function Fe(e){E(e)||Object.defineProperty(e,te,{value:!0,writable:!1,configurable:!1,enumerable:!0})}function E(e){return Object.prototype.hasOwnProperty.call(e,te)}function ne(e,r){const n=[...e];for(const t of r){const i=n.find(c=>c.name===t.name);i?i.value=t.value:n.push(t)}return n}function re(e,r){const n=[...e];for(const t of r){const i=n.find(c=>c.name===t.name);i?Object.assign(i,N(i,t)):n.push(t)}return n}function N(e,r){return Object.keys(e).reduce((n,t)=>(t==="variables"?n.variables=ne(e.variables,r.variables):t==="declarations"?n.declarations={...e.declarations,...r.declarations}:t==="themes"&&R(n)&&R(e)&&R(r)?n.themes=re(e.themes,r.themes):Array.isArray(e[t])&&(n[t]=e[t].concat(r[t])),n),{...e,...r})}function Me(e,...r){return r.reduce((n,t)=>{const i={...n,root:N(n.root,t.root)};return(E(n)||E(t))&&Fe(i),i},e)}function ie(e){const r=[];function n(t,i){i.length>0&&r.push([...i].sort());for(let c=t;c<e.length;c++){const s=e[c];if(s)if(s.length===1&&s[0])n(c+1,[...i,s[0]]);else for(const a of s)n(c+1,[...i,a])}}return n(0,[]),r.sort((t,i)=>t.length!==i.length?t.length-i.length:t.join(",").localeCompare(i.join(",")))}function se(e,r,n){const t={...e,modifiers:[...n.keys()]},i=k(t,r);for(const c of n.values())c.factory({...i,declarations:O(t.declarations),variables:O(t.variables),children:O(t.children)}),V(t.declarations,i);return t}function oe(e,r){return function(t,i){const c={type:"modifier",key:Array.isArray(t)?t:[t],factory:i};return r.modifiers.push(c),c}}function ce(){return{type:"root",declarations:{},utilities:[],modifiers:[],recipes:[],variables:[],children:[],themes:[]}}function Te(e,r){const n=U({namespace:e});return t=>{if(typeof t=="string"&&t[0]==="@"){const i=t.slice(1),c=e.find(s=>i===s||i.startsWith(`${s}.`));if(c){const s=i.slice(c.length+1)||i;if(r.variables.some(a=>a.name===i))return{[s]:{type:"reference",name:i}}}else for(const s of e){const a=`${s}.${i}`;if(r.variables.some(o=>o.name===a))return{[i]:{type:"reference",name:a}}}return n(t)}return n(t)}}function fe(e,r){return function(t,i,c={}){const s={type:"utility",name:t,factory:i,values:[],autogenerate:c.autogenerate??(Array.isArray(c.namespace)?Te(c.namespace,r):U(c.namespace?{namespace:c.namespace}:void 0)),namespace:c.namespace,create:(a,o=[])=>{let f=a;if(Array.isArray(a)){f={};for(const y of a){const l=s.autogenerate(y);f={...f,...l}}}for(const[y,l]of Object.entries(f)){let d=l;if(s.namespace&&v(l))if(r.variables.some(A=>A.name===l.name))d=l;else{const A=Array.isArray(s.namespace)?s.namespace:[s.namespace];let _=!1;for(const P of A){const p=`${P}.${y}`;if(p!==l.name&&r.variables.some(j=>j.name===p)){d={type:"reference",name:p},_=!0;break}}_||(d=y)}const g=s.values.find(A=>A.key===y&&A.modifiers.length===0),m={type:"utility",name:t,value:y,declarations:{},variables:[],children:[],modifiers:[]},F=k(m,r);if(m.declarations=i({...F,value:d})??{},V(m.declarations,F),g||(s.values.push({key:y,value:d,modifiers:[]}),e.children.push(m)),o&&o.length>0){const A=o.map(p=>p.key),P=ie(A).filter(p=>!s.values.find(j=>j.key===y&&j.modifiers.length===p.length&&j.modifiers.every(S=>p.includes(S)))).reduce((p,j)=>{const S=new Map;for(const he of j){const H=o.find($e=>$e.key.includes(he));H&&q(H)&&S.set(he,H)}return s.values.push({key:y,value:d,modifiers:j}),p.push(se(m,r,S)),p},[]);e.children.push(...P)}}}};return r.utilities.push(s),s.create}}function ae(e,r){return function(t,i){const c=r.themes.find(o=>o.name===t),s=c??{type:"theme",name:t,declarations:{},variables:[],children:[]};c||r.themes.push(s);const a=k(s,r);return i&&i(a),s}}function ue(e,r){return function(t){const i={type:"recipe",...t};return i._runtime=ye(i,r),me(i,r),r.recipes.push(i),i}}function le(e,r){const n=e.autogenerate(r);return Object.keys(n)[0]??"default"}function B(e,r){const n={};for(const[t,i]of Object.entries(e))if(de(i)){const c={};for(const[s,a]of Object.entries(i)){const o=D(r,s);o?c[s]=le(o,a):console.warn(`[styleframe] Utility "${s}" not found in registry. Skipping runtime generation for this declaration.`)}n[t]=c}else if(typeof i=="boolean")n[t]=i;else{const c=D(r,t);c?n[t]=le(c,i):console.warn(`[styleframe] Utility "${t}" not found in registry. Skipping runtime generation for this declaration.`)}return n}function ye(e,r){const n={};if(e.base&&(n.base=B(e.base,r)),e.variants){const t={};for(const[i,c]of Object.entries(e.variants)){const s={};for(const[a,o]of Object.entries(c))o==null?s[a]=null:s[a]=B(o,r);t[i]=s}n.variants=t}return e.defaultVariants&&(n.defaultVariants={...e.defaultVariants}),e.compoundVariants&&(n.compoundVariants=e.compoundVariants.map(t=>({match:{...t.match},css:B(t.css,r)}))),n}function de(e){return!v(e)&&typeof e=="object"&&e!==null}function K(e,r){const n=(t,i,c)=>{let s=r.get(t);s||(s=[],r.set(t,s)),s.push({value:i,modifiers:c})};for(const[t,i]of Object.entries(e))if(de(i)){const c=t.split(":");for(const[s,a]of Object.entries(i))n(s,a,c)}else n(t,i,[])}function D(e,r){const n=e.utilities.find(i=>i.name===r);if(n)return n;const t=r.replace(/[A-Z]/g,i=>`-${i.toLowerCase()}`);return e.utilities.find(i=>i.name===t)}function me(e,r){const n=new Map;if(e.base&&K(e.base,n),e.variants)for(const i of Object.values(e.variants))for(const c of Object.values(i))K(c,n);if(e.compoundVariants)for(const i of e.compoundVariants)i.css&&K(i.css,n);const t=new Map;for(const[i,c]of n){const s=D(r,i);if(!s){console.warn(`[styleframe] Utility "${i}" not found in registry. Skipping.`);continue}for(const a of c){const o=[];for(const f of a.modifiers){if(!t.has(f))try{t.set(f,ee(r,f))}catch{console.warn(`[styleframe] Modifier "${f}" not found in registry. Skipping modifier for utility "${i}".`),t.set(f,null)}const y=t.get(f);y&&o.push(y)}s.create([a.value],o.length>0?o:void 0)}}}function Oe(e){const r=x("sf-"),n=ce(),t={...e},i=fe(n,n),c=oe(n,n),s=ue(n,n),a=ae(n,n),{variable:o,selector:f,atRule:y,keyframes:l,media:d,ref:g,css:m}=k(n,n);return{id:r,root:n,variable:o,selector:f,utility:i,modifier:c,recipe:s,theme:a,atRule:y,keyframes:l,media:d,ref:g,css:m,options:t}}u.applyModifiers=se,u.capitalizeFirst=ke,u.combineKeys=ie,u.createAtRuleFunction=T,u.createCssFunction=z,u.createDeclarationsCallbackContext=k,u.createKeyframesFunction=Y,u.createMediaFunction=G,u.createModifierFunction=oe,u.createRecipeFunction=ue,u.createRefFunction=Z,u.createRoot=ce,u.createSelectorFunction=J,u.createThemeFunction=ae,u.createUtilityFunction=fe,u.createVariableFunction=Q,u.deepClone=O,u.generateRandomId=x,u.generateRecipeRuntime=ye,u.getModifier=ee,u.getUtility=Ve,u.getVariable=Re,u.isAtRule=ge,u.isCSS=M,u.isContainer=L,u.isModifier=q,u.isObject=b,u.isPrimitiveTokenValue=I,u.isRecipe=je,u.isRef=v,u.isRoot=R,u.isSelector=pe,u.isStyleframe=ve,u.isTheme=Ae,u.isToken=h,u.isTokenEqual=$,u.isTokenValue=C,u.isUtility=be,u.isVariable=W,u.merge=Me,u.mergeContainers=N,u.mergeThemesArray=re,u.mergeVariablesArray=ne,u.parseDeclarationsBlock=V,u.processRecipeUtilities=me,u.rfdc=X,u.styleframe=Oe,u.transformUtilityKey=U,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@styleframe/core",
3
- "version": "2.6.0",
3
+ "version": "3.0.0",
4
4
  "type": "module",
5
5
  "types": "./dist/styleframe.d.ts",
6
6
  "module": "./dist/styleframe.js",
@@ -22,12 +22,12 @@
22
22
  "csstype": "^3.1.3"
23
23
  },
24
24
  "peerDependencies": {
25
- "@styleframe/license": "^2.0.0"
25
+ "@styleframe/license": "^2.0.2"
26
26
  },
27
27
  "devDependencies": {
28
- "@styleframe/config-typescript": "^2",
29
- "@styleframe/config-vite": "^2",
30
- "@styleframe/license": "^2.0.0",
28
+ "@styleframe/config-typescript": "^3.0.0",
29
+ "@styleframe/config-vite": "^3.0.0",
30
+ "@styleframe/license": "^2.0.2",
31
31
  "@vitest/coverage-v8": "^3.2.4",
32
32
  "typescript": "^5.8.3",
33
33
  "vite": "^7.0.6",