@styleframe/loader 1.0.2 → 1.0.3
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 +10 -0
- package/dist/index.cjs +875 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +874 -0
- package/package.json +13 -7
- package/.tsbuildinfo +0 -1
- package/playground/build.ts +0 -13
- package/playground/load.ts +0 -9
- package/playground/styleframe.config.ts +0 -50
- package/playground/watch.ts +0 -9
- package/src/build.ts +0 -36
- package/src/config.ts +0 -45
- package/src/index.ts +0 -3
- package/src/utils.ts +0 -10
- package/src/vite-env.d.ts +0 -1
- package/tsconfig.json +0 -12
- package/vite.config.ts +0 -13
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,875 @@
|
|
|
1
|
+
(function(global, factory) {
|
|
2
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("node:fs/promises"), require("node:path"), require("c12")) : typeof define === "function" && define.amd ? define(["exports", "node:fs/promises", "node:path", "c12"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.loader = {}, global.promises, global.path, global.c12));
|
|
3
|
+
})(this, (function(exports2, promises, path, c12) {
|
|
4
|
+
"use strict";
|
|
5
|
+
const N$1 = ["charset", "import", "namespace"], E$1 = ["layer"], V$1 = ({ name: e }) => `[data-theme="${e}"]`, _$1 = ({
|
|
6
|
+
name: e,
|
|
7
|
+
value: t,
|
|
8
|
+
modifiers: s
|
|
9
|
+
}) => `._${[...s, e, t].filter(Boolean).join("\\:")}`, O$1 = ({ name: e }) => e;
|
|
10
|
+
function D$1(e, t) {
|
|
11
|
+
return `@${e}${t ? " " : ""}${t}`;
|
|
12
|
+
}
|
|
13
|
+
const B$1 = /\d/, L$1 = ["-", "_", "/", "."];
|
|
14
|
+
function M$1(e = "") {
|
|
15
|
+
if (!B$1.test(e))
|
|
16
|
+
return e !== e.toLowerCase();
|
|
17
|
+
}
|
|
18
|
+
function U(e, t) {
|
|
19
|
+
const s = L$1, r = [];
|
|
20
|
+
if (!e || typeof e != "string")
|
|
21
|
+
return r;
|
|
22
|
+
let c = "", l, u;
|
|
23
|
+
for (const i of e) {
|
|
24
|
+
const n = s.includes(i);
|
|
25
|
+
if (n === true) {
|
|
26
|
+
r.push(c), c = "", l = void 0;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const o = M$1(i);
|
|
30
|
+
if (u === false) {
|
|
31
|
+
if (l === false && o === true) {
|
|
32
|
+
r.push(c), c = i, l = o;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (l === true && o === false && c.length > 1) {
|
|
36
|
+
const f = c.at(-1);
|
|
37
|
+
r.push(c.slice(0, Math.max(0, c.length - 1))), c = f + i, l = o;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
c += i, l = o, u = n;
|
|
42
|
+
}
|
|
43
|
+
return r.push(c), r;
|
|
44
|
+
}
|
|
45
|
+
function P(e, t) {
|
|
46
|
+
return e ? (Array.isArray(e) ? e : U(e)).map((s) => s.toLowerCase()).join("-") : "";
|
|
47
|
+
}
|
|
48
|
+
function k$1(e) {
|
|
49
|
+
return ` ${e}`;
|
|
50
|
+
}
|
|
51
|
+
function x(e) {
|
|
52
|
+
return e.split(`
|
|
53
|
+
`).map((t) => k$1(t)).join(`
|
|
54
|
+
`);
|
|
55
|
+
}
|
|
56
|
+
function z$1(e) {
|
|
57
|
+
return P(e);
|
|
58
|
+
}
|
|
59
|
+
function H$1(e) {
|
|
60
|
+
return z$1(e);
|
|
61
|
+
}
|
|
62
|
+
function T$1(e, t) {
|
|
63
|
+
return `${e.startsWith("--") ? e : H$1(e)}: ${t};`;
|
|
64
|
+
}
|
|
65
|
+
function I$1(e) {
|
|
66
|
+
return `{${e.length > 0 ? `
|
|
67
|
+
` : ""}${e.map((t) => `${x(`${t}`)}
|
|
68
|
+
`).join("")}}`;
|
|
69
|
+
}
|
|
70
|
+
function $$1(e) {
|
|
71
|
+
return `--${(e.startsWith("--") ? e.slice(2) : e).replace(/[^a-zA-Z0-9_\-\u0080-\uFFFF]/g, "-") || "unknown-variable"}`;
|
|
72
|
+
}
|
|
73
|
+
function K$1(e, t) {
|
|
74
|
+
return T$1($$1(e), t);
|
|
75
|
+
}
|
|
76
|
+
function Q(e, t) {
|
|
77
|
+
return `var(${$$1(e)}${t ? `, ${t}` : ""})`;
|
|
78
|
+
}
|
|
79
|
+
function C$1(e, t) {
|
|
80
|
+
return `${e} ${I$1(t)}`;
|
|
81
|
+
}
|
|
82
|
+
function W$1(e) {
|
|
83
|
+
return function(s, r) {
|
|
84
|
+
return Object.entries(s).map(([c, l]) => T$1(c, e(l, r)));
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function w$1(e) {
|
|
88
|
+
return function(s, r) {
|
|
89
|
+
const l = (r.variables?.name ?? O$1)({ name: s.name });
|
|
90
|
+
return K$1(l, e(s.value, r));
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function A(e) {
|
|
94
|
+
const t = w$1(e), s = W$1(e);
|
|
95
|
+
return function(c, l, u) {
|
|
96
|
+
const { variables: i, declarations: n, children: o } = l, f = c === ":root", a = (i ?? []).map(
|
|
97
|
+
(g2) => t(g2, u)
|
|
98
|
+
), m2 = s(
|
|
99
|
+
n ?? {},
|
|
100
|
+
u
|
|
101
|
+
), b2 = (o ?? []).map(
|
|
102
|
+
(g2) => e(g2, u)
|
|
103
|
+
), p2 = a.length > 0, h = m2.length > 0, S2 = b2.length > 0;
|
|
104
|
+
return f ? `${p2 || h ? C$1(c, [
|
|
105
|
+
...a,
|
|
106
|
+
...p2 && h ? [""] : [],
|
|
107
|
+
...m2
|
|
108
|
+
]) : ""}${S2 && (p2 || h) ? `
|
|
109
|
+
|
|
110
|
+
` : ""}${b2.join(`
|
|
111
|
+
|
|
112
|
+
`)}` : C$1(c, [
|
|
113
|
+
...a,
|
|
114
|
+
...p2 && (S2 || h) ? [""] : [],
|
|
115
|
+
...m2,
|
|
116
|
+
...h && S2 ? [""] : [],
|
|
117
|
+
...b2.flatMap(
|
|
118
|
+
(g2, F2) => F2 === b2.length - 1 ? [g2] : [g2, ""]
|
|
119
|
+
)
|
|
120
|
+
]);
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function Z(e) {
|
|
124
|
+
const t = A(e);
|
|
125
|
+
return function(r, c) {
|
|
126
|
+
const l = N$1.includes(r.identifier), u = E$1.includes(
|
|
127
|
+
r.identifier
|
|
128
|
+
), i = Object.keys(r.declarations).length > 0, n = r.variables.length > 0, o = r.children.length > 0, f = D$1(r.identifier, r.rule);
|
|
129
|
+
return l || u && !(i || n || o) ? `${f};` : t(f, r, c);
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function q$1(e) {
|
|
133
|
+
return typeof e == "object" && e !== null;
|
|
134
|
+
}
|
|
135
|
+
function d(e, t) {
|
|
136
|
+
return q$1(e) && "type" in e && e.type === t;
|
|
137
|
+
}
|
|
138
|
+
function G(e) {
|
|
139
|
+
return d(e, "variable");
|
|
140
|
+
}
|
|
141
|
+
function J(e) {
|
|
142
|
+
return d(e, "reference");
|
|
143
|
+
}
|
|
144
|
+
function Y$1(e) {
|
|
145
|
+
return d(e, "selector");
|
|
146
|
+
}
|
|
147
|
+
function X(e) {
|
|
148
|
+
return d(e, "at-rule");
|
|
149
|
+
}
|
|
150
|
+
function ee(e) {
|
|
151
|
+
return d(e, "utility");
|
|
152
|
+
}
|
|
153
|
+
function te(e) {
|
|
154
|
+
return d(e, "css");
|
|
155
|
+
}
|
|
156
|
+
function re(e) {
|
|
157
|
+
return d(e, "theme");
|
|
158
|
+
}
|
|
159
|
+
function ne(e) {
|
|
160
|
+
return d(e, "root");
|
|
161
|
+
}
|
|
162
|
+
function j$1(e) {
|
|
163
|
+
if (e instanceof Buffer)
|
|
164
|
+
return Buffer.from(e);
|
|
165
|
+
const t = e.constructor;
|
|
166
|
+
return new t(
|
|
167
|
+
e.buffer.slice(0),
|
|
168
|
+
e.byteOffset,
|
|
169
|
+
e.byteLength / e.BYTES_PER_ELEMENT || 1
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
function oe$1(e) {
|
|
173
|
+
if (e = e || {}, e.circular)
|
|
174
|
+
return ue(e);
|
|
175
|
+
const t = /* @__PURE__ */ new Map();
|
|
176
|
+
if (t.set(Date, (u) => new Date(u)), t.set(
|
|
177
|
+
Map,
|
|
178
|
+
(u, i) => new Map(r(Array.from(u), i))
|
|
179
|
+
), t.set(
|
|
180
|
+
Set,
|
|
181
|
+
(u, i) => new Set(r(Array.from(u), i))
|
|
182
|
+
), e.constructorHandlers)
|
|
183
|
+
for (const u of e.constructorHandlers)
|
|
184
|
+
t.set(u[0], u[1]);
|
|
185
|
+
let s;
|
|
186
|
+
return e.proto ? l : c;
|
|
187
|
+
function r(u, i) {
|
|
188
|
+
const n = Object.keys(u), o = Array.from({ length: n.length });
|
|
189
|
+
for (let f = 0; f < n.length; f++) {
|
|
190
|
+
const a = n[f], m2 = u[a];
|
|
191
|
+
typeof m2 != "object" || m2 === null ? o[a] = m2 : m2.constructor !== Object && (s = t.get(m2.constructor)) ? o[a] = s(m2, i) : ArrayBuffer.isView(m2) ? o[a] = j$1(m2) : o[a] = i(m2);
|
|
192
|
+
}
|
|
193
|
+
return o;
|
|
194
|
+
}
|
|
195
|
+
function c(u) {
|
|
196
|
+
if (typeof u != "object" || u === null) return u;
|
|
197
|
+
if (Array.isArray(u)) return r(u, c);
|
|
198
|
+
if (u.constructor !== Object && (s = t.get(u.constructor)))
|
|
199
|
+
return s(u, c);
|
|
200
|
+
const i = {};
|
|
201
|
+
for (const n in u) {
|
|
202
|
+
if (Object.hasOwnProperty.call(u, n) === false) continue;
|
|
203
|
+
const o = u[n];
|
|
204
|
+
typeof o != "object" || o === null ? i[n] = o : o.constructor !== Object && (s = t.get(o.constructor)) ? i[n] = s(o, c) : ArrayBuffer.isView(o) ? i[n] = j$1(o) : i[n] = c(o);
|
|
205
|
+
}
|
|
206
|
+
return i;
|
|
207
|
+
}
|
|
208
|
+
function l(u) {
|
|
209
|
+
if (typeof u != "object" || u === null) return u;
|
|
210
|
+
if (Array.isArray(u)) return r(u, l);
|
|
211
|
+
if (u.constructor !== Object && (s = t.get(u.constructor)))
|
|
212
|
+
return s(u, l);
|
|
213
|
+
const i = {};
|
|
214
|
+
for (const n in u) {
|
|
215
|
+
const o = u[n];
|
|
216
|
+
typeof o != "object" || o === null ? i[n] = o : o.constructor !== Object && (s = t.get(o.constructor)) ? i[n] = s(o, l) : ArrayBuffer.isView(o) ? i[n] = j$1(o) : i[n] = l(o);
|
|
217
|
+
}
|
|
218
|
+
return i;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
function ue(e) {
|
|
222
|
+
const t = [], s = [], r = /* @__PURE__ */ new Map();
|
|
223
|
+
if (r.set(Date, (n) => new Date(n)), r.set(
|
|
224
|
+
Map,
|
|
225
|
+
(n, o) => new Map(l(Array.from(n), o))
|
|
226
|
+
), r.set(
|
|
227
|
+
Set,
|
|
228
|
+
(n, o) => new Set(l(Array.from(n), o))
|
|
229
|
+
), e.constructorHandlers)
|
|
230
|
+
for (const n of e.constructorHandlers)
|
|
231
|
+
r.set(n[0], n[1]);
|
|
232
|
+
let c;
|
|
233
|
+
return e.proto ? i : u;
|
|
234
|
+
function l(n, o) {
|
|
235
|
+
const f = Object.keys(n), a = Array.from({ length: f.length });
|
|
236
|
+
for (let m2 = 0; m2 < f.length; m2++) {
|
|
237
|
+
const b2 = f[m2], p2 = n[b2];
|
|
238
|
+
if (typeof p2 != "object" || p2 === null)
|
|
239
|
+
a[b2] = p2;
|
|
240
|
+
else if (p2.constructor !== Object && (c = r.get(p2.constructor)))
|
|
241
|
+
a[b2] = c(p2, o);
|
|
242
|
+
else if (ArrayBuffer.isView(p2))
|
|
243
|
+
a[b2] = j$1(p2);
|
|
244
|
+
else {
|
|
245
|
+
const h = t.indexOf(p2);
|
|
246
|
+
h !== -1 ? a[b2] = s[h] : a[b2] = o(p2);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return a;
|
|
250
|
+
}
|
|
251
|
+
function u(n) {
|
|
252
|
+
if (typeof n != "object" || n === null) return n;
|
|
253
|
+
if (Array.isArray(n)) return l(n, u);
|
|
254
|
+
if (n.constructor !== Object && (c = r.get(n.constructor)))
|
|
255
|
+
return c(n, u);
|
|
256
|
+
const o = {};
|
|
257
|
+
t.push(n), s.push(o);
|
|
258
|
+
for (const f in n) {
|
|
259
|
+
if (Object.hasOwnProperty.call(n, f) === false) continue;
|
|
260
|
+
const a = n[f];
|
|
261
|
+
if (typeof a != "object" || a === null)
|
|
262
|
+
o[f] = a;
|
|
263
|
+
else if (a.constructor !== Object && (c = r.get(a.constructor)))
|
|
264
|
+
o[f] = c(a, u);
|
|
265
|
+
else if (ArrayBuffer.isView(a))
|
|
266
|
+
o[f] = j$1(a);
|
|
267
|
+
else {
|
|
268
|
+
const m2 = t.indexOf(a);
|
|
269
|
+
m2 !== -1 ? o[f] = s[m2] : o[f] = u(a);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return t.pop(), s.pop(), o;
|
|
273
|
+
}
|
|
274
|
+
function i(n) {
|
|
275
|
+
if (typeof n != "object" || n === null) return n;
|
|
276
|
+
if (Array.isArray(n)) return l(n, i);
|
|
277
|
+
if (n.constructor !== Object && (c = r.get(n.constructor)))
|
|
278
|
+
return c(n, i);
|
|
279
|
+
const o = {};
|
|
280
|
+
t.push(n), s.push(o);
|
|
281
|
+
for (const f in n) {
|
|
282
|
+
const a = n[f];
|
|
283
|
+
if (typeof a != "object" || a === null)
|
|
284
|
+
o[f] = a;
|
|
285
|
+
else if (a.constructor !== Object && (c = r.get(a.constructor)))
|
|
286
|
+
o[f] = c(a, i);
|
|
287
|
+
else if (ArrayBuffer.isView(a))
|
|
288
|
+
o[f] = j$1(a);
|
|
289
|
+
else {
|
|
290
|
+
const m2 = t.indexOf(a);
|
|
291
|
+
m2 !== -1 ? o[f] = s[m2] : o[f] = i(a);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return t.pop(), s.pop(), o;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
oe$1();
|
|
298
|
+
function ce(e) {
|
|
299
|
+
return function(s, r) {
|
|
300
|
+
return s.value.map((c) => e(c, r)).join("").trim();
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
function se(e) {
|
|
304
|
+
return function(s, r) {
|
|
305
|
+
return s != null ? `${s}` : "";
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
function ie(e) {
|
|
309
|
+
return function(s, r) {
|
|
310
|
+
const l = (r.variables?.name ?? O$1)({ name: s.name });
|
|
311
|
+
return Q(
|
|
312
|
+
l,
|
|
313
|
+
s.fallback ? e(s.fallback, r) : void 0
|
|
314
|
+
);
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
function ae(e) {
|
|
318
|
+
const t = A(e);
|
|
319
|
+
return function(r, c) {
|
|
320
|
+
return r.themes.reduce(
|
|
321
|
+
(l, u) => (l.push(e(u, c)), l),
|
|
322
|
+
[t(":root", r, c)]
|
|
323
|
+
// Default theme (root)
|
|
324
|
+
).join(`
|
|
325
|
+
|
|
326
|
+
`);
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
function le(e) {
|
|
330
|
+
const t = A(e);
|
|
331
|
+
return function(r, c) {
|
|
332
|
+
return t(r.query, r, c);
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
function fe(e) {
|
|
336
|
+
const t = A(e);
|
|
337
|
+
return function(r, c) {
|
|
338
|
+
const u = (c.theme?.selector ?? V$1)({ name: r.name });
|
|
339
|
+
return t(u, r, c);
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
function me(e) {
|
|
343
|
+
const t = A(e);
|
|
344
|
+
return function(r, c) {
|
|
345
|
+
const l = [], i = (c.utilities?.selector ?? _$1)({
|
|
346
|
+
name: r.name,
|
|
347
|
+
value: r.value,
|
|
348
|
+
modifiers: r.modifiers
|
|
349
|
+
});
|
|
350
|
+
return l.push(t(i, r, c)), l.join(`
|
|
351
|
+
|
|
352
|
+
`);
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
function y(e, t) {
|
|
356
|
+
const s = ae(y), r = le(y), c = me(y), l = Z(y), u = fe(y), i = w$1(y), n = ie(y), o = ce(y), f = se();
|
|
357
|
+
switch (true) {
|
|
358
|
+
case Y$1(e):
|
|
359
|
+
return r(e, t);
|
|
360
|
+
case ee(e):
|
|
361
|
+
return c(e, t);
|
|
362
|
+
case X(e):
|
|
363
|
+
return l(e, t);
|
|
364
|
+
case ne(e):
|
|
365
|
+
return s(e, t);
|
|
366
|
+
case re(e):
|
|
367
|
+
return u(e, t);
|
|
368
|
+
case G(e):
|
|
369
|
+
return i(e, t);
|
|
370
|
+
case J(e):
|
|
371
|
+
return n(e, t);
|
|
372
|
+
case te(e):
|
|
373
|
+
return o(e, t);
|
|
374
|
+
default:
|
|
375
|
+
return f(e, t);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
function R$1(e, t) {
|
|
379
|
+
switch (true) {
|
|
380
|
+
case Array.isArray(e):
|
|
381
|
+
return e.map((s) => R$1(s)).join(`
|
|
382
|
+
`);
|
|
383
|
+
// case isRecipe(instance):
|
|
384
|
+
// return consumeRecipe(instance, options);
|
|
385
|
+
// break;
|
|
386
|
+
default:
|
|
387
|
+
return "";
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
function v(e, t = "") {
|
|
391
|
+
return {
|
|
392
|
+
name: e,
|
|
393
|
+
content: t
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
function be(e, {
|
|
397
|
+
type: t = "all",
|
|
398
|
+
consumers: s = { css: y, ts: R$1 }
|
|
399
|
+
} = {}) {
|
|
400
|
+
const r = { files: [] }, c = e.options, { recipes: l, ...u } = e.root;
|
|
401
|
+
if (t === "all" || t === "css") {
|
|
402
|
+
const i = v("index.css", s.css(u, c));
|
|
403
|
+
r.files.push(i);
|
|
404
|
+
}
|
|
405
|
+
if (t === "all" || t === "ts") {
|
|
406
|
+
const i = v("index.ts", s.ts([], c));
|
|
407
|
+
r.files.push(i);
|
|
408
|
+
}
|
|
409
|
+
return r;
|
|
410
|
+
}
|
|
411
|
+
async function directoryExists(path2) {
|
|
412
|
+
try {
|
|
413
|
+
const stats = await promises.stat(path2);
|
|
414
|
+
return stats.isDirectory();
|
|
415
|
+
} catch {
|
|
416
|
+
return false;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
async function build(instance, { clean = true, outputDir = "./styleframe", transpiler } = {}) {
|
|
420
|
+
const output = be(instance, transpiler);
|
|
421
|
+
const outputDirExists = await directoryExists(outputDir);
|
|
422
|
+
if (clean && outputDirExists) {
|
|
423
|
+
await promises.rm(outputDir, { recursive: true });
|
|
424
|
+
}
|
|
425
|
+
for (const file of output.files) {
|
|
426
|
+
const filePath = path.join(outputDir, file.name);
|
|
427
|
+
const fileOutputDirPath = path.dirname(filePath);
|
|
428
|
+
const fileOutputDirExists = await directoryExists(fileOutputDirPath);
|
|
429
|
+
if (!fileOutputDirExists) {
|
|
430
|
+
await promises.mkdir(fileOutputDirPath, { recursive: true });
|
|
431
|
+
}
|
|
432
|
+
await promises.writeFile(filePath, file.content);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
function M(e, t) {
|
|
436
|
+
return function(n, ...o) {
|
|
437
|
+
return {
|
|
438
|
+
type: "css",
|
|
439
|
+
value: n.reduce((i, u, c) => (i.push(u), c < o.length && i.push(o[c]), i), [])
|
|
440
|
+
};
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
function V(e) {
|
|
444
|
+
return typeof e == "object" && e !== null;
|
|
445
|
+
}
|
|
446
|
+
function p(e, t) {
|
|
447
|
+
return V(e) && "type" in e && e.type === t;
|
|
448
|
+
}
|
|
449
|
+
function k(e) {
|
|
450
|
+
return p(e, "variable");
|
|
451
|
+
}
|
|
452
|
+
function O(e) {
|
|
453
|
+
return p(e, "reference");
|
|
454
|
+
}
|
|
455
|
+
function B(e) {
|
|
456
|
+
return p(e, "css");
|
|
457
|
+
}
|
|
458
|
+
function F(e) {
|
|
459
|
+
return typeof e == "string" || typeof e == "number" || typeof e == "boolean" || e === null;
|
|
460
|
+
}
|
|
461
|
+
function R(e) {
|
|
462
|
+
return F(e) || O(e) || B(e) || Array.isArray(e) && e.every(R);
|
|
463
|
+
}
|
|
464
|
+
function T(e) {
|
|
465
|
+
return V(e) && "children" in e && "declarations" in e && "variables" in e;
|
|
466
|
+
}
|
|
467
|
+
function w(e, t) {
|
|
468
|
+
return function(n, o, s) {
|
|
469
|
+
const i = {
|
|
470
|
+
type: "at-rule",
|
|
471
|
+
identifier: n,
|
|
472
|
+
rule: o,
|
|
473
|
+
declarations: {},
|
|
474
|
+
variables: [],
|
|
475
|
+
children: []
|
|
476
|
+
}, u = b(i, t);
|
|
477
|
+
return typeof s == "function" ? i.declarations = s(u) ?? {} : s && (i.declarations = s), g(i.declarations, u), e.children.push(i), i;
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
function C(e, t) {
|
|
481
|
+
const r = w(e, t);
|
|
482
|
+
return function(o, s) {
|
|
483
|
+
return r("media", o, s);
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
function _(e, t) {
|
|
487
|
+
const r = w(e, t);
|
|
488
|
+
return function(o, s) {
|
|
489
|
+
return r("keyframes", o, s);
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
function S(e, t) {
|
|
493
|
+
return function(n, o) {
|
|
494
|
+
return k(n) ? {
|
|
495
|
+
type: "reference",
|
|
496
|
+
name: n.name,
|
|
497
|
+
fallback: o
|
|
498
|
+
} : {
|
|
499
|
+
type: "reference",
|
|
500
|
+
name: n,
|
|
501
|
+
fallback: o
|
|
502
|
+
};
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
function E(e, t) {
|
|
506
|
+
return function(n, o) {
|
|
507
|
+
const s = {
|
|
508
|
+
type: "selector",
|
|
509
|
+
query: n,
|
|
510
|
+
declarations: {},
|
|
511
|
+
variables: [],
|
|
512
|
+
children: []
|
|
513
|
+
}, i = b(s, t);
|
|
514
|
+
return typeof o == "function" ? s.declarations = o(i) ?? {} : T(o) ? (s.variables = o.variables, s.declarations = o.declarations, s.children = o.children) : s.declarations = o, g(s.declarations, i), e.children.push(s), s;
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
function D(e, t) {
|
|
518
|
+
return function(n, o, s = {
|
|
519
|
+
default: false
|
|
520
|
+
}) {
|
|
521
|
+
const i = typeof n == "string" ? n : n.name, u = e.variables.find(
|
|
522
|
+
(f) => f.name === i
|
|
523
|
+
);
|
|
524
|
+
if (s.default && u)
|
|
525
|
+
return u;
|
|
526
|
+
if (u)
|
|
527
|
+
return u.value = o, u;
|
|
528
|
+
const c = {
|
|
529
|
+
type: "variable",
|
|
530
|
+
name: i,
|
|
531
|
+
value: o
|
|
532
|
+
};
|
|
533
|
+
return e.variables.push(c), c;
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
function b(e, t) {
|
|
537
|
+
const r = D(e), n = E(e, t), o = w(e, t), s = _(t, t), i = C(e, t), u = S(), c = M();
|
|
538
|
+
return {
|
|
539
|
+
variable: r,
|
|
540
|
+
selector: n,
|
|
541
|
+
keyframes: s,
|
|
542
|
+
atRule: o,
|
|
543
|
+
media: i,
|
|
544
|
+
ref: u,
|
|
545
|
+
css: c
|
|
546
|
+
};
|
|
547
|
+
}
|
|
548
|
+
function g(e, t) {
|
|
549
|
+
for (const r in e)
|
|
550
|
+
if (r.startsWith("@")) {
|
|
551
|
+
const n = e[r];
|
|
552
|
+
if (typeof n == "object" && n !== null && !R(n)) {
|
|
553
|
+
const o = r.replace(/^@(\w+).*/, "$1"), s = r.replace(`@${o}`, "").trim();
|
|
554
|
+
t.atRule(o, s, n), delete e[r];
|
|
555
|
+
}
|
|
556
|
+
} else if (/^[.&:]/.test(r)) {
|
|
557
|
+
const n = e[r];
|
|
558
|
+
typeof n == "object" && (t.selector(r, n), delete e[r]);
|
|
559
|
+
}
|
|
560
|
+
return e;
|
|
561
|
+
}
|
|
562
|
+
function m(e) {
|
|
563
|
+
if (e instanceof Buffer)
|
|
564
|
+
return Buffer.from(e);
|
|
565
|
+
const t = e.constructor;
|
|
566
|
+
return new t(
|
|
567
|
+
e.buffer.slice(0),
|
|
568
|
+
e.byteOffset,
|
|
569
|
+
e.byteLength / e.BYTES_PER_ELEMENT || 1
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
function H(e) {
|
|
573
|
+
if (e = e || {}, e.circular)
|
|
574
|
+
return K(e);
|
|
575
|
+
const t = /* @__PURE__ */ new Map();
|
|
576
|
+
if (t.set(Date, (i) => new Date(i)), t.set(
|
|
577
|
+
Map,
|
|
578
|
+
(i, u) => new Map(n(Array.from(i), u))
|
|
579
|
+
), t.set(
|
|
580
|
+
Set,
|
|
581
|
+
(i, u) => new Set(n(Array.from(i), u))
|
|
582
|
+
), e.constructorHandlers)
|
|
583
|
+
for (const i of e.constructorHandlers)
|
|
584
|
+
t.set(i[0], i[1]);
|
|
585
|
+
let r;
|
|
586
|
+
return e.proto ? s : o;
|
|
587
|
+
function n(i, u) {
|
|
588
|
+
const c = Object.keys(i), f = Array.from({ length: c.length });
|
|
589
|
+
for (let a = 0; a < c.length; a++) {
|
|
590
|
+
const l = c[a], y2 = i[l];
|
|
591
|
+
typeof y2 != "object" || y2 === null ? f[l] = y2 : y2.constructor !== Object && (r = t.get(y2.constructor)) ? f[l] = r(y2, u) : ArrayBuffer.isView(y2) ? f[l] = m(y2) : f[l] = u(y2);
|
|
592
|
+
}
|
|
593
|
+
return f;
|
|
594
|
+
}
|
|
595
|
+
function o(i) {
|
|
596
|
+
if (typeof i != "object" || i === null) return i;
|
|
597
|
+
if (Array.isArray(i)) return n(i, o);
|
|
598
|
+
if (i.constructor !== Object && (r = t.get(i.constructor)))
|
|
599
|
+
return r(i, o);
|
|
600
|
+
const u = {};
|
|
601
|
+
for (const c in i) {
|
|
602
|
+
if (Object.hasOwnProperty.call(i, c) === false) continue;
|
|
603
|
+
const f = i[c];
|
|
604
|
+
typeof f != "object" || f === null ? u[c] = f : f.constructor !== Object && (r = t.get(f.constructor)) ? u[c] = r(f, o) : ArrayBuffer.isView(f) ? u[c] = m(f) : u[c] = o(f);
|
|
605
|
+
}
|
|
606
|
+
return u;
|
|
607
|
+
}
|
|
608
|
+
function s(i) {
|
|
609
|
+
if (typeof i != "object" || i === null) return i;
|
|
610
|
+
if (Array.isArray(i)) return n(i, s);
|
|
611
|
+
if (i.constructor !== Object && (r = t.get(i.constructor)))
|
|
612
|
+
return r(i, s);
|
|
613
|
+
const u = {};
|
|
614
|
+
for (const c in i) {
|
|
615
|
+
const f = i[c];
|
|
616
|
+
typeof f != "object" || f === null ? u[c] = f : f.constructor !== Object && (r = t.get(f.constructor)) ? u[c] = r(f, s) : ArrayBuffer.isView(f) ? u[c] = m(f) : u[c] = s(f);
|
|
617
|
+
}
|
|
618
|
+
return u;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
function K(e) {
|
|
622
|
+
const t = [], r = [], n = /* @__PURE__ */ new Map();
|
|
623
|
+
if (n.set(Date, (c) => new Date(c)), n.set(
|
|
624
|
+
Map,
|
|
625
|
+
(c, f) => new Map(s(Array.from(c), f))
|
|
626
|
+
), n.set(
|
|
627
|
+
Set,
|
|
628
|
+
(c, f) => new Set(s(Array.from(c), f))
|
|
629
|
+
), e.constructorHandlers)
|
|
630
|
+
for (const c of e.constructorHandlers)
|
|
631
|
+
n.set(c[0], c[1]);
|
|
632
|
+
let o;
|
|
633
|
+
return e.proto ? u : i;
|
|
634
|
+
function s(c, f) {
|
|
635
|
+
const a = Object.keys(c), l = Array.from({ length: a.length });
|
|
636
|
+
for (let y2 = 0; y2 < a.length; y2++) {
|
|
637
|
+
const h = a[y2], d2 = c[h];
|
|
638
|
+
if (typeof d2 != "object" || d2 === null)
|
|
639
|
+
l[h] = d2;
|
|
640
|
+
else if (d2.constructor !== Object && (o = n.get(d2.constructor)))
|
|
641
|
+
l[h] = o(d2, f);
|
|
642
|
+
else if (ArrayBuffer.isView(d2))
|
|
643
|
+
l[h] = m(d2);
|
|
644
|
+
else {
|
|
645
|
+
const v2 = t.indexOf(d2);
|
|
646
|
+
v2 !== -1 ? l[h] = r[v2] : l[h] = f(d2);
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
return l;
|
|
650
|
+
}
|
|
651
|
+
function i(c) {
|
|
652
|
+
if (typeof c != "object" || c === null) return c;
|
|
653
|
+
if (Array.isArray(c)) return s(c, i);
|
|
654
|
+
if (c.constructor !== Object && (o = n.get(c.constructor)))
|
|
655
|
+
return o(c, i);
|
|
656
|
+
const f = {};
|
|
657
|
+
t.push(c), r.push(f);
|
|
658
|
+
for (const a in c) {
|
|
659
|
+
if (Object.hasOwnProperty.call(c, a) === false) continue;
|
|
660
|
+
const l = c[a];
|
|
661
|
+
if (typeof l != "object" || l === null)
|
|
662
|
+
f[a] = l;
|
|
663
|
+
else if (l.constructor !== Object && (o = n.get(l.constructor)))
|
|
664
|
+
f[a] = o(l, i);
|
|
665
|
+
else if (ArrayBuffer.isView(l))
|
|
666
|
+
f[a] = m(l);
|
|
667
|
+
else {
|
|
668
|
+
const y2 = t.indexOf(l);
|
|
669
|
+
y2 !== -1 ? f[a] = r[y2] : f[a] = i(l);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
return t.pop(), r.pop(), f;
|
|
673
|
+
}
|
|
674
|
+
function u(c) {
|
|
675
|
+
if (typeof c != "object" || c === null) return c;
|
|
676
|
+
if (Array.isArray(c)) return s(c, u);
|
|
677
|
+
if (c.constructor !== Object && (o = n.get(c.constructor)))
|
|
678
|
+
return o(c, u);
|
|
679
|
+
const f = {};
|
|
680
|
+
t.push(c), r.push(f);
|
|
681
|
+
for (const a in c) {
|
|
682
|
+
const l = c[a];
|
|
683
|
+
if (typeof l != "object" || l === null)
|
|
684
|
+
f[a] = l;
|
|
685
|
+
else if (l.constructor !== Object && (o = n.get(l.constructor)))
|
|
686
|
+
f[a] = o(l, u);
|
|
687
|
+
else if (ArrayBuffer.isView(l))
|
|
688
|
+
f[a] = m(l);
|
|
689
|
+
else {
|
|
690
|
+
const y2 = t.indexOf(l);
|
|
691
|
+
y2 !== -1 ? f[a] = r[y2] : f[a] = u(l);
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
return t.pop(), r.pop(), f;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
const j = H();
|
|
698
|
+
function $(e) {
|
|
699
|
+
const t = [];
|
|
700
|
+
function r(n, o) {
|
|
701
|
+
o.length > 0 && t.push([...o].sort());
|
|
702
|
+
for (let s = n; s < e.length; s++) {
|
|
703
|
+
const i = e[s];
|
|
704
|
+
if (i)
|
|
705
|
+
if (i.length === 1 && i[0])
|
|
706
|
+
r(s + 1, [...o, i[0]]);
|
|
707
|
+
else
|
|
708
|
+
for (const u of i)
|
|
709
|
+
r(s + 1, [...o, u]);
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
return r(0, []), t.sort((n, o) => n.length !== o.length ? n.length - o.length : n.join(",").localeCompare(o.join(",")));
|
|
713
|
+
}
|
|
714
|
+
function L(e, t, r) {
|
|
715
|
+
const n = {
|
|
716
|
+
...e,
|
|
717
|
+
modifiers: [...r.keys()]
|
|
718
|
+
}, o = b(n, t);
|
|
719
|
+
for (const s of r.values())
|
|
720
|
+
s.factory({
|
|
721
|
+
...o,
|
|
722
|
+
declarations: j(n.declarations),
|
|
723
|
+
variables: j(n.variables),
|
|
724
|
+
children: j(n.children)
|
|
725
|
+
}), g(n.declarations, o);
|
|
726
|
+
return n;
|
|
727
|
+
}
|
|
728
|
+
function N(e, t) {
|
|
729
|
+
return function(n, o) {
|
|
730
|
+
const s = {
|
|
731
|
+
type: "modifier",
|
|
732
|
+
key: Array.isArray(n) ? n : [n],
|
|
733
|
+
factory: o
|
|
734
|
+
};
|
|
735
|
+
return t.modifiers.push(s), s;
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
function z() {
|
|
739
|
+
return {
|
|
740
|
+
type: "root",
|
|
741
|
+
declarations: {},
|
|
742
|
+
utilities: [],
|
|
743
|
+
modifiers: [],
|
|
744
|
+
recipes: [],
|
|
745
|
+
variables: [],
|
|
746
|
+
children: [],
|
|
747
|
+
themes: []
|
|
748
|
+
};
|
|
749
|
+
}
|
|
750
|
+
function I(e, t, r) {
|
|
751
|
+
const n = t.map((s) => s.key);
|
|
752
|
+
return $(n).map((s) => {
|
|
753
|
+
const i = /* @__PURE__ */ new Map();
|
|
754
|
+
for (const u of s) {
|
|
755
|
+
const c = t.find(
|
|
756
|
+
(f) => f.key.includes(u)
|
|
757
|
+
);
|
|
758
|
+
c && i.set(u, c);
|
|
759
|
+
}
|
|
760
|
+
return L(e, r, i);
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
function W(e, t) {
|
|
764
|
+
return function(n, o) {
|
|
765
|
+
const s = {
|
|
766
|
+
type: "utility",
|
|
767
|
+
name: n,
|
|
768
|
+
factory: o
|
|
769
|
+
};
|
|
770
|
+
return t.utilities.push(s), (i, u = []) => {
|
|
771
|
+
for (const [c, f] of Object.entries(i)) {
|
|
772
|
+
const a = {
|
|
773
|
+
type: "utility",
|
|
774
|
+
name: n,
|
|
775
|
+
value: c,
|
|
776
|
+
declarations: {},
|
|
777
|
+
variables: [],
|
|
778
|
+
children: [],
|
|
779
|
+
modifiers: []
|
|
780
|
+
}, l = b(
|
|
781
|
+
a,
|
|
782
|
+
t
|
|
783
|
+
);
|
|
784
|
+
a.declarations = o({
|
|
785
|
+
...l,
|
|
786
|
+
value: f
|
|
787
|
+
}) ?? {}, g(a.declarations, l), e.children.push(a), u.length > 0 && e.children.push(
|
|
788
|
+
...I(a, u, t)
|
|
789
|
+
);
|
|
790
|
+
}
|
|
791
|
+
};
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
function Y(e, t) {
|
|
795
|
+
return function(n, o) {
|
|
796
|
+
const s = t.themes.find((c) => c.name === n), i = s ?? {
|
|
797
|
+
type: "theme",
|
|
798
|
+
name: n,
|
|
799
|
+
declarations: {},
|
|
800
|
+
variables: [],
|
|
801
|
+
children: []
|
|
802
|
+
};
|
|
803
|
+
s || t.themes.push(i);
|
|
804
|
+
const u = b(i, t);
|
|
805
|
+
return o && o(u), i;
|
|
806
|
+
};
|
|
807
|
+
}
|
|
808
|
+
function q(e, t) {
|
|
809
|
+
return function(n, o, s, i) {
|
|
810
|
+
const u = {
|
|
811
|
+
type: "recipe",
|
|
812
|
+
name: n,
|
|
813
|
+
defaults: o,
|
|
814
|
+
variants: s,
|
|
815
|
+
...i
|
|
816
|
+
};
|
|
817
|
+
return t.recipes.push(u), u;
|
|
818
|
+
};
|
|
819
|
+
}
|
|
820
|
+
function oe(e) {
|
|
821
|
+
const t = z(), r = { ...e }, n = W(t, t), o = N(t, t), s = q(t, t), i = Y(t, t), { variable: u, selector: c, atRule: f, keyframes: a, media: l, ref: y2, css: h } = b(t, t);
|
|
822
|
+
return {
|
|
823
|
+
root: t,
|
|
824
|
+
variable: u,
|
|
825
|
+
selector: c,
|
|
826
|
+
utility: n,
|
|
827
|
+
modifier: o,
|
|
828
|
+
recipe: s,
|
|
829
|
+
theme: i,
|
|
830
|
+
atRule: f,
|
|
831
|
+
keyframes: a,
|
|
832
|
+
media: l,
|
|
833
|
+
ref: y2,
|
|
834
|
+
css: h,
|
|
835
|
+
options: r
|
|
836
|
+
};
|
|
837
|
+
}
|
|
838
|
+
async function loadConfiguration({
|
|
839
|
+
cwd = process.cwd(),
|
|
840
|
+
name = "styleframe"
|
|
841
|
+
} = {}) {
|
|
842
|
+
const { config } = await c12.loadConfig({
|
|
843
|
+
cwd,
|
|
844
|
+
name,
|
|
845
|
+
defaults: oe()
|
|
846
|
+
});
|
|
847
|
+
return config;
|
|
848
|
+
}
|
|
849
|
+
async function loadConfigurationFromPath(entry) {
|
|
850
|
+
const entryPath = path.resolve(entry);
|
|
851
|
+
const cwd = path.dirname(entryPath);
|
|
852
|
+
const name = path.basename(entryPath).replace(/(\.config)?(\.ts)?$/, "");
|
|
853
|
+
return await loadConfiguration({ cwd, name });
|
|
854
|
+
}
|
|
855
|
+
async function watchConfiguration({
|
|
856
|
+
cwd = process.cwd()
|
|
857
|
+
} = {}) {
|
|
858
|
+
return await c12.watchConfig({
|
|
859
|
+
cwd,
|
|
860
|
+
name: "styleframe",
|
|
861
|
+
acceptHMR({ getDiff }) {
|
|
862
|
+
const diff = getDiff();
|
|
863
|
+
if (diff.length === 0) {
|
|
864
|
+
return true;
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
exports2.build = build;
|
|
870
|
+
exports2.directoryExists = directoryExists;
|
|
871
|
+
exports2.loadConfiguration = loadConfiguration;
|
|
872
|
+
exports2.loadConfigurationFromPath = loadConfigurationFromPath;
|
|
873
|
+
exports2.watchConfiguration = watchConfiguration;
|
|
874
|
+
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
|
875
|
+
}));
|