@styleframe/loader 3.0.0 → 3.0.2

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