@styleframe/loader 2.2.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,165 +1,194 @@
1
1
  (function(global, factory) {
2
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("node:fs/promises"), require("node:path"), require("@styleframe/license"), require("c12")) : typeof define === "function" && define.amd ? define(["exports", "node:fs/promises", "node:path", "@styleframe/license", "c12"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.loader = {}, global.promises, global.path, global.license, global.c12));
3
- })(this, (function(exports2, promises, path, license, c12) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("node:fs/promises"), require("node:path"), require("@styleframe/license"), require("chokidar"), require("jiti"), require("node:fs")) : typeof define === "function" && define.amd ? define(["exports", "node:fs/promises", "node:path", "@styleframe/license", "chokidar", "jiti", "node:fs"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.loader = {}, global.promises, global.path, global.license, global.chokidar, global.jiti, global.node_fs));
3
+ })(this, (function(exports2, promises, path, license, chokidar, jiti, node_fs) {
4
4
  "use strict";
5
- const N = ["charset", "import", "namespace"], R$1 = ["layer"], D$1 = ({ name: e }) => `[data-theme="${e}"]`, I = ({
5
+ const F$1 = ["charset", "import", "namespace"], L$1 = ["layer"], D = ({ name: e }) => `[data-theme="${e}"]`, x$1 = ({
6
6
  name: e,
7
7
  value: t,
8
- modifiers: n
9
- }) => `._${[...n, e, t].filter(Boolean).join("\\:")}`, w = ({ name: e }) => e;
10
- function L(e, t) {
8
+ modifiers: r
9
+ }) => `._${[...r, e, ...t === "default" ? [] : [t]].filter(Boolean).join("\\:").replace(/[[\].#()%,]/g, "\\$&")}`, w = ({ name: e }) => e.replace(/^\.+|\.+$/g, "").replace(/\.+/g, "--");
10
+ function I$1(e, t) {
11
11
  return `@${e}${t ? " " : ""}${t}`;
12
12
  }
13
- const P$1 = /\d/, M$1 = ["-", "_", "/", "."];
14
- function $$1(e = "") {
15
- if (!P$1.test(e))
13
+ const U = /\d/, P$1 = ["-", "_", "/", "."];
14
+ function M(e = "") {
15
+ if (!U.test(e))
16
16
  return e !== e.toLowerCase();
17
17
  }
18
- function U$1(e, t) {
19
- const n = M$1, r = [];
18
+ function N(e, t) {
19
+ const r = P$1, n = [];
20
20
  if (!e || typeof e != "string")
21
- return r;
22
- let c = "", a, i;
23
- for (const s of e) {
24
- const o = n.includes(s);
25
- if (o === true) {
26
- r.push(c), c = "", a = void 0;
21
+ return n;
22
+ let o = "", s, u;
23
+ for (const a of e) {
24
+ const c = r.includes(a);
25
+ if (c === true) {
26
+ n.push(o), o = "", s = void 0;
27
27
  continue;
28
28
  }
29
- const u = $$1(s);
30
- if (i === false) {
31
- if (a === false && u === true) {
32
- r.push(c), c = s, a = u;
29
+ const i = M(a);
30
+ if (u === false) {
31
+ if (s === false && i === true) {
32
+ n.push(o), o = a, s = i;
33
33
  continue;
34
34
  }
35
- if (a === true && u === false && c.length > 1) {
36
- const f = c.at(-1);
37
- r.push(c.slice(0, Math.max(0, c.length - 1))), c = f + s, a = u;
35
+ if (s === true && i === false && o.length > 1) {
36
+ const f = o.at(-1);
37
+ n.push(o.slice(0, Math.max(0, o.length - 1))), o = f + a, s = i;
38
38
  continue;
39
39
  }
40
40
  }
41
- c += s, a = u, i = o;
41
+ o += a, s = i, u = c;
42
42
  }
43
- return r.push(c), r;
43
+ return n.push(o), n;
44
44
  }
45
- function _$1(e, t) {
46
- return e ? (Array.isArray(e) ? e : U$1(e)).map((n) => n.toLowerCase()).join("-") : "";
45
+ function k(e) {
46
+ return e ? e[0].toUpperCase() + e.slice(1) : "";
47
47
  }
48
- function k$1(e) {
48
+ function V$1(e) {
49
+ return e ? e[0].toLowerCase() + e.slice(1) : "";
50
+ }
51
+ function q$1(e, t) {
52
+ return e ? (Array.isArray(e) ? e : N(e)).map((r) => k(r)).join("") : "";
53
+ }
54
+ function K(e, t) {
55
+ return V$1(q$1(e || ""));
56
+ }
57
+ function z$1(e, t) {
58
+ return e ? (Array.isArray(e) ? e : N(e)).map((r) => r.toLowerCase()).join("-") : "";
59
+ }
60
+ function H(e) {
49
61
  return ` ${e}`;
50
62
  }
51
- function V(e) {
63
+ function Q$1(e) {
52
64
  return e.split(`
53
- `).map((t) => k$1(t)).join(`
65
+ `).map((t) => H(t)).join(`
54
66
  `);
55
67
  }
56
- function x(e) {
57
- return _$1(e);
68
+ function J$1(e) {
69
+ return e === e.toUpperCase();
70
+ }
71
+ function Z$1(e) {
72
+ return K(e);
73
+ }
74
+ function W$1(e) {
75
+ return z$1(e);
58
76
  }
59
- function K$1(e) {
60
- return x(e);
77
+ function G$1(e) {
78
+ return W$1(e);
61
79
  }
62
- function B$1(e, t) {
63
- return `${e.startsWith("--") ? e : K$1(e)}: ${t};`;
80
+ function O(e, t) {
81
+ return `${e.startsWith("--") ? e : G$1(e)}: ${t};`;
64
82
  }
65
- function q$1(e) {
83
+ function Y$1(e) {
66
84
  return `{${e.length > 0 ? `
67
- ` : ""}${e.map((t) => `${V(`${t}`)}
85
+ ` : ""}${e.map((t) => `${Q$1(`${t}`)}
68
86
  `).join("")}}`;
69
87
  }
70
- function O$1(e) {
88
+ function E$1(e) {
71
89
  return `--${(e.startsWith("--") ? e.slice(2) : e).replace(/[^a-zA-Z0-9_\-\u0080-\uFFFF]/g, "-") || "unknown-variable"}`;
72
90
  }
73
- function z$1(e, t) {
74
- return B$1(O$1(e), t);
91
+ function X$1(e, t) {
92
+ return O(E$1(e), t);
75
93
  }
76
- function H$1(e, t) {
77
- return `var(${O$1(e)}${t ? `, ${t}` : ""})`;
94
+ function ee$1(e, t) {
95
+ return `var(${E$1(e)}${t ? `, ${t}` : ""})`;
78
96
  }
79
- function C$1(e, t) {
80
- return `${e} ${q$1(t)}`;
97
+ function R$1(e, t) {
98
+ return `${e} ${Y$1(t)}`;
81
99
  }
82
- function Q$1(e) {
83
- return function(n, r) {
84
- return Object.entries(n).map(([c, a]) => B$1(c, e(a, r)));
100
+ function te$1(e) {
101
+ return function(r, n) {
102
+ return Object.entries(r).map(([o, s]) => O(o, e(s, n)));
85
103
  };
86
104
  }
87
- function E$1(e) {
88
- return function(n, r) {
89
- const a = (r.variables?.name ?? w)({ name: n.name });
90
- return z$1(a, e(n.value, r));
105
+ function B(e) {
106
+ return function(r, n) {
107
+ const s = (n.variables?.name ?? w)({ name: r.name });
108
+ return X$1(s, e(r.value, n));
91
109
  };
92
110
  }
93
111
  function S$1(e) {
94
- const t = E$1(e), n = Q$1(e);
95
- return function(c, a, i) {
96
- const { variables: s, declarations: o, children: u } = a, f = c === ":root", l = (s ?? []).map(
97
- (A2) => t(A2, i)
98
- ), m2 = n(
99
- o ?? {},
100
- i
101
- ), y = (u ?? []).map(
102
- (A2) => e(A2, i)
103
- ), d = l.length > 0, h = m2.length > 0, v = y.length > 0;
104
- return f ? `${d || h ? C$1(c, [
112
+ const t = B(e), r = te$1(e);
113
+ return function(o, s, u) {
114
+ const { variables: a, declarations: c, children: i } = s, f = o === ":root", l = (a ?? []).map(
115
+ (A2) => t(A2, u)
116
+ ), m = r(
117
+ c ?? {},
118
+ u
119
+ ), y = (i ?? []).map(
120
+ (A2) => e(A2, u)
121
+ ), p2 = l.length > 0, b = m.length > 0, C2 = y.length > 0;
122
+ return f ? `${p2 || b ? R$1(o, [
105
123
  ...l,
106
- ...d && h ? [""] : [],
107
- ...m2
108
- ]) : ""}${v && (d || h) ? `
124
+ ...p2 && b ? [""] : [],
125
+ ...m
126
+ ]) : ""}${C2 && (p2 || b) ? `
109
127
 
110
128
  ` : ""}${y.join(`
111
129
 
112
- `)}` : C$1(c, [
130
+ `)}` : R$1(o, [
113
131
  ...l,
114
- ...d && (v || h) ? [""] : [],
115
- ...m2,
116
- ...h && v ? [""] : [],
132
+ ...p2 && (C2 || b) ? [""] : [],
133
+ ...m,
134
+ ...b && C2 ? [""] : [],
117
135
  ...y.flatMap(
118
- (A2, F2) => F2 === y.length - 1 ? [A2] : [A2, ""]
136
+ (A2, _2) => _2 === y.length - 1 ? [A2] : [A2, ""]
119
137
  )
120
138
  ]);
121
139
  };
122
140
  }
123
- function Z(e) {
141
+ function re$1(e) {
124
142
  const t = S$1(e);
125
- return function(r, c) {
126
- const a = N.includes(r.identifier), i = R$1.includes(
127
- r.identifier
128
- ), s = Object.keys(r.declarations).length > 0, o = r.variables.length > 0, u = r.children.length > 0, f = L(r.identifier, r.rule);
129
- return a || i && !(s || o || u) ? `${f};` : t(f, r, c);
143
+ return function(n, o) {
144
+ const s = F$1.includes(n.identifier), u = L$1.includes(
145
+ n.identifier
146
+ ), a = Object.keys(n.declarations).length > 0, c = n.variables.length > 0, i = n.children.length > 0, f = I$1(n.identifier, n.rule);
147
+ return s || u && !(a || c || i) ? `${f};` : t(f, n, o);
130
148
  };
131
149
  }
132
- function W$1(e) {
150
+ function ne$1(e) {
151
+ return function(r, n) {
152
+ return r.value.map((o) => e(o, n)).join("").trim();
153
+ };
154
+ }
155
+ function oe(e) {
133
156
  return typeof e == "object" && e !== null;
134
157
  }
135
- function b$1(e, t) {
136
- return W$1(e) && "type" in e && e.type === t;
158
+ function h(e, t) {
159
+ return oe(e) && "type" in e && e.type === t;
137
160
  }
138
- function J$1(e) {
139
- return b$1(e, "variable");
161
+ function ce$1(e) {
162
+ return h(e, "variable");
140
163
  }
141
- function G$1(e) {
142
- return b$1(e, "reference");
164
+ function ue$1(e) {
165
+ return h(e, "reference");
143
166
  }
144
- function Y$1(e) {
145
- return b$1(e, "selector");
167
+ function v$1(e) {
168
+ return h(e, "selector");
146
169
  }
147
- function X$1(e) {
148
- return b$1(e, "at-rule");
170
+ function ie(e) {
171
+ return h(e, "at-rule");
149
172
  }
150
- function ee(e) {
151
- return b$1(e, "utility");
173
+ function se(e) {
174
+ return h(e, "utility");
152
175
  }
153
- function te(e) {
154
- return b$1(e, "css");
176
+ function ae$1(e) {
177
+ return h(e, "css");
178
+ }
179
+ function le$1(e) {
180
+ return h(e, "theme");
155
181
  }
156
- function ne(e) {
157
- return b$1(e, "theme");
182
+ function T$1(e) {
183
+ return h(e, "root");
158
184
  }
159
- function re(e) {
160
- return b$1(e, "root");
185
+ function fe$1(e) {
186
+ return h(e, "recipe");
161
187
  }
162
- function g$1(e) {
188
+ function me$1(e) {
189
+ return e.charAt(0).toUpperCase() + e.slice(1);
190
+ }
191
+ function g(e) {
163
192
  if (e instanceof Buffer)
164
193
  return Buffer.from(e);
165
194
  const t = e.constructor;
@@ -169,225 +198,262 @@
169
198
  e.byteLength / e.BYTES_PER_ELEMENT || 1
170
199
  );
171
200
  }
172
- function oe(e) {
201
+ function pe$1(e) {
173
202
  if (e = e || {}, e.circular)
174
- return ue$1(e);
203
+ return ye$1(e);
175
204
  const t = /* @__PURE__ */ new Map();
176
- if (t.set(Date, (i) => new Date(i)), t.set(
205
+ if (t.set(Date, (u) => new Date(u)), t.set(
177
206
  Map,
178
- (i, s) => new Map(r(Array.from(i), s))
207
+ (u, a) => new Map(n(Array.from(u), a))
179
208
  ), t.set(
180
209
  Set,
181
- (i, s) => new Set(r(Array.from(i), s))
210
+ (u, a) => new Set(n(Array.from(u), a))
182
211
  ), e.constructorHandlers)
183
- for (const i of e.constructorHandlers)
184
- t.set(i[0], i[1]);
185
- let n;
186
- return e.proto ? a : c;
187
- function r(i, s) {
188
- const o = Object.keys(i), u = Array.from({ length: o.length });
189
- for (let f = 0; f < o.length; f++) {
190
- const l = o[f], m2 = i[l];
191
- typeof m2 != "object" || m2 === null ? u[l] = m2 : m2.constructor !== Object && (n = t.get(m2.constructor)) ? u[l] = n(m2, s) : ArrayBuffer.isView(m2) ? u[l] = g$1(m2) : u[l] = s(m2);
212
+ for (const u of e.constructorHandlers)
213
+ t.set(u[0], u[1]);
214
+ let r;
215
+ return e.proto ? s : o;
216
+ function n(u, a) {
217
+ const c = Object.keys(u), i = Array.from({ length: c.length });
218
+ for (let f = 0; f < c.length; f++) {
219
+ const l = c[f], m = u[l];
220
+ typeof m != "object" || m === null ? i[l] = m : m.constructor !== Object && (r = t.get(m.constructor)) ? i[l] = r(m, a) : ArrayBuffer.isView(m) ? i[l] = g(m) : i[l] = a(m);
192
221
  }
193
- return u;
222
+ return i;
194
223
  }
195
- function c(i) {
196
- if (typeof i != "object" || i === null) return i;
197
- if (Array.isArray(i)) return r(i, c);
198
- if (i.constructor !== Object && (n = t.get(i.constructor)))
199
- return n(i, c);
200
- const s = {};
201
- for (const o in i) {
202
- if (Object.hasOwnProperty.call(i, o) === false) continue;
203
- const u = i[o];
204
- typeof u != "object" || u === null ? s[o] = u : u.constructor !== Object && (n = t.get(u.constructor)) ? s[o] = n(u, c) : ArrayBuffer.isView(u) ? s[o] = g$1(u) : s[o] = c(u);
224
+ function o(u) {
225
+ if (typeof u != "object" || u === null) return u;
226
+ if (Array.isArray(u)) return n(u, o);
227
+ if (u.constructor !== Object && (r = t.get(u.constructor)))
228
+ return r(u, o);
229
+ const a = {};
230
+ for (const c in u) {
231
+ if (Object.hasOwnProperty.call(u, c) === false) continue;
232
+ const i = u[c];
233
+ typeof i != "object" || i === null ? a[c] = i : i.constructor !== Object && (r = t.get(i.constructor)) ? a[c] = r(i, o) : ArrayBuffer.isView(i) ? a[c] = g(i) : a[c] = o(i);
205
234
  }
206
- return s;
207
- }
208
- function a(i) {
209
- if (typeof i != "object" || i === null) return i;
210
- if (Array.isArray(i)) return r(i, a);
211
- if (i.constructor !== Object && (n = t.get(i.constructor)))
212
- return n(i, a);
213
- const s = {};
214
- for (const o in i) {
215
- const u = i[o];
216
- typeof u != "object" || u === null ? s[o] = u : u.constructor !== Object && (n = t.get(u.constructor)) ? s[o] = n(u, a) : ArrayBuffer.isView(u) ? s[o] = g$1(u) : s[o] = a(u);
235
+ return a;
236
+ }
237
+ function s(u) {
238
+ if (typeof u != "object" || u === null) return u;
239
+ if (Array.isArray(u)) return n(u, s);
240
+ if (u.constructor !== Object && (r = t.get(u.constructor)))
241
+ return r(u, s);
242
+ const a = {};
243
+ for (const c in u) {
244
+ const i = u[c];
245
+ typeof i != "object" || i === null ? a[c] = i : i.constructor !== Object && (r = t.get(i.constructor)) ? a[c] = r(i, s) : ArrayBuffer.isView(i) ? a[c] = g(i) : a[c] = s(i);
217
246
  }
218
- return s;
247
+ return a;
219
248
  }
220
249
  }
221
- function ue$1(e) {
222
- const t = [], n = [], r = /* @__PURE__ */ new Map();
223
- if (r.set(Date, (o) => new Date(o)), r.set(
250
+ function ye$1(e) {
251
+ const t = [], r = [], n = /* @__PURE__ */ new Map();
252
+ if (n.set(Date, (c) => new Date(c)), n.set(
224
253
  Map,
225
- (o, u) => new Map(a(Array.from(o), u))
226
- ), r.set(
254
+ (c, i) => new Map(s(Array.from(c), i))
255
+ ), n.set(
227
256
  Set,
228
- (o, u) => new Set(a(Array.from(o), u))
257
+ (c, i) => new Set(s(Array.from(c), i))
229
258
  ), e.constructorHandlers)
230
- for (const o of e.constructorHandlers)
231
- r.set(o[0], o[1]);
232
- let c;
233
- return e.proto ? s : i;
234
- function a(o, u) {
235
- const f = Object.keys(o), l = Array.from({ length: f.length });
236
- for (let m2 = 0; m2 < f.length; m2++) {
237
- const y = f[m2], d = o[y];
238
- if (typeof d != "object" || d === null)
239
- l[y] = d;
240
- else if (d.constructor !== Object && (c = r.get(d.constructor)))
241
- l[y] = c(d, u);
242
- else if (ArrayBuffer.isView(d))
243
- l[y] = g$1(d);
259
+ for (const c of e.constructorHandlers)
260
+ n.set(c[0], c[1]);
261
+ let o;
262
+ return e.proto ? a : u;
263
+ function s(c, i) {
264
+ const f = Object.keys(c), l = Array.from({ length: f.length });
265
+ for (let m = 0; m < f.length; m++) {
266
+ const y = f[m], p2 = c[y];
267
+ if (typeof p2 != "object" || p2 === null)
268
+ l[y] = p2;
269
+ else if (p2.constructor !== Object && (o = n.get(p2.constructor)))
270
+ l[y] = o(p2, i);
271
+ else if (ArrayBuffer.isView(p2))
272
+ l[y] = g(p2);
244
273
  else {
245
- const h = t.indexOf(d);
246
- h !== -1 ? l[y] = n[h] : l[y] = u(d);
274
+ const b = t.indexOf(p2);
275
+ b !== -1 ? l[y] = r[b] : l[y] = i(p2);
247
276
  }
248
277
  }
249
278
  return l;
250
279
  }
251
- function i(o) {
252
- if (typeof o != "object" || o === null) return o;
253
- if (Array.isArray(o)) return a(o, i);
254
- if (o.constructor !== Object && (c = r.get(o.constructor)))
255
- return c(o, i);
256
- const u = {};
257
- t.push(o), n.push(u);
258
- for (const f in o) {
259
- if (Object.hasOwnProperty.call(o, f) === false) continue;
260
- const l = o[f];
280
+ function u(c) {
281
+ if (typeof c != "object" || c === null) return c;
282
+ if (Array.isArray(c)) return s(c, u);
283
+ if (c.constructor !== Object && (o = n.get(c.constructor)))
284
+ return o(c, u);
285
+ const i = {};
286
+ t.push(c), r.push(i);
287
+ for (const f in c) {
288
+ if (Object.hasOwnProperty.call(c, f) === false) continue;
289
+ const l = c[f];
261
290
  if (typeof l != "object" || l === null)
262
- u[f] = l;
263
- else if (l.constructor !== Object && (c = r.get(l.constructor)))
264
- u[f] = c(l, i);
291
+ i[f] = l;
292
+ else if (l.constructor !== Object && (o = n.get(l.constructor)))
293
+ i[f] = o(l, u);
265
294
  else if (ArrayBuffer.isView(l))
266
- u[f] = g$1(l);
295
+ i[f] = g(l);
267
296
  else {
268
- const m2 = t.indexOf(l);
269
- m2 !== -1 ? u[f] = n[m2] : u[f] = i(l);
297
+ const m = t.indexOf(l);
298
+ m !== -1 ? i[f] = r[m] : i[f] = u(l);
270
299
  }
271
300
  }
272
- return t.pop(), n.pop(), u;
301
+ return t.pop(), r.pop(), i;
273
302
  }
274
- function s(o) {
275
- if (typeof o != "object" || o === null) return o;
276
- if (Array.isArray(o)) return a(o, s);
277
- if (o.constructor !== Object && (c = r.get(o.constructor)))
278
- return c(o, s);
279
- const u = {};
280
- t.push(o), n.push(u);
281
- for (const f in o) {
282
- const l = o[f];
303
+ function a(c) {
304
+ if (typeof c != "object" || c === null) return c;
305
+ if (Array.isArray(c)) return s(c, a);
306
+ if (c.constructor !== Object && (o = n.get(c.constructor)))
307
+ return o(c, a);
308
+ const i = {};
309
+ t.push(c), r.push(i);
310
+ for (const f in c) {
311
+ const l = c[f];
283
312
  if (typeof l != "object" || l === null)
284
- u[f] = l;
285
- else if (l.constructor !== Object && (c = r.get(l.constructor)))
286
- u[f] = c(l, s);
313
+ i[f] = l;
314
+ else if (l.constructor !== Object && (o = n.get(l.constructor)))
315
+ i[f] = o(l, a);
287
316
  else if (ArrayBuffer.isView(l))
288
- u[f] = g$1(l);
317
+ i[f] = g(l);
289
318
  else {
290
- const m2 = t.indexOf(l);
291
- m2 !== -1 ? u[f] = n[m2] : u[f] = s(l);
319
+ const m = t.indexOf(l);
320
+ m !== -1 ? i[f] = r[m] : i[f] = a(l);
292
321
  }
293
322
  }
294
- return t.pop(), n.pop(), u;
323
+ return t.pop(), r.pop(), i;
295
324
  }
296
325
  }
297
- oe();
298
- function ce(e) {
299
- return function(n, r) {
300
- return n.value.map((c) => e(c, r)).join("").trim();
301
- };
302
- }
303
- function ie(e) {
304
- return function(n, r) {
305
- return n != null ? `${n}` : "";
326
+ pe$1();
327
+ function de$1(e) {
328
+ return function(r, n) {
329
+ return r != null ? `${r}` : "";
306
330
  };
307
331
  }
308
- function se(e) {
309
- return function(n, r) {
310
- const a = (r.variables?.name ?? w)({ name: n.name });
311
- return H$1(
312
- a,
313
- n.fallback ? e(n.fallback, r) : void 0
332
+ function he(e) {
333
+ return function(r, n) {
334
+ const s = (n.variables?.name ?? w)({ name: r.name });
335
+ return ee$1(
336
+ s,
337
+ r.fallback ? e(r.fallback, n) : void 0
314
338
  );
315
339
  };
316
340
  }
317
- function ae(e) {
341
+ function be$1(e) {
318
342
  const t = S$1(e);
319
- return function(r, c) {
320
- return r.themes.reduce(
321
- (a, i) => (a.push(e(i, c)), a),
322
- [t(":root", r, c)]
343
+ return function(n, o) {
344
+ return n.themes.reduce(
345
+ (s, u) => (s.push(e(u, o)), s),
346
+ [t(":root", n, o)]
323
347
  // Default theme (root)
324
348
  ).join(`
325
349
 
326
350
  `);
327
351
  };
328
352
  }
329
- function le(e) {
353
+ function Ae$1(e) {
330
354
  const t = S$1(e);
331
- return function(r, c) {
332
- return t(r.query, r, c);
355
+ return function(n, o) {
356
+ return t(n.query, n, o);
333
357
  };
334
358
  }
335
- function fe(e) {
359
+ function ge(e) {
336
360
  const t = S$1(e);
337
- return function(r, c) {
338
- const i = (c.theme?.selector ?? D$1)({ name: r.name });
339
- return t(i, r, c);
361
+ return function(n, o) {
362
+ const u = (o.themes?.selector ?? D)({ name: n.name });
363
+ return t(u, n, o);
340
364
  };
341
365
  }
342
- function me(e) {
366
+ function Se(e) {
343
367
  const t = S$1(e);
344
- return function(r, c) {
345
- const a = [], s = (c.utilities?.selector ?? I)({
346
- name: r.name,
347
- value: r.value,
348
- modifiers: r.modifiers
368
+ return function(n, o) {
369
+ const s = [], a = (o.utilities?.selector ?? x$1)({
370
+ name: n.name,
371
+ value: n.value,
372
+ modifiers: n.modifiers
349
373
  });
350
- return a.push(t(s, r, c)), a.join(`
374
+ return s.push(t(a, n, o)), s.join(`
351
375
 
352
376
  `);
353
377
  };
354
378
  }
355
- function p$1(e, t) {
356
- const n = ae(p$1), r = le(p$1), c = me(p$1), a = Z(p$1), i = fe(p$1), s = E$1(p$1), o = se(p$1), u = ce(p$1), f = ie();
379
+ function d(e, t) {
380
+ const r = be$1(d), n = Ae$1(d), o = Se(d), s = re$1(d), u = ge(d), a = B(d), c = he(d), i = ne$1(d), f = de$1();
357
381
  switch (true) {
358
- case Y$1(e):
359
- return r(e, t);
360
- case ee(e):
361
- return c(e, t);
362
- case X$1(e):
363
- return a(e, t);
364
- case re(e):
382
+ case v$1(e):
365
383
  return n(e, t);
366
- case ne(e):
367
- return i(e, t);
368
- case J$1(e):
369
- return s(e, t);
370
- case G$1(e):
384
+ case se(e):
371
385
  return o(e, t);
372
- case te(e):
386
+ case ie(e):
387
+ return s(e, t);
388
+ case T$1(e):
389
+ return r(e, t);
390
+ case le$1(e):
373
391
  return u(e, t);
392
+ case ce$1(e):
393
+ return a(e, t);
394
+ case ue$1(e):
395
+ return c(e, t);
396
+ case ae$1(e):
397
+ return i(e, t);
374
398
  default:
375
399
  return f(e, t);
376
400
  }
377
401
  }
378
- function T$1(e, t) {
402
+ function Ce(e) {
403
+ return function(r, n) {
404
+ let o = r._exportName;
405
+ o || (o = Z$1(r.name), r.name[0] && J$1(r.name[0]) && (o = me$1(o)));
406
+ const s = `${o}Recipe`, u = r._runtime ?? {};
407
+ return `const ${s} = ${JSON.stringify(
408
+ u,
409
+ null,
410
+ 4
411
+ )} as const satisfies RecipeRuntime;
412
+
413
+ export const ${o} = createRecipe("${r.name}", ${s});
414
+ `;
415
+ };
416
+ }
417
+ function je(e) {
418
+ return e.filter(
419
+ (t) => v$1(t) && !!t._exportName
420
+ );
421
+ }
422
+ function ve(e) {
423
+ return function(r, n) {
424
+ const o = je(r.children), s = r.recipes.length > 0, u = o.length > 0;
425
+ if (!s && !u)
426
+ return "";
427
+ const a = [];
428
+ return s && (a.push(`import { createRecipe } from '@styleframe/runtime';
429
+ import type { RecipeRuntime } from '@styleframe/runtime';
430
+ `), a.push(e(r.recipes, n))), u && a.push(e(o, n)), a.join(`
431
+ `);
432
+ };
433
+ }
434
+ function Re$1(e) {
435
+ return function(r, n) {
436
+ return r._exportName ? `export const ${r._exportName} = ${JSON.stringify(r.query)};
437
+ ` : "";
438
+ };
439
+ }
440
+ function j$1(e, t) {
441
+ const r = ve(j$1), n = Ce(), o = Re$1();
379
442
  switch (true) {
380
443
  case Array.isArray(e):
381
- return e.map((n) => T$1(n)).join(`
444
+ return e.map((s) => j$1(s, t)).join(`
382
445
  `);
383
- // case isRecipe(instance):
384
- // return consumeRecipe(instance, options);
385
- // break;
446
+ case T$1(e):
447
+ return r(e, t);
448
+ case fe$1(e):
449
+ return n(e, t);
450
+ case v$1(e):
451
+ return o(e, t);
386
452
  default:
387
453
  return "";
388
454
  }
389
455
  }
390
- const de = `-----BEGIN PUBLIC KEY-----
456
+ const $e = `-----BEGIN PUBLIC KEY-----
391
457
  MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAs7zAFssgxOMPeo80iig4
392
458
  qSSshgNOLnW1gd4tPUrsezndaUrAKlsAys6XD8kuF+bBEIR0uFNSgKlqINLjWM1n
393
459
  BiTUzCctodyRaq6/tyFSoPLD35iblkwtfxKPM42lAJZsyTu9qoBr8MJyXmhDLuqA
@@ -395,12 +461,12 @@ dQ8di7mQHz+mCy96jQR4lFSDfHMgl27qaAh5VboTBRxgZliN8D5Fl590QkS94wAj
395
461
  hC7NbH+hPcGc/qIaZSjZfyZeBIZS74qJkrzjEA7/pukROD8UQUrQ512HHZ6XlgMn
396
462
  4bWT2K9CpWbbhsKFTecCHuxlmPkFJNMuvAb/LdP08BSnpntlyAJcQeBrna2qBen+
397
463
  GwIDAQAB
398
- -----END PUBLIC KEY-----`, ye = "__licenseRequired", pe = "__licenseValidated";
399
- async function he(e) {
400
- const t = e.replace(/-----BEGIN PUBLIC KEY-----/, "").replace(/-----END PUBLIC KEY-----/, "").replace(/\s/g, ""), n = Uint8Array.from(atob(t), (r) => r.charCodeAt(0));
464
+ -----END PUBLIC KEY-----`, we = "__licenseRequired", Ne = "__licenseValidated";
465
+ async function Oe(e) {
466
+ const t = e.replace(/-----BEGIN PUBLIC KEY-----/, "").replace(/-----END PUBLIC KEY-----/, "").replace(/\s/g, ""), r = Uint8Array.from(atob(t), (n) => n.charCodeAt(0));
401
467
  return await crypto.subtle.importKey(
402
468
  "spki",
403
- n,
469
+ r,
404
470
  {
405
471
  name: "RSASSA-PKCS1-v1_5",
406
472
  hash: "SHA-256"
@@ -409,32 +475,32 @@ GwIDAQAB
409
475
  ["verify"]
410
476
  );
411
477
  }
412
- async function be({
478
+ async function Ee({
413
479
  payload: e,
414
480
  signature: t
415
481
  }) {
416
- const n = new TextEncoder().encode(e), r = Uint8Array.from(
482
+ const r = new TextEncoder().encode(e), n = Uint8Array.from(
417
483
  atob(t),
418
- (a) => a.charCodeAt(0)
419
- ), c = await he(de);
484
+ (s) => s.charCodeAt(0)
485
+ ), o = await Oe($e);
420
486
  if (!await crypto.subtle.verify(
421
487
  { name: "RSASSA-PKCS1-v1_5" },
422
- c,
423
- r,
424
- n
488
+ o,
489
+ n,
490
+ r
425
491
  ))
426
492
  throw new Error(
427
493
  "License validation failed: Invalid signature detected. The license may have been modified or corrupted."
428
494
  );
429
495
  return JSON.parse(e);
430
496
  }
431
- function Ae(e) {
432
- return Object.prototype.hasOwnProperty.call(e, ye);
497
+ function Be(e) {
498
+ return Object.prototype.hasOwnProperty.call(e, we);
433
499
  }
434
- async function ge(e) {
500
+ async function Te(e) {
435
501
  const t = Object.getOwnPropertyDescriptor(
436
502
  e,
437
- pe
503
+ Ne
438
504
  );
439
505
  if (!t?.value)
440
506
  return {
@@ -443,8 +509,8 @@ GwIDAQAB
443
509
  environment: "",
444
510
  valid: false
445
511
  };
446
- const n = t.value;
447
- if (typeof n != "object" || n === null || !("payload" in n) || !("signature" in n) || typeof n.payload != "string" || typeof n.signature != "string")
512
+ const r = t.value;
513
+ if (typeof r != "object" || r === null || !("payload" in r) || !("signature" in r) || typeof r.payload != "string" || typeof r.signature != "string")
448
514
  return {
449
515
  key: "",
450
516
  instanceId: "",
@@ -452,8 +518,8 @@ GwIDAQAB
452
518
  valid: false
453
519
  };
454
520
  try {
455
- return await be(
456
- n
521
+ return await Ee(
522
+ r
457
523
  );
458
524
  } catch {
459
525
  return {
@@ -464,7 +530,7 @@ GwIDAQAB
464
530
  };
465
531
  }
466
532
  }
467
- function Se(e) {
533
+ function _e(e) {
468
534
  const t = Math.floor(Math.random() * 100);
469
535
  e.root.children.push({
470
536
  type: "selector",
@@ -488,31 +554,36 @@ GwIDAQAB
488
554
  }
489
555
  });
490
556
  }
491
- function j(e, t = "") {
557
+ function $$1(e, t = "") {
492
558
  return {
493
559
  name: e,
494
560
  content: t
495
561
  };
496
562
  }
497
- async function Ce(e, {
563
+ async function Le(e, {
498
564
  type: t = "all",
499
- consumers: n = { css: p$1, ts: T$1 }
565
+ consumers: r = { css: d, ts: j$1 }
500
566
  } = {}) {
501
- const r = { files: [] }, c = e.options;
502
- if (Ae(e)) {
503
- const s = await ge(e);
504
- (!s.valid || s.instanceId !== e.id) && Se(e);
567
+ const n = { files: [] }, o = e.options;
568
+ if (Be(e)) {
569
+ const s = await Te(e);
570
+ (!s.valid || s.instanceId !== e.id) && _e(e);
505
571
  }
506
- const { recipes: a, ...i } = e.root;
507
572
  if (t === "all" || t === "css") {
508
- const s = j("index.css", n.css(i, c));
509
- r.files.push(s);
573
+ const s = $$1(
574
+ "index.css",
575
+ r.css(e.root, o)
576
+ );
577
+ n.files.push(s);
510
578
  }
511
579
  if (t === "all" || t === "ts") {
512
- const s = j("index.ts", n.ts([], c));
513
- r.files.push(s);
580
+ const s = $$1(
581
+ "index.ts",
582
+ r.ts(e.root, o)
583
+ );
584
+ n.files.push(s);
514
585
  }
515
- return r;
586
+ return n;
516
587
  }
517
588
  async function directoryExists(path2) {
518
589
  try {
@@ -528,7 +599,7 @@ GwIDAQAB
528
599
  environment: process.env.NODE_ENV || "development",
529
600
  isBuild: true
530
601
  });
531
- const output = await Ce(instance, transpiler);
602
+ const output = await Le(instance, transpiler);
532
603
  const outputDirExists = await directoryExists(outputDir);
533
604
  if (clean && outputDirExists) {
534
605
  await promises.rm(outputDir, { recursive: true });
@@ -543,40 +614,64 @@ GwIDAQAB
543
614
  await promises.writeFile(filePath, file.content);
544
615
  }
545
616
  }
546
- function k(e, r) {
547
- return function(t, ...i) {
548
- return {
549
- type: "css",
550
- value: t.reduce((o, u, c) => (o.push(u), c < i.length && o.push(i[c]), o), [])
551
- };
552
- };
553
- }
554
- function M(e) {
617
+ function S(e) {
555
618
  return typeof e == "object" && e !== null;
556
619
  }
557
620
  function p(e, r) {
558
- return M(e) && "type" in e && e.type === r;
621
+ return S(e) && "type" in e && e.type === r;
559
622
  }
560
- function B(e) {
623
+ function L(e) {
561
624
  return p(e, "variable");
562
625
  }
563
- function F(e) {
626
+ function A(e) {
564
627
  return p(e, "reference");
565
628
  }
566
- function T(e) {
629
+ function be(e) {
630
+ return p(e, "selector");
631
+ }
632
+ function q(e) {
633
+ return p(e, "modifier");
634
+ }
635
+ function E(e) {
567
636
  return p(e, "css");
568
637
  }
569
- function _(e) {
638
+ function Ae(e) {
639
+ return p(e, "recipe");
640
+ }
641
+ function G(e) {
570
642
  return typeof e == "string" || typeof e == "number" || typeof e == "boolean" || e === null;
571
643
  }
572
- function O(e) {
573
- return _(e) || F(e) || T(e) || Array.isArray(e) && e.every(O);
644
+ function $(e) {
645
+ return G(e) || A(e) || E(e) || Array.isArray(e) && e.every($);
646
+ }
647
+ function I(e) {
648
+ return S(e) && "children" in e && "declarations" in e && "variables" in e;
649
+ }
650
+ function z(e = (r) => r) {
651
+ return (r) => {
652
+ let n = r, t;
653
+ if (typeof n == "string" && n[0] === "@") {
654
+ const i = n.slice(1);
655
+ t = e(i), n = {
656
+ type: "reference",
657
+ name: i
658
+ };
659
+ } else A(n) ? t = e(n.name) : t = `[${r}]`;
660
+ return {
661
+ [t]: n
662
+ };
663
+ };
574
664
  }
575
- function C(e) {
576
- return M(e) && "children" in e && "declarations" in e && "variables" in e;
665
+ function W(e, r) {
666
+ return function(t, ...i) {
667
+ return {
668
+ type: "css",
669
+ value: t.reduce((o, u, s) => (o.push(u), s < i.length && o.push(i[s]), o), [])
670
+ };
671
+ };
577
672
  }
578
- function R(e, r) {
579
- return function(t, i, s) {
673
+ function C(e, r) {
674
+ return function(t, i, c) {
580
675
  const o = {
581
676
  type: "at-rule",
582
677
  identifier: t,
@@ -584,25 +679,25 @@ GwIDAQAB
584
679
  declarations: {},
585
680
  variables: [],
586
681
  children: []
587
- }, u = b(o, r);
588
- return typeof s == "function" ? o.declarations = s(u) ?? {} : s && (o.declarations = s), g(o.declarations, u), e.children.push(o), o;
682
+ }, u = v(o, r);
683
+ return typeof c == "function" ? o.declarations = c(u) ?? {} : c && (o.declarations = c), V(o.declarations, u), e.children.push(o), o;
589
684
  };
590
685
  }
591
- function S(e, r) {
592
- const n = R(e, r);
593
- return function(i, s) {
594
- return n("media", i, s);
686
+ function Y(e, r) {
687
+ const n = C(e, r);
688
+ return function(i, c) {
689
+ return n("media", i, c);
595
690
  };
596
691
  }
597
- function E(e, r) {
598
- const n = R(e, r);
599
- return function(i, s) {
600
- return n("keyframes", i, s);
692
+ function Z(e, r) {
693
+ const n = C(e, r);
694
+ return function(i, c) {
695
+ return n("keyframes", i, c);
601
696
  };
602
697
  }
603
- function P(e, r) {
698
+ function J(e, r) {
604
699
  return function(t, i) {
605
- return B(t) ? {
700
+ return L(t) ? {
606
701
  type: "reference",
607
702
  name: t.name,
608
703
  fallback: i
@@ -613,56 +708,56 @@ GwIDAQAB
613
708
  };
614
709
  };
615
710
  }
616
- function D(e, r) {
711
+ function Q(e, r) {
617
712
  return function(t, i) {
618
- const s = {
713
+ const c = {
619
714
  type: "selector",
620
715
  query: t,
621
716
  declarations: {},
622
717
  variables: [],
623
718
  children: []
624
- }, o = b(s, r);
625
- return typeof i == "function" ? s.declarations = i(o) ?? {} : C(i) ? (s.variables = i.variables, s.declarations = i.declarations, s.children = i.children) : s.declarations = i, g(s.declarations, o), e.children.push(s), s;
719
+ }, o = v(c, r);
720
+ 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;
626
721
  };
627
722
  }
628
- function H(e, r) {
629
- return function(t, i, s = {
723
+ function X(e, r) {
724
+ return function(t, i, c = {
630
725
  default: false
631
726
  }) {
632
727
  const o = typeof t == "string" ? t : t.name, u = e.variables.find(
633
728
  (f) => f.name === o
634
729
  );
635
- if (s.default && u)
730
+ if (c.default && u)
636
731
  return u;
637
732
  if (u)
638
733
  return u.value = i, u;
639
- const c = {
734
+ const s = {
640
735
  type: "variable",
641
736
  name: o,
642
737
  value: i
643
738
  };
644
- return e.variables.push(c), c;
739
+ return e.variables.push(s), s;
645
740
  };
646
741
  }
647
- function b(e, r) {
648
- const n = H(e), t = D(e, r), i = R(e, r), s = E(r, r), o = S(e, r), u = P(), c = k();
742
+ function v(e, r) {
743
+ const n = X(e), t = Q(e, r), i = C(e, r), c = Z(r, r), o = Y(e, r), u = J(), s = W();
649
744
  return {
650
745
  variable: n,
651
746
  selector: t,
652
- keyframes: s,
747
+ keyframes: c,
653
748
  atRule: i,
654
749
  media: o,
655
750
  ref: u,
656
- css: c
751
+ css: s
657
752
  };
658
753
  }
659
- function g(e, r) {
754
+ function V(e, r) {
660
755
  for (const n in e)
661
756
  if (n.startsWith("@")) {
662
757
  const t = e[n];
663
- if (typeof t == "object" && t !== null && !O(t)) {
664
- const i = n.replace(/^@(\w+).*/, "$1"), s = n.replace(`@${i}`, "").trim();
665
- r.atRule(i, s, t), delete e[n];
758
+ if (typeof t == "object" && t !== null && !$(t)) {
759
+ const i = n.replace(/^@(\w+).*/, "$1"), c = n.replace(`@${i}`, "").trim();
760
+ r.atRule(i, c, t), delete e[n];
666
761
  }
667
762
  } else if (/^[.&:]/.test(n)) {
668
763
  const t = e[n];
@@ -670,7 +765,7 @@ GwIDAQAB
670
765
  }
671
766
  return e;
672
767
  }
673
- function m(e) {
768
+ function j(e) {
674
769
  if (e instanceof Buffer)
675
770
  return Buffer.from(e);
676
771
  const r = e.constructor;
@@ -680,9 +775,9 @@ GwIDAQAB
680
775
  e.byteLength / e.BYTES_PER_ELEMENT || 1
681
776
  );
682
777
  }
683
- function K(e) {
778
+ function ee(e) {
684
779
  if (e = e || {}, e.circular)
685
- return U(e);
780
+ return te(e);
686
781
  const r = /* @__PURE__ */ new Map();
687
782
  if (r.set(Date, (o) => new Date(o)), r.set(
688
783
  Map,
@@ -694,12 +789,12 @@ GwIDAQAB
694
789
  for (const o of e.constructorHandlers)
695
790
  r.set(o[0], o[1]);
696
791
  let n;
697
- return e.proto ? s : i;
792
+ return e.proto ? c : i;
698
793
  function t(o, u) {
699
- const c = Object.keys(o), f = Array.from({ length: c.length });
700
- for (let a = 0; a < c.length; a++) {
701
- const l = c[a], y = o[l];
702
- typeof y != "object" || y === null ? f[l] = y : y.constructor !== Object && (n = r.get(y.constructor)) ? f[l] = n(y, u) : ArrayBuffer.isView(y) ? f[l] = m(y) : f[l] = u(y);
794
+ const s = Object.keys(o), f = Array.from({ length: s.length });
795
+ for (let l = 0; l < s.length; l++) {
796
+ const a = s[l], y = o[a];
797
+ 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);
703
798
  }
704
799
  return f;
705
800
  }
@@ -709,153 +804,161 @@ GwIDAQAB
709
804
  if (o.constructor !== Object && (n = r.get(o.constructor)))
710
805
  return n(o, i);
711
806
  const u = {};
712
- for (const c in o) {
713
- if (Object.hasOwnProperty.call(o, c) === false) continue;
714
- const f = o[c];
715
- typeof f != "object" || f === null ? u[c] = f : f.constructor !== Object && (n = r.get(f.constructor)) ? u[c] = n(f, i) : ArrayBuffer.isView(f) ? u[c] = m(f) : u[c] = i(f);
807
+ for (const s in o) {
808
+ if (Object.hasOwnProperty.call(o, s) === false) continue;
809
+ const f = o[s];
810
+ 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);
716
811
  }
717
812
  return u;
718
813
  }
719
- function s(o) {
814
+ function c(o) {
720
815
  if (typeof o != "object" || o === null) return o;
721
- if (Array.isArray(o)) return t(o, s);
816
+ if (Array.isArray(o)) return t(o, c);
722
817
  if (o.constructor !== Object && (n = r.get(o.constructor)))
723
- return n(o, s);
818
+ return n(o, c);
724
819
  const u = {};
725
- for (const c in o) {
726
- const f = o[c];
727
- typeof f != "object" || f === null ? u[c] = f : f.constructor !== Object && (n = r.get(f.constructor)) ? u[c] = n(f, s) : ArrayBuffer.isView(f) ? u[c] = m(f) : u[c] = s(f);
820
+ for (const s in o) {
821
+ const f = o[s];
822
+ 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);
728
823
  }
729
824
  return u;
730
825
  }
731
826
  }
732
- function U(e) {
827
+ function te(e) {
733
828
  const r = [], n = [], t = /* @__PURE__ */ new Map();
734
- if (t.set(Date, (c) => new Date(c)), t.set(
829
+ if (t.set(Date, (s) => new Date(s)), t.set(
735
830
  Map,
736
- (c, f) => new Map(s(Array.from(c), f))
831
+ (s, f) => new Map(c(Array.from(s), f))
737
832
  ), t.set(
738
833
  Set,
739
- (c, f) => new Set(s(Array.from(c), f))
834
+ (s, f) => new Set(c(Array.from(s), f))
740
835
  ), e.constructorHandlers)
741
- for (const c of e.constructorHandlers)
742
- t.set(c[0], c[1]);
836
+ for (const s of e.constructorHandlers)
837
+ t.set(s[0], s[1]);
743
838
  let i;
744
839
  return e.proto ? u : o;
745
- function s(c, f) {
746
- const a = Object.keys(c), l = Array.from({ length: a.length });
747
- for (let y = 0; y < a.length; y++) {
748
- const h = a[y], d = c[h];
749
- if (typeof d != "object" || d === null)
750
- l[h] = d;
751
- else if (d.constructor !== Object && (i = t.get(d.constructor)))
752
- l[h] = i(d, f);
753
- else if (ArrayBuffer.isView(d))
754
- l[h] = m(d);
840
+ function c(s, f) {
841
+ const l = Object.keys(s), a = Array.from({ length: l.length });
842
+ for (let y = 0; y < l.length; y++) {
843
+ const m = l[y], d2 = s[m];
844
+ if (typeof d2 != "object" || d2 === null)
845
+ a[m] = d2;
846
+ else if (d2.constructor !== Object && (i = t.get(d2.constructor)))
847
+ a[m] = i(d2, f);
848
+ else if (ArrayBuffer.isView(d2))
849
+ a[m] = j(d2);
755
850
  else {
756
- const v = r.indexOf(d);
757
- v !== -1 ? l[h] = n[v] : l[h] = f(d);
851
+ const h2 = r.indexOf(d2);
852
+ h2 !== -1 ? a[m] = n[h2] : a[m] = f(d2);
758
853
  }
759
854
  }
760
- return l;
855
+ return a;
761
856
  }
762
- function o(c) {
763
- if (typeof c != "object" || c === null) return c;
764
- if (Array.isArray(c)) return s(c, o);
765
- if (c.constructor !== Object && (i = t.get(c.constructor)))
766
- return i(c, o);
857
+ function o(s) {
858
+ if (typeof s != "object" || s === null) return s;
859
+ if (Array.isArray(s)) return c(s, o);
860
+ if (s.constructor !== Object && (i = t.get(s.constructor)))
861
+ return i(s, o);
767
862
  const f = {};
768
- r.push(c), n.push(f);
769
- for (const a in c) {
770
- if (Object.hasOwnProperty.call(c, a) === false) continue;
771
- const l = c[a];
772
- if (typeof l != "object" || l === null)
773
- f[a] = l;
774
- else if (l.constructor !== Object && (i = t.get(l.constructor)))
775
- f[a] = i(l, o);
776
- else if (ArrayBuffer.isView(l))
777
- f[a] = m(l);
863
+ r.push(s), n.push(f);
864
+ for (const l in s) {
865
+ if (Object.hasOwnProperty.call(s, l) === false) continue;
866
+ const a = s[l];
867
+ if (typeof a != "object" || a === null)
868
+ f[l] = a;
869
+ else if (a.constructor !== Object && (i = t.get(a.constructor)))
870
+ f[l] = i(a, o);
871
+ else if (ArrayBuffer.isView(a))
872
+ f[l] = j(a);
778
873
  else {
779
- const y = r.indexOf(l);
780
- y !== -1 ? f[a] = n[y] : f[a] = o(l);
874
+ const y = r.indexOf(a);
875
+ y !== -1 ? f[l] = n[y] : f[l] = o(a);
781
876
  }
782
877
  }
783
878
  return r.pop(), n.pop(), f;
784
879
  }
785
- function u(c) {
786
- if (typeof c != "object" || c === null) return c;
787
- if (Array.isArray(c)) return s(c, u);
788
- if (c.constructor !== Object && (i = t.get(c.constructor)))
789
- return i(c, u);
880
+ function u(s) {
881
+ if (typeof s != "object" || s === null) return s;
882
+ if (Array.isArray(s)) return c(s, u);
883
+ if (s.constructor !== Object && (i = t.get(s.constructor)))
884
+ return i(s, u);
790
885
  const f = {};
791
- r.push(c), n.push(f);
792
- for (const a in c) {
793
- const l = c[a];
794
- if (typeof l != "object" || l === null)
795
- f[a] = l;
796
- else if (l.constructor !== Object && (i = t.get(l.constructor)))
797
- f[a] = i(l, u);
798
- else if (ArrayBuffer.isView(l))
799
- f[a] = m(l);
886
+ r.push(s), n.push(f);
887
+ for (const l in s) {
888
+ const a = s[l];
889
+ if (typeof a != "object" || a === null)
890
+ f[l] = a;
891
+ else if (a.constructor !== Object && (i = t.get(a.constructor)))
892
+ f[l] = i(a, u);
893
+ else if (ArrayBuffer.isView(a))
894
+ f[l] = j(a);
800
895
  else {
801
- const y = r.indexOf(l);
802
- y !== -1 ? f[a] = n[y] : f[a] = u(l);
896
+ const y = r.indexOf(a);
897
+ y !== -1 ? f[l] = n[y] : f[l] = u(a);
803
898
  }
804
899
  }
805
900
  return r.pop(), n.pop(), f;
806
901
  }
807
902
  }
808
- const A = K();
809
- function $(e, r = 8) {
903
+ const R = ee();
904
+ function ne(e, r = 8) {
810
905
  const n = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
811
906
  let t = "";
812
907
  for (let i = 0; i < r; i++) {
813
- const s = Math.floor(Math.random() * n.length);
814
- t += n[s];
908
+ const c = Math.floor(Math.random() * n.length);
909
+ t += n[c];
815
910
  }
816
911
  return e ? `${e}${t}` : t;
817
912
  }
818
- function q(e) {
913
+ function re(e, r) {
914
+ const n = e.modifiers.find(
915
+ (t) => t.key.includes(r)
916
+ );
917
+ if (!n)
918
+ throw new Error(`Modifier "${r}" not found`);
919
+ return n;
920
+ }
921
+ function ce(e) {
819
922
  const r = [];
820
923
  function n(t, i) {
821
924
  i.length > 0 && r.push([...i].sort());
822
- for (let s = t; s < e.length; s++) {
823
- const o = e[s];
925
+ for (let c = t; c < e.length; c++) {
926
+ const o = e[c];
824
927
  if (o)
825
928
  if (o.length === 1 && o[0])
826
- n(s + 1, [...i, o[0]]);
929
+ n(c + 1, [...i, o[0]]);
827
930
  else
828
931
  for (const u of o)
829
- n(s + 1, [...i, u]);
932
+ n(c + 1, [...i, u]);
830
933
  }
831
934
  }
832
935
  return n(0, []), r.sort((t, i) => t.length !== i.length ? t.length - i.length : t.join(",").localeCompare(i.join(",")));
833
936
  }
834
- function z(e, r, n) {
937
+ function fe(e, r, n) {
835
938
  const t = {
836
939
  ...e,
837
940
  modifiers: [...n.keys()]
838
- }, i = b(t, r);
839
- for (const s of n.values())
840
- s.factory({
941
+ }, i = v(t, r);
942
+ for (const c of n.values())
943
+ c.factory({
841
944
  ...i,
842
- declarations: A(t.declarations),
843
- variables: A(t.variables),
844
- children: A(t.children)
845
- }), g(t.declarations, i);
945
+ declarations: R(t.declarations),
946
+ variables: R(t.variables),
947
+ children: R(t.children)
948
+ }), V(t.declarations, i);
846
949
  return t;
847
950
  }
848
- function W(e, r) {
951
+ function ue(e, r) {
849
952
  return function(t, i) {
850
- const s = {
953
+ const c = {
851
954
  type: "modifier",
852
955
  key: Array.isArray(t) ? t : [t],
853
956
  factory: i
854
957
  };
855
- return r.modifiers.push(s), s;
958
+ return r.modifiers.push(c), c;
856
959
  };
857
960
  }
858
- function Y() {
961
+ function ae() {
859
962
  return {
860
963
  type: "root",
861
964
  declarations: {},
@@ -867,130 +970,303 @@ GwIDAQAB
867
970
  themes: []
868
971
  };
869
972
  }
870
- function G(e, r, n) {
871
- const t = r.map((s) => s.key);
872
- return q(t).map((s) => {
873
- const o = /* @__PURE__ */ new Map();
874
- for (const u of s) {
875
- const c = r.find(
876
- (f) => f.key.includes(u)
877
- );
878
- c && o.set(u, c);
879
- }
880
- return z(e, n, o);
881
- });
882
- }
883
- function J(e, r) {
884
- return function(t, i) {
885
- const s = {
973
+ function le(e, r) {
974
+ return function(t, i, c = {}) {
975
+ const o = {
886
976
  type: "utility",
887
977
  name: t,
888
- factory: i
889
- };
890
- return r.utilities.push(s), (o, u = []) => {
891
- for (const [c, f] of Object.entries(o)) {
892
- const a = {
893
- type: "utility",
894
- name: t,
895
- value: c,
896
- declarations: {},
897
- variables: [],
898
- children: [],
899
- modifiers: []
900
- }, l = b(
901
- a,
902
- r
903
- );
904
- a.declarations = i({
905
- ...l,
906
- value: f
907
- }) ?? {}, g(a.declarations, l), e.children.push(a), u.length > 0 && e.children.push(
908
- ...G(a, u, r)
909
- );
978
+ factory: i,
979
+ values: [],
980
+ autogenerate: c.autogenerate ?? z(),
981
+ create: (u, s = []) => {
982
+ let f = u;
983
+ if (Array.isArray(u)) {
984
+ f = {};
985
+ for (const l of u) {
986
+ const a = o.autogenerate(l);
987
+ f = {
988
+ ...f,
989
+ ...a
990
+ };
991
+ }
992
+ }
993
+ for (const [l, a] of Object.entries(f)) {
994
+ const y = o.values.find(
995
+ (h2) => h2.key === l && h2.modifiers.length === 0
996
+ ), m = {
997
+ type: "utility",
998
+ name: t,
999
+ value: l,
1000
+ declarations: {},
1001
+ variables: [],
1002
+ children: [],
1003
+ modifiers: []
1004
+ }, d2 = v(
1005
+ m,
1006
+ r
1007
+ );
1008
+ if (m.declarations = i({
1009
+ ...d2,
1010
+ value: a
1011
+ }) ?? {}, V(m.declarations, d2), y || (o.values.push({
1012
+ key: l,
1013
+ value: a,
1014
+ modifiers: []
1015
+ }), e.children.push(m)), s && s.length > 0) {
1016
+ const h2 = s.map((b) => b.key), H2 = ce(h2).filter((b) => !o.values.find(
1017
+ (g2) => g2.key === l && g2.modifiers.length === b.length && g2.modifiers.every((w2) => b.includes(w2))
1018
+ )).reduce((b, g2) => {
1019
+ const w2 = /* @__PURE__ */ new Map();
1020
+ for (const K2 of g2) {
1021
+ const k2 = s.find(
1022
+ (N2) => N2.key.includes(K2)
1023
+ );
1024
+ k2 && q(k2) && w2.set(K2, k2);
1025
+ }
1026
+ return o.values.push({
1027
+ key: l,
1028
+ value: a,
1029
+ modifiers: g2
1030
+ }), b.push(fe(m, r, w2)), b;
1031
+ }, []);
1032
+ e.children.push(...H2);
1033
+ }
1034
+ }
910
1035
  }
911
1036
  };
1037
+ return r.utilities.push(o), o.create;
912
1038
  };
913
1039
  }
914
- function Q(e, r) {
1040
+ function ye(e, r) {
915
1041
  return function(t, i) {
916
- const s = r.themes.find((c) => c.name === t), o = s ?? {
1042
+ const c = r.themes.find((s) => s.name === t), o = c ?? {
917
1043
  type: "theme",
918
1044
  name: t,
919
1045
  declarations: {},
920
1046
  variables: [],
921
1047
  children: []
922
1048
  };
923
- s || r.themes.push(o);
924
- const u = b(o, r);
1049
+ c || r.themes.push(o);
1050
+ const u = v(o, r);
925
1051
  return i && i(u), o;
926
1052
  };
927
1053
  }
928
- function X(e, r) {
929
- return function(t, i, s, o) {
930
- const u = {
1054
+ function de(e, r) {
1055
+ return function(t) {
1056
+ const i = {
931
1057
  type: "recipe",
932
- name: t,
933
- defaults: i,
934
- variants: s,
935
- ...o
1058
+ ...t
936
1059
  };
937
- return r.recipes.push(u), u;
1060
+ return i._runtime = me(i, r), pe(i, r), r.recipes.push(i), i;
938
1061
  };
939
1062
  }
940
- function ue(e) {
941
- const r = $("sf-"), n = Y(), t = { ...e }, i = J(n, n), s = W(n, n), o = X(n, n), u = Q(n, n), { variable: c, selector: f, atRule: a, keyframes: l, media: y, ref: h, css: d } = b(n, n);
1063
+ function _(e, r) {
1064
+ const n = e.autogenerate(r);
1065
+ return Object.keys(n)[0] ?? "default";
1066
+ }
1067
+ function F(e, r) {
1068
+ const n = {};
1069
+ for (const [t, i] of Object.entries(e))
1070
+ if (P(i)) {
1071
+ const c = {};
1072
+ for (const [o, u] of Object.entries(i)) {
1073
+ const s = T(r, o);
1074
+ s && (c[o] = _(
1075
+ s,
1076
+ u
1077
+ ));
1078
+ }
1079
+ n[t] = c;
1080
+ } else if (typeof i == "boolean")
1081
+ n[t] = i;
1082
+ else {
1083
+ const c = T(r, t);
1084
+ c && (n[t] = _(c, i));
1085
+ }
1086
+ return n;
1087
+ }
1088
+ function me(e, r) {
1089
+ const n = {};
1090
+ if (e.base && (n.base = F(e.base, r)), e.variants) {
1091
+ const t = {};
1092
+ for (const [i, c] of Object.entries(e.variants)) {
1093
+ const o = {};
1094
+ for (const [u, s] of Object.entries(
1095
+ c
1096
+ ))
1097
+ s == null ? o[u] = null : o[u] = F(
1098
+ s,
1099
+ r
1100
+ );
1101
+ t[i] = o;
1102
+ }
1103
+ n.variants = t;
1104
+ }
1105
+ return e.defaultVariants && (n.defaultVariants = { ...e.defaultVariants }), e.compoundVariants && (n.compoundVariants = e.compoundVariants.map((t) => ({
1106
+ match: { ...t.match },
1107
+ css: F(t.css, r)
1108
+ }))), n;
1109
+ }
1110
+ function P(e) {
1111
+ return !A(e) && typeof e == "object" && e !== null;
1112
+ }
1113
+ function x(e, r) {
1114
+ const n = (t, i, c) => {
1115
+ let o = r.get(t);
1116
+ o || (o = [], r.set(t, o)), o.push({ value: i, modifiers: c });
1117
+ };
1118
+ for (const [t, i] of Object.entries(e))
1119
+ if (P(i)) {
1120
+ const c = t.split(":");
1121
+ for (const [o, u] of Object.entries(i))
1122
+ n(o, u, c);
1123
+ } else
1124
+ n(t, i, []);
1125
+ }
1126
+ function T(e, r) {
1127
+ const n = e.utilities.find((i) => i.name === r);
1128
+ if (n)
1129
+ return n;
1130
+ const t = r.replace(/[A-Z]/g, (i) => `-${i.toLowerCase()}`);
1131
+ return e.utilities.find((i) => i.name === t);
1132
+ }
1133
+ function pe(e, r) {
1134
+ const n = /* @__PURE__ */ new Map();
1135
+ if (e.base && x(e.base, n), e.variants)
1136
+ for (const i of Object.values(e.variants))
1137
+ for (const c of Object.values(i))
1138
+ x(
1139
+ c,
1140
+ n
1141
+ );
1142
+ if (e.compoundVariants)
1143
+ for (const i of e.compoundVariants)
1144
+ i.css && x(i.css, n);
1145
+ const t = /* @__PURE__ */ new Map();
1146
+ for (const [i, c] of n) {
1147
+ const o = T(r, i);
1148
+ if (!o) {
1149
+ console.warn(
1150
+ `[styleframe] Utility "${i}" not found in registry. Skipping.`
1151
+ );
1152
+ continue;
1153
+ }
1154
+ for (const u of c) {
1155
+ const s = [];
1156
+ for (const f of u.modifiers) {
1157
+ if (!t.has(f))
1158
+ try {
1159
+ t.set(f, re(r, f));
1160
+ } catch {
1161
+ console.warn(
1162
+ `[styleframe] Modifier "${f}" not found in registry. Skipping modifier for utility "${i}".`
1163
+ ), t.set(f, null);
1164
+ }
1165
+ const l = t.get(f);
1166
+ l && s.push(l);
1167
+ }
1168
+ o.create(
1169
+ [u.value],
1170
+ s.length > 0 ? s : void 0
1171
+ );
1172
+ }
1173
+ }
1174
+ }
1175
+ function Re(e) {
1176
+ 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: d2 } = v(n, n);
942
1177
  return {
943
1178
  id: r,
944
1179
  root: n,
945
- variable: c,
1180
+ variable: s,
946
1181
  selector: f,
947
1182
  utility: i,
948
- modifier: s,
1183
+ modifier: c,
949
1184
  recipe: o,
950
1185
  theme: u,
951
- atRule: a,
952
- keyframes: l,
1186
+ atRule: l,
1187
+ keyframes: a,
953
1188
  media: y,
954
- ref: h,
955
- css: d,
1189
+ ref: m,
1190
+ css: d2,
956
1191
  options: t
957
1192
  };
958
1193
  }
1194
+ const SUPPORTED_EXTENSIONS = [".ts", ".mts", ".cts", ".js", ".mjs", ".cjs"];
1195
+ function hasKnownExtension(filePath) {
1196
+ return SUPPORTED_EXTENSIONS.some((ext) => filePath.endsWith(ext));
1197
+ }
1198
+ function resolveConfigFile(cwd, entry) {
1199
+ const basePath = path.isAbsolute(entry) ? entry : path.join(cwd, entry);
1200
+ if (hasKnownExtension(basePath)) {
1201
+ return node_fs.existsSync(basePath) ? basePath : void 0;
1202
+ }
1203
+ for (const ext of SUPPORTED_EXTENSIONS) {
1204
+ const filePath = `${basePath}${ext}`;
1205
+ if (node_fs.existsSync(filePath)) {
1206
+ return filePath;
1207
+ }
1208
+ }
1209
+ return void 0;
1210
+ }
1211
+ function trackNamedExports(module2) {
1212
+ for (const [exportName, exportValue] of Object.entries(module2)) {
1213
+ if (exportName === "default") continue;
1214
+ if (Ae(exportValue)) {
1215
+ exportValue._exportName = exportName;
1216
+ } else if (be(exportValue)) {
1217
+ exportValue._exportName = exportName;
1218
+ }
1219
+ }
1220
+ }
959
1221
  async function loadConfiguration({
960
1222
  cwd = process.cwd(),
961
- name = "styleframe"
1223
+ entry = "styleframe.config"
962
1224
  } = {}) {
963
- const { config } = await c12.loadConfig({
964
- cwd,
965
- name,
966
- defaults: ue()
967
- });
968
- return config;
969
- }
970
- async function loadConfigurationFromPath(entry) {
971
- const entryPath = path.resolve(entry);
972
- const cwd = path.dirname(entryPath);
973
- const name = path.basename(entryPath).replace(/(\.config)?(\.ts)?$/, "");
974
- return await loadConfiguration({ cwd, name });
1225
+ const resolvedPath = resolveConfigFile(cwd, entry);
1226
+ if (!resolvedPath) {
1227
+ return Re();
1228
+ }
1229
+ const jiti$1 = jiti.createJiti(path.dirname(resolvedPath), { cache: false });
1230
+ const module2 = await jiti$1.import(resolvedPath);
1231
+ if (!module2.default) {
1232
+ throw new Error(
1233
+ `Missing default export in ${resolvedPath}. Expected a Styleframe instance.`
1234
+ );
1235
+ }
1236
+ trackNamedExports(module2);
1237
+ return module2.default;
975
1238
  }
976
1239
  async function watchConfiguration({
977
- cwd = process.cwd()
1240
+ cwd = process.cwd(),
1241
+ entry = "styleframe.config",
1242
+ onUpdate,
1243
+ onError
978
1244
  } = {}) {
979
- return await c12.watchConfig({
980
- cwd,
981
- name: "styleframe",
982
- acceptHMR({ getDiff }) {
983
- const diff = getDiff();
984
- if (diff.length === 0) {
985
- return true;
986
- }
1245
+ const resolvedPath = resolveConfigFile(cwd, entry);
1246
+ if (!resolvedPath) {
1247
+ throw new Error(`Config file not found: ${entry}`);
1248
+ }
1249
+ const watcher = chokidar.watch(resolvedPath, { ignoreInitial: true });
1250
+ watcher.on("change", async () => {
1251
+ try {
1252
+ const config = await loadConfiguration({ entry: resolvedPath });
1253
+ onUpdate?.(config);
1254
+ } catch (error) {
1255
+ onError?.(error instanceof Error ? error : new Error(String(error)));
987
1256
  }
988
1257
  });
1258
+ watcher.on("unlink", () => {
1259
+ onError?.(new Error(`Config file was deleted: ${resolvedPath}`));
1260
+ });
1261
+ return {
1262
+ config: await loadConfiguration({ entry: resolvedPath }),
1263
+ configFile: resolvedPath,
1264
+ unwatch: () => watcher.close()
1265
+ };
989
1266
  }
990
1267
  exports2.build = build;
991
1268
  exports2.directoryExists = directoryExists;
992
1269
  exports2.loadConfiguration = loadConfiguration;
993
- exports2.loadConfigurationFromPath = loadConfigurationFromPath;
994
1270
  exports2.watchConfiguration = watchConfiguration;
995
1271
  Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
996
1272
  }));