@styleframe/transpiler 1.0.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/.tsbuildinfo +1 -0
- package/CHANGELOG.md +12 -0
- package/package.json +43 -0
- package/src/constants.ts +4 -0
- package/src/consume/at-rule.test.ts +339 -0
- package/src/consume/at-rule.ts +34 -0
- package/src/consume/consume.test.ts +259 -0
- package/src/consume/consume.ts +60 -0
- package/src/consume/container.test.ts +501 -0
- package/src/consume/container.ts +73 -0
- package/src/consume/css.test.ts +184 -0
- package/src/consume/css.ts +17 -0
- package/src/consume/declarations.test.ts +210 -0
- package/src/consume/declarations.ts +17 -0
- package/src/consume/index.ts +12 -0
- package/src/consume/primitive.test.ts +52 -0
- package/src/consume/primitive.ts +16 -0
- package/src/consume/ref.test.ts +84 -0
- package/src/consume/ref.ts +22 -0
- package/src/consume/root.test.ts +353 -0
- package/src/consume/root.ts +19 -0
- package/src/consume/selector.test.ts +441 -0
- package/src/consume/selector.ts +17 -0
- package/src/consume/theme.test.ts +215 -0
- package/src/consume/theme.ts +15 -0
- package/src/consume/utility.test.ts +696 -0
- package/src/consume/utility.ts +31 -0
- package/src/consume/variable.test.ts +197 -0
- package/src/consume/variable.ts +20 -0
- package/src/defaults.ts +21 -0
- package/src/generator/genAtRuleQuery.test.ts +148 -0
- package/src/generator/genAtRuleQuery.ts +3 -0
- package/src/generator/genDeclaration.test.ts +283 -0
- package/src/generator/genDeclaration.ts +9 -0
- package/src/generator/genDeclarationsBlock.test.ts +278 -0
- package/src/generator/genDeclarationsBlock.ts +7 -0
- package/src/generator/genDeclareVariable.test.ts +323 -0
- package/src/generator/genDeclareVariable.ts +6 -0
- package/src/generator/genInlineAtRule.test.ts +351 -0
- package/src/generator/genInlineAtRule.ts +5 -0
- package/src/generator/genReferenceVariable.test.ts +392 -0
- package/src/generator/genReferenceVariable.ts +5 -0
- package/src/generator/genSafePropertyName.test.ts +489 -0
- package/src/generator/genSafePropertyName.ts +5 -0
- package/src/generator/genSafeVariableName.test.ts +358 -0
- package/src/generator/genSafeVariableName.ts +21 -0
- package/src/generator/genSelector.test.ts +357 -0
- package/src/generator/genSelector.ts +5 -0
- package/src/generator/index.ts +9 -0
- package/src/index.ts +6 -0
- package/src/transpile.test.ts +825 -0
- package/src/transpile.ts +21 -0
- package/src/types.ts +15 -0
- package/src/utils.ts +18 -0
- package/src/vite-env.d.ts +1 -0
- package/tsconfig.json +7 -0
- package/vite.config.ts +5 -0
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { genDeclarationsBlock } from "./genDeclarationsBlock";
|
|
3
|
+
|
|
4
|
+
describe("genDeclarationsBlock", () => {
|
|
5
|
+
it("should generate an empty block for empty declarations array", () => {
|
|
6
|
+
const result = genDeclarationsBlock([]);
|
|
7
|
+
expect(result).toBe("{}");
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("should generate a block with a single declaration", () => {
|
|
11
|
+
const result = genDeclarationsBlock(["color: red;"]);
|
|
12
|
+
expect(result).toBe("{\n\tcolor: red;\n}");
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("should generate a block with multiple declarations", () => {
|
|
16
|
+
const result = genDeclarationsBlock([
|
|
17
|
+
"color: red;",
|
|
18
|
+
"background: blue;",
|
|
19
|
+
"margin: 10px;",
|
|
20
|
+
]);
|
|
21
|
+
expect(result).toBe(
|
|
22
|
+
"{\n\tcolor: red;\n\tbackground: blue;\n\tmargin: 10px;\n}",
|
|
23
|
+
);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("should handle declarations with complex values", () => {
|
|
27
|
+
const result = genDeclarationsBlock([
|
|
28
|
+
"background: linear-gradient(to right, red, blue);",
|
|
29
|
+
"box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);",
|
|
30
|
+
]);
|
|
31
|
+
expect(result).toBe(
|
|
32
|
+
"{\n\tbackground: linear-gradient(to right, red, blue);\n\tbox-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);\n}",
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("should handle CSS custom properties", () => {
|
|
37
|
+
const result = genDeclarationsBlock([
|
|
38
|
+
"--primary-color: #007bff;",
|
|
39
|
+
"--spacing: 1rem;",
|
|
40
|
+
"color: var(--primary-color);",
|
|
41
|
+
]);
|
|
42
|
+
expect(result).toBe(
|
|
43
|
+
"{\n\t--primary-color: #007bff;\n\t--spacing: 1rem;\n\tcolor: var(--primary-color);\n}",
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("should handle declarations with !important", () => {
|
|
48
|
+
const result = genDeclarationsBlock([
|
|
49
|
+
"color: red !important;",
|
|
50
|
+
"display: none !important;",
|
|
51
|
+
]);
|
|
52
|
+
expect(result).toBe(
|
|
53
|
+
"{\n\tcolor: red !important;\n\tdisplay: none !important;\n}",
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("should handle vendor-prefixed properties", () => {
|
|
58
|
+
const result = genDeclarationsBlock([
|
|
59
|
+
"-webkit-transform: rotate(45deg);",
|
|
60
|
+
"-moz-transform: rotate(45deg);",
|
|
61
|
+
"transform: rotate(45deg);",
|
|
62
|
+
]);
|
|
63
|
+
expect(result).toBe(
|
|
64
|
+
"{\n\t-webkit-transform: rotate(45deg);\n\t-moz-transform: rotate(45deg);\n\ttransform: rotate(45deg);\n}",
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("should handle declarations with calc() values", () => {
|
|
69
|
+
const result = genDeclarationsBlock([
|
|
70
|
+
"width: calc(100% - 20px);",
|
|
71
|
+
"height: calc(100vh - 80px);",
|
|
72
|
+
]);
|
|
73
|
+
expect(result).toBe(
|
|
74
|
+
"{\n\twidth: calc(100% - 20px);\n\theight: calc(100vh - 80px);\n}",
|
|
75
|
+
);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("should handle declarations with url() values", () => {
|
|
79
|
+
const result = genDeclarationsBlock([
|
|
80
|
+
"background-image: url('image.jpg');",
|
|
81
|
+
"cursor: url('cursor.png'), auto;",
|
|
82
|
+
]);
|
|
83
|
+
expect(result).toBe(
|
|
84
|
+
"{\n\tbackground-image: url('image.jpg');\n\tcursor: url('cursor.png'), auto;\n}",
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("should handle grid and flexbox properties", () => {
|
|
89
|
+
const result = genDeclarationsBlock([
|
|
90
|
+
"display: grid;",
|
|
91
|
+
"grid-template-columns: repeat(3, 1fr);",
|
|
92
|
+
"gap: 20px;",
|
|
93
|
+
"align-items: center;",
|
|
94
|
+
]);
|
|
95
|
+
expect(result).toBe(
|
|
96
|
+
"{\n\tdisplay: grid;\n\tgrid-template-columns: repeat(3, 1fr);\n\tgap: 20px;\n\talign-items: center;\n}",
|
|
97
|
+
);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("should handle animation and transition properties", () => {
|
|
101
|
+
const result = genDeclarationsBlock([
|
|
102
|
+
"animation: slide 2s ease-in-out infinite;",
|
|
103
|
+
"transition: all 0.3s ease;",
|
|
104
|
+
]);
|
|
105
|
+
expect(result).toBe(
|
|
106
|
+
"{\n\tanimation: slide 2s ease-in-out infinite;\n\ttransition: all 0.3s ease;\n}",
|
|
107
|
+
);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("should handle shorthand properties", () => {
|
|
111
|
+
const result = genDeclarationsBlock([
|
|
112
|
+
"margin: 10px 20px 30px 40px;",
|
|
113
|
+
"padding: 10px;",
|
|
114
|
+
"border: 1px solid #ccc;",
|
|
115
|
+
]);
|
|
116
|
+
expect(result).toBe(
|
|
117
|
+
"{\n\tmargin: 10px 20px 30px 40px;\n\tpadding: 10px;\n\tborder: 1px solid #ccc;\n}",
|
|
118
|
+
);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("should handle font properties", () => {
|
|
122
|
+
const result = genDeclarationsBlock([
|
|
123
|
+
"font-family: 'Helvetica Neue', Arial, sans-serif;",
|
|
124
|
+
"font-size: 16px;",
|
|
125
|
+
"font-weight: bold;",
|
|
126
|
+
"line-height: 1.5;",
|
|
127
|
+
]);
|
|
128
|
+
expect(result).toBe(
|
|
129
|
+
"{\n\tfont-family: 'Helvetica Neue', Arial, sans-serif;\n\tfont-size: 16px;\n\tfont-weight: bold;\n\tline-height: 1.5;\n}",
|
|
130
|
+
);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("should handle transform functions", () => {
|
|
134
|
+
const result = genDeclarationsBlock([
|
|
135
|
+
"transform: translateX(50%) rotate(45deg) scale(1.5);",
|
|
136
|
+
]);
|
|
137
|
+
expect(result).toBe(
|
|
138
|
+
"{\n\ttransform: translateX(50%) rotate(45deg) scale(1.5);\n}",
|
|
139
|
+
);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("should handle filter functions", () => {
|
|
143
|
+
const result = genDeclarationsBlock([
|
|
144
|
+
"filter: blur(5px) brightness(1.5) contrast(2);",
|
|
145
|
+
]);
|
|
146
|
+
expect(result).toBe(
|
|
147
|
+
"{\n\tfilter: blur(5px) brightness(1.5) contrast(2);\n}",
|
|
148
|
+
);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("should handle declarations with empty values", () => {
|
|
152
|
+
const result = genDeclarationsBlock(["content: '';", 'content: "";']);
|
|
153
|
+
expect(result).toBe("{\n\tcontent: '';\n\tcontent: \"\";\n}");
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("should handle declarations with special characters", () => {
|
|
157
|
+
const result = genDeclarationsBlock([
|
|
158
|
+
"content: '\\2022';",
|
|
159
|
+
"content: '\\00a0';",
|
|
160
|
+
]);
|
|
161
|
+
expect(result).toBe("{\n\tcontent: '\\2022';\n\tcontent: '\\00a0';\n}");
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("should handle declarations with data URIs", () => {
|
|
165
|
+
const result = genDeclarationsBlock([
|
|
166
|
+
"background-image: url('data:image/png;base64,iVBORw0KGgo...');",
|
|
167
|
+
]);
|
|
168
|
+
expect(result).toBe(
|
|
169
|
+
"{\n\tbackground-image: url('data:image/png;base64,iVBORw0KGgo...');\n}",
|
|
170
|
+
);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("should handle CSS math functions", () => {
|
|
174
|
+
const result = genDeclarationsBlock([
|
|
175
|
+
"width: min(100%, 500px);",
|
|
176
|
+
"height: max(50vh, 300px);",
|
|
177
|
+
"font-size: clamp(1rem, 2vw, 3rem);",
|
|
178
|
+
]);
|
|
179
|
+
expect(result).toBe(
|
|
180
|
+
"{\n\twidth: min(100%, 500px);\n\theight: max(50vh, 300px);\n\tfont-size: clamp(1rem, 2vw, 3rem);\n}",
|
|
181
|
+
);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("should handle CSS logical properties", () => {
|
|
185
|
+
const result = genDeclarationsBlock([
|
|
186
|
+
"margin-block-start: 1rem;",
|
|
187
|
+
"padding-inline-end: 2rem;",
|
|
188
|
+
"border-block-end: 1px solid black;",
|
|
189
|
+
]);
|
|
190
|
+
expect(result).toBe(
|
|
191
|
+
"{\n\tmargin-block-start: 1rem;\n\tpadding-inline-end: 2rem;\n\tborder-block-end: 1px solid black;\n}",
|
|
192
|
+
);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it("should handle CSS environment variables", () => {
|
|
196
|
+
const result = genDeclarationsBlock([
|
|
197
|
+
"padding-top: env(safe-area-inset-top);",
|
|
198
|
+
"padding-bottom: env(safe-area-inset-bottom);",
|
|
199
|
+
]);
|
|
200
|
+
expect(result).toBe(
|
|
201
|
+
"{\n\tpadding-top: env(safe-area-inset-top);\n\tpadding-bottom: env(safe-area-inset-bottom);\n}",
|
|
202
|
+
);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it("should handle CSS counters", () => {
|
|
206
|
+
const result = genDeclarationsBlock([
|
|
207
|
+
"counter-reset: section;",
|
|
208
|
+
"counter-increment: section;",
|
|
209
|
+
"content: counter(section);",
|
|
210
|
+
]);
|
|
211
|
+
expect(result).toBe(
|
|
212
|
+
"{\n\tcounter-reset: section;\n\tcounter-increment: section;\n\tcontent: counter(section);\n}",
|
|
213
|
+
);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it("should handle CSS attr() function", () => {
|
|
217
|
+
const result = genDeclarationsBlock([
|
|
218
|
+
"content: attr(data-label);",
|
|
219
|
+
"content: attr(href);",
|
|
220
|
+
]);
|
|
221
|
+
expect(result).toBe(
|
|
222
|
+
"{\n\tcontent: attr(data-label);\n\tcontent: attr(href);\n}",
|
|
223
|
+
);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it("should handle single declaration without array wrapper", () => {
|
|
227
|
+
const result = genDeclarationsBlock(["display: block;"]);
|
|
228
|
+
expect(result).toBe("{\n\tdisplay: block;\n}");
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it("should preserve exact declaration strings", () => {
|
|
232
|
+
const result = genDeclarationsBlock([
|
|
233
|
+
"color:red;",
|
|
234
|
+
"background: blue ;",
|
|
235
|
+
"margin:10px 20px;",
|
|
236
|
+
]);
|
|
237
|
+
expect(result).toBe(
|
|
238
|
+
"{\n\tcolor:red;\n\tbackground: blue ;\n\tmargin:10px 20px;\n}",
|
|
239
|
+
);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it("should handle declarations with newlines in values", () => {
|
|
243
|
+
const result = genDeclarationsBlock([
|
|
244
|
+
"white-space: pre-wrap;",
|
|
245
|
+
"content: 'Line 1\\A Line 2';",
|
|
246
|
+
]);
|
|
247
|
+
expect(result).toBe(
|
|
248
|
+
"{\n\twhite-space: pre-wrap;\n\tcontent: 'Line 1\\A Line 2';\n}",
|
|
249
|
+
);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it("should handle very long declaration values", () => {
|
|
253
|
+
const longGradient =
|
|
254
|
+
"linear-gradient(to right, red 0%, orange 10%, yellow 20%, green 30%, blue 40%, indigo 50%, violet 60%, red 70%, orange 80%, yellow 90%, green 100%)";
|
|
255
|
+
const result = genDeclarationsBlock([`background: ${longGradient};`]);
|
|
256
|
+
expect(result).toBe(`{\n\tbackground: ${longGradient};\n}`);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it("should handle declarations with multiple semicolons", () => {
|
|
260
|
+
const result = genDeclarationsBlock(["content: ';';", "content: ';;';"]);
|
|
261
|
+
expect(result).toBe("{\n\tcontent: ';';\n\tcontent: ';;';\n}");
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it("should handle CSS container queries", () => {
|
|
265
|
+
const result = genDeclarationsBlock([
|
|
266
|
+
"container-type: inline-size;",
|
|
267
|
+
"container-name: sidebar;",
|
|
268
|
+
]);
|
|
269
|
+
expect(result).toBe(
|
|
270
|
+
"{\n\tcontainer-type: inline-size;\n\tcontainer-name: sidebar;\n}",
|
|
271
|
+
);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it("should handle CSS cascade layers", () => {
|
|
275
|
+
const result = genDeclarationsBlock(["layer: utilities;", "layer: base;"]);
|
|
276
|
+
expect(result).toBe("{\n\tlayer: utilities;\n\tlayer: base;\n}");
|
|
277
|
+
});
|
|
278
|
+
});
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { genDeclareVariable } from "./genDeclareVariable";
|
|
3
|
+
|
|
4
|
+
describe("genDeclareVariable", () => {
|
|
5
|
+
it("should generate a CSS variable declaration with -- prefix", () => {
|
|
6
|
+
const result = genDeclareVariable("primary-color", "#007bff");
|
|
7
|
+
expect(result).toBe("--primary-color: #007bff;");
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("should preserve existing -- prefix", () => {
|
|
11
|
+
const result = genDeclareVariable("--secondary-color", "#6c757d");
|
|
12
|
+
expect(result).toBe("--secondary-color: #6c757d;");
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("should handle simple color values", () => {
|
|
16
|
+
const result = genDeclareVariable("text-color", "black");
|
|
17
|
+
expect(result).toBe("--text-color: black;");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("should handle hex color values", () => {
|
|
21
|
+
const result = genDeclareVariable("background", "#ffffff");
|
|
22
|
+
expect(result).toBe("--background: #ffffff;");
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("should handle rgb values", () => {
|
|
26
|
+
const result = genDeclareVariable("accent", "rgb(255, 0, 0)");
|
|
27
|
+
expect(result).toBe("--accent: rgb(255, 0, 0);");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("should handle rgba values", () => {
|
|
31
|
+
const result = genDeclareVariable("overlay", "rgba(0, 0, 0, 0.5)");
|
|
32
|
+
expect(result).toBe("--overlay: rgba(0, 0, 0, 0.5);");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("should handle hsl values", () => {
|
|
36
|
+
const result = genDeclareVariable("theme-color", "hsl(210, 100%, 50%)");
|
|
37
|
+
expect(result).toBe("--theme-color: hsl(210, 100%, 50%);");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("should handle numeric values", () => {
|
|
41
|
+
const result = genDeclareVariable("spacing", "16px");
|
|
42
|
+
expect(result).toBe("--spacing: 16px;");
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("should handle percentage values", () => {
|
|
46
|
+
const result = genDeclareVariable("width", "100%");
|
|
47
|
+
expect(result).toBe("--width: 100%;");
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("should handle em values", () => {
|
|
51
|
+
const result = genDeclareVariable("font-size", "1.5em");
|
|
52
|
+
expect(result).toBe("--font-size: 1.5em;");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("should handle rem values", () => {
|
|
56
|
+
const result = genDeclareVariable("margin", "2rem");
|
|
57
|
+
expect(result).toBe("--margin: 2rem;");
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("should handle viewport units", () => {
|
|
61
|
+
const result = genDeclareVariable("height", "100vh");
|
|
62
|
+
expect(result).toBe("--height: 100vh;");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("should handle calc() expressions", () => {
|
|
66
|
+
const result = genDeclareVariable("computed-width", "calc(100% - 20px)");
|
|
67
|
+
expect(result).toBe("--computed-width: calc(100% - 20px);");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("should handle var() references", () => {
|
|
71
|
+
const result = genDeclareVariable("derived-color", "var(--primary-color)");
|
|
72
|
+
expect(result).toBe("--derived-color: var(--primary-color);");
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("should handle var() with fallback", () => {
|
|
76
|
+
const result = genDeclareVariable(
|
|
77
|
+
"safe-color",
|
|
78
|
+
"var(--custom-color, #000000)",
|
|
79
|
+
);
|
|
80
|
+
expect(result).toBe("--safe-color: var(--custom-color, #000000);");
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("should handle gradient values", () => {
|
|
84
|
+
const result = genDeclareVariable(
|
|
85
|
+
"gradient",
|
|
86
|
+
"linear-gradient(to right, red, blue)",
|
|
87
|
+
);
|
|
88
|
+
expect(result).toBe("--gradient: linear-gradient(to right, red, blue);");
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("should handle shadow values", () => {
|
|
92
|
+
const result = genDeclareVariable("shadow", "0 4px 6px rgba(0, 0, 0, 0.1)");
|
|
93
|
+
expect(result).toBe("--shadow: 0 4px 6px rgba(0, 0, 0, 0.1);");
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("should handle font-family values", () => {
|
|
97
|
+
const result = genDeclareVariable(
|
|
98
|
+
"font-stack",
|
|
99
|
+
"'Helvetica Neue', Arial, sans-serif",
|
|
100
|
+
);
|
|
101
|
+
expect(result).toBe("--font-stack: 'Helvetica Neue', Arial, sans-serif;");
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("should handle transition timing", () => {
|
|
105
|
+
const result = genDeclareVariable("transition", "all 0.3s ease-in-out");
|
|
106
|
+
expect(result).toBe("--transition: all 0.3s ease-in-out;");
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("should handle transform functions", () => {
|
|
110
|
+
const result = genDeclareVariable("transform", "rotate(45deg) scale(1.5)");
|
|
111
|
+
expect(result).toBe("--transform: rotate(45deg) scale(1.5);");
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("should handle url() values", () => {
|
|
115
|
+
const result = genDeclareVariable("background-image", "url('image.jpg')");
|
|
116
|
+
expect(result).toBe("--background-image: url('image.jpg');");
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("should handle multiple values", () => {
|
|
120
|
+
const result = genDeclareVariable("margin-values", "10px 20px 30px 40px");
|
|
121
|
+
expect(result).toBe("--margin-values: 10px 20px 30px 40px;");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("should handle empty string value", () => {
|
|
125
|
+
const result = genDeclareVariable("empty", "");
|
|
126
|
+
expect(result).toBe("--empty: ;");
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("should handle quoted string values", () => {
|
|
130
|
+
const result = genDeclareVariable("content", '"Hello World"');
|
|
131
|
+
expect(result).toBe('--content: "Hello World";');
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("should handle single quoted string values", () => {
|
|
135
|
+
const result = genDeclareVariable("label", "'Click here'");
|
|
136
|
+
expect(result).toBe("--label: 'Click here';");
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("should handle numeric values without units", () => {
|
|
140
|
+
const result = genDeclareVariable("line-height", "1.5");
|
|
141
|
+
expect(result).toBe("--line-height: 1.5;");
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("should handle zero value", () => {
|
|
145
|
+
const result = genDeclareVariable("reset", "0");
|
|
146
|
+
expect(result).toBe("--reset: 0;");
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("should handle negative values", () => {
|
|
150
|
+
const result = genDeclareVariable("offset", "-10px");
|
|
151
|
+
expect(result).toBe("--offset: -10px;");
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("should handle decimal values", () => {
|
|
155
|
+
const result = genDeclareVariable("opacity", "0.75");
|
|
156
|
+
expect(result).toBe("--opacity: 0.75;");
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("should handle CSS keywords", () => {
|
|
160
|
+
const result = genDeclareVariable("display", "none");
|
|
161
|
+
expect(result).toBe("--display: none;");
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("should handle inherit keyword", () => {
|
|
165
|
+
const result = genDeclareVariable("color", "inherit");
|
|
166
|
+
expect(result).toBe("--color: inherit;");
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("should handle initial keyword", () => {
|
|
170
|
+
const result = genDeclareVariable("value", "initial");
|
|
171
|
+
expect(result).toBe("--value: initial;");
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("should handle unset keyword", () => {
|
|
175
|
+
const result = genDeclareVariable("property", "unset");
|
|
176
|
+
expect(result).toBe("--property: unset;");
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("should handle currentColor keyword", () => {
|
|
180
|
+
const result = genDeclareVariable("border-color", "currentColor");
|
|
181
|
+
expect(result).toBe("--border-color: currentColor;");
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("should handle transparent keyword", () => {
|
|
185
|
+
const result = genDeclareVariable("bg", "transparent");
|
|
186
|
+
expect(result).toBe("--bg: transparent;");
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("should handle variable names with numbers", () => {
|
|
190
|
+
const result = genDeclareVariable("spacing-2", "8px");
|
|
191
|
+
expect(result).toBe("--spacing-2: 8px;");
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("should handle variable names with underscores", () => {
|
|
195
|
+
const result = genDeclareVariable("primary_color", "#007bff");
|
|
196
|
+
expect(result).toBe("--primary_color: #007bff;");
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("should handle camelCase variable names", () => {
|
|
200
|
+
const result = genDeclareVariable("primaryColor", "#007bff");
|
|
201
|
+
expect(result).toBe("--primaryColor: #007bff;");
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("should handle variable names starting with numbers (CSS allows this with --)", () => {
|
|
205
|
+
const result = genDeclareVariable("1-column", "100px");
|
|
206
|
+
expect(result).toBe("--1-column: 100px;");
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it("should handle complex calc with nested operations", () => {
|
|
210
|
+
const result = genDeclareVariable("complex", "calc((100% - 20px) / 2)");
|
|
211
|
+
expect(result).toBe("--complex: calc((100% - 20px) / 2);");
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("should handle min() function", () => {
|
|
215
|
+
const result = genDeclareVariable("width", "min(100%, 500px)");
|
|
216
|
+
expect(result).toBe("--width: min(100%, 500px);");
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("should handle max() function", () => {
|
|
220
|
+
const result = genDeclareVariable("height", "max(50vh, 300px)");
|
|
221
|
+
expect(result).toBe("--height: max(50vh, 300px);");
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("should handle clamp() function", () => {
|
|
225
|
+
const result = genDeclareVariable("font-size", "clamp(1rem, 2vw, 3rem)");
|
|
226
|
+
expect(result).toBe("--font-size: clamp(1rem, 2vw, 3rem);");
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it("should handle cubic-bezier timing function", () => {
|
|
230
|
+
const result = genDeclareVariable("easing", "cubic-bezier(0.4, 0, 0.2, 1)");
|
|
231
|
+
expect(result).toBe("--easing: cubic-bezier(0.4, 0, 0.2, 1);");
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it("should handle filter functions", () => {
|
|
235
|
+
const result = genDeclareVariable("blur", "blur(5px)");
|
|
236
|
+
expect(result).toBe("--blur: blur(5px);");
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it("should handle multiple box-shadow values", () => {
|
|
240
|
+
const result = genDeclareVariable(
|
|
241
|
+
"shadows",
|
|
242
|
+
"0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24)",
|
|
243
|
+
);
|
|
244
|
+
expect(result).toBe(
|
|
245
|
+
"--shadows: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);",
|
|
246
|
+
);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it("should handle grid template values", () => {
|
|
250
|
+
const result = genDeclareVariable("grid-columns", "repeat(3, 1fr)");
|
|
251
|
+
expect(result).toBe("--grid-columns: repeat(3, 1fr);");
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it("should handle CSS Grid line names", () => {
|
|
255
|
+
const result = genDeclareVariable(
|
|
256
|
+
"grid-rows",
|
|
257
|
+
"[header-start] 100px [header-end content-start] 1fr [content-end]",
|
|
258
|
+
);
|
|
259
|
+
expect(result).toBe(
|
|
260
|
+
"--grid-rows: [header-start] 100px [header-end content-start] 1fr [content-end];",
|
|
261
|
+
);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it("should handle env() function", () => {
|
|
265
|
+
const result = genDeclareVariable("safe-top", "env(safe-area-inset-top)");
|
|
266
|
+
expect(result).toBe("--safe-top: env(safe-area-inset-top);");
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it("should handle attr() function", () => {
|
|
270
|
+
const result = genDeclareVariable("content", "attr(data-label)");
|
|
271
|
+
expect(result).toBe("--content: attr(data-label);");
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it("should handle counter() function", () => {
|
|
275
|
+
const result = genDeclareVariable("counter", "counter(section)");
|
|
276
|
+
expect(result).toBe("--counter: counter(section);");
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it("should handle whitespace in values", () => {
|
|
280
|
+
const result = genDeclareVariable("padding", " 10px 20px ");
|
|
281
|
+
expect(result).toBe("--padding: 10px 20px ;");
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it("should handle special CSS color names", () => {
|
|
285
|
+
const result = genDeclareVariable("color", "rebeccapurple");
|
|
286
|
+
expect(result).toBe("--color: rebeccapurple;");
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it("should handle system colors", () => {
|
|
290
|
+
const result = genDeclareVariable("color", "ButtonText");
|
|
291
|
+
expect(result).toBe("--color: ButtonText;");
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it("should handle variable name with single dash", () => {
|
|
295
|
+
const result = genDeclareVariable("-custom", "value");
|
|
296
|
+
expect(result).toBe("---custom: value;");
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it("should handle variable name with triple dash", () => {
|
|
300
|
+
const result = genDeclareVariable("---extra", "value");
|
|
301
|
+
expect(result).toBe("---extra: value;");
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it("should handle emoji in values", () => {
|
|
305
|
+
const result = genDeclareVariable("emoji", "'🎉'");
|
|
306
|
+
expect(result).toBe("--emoji: '🎉';");
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
it("should handle unicode escape sequences", () => {
|
|
310
|
+
const result = genDeclareVariable("unicode", "'\\2022'");
|
|
311
|
+
expect(result).toBe("--unicode: '\\2022';");
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it("should handle data URI values", () => {
|
|
315
|
+
const result = genDeclareVariable(
|
|
316
|
+
"icon",
|
|
317
|
+
"url('data:image/svg+xml;base64,PHN2ZyB4...')",
|
|
318
|
+
);
|
|
319
|
+
expect(result).toBe(
|
|
320
|
+
"--icon: url('data:image/svg+xml;base64,PHN2ZyB4...');",
|
|
321
|
+
);
|
|
322
|
+
});
|
|
323
|
+
});
|