@styleframe/loader 2.3.0 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/dist/index.cjs +317 -246
- package/dist/index.d.ts +11 -8
- package/dist/index.js +318 -245
- package/package.json +9 -8
package/dist/index.js
CHANGED
|
@@ -1,103 +1,105 @@
|
|
|
1
1
|
import { stat, rm, mkdir, writeFile } from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { validateInstanceLicense, getLicenseKeyFromEnv } from "@styleframe/license";
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import { watch } from "chokidar";
|
|
5
|
+
import { createJiti } from "jiti";
|
|
6
|
+
import { existsSync } from "node:fs";
|
|
7
|
+
const F$1 = ["charset", "import", "namespace"], L$1 = ["layer"], D = ({ name: e }) => `[data-theme="${e}"]`, x$1 = ({
|
|
6
8
|
name: e,
|
|
7
9
|
value: t,
|
|
8
10
|
modifiers: r
|
|
9
11
|
}) => `._${[...r, e, ...t === "default" ? [] : [t]].filter(Boolean).join("\\:").replace(/[[\].#()%,]/g, "\\$&")}`, w = ({ name: e }) => e.replace(/^\.+|\.+$/g, "").replace(/\.+/g, "--");
|
|
10
|
-
function
|
|
12
|
+
function I$1(e, t) {
|
|
11
13
|
return `@${e}${t ? " " : ""}${t}`;
|
|
12
14
|
}
|
|
13
|
-
const
|
|
15
|
+
const U$1 = /\d/, P$1 = ["-", "_", "/", "."];
|
|
14
16
|
function M(e = "") {
|
|
15
|
-
if (!
|
|
17
|
+
if (!U$1.test(e))
|
|
16
18
|
return e !== e.toLowerCase();
|
|
17
19
|
}
|
|
18
|
-
function
|
|
20
|
+
function N(e, t) {
|
|
19
21
|
const r = P$1, n = [];
|
|
20
22
|
if (!e || typeof e != "string")
|
|
21
23
|
return n;
|
|
22
|
-
let o = "", s,
|
|
24
|
+
let o = "", s, u;
|
|
23
25
|
for (const a of e) {
|
|
24
26
|
const c = r.includes(a);
|
|
25
27
|
if (c === true) {
|
|
26
28
|
n.push(o), o = "", s = void 0;
|
|
27
29
|
continue;
|
|
28
30
|
}
|
|
29
|
-
const
|
|
30
|
-
if (
|
|
31
|
-
if (s === false &&
|
|
32
|
-
n.push(o), o = a, s =
|
|
31
|
+
const i = M(a);
|
|
32
|
+
if (u === false) {
|
|
33
|
+
if (s === false && i === true) {
|
|
34
|
+
n.push(o), o = a, s = i;
|
|
33
35
|
continue;
|
|
34
36
|
}
|
|
35
|
-
if (s === true &&
|
|
37
|
+
if (s === true && i === false && o.length > 1) {
|
|
36
38
|
const f = o.at(-1);
|
|
37
|
-
n.push(o.slice(0, Math.max(0, o.length - 1))), o = f + a, s =
|
|
39
|
+
n.push(o.slice(0, Math.max(0, o.length - 1))), o = f + a, s = i;
|
|
38
40
|
continue;
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
|
-
o += a, s =
|
|
43
|
+
o += a, s = i, u = c;
|
|
42
44
|
}
|
|
43
45
|
return n.push(o), n;
|
|
44
46
|
}
|
|
45
|
-
function k(e) {
|
|
47
|
+
function k$1(e) {
|
|
46
48
|
return e ? e[0].toUpperCase() + e.slice(1) : "";
|
|
47
49
|
}
|
|
48
|
-
function
|
|
50
|
+
function V(e) {
|
|
49
51
|
return e ? e[0].toLowerCase() + e.slice(1) : "";
|
|
50
52
|
}
|
|
51
|
-
function
|
|
52
|
-
return e ? (Array.isArray(e) ? e :
|
|
53
|
-
}
|
|
54
|
-
function K(e, t) {
|
|
55
|
-
return x$1(V$1(e || ""));
|
|
53
|
+
function K$1(e, t) {
|
|
54
|
+
return e ? (Array.isArray(e) ? e : N(e)).map((r) => k$1(r)).join("") : "";
|
|
56
55
|
}
|
|
57
56
|
function q$1(e, t) {
|
|
58
|
-
return
|
|
57
|
+
return V(K$1(e || ""));
|
|
59
58
|
}
|
|
60
|
-
function z$1(e) {
|
|
61
|
-
return
|
|
59
|
+
function z$1(e, t) {
|
|
60
|
+
return e ? (Array.isArray(e) ? e : N(e)).map((r) => r.toLowerCase()).join("-") : "";
|
|
62
61
|
}
|
|
63
62
|
function H(e) {
|
|
63
|
+
return ` ${e}`;
|
|
64
|
+
}
|
|
65
|
+
function Q$1(e) {
|
|
64
66
|
return e.split(`
|
|
65
|
-
`).map((t) =>
|
|
67
|
+
`).map((t) => H(t)).join(`
|
|
66
68
|
`);
|
|
67
69
|
}
|
|
68
|
-
function
|
|
70
|
+
function J$1(e) {
|
|
69
71
|
return e === e.toUpperCase();
|
|
70
72
|
}
|
|
71
73
|
function Z$1(e) {
|
|
72
|
-
return K(e);
|
|
73
|
-
}
|
|
74
|
-
function J$1(e) {
|
|
75
74
|
return q$1(e);
|
|
76
75
|
}
|
|
77
76
|
function W$1(e) {
|
|
78
|
-
return
|
|
77
|
+
return z$1(e);
|
|
78
|
+
}
|
|
79
|
+
function G$1(e) {
|
|
80
|
+
return W$1(e);
|
|
79
81
|
}
|
|
80
82
|
function O(e, t) {
|
|
81
|
-
return `${e.startsWith("--") ? e :
|
|
83
|
+
return `${e.startsWith("--") ? e : G$1(e)}: ${t};`;
|
|
82
84
|
}
|
|
83
|
-
function
|
|
85
|
+
function Y$1(e) {
|
|
84
86
|
return `{${e.length > 0 ? `
|
|
85
|
-
` : ""}${e.map((t) => `${
|
|
87
|
+
` : ""}${e.map((t) => `${Q$1(`${t}`)}
|
|
86
88
|
`).join("")}}`;
|
|
87
89
|
}
|
|
88
90
|
function B(e) {
|
|
89
91
|
return `--${(e.startsWith("--") ? e.slice(2) : e).replace(/[^a-zA-Z0-9_\-\u0080-\uFFFF]/g, "-") || "unknown-variable"}`;
|
|
90
92
|
}
|
|
91
|
-
function
|
|
93
|
+
function X$1(e, t) {
|
|
92
94
|
return O(B(e), t);
|
|
93
95
|
}
|
|
94
|
-
function
|
|
96
|
+
function ee$1(e, t) {
|
|
95
97
|
return `var(${B(e)}${t ? `, ${t}` : ""})`;
|
|
96
98
|
}
|
|
97
|
-
function
|
|
98
|
-
return `${e} ${
|
|
99
|
+
function R$1(e, t) {
|
|
100
|
+
return `${e} ${Y$1(t)}`;
|
|
99
101
|
}
|
|
100
|
-
function
|
|
102
|
+
function te$1(e) {
|
|
101
103
|
return function(r, n) {
|
|
102
104
|
return Object.entries(r).map(([o, s]) => O(o, e(s, n)));
|
|
103
105
|
};
|
|
@@ -105,66 +107,66 @@ function ee$1(e) {
|
|
|
105
107
|
function E$1(e) {
|
|
106
108
|
return function(r, n) {
|
|
107
109
|
const s = (n.variables?.name ?? w)({ name: r.name });
|
|
108
|
-
return
|
|
110
|
+
return X$1(s, e(r.value, n));
|
|
109
111
|
};
|
|
110
112
|
}
|
|
111
|
-
function
|
|
112
|
-
const t = E$1(e), r =
|
|
113
|
-
return function(o, s,
|
|
114
|
-
const { variables: a, declarations: c, children:
|
|
115
|
-
(A2) => t(A2,
|
|
116
|
-
),
|
|
113
|
+
function S$1(e) {
|
|
114
|
+
const t = E$1(e), r = te$1(e);
|
|
115
|
+
return function(o, s, u) {
|
|
116
|
+
const { variables: a, declarations: c, children: i } = s, f = o === ":root", l = (a ?? []).map(
|
|
117
|
+
(A2) => t(A2, u)
|
|
118
|
+
), m2 = r(
|
|
117
119
|
c ?? {},
|
|
118
|
-
|
|
119
|
-
), y = (
|
|
120
|
-
(A2) => e(A2,
|
|
121
|
-
),
|
|
122
|
-
return f ? `${
|
|
120
|
+
u
|
|
121
|
+
), y = (i ?? []).map(
|
|
122
|
+
(A2) => e(A2, u)
|
|
123
|
+
), p = l.length > 0, b = m2.length > 0, C2 = y.length > 0;
|
|
124
|
+
return f ? `${p || b ? R$1(o, [
|
|
123
125
|
...l,
|
|
124
|
-
...
|
|
125
|
-
...
|
|
126
|
-
]) : ""}${
|
|
126
|
+
...p && b ? [""] : [],
|
|
127
|
+
...m2
|
|
128
|
+
]) : ""}${C2 && (p || b) ? `
|
|
127
129
|
|
|
128
130
|
` : ""}${y.join(`
|
|
129
131
|
|
|
130
|
-
`)}` :
|
|
132
|
+
`)}` : R$1(o, [
|
|
131
133
|
...l,
|
|
132
|
-
...
|
|
133
|
-
...
|
|
134
|
-
...b &&
|
|
134
|
+
...p && (C2 || b) ? [""] : [],
|
|
135
|
+
...m2,
|
|
136
|
+
...b && C2 ? [""] : [],
|
|
135
137
|
...y.flatMap(
|
|
136
|
-
(A2,
|
|
138
|
+
(A2, _) => _ === y.length - 1 ? [A2] : [A2, ""]
|
|
137
139
|
)
|
|
138
140
|
]);
|
|
139
141
|
};
|
|
140
142
|
}
|
|
141
|
-
function
|
|
142
|
-
const t =
|
|
143
|
+
function re$1(e) {
|
|
144
|
+
const t = S$1(e);
|
|
143
145
|
return function(n, o) {
|
|
144
|
-
const s =
|
|
146
|
+
const s = F$1.includes(n.identifier), u = L$1.includes(
|
|
145
147
|
n.identifier
|
|
146
|
-
), a = Object.keys(n.declarations).length > 0, c = n.variables.length > 0,
|
|
147
|
-
return s ||
|
|
148
|
+
), a = Object.keys(n.declarations).length > 0, c = n.variables.length > 0, i = n.children.length > 0, f = I$1(n.identifier, n.rule);
|
|
149
|
+
return s || u && !(a || c || i) ? `${f};` : t(f, n, o);
|
|
148
150
|
};
|
|
149
151
|
}
|
|
150
|
-
function
|
|
152
|
+
function ne$1(e) {
|
|
151
153
|
return function(r, n) {
|
|
152
154
|
return r.value.map((o) => e(o, n)).join("").trim();
|
|
153
155
|
};
|
|
154
156
|
}
|
|
155
|
-
function
|
|
157
|
+
function oe(e) {
|
|
156
158
|
return typeof e == "object" && e !== null;
|
|
157
159
|
}
|
|
158
160
|
function h(e, t) {
|
|
159
|
-
return
|
|
161
|
+
return oe(e) && "type" in e && e.type === t;
|
|
160
162
|
}
|
|
161
|
-
function
|
|
163
|
+
function ce$1(e) {
|
|
162
164
|
return h(e, "variable");
|
|
163
165
|
}
|
|
164
|
-
function
|
|
166
|
+
function ue$1(e) {
|
|
165
167
|
return h(e, "reference");
|
|
166
168
|
}
|
|
167
|
-
function
|
|
169
|
+
function v$1(e) {
|
|
168
170
|
return h(e, "selector");
|
|
169
171
|
}
|
|
170
172
|
function ie(e) {
|
|
@@ -202,47 +204,47 @@ function pe$1(e) {
|
|
|
202
204
|
if (e = e || {}, e.circular)
|
|
203
205
|
return ye$1(e);
|
|
204
206
|
const t = /* @__PURE__ */ new Map();
|
|
205
|
-
if (t.set(Date, (
|
|
207
|
+
if (t.set(Date, (u) => new Date(u)), t.set(
|
|
206
208
|
Map,
|
|
207
|
-
(
|
|
209
|
+
(u, a) => new Map(n(Array.from(u), a))
|
|
208
210
|
), t.set(
|
|
209
211
|
Set,
|
|
210
|
-
(
|
|
212
|
+
(u, a) => new Set(n(Array.from(u), a))
|
|
211
213
|
), e.constructorHandlers)
|
|
212
|
-
for (const
|
|
213
|
-
t.set(
|
|
214
|
+
for (const u of e.constructorHandlers)
|
|
215
|
+
t.set(u[0], u[1]);
|
|
214
216
|
let r;
|
|
215
217
|
return e.proto ? s : o;
|
|
216
|
-
function n(
|
|
217
|
-
const c = Object.keys(
|
|
218
|
+
function n(u, a) {
|
|
219
|
+
const c = Object.keys(u), i = Array.from({ length: c.length });
|
|
218
220
|
for (let f = 0; f < c.length; f++) {
|
|
219
|
-
const l = c[f],
|
|
220
|
-
typeof
|
|
221
|
+
const l = c[f], m2 = u[l];
|
|
222
|
+
typeof m2 != "object" || m2 === null ? i[l] = m2 : m2.constructor !== Object && (r = t.get(m2.constructor)) ? i[l] = r(m2, a) : ArrayBuffer.isView(m2) ? i[l] = g(m2) : i[l] = a(m2);
|
|
221
223
|
}
|
|
222
|
-
return
|
|
224
|
+
return i;
|
|
223
225
|
}
|
|
224
|
-
function o(
|
|
225
|
-
if (typeof
|
|
226
|
-
if (Array.isArray(
|
|
227
|
-
if (
|
|
228
|
-
return r(
|
|
226
|
+
function o(u) {
|
|
227
|
+
if (typeof u != "object" || u === null) return u;
|
|
228
|
+
if (Array.isArray(u)) return n(u, o);
|
|
229
|
+
if (u.constructor !== Object && (r = t.get(u.constructor)))
|
|
230
|
+
return r(u, o);
|
|
229
231
|
const a = {};
|
|
230
|
-
for (const c in
|
|
231
|
-
if (Object.hasOwnProperty.call(
|
|
232
|
-
const
|
|
233
|
-
typeof
|
|
232
|
+
for (const c in u) {
|
|
233
|
+
if (Object.hasOwnProperty.call(u, c) === false) continue;
|
|
234
|
+
const i = u[c];
|
|
235
|
+
typeof i != "object" || i === null ? a[c] = i : i.constructor !== Object && (r = t.get(i.constructor)) ? a[c] = r(i, o) : ArrayBuffer.isView(i) ? a[c] = g(i) : a[c] = o(i);
|
|
234
236
|
}
|
|
235
237
|
return a;
|
|
236
238
|
}
|
|
237
|
-
function s(
|
|
238
|
-
if (typeof
|
|
239
|
-
if (Array.isArray(
|
|
240
|
-
if (
|
|
241
|
-
return r(
|
|
239
|
+
function s(u) {
|
|
240
|
+
if (typeof u != "object" || u === null) return u;
|
|
241
|
+
if (Array.isArray(u)) return n(u, s);
|
|
242
|
+
if (u.constructor !== Object && (r = t.get(u.constructor)))
|
|
243
|
+
return r(u, s);
|
|
242
244
|
const a = {};
|
|
243
|
-
for (const c in
|
|
244
|
-
const
|
|
245
|
-
typeof
|
|
245
|
+
for (const c in u) {
|
|
246
|
+
const i = u[c];
|
|
247
|
+
typeof i != "object" || i === null ? a[c] = i : i.constructor !== Object && (r = t.get(i.constructor)) ? a[c] = r(i, s) : ArrayBuffer.isView(i) ? a[c] = g(i) : a[c] = s(i);
|
|
246
248
|
}
|
|
247
249
|
return a;
|
|
248
250
|
}
|
|
@@ -251,76 +253,76 @@ function ye$1(e) {
|
|
|
251
253
|
const t = [], r = [], n = /* @__PURE__ */ new Map();
|
|
252
254
|
if (n.set(Date, (c) => new Date(c)), n.set(
|
|
253
255
|
Map,
|
|
254
|
-
(c,
|
|
256
|
+
(c, i) => new Map(s(Array.from(c), i))
|
|
255
257
|
), n.set(
|
|
256
258
|
Set,
|
|
257
|
-
(c,
|
|
259
|
+
(c, i) => new Set(s(Array.from(c), i))
|
|
258
260
|
), e.constructorHandlers)
|
|
259
261
|
for (const c of e.constructorHandlers)
|
|
260
262
|
n.set(c[0], c[1]);
|
|
261
263
|
let o;
|
|
262
|
-
return e.proto ? a :
|
|
263
|
-
function s(c,
|
|
264
|
+
return e.proto ? a : u;
|
|
265
|
+
function s(c, i) {
|
|
264
266
|
const f = Object.keys(c), l = Array.from({ length: f.length });
|
|
265
|
-
for (let
|
|
266
|
-
const y = f[
|
|
267
|
-
if (typeof
|
|
268
|
-
l[y] =
|
|
269
|
-
else if (
|
|
270
|
-
l[y] = o(
|
|
271
|
-
else if (ArrayBuffer.isView(
|
|
272
|
-
l[y] = g(
|
|
267
|
+
for (let m2 = 0; m2 < f.length; m2++) {
|
|
268
|
+
const y = f[m2], p = c[y];
|
|
269
|
+
if (typeof p != "object" || p === null)
|
|
270
|
+
l[y] = p;
|
|
271
|
+
else if (p.constructor !== Object && (o = n.get(p.constructor)))
|
|
272
|
+
l[y] = o(p, i);
|
|
273
|
+
else if (ArrayBuffer.isView(p))
|
|
274
|
+
l[y] = g(p);
|
|
273
275
|
else {
|
|
274
|
-
const b = t.indexOf(
|
|
275
|
-
b !== -1 ? l[y] = r[b] : l[y] =
|
|
276
|
+
const b = t.indexOf(p);
|
|
277
|
+
b !== -1 ? l[y] = r[b] : l[y] = i(p);
|
|
276
278
|
}
|
|
277
279
|
}
|
|
278
280
|
return l;
|
|
279
281
|
}
|
|
280
|
-
function
|
|
282
|
+
function u(c) {
|
|
281
283
|
if (typeof c != "object" || c === null) return c;
|
|
282
|
-
if (Array.isArray(c)) return s(c,
|
|
284
|
+
if (Array.isArray(c)) return s(c, u);
|
|
283
285
|
if (c.constructor !== Object && (o = n.get(c.constructor)))
|
|
284
|
-
return o(c,
|
|
285
|
-
const
|
|
286
|
-
t.push(c), r.push(
|
|
286
|
+
return o(c, u);
|
|
287
|
+
const i = {};
|
|
288
|
+
t.push(c), r.push(i);
|
|
287
289
|
for (const f in c) {
|
|
288
290
|
if (Object.hasOwnProperty.call(c, f) === false) continue;
|
|
289
291
|
const l = c[f];
|
|
290
292
|
if (typeof l != "object" || l === null)
|
|
291
|
-
|
|
293
|
+
i[f] = l;
|
|
292
294
|
else if (l.constructor !== Object && (o = n.get(l.constructor)))
|
|
293
|
-
|
|
295
|
+
i[f] = o(l, u);
|
|
294
296
|
else if (ArrayBuffer.isView(l))
|
|
295
|
-
|
|
297
|
+
i[f] = g(l);
|
|
296
298
|
else {
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
+
const m2 = t.indexOf(l);
|
|
300
|
+
m2 !== -1 ? i[f] = r[m2] : i[f] = u(l);
|
|
299
301
|
}
|
|
300
302
|
}
|
|
301
|
-
return t.pop(), r.pop(),
|
|
303
|
+
return t.pop(), r.pop(), i;
|
|
302
304
|
}
|
|
303
305
|
function a(c) {
|
|
304
306
|
if (typeof c != "object" || c === null) return c;
|
|
305
307
|
if (Array.isArray(c)) return s(c, a);
|
|
306
308
|
if (c.constructor !== Object && (o = n.get(c.constructor)))
|
|
307
309
|
return o(c, a);
|
|
308
|
-
const
|
|
309
|
-
t.push(c), r.push(
|
|
310
|
+
const i = {};
|
|
311
|
+
t.push(c), r.push(i);
|
|
310
312
|
for (const f in c) {
|
|
311
313
|
const l = c[f];
|
|
312
314
|
if (typeof l != "object" || l === null)
|
|
313
|
-
|
|
315
|
+
i[f] = l;
|
|
314
316
|
else if (l.constructor !== Object && (o = n.get(l.constructor)))
|
|
315
|
-
|
|
317
|
+
i[f] = o(l, a);
|
|
316
318
|
else if (ArrayBuffer.isView(l))
|
|
317
|
-
|
|
319
|
+
i[f] = g(l);
|
|
318
320
|
else {
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
+
const m2 = t.indexOf(l);
|
|
322
|
+
m2 !== -1 ? i[f] = r[m2] : i[f] = a(l);
|
|
321
323
|
}
|
|
322
324
|
}
|
|
323
|
-
return t.pop(), r.pop(),
|
|
325
|
+
return t.pop(), r.pop(), i;
|
|
324
326
|
}
|
|
325
327
|
}
|
|
326
328
|
pe$1();
|
|
@@ -332,17 +334,17 @@ function de$1(e) {
|
|
|
332
334
|
function he(e) {
|
|
333
335
|
return function(r, n) {
|
|
334
336
|
const s = (n.variables?.name ?? w)({ name: r.name });
|
|
335
|
-
return
|
|
337
|
+
return ee$1(
|
|
336
338
|
s,
|
|
337
339
|
r.fallback ? e(r.fallback, n) : void 0
|
|
338
340
|
);
|
|
339
341
|
};
|
|
340
342
|
}
|
|
341
343
|
function be(e) {
|
|
342
|
-
const t =
|
|
344
|
+
const t = S$1(e);
|
|
343
345
|
return function(n, o) {
|
|
344
346
|
return n.themes.reduce(
|
|
345
|
-
(s,
|
|
347
|
+
(s, u) => (s.push(e(u, o)), s),
|
|
346
348
|
[t(":root", n, o)]
|
|
347
349
|
// Default theme (root)
|
|
348
350
|
).join(`
|
|
@@ -350,23 +352,23 @@ function be(e) {
|
|
|
350
352
|
`);
|
|
351
353
|
};
|
|
352
354
|
}
|
|
353
|
-
function Ae(e) {
|
|
354
|
-
const t =
|
|
355
|
+
function Ae$1(e) {
|
|
356
|
+
const t = S$1(e);
|
|
355
357
|
return function(n, o) {
|
|
356
358
|
return t(n.query, n, o);
|
|
357
359
|
};
|
|
358
360
|
}
|
|
359
|
-
function ge(e) {
|
|
360
|
-
const t =
|
|
361
|
+
function ge$1(e) {
|
|
362
|
+
const t = S$1(e);
|
|
361
363
|
return function(n, o) {
|
|
362
|
-
const
|
|
363
|
-
return t(
|
|
364
|
+
const u = (o.themes?.selector ?? D)({ name: n.name });
|
|
365
|
+
return t(u, n, o);
|
|
364
366
|
};
|
|
365
367
|
}
|
|
366
|
-
function
|
|
367
|
-
const t =
|
|
368
|
+
function Se(e) {
|
|
369
|
+
const t = S$1(e);
|
|
368
370
|
return function(n, o) {
|
|
369
|
-
const s = [], a = (o.utilities?.selector ??
|
|
371
|
+
const s = [], a = (o.utilities?.selector ?? x$1)({
|
|
370
372
|
name: n.name,
|
|
371
373
|
value: n.value,
|
|
372
374
|
modifiers: n.modifiers
|
|
@@ -377,9 +379,9 @@ function Ce(e) {
|
|
|
377
379
|
};
|
|
378
380
|
}
|
|
379
381
|
function d(e, t) {
|
|
380
|
-
const r = be(d), n = Ae(d), o =
|
|
382
|
+
const r = be(d), n = Ae$1(d), o = Se(d), s = re$1(d), u = ge$1(d), a = E$1(d), c = he(d), i = ne$1(d), f = de$1();
|
|
381
383
|
switch (true) {
|
|
382
|
-
case
|
|
384
|
+
case v$1(e):
|
|
383
385
|
return n(e, t);
|
|
384
386
|
case se(e):
|
|
385
387
|
return o(e, t);
|
|
@@ -388,24 +390,24 @@ function d(e, t) {
|
|
|
388
390
|
case T$1(e):
|
|
389
391
|
return r(e, t);
|
|
390
392
|
case le$1(e):
|
|
391
|
-
return
|
|
392
|
-
case oe(e):
|
|
393
|
-
return a(e, t);
|
|
393
|
+
return u(e, t);
|
|
394
394
|
case ce$1(e):
|
|
395
|
+
return a(e, t);
|
|
396
|
+
case ue$1(e):
|
|
395
397
|
return c(e, t);
|
|
396
398
|
case ae$1(e):
|
|
397
|
-
return
|
|
399
|
+
return i(e, t);
|
|
398
400
|
default:
|
|
399
401
|
return f(e, t);
|
|
400
402
|
}
|
|
401
403
|
}
|
|
402
|
-
function
|
|
404
|
+
function Ce(e) {
|
|
403
405
|
return function(r, n) {
|
|
404
|
-
let o =
|
|
405
|
-
r.name[0] &&
|
|
406
|
-
const s = `${o}Recipe`,
|
|
406
|
+
let o = r._exportName;
|
|
407
|
+
o || (o = Z$1(r.name), r.name[0] && J$1(r.name[0]) && (o = me$1(o)));
|
|
408
|
+
const s = `${o}Recipe`, u = r._runtime ?? {};
|
|
407
409
|
return `const ${s} = ${JSON.stringify(
|
|
408
|
-
|
|
410
|
+
u,
|
|
409
411
|
null,
|
|
410
412
|
4
|
|
411
413
|
)} as const satisfies RecipeRuntime;
|
|
@@ -415,28 +417,45 @@ export const ${o} = createRecipe("${r.name}", ${s});
|
|
|
415
417
|
};
|
|
416
418
|
}
|
|
417
419
|
function je(e) {
|
|
420
|
+
return e.filter(
|
|
421
|
+
(t) => v$1(t) && !!t._exportName
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
function ve(e) {
|
|
418
425
|
return function(r, n) {
|
|
419
|
-
|
|
426
|
+
const o = je(r.children), s = r.recipes.length > 0, u = o.length > 0;
|
|
427
|
+
if (!s && !u)
|
|
428
|
+
return "";
|
|
429
|
+
const a = [];
|
|
430
|
+
return s && (a.push(`import { createRecipe } from '@styleframe/runtime';
|
|
420
431
|
import type { RecipeRuntime } from '@styleframe/runtime';
|
|
421
|
-
|
|
422
|
-
|
|
432
|
+
`), a.push(e(r.recipes, n))), u && a.push(e(o, n)), a.join(`
|
|
433
|
+
`);
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
function Re$1(e) {
|
|
437
|
+
return function(r, n) {
|
|
438
|
+
return r._exportName ? `export const ${r._exportName} = ${JSON.stringify(r.query)};
|
|
439
|
+
` : "";
|
|
423
440
|
};
|
|
424
441
|
}
|
|
425
442
|
function j$1(e, t) {
|
|
426
|
-
const r =
|
|
443
|
+
const r = ve(j$1), n = Ce(), o = Re$1();
|
|
427
444
|
switch (true) {
|
|
428
445
|
case Array.isArray(e):
|
|
429
|
-
return e.map((
|
|
446
|
+
return e.map((s) => j$1(s, t)).join(`
|
|
430
447
|
`);
|
|
431
448
|
case T$1(e):
|
|
432
449
|
return r(e, t);
|
|
433
450
|
case fe$1(e):
|
|
434
451
|
return n(e, t);
|
|
452
|
+
case v$1(e):
|
|
453
|
+
return o(e, t);
|
|
435
454
|
default:
|
|
436
455
|
return "";
|
|
437
456
|
}
|
|
438
457
|
}
|
|
439
|
-
const
|
|
458
|
+
const $e = `-----BEGIN PUBLIC KEY-----
|
|
440
459
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAs7zAFssgxOMPeo80iig4
|
|
441
460
|
qSSshgNOLnW1gd4tPUrsezndaUrAKlsAys6XD8kuF+bBEIR0uFNSgKlqINLjWM1n
|
|
442
461
|
BiTUzCctodyRaq6/tyFSoPLD35iblkwtfxKPM42lAJZsyTu9qoBr8MJyXmhDLuqA
|
|
@@ -444,8 +463,8 @@ dQ8di7mQHz+mCy96jQR4lFSDfHMgl27qaAh5VboTBRxgZliN8D5Fl590QkS94wAj
|
|
|
444
463
|
hC7NbH+hPcGc/qIaZSjZfyZeBIZS74qJkrzjEA7/pukROD8UQUrQ512HHZ6XlgMn
|
|
445
464
|
4bWT2K9CpWbbhsKFTecCHuxlmPkFJNMuvAb/LdP08BSnpntlyAJcQeBrna2qBen+
|
|
446
465
|
GwIDAQAB
|
|
447
|
-
-----END PUBLIC KEY-----`,
|
|
448
|
-
async function
|
|
466
|
+
-----END PUBLIC KEY-----`, we = "__licenseRequired", Ne = "__licenseValidated";
|
|
467
|
+
async function Oe(e) {
|
|
449
468
|
const t = e.replace(/-----BEGIN PUBLIC KEY-----/, "").replace(/-----END PUBLIC KEY-----/, "").replace(/\s/g, ""), r = Uint8Array.from(atob(t), (n) => n.charCodeAt(0));
|
|
450
469
|
return await crypto.subtle.importKey(
|
|
451
470
|
"spki",
|
|
@@ -458,14 +477,14 @@ async function $e(e) {
|
|
|
458
477
|
["verify"]
|
|
459
478
|
);
|
|
460
479
|
}
|
|
461
|
-
async function
|
|
480
|
+
async function Be({
|
|
462
481
|
payload: e,
|
|
463
482
|
signature: t
|
|
464
483
|
}) {
|
|
465
484
|
const r = new TextEncoder().encode(e), n = Uint8Array.from(
|
|
466
485
|
atob(t),
|
|
467
486
|
(s) => s.charCodeAt(0)
|
|
468
|
-
), o = await $e
|
|
487
|
+
), o = await Oe($e);
|
|
469
488
|
if (!await crypto.subtle.verify(
|
|
470
489
|
{ name: "RSASSA-PKCS1-v1_5" },
|
|
471
490
|
o,
|
|
@@ -477,13 +496,13 @@ async function Oe({
|
|
|
477
496
|
);
|
|
478
497
|
return JSON.parse(e);
|
|
479
498
|
}
|
|
480
|
-
function
|
|
481
|
-
return Object.prototype.hasOwnProperty.call(e,
|
|
499
|
+
function Ee(e) {
|
|
500
|
+
return Object.prototype.hasOwnProperty.call(e, we);
|
|
482
501
|
}
|
|
483
|
-
async function
|
|
502
|
+
async function Te(e) {
|
|
484
503
|
const t = Object.getOwnPropertyDescriptor(
|
|
485
504
|
e,
|
|
486
|
-
|
|
505
|
+
Ne
|
|
487
506
|
);
|
|
488
507
|
if (!t?.value)
|
|
489
508
|
return {
|
|
@@ -501,7 +520,7 @@ async function Ee(e) {
|
|
|
501
520
|
valid: false
|
|
502
521
|
};
|
|
503
522
|
try {
|
|
504
|
-
return await
|
|
523
|
+
return await Be(
|
|
505
524
|
r
|
|
506
525
|
);
|
|
507
526
|
} catch {
|
|
@@ -513,7 +532,7 @@ async function Ee(e) {
|
|
|
513
532
|
};
|
|
514
533
|
}
|
|
515
534
|
}
|
|
516
|
-
function
|
|
535
|
+
function _e(e) {
|
|
517
536
|
const t = Math.floor(Math.random() * 100);
|
|
518
537
|
e.root.children.push({
|
|
519
538
|
type: "selector",
|
|
@@ -537,30 +556,30 @@ function Te(e) {
|
|
|
537
556
|
}
|
|
538
557
|
});
|
|
539
558
|
}
|
|
540
|
-
function
|
|
559
|
+
function $(e, t = "") {
|
|
541
560
|
return {
|
|
542
561
|
name: e,
|
|
543
562
|
content: t
|
|
544
563
|
};
|
|
545
564
|
}
|
|
546
|
-
async function
|
|
565
|
+
async function Le(e, {
|
|
547
566
|
type: t = "all",
|
|
548
567
|
consumers: r = { css: d, ts: j$1 }
|
|
549
568
|
} = {}) {
|
|
550
569
|
const n = { files: [] }, o = e.options;
|
|
551
|
-
if (
|
|
552
|
-
const s = await
|
|
553
|
-
(!s.valid || s.instanceId !== e.id) &&
|
|
570
|
+
if (Ee(e)) {
|
|
571
|
+
const s = await Te(e);
|
|
572
|
+
(!s.valid || s.instanceId !== e.id) && _e(e);
|
|
554
573
|
}
|
|
555
574
|
if (t === "all" || t === "css") {
|
|
556
|
-
const s =
|
|
575
|
+
const s = $(
|
|
557
576
|
"index.css",
|
|
558
577
|
r.css(e.root, o)
|
|
559
578
|
);
|
|
560
579
|
n.files.push(s);
|
|
561
580
|
}
|
|
562
581
|
if (t === "all" || t === "ts") {
|
|
563
|
-
const s =
|
|
582
|
+
const s = $(
|
|
564
583
|
"index.ts",
|
|
565
584
|
r.ts(e.root, o)
|
|
566
585
|
);
|
|
@@ -582,7 +601,7 @@ async function build(instance, { clean = true, outputDir = "./styleframe", trans
|
|
|
582
601
|
environment: process.env.NODE_ENV || "development",
|
|
583
602
|
isBuild: true
|
|
584
603
|
});
|
|
585
|
-
const output = await
|
|
604
|
+
const output = await Le(instance, transpiler);
|
|
586
605
|
const outputDirExists = await directoryExists(outputDir);
|
|
587
606
|
if (clean && outputDirExists) {
|
|
588
607
|
await rm(outputDir, { recursive: true });
|
|
@@ -597,32 +616,38 @@ async function build(instance, { clean = true, outputDir = "./styleframe", trans
|
|
|
597
616
|
await writeFile(filePath, file.content);
|
|
598
617
|
}
|
|
599
618
|
}
|
|
600
|
-
function
|
|
619
|
+
function K(e) {
|
|
601
620
|
return typeof e == "object" && e !== null;
|
|
602
621
|
}
|
|
603
|
-
function
|
|
604
|
-
return
|
|
622
|
+
function m(e, r) {
|
|
623
|
+
return K(e) && "type" in e && e.type === r;
|
|
605
624
|
}
|
|
606
625
|
function L(e) {
|
|
607
|
-
return
|
|
626
|
+
return m(e, "variable");
|
|
608
627
|
}
|
|
609
628
|
function A(e) {
|
|
610
|
-
return
|
|
629
|
+
return m(e, "reference");
|
|
630
|
+
}
|
|
631
|
+
function ge(e) {
|
|
632
|
+
return m(e, "selector");
|
|
611
633
|
}
|
|
612
634
|
function q(e) {
|
|
613
|
-
return
|
|
635
|
+
return m(e, "modifier");
|
|
614
636
|
}
|
|
615
637
|
function E(e) {
|
|
616
|
-
return
|
|
638
|
+
return m(e, "css");
|
|
639
|
+
}
|
|
640
|
+
function Ae(e) {
|
|
641
|
+
return m(e, "recipe");
|
|
617
642
|
}
|
|
618
643
|
function G(e) {
|
|
619
644
|
return typeof e == "string" || typeof e == "number" || typeof e == "boolean" || e === null;
|
|
620
645
|
}
|
|
621
|
-
function
|
|
622
|
-
return G(e) || A(e) || E(e) || Array.isArray(e) && e.every(
|
|
646
|
+
function U(e) {
|
|
647
|
+
return G(e) || A(e) || E(e) || Array.isArray(e) && e.every(U);
|
|
623
648
|
}
|
|
624
649
|
function I(e) {
|
|
625
|
-
return
|
|
650
|
+
return K(e) && "children" in e && "declarations" in e && "variables" in e;
|
|
626
651
|
}
|
|
627
652
|
function z(e = (r) => r) {
|
|
628
653
|
return (r) => {
|
|
@@ -647,7 +672,7 @@ function W(e, r) {
|
|
|
647
672
|
};
|
|
648
673
|
};
|
|
649
674
|
}
|
|
650
|
-
function
|
|
675
|
+
function S(e, r) {
|
|
651
676
|
return function(t, i, c) {
|
|
652
677
|
const o = {
|
|
653
678
|
type: "at-rule",
|
|
@@ -657,17 +682,17 @@ function C(e, r) {
|
|
|
657
682
|
variables: [],
|
|
658
683
|
children: []
|
|
659
684
|
}, u = v(o, r);
|
|
660
|
-
return typeof c == "function" ? o.declarations = c(u) ?? {} : c && (o.declarations = c),
|
|
685
|
+
return typeof c == "function" ? o.declarations = c(u) ?? {} : c && (o.declarations = c), k(o.declarations, u), e.children.push(o), o;
|
|
661
686
|
};
|
|
662
687
|
}
|
|
663
688
|
function Y(e, r) {
|
|
664
|
-
const n =
|
|
689
|
+
const n = S(e, r);
|
|
665
690
|
return function(i, c) {
|
|
666
691
|
return n("media", i, c);
|
|
667
692
|
};
|
|
668
693
|
}
|
|
669
694
|
function Z(e, r) {
|
|
670
|
-
const n =
|
|
695
|
+
const n = S(e, r);
|
|
671
696
|
return function(i, c) {
|
|
672
697
|
return n("keyframes", i, c);
|
|
673
698
|
};
|
|
@@ -694,7 +719,7 @@ function Q(e, r) {
|
|
|
694
719
|
variables: [],
|
|
695
720
|
children: []
|
|
696
721
|
}, o = v(c, r);
|
|
697
|
-
return typeof i == "function" ? c.declarations = i(o) ?? {} : I(i) ? (c.variables = i.variables, c.declarations = i.declarations, c.children = i.children) : c.declarations = i,
|
|
722
|
+
return typeof i == "function" ? c.declarations = i(o) ?? {} : I(i) ? (c.variables = i.variables, c.declarations = i.declarations, c.children = i.children) : c.declarations = i, k(c.declarations, o), e.children.push(c), c;
|
|
698
723
|
};
|
|
699
724
|
}
|
|
700
725
|
function X(e, r) {
|
|
@@ -717,7 +742,7 @@ function X(e, r) {
|
|
|
717
742
|
};
|
|
718
743
|
}
|
|
719
744
|
function v(e, r) {
|
|
720
|
-
const n = X(e), t = Q(e, r), i =
|
|
745
|
+
const n = X(e), t = Q(e, r), i = S(e, r), c = Z(r, r), o = Y(e, r), u = J(), s = W();
|
|
721
746
|
return {
|
|
722
747
|
variable: n,
|
|
723
748
|
selector: t,
|
|
@@ -728,11 +753,11 @@ function v(e, r) {
|
|
|
728
753
|
css: s
|
|
729
754
|
};
|
|
730
755
|
}
|
|
731
|
-
function
|
|
756
|
+
function k(e, r) {
|
|
732
757
|
for (const n in e)
|
|
733
758
|
if (n.startsWith("@")) {
|
|
734
759
|
const t = e[n];
|
|
735
|
-
if (typeof t == "object" && t !== null &&
|
|
760
|
+
if (typeof t == "object" && t !== null && !U(t)) {
|
|
736
761
|
const i = n.replace(/^@(\w+).*/, "$1"), c = n.replace(`@${i}`, "").trim();
|
|
737
762
|
r.atRule(i, c, t), delete e[n];
|
|
738
763
|
}
|
|
@@ -817,16 +842,16 @@ function te(e) {
|
|
|
817
842
|
function c(s, f) {
|
|
818
843
|
const l = Object.keys(s), a = Array.from({ length: l.length });
|
|
819
844
|
for (let y = 0; y < l.length; y++) {
|
|
820
|
-
const
|
|
845
|
+
const p = l[y], d2 = s[p];
|
|
821
846
|
if (typeof d2 != "object" || d2 === null)
|
|
822
|
-
a[
|
|
847
|
+
a[p] = d2;
|
|
823
848
|
else if (d2.constructor !== Object && (i = t.get(d2.constructor)))
|
|
824
|
-
a[
|
|
849
|
+
a[p] = i(d2, f);
|
|
825
850
|
else if (ArrayBuffer.isView(d2))
|
|
826
|
-
a[
|
|
851
|
+
a[p] = j(d2);
|
|
827
852
|
else {
|
|
828
853
|
const h2 = r.indexOf(d2);
|
|
829
|
-
h2 !== -1 ? a[
|
|
854
|
+
h2 !== -1 ? a[p] = n[h2] : a[p] = f(d2);
|
|
830
855
|
}
|
|
831
856
|
}
|
|
832
857
|
return a;
|
|
@@ -922,7 +947,7 @@ function fe(e, r, n) {
|
|
|
922
947
|
declarations: R(t.declarations),
|
|
923
948
|
variables: R(t.variables),
|
|
924
949
|
children: R(t.children)
|
|
925
|
-
}),
|
|
950
|
+
}), k(t.declarations, i);
|
|
926
951
|
return t;
|
|
927
952
|
}
|
|
928
953
|
function ue(e, r) {
|
|
@@ -970,7 +995,7 @@ function le(e, r) {
|
|
|
970
995
|
for (const [l, a] of Object.entries(f)) {
|
|
971
996
|
const y = o.values.find(
|
|
972
997
|
(h2) => h2.key === l && h2.modifiers.length === 0
|
|
973
|
-
),
|
|
998
|
+
), p = {
|
|
974
999
|
type: "utility",
|
|
975
1000
|
name: t,
|
|
976
1001
|
value: l,
|
|
@@ -979,32 +1004,32 @@ function le(e, r) {
|
|
|
979
1004
|
children: [],
|
|
980
1005
|
modifiers: []
|
|
981
1006
|
}, d2 = v(
|
|
982
|
-
|
|
1007
|
+
p,
|
|
983
1008
|
r
|
|
984
1009
|
);
|
|
985
|
-
if (
|
|
1010
|
+
if (p.declarations = i({
|
|
986
1011
|
...d2,
|
|
987
1012
|
value: a
|
|
988
|
-
}) ?? {},
|
|
1013
|
+
}) ?? {}, k(p.declarations, d2), y || (o.values.push({
|
|
989
1014
|
key: l,
|
|
990
1015
|
value: a,
|
|
991
1016
|
modifiers: []
|
|
992
|
-
}), e.children.push(
|
|
993
|
-
const h2 = s.map((
|
|
994
|
-
(
|
|
995
|
-
)).reduce((
|
|
1017
|
+
}), e.children.push(p)), s && s.length > 0) {
|
|
1018
|
+
const h2 = s.map((g2) => g2.key), H2 = ce(h2).filter((g2) => !o.values.find(
|
|
1019
|
+
(b) => b.key === l && b.modifiers.length === g2.length && b.modifiers.every((w2) => g2.includes(w2))
|
|
1020
|
+
)).reduce((g2, b) => {
|
|
996
1021
|
const w2 = /* @__PURE__ */ new Map();
|
|
997
|
-
for (const
|
|
998
|
-
const
|
|
999
|
-
(N2) => N2.key.includes(
|
|
1022
|
+
for (const $2 of b) {
|
|
1023
|
+
const V2 = s.find(
|
|
1024
|
+
(N2) => N2.key.includes($2)
|
|
1000
1025
|
);
|
|
1001
|
-
|
|
1026
|
+
V2 && q(V2) && w2.set($2, V2);
|
|
1002
1027
|
}
|
|
1003
1028
|
return o.values.push({
|
|
1004
1029
|
key: l,
|
|
1005
1030
|
value: a,
|
|
1006
|
-
modifiers:
|
|
1007
|
-
}),
|
|
1031
|
+
modifiers: b
|
|
1032
|
+
}), g2.push(fe(p, r, w2)), g2;
|
|
1008
1033
|
}, []);
|
|
1009
1034
|
e.children.push(...H2);
|
|
1010
1035
|
}
|
|
@@ -1034,10 +1059,10 @@ function de(e, r) {
|
|
|
1034
1059
|
type: "recipe",
|
|
1035
1060
|
...t
|
|
1036
1061
|
};
|
|
1037
|
-
return i._runtime =
|
|
1062
|
+
return i._runtime = pe(i, r), me(i, r), r.recipes.push(i), i;
|
|
1038
1063
|
};
|
|
1039
1064
|
}
|
|
1040
|
-
function
|
|
1065
|
+
function C(e, r) {
|
|
1041
1066
|
const n = e.autogenerate(r);
|
|
1042
1067
|
return Object.keys(n)[0] ?? "default";
|
|
1043
1068
|
}
|
|
@@ -1048,21 +1073,25 @@ function F(e, r) {
|
|
|
1048
1073
|
const c = {};
|
|
1049
1074
|
for (const [o, u] of Object.entries(i)) {
|
|
1050
1075
|
const s = T(r, o);
|
|
1051
|
-
s
|
|
1076
|
+
s ? c[o] = C(
|
|
1052
1077
|
s,
|
|
1053
1078
|
u
|
|
1054
|
-
)
|
|
1079
|
+
) : console.warn(
|
|
1080
|
+
`[styleframe] Utility "${o}" not found in registry. Skipping runtime generation for this declaration.`
|
|
1081
|
+
);
|
|
1055
1082
|
}
|
|
1056
1083
|
n[t] = c;
|
|
1057
1084
|
} else if (typeof i == "boolean")
|
|
1058
1085
|
n[t] = i;
|
|
1059
1086
|
else {
|
|
1060
1087
|
const c = T(r, t);
|
|
1061
|
-
c
|
|
1088
|
+
c ? n[t] = C(c, i) : console.warn(
|
|
1089
|
+
`[styleframe] Utility "${t}" not found in registry. Skipping runtime generation for this declaration.`
|
|
1090
|
+
);
|
|
1062
1091
|
}
|
|
1063
1092
|
return n;
|
|
1064
1093
|
}
|
|
1065
|
-
function
|
|
1094
|
+
function pe(e, r) {
|
|
1066
1095
|
const n = {};
|
|
1067
1096
|
if (e.base && (n.base = F(e.base, r)), e.variants) {
|
|
1068
1097
|
const t = {};
|
|
@@ -1107,7 +1136,7 @@ function T(e, r) {
|
|
|
1107
1136
|
const t = r.replace(/[A-Z]/g, (i) => `-${i.toLowerCase()}`);
|
|
1108
1137
|
return e.utilities.find((i) => i.name === t);
|
|
1109
1138
|
}
|
|
1110
|
-
function
|
|
1139
|
+
function me(e, r) {
|
|
1111
1140
|
const n = /* @__PURE__ */ new Map();
|
|
1112
1141
|
if (e.base && x(e.base, n), e.variants)
|
|
1113
1142
|
for (const i of Object.values(e.variants))
|
|
@@ -1150,7 +1179,7 @@ function pe(e, r) {
|
|
|
1150
1179
|
}
|
|
1151
1180
|
}
|
|
1152
1181
|
function Re(e) {
|
|
1153
|
-
const r = ne("sf-"), n = ae(), t = { ...e }, i = le(n, n), c = ue(n, n), o = de(n, n), u = ye(n, n), { variable: s, selector: f, atRule: l, keyframes: a, media: y, ref:
|
|
1182
|
+
const r = ne("sf-"), n = ae(), t = { ...e }, i = le(n, n), c = ue(n, n), o = de(n, n), u = ye(n, n), { variable: s, selector: f, atRule: l, keyframes: a, media: y, ref: p, css: d2 } = v(n, n);
|
|
1154
1183
|
return {
|
|
1155
1184
|
id: r,
|
|
1156
1185
|
root: n,
|
|
@@ -1163,46 +1192,90 @@ function Re(e) {
|
|
|
1163
1192
|
atRule: l,
|
|
1164
1193
|
keyframes: a,
|
|
1165
1194
|
media: y,
|
|
1166
|
-
ref:
|
|
1195
|
+
ref: p,
|
|
1167
1196
|
css: d2,
|
|
1168
1197
|
options: t
|
|
1169
1198
|
};
|
|
1170
1199
|
}
|
|
1200
|
+
const SUPPORTED_EXTENSIONS = [".ts", ".mts", ".cts", ".js", ".mjs", ".cjs"];
|
|
1201
|
+
function hasKnownExtension(filePath) {
|
|
1202
|
+
return SUPPORTED_EXTENSIONS.some((ext) => filePath.endsWith(ext));
|
|
1203
|
+
}
|
|
1204
|
+
function resolveConfigFile(cwd, entry) {
|
|
1205
|
+
const basePath = path.isAbsolute(entry) ? entry : path.join(cwd, entry);
|
|
1206
|
+
if (hasKnownExtension(basePath)) {
|
|
1207
|
+
return existsSync(basePath) ? basePath : void 0;
|
|
1208
|
+
}
|
|
1209
|
+
for (const ext of SUPPORTED_EXTENSIONS) {
|
|
1210
|
+
const filePath = `${basePath}${ext}`;
|
|
1211
|
+
if (existsSync(filePath)) {
|
|
1212
|
+
return filePath;
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
return void 0;
|
|
1216
|
+
}
|
|
1217
|
+
function trackNamedExports(module) {
|
|
1218
|
+
for (const [exportName, exportValue] of Object.entries(module)) {
|
|
1219
|
+
if (exportName === "default") continue;
|
|
1220
|
+
if (Ae(exportValue)) {
|
|
1221
|
+
exportValue._exportName = exportName;
|
|
1222
|
+
} else if (ge(exportValue)) {
|
|
1223
|
+
exportValue._exportName = exportName;
|
|
1224
|
+
}
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1171
1227
|
async function loadConfiguration({
|
|
1172
1228
|
cwd = process.cwd(),
|
|
1173
|
-
|
|
1229
|
+
entry = "styleframe.config"
|
|
1174
1230
|
} = {}) {
|
|
1175
|
-
const
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1231
|
+
const resolvedPath = resolveConfigFile(cwd, entry);
|
|
1232
|
+
if (!resolvedPath) {
|
|
1233
|
+
return Re();
|
|
1234
|
+
}
|
|
1235
|
+
const jiti = createJiti(path.dirname(resolvedPath), {
|
|
1236
|
+
fsCache: false,
|
|
1237
|
+
moduleCache: false
|
|
1179
1238
|
});
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1239
|
+
const module = await jiti.import(resolvedPath);
|
|
1240
|
+
if (!module.default) {
|
|
1241
|
+
throw new Error(
|
|
1242
|
+
`Missing default export in ${resolvedPath}. Expected a Styleframe instance.`
|
|
1243
|
+
);
|
|
1244
|
+
}
|
|
1245
|
+
trackNamedExports(module);
|
|
1246
|
+
return module.default;
|
|
1187
1247
|
}
|
|
1188
1248
|
async function watchConfiguration({
|
|
1189
|
-
cwd = process.cwd()
|
|
1249
|
+
cwd = process.cwd(),
|
|
1250
|
+
entry = "styleframe.config",
|
|
1251
|
+
onUpdate,
|
|
1252
|
+
onError
|
|
1190
1253
|
} = {}) {
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
}
|
|
1254
|
+
const resolvedPath = resolveConfigFile(cwd, entry);
|
|
1255
|
+
if (!resolvedPath) {
|
|
1256
|
+
throw new Error(`Config file not found: ${entry}`);
|
|
1257
|
+
}
|
|
1258
|
+
const watcher = watch(resolvedPath, { ignoreInitial: true });
|
|
1259
|
+
watcher.on("change", async () => {
|
|
1260
|
+
try {
|
|
1261
|
+
const config = await loadConfiguration({ entry: resolvedPath });
|
|
1262
|
+
onUpdate?.(config);
|
|
1263
|
+
} catch (error) {
|
|
1264
|
+
onError?.(error instanceof Error ? error : new Error(String(error)));
|
|
1199
1265
|
}
|
|
1200
1266
|
});
|
|
1267
|
+
watcher.on("unlink", () => {
|
|
1268
|
+
onError?.(new Error(`Config file was deleted: ${resolvedPath}`));
|
|
1269
|
+
});
|
|
1270
|
+
return {
|
|
1271
|
+
config: await loadConfiguration({ entry: resolvedPath }),
|
|
1272
|
+
configFile: resolvedPath,
|
|
1273
|
+
unwatch: () => watcher.close()
|
|
1274
|
+
};
|
|
1201
1275
|
}
|
|
1202
1276
|
export {
|
|
1203
1277
|
build,
|
|
1204
1278
|
directoryExists,
|
|
1205
1279
|
loadConfiguration,
|
|
1206
|
-
loadConfigurationFromPath,
|
|
1207
1280
|
watchConfiguration
|
|
1208
1281
|
};
|