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