@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,107 +0,0 @@
1
- import type { Styleframe, TokenValue, Variable } from "@styleframe/core";
2
- import type { CamelCase } from "scule";
3
- import { camelCase } from "scule";
4
- import type { ExportKeys } from "../types";
5
-
6
- export function isKeyReferenceValue(value: unknown): value is string {
7
- return typeof value === "string" && value.startsWith("@");
8
- }
9
-
10
- /**
11
- * Creates a generic composable function for a CSS property.
12
- *
13
- * This factory function generates `use*` composables (like `useFontFamily`, `useLineHeight`, etc.)
14
- * from a CSS property name string.
15
- *
16
- * @param propertyName - The CSS property name (e.g., 'font-family', 'line-height')
17
- * @returns A composable function that creates variables for the given property
18
- *
19
- * @example
20
- * ```typescript
21
- * import { styleframe } from "styleframe";
22
- * import { createUseVariable } from "styleframe/theme";
23
- *
24
- * // Create a useFontFamily composable
25
- * const useFontFamily = createUseVariable("font-family");
26
- *
27
- * const s = styleframe();
28
- * const { fontFamily, fontFamilyMono } = useFontFamily(s, {
29
- * default: "Arial, sans-serif",
30
- * mono: "Courier, monospace",
31
- * });
32
- * ```
33
- *
34
- * @example
35
- * ```typescript
36
- * // Create a useLineHeight composable
37
- * const useLineHeight = createUseVariable("line-height");
38
- *
39
- * const s = styleframe();
40
- * const { lineHeight, lineHeightTight, lineHeightLoose } = useLineHeight(s, {
41
- * default: "1.5",
42
- * tight: "1.25",
43
- * loose: "1.75",
44
- * });
45
- * ```
46
- */
47
- export function createUseVariable<
48
- PropertyName extends string,
49
- Delimiter extends string = "--",
50
- Defaults extends Record<string, TokenValue> = Record<string, TokenValue>,
51
- MergeDefaults extends boolean = false,
52
- >(
53
- propertyName: PropertyName,
54
- {
55
- defaults,
56
- mergeDefaults = false as MergeDefaults,
57
- transform = (value) => value,
58
- delimiter = "--" as Delimiter,
59
- }: {
60
- defaults?: Defaults;
61
- mergeDefaults?: MergeDefaults;
62
- transform?: (value: TokenValue) => TokenValue;
63
- delimiter?: Delimiter;
64
- } = {},
65
- ) {
66
- type WithDefaults<T> = MergeDefaults extends true ? Defaults & T : T;
67
-
68
- return function useVariable<T extends Record<string, TokenValue> = Defaults>(
69
- s: Styleframe,
70
- tokens?: T,
71
- ): ExportKeys<PropertyName, WithDefaults<T>, Delimiter> {
72
- const result: Record<string, Variable<string>> = {};
73
-
74
- const resolvedTokens = mergeDefaults
75
- ? ({ ...defaults, ...tokens } as T)
76
- : ((tokens ?? defaults ?? {}) as T);
77
- const pairs = Object.entries(resolvedTokens);
78
-
79
- const hasDefaultKey = "default" in resolvedTokens;
80
- if (hasDefaultKey) {
81
- pairs.sort(([_aKey, aValue], [_bKey, bValue]) => {
82
- if (isKeyReferenceValue(aValue)) return 1;
83
- if (isKeyReferenceValue(bValue)) return -1;
84
- return 0;
85
- });
86
- }
87
-
88
- const createVariableName = (key: string) =>
89
- `${propertyName}${key === "default" ? "" : `${delimiter}${key}`}` as const;
90
-
91
- for (const [key, value] of pairs) {
92
- const variableName = createVariableName(key);
93
- const exportName: CamelCase<typeof variableName> =
94
- camelCase(variableName);
95
-
96
- const variableValue = isKeyReferenceValue(value)
97
- ? s.ref(createVariableName(value.substring(1)))
98
- : transform(value);
99
-
100
- result[exportName] = s.variable(variableName, variableValue, {
101
- default: true,
102
- });
103
- }
104
-
105
- return result as ExportKeys<PropertyName, WithDefaults<T>, Delimiter>;
106
- };
107
- }
@@ -1 +0,0 @@
1
- export * from "./createUseVariable";
@@ -1,20 +0,0 @@
1
- export * from "./useBorderColor";
2
- export * from "./useBorderRadius";
3
- export * from "./useBorderStyle";
4
- export * from "./useBorderWidth";
5
- export * from "./useBoxShadow";
6
- export * from "./useBreakpoint";
7
- export * from "./useColor";
8
- export * from "./useColorLightness";
9
- export * from "./useColorShade";
10
- export * from "./useColorTint";
11
- export * from "./useEasing";
12
- export * from "./useFontFamily";
13
- export * from "./useFontSize";
14
- export * from "./useFontWeight";
15
- export * from "./useLetterSpacing";
16
- export * from "./useLineHeight";
17
- export * from "./useMultiplier";
18
- export * from "./useScale";
19
- export * from "./useScalePowers";
20
- export * from "./useSpacing";
@@ -1,27 +0,0 @@
1
- import { createUseVariable } from "../utils";
2
-
3
- /**
4
- * Create a set of border-color variables for use in a Styleframe instance.
5
- *
6
- * @usage
7
- * ```typescript
8
- * import { styleframe } from "styleframe";
9
- * import { useBorderColor, useColor } from "styleframe/theme";
10
- *
11
- * const s = styleframe();
12
- *
13
- * const { colorPrimary, colorSecondary } = useColor(s, {
14
- * primary: "#007bff",
15
- * secondary: "#6c757d",
16
- * });
17
- *
18
- * const {
19
- * borderColorPrimary, // Variable<'border-color--primary'>
20
- * borderColorSecondary, // Variable<'border-color--secondary'>
21
- * } = useBorderColor(s, {
22
- * primary: ref(colorPrimary),
23
- * secondary: ref(colorSecondary),
24
- * });
25
- * ```
26
- */
27
- export const useBorderColor = createUseVariable("border-color");
@@ -1,335 +0,0 @@
1
- import type { Variable } from "@styleframe/core";
2
- import { styleframe } from "@styleframe/core";
3
- import { consume } from "@styleframe/transpiler";
4
- import { useBorderRadius } from "./useBorderRadius";
5
-
6
- describe("useBorderRadius", () => {
7
- it("should create a single border-radius variable with 'default' key", () => {
8
- const s = styleframe();
9
- const { borderRadius } = useBorderRadius(s, {
10
- default: "0.25rem",
11
- });
12
-
13
- expect(borderRadius).toEqual({
14
- type: "variable",
15
- name: "border-radius",
16
- value: "0.25rem",
17
- });
18
-
19
- const css = consume(borderRadius, s.options);
20
- expect(css).toBe(`--border-radius: 0.25rem;`);
21
- });
22
-
23
- it("should create border-radius variable with modifier for non-default keys", () => {
24
- const s = styleframe();
25
- const { borderRadiusSm } = useBorderRadius(s, {
26
- sm: "0.125rem",
27
- });
28
-
29
- expect(borderRadiusSm).toEqual({
30
- type: "variable",
31
- name: "border-radius--sm",
32
- value: "0.125rem",
33
- });
34
-
35
- const css = consume(borderRadiusSm, s.options);
36
- expect(css).toBe(`--border-radius--sm: 0.125rem;`);
37
- });
38
-
39
- it("should create multiple border-radius variables", () => {
40
- const s = styleframe();
41
- const { borderRadius, borderRadiusSm, borderRadiusMd, borderRadiusLg } =
42
- useBorderRadius(s, {
43
- default: "0.25rem",
44
- sm: "0.125rem",
45
- md: "0.25rem",
46
- lg: "0.5rem",
47
- });
48
-
49
- expect(borderRadius).toEqual({
50
- type: "variable",
51
- name: "border-radius",
52
- value: "0.25rem",
53
- });
54
-
55
- expect(borderRadiusSm).toEqual({
56
- type: "variable",
57
- name: "border-radius--sm",
58
- value: "0.125rem",
59
- });
60
-
61
- expect(borderRadiusMd).toEqual({
62
- type: "variable",
63
- name: "border-radius--md",
64
- value: "0.25rem",
65
- });
66
-
67
- expect(borderRadiusLg).toEqual({
68
- type: "variable",
69
- name: "border-radius--lg",
70
- value: "0.5rem",
71
- });
72
- });
73
-
74
- it("should add variables to root", () => {
75
- const s = styleframe();
76
- useBorderRadius(s, {
77
- default: "0.25rem",
78
- sm: "0.125rem",
79
- });
80
-
81
- expect(s.root.variables).toHaveLength(2);
82
- expect(s.root.variables[0]?.name).toBe("border-radius");
83
- expect(s.root.variables[1]?.name).toBe("border-radius--sm");
84
- });
85
-
86
- it("should handle kebab-case border-radius names", () => {
87
- const s = styleframe();
88
- const { borderRadiusExtraLarge } = useBorderRadius(s, {
89
- "extra-large": "1rem",
90
- });
91
-
92
- expect(borderRadiusExtraLarge).toEqual({
93
- type: "variable",
94
- name: "border-radius--extra-large",
95
- value: "1rem",
96
- });
97
- });
98
-
99
- it("should handle snake_case border-radius names", () => {
100
- const s = styleframe();
101
- const { borderRadiusCardCorner } = useBorderRadius(s, {
102
- card_corner: "0.375rem",
103
- });
104
-
105
- expect(borderRadiusCardCorner).toEqual({
106
- type: "variable",
107
- name: "border-radius--card_corner",
108
- value: "0.375rem",
109
- });
110
- });
111
-
112
- it("should handle numeric border-radius names", () => {
113
- const s = styleframe();
114
- const { borderRadius100 } = useBorderRadius(s, {
115
- "100": "0.25rem",
116
- });
117
-
118
- expect(borderRadius100).toEqual({
119
- type: "variable",
120
- name: "border-radius--100",
121
- value: "0.25rem",
122
- });
123
- });
124
-
125
- it("should handle pixel values", () => {
126
- const s = styleframe();
127
- const { borderRadius } = useBorderRadius(s, {
128
- default: "4px",
129
- });
130
-
131
- expect(borderRadius).toEqual({
132
- type: "variable",
133
- name: "border-radius",
134
- value: "4px",
135
- });
136
- });
137
-
138
- it("should handle em values", () => {
139
- const s = styleframe();
140
- const { borderRadiusBase } = useBorderRadius(s, {
141
- base: "0.5em",
142
- });
143
-
144
- expect(borderRadiusBase).toEqual({
145
- type: "variable",
146
- name: "border-radius--base",
147
- value: "0.5em",
148
- });
149
- });
150
-
151
- it("should handle percentage values", () => {
152
- const s = styleframe();
153
- const { borderRadiusCircle } = useBorderRadius(s, {
154
- circle: "50%",
155
- });
156
-
157
- expect(borderRadiusCircle).toEqual({
158
- type: "variable",
159
- name: "border-radius--circle",
160
- value: "50%",
161
- });
162
- });
163
-
164
- it("should handle viewport units", () => {
165
- const s = styleframe();
166
- const { borderRadiusFluid } = useBorderRadius(s, {
167
- fluid: "1vw",
168
- });
169
-
170
- expect(borderRadiusFluid).toEqual({
171
- type: "variable",
172
- name: "border-radius--fluid",
173
- value: "1vw",
174
- });
175
- });
176
-
177
- it("should handle calc() expressions", () => {
178
- const s = styleframe();
179
- const { borderRadiusDynamic } = useBorderRadius(s, {
180
- dynamic: "calc(0.25rem + 0.5vw)",
181
- });
182
-
183
- expect(borderRadiusDynamic.value).toBe("calc(0.25rem + 0.5vw)");
184
- });
185
-
186
- it("should handle clamp() expressions", () => {
187
- const s = styleframe();
188
- const { borderRadiusResponsive } = useBorderRadius(s, {
189
- responsive: "clamp(0.125rem, 1vw, 1rem)",
190
- });
191
-
192
- expect(borderRadiusResponsive.value).toBe("clamp(0.125rem, 1vw, 1rem)");
193
- });
194
-
195
- it("should handle special keyword values", () => {
196
- const s = styleframe();
197
- const { borderRadiusNone, borderRadiusFull } = useBorderRadius(s, {
198
- none: "0",
199
- full: "9999px",
200
- });
201
-
202
- expect(borderRadiusNone.value).toBe("0");
203
- expect(borderRadiusFull.value).toBe("9999px");
204
- });
205
-
206
- it("should handle multi-value border-radius", () => {
207
- const s = styleframe();
208
- const { borderRadiusCustom } = useBorderRadius(s, {
209
- custom: "0.25rem 0.5rem",
210
- });
211
-
212
- expect(borderRadiusCustom.value).toBe("0.25rem 0.5rem");
213
- });
214
-
215
- it("should handle four-value border-radius", () => {
216
- const s = styleframe();
217
- const { borderRadiusAsymmetric } = useBorderRadius(s, {
218
- asymmetric: "0.25rem 0.5rem 0.75rem 1rem",
219
- });
220
-
221
- expect(borderRadiusAsymmetric.value).toBe("0.25rem 0.5rem 0.75rem 1rem");
222
- });
223
-
224
- it("should handle empty border-radius object", () => {
225
- const s = styleframe();
226
- const result = useBorderRadius(s, {});
227
-
228
- expect(result).toEqual({});
229
- expect(s.root.variables).toHaveLength(0);
230
- });
231
-
232
- it("should handle border-radius references", () => {
233
- const s = styleframe();
234
- const baseBorderRadius = s.variable("base-border-radius", "0.25rem");
235
- const { borderRadius } = useBorderRadius(s, {
236
- default: s.ref(baseBorderRadius),
237
- });
238
-
239
- expect(borderRadius.value).toEqual({
240
- type: "reference",
241
- name: "base-border-radius",
242
- fallback: undefined,
243
- });
244
- });
245
-
246
- it("should compile to correct CSS output using consume", () => {
247
- const s = styleframe();
248
- useBorderRadius(s, {
249
- default: "0.25rem",
250
- none: "0",
251
- sm: "0.125rem",
252
- md: "0.25rem",
253
- lg: "0.5rem",
254
- });
255
-
256
- const css = consume(s.root, s.options);
257
-
258
- expect(css).toBe(`:root {
259
- --border-radius: 0.25rem;
260
- --border-radius--none: 0;
261
- --border-radius--sm: 0.125rem;
262
- --border-radius--md: 0.25rem;
263
- --border-radius--lg: 0.5rem;
264
- }`);
265
- });
266
-
267
- it("should handle a complete border-radius scale", () => {
268
- const s = styleframe();
269
- const radii = useBorderRadius(s, {
270
- none: "0",
271
- xs: "0.125rem",
272
- sm: "0.25rem",
273
- default: "0.375rem",
274
- md: "0.5rem",
275
- lg: "0.75rem",
276
- xl: "1rem",
277
- "2xl": "1.5rem",
278
- "3xl": "2rem",
279
- full: "9999px",
280
- });
281
-
282
- expect(radii.borderRadiusNone.value).toBe("0");
283
- expect(radii.borderRadiusXs.value).toBe("0.125rem");
284
- expect(radii.borderRadiusSm.value).toBe("0.25rem");
285
- expect(radii.borderRadius.value).toBe("0.375rem");
286
- expect(radii.borderRadiusMd.value).toBe("0.5rem");
287
- expect(radii.borderRadiusLg.value).toBe("0.75rem");
288
- expect(radii.borderRadiusXl.value).toBe("1rem");
289
- expect(radii.borderRadius2xl.value).toBe("1.5rem");
290
- expect(radii.borderRadius3xl.value).toBe("2rem");
291
- expect(radii.borderRadiusFull.value).toBe("9999px");
292
- });
293
-
294
- describe("type safety", () => {
295
- it("should preserve exact border-radius names in return type", () => {
296
- const s = styleframe();
297
- const radii = useBorderRadius(s, {
298
- default: "0.25rem",
299
- sm: "0.125rem",
300
- });
301
-
302
- // Type assertions to verify the generic types are preserved
303
- const defaultBorderRadius: Variable<"border-radius"> = radii.borderRadius;
304
- const smBorderRadius: Variable<"border-radius--sm"> =
305
- radii.borderRadiusSm;
306
-
307
- expect(defaultBorderRadius.name).toBe("border-radius");
308
- expect(smBorderRadius.name).toBe("border-radius--sm");
309
- });
310
-
311
- it("should maintain type information for kebab-case names", () => {
312
- const s = styleframe();
313
- const { borderRadiusExtraLarge } = useBorderRadius(s, {
314
- "extra-large": "1rem",
315
- });
316
-
317
- const typed: Variable<"border-radius--extra-large"> =
318
- borderRadiusExtraLarge;
319
- expect(typed.name).toBe("border-radius--extra-large");
320
- });
321
-
322
- it("should work with const assertion", () => {
323
- const s = styleframe();
324
- const borderRadiusConfig = {
325
- default: "0.25rem",
326
- sm: "0.125rem",
327
- } as const;
328
-
329
- const radii = useBorderRadius(s, borderRadiusConfig);
330
-
331
- expect(radii.borderRadius.name).toBe("border-radius");
332
- expect(radii.borderRadiusSm.name).toBe("border-radius--sm");
333
- });
334
- });
335
- });
@@ -1,26 +0,0 @@
1
- import { createUseVariable } from "../utils";
2
-
3
- /**
4
- * Create a set of border-radius variables for use in a Styleframe instance.
5
- *
6
- * @usage
7
- * ```typescript
8
- * import { styleframe } from "styleframe";
9
- * import { useBorderRadius } from "styleframe/theme";
10
- *
11
- * const s = styleframe();
12
- *
13
- * const {
14
- * borderRadius, // Variable<'border-radius'>
15
- * borderRadiusSm, // Variable<'border-radius--sm'>
16
- * borderRadiusMd, // Variable<'border-radius--md'>
17
- * borderRadiusLg, // Variable<'border-radius--lg'>
18
- * } = useBorderRadius(s, {
19
- * default: "0.25rem",
20
- * sm: "0.125rem",
21
- * md: "0.25rem",
22
- * lg: "0.5rem",
23
- * });
24
- * ```
25
- */
26
- export const useBorderRadius = createUseVariable("border-radius");