@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,535 +0,0 @@
1
- import type { Variable } from "@styleframe/core";
2
- import { styleframe } from "@styleframe/core";
3
- import { consume } from "@styleframe/transpiler";
4
- import { defaultBorderWidthValues, useBorderWidth } from "./useBorderWidth";
5
-
6
- describe("useBorderWidth", () => {
7
- it("should create all border width variables with correct names and values", () => {
8
- const s = styleframe();
9
- const {
10
- borderWidthNone,
11
- borderWidthThin,
12
- borderWidthMedium,
13
- borderWidthThick,
14
- borderWidth,
15
- } = useBorderWidth(s);
16
-
17
- expect(borderWidthNone).toEqual({
18
- type: "variable",
19
- name: "border-width--none",
20
- value: 0,
21
- });
22
-
23
- expect(borderWidthThin).toEqual({
24
- type: "variable",
25
- name: "border-width--thin",
26
- value: "thin",
27
- });
28
-
29
- expect(borderWidthMedium).toEqual({
30
- type: "variable",
31
- name: "border-width--medium",
32
- value: "medium",
33
- });
34
-
35
- expect(borderWidthThick).toEqual({
36
- type: "variable",
37
- name: "border-width--thick",
38
- value: "thick",
39
- });
40
-
41
- expect(borderWidth).toEqual({
42
- type: "variable",
43
- name: "border-width",
44
- value: {
45
- type: "reference",
46
- name: "border-width--thin",
47
- fallback: undefined,
48
- },
49
- });
50
- });
51
-
52
- it("should add all border width variables to root", () => {
53
- const s = styleframe();
54
- useBorderWidth(s);
55
-
56
- expect(s.root.variables).toHaveLength(5);
57
- expect(s.root.variables[0]?.name).toBe("border-width--none");
58
- expect(s.root.variables[1]?.name).toBe("border-width--thin");
59
- expect(s.root.variables[2]?.name).toBe("border-width--medium");
60
- expect(s.root.variables[3]?.name).toBe("border-width--thick");
61
- expect(s.root.variables[4]?.name).toBe("border-width");
62
- });
63
-
64
- it("should return all border width variables in an object", () => {
65
- const s = styleframe();
66
- const borderWidths = useBorderWidth(s);
67
-
68
- expect(Object.keys(borderWidths)).toEqual([
69
- "borderWidthNone",
70
- "borderWidthThin",
71
- "borderWidthMedium",
72
- "borderWidthThick",
73
- "borderWidth",
74
- ]);
75
- });
76
-
77
- it("should compile to correct CSS output using consume", () => {
78
- const s = styleframe();
79
- useBorderWidth(s);
80
-
81
- const css = consume(s.root, s.options);
82
-
83
- expect(css).toBe(`:root {
84
- --border-width--none: 0;
85
- --border-width--thin: thin;
86
- --border-width--medium: medium;
87
- --border-width--thick: thick;
88
- --border-width: var(--border-width--thin);
89
- }`);
90
- });
91
-
92
- it("should compile individual border width variable to correct CSS", () => {
93
- const s = styleframe();
94
- const { borderWidthMedium } = useBorderWidth(s);
95
-
96
- const css = consume(borderWidthMedium, s.options);
97
-
98
- expect(css).toBe("--border-width--medium: medium;");
99
- });
100
-
101
- it("should not create duplicate variables when called multiple times", () => {
102
- const s = styleframe();
103
- const borderWidths1 = useBorderWidth(s);
104
- const borderWidths2 = useBorderWidth(s);
105
-
106
- // Should return the same variables (default: true behavior)
107
- expect(borderWidths1.borderWidthThin).toBe(borderWidths2.borderWidthThin);
108
- expect(borderWidths1.borderWidth).toBe(borderWidths2.borderWidth);
109
- expect(s.root.variables).toHaveLength(5);
110
- });
111
-
112
- it("should allow border width variables to be used as references", () => {
113
- const s = styleframe();
114
- const { borderWidthThick } = useBorderWidth(s);
115
-
116
- const customBorderWidth = s.variable(
117
- "custom-border-width",
118
- s.ref(borderWidthThick),
119
- );
120
-
121
- expect(customBorderWidth.value).toEqual({
122
- type: "reference",
123
- name: "border-width--thick",
124
- fallback: undefined,
125
- });
126
-
127
- const css = consume(s.root, s.options);
128
- expect(css).toEqual(`:root {
129
- --border-width--none: 0;
130
- --border-width--thin: thin;
131
- --border-width--medium: medium;
132
- --border-width--thick: thick;
133
- --border-width: var(--border-width--thin);
134
- --custom-border-width: var(--border-width--thick);
135
- }`);
136
- });
137
-
138
- it("should work with selector overrides", () => {
139
- const s = styleframe();
140
- const { borderWidthThin } = useBorderWidth(s);
141
-
142
- s.selector(".custom-border-width", ({ variable }) => {
143
- variable(borderWidthThin, "2px");
144
- });
145
-
146
- const css = consume(s.root, s.options);
147
-
148
- expect(css).toEqual(`:root {
149
- --border-width--none: 0;
150
- --border-width--thin: thin;
151
- --border-width--medium: medium;
152
- --border-width--thick: thick;
153
- --border-width: var(--border-width--thin);
154
- }
155
-
156
- .custom-border-width {
157
- --border-width--thin: 2px;
158
- }`);
159
- });
160
-
161
- describe("type safety", () => {
162
- it("should preserve exact border width variable names in return type", () => {
163
- const s = styleframe();
164
- const borderWidths = useBorderWidth(s);
165
-
166
- // Type assertions to verify the generic types are preserved
167
- const none: Variable<"border-width--none"> = borderWidths.borderWidthNone;
168
- const thin: Variable<"border-width--thin"> = borderWidths.borderWidthThin;
169
- const medium: Variable<"border-width--medium"> =
170
- borderWidths.borderWidthMedium;
171
- const thick: Variable<"border-width--thick"> =
172
- borderWidths.borderWidthThick;
173
- const borderWidth: Variable<"border-width"> = borderWidths.borderWidth;
174
-
175
- expect(none.name).toBe("border-width--none");
176
- expect(thin.name).toBe("border-width--thin");
177
- expect(medium.name).toBe("border-width--medium");
178
- expect(thick.name).toBe("border-width--thick");
179
- expect(borderWidth.name).toBe("border-width");
180
- });
181
-
182
- it("should have correct value types", () => {
183
- const s = styleframe();
184
- const borderWidths = useBorderWidth(s);
185
-
186
- expect(typeof borderWidths.borderWidthNone.value).toBe("number");
187
- expect(typeof borderWidths.borderWidthThin.value).toBe("string");
188
- expect(typeof borderWidths.borderWidthMedium.value).toBe("string");
189
- expect(typeof borderWidths.borderWidthThick.value).toBe("string");
190
- expect(typeof borderWidths.borderWidth.value).toBe("object");
191
- });
192
- });
193
-
194
- describe("default border width", () => {
195
- it("should create a default border width variable referencing thin by default", () => {
196
- const s = styleframe();
197
- const { borderWidth } = useBorderWidth(s);
198
-
199
- expect(borderWidth).toEqual({
200
- type: "variable",
201
- name: "border-width",
202
- value: {
203
- type: "reference",
204
- name: "border-width--thin",
205
- fallback: undefined,
206
- },
207
- });
208
- });
209
-
210
- it("should allow customizing the default border width", () => {
211
- const s = styleframe();
212
- const { borderWidth } = useBorderWidth(s, {
213
- ...defaultBorderWidthValues,
214
- default: "@medium",
215
- });
216
-
217
- expect(borderWidth.value).toEqual({
218
- type: "reference",
219
- name: "border-width--medium",
220
- fallback: undefined,
221
- });
222
- });
223
-
224
- it("should compile default border width to CSS correctly", () => {
225
- const s = styleframe();
226
- useBorderWidth(s, {
227
- ...defaultBorderWidthValues,
228
- default: "@thick",
229
- });
230
-
231
- const css = consume(s.root, s.options);
232
-
233
- expect(css).toEqual(`:root {
234
- --border-width--none: 0;
235
- --border-width--thin: thin;
236
- --border-width--medium: medium;
237
- --border-width--thick: thick;
238
- --border-width: var(--border-width--thick);
239
- }`);
240
- });
241
-
242
- it("should work with different default border widths", () => {
243
- const borderWidthNames = ["none", "thin", "medium", "thick"];
244
-
245
- for (const borderWidthName of borderWidthNames) {
246
- const s = styleframe();
247
- const { borderWidth } = useBorderWidth(s, {
248
- ...defaultBorderWidthValues,
249
- default: `@${borderWidthName}`,
250
- });
251
-
252
- expect(borderWidth.value).toEqual({
253
- type: "reference",
254
- name: `border-width--${borderWidthName}`,
255
- fallback: undefined,
256
- });
257
- }
258
- });
259
- });
260
-
261
- describe("border width values", () => {
262
- it("should have correct CSS keyword values", () => {
263
- const s = styleframe();
264
- const {
265
- borderWidthNone,
266
- borderWidthThin,
267
- borderWidthMedium,
268
- borderWidthThick,
269
- } = useBorderWidth(s);
270
-
271
- expect(borderWidthNone.value).toBe(0);
272
- expect(borderWidthThin.value).toBe("thin");
273
- expect(borderWidthMedium.value).toBe("medium");
274
- expect(borderWidthThick.value).toBe("thick");
275
- });
276
-
277
- it("should have all standard CSS border-width values", () => {
278
- const s = styleframe();
279
- const borderWidths = useBorderWidth(s);
280
- const values = [
281
- borderWidths.borderWidthNone.value,
282
- borderWidths.borderWidthThin.value,
283
- borderWidths.borderWidthMedium.value,
284
- borderWidths.borderWidthThick.value,
285
- ];
286
-
287
- const expectedValues = [0, "thin", "medium", "thick"];
288
-
289
- expect(values).toEqual(expectedValues);
290
- });
291
-
292
- it("should have none as zero value", () => {
293
- const s = styleframe();
294
- const { borderWidthNone } = useBorderWidth(s);
295
-
296
- expect(borderWidthNone.value).toBe(0);
297
- expect(typeof borderWidthNone.value).toBe("number");
298
- });
299
- });
300
-
301
- describe("practical usage", () => {
302
- it("should work for creating borders with different widths", () => {
303
- const s = styleframe();
304
- const { borderWidthThin, borderWidthThick } = useBorderWidth(s);
305
-
306
- s.selector(".card", ({ variable }) => {
307
- variable("border-width", s.ref(borderWidthThin));
308
- });
309
-
310
- s.selector(".emphasis", ({ variable }) => {
311
- variable("border-width", s.ref(borderWidthThick));
312
- });
313
-
314
- const css = consume(s.root, s.options);
315
- expect(css).toEqual(`:root {
316
- --border-width--none: 0;
317
- --border-width--thin: thin;
318
- --border-width--medium: medium;
319
- --border-width--thick: thick;
320
- --border-width: var(--border-width--thin);
321
- }
322
-
323
- .card {
324
- --border-width: var(--border-width--thin);
325
- }
326
-
327
- .emphasis {
328
- --border-width: var(--border-width--thick);
329
- }`);
330
- });
331
-
332
- it("should work for responsive border width adjustments", () => {
333
- const s = styleframe();
334
- const { borderWidthThin, borderWidthMedium } = useBorderWidth(s);
335
-
336
- const buttonBorderWidth = s.variable(
337
- "button-border-width",
338
- s.ref(borderWidthThin),
339
- );
340
-
341
- s.selector("@media (min-width: 768px)", ({ variable }) => {
342
- variable(buttonBorderWidth, s.ref(borderWidthMedium));
343
- });
344
-
345
- const css = consume(s.root, s.options);
346
- expect(css).toEqual(`:root {
347
- --border-width--none: 0;
348
- --border-width--thin: thin;
349
- --border-width--medium: medium;
350
- --border-width--thick: thick;
351
- --border-width: var(--border-width--thin);
352
- --button-border-width: var(--border-width--thin);
353
- }
354
-
355
- @media (min-width: 768px) {
356
- --button-border-width: var(--border-width--medium);
357
- }`);
358
- });
359
-
360
- it("should work for theme-specific border width overrides", () => {
361
- const s = styleframe();
362
- const { borderWidthThin, borderWidthThick } = useBorderWidth(s);
363
-
364
- s.selector(".theme-bold", ({ variable }) => {
365
- variable(borderWidthThin, s.ref(borderWidthThick));
366
- });
367
-
368
- const css = consume(s.root, s.options);
369
- expect(css).toEqual(`:root {
370
- --border-width--none: 0;
371
- --border-width--thin: thin;
372
- --border-width--medium: medium;
373
- --border-width--thick: thick;
374
- --border-width: var(--border-width--thin);
375
- }
376
-
377
- .theme-bold {
378
- --border-width--thin: var(--border-width--thick);
379
- }`);
380
- });
381
-
382
- it("should work for state-specific border widths", () => {
383
- const s = styleframe();
384
- const { borderWidthThin, borderWidthMedium, borderWidthNone } =
385
- useBorderWidth(s);
386
-
387
- s.selector(".input", ({ variable }) => {
388
- variable("border-width", s.ref(borderWidthThin));
389
- });
390
-
391
- s.selector(".input:focus", ({ variable }) => {
392
- variable("border-width", s.ref(borderWidthMedium));
393
- });
394
-
395
- s.selector(".input:disabled", ({ variable }) => {
396
- variable("border-width", s.ref(borderWidthNone));
397
- });
398
-
399
- const css = consume(s.root, s.options);
400
- expect(css).toEqual(`:root {
401
- --border-width--none: 0;
402
- --border-width--thin: thin;
403
- --border-width--medium: medium;
404
- --border-width--thick: thick;
405
- --border-width: var(--border-width--thin);
406
- }
407
-
408
- .input {
409
- --border-width: var(--border-width--thin);
410
- }
411
-
412
- .input:focus {
413
- --border-width: var(--border-width--medium);
414
- }
415
-
416
- .input:disabled {
417
- --border-width: var(--border-width--none);
418
- }`);
419
- });
420
-
421
- it("should work for combining border widths with other border properties", () => {
422
- const s = styleframe();
423
- const { borderWidthThin, borderWidthThick } = useBorderWidth(s);
424
-
425
- const borderStyle = s.variable("border-style", "solid");
426
- s.variable("border-color", "#000");
427
-
428
- s.selector(".box", ({ variable }) => {
429
- variable("border-width", s.ref(borderWidthThin));
430
- });
431
-
432
- s.selector(".box-fancy", ({ variable }) => {
433
- variable("border-width", s.ref(borderWidthThick));
434
- variable(borderStyle, "double");
435
- });
436
-
437
- const css = consume(s.root, s.options);
438
- expect(css).toEqual(`:root {
439
- --border-width--none: 0;
440
- --border-width--thin: thin;
441
- --border-width--medium: medium;
442
- --border-width--thick: thick;
443
- --border-width: var(--border-width--thin);
444
- --border-style: solid;
445
- --border-color: #000;
446
- }
447
-
448
- .box {
449
- --border-width: var(--border-width--thin);
450
- }
451
-
452
- .box-fancy {
453
- --border-width: var(--border-width--thick);
454
- --border-style: double;
455
- }`);
456
- });
457
-
458
- it("should work with custom pixel values for overrides", () => {
459
- const s = styleframe();
460
- const { borderWidthThin } = useBorderWidth(s);
461
-
462
- s.selector(".custom", ({ variable }) => {
463
- variable(borderWidthThin, "1px");
464
- });
465
-
466
- s.selector(".custom-thick", ({ variable }) => {
467
- variable(borderWidthThin, "3px");
468
- });
469
-
470
- const css = consume(s.root, s.options);
471
- expect(css).toEqual(`:root {
472
- --border-width--none: 0;
473
- --border-width--thin: thin;
474
- --border-width--medium: medium;
475
- --border-width--thick: thick;
476
- --border-width: var(--border-width--thin);
477
- }
478
-
479
- .custom {
480
- --border-width--thin: 1px;
481
- }
482
-
483
- .custom-thick {
484
- --border-width--thin: 3px;
485
- }`);
486
- });
487
-
488
- it("should work for removing borders with none value", () => {
489
- const s = styleframe();
490
- const { borderWidthNone } = useBorderWidth(s);
491
-
492
- s.selector(".no-border", ({ variable }) => {
493
- variable("border-width", s.ref(borderWidthNone));
494
- });
495
-
496
- const css = consume(s.root, s.options);
497
- expect(css).toEqual(`:root {
498
- --border-width--none: 0;
499
- --border-width--thin: thin;
500
- --border-width--medium: medium;
501
- --border-width--thick: thick;
502
- --border-width: var(--border-width--thin);
503
- }
504
-
505
- .no-border {
506
- --border-width: var(--border-width--none);
507
- }`);
508
- });
509
- });
510
-
511
- describe("border width value relationships", () => {
512
- it("should have none as the smallest value", () => {
513
- const s = styleframe();
514
- const { borderWidthNone } = useBorderWidth(s);
515
-
516
- expect(borderWidthNone.value).toBe(0);
517
- });
518
-
519
- it("should have semantic progression from thin to thick", () => {
520
- const s = styleframe();
521
- const { borderWidthThin, borderWidthMedium, borderWidthThick } =
522
- useBorderWidth(s);
523
-
524
- // Verify semantic naming progression exists
525
- expect(borderWidthThin.value).toBe("thin");
526
- expect(borderWidthMedium.value).toBe("medium");
527
- expect(borderWidthThick.value).toBe("thick");
528
-
529
- // These CSS keywords have defined progressive values
530
- expect(borderWidthThin.name).toContain("thin");
531
- expect(borderWidthMedium.name).toContain("medium");
532
- expect(borderWidthThick.name).toContain("thick");
533
- });
534
- });
535
- });
@@ -1,38 +0,0 @@
1
- import { createUseVariable } from "../utils";
2
-
3
- export const defaultBorderWidthValues = {
4
- default: "@thin",
5
- none: 0,
6
- thin: "thin",
7
- medium: "medium",
8
- thick: "thick",
9
- };
10
-
11
- /**
12
- * Create a set of border-width variables for use in a Styleframe instance.
13
- *
14
- * @usage
15
- * ```typescript
16
- * import { styleframe } from "styleframe";
17
- * import { useBorderWidth } from "styleframe/theme";
18
- *
19
- * const s = styleframe();
20
- *
21
- * const {
22
- * borderWidthNone,
23
- * borderWidthThin,
24
- * borderWidthMedium,
25
- * borderWidthThick,
26
- * borderWidth,
27
- * } = useBorderWidth(s, {
28
- * default: "thin",
29
- * none: 0,
30
- * thin: "thin",
31
- * medium: "medium",
32
- * thick: "thick",
33
- * });
34
- * ```
35
- */
36
- export const useBorderWidth = createUseVariable("border-width", {
37
- defaults: defaultBorderWidthValues,
38
- });