@styleframe/transpiler 3.2.0 → 3.3.0
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 +13 -0
- package/dist/transpiler.d.ts +10 -3
- package/dist/transpiler.js +300 -289
- package/dist/transpiler.umd.cjs +21 -19
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @styleframe/transpiler
|
|
2
2
|
|
|
3
|
+
## 3.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#221](https://github.com/styleframe-dev/styleframe/pull/221) [`6d406c2`](https://github.com/styleframe-dev/styleframe/commit/6d406c289b39c666a3fb7468aa3ec08f5a6d316b) Thanks [@alexgrozav](https://github.com/alexgrozav)! - Add `treeshake` option to remove unused variables from CSS output.
|
|
8
|
+
|
|
9
|
+
`root._usage` now tracks both `variables` and `utilities` referenced during config execution and scanner registration. The transpiler's new `treeshake: true` option filters `root.variables` and theme variables down to only those present in `_usage.variables`. The plugin enables treeshaking by default when generating global CSS.
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [[`6d406c2`](https://github.com/styleframe-dev/styleframe/commit/6d406c289b39c666a3fb7468aa3ec08f5a6d316b)]:
|
|
14
|
+
- @styleframe/core@3.5.0
|
|
15
|
+
|
|
3
16
|
## 3.2.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
package/dist/transpiler.d.ts
CHANGED
|
@@ -11,9 +11,9 @@ export declare function addIndentToLine(line: string): string;
|
|
|
11
11
|
/**
|
|
12
12
|
* Consumes any token instance and returns the CSS string representation
|
|
13
13
|
*/
|
|
14
|
-
export declare function consumeCSS(instance: unknown, options: StyleframeOptions): string;
|
|
14
|
+
export declare function consumeCSS(instance: unknown, options: StyleframeOptions, context?: TranspileContext): string;
|
|
15
15
|
|
|
16
|
-
export declare type ConsumeFunction = (instance: unknown, options: StyleframeOptions) => string;
|
|
16
|
+
export declare type ConsumeFunction = (instance: unknown, options: StyleframeOptions, context?: TranspileContext) => string;
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* Consumes any token instance and returns the TS string representation
|
|
@@ -51,10 +51,17 @@ export declare function toCamelCase<S extends string>(str: S): CamelCase<S>;
|
|
|
51
51
|
|
|
52
52
|
export declare function toKebabCase<S extends string>(str: S): KebabCase<S>;
|
|
53
53
|
|
|
54
|
-
export declare function transpile(instance: Styleframe, { type, consumers, }?: TranspileOptions): Promise<Output>;
|
|
54
|
+
export declare function transpile(instance: Styleframe, { type, treeshake, scanner, consumers, }?: TranspileOptions): Promise<Output>;
|
|
55
|
+
|
|
56
|
+
export declare type TranspileContext = {
|
|
57
|
+
treeshake?: boolean;
|
|
58
|
+
scanner?: boolean;
|
|
59
|
+
};
|
|
55
60
|
|
|
56
61
|
export declare type TranspileOptions = {
|
|
57
62
|
type?: "css" | "ts" | "dts" | "all";
|
|
63
|
+
treeshake?: boolean;
|
|
64
|
+
scanner?: boolean;
|
|
58
65
|
consumers?: {
|
|
59
66
|
css: ConsumeFunction;
|
|
60
67
|
ts: ConsumeFunction;
|
package/dist/transpiler.js
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
const
|
|
1
|
+
const Me = " ", L = ["charset", "import", "namespace"], I = ["layer"];
|
|
2
2
|
function M(e) {
|
|
3
3
|
return typeof e == "object" && e !== null;
|
|
4
4
|
}
|
|
5
|
-
function
|
|
5
|
+
function g(e, t) {
|
|
6
6
|
return M(e) && "type" in e && e.type === t;
|
|
7
7
|
}
|
|
8
|
-
function k(e) {
|
|
9
|
-
return h(e, "variable");
|
|
10
|
-
}
|
|
11
8
|
function V(e) {
|
|
12
|
-
return
|
|
13
|
-
}
|
|
14
|
-
function S(e) {
|
|
15
|
-
return h(e, "selector");
|
|
9
|
+
return g(e, "variable");
|
|
16
10
|
}
|
|
17
11
|
function K(e) {
|
|
18
|
-
return
|
|
12
|
+
return g(e, "reference");
|
|
13
|
+
}
|
|
14
|
+
function S(e) {
|
|
15
|
+
return g(e, "selector");
|
|
19
16
|
}
|
|
20
17
|
function q(e) {
|
|
21
|
-
return
|
|
18
|
+
return g(e, "at-rule");
|
|
22
19
|
}
|
|
23
20
|
function z(e) {
|
|
24
|
-
return
|
|
21
|
+
return g(e, "utility");
|
|
25
22
|
}
|
|
26
23
|
function H(e) {
|
|
27
|
-
return
|
|
24
|
+
return g(e, "css");
|
|
28
25
|
}
|
|
29
|
-
function
|
|
30
|
-
return
|
|
26
|
+
function Q(e) {
|
|
27
|
+
return g(e, "theme");
|
|
31
28
|
}
|
|
32
|
-
function
|
|
33
|
-
return
|
|
29
|
+
function O(e) {
|
|
30
|
+
return g(e, "root");
|
|
34
31
|
}
|
|
35
|
-
|
|
32
|
+
function w(e) {
|
|
33
|
+
return g(e, "recipe");
|
|
34
|
+
}
|
|
35
|
+
const T = ({
|
|
36
36
|
name: e,
|
|
37
37
|
value: t,
|
|
38
38
|
modifiers: r
|
|
@@ -41,7 +41,7 @@ const Q = ({
|
|
|
41
41
|
e,
|
|
42
42
|
...t === "default" ? [] : [t]
|
|
43
43
|
].filter(Boolean).join(":")}`;
|
|
44
|
-
function
|
|
44
|
+
function $(e) {
|
|
45
45
|
return e.charAt(0).toUpperCase() + e.slice(1);
|
|
46
46
|
}
|
|
47
47
|
function J(e) {
|
|
@@ -61,138 +61,138 @@ function Z(e) {
|
|
|
61
61
|
if (e = e || {}, e.circular)
|
|
62
62
|
return W(e);
|
|
63
63
|
const t = /* @__PURE__ */ new Map();
|
|
64
|
-
if (t.set(Date, (
|
|
64
|
+
if (t.set(Date, (c) => new Date(c)), t.set(
|
|
65
65
|
Map,
|
|
66
|
-
(
|
|
66
|
+
(c, a) => new Map(o(Array.from(c), a))
|
|
67
67
|
), t.set(
|
|
68
68
|
Set,
|
|
69
|
-
(
|
|
69
|
+
(c, a) => new Set(o(Array.from(c), a))
|
|
70
70
|
), e.constructorHandlers)
|
|
71
|
-
for (const
|
|
72
|
-
t.set(
|
|
71
|
+
for (const c of e.constructorHandlers)
|
|
72
|
+
t.set(c[0], c[1]);
|
|
73
73
|
let r;
|
|
74
|
-
return e.proto ?
|
|
75
|
-
function
|
|
76
|
-
const
|
|
77
|
-
for (let f = 0; f <
|
|
78
|
-
const l =
|
|
79
|
-
typeof m != "object" || m === null ?
|
|
74
|
+
return e.proto ? i : n;
|
|
75
|
+
function o(c, a) {
|
|
76
|
+
const s = Object.keys(c), u = Array.from({ length: s.length });
|
|
77
|
+
for (let f = 0; f < s.length; f++) {
|
|
78
|
+
const l = s[f], m = c[l];
|
|
79
|
+
typeof m != "object" || m === null ? u[l] = m : m.constructor !== Object && (r = t.get(m.constructor)) ? u[l] = r(m, a) : ArrayBuffer.isView(m) ? u[l] = A(m) : u[l] = a(m);
|
|
80
80
|
}
|
|
81
|
-
return
|
|
81
|
+
return u;
|
|
82
82
|
}
|
|
83
|
-
function
|
|
84
|
-
if (typeof
|
|
85
|
-
if (Array.isArray(
|
|
86
|
-
if (
|
|
87
|
-
return r(
|
|
83
|
+
function n(c) {
|
|
84
|
+
if (typeof c != "object" || c === null) return c;
|
|
85
|
+
if (Array.isArray(c)) return o(c, n);
|
|
86
|
+
if (c.constructor !== Object && (r = t.get(c.constructor)))
|
|
87
|
+
return r(c, n);
|
|
88
88
|
const a = {};
|
|
89
|
-
for (const
|
|
90
|
-
if (Object.hasOwnProperty.call(
|
|
91
|
-
const
|
|
92
|
-
typeof
|
|
89
|
+
for (const s in c) {
|
|
90
|
+
if (Object.hasOwnProperty.call(c, s) === !1) continue;
|
|
91
|
+
const u = c[s];
|
|
92
|
+
typeof u != "object" || u === null ? a[s] = u : u.constructor !== Object && (r = t.get(u.constructor)) ? a[s] = r(u, n) : ArrayBuffer.isView(u) ? a[s] = A(u) : a[s] = n(u);
|
|
93
93
|
}
|
|
94
94
|
return a;
|
|
95
95
|
}
|
|
96
|
-
function c
|
|
97
|
-
if (typeof
|
|
98
|
-
if (Array.isArray(
|
|
99
|
-
if (
|
|
100
|
-
return r(
|
|
96
|
+
function i(c) {
|
|
97
|
+
if (typeof c != "object" || c === null) return c;
|
|
98
|
+
if (Array.isArray(c)) return o(c, i);
|
|
99
|
+
if (c.constructor !== Object && (r = t.get(c.constructor)))
|
|
100
|
+
return r(c, i);
|
|
101
101
|
const a = {};
|
|
102
|
-
for (const
|
|
103
|
-
const
|
|
104
|
-
typeof
|
|
102
|
+
for (const s in c) {
|
|
103
|
+
const u = c[s];
|
|
104
|
+
typeof u != "object" || u === null ? a[s] = u : u.constructor !== Object && (r = t.get(u.constructor)) ? a[s] = r(u, i) : ArrayBuffer.isView(u) ? a[s] = A(u) : a[s] = i(u);
|
|
105
105
|
}
|
|
106
106
|
return a;
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
function W(e) {
|
|
110
|
-
const t = [], r = [],
|
|
111
|
-
if (
|
|
110
|
+
const t = [], r = [], o = /* @__PURE__ */ new Map();
|
|
111
|
+
if (o.set(Date, (s) => new Date(s)), o.set(
|
|
112
112
|
Map,
|
|
113
|
-
(
|
|
114
|
-
),
|
|
113
|
+
(s, u) => new Map(i(Array.from(s), u))
|
|
114
|
+
), o.set(
|
|
115
115
|
Set,
|
|
116
|
-
(
|
|
116
|
+
(s, u) => new Set(i(Array.from(s), u))
|
|
117
117
|
), e.constructorHandlers)
|
|
118
|
-
for (const
|
|
119
|
-
|
|
120
|
-
let
|
|
121
|
-
return e.proto ? a :
|
|
122
|
-
function
|
|
123
|
-
const f = Object.keys(
|
|
118
|
+
for (const s of e.constructorHandlers)
|
|
119
|
+
o.set(s[0], s[1]);
|
|
120
|
+
let n;
|
|
121
|
+
return e.proto ? a : c;
|
|
122
|
+
function i(s, u) {
|
|
123
|
+
const f = Object.keys(s), l = Array.from({ length: f.length });
|
|
124
124
|
for (let m = 0; m < f.length; m++) {
|
|
125
|
-
const
|
|
126
|
-
if (typeof
|
|
127
|
-
l[
|
|
128
|
-
else if (
|
|
129
|
-
l[
|
|
130
|
-
else if (ArrayBuffer.isView(
|
|
131
|
-
l[
|
|
125
|
+
const y = f[m], d = s[y];
|
|
126
|
+
if (typeof d != "object" || d === null)
|
|
127
|
+
l[y] = d;
|
|
128
|
+
else if (d.constructor !== Object && (n = o.get(d.constructor)))
|
|
129
|
+
l[y] = n(d, u);
|
|
130
|
+
else if (ArrayBuffer.isView(d))
|
|
131
|
+
l[y] = A(d);
|
|
132
132
|
else {
|
|
133
|
-
const
|
|
134
|
-
|
|
133
|
+
const h = t.indexOf(d);
|
|
134
|
+
h !== -1 ? l[y] = r[h] : l[y] = u(d);
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
return l;
|
|
138
138
|
}
|
|
139
|
-
function s
|
|
140
|
-
if (typeof
|
|
141
|
-
if (Array.isArray(
|
|
142
|
-
if (
|
|
143
|
-
return
|
|
144
|
-
const
|
|
145
|
-
t.push(
|
|
146
|
-
for (const f in
|
|
147
|
-
if (Object.hasOwnProperty.call(
|
|
148
|
-
const l =
|
|
139
|
+
function c(s) {
|
|
140
|
+
if (typeof s != "object" || s === null) return s;
|
|
141
|
+
if (Array.isArray(s)) return i(s, c);
|
|
142
|
+
if (s.constructor !== Object && (n = o.get(s.constructor)))
|
|
143
|
+
return n(s, c);
|
|
144
|
+
const u = {};
|
|
145
|
+
t.push(s), r.push(u);
|
|
146
|
+
for (const f in s) {
|
|
147
|
+
if (Object.hasOwnProperty.call(s, f) === !1) continue;
|
|
148
|
+
const l = s[f];
|
|
149
149
|
if (typeof l != "object" || l === null)
|
|
150
|
-
|
|
151
|
-
else if (l.constructor !== Object && (
|
|
152
|
-
|
|
150
|
+
u[f] = l;
|
|
151
|
+
else if (l.constructor !== Object && (n = o.get(l.constructor)))
|
|
152
|
+
u[f] = n(l, c);
|
|
153
153
|
else if (ArrayBuffer.isView(l))
|
|
154
|
-
|
|
154
|
+
u[f] = A(l);
|
|
155
155
|
else {
|
|
156
156
|
const m = t.indexOf(l);
|
|
157
|
-
m !== -1 ?
|
|
157
|
+
m !== -1 ? u[f] = r[m] : u[f] = c(l);
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
|
-
return t.pop(), r.pop(),
|
|
160
|
+
return t.pop(), r.pop(), u;
|
|
161
161
|
}
|
|
162
|
-
function a(
|
|
163
|
-
if (typeof
|
|
164
|
-
if (Array.isArray(
|
|
165
|
-
if (
|
|
166
|
-
return
|
|
167
|
-
const
|
|
168
|
-
t.push(
|
|
169
|
-
for (const f in
|
|
170
|
-
const l =
|
|
162
|
+
function a(s) {
|
|
163
|
+
if (typeof s != "object" || s === null) return s;
|
|
164
|
+
if (Array.isArray(s)) return i(s, a);
|
|
165
|
+
if (s.constructor !== Object && (n = o.get(s.constructor)))
|
|
166
|
+
return n(s, a);
|
|
167
|
+
const u = {};
|
|
168
|
+
t.push(s), r.push(u);
|
|
169
|
+
for (const f in s) {
|
|
170
|
+
const l = s[f];
|
|
171
171
|
if (typeof l != "object" || l === null)
|
|
172
|
-
|
|
173
|
-
else if (l.constructor !== Object && (
|
|
174
|
-
|
|
172
|
+
u[f] = l;
|
|
173
|
+
else if (l.constructor !== Object && (n = o.get(l.constructor)))
|
|
174
|
+
u[f] = n(l, a);
|
|
175
175
|
else if (ArrayBuffer.isView(l))
|
|
176
|
-
|
|
176
|
+
u[f] = A(l);
|
|
177
177
|
else {
|
|
178
178
|
const m = t.indexOf(l);
|
|
179
|
-
m !== -1 ?
|
|
179
|
+
m !== -1 ? u[f] = r[m] : u[f] = a(l);
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
|
-
return t.pop(), r.pop(),
|
|
182
|
+
return t.pop(), r.pop(), u;
|
|
183
183
|
}
|
|
184
184
|
}
|
|
185
185
|
Z();
|
|
186
186
|
function G(e, t = 8) {
|
|
187
187
|
const r = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
188
|
-
let
|
|
189
|
-
for (let
|
|
190
|
-
const
|
|
191
|
-
|
|
188
|
+
let o = "";
|
|
189
|
+
for (let n = 0; n < t; n++) {
|
|
190
|
+
const i = Math.floor(Math.random() * r.length);
|
|
191
|
+
o += r[i];
|
|
192
192
|
}
|
|
193
|
-
return e ? `${e}${
|
|
193
|
+
return e ? `${e}${o}` : o;
|
|
194
194
|
}
|
|
195
|
-
const Y = ({ name: e }) => `.${e}-theme, [data-theme="${e}"]`,
|
|
195
|
+
const Y = ({ name: e }) => `.${e}-theme, [data-theme="${e}"]`, B = ({ name: e }) => e.replace(/^\.+|\.+$/g, "").replace(/\.+/g, "--");
|
|
196
196
|
function X(e, t) {
|
|
197
197
|
return `@${e}${t ? " " : ""}${t}`;
|
|
198
198
|
}
|
|
@@ -201,32 +201,32 @@ function re(e = "") {
|
|
|
201
201
|
if (!ee.test(e))
|
|
202
202
|
return e !== e.toLowerCase();
|
|
203
203
|
}
|
|
204
|
-
function
|
|
205
|
-
const r = te,
|
|
204
|
+
function E(e, t) {
|
|
205
|
+
const r = te, o = [];
|
|
206
206
|
if (!e || typeof e != "string")
|
|
207
|
-
return
|
|
208
|
-
let
|
|
207
|
+
return o;
|
|
208
|
+
let n = "", i, c;
|
|
209
209
|
for (const a of e) {
|
|
210
|
-
const
|
|
211
|
-
if (
|
|
212
|
-
|
|
210
|
+
const s = r.includes(a);
|
|
211
|
+
if (s === !0) {
|
|
212
|
+
o.push(n), n = "", i = void 0;
|
|
213
213
|
continue;
|
|
214
214
|
}
|
|
215
|
-
const
|
|
216
|
-
if (
|
|
217
|
-
if (
|
|
218
|
-
|
|
215
|
+
const u = re(a);
|
|
216
|
+
if (c === !1) {
|
|
217
|
+
if (i === !1 && u === !0) {
|
|
218
|
+
o.push(n), n = a, i = u;
|
|
219
219
|
continue;
|
|
220
220
|
}
|
|
221
|
-
if (
|
|
222
|
-
const f =
|
|
223
|
-
|
|
221
|
+
if (i === !0 && u === !1 && n.length > 1) {
|
|
222
|
+
const f = n.at(-1);
|
|
223
|
+
o.push(n.slice(0, Math.max(0, n.length - 1))), n = f + a, i = u;
|
|
224
224
|
continue;
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
|
-
|
|
227
|
+
n += a, i = u, c = s;
|
|
228
228
|
}
|
|
229
|
-
return
|
|
229
|
+
return o.push(n), o;
|
|
230
230
|
}
|
|
231
231
|
function ne(e) {
|
|
232
232
|
return e ? e[0].toUpperCase() + e.slice(1) : "";
|
|
@@ -234,14 +234,14 @@ function ne(e) {
|
|
|
234
234
|
function oe(e) {
|
|
235
235
|
return e ? e[0].toLowerCase() + e.slice(1) : "";
|
|
236
236
|
}
|
|
237
|
-
function
|
|
238
|
-
return e ? (Array.isArray(e) ? e :
|
|
237
|
+
function se(e, t) {
|
|
238
|
+
return e ? (Array.isArray(e) ? e : E(e)).map((r) => ne(r)).join("") : "";
|
|
239
239
|
}
|
|
240
240
|
function ce(e, t) {
|
|
241
|
-
return oe(
|
|
241
|
+
return oe(se(e || ""));
|
|
242
242
|
}
|
|
243
|
-
function
|
|
244
|
-
return e ? (Array.isArray(e) ? e :
|
|
243
|
+
function ue(e, t) {
|
|
244
|
+
return e ? (Array.isArray(e) ? e : E(e)).map((r) => r.toLowerCase()).join("-") : "";
|
|
245
245
|
}
|
|
246
246
|
function ie(e) {
|
|
247
247
|
return ` ${e}`;
|
|
@@ -251,19 +251,19 @@ function ae(e) {
|
|
|
251
251
|
`).map((t) => ie(t)).join(`
|
|
252
252
|
`);
|
|
253
253
|
}
|
|
254
|
-
function
|
|
254
|
+
function F(e) {
|
|
255
255
|
return e === e.toUpperCase();
|
|
256
256
|
}
|
|
257
|
-
function
|
|
257
|
+
function D(e) {
|
|
258
258
|
return ce(e);
|
|
259
259
|
}
|
|
260
260
|
function le(e) {
|
|
261
|
-
return
|
|
261
|
+
return ue(e);
|
|
262
262
|
}
|
|
263
263
|
function fe(e) {
|
|
264
264
|
return le(e);
|
|
265
265
|
}
|
|
266
|
-
function
|
|
266
|
+
function P(e, t) {
|
|
267
267
|
return `${e.startsWith("--") ? e : fe(e)}: ${t};`;
|
|
268
268
|
}
|
|
269
269
|
function me(e) {
|
|
@@ -271,93 +271,100 @@ function me(e) {
|
|
|
271
271
|
` : ""}${e.map((t) => `${ae(`${t}`)}
|
|
272
272
|
`).join("")}}`;
|
|
273
273
|
}
|
|
274
|
-
function
|
|
274
|
+
function U(e) {
|
|
275
275
|
return `--${(e.startsWith("--") ? e.slice(2) : e).replace(/[^a-zA-Z0-9_\-\u0080-\uFFFF]/g, "-") || "unknown-variable"}`;
|
|
276
276
|
}
|
|
277
277
|
function pe(e, t) {
|
|
278
|
-
return
|
|
278
|
+
return P(U(e), t);
|
|
279
279
|
}
|
|
280
280
|
function de(e, t) {
|
|
281
|
-
return `var(${
|
|
281
|
+
return `var(${U(e)}${t ? `, ${t}` : ""})`;
|
|
282
282
|
}
|
|
283
|
-
function
|
|
283
|
+
function _(e, t) {
|
|
284
284
|
return `${e} ${me(t)}`;
|
|
285
285
|
}
|
|
286
286
|
function ye(e) {
|
|
287
|
-
return function(r,
|
|
288
|
-
return Object.entries(r).map(([
|
|
287
|
+
return function(r, o) {
|
|
288
|
+
return Object.entries(r).map(([n, i]) => P(n, e(i, o)));
|
|
289
289
|
};
|
|
290
290
|
}
|
|
291
|
-
function
|
|
292
|
-
return function(r,
|
|
293
|
-
const
|
|
294
|
-
return pe(
|
|
291
|
+
function k(e) {
|
|
292
|
+
return function(r, o) {
|
|
293
|
+
const i = (o.variables?.name ?? B)({ name: r.name });
|
|
294
|
+
return pe(i, e(r.value, o));
|
|
295
295
|
};
|
|
296
296
|
}
|
|
297
297
|
function C(e) {
|
|
298
|
-
const t =
|
|
299
|
-
return function(
|
|
300
|
-
const { variables: a, declarations:
|
|
301
|
-
(
|
|
298
|
+
const t = k(e), r = ye(e);
|
|
299
|
+
return function(n, i, c) {
|
|
300
|
+
const { variables: a, declarations: s, children: u } = i, f = n === ":root", l = (a ?? []).map(
|
|
301
|
+
(p) => t(p, c)
|
|
302
302
|
), m = r(
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
),
|
|
306
|
-
(
|
|
307
|
-
),
|
|
308
|
-
return f ? `${
|
|
303
|
+
s ?? {},
|
|
304
|
+
c
|
|
305
|
+
), y = (u ?? []).map(
|
|
306
|
+
(p) => e(p, c)
|
|
307
|
+
), d = l.length > 0, h = m.length > 0, v = y.length > 0;
|
|
308
|
+
return f ? `${d || h ? _(n, [
|
|
309
309
|
...l,
|
|
310
|
-
...
|
|
310
|
+
...d && h ? [""] : [],
|
|
311
311
|
...m
|
|
312
|
-
]) : ""}${v && (
|
|
312
|
+
]) : ""}${v && (d || h) ? `
|
|
313
313
|
|
|
314
|
-
` : ""}${
|
|
314
|
+
` : ""}${y.join(`
|
|
315
315
|
|
|
316
|
-
`)}` :
|
|
316
|
+
`)}` : _(n, [
|
|
317
317
|
...l,
|
|
318
|
-
...
|
|
318
|
+
...d && (v || h) ? [""] : [],
|
|
319
319
|
...m,
|
|
320
|
-
...
|
|
321
|
-
...
|
|
322
|
-
(
|
|
320
|
+
...h && v ? [""] : [],
|
|
321
|
+
...y.flatMap(
|
|
322
|
+
(p, j) => j === y.length - 1 ? [p] : [p, ""]
|
|
323
323
|
)
|
|
324
324
|
]);
|
|
325
325
|
};
|
|
326
326
|
}
|
|
327
327
|
function he(e) {
|
|
328
328
|
const t = C(e);
|
|
329
|
-
return function(
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
), a = Object.keys(
|
|
333
|
-
return
|
|
329
|
+
return function(o, n) {
|
|
330
|
+
const i = L.includes(o.identifier), c = I.includes(
|
|
331
|
+
o.identifier
|
|
332
|
+
), a = Object.keys(o.declarations).length > 0, s = o.variables.length > 0, u = o.children.length > 0, f = X(o.identifier, o.rule);
|
|
333
|
+
return i || c && !(a || s || u) ? `${f};` : t(f, o, n);
|
|
334
334
|
};
|
|
335
335
|
}
|
|
336
336
|
function be(e) {
|
|
337
|
-
return function(r,
|
|
338
|
-
return r.value.map((
|
|
337
|
+
return function(r, o) {
|
|
338
|
+
return r.value.map((n) => e(n, o)).join("").trim();
|
|
339
339
|
};
|
|
340
340
|
}
|
|
341
341
|
function ge(e) {
|
|
342
|
-
return function(r,
|
|
342
|
+
return function(r, o) {
|
|
343
343
|
return r != null ? `${r}` : "";
|
|
344
344
|
};
|
|
345
345
|
}
|
|
346
346
|
function Ae(e) {
|
|
347
|
-
return function(r,
|
|
348
|
-
const
|
|
347
|
+
return function(r, o) {
|
|
348
|
+
const i = (o.variables?.name ?? B)({ name: r.name });
|
|
349
349
|
return de(
|
|
350
|
-
|
|
351
|
-
r.fallback ? e(r.fallback,
|
|
350
|
+
i,
|
|
351
|
+
r.fallback ? e(r.fallback, o) : void 0
|
|
352
352
|
);
|
|
353
353
|
};
|
|
354
354
|
}
|
|
355
355
|
function Se(e) {
|
|
356
356
|
const t = C(e);
|
|
357
|
-
return function(n,
|
|
358
|
-
|
|
359
|
-
(
|
|
360
|
-
|
|
357
|
+
return function(o, n, i) {
|
|
358
|
+
const c = i?.treeshake ?? !1, a = i?.scanner ?? !1, s = o._usage.variables, u = (p) => !c || s.has(p.name), f = (p) => c ? { ...p, variables: p.variables.filter(u) } : p, l = c && a, m = o._usage.utilities, y = (p) => p.type !== "utility" || !l ? !0 : m.has(
|
|
359
|
+
T({
|
|
360
|
+
name: p.name,
|
|
361
|
+
value: p.value,
|
|
362
|
+
modifiers: p.modifiers
|
|
363
|
+
})
|
|
364
|
+
), d = f(o), h = l ? { ...d, children: d.children.filter(y) } : d;
|
|
365
|
+
return o.themes.map(f).reduce(
|
|
366
|
+
(p, j) => (p.push(e(j, n)), p),
|
|
367
|
+
[t(":root", h, n)]
|
|
361
368
|
// Default theme (root)
|
|
362
369
|
).join(`
|
|
363
370
|
|
|
@@ -366,65 +373,66 @@ function Se(e) {
|
|
|
366
373
|
}
|
|
367
374
|
function Ce(e) {
|
|
368
375
|
const t = C(e);
|
|
369
|
-
return function(
|
|
370
|
-
return t(
|
|
376
|
+
return function(o, n) {
|
|
377
|
+
return t(o.query, o, n);
|
|
371
378
|
};
|
|
372
379
|
}
|
|
373
380
|
function ve(e) {
|
|
374
381
|
const t = C(e);
|
|
375
|
-
return function(
|
|
376
|
-
const
|
|
377
|
-
return t(
|
|
382
|
+
return function(o, n) {
|
|
383
|
+
const c = (n.themes?.selector ?? Y)({ name: o.name });
|
|
384
|
+
return t(c, o, n);
|
|
378
385
|
};
|
|
379
386
|
}
|
|
380
387
|
function $e(e) {
|
|
381
388
|
const t = C(e);
|
|
382
|
-
return function(
|
|
383
|
-
const
|
|
384
|
-
name:
|
|
385
|
-
value:
|
|
386
|
-
modifiers:
|
|
387
|
-
}),
|
|
388
|
-
return
|
|
389
|
+
return function(o, n) {
|
|
390
|
+
const i = [], a = (n.utilities?.selector ?? T)({
|
|
391
|
+
name: o.name,
|
|
392
|
+
value: o.value,
|
|
393
|
+
modifiers: o.modifiers
|
|
394
|
+
}), s = J(a);
|
|
395
|
+
return i.push(t(s, o, n)), i.join(`
|
|
389
396
|
|
|
390
397
|
`);
|
|
391
398
|
};
|
|
392
399
|
}
|
|
393
|
-
function
|
|
394
|
-
const
|
|
400
|
+
function b(e, t, r) {
|
|
401
|
+
const o = Se(b), n = Ce(b), i = $e(b), c = he(b), a = ve(b), s = k(b), u = Ae(b), f = be(b), l = ge();
|
|
395
402
|
switch (!0) {
|
|
396
403
|
case S(e):
|
|
397
404
|
return n(e, t);
|
|
405
|
+
case z(e):
|
|
406
|
+
return i(e, t);
|
|
398
407
|
case q(e):
|
|
399
|
-
return o(e, t);
|
|
400
|
-
case K(e):
|
|
401
408
|
return c(e, t);
|
|
402
|
-
case
|
|
403
|
-
return
|
|
404
|
-
case
|
|
405
|
-
return s(e, t);
|
|
406
|
-
case k(e):
|
|
409
|
+
case O(e):
|
|
410
|
+
return o(e, t, r);
|
|
411
|
+
case Q(e):
|
|
407
412
|
return a(e, t);
|
|
408
413
|
case V(e):
|
|
414
|
+
return s(e, t);
|
|
415
|
+
case K(e):
|
|
409
416
|
return u(e, t);
|
|
410
|
-
case
|
|
411
|
-
return i(e, t);
|
|
412
|
-
default:
|
|
417
|
+
case H(e):
|
|
413
418
|
return f(e, t);
|
|
419
|
+
default:
|
|
420
|
+
return l(e, t);
|
|
414
421
|
}
|
|
415
422
|
}
|
|
416
423
|
function je(e) {
|
|
417
|
-
return function(r,
|
|
418
|
-
let
|
|
419
|
-
|
|
420
|
-
const
|
|
421
|
-
return `const ${
|
|
422
|
-
|
|
424
|
+
return function(r, o) {
|
|
425
|
+
let n = r._exportName;
|
|
426
|
+
n || (n = D(r.name), r.name[0] && F(r.name[0]) && (n = $(n)));
|
|
427
|
+
const i = `${n}Recipe`, c = r._runtime ?? {}, a = `${$(n)}Props`;
|
|
428
|
+
return `const ${i} = ${JSON.stringify(
|
|
429
|
+
c,
|
|
423
430
|
null,
|
|
424
431
|
4
|
|
425
432
|
)} as const satisfies RecipeRuntime;
|
|
426
433
|
|
|
427
|
-
export
|
|
434
|
+
export type ${a} = RecipeVariantProps<typeof ${i}>;
|
|
435
|
+
export const ${n} = createRecipe("${r.name}", ${i});
|
|
428
436
|
`;
|
|
429
437
|
};
|
|
430
438
|
}
|
|
@@ -434,40 +442,40 @@ function Re(e) {
|
|
|
434
442
|
);
|
|
435
443
|
}
|
|
436
444
|
function Ne(e) {
|
|
437
|
-
return function(r,
|
|
438
|
-
const
|
|
439
|
-
if (!
|
|
445
|
+
return function(r, o) {
|
|
446
|
+
const n = Re(r.children), i = r.recipes.length > 0, c = n.length > 0;
|
|
447
|
+
if (!i && !c)
|
|
440
448
|
return "";
|
|
441
449
|
const a = [];
|
|
442
|
-
return
|
|
443
|
-
import type { RecipeRuntime } from '@styleframe/runtime';
|
|
444
|
-
`), a.push(e(r.recipes,
|
|
450
|
+
return i && (a.push(`import { createRecipe } from '@styleframe/runtime';
|
|
451
|
+
import type { RecipeRuntime, RecipeVariantProps } from '@styleframe/runtime';
|
|
452
|
+
`), a.push(e(r.recipes, o))), c && a.push(e(n, o)), a.join(`
|
|
445
453
|
`);
|
|
446
454
|
};
|
|
447
455
|
}
|
|
448
|
-
function
|
|
449
|
-
return function(r,
|
|
456
|
+
function xe(e) {
|
|
457
|
+
return function(r, o) {
|
|
450
458
|
return r._exportName ? `export const ${r._exportName} = ${JSON.stringify(r.query)};
|
|
451
459
|
` : "";
|
|
452
460
|
};
|
|
453
461
|
}
|
|
454
|
-
function
|
|
455
|
-
const r = Ne(
|
|
462
|
+
function N(e, t) {
|
|
463
|
+
const r = Ne(N), o = je(), n = xe();
|
|
456
464
|
switch (!0) {
|
|
457
465
|
case Array.isArray(e):
|
|
458
|
-
return e.map((
|
|
466
|
+
return e.map((i) => N(i, t)).join(`
|
|
459
467
|
`);
|
|
460
|
-
case
|
|
468
|
+
case O(e):
|
|
461
469
|
return r(e, t);
|
|
462
|
-
case
|
|
463
|
-
return n(e, t);
|
|
464
|
-
case S(e):
|
|
470
|
+
case w(e):
|
|
465
471
|
return o(e, t);
|
|
472
|
+
case S(e):
|
|
473
|
+
return n(e, t);
|
|
466
474
|
default:
|
|
467
475
|
return "";
|
|
468
476
|
}
|
|
469
477
|
}
|
|
470
|
-
const
|
|
478
|
+
const Oe = `-----BEGIN PUBLIC KEY-----
|
|
471
479
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAs7zAFssgxOMPeo80iig4
|
|
472
480
|
qSSshgNOLnW1gd4tPUrsezndaUrAKlsAys6XD8kuF+bBEIR0uFNSgKlqINLjWM1n
|
|
473
481
|
BiTUzCctodyRaq6/tyFSoPLD35iblkwtfxKPM42lAJZsyTu9qoBr8MJyXmhDLuqA
|
|
@@ -475,9 +483,9 @@ dQ8di7mQHz+mCy96jQR4lFSDfHMgl27qaAh5VboTBRxgZliN8D5Fl590QkS94wAj
|
|
|
475
483
|
hC7NbH+hPcGc/qIaZSjZfyZeBIZS74qJkrzjEA7/pukROD8UQUrQ512HHZ6XlgMn
|
|
476
484
|
4bWT2K9CpWbbhsKFTecCHuxlmPkFJNMuvAb/LdP08BSnpntlyAJcQeBrna2qBen+
|
|
477
485
|
GwIDAQAB
|
|
478
|
-
-----END PUBLIC KEY-----`,
|
|
479
|
-
async function
|
|
480
|
-
const t = e.replace(/-----BEGIN PUBLIC KEY-----/, "").replace(/-----END PUBLIC KEY-----/, "").replace(/\s/g, ""), r = Uint8Array.from(atob(t), (
|
|
486
|
+
-----END PUBLIC KEY-----`, _e = "__licenseRequired", we = "__licenseValidated";
|
|
487
|
+
async function Te(e) {
|
|
488
|
+
const t = e.replace(/-----BEGIN PUBLIC KEY-----/, "").replace(/-----END PUBLIC KEY-----/, "").replace(/\s/g, ""), r = Uint8Array.from(atob(t), (o) => o.charCodeAt(0));
|
|
481
489
|
return await crypto.subtle.importKey(
|
|
482
490
|
"spki",
|
|
483
491
|
r,
|
|
@@ -489,18 +497,18 @@ async function Be(e) {
|
|
|
489
497
|
["verify"]
|
|
490
498
|
);
|
|
491
499
|
}
|
|
492
|
-
async function
|
|
500
|
+
async function Be({
|
|
493
501
|
payload: e,
|
|
494
502
|
signature: t
|
|
495
503
|
}) {
|
|
496
|
-
const r = new TextEncoder().encode(e),
|
|
504
|
+
const r = new TextEncoder().encode(e), o = Uint8Array.from(
|
|
497
505
|
atob(t),
|
|
498
|
-
(
|
|
499
|
-
),
|
|
506
|
+
(i) => i.charCodeAt(0)
|
|
507
|
+
), n = await Te(Oe);
|
|
500
508
|
if (!await crypto.subtle.verify(
|
|
501
509
|
{ name: "RSASSA-PKCS1-v1_5" },
|
|
502
|
-
o,
|
|
503
510
|
n,
|
|
511
|
+
o,
|
|
504
512
|
r
|
|
505
513
|
))
|
|
506
514
|
throw new Error(
|
|
@@ -509,9 +517,9 @@ async function Te({
|
|
|
509
517
|
return JSON.parse(e);
|
|
510
518
|
}
|
|
511
519
|
function Ee(e) {
|
|
512
|
-
return Object.prototype.hasOwnProperty.call(e,
|
|
520
|
+
return Object.prototype.hasOwnProperty.call(e, _e);
|
|
513
521
|
}
|
|
514
|
-
async function
|
|
522
|
+
async function Fe(e) {
|
|
515
523
|
const t = Object.getOwnPropertyDescriptor(
|
|
516
524
|
e,
|
|
517
525
|
we
|
|
@@ -532,7 +540,7 @@ async function De(e) {
|
|
|
532
540
|
valid: !1
|
|
533
541
|
};
|
|
534
542
|
try {
|
|
535
|
-
return await
|
|
543
|
+
return await Be(
|
|
536
544
|
r
|
|
537
545
|
);
|
|
538
546
|
} catch {
|
|
@@ -544,37 +552,38 @@ async function De(e) {
|
|
|
544
552
|
};
|
|
545
553
|
}
|
|
546
554
|
}
|
|
547
|
-
function
|
|
555
|
+
function De(e) {
|
|
548
556
|
const t = e?.variants;
|
|
549
557
|
if (!t || Object.keys(t).length === 0)
|
|
550
558
|
return "Record<string, never>";
|
|
551
559
|
const r = [];
|
|
552
|
-
for (const [
|
|
553
|
-
if (!
|
|
554
|
-
const
|
|
555
|
-
if (
|
|
556
|
-
const
|
|
557
|
-
r.push(`${
|
|
560
|
+
for (const [o, n] of Object.entries(t)) {
|
|
561
|
+
if (!n) continue;
|
|
562
|
+
const i = Object.keys(n);
|
|
563
|
+
if (i.length > 0) {
|
|
564
|
+
const c = i.map((u) => `"${u}"`).join(" | "), s = i.includes("true") && i.includes("false") ? `${c} | boolean` : c;
|
|
565
|
+
r.push(`${o}?: ${s}`);
|
|
558
566
|
}
|
|
559
567
|
}
|
|
560
568
|
return r.length === 0 ? "Record<string, never>" : `{ ${r.join("; ")} }`;
|
|
561
569
|
}
|
|
562
|
-
function
|
|
563
|
-
return function(r,
|
|
564
|
-
let
|
|
565
|
-
|
|
566
|
-
const
|
|
567
|
-
return ` export
|
|
570
|
+
function Pe(e) {
|
|
571
|
+
return function(r, o) {
|
|
572
|
+
let n = r._exportName;
|
|
573
|
+
n || (n = D(r.name), r.name[0] && F(r.name[0]) && (n = $(n)));
|
|
574
|
+
const i = De(r._runtime), c = `${$(n)}Props`;
|
|
575
|
+
return ` export type ${c} = ${i};
|
|
576
|
+
export const ${n}: (props?: ${c}) => string;`;
|
|
568
577
|
};
|
|
569
578
|
}
|
|
570
|
-
function
|
|
579
|
+
function Ue(e) {
|
|
571
580
|
return e.filter(
|
|
572
581
|
(t) => S(t) && !!t._exportName
|
|
573
582
|
);
|
|
574
583
|
}
|
|
575
|
-
function
|
|
576
|
-
return function(r,
|
|
577
|
-
const
|
|
584
|
+
function ke(e) {
|
|
585
|
+
return function(r, o) {
|
|
586
|
+
const n = Ue(r.children), i = r.recipes.length > 0, c = n.length > 0, a = [
|
|
578
587
|
"// Auto-generated by @styleframe/plugin - DO NOT EDIT",
|
|
579
588
|
"",
|
|
580
589
|
'declare module "virtual:styleframe" {',
|
|
@@ -583,42 +592,42 @@ function Pe(e) {
|
|
|
583
592
|
" /** Returns the global styleframe instance from styleframe.config.ts */",
|
|
584
593
|
" export function styleframe(): Styleframe;"
|
|
585
594
|
];
|
|
586
|
-
if (
|
|
595
|
+
if (i) {
|
|
587
596
|
a.push("");
|
|
588
|
-
const
|
|
589
|
-
a.push(...
|
|
597
|
+
const s = r.recipes.map((u) => e(u, o)).filter(Boolean);
|
|
598
|
+
a.push(...s);
|
|
590
599
|
}
|
|
591
|
-
if (
|
|
600
|
+
if (c) {
|
|
592
601
|
a.push("");
|
|
593
|
-
const
|
|
594
|
-
a.push(...
|
|
602
|
+
const s = n.map((u) => e(u, o)).filter(Boolean);
|
|
603
|
+
a.push(...s);
|
|
595
604
|
}
|
|
596
605
|
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(`
|
|
597
606
|
`);
|
|
598
607
|
};
|
|
599
608
|
}
|
|
600
|
-
function
|
|
601
|
-
return function(r,
|
|
609
|
+
function Le(e) {
|
|
610
|
+
return function(r, o) {
|
|
602
611
|
return r._exportName ? ` export const ${r._exportName}: string;` : "";
|
|
603
612
|
};
|
|
604
613
|
}
|
|
605
|
-
function
|
|
606
|
-
const r =
|
|
614
|
+
function x(e, t) {
|
|
615
|
+
const r = ke(x), o = Pe(), n = Le();
|
|
607
616
|
switch (!0) {
|
|
608
617
|
case Array.isArray(e):
|
|
609
|
-
return e.map((
|
|
618
|
+
return e.map((i) => x(i, t)).join(`
|
|
610
619
|
`);
|
|
611
|
-
case
|
|
620
|
+
case O(e):
|
|
612
621
|
return r(e, t);
|
|
613
|
-
case
|
|
614
|
-
return n(e, t);
|
|
615
|
-
case S(e):
|
|
622
|
+
case w(e):
|
|
616
623
|
return o(e, t);
|
|
624
|
+
case S(e):
|
|
625
|
+
return n(e, t);
|
|
617
626
|
default:
|
|
618
627
|
return "";
|
|
619
628
|
}
|
|
620
629
|
}
|
|
621
|
-
function
|
|
630
|
+
function Ie(e) {
|
|
622
631
|
const t = Math.floor(Math.random() * 100);
|
|
623
632
|
e.root.children.push({
|
|
624
633
|
type: "selector",
|
|
@@ -643,7 +652,7 @@ function Me(e) {
|
|
|
643
652
|
}
|
|
644
653
|
});
|
|
645
654
|
}
|
|
646
|
-
function
|
|
655
|
+
function R(e, t = "") {
|
|
647
656
|
return {
|
|
648
657
|
name: e,
|
|
649
658
|
content: t
|
|
@@ -651,50 +660,52 @@ function $(e, t = "") {
|
|
|
651
660
|
}
|
|
652
661
|
async function Ve(e, {
|
|
653
662
|
type: t = "all",
|
|
654
|
-
|
|
663
|
+
treeshake: r = !1,
|
|
664
|
+
scanner: o = !1,
|
|
665
|
+
consumers: n = { css: b, ts: N, dts: x }
|
|
655
666
|
} = {}) {
|
|
656
|
-
const
|
|
667
|
+
const i = { files: [] }, c = e.options, a = { treeshake: r, scanner: o };
|
|
657
668
|
if (Ee(e)) {
|
|
658
|
-
const
|
|
659
|
-
(!
|
|
669
|
+
const s = await Fe(e);
|
|
670
|
+
(!s.valid || s.instanceId !== e.id) && Ie(e);
|
|
660
671
|
}
|
|
661
672
|
if (t === "all" || t === "css") {
|
|
662
|
-
const
|
|
673
|
+
const s = R(
|
|
663
674
|
"index.css",
|
|
664
|
-
|
|
675
|
+
n.css(e.root, c, a)
|
|
665
676
|
);
|
|
666
|
-
|
|
677
|
+
i.files.push(s);
|
|
667
678
|
}
|
|
668
679
|
if (t === "all" || t === "ts") {
|
|
669
|
-
const
|
|
680
|
+
const s = R(
|
|
670
681
|
"index.ts",
|
|
671
|
-
|
|
682
|
+
n.ts(e.root, c)
|
|
672
683
|
);
|
|
673
|
-
|
|
684
|
+
i.files.push(s);
|
|
674
685
|
}
|
|
675
686
|
if (t === "dts") {
|
|
676
|
-
const
|
|
687
|
+
const s = R(
|
|
677
688
|
"index.d.ts",
|
|
678
|
-
|
|
689
|
+
n.dts(e.root, c)
|
|
679
690
|
);
|
|
680
|
-
|
|
691
|
+
i.files.push(s);
|
|
681
692
|
}
|
|
682
|
-
return
|
|
693
|
+
return i;
|
|
683
694
|
}
|
|
684
695
|
export {
|
|
685
|
-
|
|
686
|
-
|
|
696
|
+
Me as DEFAULT_INDENT,
|
|
697
|
+
L as STATEMENT_AT_RULES,
|
|
687
698
|
I as STATEMENT_OR_BLOCK_AT_RULES,
|
|
688
699
|
ie as addIndentToLine,
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
700
|
+
b as consumeCSS,
|
|
701
|
+
N as consumeTS,
|
|
702
|
+
R as createFile,
|
|
692
703
|
Y as defaultThemeSelectorFn,
|
|
693
|
-
|
|
694
|
-
|
|
704
|
+
T as defaultUtilitySelectorFn,
|
|
705
|
+
B as defaultVariableNameFn,
|
|
695
706
|
ae as indentLines,
|
|
696
|
-
|
|
697
|
-
|
|
707
|
+
F as isUppercase,
|
|
708
|
+
D as toCamelCase,
|
|
698
709
|
le as toKebabCase,
|
|
699
710
|
Ve as transpile
|
|
700
711
|
};
|
package/dist/transpiler.umd.cjs
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
(function(p
|
|
2
|
-
`).map(t=>
|
|
3
|
-
`)}function
|
|
4
|
-
`:""}${e.map(t=>`${
|
|
5
|
-
`).join("")}}`}function
|
|
1
|
+
(function(p,$){typeof exports=="object"&&typeof module<"u"?$(exports):typeof define=="function"&&define.amd?define(["exports"],$):(p=typeof globalThis<"u"?globalThis:p||self,$(p.transpiler={}))})(this,(function(p){"use strict";const L=["charset","import","namespace"],U=["layer"];function Q(e){return typeof e=="object"&&e!==null}function S(e,t){return Q(e)&&"type"in e&&e.type===t}function J(e){return S(e,"variable")}function Z(e){return S(e,"reference")}function C(e){return S(e,"selector")}function W(e){return S(e,"at-rule")}function G(e){return S(e,"utility")}function Y(e){return S(e,"css")}function X(e){return S(e,"theme")}function _(e){return S(e,"root")}function P(e){return S(e,"recipe")}const E=({name:e,value:t,modifiers:r})=>`_${[...r,e,...t==="default"?[]:[t]].filter(Boolean).join(":")}`;function j(e){return e.charAt(0).toUpperCase()+e.slice(1)}function ee(e){return`.${e.replace(/[[\].#()%,:/]/g,"\\$&")}`}function A(e){if(e instanceof Buffer)return Buffer.from(e);const t=e.constructor;return new t(e.buffer.slice(0),e.byteOffset,e.byteLength/e.BYTES_PER_ELEMENT||1)}function te(e){if(e=e||{},e.circular)return re(e);const t=new Map;if(t.set(Date,s=>new Date(s)),t.set(Map,(s,a)=>new Map(o(Array.from(s),a))),t.set(Set,(s,a)=>new Set(o(Array.from(s),a))),e.constructorHandlers)for(const s of e.constructorHandlers)t.set(s[0],s[1]);let r;return e.proto?i:n;function o(s,a){const c=Object.keys(s),u=Array.from({length:c.length});for(let f=0;f<c.length;f++){const l=c[f],m=s[l];typeof m!="object"||m===null?u[l]=m:m.constructor!==Object&&(r=t.get(m.constructor))?u[l]=r(m,a):ArrayBuffer.isView(m)?u[l]=A(m):u[l]=a(m)}return u}function n(s){if(typeof s!="object"||s===null)return s;if(Array.isArray(s))return o(s,n);if(s.constructor!==Object&&(r=t.get(s.constructor)))return r(s,n);const a={};for(const c in s){if(Object.hasOwnProperty.call(s,c)===!1)continue;const u=s[c];typeof u!="object"||u===null?a[c]=u:u.constructor!==Object&&(r=t.get(u.constructor))?a[c]=r(u,n):ArrayBuffer.isView(u)?a[c]=A(u):a[c]=n(u)}return a}function i(s){if(typeof s!="object"||s===null)return s;if(Array.isArray(s))return o(s,i);if(s.constructor!==Object&&(r=t.get(s.constructor)))return r(s,i);const a={};for(const c in s){const u=s[c];typeof u!="object"||u===null?a[c]=u:u.constructor!==Object&&(r=t.get(u.constructor))?a[c]=r(u,i):ArrayBuffer.isView(u)?a[c]=A(u):a[c]=i(u)}return a}}function re(e){const t=[],r=[],o=new Map;if(o.set(Date,c=>new Date(c)),o.set(Map,(c,u)=>new Map(i(Array.from(c),u))),o.set(Set,(c,u)=>new Set(i(Array.from(c),u))),e.constructorHandlers)for(const c of e.constructorHandlers)o.set(c[0],c[1]);let n;return e.proto?a:s;function i(c,u){const f=Object.keys(c),l=Array.from({length:f.length});for(let m=0;m<f.length;m++){const h=f[m],y=c[h];if(typeof y!="object"||y===null)l[h]=y;else if(y.constructor!==Object&&(n=o.get(y.constructor)))l[h]=n(y,u);else if(ArrayBuffer.isView(y))l[h]=A(y);else{const g=t.indexOf(y);g!==-1?l[h]=r[g]:l[h]=u(y)}}return l}function s(c){if(typeof c!="object"||c===null)return c;if(Array.isArray(c))return i(c,s);if(c.constructor!==Object&&(n=o.get(c.constructor)))return n(c,s);const u={};t.push(c),r.push(u);for(const f in c){if(Object.hasOwnProperty.call(c,f)===!1)continue;const l=c[f];if(typeof l!="object"||l===null)u[f]=l;else if(l.constructor!==Object&&(n=o.get(l.constructor)))u[f]=n(l,s);else if(ArrayBuffer.isView(l))u[f]=A(l);else{const m=t.indexOf(l);m!==-1?u[f]=r[m]:u[f]=s(l)}}return t.pop(),r.pop(),u}function a(c){if(typeof c!="object"||c===null)return c;if(Array.isArray(c))return i(c,a);if(c.constructor!==Object&&(n=o.get(c.constructor)))return n(c,a);const u={};t.push(c),r.push(u);for(const f in c){const l=c[f];if(typeof l!="object"||l===null)u[f]=l;else if(l.constructor!==Object&&(n=o.get(l.constructor)))u[f]=n(l,a);else if(ArrayBuffer.isView(l))u[f]=A(l);else{const m=t.indexOf(l);m!==-1?u[f]=r[m]:u[f]=a(l)}}return t.pop(),r.pop(),u}}te();function ne(e,t=8){const r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";let o="";for(let n=0;n<t;n++){const i=Math.floor(Math.random()*r.length);o+=r[i]}return e?`${e}${o}`:o}const I=({name:e})=>`.${e}-theme, [data-theme="${e}"]`,O=({name:e})=>e.replace(/^\.+|\.+$/g,"").replace(/\.+/g,"--");function oe(e,t){return`@${e}${t?" ":""}${t}`}const ce=/\d/,se=["-","_","/","."];function ue(e=""){if(!ce.test(e))return e!==e.toLowerCase()}function k(e,t){const r=se,o=[];if(!e||typeof e!="string")return o;let n="",i,s;for(const a of e){const c=r.includes(a);if(c===!0){o.push(n),n="",i=void 0;continue}const u=ue(a);if(s===!1){if(i===!1&&u===!0){o.push(n),n=a,i=u;continue}if(i===!0&&u===!1&&n.length>1){const f=n.at(-1);o.push(n.slice(0,Math.max(0,n.length-1))),n=f+a,i=u;continue}}n+=a,i=u,s=c}return o.push(n),o}function ie(e){return e?e[0].toUpperCase()+e.slice(1):""}function ae(e){return e?e[0].toLowerCase()+e.slice(1):""}function le(e,t){return e?(Array.isArray(e)?e:k(e)).map(r=>ie(r)).join(""):""}function fe(e,t){return ae(le(e||""))}function me(e,t){return e?(Array.isArray(e)?e:k(e)).map(r=>r.toLowerCase()).join("-"):""}function x(e){return` ${e}`}function M(e){return e.split(`
|
|
2
|
+
`).map(t=>x(t)).join(`
|
|
3
|
+
`)}function F(e){return e===e.toUpperCase()}function w(e){return fe(e)}function V(e){return me(e)}function pe(e){return V(e)}function K(e,t){return`${e.startsWith("--")?e:pe(e)}: ${t};`}function de(e){return`{${e.length>0?`
|
|
4
|
+
`:""}${e.map(t=>`${M(`${t}`)}
|
|
5
|
+
`).join("")}}`}function q(e){return`--${(e.startsWith("--")?e.slice(2):e).replace(/[^a-zA-Z0-9_\-\u0080-\uFFFF]/g,"-")||"unknown-variable"}`}function ye(e,t){return K(q(e),t)}function he(e,t){return`var(${q(e)}${t?`, ${t}`:""})`}function z(e,t){return`${e} ${de(t)}`}function be(e){return function(r,o){return Object.entries(r).map(([n,i])=>K(n,e(i,o)))}}function H(e){return function(r,o){const i=(o.variables?.name??O)({name:r.name});return ye(i,e(r.value,o))}}function v(e){const t=H(e),r=be(e);return function(n,i,s){const{variables:a,declarations:c,children:u}=i,f=n===":root",l=(a??[]).map(d=>t(d,s)),m=r(c??{},s),h=(u??[]).map(d=>e(d,s)),y=l.length>0,g=m.length>0,N=h.length>0;return f?`${y||g?z(n,[...l,...y&&g?[""]:[],...m]):""}${N&&(y||g)?`
|
|
6
6
|
|
|
7
|
-
`:""}${
|
|
7
|
+
`:""}${h.join(`
|
|
8
8
|
|
|
9
|
-
`)}`:
|
|
9
|
+
`)}`:z(n,[...l,...y&&(N||g)?[""]:[],...m,...g&&N?[""]:[],...h.flatMap((d,D)=>D===h.length-1?[d]:[d,""])])}}function ge(e){const t=v(e);return function(o,n){const i=L.includes(o.identifier),s=U.includes(o.identifier),a=Object.keys(o.declarations).length>0,c=o.variables.length>0,u=o.children.length>0,f=oe(o.identifier,o.rule);return i||s&&!(a||c||u)?`${f};`:t(f,o,n)}}function Se(e){return function(r,o){return r.value.map(n=>e(n,o)).join("").trim()}}function Ae(e){return function(r,o){return r!=null?`${r}`:""}}function Ce(e){return function(r,o){const i=(o.variables?.name??O)({name:r.name});return he(i,r.fallback?e(r.fallback,o):void 0)}}function ve(e){const t=v(e);return function(o,n,i){const s=i?.treeshake??!1,a=i?.scanner??!1,c=o._usage.variables,u=d=>!s||c.has(d.name),f=d=>s?{...d,variables:d.variables.filter(u)}:d,l=s&&a,m=o._usage.utilities,h=d=>d.type!=="utility"||!l?!0:m.has(E({name:d.name,value:d.value,modifiers:d.modifiers})),y=f(o),g=l?{...y,children:y.children.filter(h)}:y;return o.themes.map(f).reduce((d,D)=>(d.push(e(D,n)),d),[t(":root",g,n)]).join(`
|
|
10
10
|
|
|
11
|
-
`)}}function
|
|
11
|
+
`)}}function $e(e){const t=v(e);return function(o,n){return t(o.query,o,n)}}function je(e){const t=v(e);return function(o,n){const s=(n.themes?.selector??I)({name:o.name});return t(s,o,n)}}function Re(e){const t=v(e);return function(o,n){const i=[],a=(n.utilities?.selector??E)({name:o.name,value:o.value,modifiers:o.modifiers}),c=ee(a);return i.push(t(c,o,n)),i.join(`
|
|
12
12
|
|
|
13
|
-
`)}}function
|
|
13
|
+
`)}}function b(e,t,r){const o=ve(b),n=$e(b),i=Re(b),s=ge(b),a=je(b),c=H(b),u=Ce(b),f=Se(b),l=Ae();switch(!0){case C(e):return n(e,t);case G(e):return i(e,t);case W(e):return s(e,t);case _(e):return o(e,t,r);case X(e):return a(e,t);case J(e):return c(e,t);case Z(e):return u(e,t);case Y(e):return f(e,t);default:return l(e,t)}}function Te(e){return function(r,o){let n=r._exportName;n||(n=w(r.name),r.name[0]&&F(r.name[0])&&(n=j(n)));const i=`${n}Recipe`,s=r._runtime??{},a=`${j(n)}Props`;return`const ${i} = ${JSON.stringify(s,null,4)} as const satisfies RecipeRuntime;
|
|
14
14
|
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
`)
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
export type ${a} = RecipeVariantProps<typeof ${i}>;
|
|
16
|
+
export const ${n} = createRecipe("${r.name}", ${i});
|
|
17
|
+
`}}function Ne(e){return e.filter(t=>C(t)&&!!t._exportName)}function _e(e){return function(r,o){const n=Ne(r.children),i=r.recipes.length>0,s=n.length>0;if(!i&&!s)return"";const a=[];return i&&(a.push(`import { createRecipe } from '@styleframe/runtime';
|
|
18
|
+
import type { RecipeRuntime, RecipeVariantProps } from '@styleframe/runtime';
|
|
19
|
+
`),a.push(e(r.recipes,o))),s&&a.push(e(n,o)),a.join(`
|
|
20
|
+
`)}}function Ee(e){return function(r,o){return r._exportName?`export const ${r._exportName} = ${JSON.stringify(r.query)};
|
|
21
|
+
`:""}}function R(e,t){const r=_e(R),o=Te(),n=Ee();switch(!0){case Array.isArray(e):return e.map(i=>R(i,t)).join(`
|
|
22
|
+
`);case _(e):return r(e,t);case P(e):return o(e,t);case C(e):return n(e,t);default:return""}}const Oe=`-----BEGIN PUBLIC KEY-----
|
|
22
23
|
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAs7zAFssgxOMPeo80iig4
|
|
23
24
|
qSSshgNOLnW1gd4tPUrsezndaUrAKlsAys6XD8kuF+bBEIR0uFNSgKlqINLjWM1n
|
|
24
25
|
BiTUzCctodyRaq6/tyFSoPLD35iblkwtfxKPM42lAJZsyTu9qoBr8MJyXmhDLuqA
|
|
@@ -26,6 +27,7 @@ dQ8di7mQHz+mCy96jQR4lFSDfHMgl27qaAh5VboTBRxgZliN8D5Fl590QkS94wAj
|
|
|
26
27
|
hC7NbH+hPcGc/qIaZSjZfyZeBIZS74qJkrzjEA7/pukROD8UQUrQ512HHZ6XlgMn
|
|
27
28
|
4bWT2K9CpWbbhsKFTecCHuxlmPkFJNMuvAb/LdP08BSnpntlyAJcQeBrna2qBen+
|
|
28
29
|
GwIDAQAB
|
|
29
|
-
-----END PUBLIC KEY-----`,
|
|
30
|
-
|
|
31
|
-
`)
|
|
30
|
+
-----END PUBLIC KEY-----`,Fe="__licenseRequired",we="__licenseValidated";async function Be(e){const t=e.replace(/-----BEGIN PUBLIC KEY-----/,"").replace(/-----END PUBLIC KEY-----/,"").replace(/\s/g,""),r=Uint8Array.from(atob(t),o=>o.charCodeAt(0));return await crypto.subtle.importKey("spki",r,{name:"RSASSA-PKCS1-v1_5",hash:"SHA-256"},!0,["verify"])}async function De({payload:e,signature:t}){const r=new TextEncoder().encode(e),o=Uint8Array.from(atob(t),i=>i.charCodeAt(0)),n=await Be(Oe);if(!await crypto.subtle.verify({name:"RSASSA-PKCS1-v1_5"},n,o,r))throw new Error("License validation failed: Invalid signature detected. The license may have been modified or corrupted.");return JSON.parse(e)}function Le(e){return Object.prototype.hasOwnProperty.call(e,Fe)}async function Ue(e){const t=Object.getOwnPropertyDescriptor(e,we);if(!t?.value)return{key:"",instanceId:"",environment:"",valid:!1};const r=t.value;if(typeof r!="object"||r===null||!("payload"in r)||!("signature"in r)||typeof r.payload!="string"||typeof r.signature!="string")return{key:"",instanceId:"",environment:"",valid:!1};try{return await De(r)}catch{return{key:"",instanceId:"",environment:"",valid:!1}}}function Pe(e){const t=e?.variants;if(!t||Object.keys(t).length===0)return"Record<string, never>";const r=[];for(const[o,n]of Object.entries(t)){if(!n)continue;const i=Object.keys(n);if(i.length>0){const s=i.map(u=>`"${u}"`).join(" | "),c=i.includes("true")&&i.includes("false")?`${s} | boolean`:s;r.push(`${o}?: ${c}`)}}return r.length===0?"Record<string, never>":`{ ${r.join("; ")} }`}function Ie(e){return function(r,o){let n=r._exportName;n||(n=w(r.name),r.name[0]&&F(r.name[0])&&(n=j(n)));const i=Pe(r._runtime),s=`${j(n)}Props`;return` export type ${s} = ${i};
|
|
31
|
+
export const ${n}: (props?: ${s}) => string;`}}function ke(e){return e.filter(t=>C(t)&&!!t._exportName)}function xe(e){return function(r,o){const n=ke(r.children),i=r.recipes.length>0,s=n.length>0,a=["// Auto-generated by @styleframe/plugin - DO NOT EDIT","",'declare module "virtual:styleframe" {',' import type { Styleframe } from "@styleframe/core";',""," /** Returns the global styleframe instance from styleframe.config.ts */"," export function styleframe(): Styleframe;"];if(i){a.push("");const c=r.recipes.map(u=>e(u,o)).filter(Boolean);a.push(...c)}if(s){a.push("");const c=n.map(u=>e(u,o)).filter(Boolean);a.push(...c)}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(`
|
|
32
|
+
`)}}function Me(e){return function(r,o){return r._exportName?` export const ${r._exportName}: string;`:""}}function B(e,t){const r=xe(B),o=Ie(),n=Me();switch(!0){case Array.isArray(e):return e.map(i=>B(i,t)).join(`
|
|
33
|
+
`);case _(e):return r(e,t);case P(e):return o(e,t);case C(e):return n(e,t);default:return""}}function Ve(e){const t=Math.floor(Math.random()*100);e.root.children.push({type:"selector",id:ne("sel-"),query:`html:nth-of-type(${t}n+1)::after`,variables:[],children:[],declarations:{content:'"Styleframe Pro: Development Mode – License required for production use"',zIndex:99999,position:"fixed",display:"block !important",opacity:"1 !important",bottom:0,left:0,background:"rgba(0, 0, 0, 0.5)",color:"white",fontSize:"12px",lineHeight:"1",padding:"0.5rem",fontFamily:"sans-serif"}})}function T(e,t=""){return{name:e,content:t}}async function Ke(e,{type:t="all",treeshake:r=!1,scanner:o=!1,consumers:n={css:b,ts:R,dts:B}}={}){const i={files:[]},s=e.options,a={treeshake:r,scanner:o};if(Le(e)){const c=await Ue(e);(!c.valid||c.instanceId!==e.id)&&Ve(e)}if(t==="all"||t==="css"){const c=T("index.css",n.css(e.root,s,a));i.files.push(c)}if(t==="all"||t==="ts"){const c=T("index.ts",n.ts(e.root,s));i.files.push(c)}if(t==="dts"){const c=T("index.d.ts",n.dts(e.root,s));i.files.push(c)}return i}p.DEFAULT_INDENT=" ",p.STATEMENT_AT_RULES=L,p.STATEMENT_OR_BLOCK_AT_RULES=U,p.addIndentToLine=x,p.consumeCSS=b,p.consumeTS=R,p.createFile=T,p.defaultThemeSelectorFn=I,p.defaultUtilitySelectorFn=E,p.defaultVariableNameFn=O,p.indentLines=M,p.isUppercase=F,p.toCamelCase=w,p.toKebabCase=V,p.transpile=Ke,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@styleframe/transpiler",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./dist/transpiler.d.ts",
|
|
6
6
|
"module": "./dist/transpiler.js",
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
"scule": "^1.3.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@styleframe/core": "^3.
|
|
25
|
+
"@styleframe/core": "^3.5.0",
|
|
26
26
|
"@styleframe/license": "^2.0.2"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@styleframe/config-typescript": "^3.0.0",
|
|
30
30
|
"@styleframe/config-vite": "^3.0.0",
|
|
31
|
-
"@styleframe/core": "^3.
|
|
31
|
+
"@styleframe/core": "^3.5.0",
|
|
32
32
|
"@styleframe/license": "^2.0.2",
|
|
33
33
|
"@vitest/coverage-v8": "^3.2.4",
|
|
34
34
|
"typescript": "^5.8.3",
|