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