@styleframe/loader 2.3.0 → 2.4.1

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,103 +1,105 @@
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$1 = /\d/, P$1 = ["-", "_", "/", "."];
14
16
  function M(e = "") {
15
- if (!_$1.test(e))
17
+ if (!U$1.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
- function k(e) {
47
+ function k$1(e) {
46
48
  return e ? e[0].toUpperCase() + e.slice(1) : "";
47
49
  }
48
- function x$1(e) {
50
+ function V(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
- }
54
- function K(e, t) {
55
- return x$1(V$1(e || ""));
53
+ function K$1(e, t) {
54
+ return e ? (Array.isArray(e) ? e : N(e)).map((r) => k$1(r)).join("") : "";
56
55
  }
57
56
  function q$1(e, t) {
58
- return e ? (Array.isArray(e) ? e : $$1(e)).map((r) => r.toLowerCase()).join("-") : "";
57
+ return V(K$1(e || ""));
59
58
  }
60
- function z$1(e) {
61
- return ` ${e}`;
59
+ function z$1(e, t) {
60
+ return e ? (Array.isArray(e) ? e : N(e)).map((r) => r.toLowerCase()).join("-") : "";
62
61
  }
63
62
  function H(e) {
63
+ return ` ${e}`;
64
+ }
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
- return K(e);
73
- }
74
- function J$1(e) {
75
74
  return q$1(e);
76
75
  }
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
90
  function B(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) {
93
+ function X$1(e, t) {
92
94
  return O(B(e), t);
93
95
  }
94
- function X$1(e, t) {
96
+ function ee$1(e, t) {
95
97
  return `var(${B(e)}${t ? `, ${t}` : ""})`;
96
98
  }
97
- function v$1(e, t) {
98
- return `${e} ${G$1(t)}`;
99
+ function R$1(e, t) {
100
+ return `${e} ${Y$1(t)}`;
99
101
  }
100
- function ee$1(e) {
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
  };
@@ -105,66 +107,66 @@ function ee$1(e) {
105
107
  function E$1(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)
116
- ), m = r(
113
+ function S$1(e) {
114
+ const t = E$1(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
+ ), m2 = 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
+ ), p = l.length > 0, b = m2.length > 0, C2 = y.length > 0;
124
+ return f ? `${p || b ? R$1(o, [
123
125
  ...l,
124
- ...p2 && b ? [""] : [],
125
- ...m
126
- ]) : ""}${S2 && (p2 || b) ? `
126
+ ...p && b ? [""] : [],
127
+ ...m2
128
+ ]) : ""}${C2 && (p || b) ? `
127
129
 
128
130
  ` : ""}${y.join(`
129
131
 
130
- `)}` : v$1(o, [
132
+ `)}` : R$1(o, [
131
133
  ...l,
132
- ...p2 && (S2 || b) ? [""] : [],
133
- ...m,
134
- ...b && S2 ? [""] : [],
134
+ ...p && (C2 || b) ? [""] : [],
135
+ ...m2,
136
+ ...b && C2 ? [""] : [],
135
137
  ...y.flatMap(
136
- (A2, F2) => F2 === y.length - 1 ? [A2] : [A2, ""]
138
+ (A2, _) => _ === 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], m2 = u[l];
222
+ typeof m2 != "object" || m2 === null ? i[l] = m2 : m2.constructor !== Object && (r = t.get(m2.constructor)) ? i[l] = r(m2, a) : ArrayBuffer.isView(m2) ? i[l] = g(m2) : i[l] = a(m2);
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
- for (let m = 0; m < f.length; m++) {
266
- const y = f[m], p2 = c[y];
267
- if (typeof p2 != "object" || p2 === null)
268
- l[y] = p2;
269
- else if (p2.constructor !== Object && (o = n.get(p2.constructor)))
270
- l[y] = o(p2, u);
271
- else if (ArrayBuffer.isView(p2))
272
- l[y] = g(p2);
267
+ for (let m2 = 0; m2 < f.length; m2++) {
268
+ const y = f[m2], p = c[y];
269
+ if (typeof p != "object" || p === null)
270
+ l[y] = p;
271
+ else if (p.constructor !== Object && (o = n.get(p.constructor)))
272
+ l[y] = o(p, i);
273
+ else if (ArrayBuffer.isView(p))
274
+ l[y] = g(p);
273
275
  else {
274
- const b = t.indexOf(p2);
275
- b !== -1 ? l[y] = r[b] : l[y] = u(p2);
276
+ const b = t.indexOf(p);
277
+ b !== -1 ? l[y] = r[b] : l[y] = i(p);
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
- const m = t.indexOf(l);
298
- m !== -1 ? u[f] = r[m] : u[f] = i(l);
299
+ const m2 = t.indexOf(l);
300
+ m2 !== -1 ? i[f] = r[m2] : 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
- const m = t.indexOf(l);
320
- m !== -1 ? u[f] = r[m] : u[f] = a(l);
321
+ const m2 = t.indexOf(l);
322
+ m2 !== -1 ? i[f] = r[m2] : 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
343
  function be(e) {
342
- const t = C$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
- function ge(e) {
360
- const t = C$1(e);
361
+ function ge$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(d), n = Ae$1(d), o = Se(d), s = re$1(d), u = ge$1(d), a = E$1(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 Be({
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,
@@ -477,13 +496,13 @@ async function Oe({
477
496
  );
478
497
  return JSON.parse(e);
479
498
  }
480
- function Be(e) {
481
- return Object.prototype.hasOwnProperty.call(e, Re$1);
499
+ function Ee(e) {
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 Be(
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 $(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
- if (Be(e)) {
552
- const s = await Ee(e);
553
- (!s.valid || s.instanceId !== e.id) && Te(e);
570
+ if (Ee(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 = $(
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 = $(
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 });
@@ -597,32 +616,38 @@ async function build(instance, { clean = true, outputDir = "./styleframe", trans
597
616
  await writeFile(filePath, file.content);
598
617
  }
599
618
  }
600
- function S(e) {
619
+ function K(e) {
601
620
  return typeof e == "object" && e !== null;
602
621
  }
603
- function p(e, r) {
604
- return S(e) && "type" in e && e.type === r;
622
+ function m(e, r) {
623
+ return K(e) && "type" in e && e.type === r;
605
624
  }
606
625
  function L(e) {
607
- return p(e, "variable");
626
+ return m(e, "variable");
608
627
  }
609
628
  function A(e) {
610
- return p(e, "reference");
629
+ return m(e, "reference");
630
+ }
631
+ function ge(e) {
632
+ return m(e, "selector");
611
633
  }
612
634
  function q(e) {
613
- return p(e, "modifier");
635
+ return m(e, "modifier");
614
636
  }
615
637
  function E(e) {
616
- return p(e, "css");
638
+ return m(e, "css");
639
+ }
640
+ function Ae(e) {
641
+ return m(e, "recipe");
617
642
  }
618
643
  function G(e) {
619
644
  return typeof e == "string" || typeof e == "number" || typeof e == "boolean" || e === null;
620
645
  }
621
- function $(e) {
622
- return G(e) || A(e) || E(e) || Array.isArray(e) && e.every($);
646
+ function U(e) {
647
+ return G(e) || A(e) || E(e) || Array.isArray(e) && e.every(U);
623
648
  }
624
649
  function I(e) {
625
- return S(e) && "children" in e && "declarations" in e && "variables" in e;
650
+ return K(e) && "children" in e && "declarations" in e && "variables" in e;
626
651
  }
627
652
  function z(e = (r) => r) {
628
653
  return (r) => {
@@ -647,7 +672,7 @@ function W(e, r) {
647
672
  };
648
673
  };
649
674
  }
650
- function C(e, r) {
675
+ function S(e, r) {
651
676
  return function(t, i, c) {
652
677
  const o = {
653
678
  type: "at-rule",
@@ -657,17 +682,17 @@ function C(e, r) {
657
682
  variables: [],
658
683
  children: []
659
684
  }, u = v(o, r);
660
- return typeof c == "function" ? o.declarations = c(u) ?? {} : c && (o.declarations = c), V(o.declarations, u), e.children.push(o), o;
685
+ return typeof c == "function" ? o.declarations = c(u) ?? {} : c && (o.declarations = c), k(o.declarations, u), e.children.push(o), o;
661
686
  };
662
687
  }
663
688
  function Y(e, r) {
664
- const n = C(e, r);
689
+ const n = S(e, r);
665
690
  return function(i, c) {
666
691
  return n("media", i, c);
667
692
  };
668
693
  }
669
694
  function Z(e, r) {
670
- const n = C(e, r);
695
+ const n = S(e, r);
671
696
  return function(i, c) {
672
697
  return n("keyframes", i, c);
673
698
  };
@@ -694,7 +719,7 @@ function Q(e, r) {
694
719
  variables: [],
695
720
  children: []
696
721
  }, o = v(c, r);
697
- 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;
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, k(c.declarations, o), e.children.push(c), c;
698
723
  };
699
724
  }
700
725
  function X(e, r) {
@@ -717,7 +742,7 @@ function X(e, r) {
717
742
  };
718
743
  }
719
744
  function v(e, r) {
720
- const n = X(e), t = Q(e, r), i = C(e, r), c = Z(r, r), o = Y(e, r), u = J(), s = W();
745
+ const n = X(e), t = Q(e, r), i = S(e, r), c = Z(r, r), o = Y(e, r), u = J(), s = W();
721
746
  return {
722
747
  variable: n,
723
748
  selector: t,
@@ -728,11 +753,11 @@ function v(e, r) {
728
753
  css: s
729
754
  };
730
755
  }
731
- function V(e, r) {
756
+ function k(e, r) {
732
757
  for (const n in e)
733
758
  if (n.startsWith("@")) {
734
759
  const t = e[n];
735
- if (typeof t == "object" && t !== null && !$(t)) {
760
+ if (typeof t == "object" && t !== null && !U(t)) {
736
761
  const i = n.replace(/^@(\w+).*/, "$1"), c = n.replace(`@${i}`, "").trim();
737
762
  r.atRule(i, c, t), delete e[n];
738
763
  }
@@ -817,16 +842,16 @@ function te(e) {
817
842
  function c(s, f) {
818
843
  const l = Object.keys(s), a = Array.from({ length: l.length });
819
844
  for (let y = 0; y < l.length; y++) {
820
- const m = l[y], d2 = s[m];
845
+ const p = l[y], d2 = s[p];
821
846
  if (typeof d2 != "object" || d2 === null)
822
- a[m] = d2;
847
+ a[p] = d2;
823
848
  else if (d2.constructor !== Object && (i = t.get(d2.constructor)))
824
- a[m] = i(d2, f);
849
+ a[p] = i(d2, f);
825
850
  else if (ArrayBuffer.isView(d2))
826
- a[m] = j(d2);
851
+ a[p] = j(d2);
827
852
  else {
828
853
  const h2 = r.indexOf(d2);
829
- h2 !== -1 ? a[m] = n[h2] : a[m] = f(d2);
854
+ h2 !== -1 ? a[p] = n[h2] : a[p] = f(d2);
830
855
  }
831
856
  }
832
857
  return a;
@@ -922,7 +947,7 @@ function fe(e, r, n) {
922
947
  declarations: R(t.declarations),
923
948
  variables: R(t.variables),
924
949
  children: R(t.children)
925
- }), V(t.declarations, i);
950
+ }), k(t.declarations, i);
926
951
  return t;
927
952
  }
928
953
  function ue(e, r) {
@@ -970,7 +995,7 @@ function le(e, r) {
970
995
  for (const [l, a] of Object.entries(f)) {
971
996
  const y = o.values.find(
972
997
  (h2) => h2.key === l && h2.modifiers.length === 0
973
- ), m = {
998
+ ), p = {
974
999
  type: "utility",
975
1000
  name: t,
976
1001
  value: l,
@@ -979,32 +1004,32 @@ function le(e, r) {
979
1004
  children: [],
980
1005
  modifiers: []
981
1006
  }, d2 = v(
982
- m,
1007
+ p,
983
1008
  r
984
1009
  );
985
- if (m.declarations = i({
1010
+ if (p.declarations = i({
986
1011
  ...d2,
987
1012
  value: a
988
- }) ?? {}, V(m.declarations, d2), y || (o.values.push({
1013
+ }) ?? {}, k(p.declarations, d2), y || (o.values.push({
989
1014
  key: l,
990
1015
  value: a,
991
1016
  modifiers: []
992
- }), e.children.push(m)), s && s.length > 0) {
993
- const h2 = s.map((b) => b.key), H2 = ce(h2).filter((b) => !o.values.find(
994
- (g2) => g2.key === l && g2.modifiers.length === b.length && g2.modifiers.every((w2) => b.includes(w2))
995
- )).reduce((b, g2) => {
1017
+ }), e.children.push(p)), s && s.length > 0) {
1018
+ const h2 = s.map((g2) => g2.key), H2 = ce(h2).filter((g2) => !o.values.find(
1019
+ (b) => b.key === l && b.modifiers.length === g2.length && b.modifiers.every((w2) => g2.includes(w2))
1020
+ )).reduce((g2, b) => {
996
1021
  const w2 = /* @__PURE__ */ new Map();
997
- for (const K2 of g2) {
998
- const k2 = s.find(
999
- (N2) => N2.key.includes(K2)
1022
+ for (const $2 of b) {
1023
+ const V2 = s.find(
1024
+ (N2) => N2.key.includes($2)
1000
1025
  );
1001
- k2 && q(k2) && w2.set(K2, k2);
1026
+ V2 && q(V2) && w2.set($2, V2);
1002
1027
  }
1003
1028
  return o.values.push({
1004
1029
  key: l,
1005
1030
  value: a,
1006
- modifiers: g2
1007
- }), b.push(fe(m, r, w2)), b;
1031
+ modifiers: b
1032
+ }), g2.push(fe(p, r, w2)), g2;
1008
1033
  }, []);
1009
1034
  e.children.push(...H2);
1010
1035
  }
@@ -1034,10 +1059,10 @@ function de(e, r) {
1034
1059
  type: "recipe",
1035
1060
  ...t
1036
1061
  };
1037
- return i._runtime = me(i, r), pe(i, r), r.recipes.push(i), i;
1062
+ return i._runtime = pe(i, r), me(i, r), r.recipes.push(i), i;
1038
1063
  };
1039
1064
  }
1040
- function _(e, r) {
1065
+ function C(e, r) {
1041
1066
  const n = e.autogenerate(r);
1042
1067
  return Object.keys(n)[0] ?? "default";
1043
1068
  }
@@ -1048,21 +1073,25 @@ function F(e, r) {
1048
1073
  const c = {};
1049
1074
  for (const [o, u] of Object.entries(i)) {
1050
1075
  const s = T(r, o);
1051
- s && (c[o] = _(
1076
+ s ? c[o] = C(
1052
1077
  s,
1053
1078
  u
1054
- ));
1079
+ ) : console.warn(
1080
+ `[styleframe] Utility "${o}" not found in registry. Skipping runtime generation for this declaration.`
1081
+ );
1055
1082
  }
1056
1083
  n[t] = c;
1057
1084
  } else if (typeof i == "boolean")
1058
1085
  n[t] = i;
1059
1086
  else {
1060
1087
  const c = T(r, t);
1061
- c && (n[t] = _(c, i));
1088
+ c ? n[t] = C(c, i) : console.warn(
1089
+ `[styleframe] Utility "${t}" not found in registry. Skipping runtime generation for this declaration.`
1090
+ );
1062
1091
  }
1063
1092
  return n;
1064
1093
  }
1065
- function me(e, r) {
1094
+ function pe(e, r) {
1066
1095
  const n = {};
1067
1096
  if (e.base && (n.base = F(e.base, r)), e.variants) {
1068
1097
  const t = {};
@@ -1107,7 +1136,7 @@ function T(e, r) {
1107
1136
  const t = r.replace(/[A-Z]/g, (i) => `-${i.toLowerCase()}`);
1108
1137
  return e.utilities.find((i) => i.name === t);
1109
1138
  }
1110
- function pe(e, r) {
1139
+ function me(e, r) {
1111
1140
  const n = /* @__PURE__ */ new Map();
1112
1141
  if (e.base && x(e.base, n), e.variants)
1113
1142
  for (const i of Object.values(e.variants))
@@ -1150,7 +1179,7 @@ function pe(e, r) {
1150
1179
  }
1151
1180
  }
1152
1181
  function Re(e) {
1153
- 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);
1182
+ 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: p, css: d2 } = v(n, n);
1154
1183
  return {
1155
1184
  id: r,
1156
1185
  root: n,
@@ -1163,46 +1192,90 @@ function Re(e) {
1163
1192
  atRule: l,
1164
1193
  keyframes: a,
1165
1194
  media: y,
1166
- ref: m,
1195
+ ref: p,
1167
1196
  css: d2,
1168
1197
  options: t
1169
1198
  };
1170
1199
  }
1200
+ const SUPPORTED_EXTENSIONS = [".ts", ".mts", ".cts", ".js", ".mjs", ".cjs"];
1201
+ function hasKnownExtension(filePath) {
1202
+ return SUPPORTED_EXTENSIONS.some((ext) => filePath.endsWith(ext));
1203
+ }
1204
+ function resolveConfigFile(cwd, entry) {
1205
+ const basePath = path.isAbsolute(entry) ? entry : path.join(cwd, entry);
1206
+ if (hasKnownExtension(basePath)) {
1207
+ return existsSync(basePath) ? basePath : void 0;
1208
+ }
1209
+ for (const ext of SUPPORTED_EXTENSIONS) {
1210
+ const filePath = `${basePath}${ext}`;
1211
+ if (existsSync(filePath)) {
1212
+ return filePath;
1213
+ }
1214
+ }
1215
+ return void 0;
1216
+ }
1217
+ function trackNamedExports(module) {
1218
+ for (const [exportName, exportValue] of Object.entries(module)) {
1219
+ if (exportName === "default") continue;
1220
+ if (Ae(exportValue)) {
1221
+ exportValue._exportName = exportName;
1222
+ } else if (ge(exportValue)) {
1223
+ exportValue._exportName = exportName;
1224
+ }
1225
+ }
1226
+ }
1171
1227
  async function loadConfiguration({
1172
1228
  cwd = process.cwd(),
1173
- configFile = "styleframe.config"
1229
+ entry = "styleframe.config"
1174
1230
  } = {}) {
1175
- const { config } = await loadConfig({
1176
- cwd,
1177
- configFile,
1178
- defaults: Re()
1231
+ const resolvedPath = resolveConfigFile(cwd, entry);
1232
+ if (!resolvedPath) {
1233
+ return Re();
1234
+ }
1235
+ const jiti = createJiti(path.dirname(resolvedPath), {
1236
+ fsCache: false,
1237
+ moduleCache: false
1179
1238
  });
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 });
1239
+ const module = await jiti.import(resolvedPath);
1240
+ if (!module.default) {
1241
+ throw new Error(
1242
+ `Missing default export in ${resolvedPath}. Expected a Styleframe instance.`
1243
+ );
1244
+ }
1245
+ trackNamedExports(module);
1246
+ return module.default;
1187
1247
  }
1188
1248
  async function watchConfiguration({
1189
- cwd = process.cwd()
1249
+ cwd = process.cwd(),
1250
+ entry = "styleframe.config",
1251
+ onUpdate,
1252
+ onError
1190
1253
  } = {}) {
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
- }
1254
+ const resolvedPath = resolveConfigFile(cwd, entry);
1255
+ if (!resolvedPath) {
1256
+ throw new Error(`Config file not found: ${entry}`);
1257
+ }
1258
+ const watcher = watch(resolvedPath, { ignoreInitial: true });
1259
+ watcher.on("change", async () => {
1260
+ try {
1261
+ const config = await loadConfiguration({ entry: resolvedPath });
1262
+ onUpdate?.(config);
1263
+ } catch (error) {
1264
+ onError?.(error instanceof Error ? error : new Error(String(error)));
1199
1265
  }
1200
1266
  });
1267
+ watcher.on("unlink", () => {
1268
+ onError?.(new Error(`Config file was deleted: ${resolvedPath}`));
1269
+ });
1270
+ return {
1271
+ config: await loadConfiguration({ entry: resolvedPath }),
1272
+ configFile: resolvedPath,
1273
+ unwatch: () => watcher.close()
1274
+ };
1201
1275
  }
1202
1276
  export {
1203
1277
  build,
1204
1278
  directoryExists,
1205
1279
  loadConfiguration,
1206
- loadConfigurationFromPath,
1207
1280
  watchConfiguration
1208
1281
  };