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