@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.
Files changed (57) hide show
  1. package/.tsbuildinfo +1 -0
  2. package/CHANGELOG.md +12 -0
  3. package/package.json +43 -0
  4. package/src/constants.ts +4 -0
  5. package/src/consume/at-rule.test.ts +339 -0
  6. package/src/consume/at-rule.ts +34 -0
  7. package/src/consume/consume.test.ts +259 -0
  8. package/src/consume/consume.ts +60 -0
  9. package/src/consume/container.test.ts +501 -0
  10. package/src/consume/container.ts +73 -0
  11. package/src/consume/css.test.ts +184 -0
  12. package/src/consume/css.ts +17 -0
  13. package/src/consume/declarations.test.ts +210 -0
  14. package/src/consume/declarations.ts +17 -0
  15. package/src/consume/index.ts +12 -0
  16. package/src/consume/primitive.test.ts +52 -0
  17. package/src/consume/primitive.ts +16 -0
  18. package/src/consume/ref.test.ts +84 -0
  19. package/src/consume/ref.ts +22 -0
  20. package/src/consume/root.test.ts +353 -0
  21. package/src/consume/root.ts +19 -0
  22. package/src/consume/selector.test.ts +441 -0
  23. package/src/consume/selector.ts +17 -0
  24. package/src/consume/theme.test.ts +215 -0
  25. package/src/consume/theme.ts +15 -0
  26. package/src/consume/utility.test.ts +696 -0
  27. package/src/consume/utility.ts +31 -0
  28. package/src/consume/variable.test.ts +197 -0
  29. package/src/consume/variable.ts +20 -0
  30. package/src/defaults.ts +21 -0
  31. package/src/generator/genAtRuleQuery.test.ts +148 -0
  32. package/src/generator/genAtRuleQuery.ts +3 -0
  33. package/src/generator/genDeclaration.test.ts +283 -0
  34. package/src/generator/genDeclaration.ts +9 -0
  35. package/src/generator/genDeclarationsBlock.test.ts +278 -0
  36. package/src/generator/genDeclarationsBlock.ts +7 -0
  37. package/src/generator/genDeclareVariable.test.ts +323 -0
  38. package/src/generator/genDeclareVariable.ts +6 -0
  39. package/src/generator/genInlineAtRule.test.ts +351 -0
  40. package/src/generator/genInlineAtRule.ts +5 -0
  41. package/src/generator/genReferenceVariable.test.ts +392 -0
  42. package/src/generator/genReferenceVariable.ts +5 -0
  43. package/src/generator/genSafePropertyName.test.ts +489 -0
  44. package/src/generator/genSafePropertyName.ts +5 -0
  45. package/src/generator/genSafeVariableName.test.ts +358 -0
  46. package/src/generator/genSafeVariableName.ts +21 -0
  47. package/src/generator/genSelector.test.ts +357 -0
  48. package/src/generator/genSelector.ts +5 -0
  49. package/src/generator/index.ts +9 -0
  50. package/src/index.ts +6 -0
  51. package/src/transpile.test.ts +825 -0
  52. package/src/transpile.ts +21 -0
  53. package/src/types.ts +15 -0
  54. package/src/utils.ts +18 -0
  55. package/src/vite-env.d.ts +1 -0
  56. package/tsconfig.json +7 -0
  57. package/vite.config.ts +5 -0
@@ -0,0 +1,489 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { genSafePropertyName } from "./genSafePropertyName";
3
+
4
+ describe("genSafePropertyName", () => {
5
+ describe("camelCase to kebab-case conversion", () => {
6
+ it("should convert backgroundColor to background-color", () => {
7
+ const result = genSafePropertyName("backgroundColor");
8
+ expect(result).toBe("background-color");
9
+ });
10
+
11
+ it("should convert fontSize to font-size", () => {
12
+ const result = genSafePropertyName("fontSize");
13
+ expect(result).toBe("font-size");
14
+ });
15
+
16
+ it("should convert marginTop to margin-top", () => {
17
+ const result = genSafePropertyName("marginTop");
18
+ expect(result).toBe("margin-top");
19
+ });
20
+
21
+ it("should convert paddingLeft to padding-left", () => {
22
+ const result = genSafePropertyName("paddingLeft");
23
+ expect(result).toBe("padding-left");
24
+ });
25
+
26
+ it("should convert borderBottomWidth to border-bottom-width", () => {
27
+ const result = genSafePropertyName("borderBottomWidth");
28
+ expect(result).toBe("border-bottom-width");
29
+ });
30
+
31
+ it("should convert textDecorationLine to text-decoration-line", () => {
32
+ const result = genSafePropertyName("textDecorationLine");
33
+ expect(result).toBe("text-decoration-line");
34
+ });
35
+
36
+ it("should convert zIndex to z-index", () => {
37
+ const result = genSafePropertyName("zIndex");
38
+ expect(result).toBe("z-index");
39
+ });
40
+
41
+ it("should convert lineHeight to line-height", () => {
42
+ const result = genSafePropertyName("lineHeight");
43
+ expect(result).toBe("line-height");
44
+ });
45
+
46
+ it("should convert boxShadow to box-shadow", () => {
47
+ const result = genSafePropertyName("boxShadow");
48
+ expect(result).toBe("box-shadow");
49
+ });
50
+
51
+ it("should convert flexDirection to flex-direction", () => {
52
+ const result = genSafePropertyName("flexDirection");
53
+ expect(result).toBe("flex-direction");
54
+ });
55
+
56
+ it("should convert justifyContent to justify-content", () => {
57
+ const result = genSafePropertyName("justifyContent");
58
+ expect(result).toBe("justify-content");
59
+ });
60
+
61
+ it("should convert alignItems to align-items", () => {
62
+ const result = genSafePropertyName("alignItems");
63
+ expect(result).toBe("align-items");
64
+ });
65
+
66
+ it("should convert maxWidth to max-width", () => {
67
+ const result = genSafePropertyName("maxWidth");
68
+ expect(result).toBe("max-width");
69
+ });
70
+
71
+ it("should convert minHeight to min-height", () => {
72
+ const result = genSafePropertyName("minHeight");
73
+ expect(result).toBe("min-height");
74
+ });
75
+
76
+ it("should convert overflowX to overflow-x", () => {
77
+ const result = genSafePropertyName("overflowX");
78
+ expect(result).toBe("overflow-x");
79
+ });
80
+
81
+ it("should convert overflowY to overflow-y", () => {
82
+ const result = genSafePropertyName("overflowY");
83
+ expect(result).toBe("overflow-y");
84
+ });
85
+ });
86
+
87
+ describe("PascalCase to kebab-case conversion", () => {
88
+ it("should convert BackgroundColor to background-color", () => {
89
+ const result = genSafePropertyName("BackgroundColor");
90
+ expect(result).toBe("background-color");
91
+ });
92
+
93
+ it("should convert FontSize to font-size", () => {
94
+ const result = genSafePropertyName("FontSize");
95
+ expect(result).toBe("font-size");
96
+ });
97
+
98
+ it("should convert TextAlign to text-align", () => {
99
+ const result = genSafePropertyName("TextAlign");
100
+ expect(result).toBe("text-align");
101
+ });
102
+
103
+ it("should convert BorderRadius to border-radius", () => {
104
+ const result = genSafePropertyName("BorderRadius");
105
+ expect(result).toBe("border-radius");
106
+ });
107
+
108
+ it("should convert GridTemplateColumns to grid-template-columns", () => {
109
+ const result = genSafePropertyName("GridTemplateColumns");
110
+ expect(result).toBe("grid-template-columns");
111
+ });
112
+ });
113
+
114
+ describe("already kebab-case properties", () => {
115
+ it("should preserve background-color", () => {
116
+ const result = genSafePropertyName("background-color");
117
+ expect(result).toBe("background-color");
118
+ });
119
+
120
+ it("should preserve font-size", () => {
121
+ const result = genSafePropertyName("font-size");
122
+ expect(result).toBe("font-size");
123
+ });
124
+
125
+ it("should preserve margin-top", () => {
126
+ const result = genSafePropertyName("margin-top");
127
+ expect(result).toBe("margin-top");
128
+ });
129
+
130
+ it("should preserve border-bottom-width", () => {
131
+ const result = genSafePropertyName("border-bottom-width");
132
+ expect(result).toBe("border-bottom-width");
133
+ });
134
+
135
+ it("should preserve text-decoration-line", () => {
136
+ const result = genSafePropertyName("text-decoration-line");
137
+ expect(result).toBe("text-decoration-line");
138
+ });
139
+ });
140
+
141
+ describe("vendor prefixed properties", () => {
142
+ it("should handle WebkitTransform", () => {
143
+ const result = genSafePropertyName("WebkitTransform");
144
+ expect(result).toBe("webkit-transform");
145
+ });
146
+
147
+ it("should handle MozAppearance", () => {
148
+ const result = genSafePropertyName("MozAppearance");
149
+ expect(result).toBe("moz-appearance");
150
+ });
151
+
152
+ it("should handle msFlexAlign", () => {
153
+ const result = genSafePropertyName("msFlexAlign");
154
+ expect(result).toBe("ms-flex-align");
155
+ });
156
+
157
+ it("should handle OTransform", () => {
158
+ const result = genSafePropertyName("OTransform");
159
+ expect(result).toBe("o-transform");
160
+ });
161
+
162
+ it("should handle already prefixed -webkit-transform", () => {
163
+ const result = genSafePropertyName("-webkit-transform");
164
+ expect(result).toBe("-webkit-transform");
165
+ });
166
+
167
+ it("should handle already prefixed -moz-appearance", () => {
168
+ const result = genSafePropertyName("-moz-appearance");
169
+ expect(result).toBe("-moz-appearance");
170
+ });
171
+
172
+ it("should handle already prefixed -ms-flex", () => {
173
+ const result = genSafePropertyName("-ms-flex");
174
+ expect(result).toBe("-ms-flex");
175
+ });
176
+
177
+ it("should handle already prefixed -o-transform", () => {
178
+ const result = genSafePropertyName("-o-transform");
179
+ expect(result).toBe("-o-transform");
180
+ });
181
+
182
+ it("should handle webkitTransform (lowercase webkit)", () => {
183
+ const result = genSafePropertyName("webkitTransform");
184
+ expect(result).toBe("webkit-transform");
185
+ });
186
+
187
+ it("should handle mozBoxSizing", () => {
188
+ const result = genSafePropertyName("mozBoxSizing");
189
+ expect(result).toBe("moz-box-sizing");
190
+ });
191
+ });
192
+
193
+ describe("single word properties", () => {
194
+ it("should preserve color", () => {
195
+ const result = genSafePropertyName("color");
196
+ expect(result).toBe("color");
197
+ });
198
+
199
+ it("should preserve width", () => {
200
+ const result = genSafePropertyName("width");
201
+ expect(result).toBe("width");
202
+ });
203
+
204
+ it("should preserve height", () => {
205
+ const result = genSafePropertyName("height");
206
+ expect(result).toBe("height");
207
+ });
208
+
209
+ it("should preserve margin", () => {
210
+ const result = genSafePropertyName("margin");
211
+ expect(result).toBe("margin");
212
+ });
213
+
214
+ it("should preserve padding", () => {
215
+ const result = genSafePropertyName("padding");
216
+ expect(result).toBe("padding");
217
+ });
218
+
219
+ it("should preserve display", () => {
220
+ const result = genSafePropertyName("display");
221
+ expect(result).toBe("display");
222
+ });
223
+
224
+ it("should preserve position", () => {
225
+ const result = genSafePropertyName("position");
226
+ expect(result).toBe("position");
227
+ });
228
+
229
+ it("should preserve top", () => {
230
+ const result = genSafePropertyName("top");
231
+ expect(result).toBe("top");
232
+ });
233
+
234
+ it("should preserve left", () => {
235
+ const result = genSafePropertyName("left");
236
+ expect(result).toBe("left");
237
+ });
238
+
239
+ it("should preserve right", () => {
240
+ const result = genSafePropertyName("right");
241
+ expect(result).toBe("right");
242
+ });
243
+
244
+ it("should preserve bottom", () => {
245
+ const result = genSafePropertyName("bottom");
246
+ expect(result).toBe("bottom");
247
+ });
248
+
249
+ it("should preserve float", () => {
250
+ const result = genSafePropertyName("float");
251
+ expect(result).toBe("float");
252
+ });
253
+
254
+ it("should preserve clear", () => {
255
+ const result = genSafePropertyName("clear");
256
+ expect(result).toBe("clear");
257
+ });
258
+
259
+ it("should preserve content", () => {
260
+ const result = genSafePropertyName("content");
261
+ expect(result).toBe("content");
262
+ });
263
+
264
+ it("should preserve cursor", () => {
265
+ const result = genSafePropertyName("cursor");
266
+ expect(result).toBe("cursor");
267
+ });
268
+
269
+ it("should preserve opacity", () => {
270
+ const result = genSafePropertyName("opacity");
271
+ expect(result).toBe("opacity");
272
+ });
273
+
274
+ it("should preserve filter", () => {
275
+ const result = genSafePropertyName("filter");
276
+ expect(result).toBe("filter");
277
+ });
278
+
279
+ it("should preserve transform", () => {
280
+ const result = genSafePropertyName("transform");
281
+ expect(result).toBe("transform");
282
+ });
283
+
284
+ it("should preserve transition", () => {
285
+ const result = genSafePropertyName("transition");
286
+ expect(result).toBe("transition");
287
+ });
288
+
289
+ it("should preserve animation", () => {
290
+ const result = genSafePropertyName("animation");
291
+ expect(result).toBe("animation");
292
+ });
293
+ });
294
+
295
+ describe("snake_case to kebab-case conversion", () => {
296
+ it("should convert background_color to background-color", () => {
297
+ const result = genSafePropertyName("background_color");
298
+ expect(result).toBe("background-color");
299
+ });
300
+
301
+ it("should convert font_size to font-size", () => {
302
+ const result = genSafePropertyName("font_size");
303
+ expect(result).toBe("font-size");
304
+ });
305
+
306
+ it("should convert text_align to text-align", () => {
307
+ const result = genSafePropertyName("text_align");
308
+ expect(result).toBe("text-align");
309
+ });
310
+
311
+ it("should convert border_bottom_width to border-bottom-width", () => {
312
+ const result = genSafePropertyName("border_bottom_width");
313
+ expect(result).toBe("border-bottom-width");
314
+ });
315
+ });
316
+
317
+ describe("properties with spaces", () => {
318
+ it("should preserve spaces in 'background color'", () => {
319
+ const result = genSafePropertyName("background color");
320
+ expect(result).toBe("background color");
321
+ });
322
+
323
+ it("should preserve spaces in 'font size'", () => {
324
+ const result = genSafePropertyName("font size");
325
+ expect(result).toBe("font size");
326
+ });
327
+
328
+ it("should handle 'Border Bottom Width' with mixed case and spaces", () => {
329
+ const result = genSafePropertyName("Border Bottom Width");
330
+ expect(result).toBe("border -bottom -width");
331
+ });
332
+
333
+ it("should preserve multiple spaces", () => {
334
+ const result = genSafePropertyName("background color");
335
+ expect(result).toBe("background color");
336
+ });
337
+
338
+ it("should preserve leading spaces with camelCase", () => {
339
+ const result = genSafePropertyName(" backgroundColor");
340
+ expect(result).toBe(" background-color");
341
+ });
342
+
343
+ it("should preserve trailing spaces with camelCase", () => {
344
+ const result = genSafePropertyName("backgroundColor ");
345
+ expect(result).toBe("background-color ");
346
+ });
347
+ });
348
+
349
+ describe("custom properties (CSS variables)", () => {
350
+ it("should handle --custom-property", () => {
351
+ const result = genSafePropertyName("--custom-property");
352
+ expect(result).toBe("--custom-property");
353
+ });
354
+
355
+ it("should handle --theme-color-primary", () => {
356
+ const result = genSafePropertyName("--theme-color-primary");
357
+ expect(result).toBe("--theme-color-primary");
358
+ });
359
+
360
+ it("should handle --spacing-large", () => {
361
+ const result = genSafePropertyName("--spacing-large");
362
+ expect(result).toBe("--spacing-large");
363
+ });
364
+
365
+ it("should convert camelCase custom property", () => {
366
+ const result = genSafePropertyName("--primaryColor");
367
+ expect(result).toBe("--primary-color");
368
+ });
369
+
370
+ it("should convert PascalCase custom property", () => {
371
+ const result = genSafePropertyName("--PrimaryColor");
372
+ expect(result).toBe("--primary-color");
373
+ });
374
+ });
375
+
376
+ describe("edge cases", () => {
377
+ it("should handle empty string", () => {
378
+ const result = genSafePropertyName("");
379
+ expect(result).toBe("");
380
+ });
381
+
382
+ it("should handle property with numbers", () => {
383
+ const result = genSafePropertyName("grid2Columns");
384
+ expect(result).toBe("grid2-columns");
385
+ });
386
+
387
+ it("should handle property starting with number", () => {
388
+ const result = genSafePropertyName("2Columns");
389
+ expect(result).toBe("2-columns");
390
+ });
391
+
392
+ it("should handle all caps", () => {
393
+ const result = genSafePropertyName("BACKGROUNDCOLOR");
394
+ expect(result).toBe("backgroundcolor");
395
+ });
396
+
397
+ it("should handle mixed caps", () => {
398
+ const result = genSafePropertyName("BACKGROUNDColor");
399
+ expect(result).toBe("background-color");
400
+ });
401
+
402
+ it("should handle consecutive capitals", () => {
403
+ const result = genSafePropertyName("XMLHttpRequest");
404
+ expect(result).toBe("xml-http-request");
405
+ });
406
+
407
+ it("should handle acronyms in property names", () => {
408
+ const result = genSafePropertyName("htmlFontSize");
409
+ expect(result).toBe("html-font-size");
410
+ });
411
+
412
+ it("should handle property with dots", () => {
413
+ const result = genSafePropertyName("background.color");
414
+ expect(result).toBe("background-color");
415
+ });
416
+
417
+ it("should handle property with forward slash", () => {
418
+ const result = genSafePropertyName("background/color");
419
+ expect(result).toBe("background-color");
420
+ });
421
+
422
+ it("should preserve colon in property name", () => {
423
+ const result = genSafePropertyName("background:color");
424
+ expect(result).toBe("background:color");
425
+ });
426
+
427
+ it("should handle single letter", () => {
428
+ const result = genSafePropertyName("x");
429
+ expect(result).toBe("x");
430
+ });
431
+
432
+ it("should handle two letter camelCase", () => {
433
+ const result = genSafePropertyName("xY");
434
+ expect(result).toBe("x-y");
435
+ });
436
+ });
437
+
438
+ describe("special CSS property patterns", () => {
439
+ it("should handle gridTemplateAreas", () => {
440
+ const result = genSafePropertyName("gridTemplateAreas");
441
+ expect(result).toBe("grid-template-areas");
442
+ });
443
+
444
+ it("should handle willChange", () => {
445
+ const result = genSafePropertyName("willChange");
446
+ expect(result).toBe("will-change");
447
+ });
448
+
449
+ it("should handle counterReset", () => {
450
+ const result = genSafePropertyName("counterReset");
451
+ expect(result).toBe("counter-reset");
452
+ });
453
+
454
+ it("should handle listStyleType", () => {
455
+ const result = genSafePropertyName("listStyleType");
456
+ expect(result).toBe("list-style-type");
457
+ });
458
+
459
+ it("should handle borderTopLeftRadius", () => {
460
+ const result = genSafePropertyName("borderTopLeftRadius");
461
+ expect(result).toBe("border-top-left-radius");
462
+ });
463
+
464
+ it("should handle scrollBehavior", () => {
465
+ const result = genSafePropertyName("scrollBehavior");
466
+ expect(result).toBe("scroll-behavior");
467
+ });
468
+
469
+ it("should handle backdropFilter", () => {
470
+ const result = genSafePropertyName("backdropFilter");
471
+ expect(result).toBe("backdrop-filter");
472
+ });
473
+
474
+ it("should handle clipPath", () => {
475
+ const result = genSafePropertyName("clipPath");
476
+ expect(result).toBe("clip-path");
477
+ });
478
+
479
+ it("should handle objectFit", () => {
480
+ const result = genSafePropertyName("objectFit");
481
+ expect(result).toBe("object-fit");
482
+ });
483
+
484
+ it("should handle userSelect", () => {
485
+ const result = genSafePropertyName("userSelect");
486
+ expect(result).toBe("user-select");
487
+ });
488
+ });
489
+ });
@@ -0,0 +1,5 @@
1
+ import { toKebabCase } from "../utils";
2
+
3
+ export function genSafePropertyName(name: string): string {
4
+ return toKebabCase(name);
5
+ }