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