@styleframe/theme 1.0.0 → 1.0.2

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 +14 -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 +16 -6
  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 -22
  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,299 +0,0 @@
1
- import type { Variable } from "@styleframe/core";
2
- import { styleframe } from "@styleframe/core";
3
- import { consume } from "@styleframe/transpiler";
4
- import { useFontSize } from "./useFontSize";
5
-
6
- describe("useFontSize", () => {
7
- it("should create a single font size variable with 'default' key", () => {
8
- const s = styleframe();
9
- const { fontSize } = useFontSize(s, {
10
- default: "1rem",
11
- });
12
-
13
- expect(fontSize).toEqual({
14
- type: "variable",
15
- name: "font-size",
16
- value: "1rem",
17
- });
18
-
19
- const css = consume(fontSize, s.options);
20
- expect(css).toBe(`--font-size: 1rem;`);
21
- });
22
-
23
- it("should create font size variable with modifier for non-default keys", () => {
24
- const s = styleframe();
25
- const { fontSizeSm } = useFontSize(s, {
26
- sm: "0.875rem",
27
- });
28
-
29
- expect(fontSizeSm).toEqual({
30
- type: "variable",
31
- name: "font-size--sm",
32
- value: "0.875rem",
33
- });
34
-
35
- const css = consume(fontSizeSm, s.options);
36
- expect(css).toBe(`--font-size--sm: 0.875rem;`);
37
- });
38
-
39
- it("should create multiple font size variables", () => {
40
- const s = styleframe();
41
- const { fontSize, fontSizeSm, fontSizeMd, fontSizeLg } = useFontSize(s, {
42
- default: "1rem",
43
- sm: "0.875rem",
44
- md: "1rem",
45
- lg: "1.25rem",
46
- });
47
-
48
- expect(fontSize).toEqual({
49
- type: "variable",
50
- name: "font-size",
51
- value: "1rem",
52
- });
53
-
54
- expect(fontSizeSm).toEqual({
55
- type: "variable",
56
- name: "font-size--sm",
57
- value: "0.875rem",
58
- });
59
-
60
- expect(fontSizeMd).toEqual({
61
- type: "variable",
62
- name: "font-size--md",
63
- value: "1rem",
64
- });
65
-
66
- expect(fontSizeLg).toEqual({
67
- type: "variable",
68
- name: "font-size--lg",
69
- value: "1.25rem",
70
- });
71
- });
72
-
73
- it("should add variables to root", () => {
74
- const s = styleframe();
75
- useFontSize(s, {
76
- default: "1rem",
77
- sm: "0.875rem",
78
- });
79
-
80
- expect(s.root.variables).toHaveLength(2);
81
- expect(s.root.variables[0]?.name).toBe("font-size");
82
- expect(s.root.variables[1]?.name).toBe("font-size--sm");
83
- });
84
-
85
- it("should handle kebab-case font size names", () => {
86
- const s = styleframe();
87
- const { fontSizeExtraLarge } = useFontSize(s, {
88
- "extra-large": "2rem",
89
- });
90
-
91
- expect(fontSizeExtraLarge).toEqual({
92
- type: "variable",
93
- name: "font-size--extra-large",
94
- value: "2rem",
95
- });
96
- });
97
-
98
- it("should handle snake_case font size names", () => {
99
- const s = styleframe();
100
- const { fontSizeHeadingPrimary } = useFontSize(s, {
101
- heading_primary: "1.5rem",
102
- });
103
-
104
- expect(fontSizeHeadingPrimary).toEqual({
105
- type: "variable",
106
- name: "font-size--heading_primary",
107
- value: "1.5rem",
108
- });
109
- });
110
-
111
- it("should handle numeric font size names", () => {
112
- const s = styleframe();
113
- const { fontSize100 } = useFontSize(s, {
114
- "100": "0.75rem",
115
- });
116
-
117
- expect(fontSize100).toEqual({
118
- type: "variable",
119
- name: "font-size--100",
120
- value: "0.75rem",
121
- });
122
- });
123
-
124
- it("should handle pixel values", () => {
125
- const s = styleframe();
126
- const { fontSize } = useFontSize(s, {
127
- default: "16px",
128
- });
129
-
130
- expect(fontSize).toEqual({
131
- type: "variable",
132
- name: "font-size",
133
- value: "16px",
134
- });
135
- });
136
-
137
- it("should handle em values", () => {
138
- const s = styleframe();
139
- const { fontSizeBase } = useFontSize(s, {
140
- base: "1.5em",
141
- });
142
-
143
- expect(fontSizeBase).toEqual({
144
- type: "variable",
145
- name: "font-size--base",
146
- value: "1.5em",
147
- });
148
- });
149
-
150
- it("should handle percentage values", () => {
151
- const s = styleframe();
152
- const { fontSizeRelative } = useFontSize(s, {
153
- relative: "125%",
154
- });
155
-
156
- expect(fontSizeRelative).toEqual({
157
- type: "variable",
158
- name: "font-size--relative",
159
- value: "125%",
160
- });
161
- });
162
-
163
- it("should handle viewport units", () => {
164
- const s = styleframe();
165
- const { fontSizeFluid } = useFontSize(s, {
166
- fluid: "2.5vw",
167
- });
168
-
169
- expect(fontSizeFluid).toEqual({
170
- type: "variable",
171
- name: "font-size--fluid",
172
- value: "2.5vw",
173
- });
174
- });
175
-
176
- it("should handle calc() expressions", () => {
177
- const s = styleframe();
178
- const { fontSizeDynamic } = useFontSize(s, {
179
- dynamic: "calc(1rem + 0.5vw)",
180
- });
181
-
182
- expect(fontSizeDynamic.value).toBe("calc(1rem + 0.5vw)");
183
- });
184
-
185
- it("should handle clamp() expressions", () => {
186
- const s = styleframe();
187
- const { fontSizeResponsive } = useFontSize(s, {
188
- responsive: "clamp(1rem, 2vw, 2rem)",
189
- });
190
-
191
- expect(fontSizeResponsive.value).toBe("clamp(1rem, 2vw, 2rem)");
192
- });
193
-
194
- it("should handle empty font size object", () => {
195
- const s = styleframe();
196
- const result = useFontSize(s, {});
197
-
198
- expect(result).toEqual({});
199
- expect(s.root.variables).toHaveLength(0);
200
- });
201
-
202
- it("should handle font size references", () => {
203
- const s = styleframe();
204
- const baseSize = s.variable("base-size", "1rem");
205
- const { fontSize } = useFontSize(s, {
206
- default: s.ref(baseSize),
207
- });
208
-
209
- expect(fontSize.value).toEqual({
210
- type: "reference",
211
- name: "base-size",
212
- fallback: undefined,
213
- });
214
- });
215
-
216
- it("should compile to correct CSS output using consume", () => {
217
- const s = styleframe();
218
- useFontSize(s, {
219
- default: "1rem",
220
- sm: "0.875rem",
221
- md: "1rem",
222
- lg: "1.25rem",
223
- xl: "1.5rem",
224
- });
225
-
226
- const css = consume(s.root, s.options);
227
-
228
- expect(css).toBe(`:root {
229
- --font-size: 1rem;
230
- --font-size--sm: 0.875rem;
231
- --font-size--md: 1rem;
232
- --font-size--lg: 1.25rem;
233
- --font-size--xl: 1.5rem;
234
- }`);
235
- });
236
-
237
- it("should handle a complete font size scale", () => {
238
- const s = styleframe();
239
- const sizes = useFontSize(s, {
240
- xs: "0.75rem",
241
- sm: "0.875rem",
242
- default: "1rem",
243
- md: "1rem",
244
- lg: "1.25rem",
245
- xl: "1.5rem",
246
- "2xl": "2rem",
247
- "3xl": "2.5rem",
248
- });
249
-
250
- expect(sizes.fontSizeXs.value).toBe("0.75rem");
251
- expect(sizes.fontSizeSm.value).toBe("0.875rem");
252
- expect(sizes.fontSize.value).toBe("1rem");
253
- expect(sizes.fontSizeMd.value).toBe("1rem");
254
- expect(sizes.fontSizeLg.value).toBe("1.25rem");
255
- expect(sizes.fontSizeXl.value).toBe("1.5rem");
256
- expect(sizes.fontSize2xl.value).toBe("2rem");
257
- expect(sizes.fontSize3xl.value).toBe("2.5rem");
258
- });
259
-
260
- describe("type safety", () => {
261
- it("should preserve exact font size names in return type", () => {
262
- const s = styleframe();
263
- const sizes = useFontSize(s, {
264
- default: "1rem",
265
- sm: "0.875rem",
266
- });
267
-
268
- // Type assertions to verify the generic types are preserved
269
- const defaultSize: Variable<"font-size"> = sizes.fontSize;
270
- const smSize: Variable<"font-size--sm"> = sizes.fontSizeSm;
271
-
272
- expect(defaultSize.name).toBe("font-size");
273
- expect(smSize.name).toBe("font-size--sm");
274
- });
275
-
276
- it("should maintain type information for kebab-case names", () => {
277
- const s = styleframe();
278
- const { fontSizeExtraLarge } = useFontSize(s, {
279
- "extra-large": "2rem",
280
- });
281
-
282
- const typed: Variable<"font-size--extra-large"> = fontSizeExtraLarge;
283
- expect(typed.name).toBe("font-size--extra-large");
284
- });
285
-
286
- it("should work with const assertion", () => {
287
- const s = styleframe();
288
- const sizeConfig = {
289
- default: "1rem",
290
- sm: "0.875rem",
291
- } as const;
292
-
293
- const sizes = useFontSize(s, sizeConfig);
294
-
295
- expect(sizes.fontSize.name).toBe("font-size");
296
- expect(sizes.fontSizeSm.name).toBe("font-size--sm");
297
- });
298
- });
299
- });
@@ -1,32 +0,0 @@
1
- import { createUseVariable } from "../utils";
2
-
3
- export const defaultFontSizeValues = {
4
- default: "1rem",
5
- };
6
-
7
- /**
8
- * Create a set of font-size variables for use in a Styleframe instance.
9
- *
10
- * @usage
11
- * ```typescript
12
- * import { styleframe } from "styleframe";
13
- * import { useFontSize } from "styleframe/theme";
14
- *
15
- * const s = styleframe();
16
- *
17
- * const {
18
- * fontSize, // Variable<'font-size'>
19
- * fontSizeSm, // Variable<'font-size--sm'>
20
- * fontSizeMd, // Variable<'font-size--md'>
21
- * fontSizeLg, // Variable<'font-size--lg'>
22
- * } = useFontSize(s, {
23
- * default: "1rem",
24
- * sm: "0.875rem",
25
- * md: "1rem",
26
- * lg: "1.25rem",
27
- * });
28
- * ```
29
- */
30
- export const useFontSize = createUseVariable("font-size", {
31
- defaults: defaultFontSizeValues,
32
- });