@styleframe/transpiler 1.0.1 → 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.
Files changed (61) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE +21 -0
  3. package/dist/transpiler.d.ts +120 -0
  4. package/dist/transpiler.js +432 -0
  5. package/dist/transpiler.umd.cjs +14 -0
  6. package/package.json +14 -4
  7. package/.tsbuildinfo +0 -1
  8. package/src/constants.ts +0 -4
  9. package/src/consume/at-rule.test.ts +0 -339
  10. package/src/consume/at-rule.ts +0 -34
  11. package/src/consume/consume.test.ts +0 -259
  12. package/src/consume/consume.ts +0 -60
  13. package/src/consume/container.test.ts +0 -501
  14. package/src/consume/container.ts +0 -73
  15. package/src/consume/css.test.ts +0 -184
  16. package/src/consume/css.ts +0 -17
  17. package/src/consume/declarations.test.ts +0 -210
  18. package/src/consume/declarations.ts +0 -17
  19. package/src/consume/index.ts +0 -12
  20. package/src/consume/primitive.test.ts +0 -52
  21. package/src/consume/primitive.ts +0 -16
  22. package/src/consume/ref.test.ts +0 -84
  23. package/src/consume/ref.ts +0 -22
  24. package/src/consume/root.test.ts +0 -353
  25. package/src/consume/root.ts +0 -19
  26. package/src/consume/selector.test.ts +0 -441
  27. package/src/consume/selector.ts +0 -17
  28. package/src/consume/theme.test.ts +0 -215
  29. package/src/consume/theme.ts +0 -15
  30. package/src/consume/utility.test.ts +0 -696
  31. package/src/consume/utility.ts +0 -31
  32. package/src/consume/variable.test.ts +0 -197
  33. package/src/consume/variable.ts +0 -20
  34. package/src/defaults.ts +0 -21
  35. package/src/generator/genAtRuleQuery.test.ts +0 -148
  36. package/src/generator/genAtRuleQuery.ts +0 -3
  37. package/src/generator/genDeclaration.test.ts +0 -283
  38. package/src/generator/genDeclaration.ts +0 -9
  39. package/src/generator/genDeclarationsBlock.test.ts +0 -278
  40. package/src/generator/genDeclarationsBlock.ts +0 -7
  41. package/src/generator/genDeclareVariable.test.ts +0 -323
  42. package/src/generator/genDeclareVariable.ts +0 -6
  43. package/src/generator/genInlineAtRule.test.ts +0 -351
  44. package/src/generator/genInlineAtRule.ts +0 -5
  45. package/src/generator/genReferenceVariable.test.ts +0 -392
  46. package/src/generator/genReferenceVariable.ts +0 -5
  47. package/src/generator/genSafePropertyName.test.ts +0 -489
  48. package/src/generator/genSafePropertyName.ts +0 -5
  49. package/src/generator/genSafeVariableName.test.ts +0 -358
  50. package/src/generator/genSafeVariableName.ts +0 -21
  51. package/src/generator/genSelector.test.ts +0 -357
  52. package/src/generator/genSelector.ts +0 -5
  53. package/src/generator/index.ts +0 -9
  54. package/src/index.ts +0 -6
  55. package/src/transpile.test.ts +0 -825
  56. package/src/transpile.ts +0 -21
  57. package/src/types.ts +0 -15
  58. package/src/utils.ts +0 -18
  59. package/src/vite-env.d.ts +0 -1
  60. package/tsconfig.json +0 -7
  61. package/vite.config.ts +0 -5
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @styleframe/transpiler
2
2
 
3
+ ## 1.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#35](https://github.com/styleframe-dev/styleframe/pull/35) [`5d53569`](https://github.com/styleframe-dev/styleframe/commit/5d5356960af687884703f3de5d3d1638d8ee9d8a) Thanks [@alexgrozav](https://github.com/alexgrozav)! - fix: Update published files references in package.json
8
+
9
+ - Updated dependencies [[`5d53569`](https://github.com/styleframe-dev/styleframe/commit/5d5356960af687884703f3de5d3d1638d8ee9d8a)]:
10
+ - @styleframe/core@1.0.2
11
+
12
+ ## 1.0.2
13
+
14
+ ### Patch Changes
15
+
16
+ - [#30](https://github.com/styleframe-dev/styleframe/pull/30) [`68cd004`](https://github.com/styleframe-dev/styleframe/commit/68cd004b04395797876b5e805c0b910d6b665f35) Thanks [@alexgrozav](https://github.com/alexgrozav)! - feat: Add support for custom transpile functions
17
+ refactor: Separate CSS and TS transpilation
18
+
3
19
  ## 1.0.1
4
20
 
5
21
  ### Patch Changes
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Alex Grozav
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,120 @@
1
+ import { AtRule } from '@styleframe/core';
2
+ import { ContainerChild } from '@styleframe/core';
3
+ import { CSS as CSS_2 } from '@styleframe/core';
4
+ import { DeclarationsBlock } from '@styleframe/core';
5
+ import { KebabCase } from 'scule';
6
+ import { Reference } from '@styleframe/core';
7
+ import { Root } from '@styleframe/core';
8
+ import { Selector } from '@styleframe/core';
9
+ import { Styleframe } from '@styleframe/core';
10
+ import { StyleframeOptions } from '@styleframe/core';
11
+ import { Theme } from '@styleframe/core';
12
+ import { ThemeSelectorFn } from '@styleframe/core';
13
+ import { Utility } from '@styleframe/core';
14
+ import { UtilitySelectorFn } from '@styleframe/core';
15
+ import { Variable } from '@styleframe/core';
16
+ import { VariableNameFn } from '@styleframe/core';
17
+
18
+ export declare function addIndentToLine(line: string): string;
19
+
20
+ /**
21
+ * Consumes any token instance and returns the CSS string representation
22
+ */
23
+ export declare function consumeCSS(instance: unknown, options: StyleframeOptions): string;
24
+
25
+ export declare type ConsumeFunction = (instance: unknown, options: StyleframeOptions) => string;
26
+
27
+ /**
28
+ * Consumes any token instance and returns the TS string representation
29
+ */
30
+ export declare function consumeTS(instance: unknown, options: StyleframeOptions): string;
31
+
32
+ /**
33
+ * Consumes a generic at-rule instance, equivalent to setting a CSS at-rule
34
+ * such as @media, @supports, @keyframes, etc.
35
+ */
36
+ export declare function createAtRuleConsumer(consume: ConsumeFunction): (instance: AtRule, options: StyleframeOptions) => string;
37
+
38
+ /**
39
+ * Base function for consuming container-like structures (Selector, AtRule)
40
+ */
41
+ export declare function createContainerConsumer(consume: ConsumeFunction): (query: string, instance: {
42
+ variables?: Variable[];
43
+ declarations?: DeclarationsBlock;
44
+ children?: ContainerChild[];
45
+ }, options: StyleframeOptions) => string;
46
+
47
+ /**
48
+ * Consumes a CSS value, equivalent to the string body of a selector
49
+ */
50
+ export declare function createCSSTemplateLiteralConsumer(consume: ConsumeFunction): (instance: CSS_2, options: StyleframeOptions) => string;
51
+
52
+ /**
53
+ * Consumes a declarations block, equivalent to setting CSS properties
54
+ */
55
+ export declare function createDeclarationsConsumer(consume: ConsumeFunction): (instance: DeclarationsBlock, options: StyleframeOptions) => string[];
56
+
57
+ export declare function createFile(name: string, content?: string): OutputFile;
58
+
59
+ /**
60
+ * Consumes a primitive instance, equivalent to setting a CSS value
61
+ */
62
+ export declare function createPrimitiveConsumer(_consume: ConsumeFunction): (instance: unknown, _options: StyleframeOptions) => string;
63
+
64
+ /**
65
+ * Consumes a ref instance, equivalent to referencing a CSS variable with optional fallback
66
+ */
67
+ export declare function createRefConsumer(consume: ConsumeFunction): (instance: Reference, options: StyleframeOptions) => string;
68
+
69
+ export declare function createRootConsumer(consume: ConsumeFunction): (instance: Root, options: StyleframeOptions) => string;
70
+
71
+ /**
72
+ * Consumes a selector instance, equivalent to setting a CSS selector
73
+ */
74
+ export declare function createSelectorConsumer(consume: ConsumeFunction): (instance: Selector, options: StyleframeOptions) => string;
75
+
76
+ export declare function createThemeConsumer(consume: ConsumeFunction): (instance: Theme, options: StyleframeOptions) => string;
77
+
78
+ /**
79
+ * Consumes a utility instance, equivalent to setting a utility CSS selector
80
+ */
81
+ export declare function createUtilityConsumer(consume: ConsumeFunction): (instance: Utility, options: StyleframeOptions) => string;
82
+
83
+ export declare function createVariableConsumer(consume: ConsumeFunction): (instance: Variable, options: StyleframeOptions) => string;
84
+
85
+ export declare const DEFAULT_INDENT = "\t";
86
+
87
+ export declare const defaultThemeSelectorFn: ThemeSelectorFn;
88
+
89
+ export declare const defaultUtilitySelectorFn: UtilitySelectorFn;
90
+
91
+ export declare const defaultVariableNameFn: VariableNameFn;
92
+
93
+ export declare function indentLines(lines: string): string;
94
+
95
+ export declare type Output = {
96
+ files: OutputFile[];
97
+ };
98
+
99
+ export declare type OutputFile = {
100
+ name: string;
101
+ content: string;
102
+ };
103
+
104
+ export declare const STATEMENT_AT_RULES: string[];
105
+
106
+ export declare const STATEMENT_OR_BLOCK_AT_RULES: string[];
107
+
108
+ export declare function toKebabCase<S extends string>(str: S): KebabCase<S>;
109
+
110
+ export declare function transpile(instance: Styleframe, { type, consumers, }?: TranspileOptions): Output;
111
+
112
+ export declare type TranspileOptions = {
113
+ type?: "css" | "ts" | "all";
114
+ consumers?: {
115
+ css: ConsumeFunction;
116
+ ts: ConsumeFunction;
117
+ };
118
+ };
119
+
120
+ export { }
@@ -0,0 +1,432 @@
1
+ const pe = " ", N = ["charset", "import", "namespace"], E = ["layer"], V = ({ name: e }) => `[data-theme="${e}"]`, _ = ({
2
+ name: e,
3
+ value: t,
4
+ modifiers: s
5
+ }) => `._${[...s, e, t].filter(Boolean).join("\\:")}`, O = ({ name: e }) => e;
6
+ function D(e, t) {
7
+ return `@${e}${t ? " " : ""}${t}`;
8
+ }
9
+ const B = /\d/, L = ["-", "_", "/", "."];
10
+ function M(e = "") {
11
+ if (!B.test(e))
12
+ return e !== e.toLowerCase();
13
+ }
14
+ function U(e, t) {
15
+ const s = L, r = [];
16
+ if (!e || typeof e != "string")
17
+ return r;
18
+ let c = "", l, u;
19
+ for (const i of e) {
20
+ const n = s.includes(i);
21
+ if (n === !0) {
22
+ r.push(c), c = "", l = void 0;
23
+ continue;
24
+ }
25
+ const o = M(i);
26
+ if (u === !1) {
27
+ if (l === !1 && o === !0) {
28
+ r.push(c), c = i, l = o;
29
+ continue;
30
+ }
31
+ if (l === !0 && o === !1 && c.length > 1) {
32
+ const f = c.at(-1);
33
+ r.push(c.slice(0, Math.max(0, c.length - 1))), c = f + i, l = o;
34
+ continue;
35
+ }
36
+ }
37
+ c += i, l = o, u = n;
38
+ }
39
+ return r.push(c), r;
40
+ }
41
+ function P(e, t) {
42
+ return e ? (Array.isArray(e) ? e : U(e)).map((s) => s.toLowerCase()).join("-") : "";
43
+ }
44
+ function k(e) {
45
+ return ` ${e}`;
46
+ }
47
+ function x(e) {
48
+ return e.split(`
49
+ `).map((t) => k(t)).join(`
50
+ `);
51
+ }
52
+ function z(e) {
53
+ return P(e);
54
+ }
55
+ function H(e) {
56
+ return z(e);
57
+ }
58
+ function T(e, t) {
59
+ return `${e.startsWith("--") ? e : H(e)}: ${t};`;
60
+ }
61
+ function I(e) {
62
+ return `{${e.length > 0 ? `
63
+ ` : ""}${e.map((t) => `${x(`${t}`)}
64
+ `).join("")}}`;
65
+ }
66
+ function $(e) {
67
+ return `--${(e.startsWith("--") ? e.slice(2) : e).replace(/[^a-zA-Z0-9_\-\u0080-\uFFFF]/g, "-") || "unknown-variable"}`;
68
+ }
69
+ function K(e, t) {
70
+ return T($(e), t);
71
+ }
72
+ function Q(e, t) {
73
+ return `var(${$(e)}${t ? `, ${t}` : ""})`;
74
+ }
75
+ function C(e, t) {
76
+ return `${e} ${I(t)}`;
77
+ }
78
+ function W(e) {
79
+ return function(s, r) {
80
+ return Object.entries(s).map(([c, l]) => T(c, e(l, r)));
81
+ };
82
+ }
83
+ function w(e) {
84
+ return function(s, r) {
85
+ const l = (r.variables?.name ?? O)({ name: s.name });
86
+ return K(l, e(s.value, r));
87
+ };
88
+ }
89
+ function A(e) {
90
+ const t = w(e), s = W(e);
91
+ return function(c, l, u) {
92
+ const { variables: i, declarations: n, children: o } = l, f = c === ":root", a = (i ?? []).map(
93
+ (g) => t(g, u)
94
+ ), m = s(
95
+ n ?? {},
96
+ u
97
+ ), b = (o ?? []).map(
98
+ (g) => e(g, u)
99
+ ), p = a.length > 0, h = m.length > 0, S = b.length > 0;
100
+ return f ? `${p || h ? C(c, [
101
+ ...a,
102
+ ...p && h ? [""] : [],
103
+ ...m
104
+ ]) : ""}${S && (p || h) ? `
105
+
106
+ ` : ""}${b.join(`
107
+
108
+ `)}` : C(c, [
109
+ ...a,
110
+ ...p && (S || h) ? [""] : [],
111
+ ...m,
112
+ ...h && S ? [""] : [],
113
+ ...b.flatMap(
114
+ (g, F) => F === b.length - 1 ? [g] : [g, ""]
115
+ )
116
+ ]);
117
+ };
118
+ }
119
+ function Z(e) {
120
+ const t = A(e);
121
+ return function(r, c) {
122
+ const l = N.includes(r.identifier), u = E.includes(
123
+ r.identifier
124
+ ), i = Object.keys(r.declarations).length > 0, n = r.variables.length > 0, o = r.children.length > 0, f = D(r.identifier, r.rule);
125
+ return l || u && !(i || n || o) ? `${f};` : t(f, r, c);
126
+ };
127
+ }
128
+ function q(e) {
129
+ return typeof e == "object" && e !== null;
130
+ }
131
+ function d(e, t) {
132
+ return q(e) && "type" in e && e.type === t;
133
+ }
134
+ function G(e) {
135
+ return d(e, "variable");
136
+ }
137
+ function J(e) {
138
+ return d(e, "reference");
139
+ }
140
+ function Y(e) {
141
+ return d(e, "selector");
142
+ }
143
+ function X(e) {
144
+ return d(e, "at-rule");
145
+ }
146
+ function ee(e) {
147
+ return d(e, "utility");
148
+ }
149
+ function te(e) {
150
+ return d(e, "css");
151
+ }
152
+ function re(e) {
153
+ return d(e, "theme");
154
+ }
155
+ function ne(e) {
156
+ return d(e, "root");
157
+ }
158
+ function j(e) {
159
+ if (e instanceof Buffer)
160
+ return Buffer.from(e);
161
+ const t = e.constructor;
162
+ return new t(
163
+ e.buffer.slice(0),
164
+ e.byteOffset,
165
+ e.byteLength / e.BYTES_PER_ELEMENT || 1
166
+ );
167
+ }
168
+ function oe(e) {
169
+ if (e = e || {}, e.circular)
170
+ return ue(e);
171
+ const t = /* @__PURE__ */ new Map();
172
+ if (t.set(Date, (u) => new Date(u)), t.set(
173
+ Map,
174
+ (u, i) => new Map(r(Array.from(u), i))
175
+ ), t.set(
176
+ Set,
177
+ (u, i) => new Set(r(Array.from(u), i))
178
+ ), e.constructorHandlers)
179
+ for (const u of e.constructorHandlers)
180
+ t.set(u[0], u[1]);
181
+ let s;
182
+ return e.proto ? l : c;
183
+ function r(u, i) {
184
+ const n = Object.keys(u), o = Array.from({ length: n.length });
185
+ for (let f = 0; f < n.length; f++) {
186
+ const a = n[f], m = u[a];
187
+ typeof m != "object" || m === null ? o[a] = m : m.constructor !== Object && (s = t.get(m.constructor)) ? o[a] = s(m, i) : ArrayBuffer.isView(m) ? o[a] = j(m) : o[a] = i(m);
188
+ }
189
+ return o;
190
+ }
191
+ function c(u) {
192
+ if (typeof u != "object" || u === null) return u;
193
+ if (Array.isArray(u)) return r(u, c);
194
+ if (u.constructor !== Object && (s = t.get(u.constructor)))
195
+ return s(u, c);
196
+ const i = {};
197
+ for (const n in u) {
198
+ if (Object.hasOwnProperty.call(u, n) === !1) continue;
199
+ const o = u[n];
200
+ 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(o) : i[n] = c(o);
201
+ }
202
+ return i;
203
+ }
204
+ function l(u) {
205
+ if (typeof u != "object" || u === null) return u;
206
+ if (Array.isArray(u)) return r(u, l);
207
+ if (u.constructor !== Object && (s = t.get(u.constructor)))
208
+ return s(u, l);
209
+ const i = {};
210
+ for (const n in u) {
211
+ const o = u[n];
212
+ 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(o) : i[n] = l(o);
213
+ }
214
+ return i;
215
+ }
216
+ }
217
+ function ue(e) {
218
+ const t = [], s = [], r = /* @__PURE__ */ new Map();
219
+ if (r.set(Date, (n) => new Date(n)), r.set(
220
+ Map,
221
+ (n, o) => new Map(l(Array.from(n), o))
222
+ ), r.set(
223
+ Set,
224
+ (n, o) => new Set(l(Array.from(n), o))
225
+ ), e.constructorHandlers)
226
+ for (const n of e.constructorHandlers)
227
+ r.set(n[0], n[1]);
228
+ let c;
229
+ return e.proto ? i : u;
230
+ function l(n, o) {
231
+ const f = Object.keys(n), a = Array.from({ length: f.length });
232
+ for (let m = 0; m < f.length; m++) {
233
+ const b = f[m], p = n[b];
234
+ if (typeof p != "object" || p === null)
235
+ a[b] = p;
236
+ else if (p.constructor !== Object && (c = r.get(p.constructor)))
237
+ a[b] = c(p, o);
238
+ else if (ArrayBuffer.isView(p))
239
+ a[b] = j(p);
240
+ else {
241
+ const h = t.indexOf(p);
242
+ h !== -1 ? a[b] = s[h] : a[b] = o(p);
243
+ }
244
+ }
245
+ return a;
246
+ }
247
+ function u(n) {
248
+ if (typeof n != "object" || n === null) return n;
249
+ if (Array.isArray(n)) return l(n, u);
250
+ if (n.constructor !== Object && (c = r.get(n.constructor)))
251
+ return c(n, u);
252
+ const o = {};
253
+ t.push(n), s.push(o);
254
+ for (const f in n) {
255
+ if (Object.hasOwnProperty.call(n, f) === !1) continue;
256
+ const a = n[f];
257
+ if (typeof a != "object" || a === null)
258
+ o[f] = a;
259
+ else if (a.constructor !== Object && (c = r.get(a.constructor)))
260
+ o[f] = c(a, u);
261
+ else if (ArrayBuffer.isView(a))
262
+ o[f] = j(a);
263
+ else {
264
+ const m = t.indexOf(a);
265
+ m !== -1 ? o[f] = s[m] : o[f] = u(a);
266
+ }
267
+ }
268
+ return t.pop(), s.pop(), o;
269
+ }
270
+ function i(n) {
271
+ if (typeof n != "object" || n === null) return n;
272
+ if (Array.isArray(n)) return l(n, i);
273
+ if (n.constructor !== Object && (c = r.get(n.constructor)))
274
+ return c(n, i);
275
+ const o = {};
276
+ t.push(n), s.push(o);
277
+ for (const f in n) {
278
+ const a = n[f];
279
+ if (typeof a != "object" || a === null)
280
+ o[f] = a;
281
+ else if (a.constructor !== Object && (c = r.get(a.constructor)))
282
+ o[f] = c(a, i);
283
+ else if (ArrayBuffer.isView(a))
284
+ o[f] = j(a);
285
+ else {
286
+ const m = t.indexOf(a);
287
+ m !== -1 ? o[f] = s[m] : o[f] = i(a);
288
+ }
289
+ }
290
+ return t.pop(), s.pop(), o;
291
+ }
292
+ }
293
+ oe();
294
+ function ce(e) {
295
+ return function(s, r) {
296
+ return s.value.map((c) => e(c, r)).join("").trim();
297
+ };
298
+ }
299
+ function se(e) {
300
+ return function(s, r) {
301
+ return s != null ? `${s}` : "";
302
+ };
303
+ }
304
+ function ie(e) {
305
+ return function(s, r) {
306
+ const l = (r.variables?.name ?? O)({ name: s.name });
307
+ return Q(
308
+ l,
309
+ s.fallback ? e(s.fallback, r) : void 0
310
+ );
311
+ };
312
+ }
313
+ function ae(e) {
314
+ const t = A(e);
315
+ return function(r, c) {
316
+ return r.themes.reduce(
317
+ (l, u) => (l.push(e(u, c)), l),
318
+ [t(":root", r, c)]
319
+ // Default theme (root)
320
+ ).join(`
321
+
322
+ `);
323
+ };
324
+ }
325
+ function le(e) {
326
+ const t = A(e);
327
+ return function(r, c) {
328
+ return t(r.query, r, c);
329
+ };
330
+ }
331
+ function fe(e) {
332
+ const t = A(e);
333
+ return function(r, c) {
334
+ const u = (c.theme?.selector ?? V)({ name: r.name });
335
+ return t(u, r, c);
336
+ };
337
+ }
338
+ function me(e) {
339
+ const t = A(e);
340
+ return function(r, c) {
341
+ const l = [], i = (c.utilities?.selector ?? _)({
342
+ name: r.name,
343
+ value: r.value,
344
+ modifiers: r.modifiers
345
+ });
346
+ return l.push(t(i, r, c)), l.join(`
347
+
348
+ `);
349
+ };
350
+ }
351
+ function y(e, t) {
352
+ const s = ae(y), r = le(y), c = me(y), l = Z(y), u = fe(y), i = w(y), n = ie(y), o = ce(y), f = se();
353
+ switch (!0) {
354
+ case Y(e):
355
+ return r(e, t);
356
+ case ee(e):
357
+ return c(e, t);
358
+ case X(e):
359
+ return l(e, t);
360
+ case ne(e):
361
+ return s(e, t);
362
+ case re(e):
363
+ return u(e, t);
364
+ case G(e):
365
+ return i(e, t);
366
+ case J(e):
367
+ return n(e, t);
368
+ case te(e):
369
+ return o(e, t);
370
+ default:
371
+ return f(e, t);
372
+ }
373
+ }
374
+ function R(e, t) {
375
+ switch (!0) {
376
+ case Array.isArray(e):
377
+ return e.map((s) => R(s)).join(`
378
+ `);
379
+ // case isRecipe(instance):
380
+ // return consumeRecipe(instance, options);
381
+ // break;
382
+ default:
383
+ return "";
384
+ }
385
+ }
386
+ function v(e, t = "") {
387
+ return {
388
+ name: e,
389
+ content: t
390
+ };
391
+ }
392
+ function be(e, {
393
+ type: t = "all",
394
+ consumers: s = { css: y, ts: R }
395
+ } = {}) {
396
+ const r = { files: [] }, c = e.options, { recipes: l, ...u } = e.root;
397
+ if (t === "all" || t === "css") {
398
+ const i = v("index.css", s.css(u, c));
399
+ r.files.push(i);
400
+ }
401
+ if (t === "all" || t === "ts") {
402
+ const i = v("index.ts", s.ts([], c));
403
+ r.files.push(i);
404
+ }
405
+ return r;
406
+ }
407
+ export {
408
+ pe as DEFAULT_INDENT,
409
+ N as STATEMENT_AT_RULES,
410
+ E as STATEMENT_OR_BLOCK_AT_RULES,
411
+ k as addIndentToLine,
412
+ y as consumeCSS,
413
+ R as consumeTS,
414
+ Z as createAtRuleConsumer,
415
+ ce as createCSSTemplateLiteralConsumer,
416
+ A as createContainerConsumer,
417
+ W as createDeclarationsConsumer,
418
+ v as createFile,
419
+ se as createPrimitiveConsumer,
420
+ ie as createRefConsumer,
421
+ ae as createRootConsumer,
422
+ le as createSelectorConsumer,
423
+ fe as createThemeConsumer,
424
+ me as createUtilityConsumer,
425
+ w as createVariableConsumer,
426
+ V as defaultThemeSelectorFn,
427
+ _ as defaultUtilitySelectorFn,
428
+ O as defaultVariableNameFn,
429
+ x as indentLines,
430
+ z as toKebabCase,
431
+ be as transpile
432
+ };
@@ -0,0 +1,14 @@
1
+ (function(m,g){typeof exports=="object"&&typeof module<"u"?g(exports):typeof define=="function"&&define.amd?define(["exports"],g):(m=typeof globalThis<"u"?globalThis:m||self,g(m.transpiler={}))})(this,(function(m){"use strict";const F=["charset","import","namespace"],N=["layer"],_=({name:e})=>`[data-theme="${e}"]`,$=({name:e,value:t,modifiers:s})=>`._${[...s,e,t].filter(Boolean).join("\\:")}`,j=({name:e})=>e;function Z(e,t){return`@${e}${t?" ":""}${t}`}const q=/\d/,G=["-","_","/","."];function J(e=""){if(!q.test(e))return e!==e.toLowerCase()}function Y(e,t){const s=G,n=[];if(!e||typeof e!="string")return n;let c="",l,u;for(const i of e){const r=s.includes(i);if(r===!0){n.push(c),c="",l=void 0;continue}const o=J(i);if(u===!1){if(l===!1&&o===!0){n.push(c),c=i,l=o;continue}if(l===!0&&o===!1&&c.length>1){const f=c.at(-1);n.push(c.slice(0,Math.max(0,c.length-1))),c=f+i,l=o;continue}}c+=i,l=o,u=r}return n.push(c),n}function X(e,t){return e?(Array.isArray(e)?e:Y(e)).map(s=>s.toLowerCase()).join("-"):""}function w(e){return` ${e}`}function D(e){return e.split(`
2
+ `).map(t=>w(t)).join(`
3
+ `)}function L(e){return X(e)}function x(e){return L(e)}function V(e,t){return`${e.startsWith("--")?e:x(e)}: ${t};`}function ee(e){return`{${e.length>0?`
4
+ `:""}${e.map(t=>`${D(`${t}`)}
5
+ `).join("")}}`}function U(e){return`--${(e.startsWith("--")?e.slice(2):e).replace(/[^a-zA-Z0-9_\-\u0080-\uFFFF]/g,"-")||"unknown-variable"}`}function te(e,t){return V(U(e),t)}function ne(e,t){return`var(${U(e)}${t?`, ${t}`:""})`}function B(e,t){return`${e} ${ee(t)}`}function M(e){return function(s,n){return Object.entries(s).map(([c,l])=>V(c,e(l,n)))}}function v(e){return function(s,n){const l=(n.variables?.name??j)({name:s.name});return te(l,e(s.value,n))}}function C(e){const t=v(e),s=M(e);return function(c,l,u){const{variables:i,declarations:r,children:o}=l,f=c===":root",a=(i??[]).map(A=>t(A,u)),d=s(r??{},u),y=(o??[]).map(A=>e(A,u)),b=a.length>0,p=d.length>0,R=y.length>0;return f?`${b||p?B(c,[...a,...b&&p?[""]:[],...d]):""}${R&&(b||p)?`
6
+
7
+ `:""}${y.join(`
8
+
9
+ `)}`:B(c,[...a,...b&&(R||p)?[""]:[],...d,...p&&R?[""]:[],...y.flatMap((A,ye)=>ye===y.length-1?[A]:[A,""])])}}function P(e){const t=C(e);return function(n,c){const l=F.includes(n.identifier),u=N.includes(n.identifier),i=Object.keys(n.declarations).length>0,r=n.variables.length>0,o=n.children.length>0,f=Z(n.identifier,n.rule);return l||u&&!(i||r||o)?`${f};`:t(f,n,c)}}function re(e){return typeof e=="object"&&e!==null}function S(e,t){return re(e)&&"type"in e&&e.type===t}function oe(e){return S(e,"variable")}function ue(e){return S(e,"reference")}function ce(e){return S(e,"selector")}function se(e){return S(e,"at-rule")}function ie(e){return S(e,"utility")}function ae(e){return S(e,"css")}function le(e){return S(e,"theme")}function fe(e){return S(e,"root")}function T(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 me(e){if(e=e||{},e.circular)return de(e);const t=new Map;if(t.set(Date,u=>new Date(u)),t.set(Map,(u,i)=>new Map(n(Array.from(u),i))),t.set(Set,(u,i)=>new Set(n(Array.from(u),i))),e.constructorHandlers)for(const u of e.constructorHandlers)t.set(u[0],u[1]);let s;return e.proto?l:c;function n(u,i){const r=Object.keys(u),o=Array.from({length:r.length});for(let f=0;f<r.length;f++){const a=r[f],d=u[a];typeof d!="object"||d===null?o[a]=d:d.constructor!==Object&&(s=t.get(d.constructor))?o[a]=s(d,i):ArrayBuffer.isView(d)?o[a]=T(d):o[a]=i(d)}return o}function c(u){if(typeof u!="object"||u===null)return u;if(Array.isArray(u))return n(u,c);if(u.constructor!==Object&&(s=t.get(u.constructor)))return s(u,c);const i={};for(const r in u){if(Object.hasOwnProperty.call(u,r)===!1)continue;const o=u[r];typeof o!="object"||o===null?i[r]=o:o.constructor!==Object&&(s=t.get(o.constructor))?i[r]=s(o,c):ArrayBuffer.isView(o)?i[r]=T(o):i[r]=c(o)}return i}function l(u){if(typeof u!="object"||u===null)return u;if(Array.isArray(u))return n(u,l);if(u.constructor!==Object&&(s=t.get(u.constructor)))return s(u,l);const i={};for(const r in u){const o=u[r];typeof o!="object"||o===null?i[r]=o:o.constructor!==Object&&(s=t.get(o.constructor))?i[r]=s(o,l):ArrayBuffer.isView(o)?i[r]=T(o):i[r]=l(o)}return i}}function de(e){const t=[],s=[],n=new Map;if(n.set(Date,r=>new Date(r)),n.set(Map,(r,o)=>new Map(l(Array.from(r),o))),n.set(Set,(r,o)=>new Set(l(Array.from(r),o))),e.constructorHandlers)for(const r of e.constructorHandlers)n.set(r[0],r[1]);let c;return e.proto?i:u;function l(r,o){const f=Object.keys(r),a=Array.from({length:f.length});for(let d=0;d<f.length;d++){const y=f[d],b=r[y];if(typeof b!="object"||b===null)a[y]=b;else if(b.constructor!==Object&&(c=n.get(b.constructor)))a[y]=c(b,o);else if(ArrayBuffer.isView(b))a[y]=T(b);else{const p=t.indexOf(b);p!==-1?a[y]=s[p]:a[y]=o(b)}}return a}function u(r){if(typeof r!="object"||r===null)return r;if(Array.isArray(r))return l(r,u);if(r.constructor!==Object&&(c=n.get(r.constructor)))return c(r,u);const o={};t.push(r),s.push(o);for(const f in r){if(Object.hasOwnProperty.call(r,f)===!1)continue;const a=r[f];if(typeof a!="object"||a===null)o[f]=a;else if(a.constructor!==Object&&(c=n.get(a.constructor)))o[f]=c(a,u);else if(ArrayBuffer.isView(a))o[f]=T(a);else{const d=t.indexOf(a);d!==-1?o[f]=s[d]:o[f]=u(a)}}return t.pop(),s.pop(),o}function i(r){if(typeof r!="object"||r===null)return r;if(Array.isArray(r))return l(r,i);if(r.constructor!==Object&&(c=n.get(r.constructor)))return c(r,i);const o={};t.push(r),s.push(o);for(const f in r){const a=r[f];if(typeof a!="object"||a===null)o[f]=a;else if(a.constructor!==Object&&(c=n.get(a.constructor)))o[f]=c(a,i);else if(ArrayBuffer.isView(a))o[f]=T(a);else{const d=t.indexOf(a);d!==-1?o[f]=s[d]:o[f]=i(a)}}return t.pop(),s.pop(),o}}me();function k(e){return function(s,n){return s.value.map(c=>e(c,n)).join("").trim()}}function z(e){return function(s,n){return s!=null?`${s}`:""}}function I(e){return function(s,n){const l=(n.variables?.name??j)({name:s.name});return ne(l,s.fallback?e(s.fallback,n):void 0)}}function H(e){const t=C(e);return function(n,c){return n.themes.reduce((l,u)=>(l.push(e(u,c)),l),[t(":root",n,c)]).join(`
10
+
11
+ `)}}function K(e){const t=C(e);return function(n,c){return t(n.query,n,c)}}function Q(e){const t=C(e);return function(n,c){const u=(c.theme?.selector??_)({name:n.name});return t(u,n,c)}}function W(e){const t=C(e);return function(n,c){const l=[],i=(c.utilities?.selector??$)({name:n.name,value:n.value,modifiers:n.modifiers});return l.push(t(i,n,c)),l.join(`
12
+
13
+ `)}}function h(e,t){const s=H(h),n=K(h),c=W(h),l=P(h),u=Q(h),i=v(h),r=I(h),o=k(h),f=z();switch(!0){case ce(e):return n(e,t);case ie(e):return c(e,t);case se(e):return l(e,t);case fe(e):return s(e,t);case le(e):return u(e,t);case oe(e):return i(e,t);case ue(e):return r(e,t);case ae(e):return o(e,t);default:return f(e,t)}}function O(e,t){switch(!0){case Array.isArray(e):return e.map(s=>O(s)).join(`
14
+ `);default:return""}}function E(e,t=""){return{name:e,content:t}}function be(e,{type:t="all",consumers:s={css:h,ts:O}}={}){const n={files:[]},c=e.options,{recipes:l,...u}=e.root;if(t==="all"||t==="css"){const i=E("index.css",s.css(u,c));n.files.push(i)}if(t==="all"||t==="ts"){const i=E("index.ts",s.ts([],c));n.files.push(i)}return n}m.DEFAULT_INDENT=" ",m.STATEMENT_AT_RULES=F,m.STATEMENT_OR_BLOCK_AT_RULES=N,m.addIndentToLine=w,m.consumeCSS=h,m.consumeTS=O,m.createAtRuleConsumer=P,m.createCSSTemplateLiteralConsumer=k,m.createContainerConsumer=C,m.createDeclarationsConsumer=M,m.createFile=E,m.createPrimitiveConsumer=z,m.createRefConsumer=I,m.createRootConsumer=H,m.createSelectorConsumer=K,m.createThemeConsumer=Q,m.createUtilityConsumer=W,m.createVariableConsumer=v,m.defaultThemeSelectorFn=_,m.defaultUtilitySelectorFn=$,m.defaultVariableNameFn=j,m.indentLines=D,m.toKebabCase=L,m.transpile=be,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@styleframe/transpiler",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "type": "module",
5
5
  "types": "./dist/transpiler.d.ts",
6
6
  "module": "./dist/transpiler.js",
@@ -12,17 +12,24 @@
12
12
  "require": "./dist/transpiler.umd.cjs"
13
13
  }
14
14
  },
15
+ "files": [
16
+ "dist",
17
+ "LICENSE",
18
+ "CHANGELOG.md",
19
+ "README.md"
20
+ ],
15
21
  "dependencies": {
16
22
  "scule": "^1.3.0",
17
- "@styleframe/core": "^1.0.1"
23
+ "@styleframe/core": "^1.0.2"
18
24
  },
19
25
  "devDependencies": {
26
+ "@vitest/coverage-v8": "^3.2.4",
20
27
  "typescript": "^5.8.3",
21
28
  "vite": "^7.0.6",
22
29
  "vite-plugin-dts": "^4.5.4",
23
30
  "vitest": "^3.2.4",
24
- "@styleframe/config-vite": "^1.0.1",
25
- "@styleframe/config-typescript": "^1.0.1"
31
+ "@styleframe/config-typescript": "^1.0.1",
32
+ "@styleframe/config-vite": "^1.0.1"
26
33
  },
27
34
  "homepage": "https://github.com/styleframe-dev/styleframe#readme",
28
35
  "bugs": {
@@ -33,6 +40,9 @@
33
40
  "url": "git+https://github.com/styleframe-dev/styleframe.git"
34
41
  },
35
42
  "author": "Alex Grozav <alex@styleframe.dev>",
43
+ "overrides": {
44
+ "vite": "npm:rolldown-vite@latest"
45
+ },
36
46
  "scripts": {
37
47
  "dev": "vite build --watch",
38
48
  "build": "pnpm typecheck && vite build",