@styleframe/theme 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 (64) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/LICENSE +21 -0
  3. package/dist/theme.d.ts +772 -0
  4. package/dist/theme.js +2507 -0
  5. package/dist/theme.umd.cjs +4 -0
  6. package/package.json +14 -4
  7. package/.tsbuildinfo +0 -1
  8. package/src/constants/border.ts +0 -0
  9. package/src/constants/breakpoint.ts +0 -0
  10. package/src/constants/color.ts +0 -0
  11. package/src/constants/index.ts +0 -4
  12. package/src/constants/scale.ts +0 -3
  13. package/src/constants/typography.ts +0 -0
  14. package/src/index.ts +0 -4
  15. package/src/shims.d.ts +0 -8
  16. package/src/types.ts +0 -32
  17. package/src/utils/createUseVariable.test.ts +0 -928
  18. package/src/utils/createUseVariable.ts +0 -107
  19. package/src/utils/index.ts +0 -1
  20. package/src/variables/index.ts +0 -20
  21. package/src/variables/useBorderColor.ts +0 -27
  22. package/src/variables/useBorderRadius.test.ts +0 -335
  23. package/src/variables/useBorderRadius.ts +0 -26
  24. package/src/variables/useBorderStyle.test.ts +0 -569
  25. package/src/variables/useBorderStyle.ts +0 -49
  26. package/src/variables/useBorderWidth.test.ts +0 -535
  27. package/src/variables/useBorderWidth.ts +0 -38
  28. package/src/variables/useBoxShadow.test.ts +0 -336
  29. package/src/variables/useBoxShadow.ts +0 -54
  30. package/src/variables/useBreakpoint.test.ts +0 -447
  31. package/src/variables/useBreakpoint.ts +0 -38
  32. package/src/variables/useColor.test.ts +0 -360
  33. package/src/variables/useColor.ts +0 -35
  34. package/src/variables/useColorLightness.test.ts +0 -168
  35. package/src/variables/useColorLightness.ts +0 -59
  36. package/src/variables/useColorShade.test.ts +0 -166
  37. package/src/variables/useColorShade.ts +0 -52
  38. package/src/variables/useColorTint.test.ts +0 -164
  39. package/src/variables/useColorTint.ts +0 -52
  40. package/src/variables/useEasing.ts +0 -0
  41. package/src/variables/useFontFamily.test.ts +0 -228
  42. package/src/variables/useFontFamily.ts +0 -33
  43. package/src/variables/useFontSize.test.ts +0 -299
  44. package/src/variables/useFontSize.ts +0 -32
  45. package/src/variables/useFontStyle.test.ts +0 -555
  46. package/src/variables/useFontStyle.ts +0 -37
  47. package/src/variables/useFontWeight.test.ts +0 -650
  48. package/src/variables/useFontWeight.ts +0 -55
  49. package/src/variables/useLetterSpacing.test.ts +0 -455
  50. package/src/variables/useLetterSpacing.ts +0 -41
  51. package/src/variables/useLineHeight.test.ts +0 -410
  52. package/src/variables/useLineHeight.ts +0 -41
  53. package/src/variables/useMultiplier.test.ts +0 -722
  54. package/src/variables/useMultiplier.ts +0 -44
  55. package/src/variables/useScale.test.ts +0 -393
  56. package/src/variables/useScale.ts +0 -52
  57. package/src/variables/useScalePowers.test.ts +0 -412
  58. package/src/variables/useScalePowers.ts +0 -35
  59. package/src/variables/useSpacing.test.ts +0 -309
  60. package/src/variables/useSpacing.ts +0 -26
  61. package/src/vite-env.d.ts +0 -1
  62. package/test-scale.js +0 -22
  63. package/tsconfig.json +0 -7
  64. package/vite.config.ts +0 -5
@@ -1,722 +0,0 @@
1
- import type { CSS, Variable } from "@styleframe/core";
2
- import { styleframe } from "@styleframe/core";
3
- import { consume } from "@styleframe/transpiler";
4
- import { useMultiplier } from "./useMultiplier";
5
- import { useScale } from "./useScale";
6
- import { useScalePowers } from "./useScalePowers";
7
-
8
- describe("useMultiplier", () => {
9
- it("should create a single multiplied variable with 'default' key", () => {
10
- const s = styleframe();
11
- const baseVar = s.variable("font-size", "1rem");
12
- const { fontSize } = useMultiplier(s, baseVar, {
13
- default: 1,
14
- });
15
-
16
- expect(fontSize.type).toBe("variable");
17
- expect(fontSize.name).toBe("font-size");
18
- expect(fontSize.value).toBe("1rem");
19
-
20
- const css = consume(fontSize, s.options);
21
- expect(css).toBe(`--font-size: 1rem;`);
22
- });
23
-
24
- it("should create multiplied variable with modifier for non-default keys", () => {
25
- const s = styleframe();
26
- const baseVar = s.variable("font-size", "1rem");
27
- const { fontSizeSm } = useMultiplier(s, baseVar, {
28
- sm: 0.875,
29
- });
30
-
31
- expect(fontSizeSm.type).toBe("variable");
32
- expect(fontSizeSm.name).toBe("font-size--sm");
33
- expect((fontSizeSm.value as CSS)?.type).toBe("css");
34
-
35
- const css = consume(fontSizeSm, s.options);
36
- expect(css).toBe(`--font-size--sm: calc(var(--font-size) * 0.875);`);
37
- });
38
-
39
- it("should create multiple multiplied variables", () => {
40
- const s = styleframe();
41
- const baseVar = s.variable("spacing", "1rem");
42
- const { spacing, spacingSm, spacingLg } = useMultiplier(s, baseVar, {
43
- default: 1,
44
- sm: 0.5,
45
- lg: 2,
46
- });
47
-
48
- expect(spacing.type).toBe("variable");
49
- expect(spacing.name).toBe("spacing");
50
- expect(spacing.value).toBe("1rem");
51
-
52
- expect(spacingSm.type).toBe("variable");
53
- expect(spacingSm.name).toBe("spacing--sm");
54
- expect((spacingSm.value as CSS)?.type).toBe("css");
55
-
56
- expect(spacingLg.type).toBe("variable");
57
- expect(spacingLg.name).toBe("spacing--lg");
58
- expect((spacingLg.value as CSS)?.type).toBe("css");
59
- });
60
-
61
- it("should add variables to root", () => {
62
- const s = styleframe();
63
- const baseVar = s.variable("size", "1rem");
64
- useMultiplier(s, baseVar, {
65
- sm: 0.75,
66
- lg: 1.5,
67
- });
68
-
69
- expect(s.root.variables).toHaveLength(3); // base + sm + lg
70
- expect(s.root.variables[0]?.name).toBe("size");
71
- expect(s.root.variables[1]?.name).toBe("size--sm");
72
- expect(s.root.variables[2]?.name).toBe("size--lg");
73
- });
74
-
75
- it("should handle kebab-case modifier names", () => {
76
- const s = styleframe();
77
- const baseVar = s.variable("font-size", "1rem");
78
- const { fontSizeExtraLarge } = useMultiplier(s, baseVar, {
79
- "extra-large": 2.5,
80
- });
81
-
82
- expect(fontSizeExtraLarge.type).toBe("variable");
83
- expect(fontSizeExtraLarge.name).toBe("font-size--extra-large");
84
- expect((fontSizeExtraLarge.value as CSS)?.type).toBe("css");
85
- });
86
-
87
- it("should handle snake_case modifier names", () => {
88
- const s = styleframe();
89
- const baseVar = s.variable("spacing", "1rem");
90
- const { spacingVeryLarge } = useMultiplier(s, baseVar, {
91
- very_large: 3,
92
- });
93
-
94
- expect(spacingVeryLarge.type).toBe("variable");
95
- expect(spacingVeryLarge.name).toBe("spacing--very_large");
96
- expect((spacingVeryLarge.value as CSS)?.type).toBe("css");
97
- });
98
-
99
- it("should handle numeric modifier names", () => {
100
- const s = styleframe();
101
- const baseVar = s.variable("scale", "1rem");
102
- const { scale2 } = useMultiplier(s, baseVar, {
103
- "2": 2,
104
- });
105
-
106
- expect(scale2.type).toBe("variable");
107
- expect(scale2.name).toBe("scale--2");
108
- expect((scale2.value as CSS)?.type).toBe("css");
109
- });
110
-
111
- it("should handle decimal multipliers", () => {
112
- const s = styleframe();
113
- const baseVar = s.variable("font-size", "1rem");
114
- const { fontSizeXs } = useMultiplier(s, baseVar, {
115
- xs: 0.75,
116
- });
117
-
118
- expect((fontSizeXs.value as CSS)?.type).toBe("css");
119
- });
120
-
121
- it("should handle negative multipliers", () => {
122
- const s = styleframe();
123
- const baseVar = s.variable("offset", "10px");
124
- const { offsetReverse } = useMultiplier(s, baseVar, {
125
- reverse: -1,
126
- });
127
-
128
- expect((offsetReverse.value as CSS)?.type).toBe("css");
129
- });
130
-
131
- it("should handle zero multiplier", () => {
132
- const s = styleframe();
133
- const baseVar = s.variable("spacing", "1rem");
134
- const { spacingNone } = useMultiplier(s, baseVar, {
135
- none: 0,
136
- });
137
-
138
- expect((spacingNone.value as CSS)?.type).toBe("css");
139
- });
140
-
141
- it("should handle large multipliers", () => {
142
- const s = styleframe();
143
- const baseVar = s.variable("size", "1rem");
144
- const { sizeHuge } = useMultiplier(s, baseVar, {
145
- huge: 10,
146
- });
147
-
148
- expect((sizeHuge.value as CSS)?.type).toBe("css");
149
- });
150
-
151
- it("should handle very small multipliers", () => {
152
- const s = styleframe();
153
- const baseVar = s.variable("font-size", "1rem");
154
- const { fontSizeTiny } = useMultiplier(s, baseVar, {
155
- tiny: 0.125,
156
- });
157
-
158
- expect((fontSizeTiny.value as CSS)?.type).toBe("css");
159
- });
160
-
161
- it("should handle empty multiplier object", () => {
162
- const s = styleframe();
163
- const baseVar = s.variable("size", "1rem");
164
- const result = useMultiplier(s, baseVar, {});
165
-
166
- expect(result).toEqual({});
167
- expect(s.root.variables).toHaveLength(1); // Only the base variable
168
- });
169
-
170
- it("should handle variable references as multipliers", () => {
171
- const s = styleframe();
172
- const baseVar = s.variable("font-size", "1rem");
173
- const scaleVar = s.variable("scale", "1.5");
174
- const { fontSizeLg } = useMultiplier(s, baseVar, {
175
- lg: s.ref(scaleVar),
176
- });
177
-
178
- expect((fontSizeLg.value as CSS)?.type).toBe("css");
179
- });
180
-
181
- it("should compile to correct CSS output using consume", () => {
182
- const s = styleframe();
183
- const baseVar = s.variable("font-size", "1rem");
184
- useMultiplier(s, baseVar, {
185
- xs: 0.75,
186
- sm: 0.875,
187
- lg: 1.25,
188
- });
189
-
190
- const css = consume(s.root, s.options);
191
-
192
- expect(css).toBe(`:root {
193
- --font-size: 1rem;
194
- --font-size--xs: calc(var(--font-size) * 0.75);
195
- --font-size--sm: calc(var(--font-size) * 0.875);
196
- --font-size--lg: calc(var(--font-size) * 1.25);
197
- }`);
198
- });
199
-
200
- it("should work with scale powers for typography", () => {
201
- const s = styleframe();
202
- const fontSize = s.variable("font-size", "1rem");
203
- const scalePowers = {
204
- "-2": 0.563,
205
- "-1": 0.75,
206
- "1": 1.333,
207
- "2": 1.777,
208
- };
209
-
210
- const { fontSizeXs, fontSizeSm, fontSizeLg, fontSizeXl } = useMultiplier(
211
- s,
212
- fontSize,
213
- {
214
- xs: scalePowers["-2"],
215
- sm: scalePowers["-1"],
216
- lg: scalePowers["1"],
217
- xl: scalePowers["2"],
218
- },
219
- );
220
-
221
- expect((fontSizeXs.value as CSS)?.type).toBe("css");
222
- expect((fontSizeSm.value as CSS)?.type).toBe("css");
223
- expect((fontSizeLg.value as CSS)?.type).toBe("css");
224
- expect((fontSizeXl.value as CSS)?.type).toBe("css");
225
- });
226
-
227
- it("should work with spacing scale", () => {
228
- const s = styleframe();
229
- const spacing = s.variable("spacing", "1rem");
230
-
231
- const {
232
- spacing2xs,
233
- spacingXs,
234
- spacingSm,
235
- spacingMd,
236
- spacingLg,
237
- spacingXl,
238
- } = useMultiplier(s, spacing, {
239
- "2xs": 0.25,
240
- xs: 0.5,
241
- sm: 0.75,
242
- md: 1,
243
- lg: 1.5,
244
- xl: 2,
245
- });
246
-
247
- expect(spacing2xs.name).toBe("spacing--2xs");
248
- expect(spacingXs.name).toBe("spacing--xs");
249
- expect(spacingSm.name).toBe("spacing--sm");
250
- expect(spacingMd.name).toBe("spacing--md");
251
- expect(spacingLg.name).toBe("spacing--lg");
252
- expect(spacingXl.name).toBe("spacing--xl");
253
- });
254
-
255
- it("should handle complex variable names", () => {
256
- const s = styleframe();
257
- const baseVar = s.variable("component-font-size", "1rem");
258
- const { componentFontSizeLg } = useMultiplier(s, baseVar, {
259
- lg: 1.5,
260
- });
261
-
262
- expect(componentFontSizeLg.type).toBe("variable");
263
- expect(componentFontSizeLg.name).toBe("component-font-size--lg");
264
- expect((componentFontSizeLg.value as CSS)?.type).toBe("css");
265
- });
266
-
267
- it("should preserve base variable unchanged", () => {
268
- const s = styleframe();
269
- const baseVar = s.variable("size", "1rem");
270
- const originalValue = baseVar.value;
271
-
272
- useMultiplier(s, baseVar, {
273
- sm: 0.5,
274
- lg: 2,
275
- });
276
-
277
- expect(baseVar.value).toBe(originalValue);
278
- expect(baseVar.value).toBe("1rem");
279
- });
280
-
281
- it("should handle string number multipliers", () => {
282
- const s = styleframe();
283
- const baseVar = s.variable("scale", "1rem");
284
- const { scaleMd } = useMultiplier(s, baseVar, {
285
- md: "1.5",
286
- });
287
-
288
- expect((scaleMd.value as CSS)?.type).toBe("css");
289
- });
290
-
291
- it("should work with CSS custom properties in base variable", () => {
292
- const s = styleframe();
293
- const scale = s.variable("scale", "1.5");
294
- const baseVar = s.variable("font-size", s.ref(scale));
295
- const { fontSizeLg } = useMultiplier(s, baseVar, {
296
- lg: 2,
297
- });
298
-
299
- expect((fontSizeLg.value as CSS)?.type).toBe("css");
300
- });
301
-
302
- describe("type safety", () => {
303
- it("should preserve exact variable names in return type", () => {
304
- const s = styleframe();
305
- const baseVar = s.variable("font-size", "1rem");
306
- const sizes = useMultiplier(s, baseVar, {
307
- sm: 0.875,
308
- lg: 1.25,
309
- });
310
-
311
- // Type assertions to verify the generic types are preserved
312
- const smSize: Variable<"font-size--sm"> = sizes.fontSizeSm;
313
- const lgSize: Variable<"font-size--lg"> = sizes.fontSizeLg;
314
-
315
- expect(smSize.name).toBe("font-size--sm");
316
- expect(lgSize.name).toBe("font-size--lg");
317
- });
318
-
319
- it("should maintain type information for kebab-case names", () => {
320
- const s = styleframe();
321
- const baseVar = s.variable("spacing", "1rem");
322
- const { spacingExtraLarge } = useMultiplier(s, baseVar, {
323
- "extra-large": 3,
324
- });
325
-
326
- const typed: Variable<"spacing--extra-large"> = spacingExtraLarge;
327
- expect(typed.name).toBe("spacing--extra-large");
328
- });
329
-
330
- it("should work with const assertion", () => {
331
- const s = styleframe();
332
- const baseVar = s.variable("size", "1rem");
333
- const sizeConfig = {
334
- sm: 0.5,
335
- lg: 2,
336
- } as const;
337
-
338
- const sizes = useMultiplier(s, baseVar, sizeConfig);
339
-
340
- expect(sizes.sizeSm.name).toBe("size--sm");
341
- expect(sizes.sizeLg.name).toBe("size--lg");
342
- });
343
-
344
- it("should handle default key with proper typing", () => {
345
- const s = styleframe();
346
- const baseVar = s.variable("font-size", "1rem");
347
- const { fontSize } = useMultiplier(s, baseVar, {
348
- default: 1,
349
- });
350
-
351
- const typed: Variable<"font-size"> = fontSize;
352
- expect(typed.name).toBe("font-size");
353
- });
354
- });
355
-
356
- describe("integration with real-world scenarios", () => {
357
- it("should create a complete typographic scale", () => {
358
- const s = styleframe();
359
- const fontSize = s.variable("font-size", "1rem");
360
-
361
- const scale = useMultiplier(s, fontSize, {
362
- xs: 0.75,
363
- sm: 0.875,
364
- default: 1,
365
- md: 1,
366
- lg: 1.125,
367
- xl: 1.25,
368
- "2xl": 1.5,
369
- "3xl": 1.875,
370
- "4xl": 2.25,
371
- });
372
-
373
- expect(Object.keys(scale)).toHaveLength(9);
374
- expect(scale.fontSizeXs.name).toBe("font-size--xs");
375
- expect(scale.fontSize4xl.name).toBe("font-size--4xl");
376
- });
377
-
378
- it("should create a spacing scale system", () => {
379
- const s = styleframe();
380
- const spacing = s.variable("spacing", "0.25rem");
381
-
382
- const scale = useMultiplier(s, spacing, {
383
- "0": 0,
384
- "1": 1,
385
- "2": 2,
386
- "3": 3,
387
- "4": 4,
388
- "6": 6,
389
- "8": 8,
390
- "12": 12,
391
- "16": 16,
392
- });
393
-
394
- expect(scale.spacing0.name).toBe("spacing--0");
395
- expect(scale.spacing16.name).toBe("spacing--16");
396
- });
397
-
398
- it("should work with ratio scale", () => {
399
- const s = styleframe();
400
- const base = s.variable("size", "1rem");
401
-
402
- const { scale } = useScale(s);
403
- const scales = useScalePowers(s, scale);
404
-
405
- const sizes = useMultiplier(s, base, {
406
- xs: scales[-2],
407
- sm: scales[-1],
408
- md: scales[0],
409
- lg: scales[1],
410
- xl: scales[2],
411
- });
412
-
413
- expect(sizes.sizeXs.name).toBe("size--xs");
414
- expect(sizes.sizeXs.value).toMatchObject({ type: "css" });
415
- expect(sizes.sizeSm.name).toBe("size--sm");
416
- expect(sizes.sizeSm.value).toMatchObject({ type: "css" });
417
- expect(sizes.sizeMd.name).toBe("size--md");
418
- expect(sizes.sizeMd.value).toMatchObject({ type: "css" });
419
- expect(sizes.sizeLg.name).toBe("size--lg");
420
- expect(sizes.sizeLg.value).toMatchObject({ type: "css" });
421
- expect(sizes.sizeXl.name).toBe("size--xl");
422
- expect(sizes.sizeXl.value).toMatchObject({ type: "css" });
423
- });
424
- });
425
-
426
- describe("transpiling", () => {
427
- it("should transpile single multiplied variable correctly", () => {
428
- const s = styleframe();
429
- const baseVar = s.variable("font-size", "1rem");
430
- const { fontSizeLg } = useMultiplier(s, baseVar, {
431
- lg: 1.5,
432
- });
433
-
434
- const css = consume(fontSizeLg, s.options);
435
- expect(css).toBe(`--font-size--lg: calc(var(--font-size) * 1.5);`);
436
- });
437
-
438
- it("should transpile multiple multiplied variables correctly", () => {
439
- const s = styleframe();
440
- const baseVar = s.variable("spacing", "1rem");
441
- useMultiplier(s, baseVar, {
442
- xs: 0.5,
443
- sm: 0.75,
444
- md: 1,
445
- lg: 1.5,
446
- xl: 2,
447
- });
448
-
449
- const css = consume(s.root, s.options);
450
- expect(css).toBe(`:root {
451
- --spacing: 1rem;
452
- --spacing--xs: calc(var(--spacing) * 0.5);
453
- --spacing--sm: calc(var(--spacing) * 0.75);
454
- --spacing--md: calc(var(--spacing) * 1);
455
- --spacing--lg: calc(var(--spacing) * 1.5);
456
- --spacing--xl: calc(var(--spacing) * 2);
457
- }`);
458
- });
459
-
460
- it("should transpile negative multipliers correctly", () => {
461
- const s = styleframe();
462
- const baseVar = s.variable("offset", "10px");
463
- const { offsetReverse } = useMultiplier(s, baseVar, {
464
- reverse: -1,
465
- });
466
-
467
- const css = consume(offsetReverse, s.options);
468
- expect(css).toBe(`--offset--reverse: calc(var(--offset) * -1);`);
469
- });
470
-
471
- it("should transpile decimal multipliers correctly", () => {
472
- const s = styleframe();
473
- const baseVar = s.variable("font-size", "1rem");
474
- useMultiplier(s, baseVar, {
475
- xs: 0.75,
476
- sm: 0.875,
477
- });
478
-
479
- const css = consume(s.root, s.options);
480
- expect(css).toBe(`:root {
481
- --font-size: 1rem;
482
- --font-size--xs: calc(var(--font-size) * 0.75);
483
- --font-size--sm: calc(var(--font-size) * 0.875);
484
- }`);
485
- });
486
-
487
- it("should transpile variable references as multipliers", () => {
488
- const s = styleframe();
489
- const baseVar = s.variable("font-size", "1rem");
490
- const scaleVar = s.variable("scale", "1.333");
491
- useMultiplier(s, baseVar, {
492
- lg: s.ref(scaleVar),
493
- });
494
-
495
- const css = consume(s.root, s.options);
496
- expect(css).toBe(`:root {
497
- --font-size: 1rem;
498
- --scale: 1.333;
499
- --font-size--lg: calc(var(--font-size) * var(--scale));
500
- }`);
501
- });
502
-
503
- it("should transpile with kebab-case names correctly", () => {
504
- const s = styleframe();
505
- const baseVar = s.variable("line-height", "1.5");
506
- useMultiplier(s, baseVar, {
507
- "extra-tight": 0.8,
508
- tight: 0.9,
509
- normal: 1,
510
- loose: 1.1,
511
- "extra-loose": 1.2,
512
- });
513
-
514
- const css = consume(s.root, s.options);
515
- expect(css).toBe(`:root {
516
- --line-height: 1.5;
517
- --line-height--extra-tight: calc(var(--line-height) * 0.8);
518
- --line-height--tight: calc(var(--line-height) * 0.9);
519
- --line-height--normal: calc(var(--line-height) * 1);
520
- --line-height--loose: calc(var(--line-height) * 1.1);
521
- --line-height--extra-loose: calc(var(--line-height) * 1.2);
522
- }`);
523
- });
524
-
525
- it("should transpile with numeric keys correctly", () => {
526
- const s = styleframe();
527
- const baseVar = s.variable("spacing", "0.25rem");
528
- useMultiplier(s, baseVar, {
529
- "0": 0,
530
- "1": 1,
531
- "2": 2,
532
- "4": 4,
533
- "8": 8,
534
- });
535
-
536
- const css = consume(s.root, s.options);
537
- expect(css).toBe(`:root {
538
- --spacing: 0.25rem;
539
- --spacing--0: calc(var(--spacing) * 0);
540
- --spacing--1: calc(var(--spacing) * 1);
541
- --spacing--2: calc(var(--spacing) * 2);
542
- --spacing--4: calc(var(--spacing) * 4);
543
- --spacing--8: calc(var(--spacing) * 8);
544
- }`);
545
- });
546
-
547
- it("should transpile complete typography scale", () => {
548
- const s = styleframe();
549
- const fontSize = s.variable("font-size", "1rem");
550
- useMultiplier(s, fontSize, {
551
- xs: 0.75,
552
- sm: 0.875,
553
- md: 1,
554
- lg: 1.125,
555
- xl: 1.25,
556
- "2xl": 1.5,
557
- "3xl": 1.875,
558
- });
559
-
560
- const css = consume(s.root, s.options);
561
- expect(css).toBe(`:root {
562
- --font-size: 1rem;
563
- --font-size--xs: calc(var(--font-size) * 0.75);
564
- --font-size--sm: calc(var(--font-size) * 0.875);
565
- --font-size--md: calc(var(--font-size) * 1);
566
- --font-size--lg: calc(var(--font-size) * 1.125);
567
- --font-size--xl: calc(var(--font-size) * 1.25);
568
- --font-size--2xl: calc(var(--font-size) * 1.5);
569
- --font-size--3xl: calc(var(--font-size) * 1.875);
570
- }`);
571
- });
572
-
573
- it("should transpile when base variable uses a reference", () => {
574
- const s = styleframe();
575
- const baseSize = s.variable("base-size", "16px");
576
- const fontSize = s.variable("font-size", s.ref(baseSize));
577
- useMultiplier(s, fontSize, {
578
- sm: 0.875,
579
- lg: 1.25,
580
- });
581
-
582
- const css = consume(s.root, s.options);
583
- expect(css).toBe(`:root {
584
- --base-size: 16px;
585
- --font-size: var(--base-size);
586
- --font-size--sm: calc(var(--font-size) * 0.875);
587
- --font-size--lg: calc(var(--font-size) * 1.25);
588
- }`);
589
- });
590
-
591
- it("should transpile with very precise decimal values", () => {
592
- const s = styleframe();
593
- const baseVar = s.variable("size", "1rem");
594
- const golden = 1.618;
595
-
596
- useMultiplier(s, baseVar, {
597
- "-1": Math.pow(golden, -1),
598
- "1": golden,
599
- "2": Math.pow(golden, 2),
600
- });
601
-
602
- const css = consume(s.root, s.options);
603
- expect(css).toContain(`--size: 1rem;`);
604
- expect(css).toContain(
605
- `--size---1: calc(var(--size) * ${Math.pow(golden, -1)});`,
606
- );
607
- expect(css).toContain(`--size--1: calc(var(--size) * ${golden});`);
608
- expect(css).toContain(
609
- `--size--2: calc(var(--size) * ${Math.pow(golden, 2)});`,
610
- );
611
- });
612
-
613
- it("should transpile with complex variable names", () => {
614
- const s = styleframe();
615
- const baseVar = s.variable("component-button-padding", "0.5rem");
616
- useMultiplier(s, baseVar, {
617
- sm: 0.75,
618
- md: 1,
619
- lg: 1.5,
620
- });
621
-
622
- const css = consume(s.root, s.options);
623
- expect(css).toBe(`:root {
624
- --component-button-padding: 0.5rem;
625
- --component-button-padding--sm: calc(var(--component-button-padding) * 0.75);
626
- --component-button-padding--md: calc(var(--component-button-padding) * 1);
627
- --component-button-padding--lg: calc(var(--component-button-padding) * 1.5);
628
- }`);
629
- });
630
-
631
- it("should transpile zero multiplier correctly", () => {
632
- const s = styleframe();
633
- const baseVar = s.variable("margin", "1rem");
634
- const { marginNone } = useMultiplier(s, baseVar, {
635
- none: 0,
636
- });
637
-
638
- const css = consume(marginNone, s.options);
639
- expect(css).toBe(`--margin--none: calc(var(--margin) * 0);`);
640
- });
641
-
642
- it("should transpile with string number multipliers", () => {
643
- const s = styleframe();
644
- const baseVar = s.variable("scale", "1rem");
645
- useMultiplier(s, baseVar, {
646
- md: "1.5",
647
- lg: "2",
648
- });
649
-
650
- const css = consume(s.root, s.options);
651
- expect(css).toBe(`:root {
652
- --scale: 1rem;
653
- --scale--md: calc(var(--scale) * 1.5);
654
- --scale--lg: calc(var(--scale) * 2);
655
- }`);
656
- });
657
-
658
- it("should transpile multiple base variables with multipliers", () => {
659
- const s = styleframe();
660
- const fontSize = s.variable("font-size", "1rem");
661
- const spacing = s.variable("spacing", "0.5rem");
662
-
663
- useMultiplier(s, fontSize, {
664
- sm: 0.875,
665
- lg: 1.25,
666
- });
667
-
668
- useMultiplier(s, spacing, {
669
- sm: 0.5,
670
- lg: 2,
671
- });
672
-
673
- const css = consume(s.root, s.options);
674
- expect(css).toBe(`:root {
675
- --font-size: 1rem;
676
- --spacing: 0.5rem;
677
- --font-size--sm: calc(var(--font-size) * 0.875);
678
- --font-size--lg: calc(var(--font-size) * 1.25);
679
- --spacing--sm: calc(var(--spacing) * 0.5);
680
- --spacing--lg: calc(var(--spacing) * 2);
681
- }`);
682
- });
683
-
684
- it("should work with ratio scale", () => {
685
- const s = styleframe();
686
- const base = s.variable("size", "1rem");
687
-
688
- const { scale } = useScale(s);
689
- const scales = useScalePowers(s, scale);
690
-
691
- useMultiplier(s, base, {
692
- xs: scales[-2],
693
- sm: scales[-1],
694
- md: scales[0],
695
- lg: scales[1],
696
- xl: scales[2],
697
- xxl: scales[3],
698
- });
699
-
700
- const css = consume(s.root, s.options);
701
-
702
- expect(css).toEqual(`:root {
703
- --size: 1rem;
704
- --scale--minor-second: 1.067;
705
- --scale--major-second: 1.125;
706
- --scale--minor-third: 1.2;
707
- --scale--major-third: 1.25;
708
- --scale--perfect-fourth: 1.333;
709
- --scale--augmented-fourth: 1.414;
710
- --scale--perfect-fifth: 1.5;
711
- --scale--golden: 1.618;
712
- --scale: var(--scale--minor-third);
713
- --size--xs: calc(var(--size) * 1 / var(--scale) / var(--scale));
714
- --size--sm: calc(var(--size) * 1 / var(--scale));
715
- --size--md: calc(var(--size) * 1);
716
- --size--lg: calc(var(--size) * var(--scale));
717
- --size--xl: calc(var(--size) * var(--scale) * var(--scale));
718
- --size--xxl: calc(var(--size) * var(--scale) * var(--scale) * var(--scale));
719
- }`);
720
- });
721
- });
722
- });