@styleframe/loader 2.3.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,170 +1,170 @@
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"], L$1 = ["layer"], D = ({ name: e }) => `[data-theme="${e}"]`, I$1 = ({
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
8
  modifiers: r
9
9
  }) => `._${[...r, e, ...t === "default" ? [] : [t]].filter(Boolean).join("\\:").replace(/[[\].#()%,]/g, "\\$&")}`, w = ({ name: e }) => e.replace(/^\.+|\.+$/g, "").replace(/\.+/g, "--");
10
- function U(e, t) {
10
+ function I$1(e, t) {
11
11
  return `@${e}${t ? " " : ""}${t}`;
12
12
  }
13
- const _$1 = /\d/, P$1 = ["-", "_", "/", "."];
13
+ const U = /\d/, P$1 = ["-", "_", "/", "."];
14
14
  function M(e = "") {
15
- if (!_$1.test(e))
15
+ if (!U.test(e))
16
16
  return e !== e.toLowerCase();
17
17
  }
18
- function $$1(e, t) {
18
+ function N(e, t) {
19
19
  const r = P$1, n = [];
20
20
  if (!e || typeof e != "string")
21
21
  return n;
22
- let o = "", s, i;
22
+ let o = "", s, u;
23
23
  for (const a of e) {
24
24
  const c = r.includes(a);
25
25
  if (c === true) {
26
26
  n.push(o), o = "", s = void 0;
27
27
  continue;
28
28
  }
29
- const u = M(a);
30
- if (i === false) {
31
- if (s === false && u === true) {
32
- n.push(o), o = a, s = 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 (s === true && u === false && o.length > 1) {
35
+ if (s === true && i === false && o.length > 1) {
36
36
  const f = o.at(-1);
37
- n.push(o.slice(0, Math.max(0, o.length - 1))), o = f + a, s = u;
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
- o += a, s = u, i = c;
41
+ o += a, s = i, u = c;
42
42
  }
43
43
  return n.push(o), n;
44
44
  }
45
45
  function k(e) {
46
46
  return e ? e[0].toUpperCase() + e.slice(1) : "";
47
47
  }
48
- function x$1(e) {
48
+ function V$1(e) {
49
49
  return e ? e[0].toLowerCase() + e.slice(1) : "";
50
50
  }
51
- function V$1(e, t) {
52
- return e ? (Array.isArray(e) ? e : $$1(e)).map((r) => k(r)).join("") : "";
51
+ function q$1(e, t) {
52
+ return e ? (Array.isArray(e) ? e : N(e)).map((r) => k(r)).join("") : "";
53
53
  }
54
54
  function K(e, t) {
55
- return x$1(V$1(e || ""));
55
+ return V$1(q$1(e || ""));
56
56
  }
57
- function q$1(e, t) {
58
- return e ? (Array.isArray(e) ? e : $$1(e)).map((r) => r.toLowerCase()).join("-") : "";
57
+ function z$1(e, t) {
58
+ return e ? (Array.isArray(e) ? e : N(e)).map((r) => r.toLowerCase()).join("-") : "";
59
59
  }
60
- function z$1(e) {
60
+ function H(e) {
61
61
  return ` ${e}`;
62
62
  }
63
- function H(e) {
63
+ function Q$1(e) {
64
64
  return e.split(`
65
- `).map((t) => z$1(t)).join(`
65
+ `).map((t) => H(t)).join(`
66
66
  `);
67
67
  }
68
- function Q$1(e) {
68
+ function J$1(e) {
69
69
  return e === e.toUpperCase();
70
70
  }
71
71
  function Z$1(e) {
72
72
  return K(e);
73
73
  }
74
- function J$1(e) {
75
- return q$1(e);
76
- }
77
74
  function W$1(e) {
78
- return J$1(e);
75
+ return z$1(e);
76
+ }
77
+ function G$1(e) {
78
+ return W$1(e);
79
79
  }
80
80
  function O(e, t) {
81
- return `${e.startsWith("--") ? e : W$1(e)}: ${t};`;
81
+ return `${e.startsWith("--") ? e : G$1(e)}: ${t};`;
82
82
  }
83
- function G$1(e) {
83
+ function Y$1(e) {
84
84
  return `{${e.length > 0 ? `
85
- ` : ""}${e.map((t) => `${H(`${t}`)}
85
+ ` : ""}${e.map((t) => `${Q$1(`${t}`)}
86
86
  `).join("")}}`;
87
87
  }
88
- function B(e) {
88
+ function E$1(e) {
89
89
  return `--${(e.startsWith("--") ? e.slice(2) : e).replace(/[^a-zA-Z0-9_\-\u0080-\uFFFF]/g, "-") || "unknown-variable"}`;
90
90
  }
91
- function Y$1(e, t) {
92
- return O(B(e), t);
93
- }
94
91
  function X$1(e, t) {
95
- return `var(${B(e)}${t ? `, ${t}` : ""})`;
92
+ return O(E$1(e), t);
96
93
  }
97
- function v$1(e, t) {
98
- return `${e} ${G$1(t)}`;
94
+ function ee$1(e, t) {
95
+ return `var(${E$1(e)}${t ? `, ${t}` : ""})`;
99
96
  }
100
- function ee$1(e) {
97
+ function R$1(e, t) {
98
+ return `${e} ${Y$1(t)}`;
99
+ }
100
+ function te$1(e) {
101
101
  return function(r, n) {
102
102
  return Object.entries(r).map(([o, s]) => O(o, e(s, n)));
103
103
  };
104
104
  }
105
- function E$1(e) {
105
+ function B(e) {
106
106
  return function(r, n) {
107
107
  const s = (n.variables?.name ?? w)({ name: r.name });
108
- return Y$1(s, e(r.value, n));
108
+ return X$1(s, e(r.value, n));
109
109
  };
110
110
  }
111
- function C$1(e) {
112
- const t = E$1(e), r = ee$1(e);
113
- return function(o, s, i) {
114
- const { variables: a, declarations: c, children: u } = s, f = o === ":root", l = (a ?? []).map(
115
- (A2) => t(A2, i)
111
+ function S$1(e) {
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
116
  ), m = r(
117
117
  c ?? {},
118
- i
119
- ), y = (u ?? []).map(
120
- (A2) => e(A2, i)
121
- ), p2 = l.length > 0, b = m.length > 0, S2 = y.length > 0;
122
- return f ? `${p2 || b ? v$1(o, [
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, [
123
123
  ...l,
124
124
  ...p2 && b ? [""] : [],
125
125
  ...m
126
- ]) : ""}${S2 && (p2 || b) ? `
126
+ ]) : ""}${C2 && (p2 || b) ? `
127
127
 
128
128
  ` : ""}${y.join(`
129
129
 
130
- `)}` : v$1(o, [
130
+ `)}` : R$1(o, [
131
131
  ...l,
132
- ...p2 && (S2 || b) ? [""] : [],
132
+ ...p2 && (C2 || b) ? [""] : [],
133
133
  ...m,
134
- ...b && S2 ? [""] : [],
134
+ ...b && C2 ? [""] : [],
135
135
  ...y.flatMap(
136
- (A2, F2) => F2 === y.length - 1 ? [A2] : [A2, ""]
136
+ (A2, _2) => _2 === y.length - 1 ? [A2] : [A2, ""]
137
137
  )
138
138
  ]);
139
139
  };
140
140
  }
141
- function te$1(e) {
142
- const t = C$1(e);
141
+ function re$1(e) {
142
+ const t = S$1(e);
143
143
  return function(n, o) {
144
- const s = N.includes(n.identifier), i = L$1.includes(
144
+ const s = F$1.includes(n.identifier), u = L$1.includes(
145
145
  n.identifier
146
- ), a = Object.keys(n.declarations).length > 0, c = n.variables.length > 0, u = n.children.length > 0, f = U(n.identifier, n.rule);
147
- return s || i && !(a || c || u) ? `${f};` : t(f, n, o);
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);
148
148
  };
149
149
  }
150
- function re$1(e) {
150
+ function ne$1(e) {
151
151
  return function(r, n) {
152
152
  return r.value.map((o) => e(o, n)).join("").trim();
153
153
  };
154
154
  }
155
- function ne$1(e) {
155
+ function oe(e) {
156
156
  return typeof e == "object" && e !== null;
157
157
  }
158
158
  function h(e, t) {
159
- return ne$1(e) && "type" in e && e.type === t;
159
+ return oe(e) && "type" in e && e.type === t;
160
160
  }
161
- function oe(e) {
161
+ function ce$1(e) {
162
162
  return h(e, "variable");
163
163
  }
164
- function ce$1(e) {
164
+ function ue$1(e) {
165
165
  return h(e, "reference");
166
166
  }
167
- function ue$1(e) {
167
+ function v$1(e) {
168
168
  return h(e, "selector");
169
169
  }
170
170
  function ie(e) {
@@ -202,47 +202,47 @@
202
202
  if (e = e || {}, e.circular)
203
203
  return ye$1(e);
204
204
  const t = /* @__PURE__ */ new Map();
205
- if (t.set(Date, (i) => new Date(i)), t.set(
205
+ if (t.set(Date, (u) => new Date(u)), t.set(
206
206
  Map,
207
- (i, a) => new Map(n(Array.from(i), a))
207
+ (u, a) => new Map(n(Array.from(u), a))
208
208
  ), t.set(
209
209
  Set,
210
- (i, a) => new Set(n(Array.from(i), a))
210
+ (u, a) => new Set(n(Array.from(u), a))
211
211
  ), e.constructorHandlers)
212
- for (const i of e.constructorHandlers)
213
- t.set(i[0], i[1]);
212
+ for (const u of e.constructorHandlers)
213
+ t.set(u[0], u[1]);
214
214
  let r;
215
215
  return e.proto ? s : o;
216
- function n(i, a) {
217
- const c = Object.keys(i), u = Array.from({ length: c.length });
216
+ function n(u, a) {
217
+ const c = Object.keys(u), i = Array.from({ length: c.length });
218
218
  for (let f = 0; f < c.length; f++) {
219
- const l = c[f], m = i[l];
220
- typeof m != "object" || m === null ? u[l] = m : m.constructor !== Object && (r = t.get(m.constructor)) ? u[l] = r(m, a) : ArrayBuffer.isView(m) ? u[l] = g(m) : u[l] = a(m);
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);
221
221
  }
222
- return u;
222
+ return i;
223
223
  }
224
- function o(i) {
225
- if (typeof i != "object" || i === null) return i;
226
- if (Array.isArray(i)) return n(i, o);
227
- if (i.constructor !== Object && (r = t.get(i.constructor)))
228
- return r(i, o);
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
229
  const a = {};
230
- for (const c in i) {
231
- if (Object.hasOwnProperty.call(i, c) === false) continue;
232
- const u = i[c];
233
- typeof u != "object" || u === null ? a[c] = u : u.constructor !== Object && (r = t.get(u.constructor)) ? a[c] = r(u, o) : ArrayBuffer.isView(u) ? a[c] = g(u) : a[c] = o(u);
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);
234
234
  }
235
235
  return a;
236
236
  }
237
- function s(i) {
238
- if (typeof i != "object" || i === null) return i;
239
- if (Array.isArray(i)) return n(i, s);
240
- if (i.constructor !== Object && (r = t.get(i.constructor)))
241
- return r(i, s);
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
242
  const a = {};
243
- for (const c in i) {
244
- const u = i[c];
245
- typeof u != "object" || u === null ? a[c] = u : u.constructor !== Object && (r = t.get(u.constructor)) ? a[c] = r(u, s) : ArrayBuffer.isView(u) ? a[c] = g(u) : a[c] = s(u);
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);
246
246
  }
247
247
  return a;
248
248
  }
@@ -251,76 +251,76 @@
251
251
  const t = [], r = [], n = /* @__PURE__ */ new Map();
252
252
  if (n.set(Date, (c) => new Date(c)), n.set(
253
253
  Map,
254
- (c, u) => new Map(s(Array.from(c), u))
254
+ (c, i) => new Map(s(Array.from(c), i))
255
255
  ), n.set(
256
256
  Set,
257
- (c, u) => new Set(s(Array.from(c), u))
257
+ (c, i) => new Set(s(Array.from(c), i))
258
258
  ), e.constructorHandlers)
259
259
  for (const c of e.constructorHandlers)
260
260
  n.set(c[0], c[1]);
261
261
  let o;
262
- return e.proto ? a : i;
263
- function s(c, u) {
262
+ return e.proto ? a : u;
263
+ function s(c, i) {
264
264
  const f = Object.keys(c), l = Array.from({ length: f.length });
265
265
  for (let m = 0; m < f.length; m++) {
266
266
  const y = f[m], p2 = c[y];
267
267
  if (typeof p2 != "object" || p2 === null)
268
268
  l[y] = p2;
269
269
  else if (p2.constructor !== Object && (o = n.get(p2.constructor)))
270
- l[y] = o(p2, u);
270
+ l[y] = o(p2, i);
271
271
  else if (ArrayBuffer.isView(p2))
272
272
  l[y] = g(p2);
273
273
  else {
274
274
  const b = t.indexOf(p2);
275
- b !== -1 ? l[y] = r[b] : l[y] = u(p2);
275
+ b !== -1 ? l[y] = r[b] : l[y] = i(p2);
276
276
  }
277
277
  }
278
278
  return l;
279
279
  }
280
- function i(c) {
280
+ function u(c) {
281
281
  if (typeof c != "object" || c === null) return c;
282
- if (Array.isArray(c)) return s(c, i);
282
+ if (Array.isArray(c)) return s(c, u);
283
283
  if (c.constructor !== Object && (o = n.get(c.constructor)))
284
- return o(c, i);
285
- const u = {};
286
- t.push(c), r.push(u);
284
+ return o(c, u);
285
+ const i = {};
286
+ t.push(c), r.push(i);
287
287
  for (const f in c) {
288
288
  if (Object.hasOwnProperty.call(c, f) === false) continue;
289
289
  const l = c[f];
290
290
  if (typeof l != "object" || l === null)
291
- u[f] = l;
291
+ i[f] = l;
292
292
  else if (l.constructor !== Object && (o = n.get(l.constructor)))
293
- u[f] = o(l, i);
293
+ i[f] = o(l, u);
294
294
  else if (ArrayBuffer.isView(l))
295
- u[f] = g(l);
295
+ i[f] = g(l);
296
296
  else {
297
297
  const m = t.indexOf(l);
298
- m !== -1 ? u[f] = r[m] : u[f] = i(l);
298
+ m !== -1 ? i[f] = r[m] : i[f] = u(l);
299
299
  }
300
300
  }
301
- return t.pop(), r.pop(), u;
301
+ return t.pop(), r.pop(), i;
302
302
  }
303
303
  function a(c) {
304
304
  if (typeof c != "object" || c === null) return c;
305
305
  if (Array.isArray(c)) return s(c, a);
306
306
  if (c.constructor !== Object && (o = n.get(c.constructor)))
307
307
  return o(c, a);
308
- const u = {};
309
- t.push(c), r.push(u);
308
+ const i = {};
309
+ t.push(c), r.push(i);
310
310
  for (const f in c) {
311
311
  const l = c[f];
312
312
  if (typeof l != "object" || l === null)
313
- u[f] = l;
313
+ i[f] = l;
314
314
  else if (l.constructor !== Object && (o = n.get(l.constructor)))
315
- u[f] = o(l, a);
315
+ i[f] = o(l, a);
316
316
  else if (ArrayBuffer.isView(l))
317
- u[f] = g(l);
317
+ i[f] = g(l);
318
318
  else {
319
319
  const m = t.indexOf(l);
320
- m !== -1 ? u[f] = r[m] : u[f] = a(l);
320
+ m !== -1 ? i[f] = r[m] : i[f] = a(l);
321
321
  }
322
322
  }
323
- return t.pop(), r.pop(), u;
323
+ return t.pop(), r.pop(), i;
324
324
  }
325
325
  }
326
326
  pe$1();
@@ -332,17 +332,17 @@
332
332
  function he(e) {
333
333
  return function(r, n) {
334
334
  const s = (n.variables?.name ?? w)({ name: r.name });
335
- return X$1(
335
+ return ee$1(
336
336
  s,
337
337
  r.fallback ? e(r.fallback, n) : void 0
338
338
  );
339
339
  };
340
340
  }
341
- function be(e) {
342
- const t = C$1(e);
341
+ function be$1(e) {
342
+ const t = S$1(e);
343
343
  return function(n, o) {
344
344
  return n.themes.reduce(
345
- (s, i) => (s.push(e(i, o)), s),
345
+ (s, u) => (s.push(e(u, o)), s),
346
346
  [t(":root", n, o)]
347
347
  // Default theme (root)
348
348
  ).join(`
@@ -350,23 +350,23 @@
350
350
  `);
351
351
  };
352
352
  }
353
- function Ae(e) {
354
- const t = C$1(e);
353
+ function Ae$1(e) {
354
+ const t = S$1(e);
355
355
  return function(n, o) {
356
356
  return t(n.query, n, o);
357
357
  };
358
358
  }
359
359
  function ge(e) {
360
- const t = C$1(e);
360
+ const t = S$1(e);
361
361
  return function(n, o) {
362
- const i = (o.themes?.selector ?? D)({ name: n.name });
363
- return t(i, n, o);
362
+ const u = (o.themes?.selector ?? D)({ name: n.name });
363
+ return t(u, n, o);
364
364
  };
365
365
  }
366
- function Ce(e) {
367
- const t = C$1(e);
366
+ function Se(e) {
367
+ const t = S$1(e);
368
368
  return function(n, o) {
369
- const s = [], a = (o.utilities?.selector ?? I$1)({
369
+ const s = [], a = (o.utilities?.selector ?? x$1)({
370
370
  name: n.name,
371
371
  value: n.value,
372
372
  modifiers: n.modifiers
@@ -377,9 +377,9 @@
377
377
  };
378
378
  }
379
379
  function d(e, t) {
380
- const r = be(d), n = Ae(d), o = Ce(d), s = te$1(d), i = ge(d), a = E$1(d), c = he(d), u = re$1(d), f = de$1();
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();
381
381
  switch (true) {
382
- case ue$1(e):
382
+ case v$1(e):
383
383
  return n(e, t);
384
384
  case se(e):
385
385
  return o(e, t);
@@ -388,24 +388,24 @@
388
388
  case T$1(e):
389
389
  return r(e, t);
390
390
  case le$1(e):
391
- return i(e, t);
392
- case oe(e):
393
- return a(e, t);
391
+ return u(e, t);
394
392
  case ce$1(e):
393
+ return a(e, t);
394
+ case ue$1(e):
395
395
  return c(e, t);
396
396
  case ae$1(e):
397
- return u(e, t);
397
+ return i(e, t);
398
398
  default:
399
399
  return f(e, t);
400
400
  }
401
401
  }
402
- function Se(e) {
402
+ function Ce(e) {
403
403
  return function(r, n) {
404
- let o = Z$1(r.name);
405
- r.name[0] && Q$1(r.name[0]) && (o = me$1(o));
406
- const s = `${o}Recipe`, i = r._runtime ?? {};
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
407
  return `const ${s} = ${JSON.stringify(
408
- i,
408
+ u,
409
409
  null,
410
410
  4
411
411
  )} as const satisfies RecipeRuntime;
@@ -415,28 +415,45 @@ export const ${o} = createRecipe("${r.name}", ${s});
415
415
  };
416
416
  }
417
417
  function je(e) {
418
+ return e.filter(
419
+ (t) => v$1(t) && !!t._exportName
420
+ );
421
+ }
422
+ function ve(e) {
418
423
  return function(r, n) {
419
- return r.recipes.length > 0 ? `import { createRecipe } from '@styleframe/runtime';
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';
420
429
  import type { RecipeRuntime } from '@styleframe/runtime';
421
-
422
- ${e(r.recipes, n)}` : "";
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
+ ` : "";
423
438
  };
424
439
  }
425
440
  function j$1(e, t) {
426
- const r = je(j$1), n = Se();
441
+ const r = ve(j$1), n = Ce(), o = Re$1();
427
442
  switch (true) {
428
443
  case Array.isArray(e):
429
- return e.map((o) => j$1(o, t)).join(`
444
+ return e.map((s) => j$1(s, t)).join(`
430
445
  `);
431
446
  case T$1(e):
432
447
  return r(e, t);
433
448
  case fe$1(e):
434
449
  return n(e, t);
450
+ case v$1(e):
451
+ return o(e, t);
435
452
  default:
436
453
  return "";
437
454
  }
438
455
  }
439
- const ve = `-----BEGIN PUBLIC KEY-----
456
+ const $e = `-----BEGIN PUBLIC KEY-----
440
457
  MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAs7zAFssgxOMPeo80iig4
441
458
  qSSshgNOLnW1gd4tPUrsezndaUrAKlsAys6XD8kuF+bBEIR0uFNSgKlqINLjWM1n
442
459
  BiTUzCctodyRaq6/tyFSoPLD35iblkwtfxKPM42lAJZsyTu9qoBr8MJyXmhDLuqA
@@ -444,8 +461,8 @@ dQ8di7mQHz+mCy96jQR4lFSDfHMgl27qaAh5VboTBRxgZliN8D5Fl590QkS94wAj
444
461
  hC7NbH+hPcGc/qIaZSjZfyZeBIZS74qJkrzjEA7/pukROD8UQUrQ512HHZ6XlgMn
445
462
  4bWT2K9CpWbbhsKFTecCHuxlmPkFJNMuvAb/LdP08BSnpntlyAJcQeBrna2qBen+
446
463
  GwIDAQAB
447
- -----END PUBLIC KEY-----`, Re$1 = "__licenseRequired", we = "__licenseValidated";
448
- async function $e(e) {
464
+ -----END PUBLIC KEY-----`, we = "__licenseRequired", Ne = "__licenseValidated";
465
+ async function Oe(e) {
449
466
  const t = e.replace(/-----BEGIN PUBLIC KEY-----/, "").replace(/-----END PUBLIC KEY-----/, "").replace(/\s/g, ""), r = Uint8Array.from(atob(t), (n) => n.charCodeAt(0));
450
467
  return await crypto.subtle.importKey(
451
468
  "spki",
@@ -458,14 +475,14 @@ GwIDAQAB
458
475
  ["verify"]
459
476
  );
460
477
  }
461
- async function Oe({
478
+ async function Ee({
462
479
  payload: e,
463
480
  signature: t
464
481
  }) {
465
482
  const r = new TextEncoder().encode(e), n = Uint8Array.from(
466
483
  atob(t),
467
484
  (s) => s.charCodeAt(0)
468
- ), o = await $e(ve);
485
+ ), o = await Oe($e);
469
486
  if (!await crypto.subtle.verify(
470
487
  { name: "RSASSA-PKCS1-v1_5" },
471
488
  o,
@@ -478,12 +495,12 @@ GwIDAQAB
478
495
  return JSON.parse(e);
479
496
  }
480
497
  function Be(e) {
481
- return Object.prototype.hasOwnProperty.call(e, Re$1);
498
+ return Object.prototype.hasOwnProperty.call(e, we);
482
499
  }
483
- async function Ee(e) {
500
+ async function Te(e) {
484
501
  const t = Object.getOwnPropertyDescriptor(
485
502
  e,
486
- we
503
+ Ne
487
504
  );
488
505
  if (!t?.value)
489
506
  return {
@@ -501,7 +518,7 @@ GwIDAQAB
501
518
  valid: false
502
519
  };
503
520
  try {
504
- return await Oe(
521
+ return await Ee(
505
522
  r
506
523
  );
507
524
  } catch {
@@ -513,7 +530,7 @@ GwIDAQAB
513
530
  };
514
531
  }
515
532
  }
516
- function Te(e) {
533
+ function _e(e) {
517
534
  const t = Math.floor(Math.random() * 100);
518
535
  e.root.children.push({
519
536
  type: "selector",
@@ -537,30 +554,30 @@ GwIDAQAB
537
554
  }
538
555
  });
539
556
  }
540
- function R$1(e, t = "") {
557
+ function $$1(e, t = "") {
541
558
  return {
542
559
  name: e,
543
560
  content: t
544
561
  };
545
562
  }
546
- async function Ne(e, {
563
+ async function Le(e, {
547
564
  type: t = "all",
548
565
  consumers: r = { css: d, ts: j$1 }
549
566
  } = {}) {
550
567
  const n = { files: [] }, o = e.options;
551
568
  if (Be(e)) {
552
- const s = await Ee(e);
553
- (!s.valid || s.instanceId !== e.id) && Te(e);
569
+ const s = await Te(e);
570
+ (!s.valid || s.instanceId !== e.id) && _e(e);
554
571
  }
555
572
  if (t === "all" || t === "css") {
556
- const s = R$1(
573
+ const s = $$1(
557
574
  "index.css",
558
575
  r.css(e.root, o)
559
576
  );
560
577
  n.files.push(s);
561
578
  }
562
579
  if (t === "all" || t === "ts") {
563
- const s = R$1(
580
+ const s = $$1(
564
581
  "index.ts",
565
582
  r.ts(e.root, o)
566
583
  );
@@ -582,7 +599,7 @@ GwIDAQAB
582
599
  environment: process.env.NODE_ENV || "development",
583
600
  isBuild: true
584
601
  });
585
- const output = await Ne(instance, transpiler);
602
+ const output = await Le(instance, transpiler);
586
603
  const outputDirExists = await directoryExists(outputDir);
587
604
  if (clean && outputDirExists) {
588
605
  await promises.rm(outputDir, { recursive: true });
@@ -609,12 +626,18 @@ GwIDAQAB
609
626
  function A(e) {
610
627
  return p(e, "reference");
611
628
  }
629
+ function be(e) {
630
+ return p(e, "selector");
631
+ }
612
632
  function q(e) {
613
633
  return p(e, "modifier");
614
634
  }
615
635
  function E(e) {
616
636
  return p(e, "css");
617
637
  }
638
+ function Ae(e) {
639
+ return p(e, "recipe");
640
+ }
618
641
  function G(e) {
619
642
  return typeof e == "string" || typeof e == "number" || typeof e == "boolean" || e === null;
620
643
  }
@@ -1168,41 +1191,82 @@ GwIDAQAB
1168
1191
  options: t
1169
1192
  };
1170
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
+ }
1171
1221
  async function loadConfiguration({
1172
1222
  cwd = process.cwd(),
1173
- configFile = "styleframe.config"
1223
+ entry = "styleframe.config"
1174
1224
  } = {}) {
1175
- const { config } = await c12.loadConfig({
1176
- cwd,
1177
- configFile,
1178
- defaults: Re()
1179
- });
1180
- return config;
1181
- }
1182
- async function loadConfigurationFromPath(entry) {
1183
- const entryPath = path.resolve(entry);
1184
- const cwd = path.dirname(entryPath);
1185
- const configFile = path.basename(entryPath).replace(/(\.ts)?$/, "");
1186
- return await loadConfiguration({ cwd, configFile });
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;
1187
1238
  }
1188
1239
  async function watchConfiguration({
1189
- cwd = process.cwd()
1240
+ cwd = process.cwd(),
1241
+ entry = "styleframe.config",
1242
+ onUpdate,
1243
+ onError
1190
1244
  } = {}) {
1191
- return await c12.watchConfig({
1192
- cwd,
1193
- name: "styleframe",
1194
- acceptHMR({ getDiff }) {
1195
- const diff = getDiff();
1196
- if (diff.length === 0) {
1197
- return true;
1198
- }
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)));
1199
1256
  }
1200
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
+ };
1201
1266
  }
1202
1267
  exports2.build = build;
1203
1268
  exports2.directoryExists = directoryExists;
1204
1269
  exports2.loadConfiguration = loadConfiguration;
1205
- exports2.loadConfigurationFromPath = loadConfigurationFromPath;
1206
1270
  exports2.watchConfiguration = watchConfiguration;
1207
1271
  Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
1208
1272
  }));