@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.
- package/CHANGELOG.md +12 -0
- package/LICENSE +21 -0
- package/dist/theme.d.ts +772 -0
- package/dist/theme.js +2507 -0
- package/dist/theme.umd.cjs +4 -0
- package/package.json +14 -4
- package/.tsbuildinfo +0 -1
- package/src/constants/border.ts +0 -0
- package/src/constants/breakpoint.ts +0 -0
- package/src/constants/color.ts +0 -0
- package/src/constants/index.ts +0 -4
- package/src/constants/scale.ts +0 -3
- package/src/constants/typography.ts +0 -0
- package/src/index.ts +0 -4
- package/src/shims.d.ts +0 -8
- package/src/types.ts +0 -32
- package/src/utils/createUseVariable.test.ts +0 -928
- package/src/utils/createUseVariable.ts +0 -107
- package/src/utils/index.ts +0 -1
- package/src/variables/index.ts +0 -20
- package/src/variables/useBorderColor.ts +0 -27
- package/src/variables/useBorderRadius.test.ts +0 -335
- package/src/variables/useBorderRadius.ts +0 -26
- package/src/variables/useBorderStyle.test.ts +0 -569
- package/src/variables/useBorderStyle.ts +0 -49
- package/src/variables/useBorderWidth.test.ts +0 -535
- package/src/variables/useBorderWidth.ts +0 -38
- package/src/variables/useBoxShadow.test.ts +0 -336
- package/src/variables/useBoxShadow.ts +0 -54
- package/src/variables/useBreakpoint.test.ts +0 -447
- package/src/variables/useBreakpoint.ts +0 -38
- package/src/variables/useColor.test.ts +0 -360
- package/src/variables/useColor.ts +0 -35
- package/src/variables/useColorLightness.test.ts +0 -168
- package/src/variables/useColorLightness.ts +0 -59
- package/src/variables/useColorShade.test.ts +0 -166
- package/src/variables/useColorShade.ts +0 -52
- package/src/variables/useColorTint.test.ts +0 -164
- package/src/variables/useColorTint.ts +0 -52
- package/src/variables/useEasing.ts +0 -0
- package/src/variables/useFontFamily.test.ts +0 -228
- package/src/variables/useFontFamily.ts +0 -33
- package/src/variables/useFontSize.test.ts +0 -299
- package/src/variables/useFontSize.ts +0 -32
- package/src/variables/useFontStyle.test.ts +0 -555
- package/src/variables/useFontStyle.ts +0 -37
- package/src/variables/useFontWeight.test.ts +0 -650
- package/src/variables/useFontWeight.ts +0 -55
- package/src/variables/useLetterSpacing.test.ts +0 -455
- package/src/variables/useLetterSpacing.ts +0 -41
- package/src/variables/useLineHeight.test.ts +0 -410
- package/src/variables/useLineHeight.ts +0 -41
- package/src/variables/useMultiplier.test.ts +0 -722
- package/src/variables/useMultiplier.ts +0 -44
- package/src/variables/useScale.test.ts +0 -393
- package/src/variables/useScale.ts +0 -52
- package/src/variables/useScalePowers.test.ts +0 -412
- package/src/variables/useScalePowers.ts +0 -35
- package/src/variables/useSpacing.test.ts +0 -309
- package/src/variables/useSpacing.ts +0 -26
- package/src/vite-env.d.ts +0 -1
- package/test-scale.js +0 -22
- package/tsconfig.json +0 -7
- package/vite.config.ts +0 -5
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { Styleframe, TokenValue, Variable } from "@styleframe/core";
|
|
2
|
-
import { createUseVariable } from "../utils";
|
|
3
|
-
import type { ExportKeys } from "../types";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Create a font-size scale for use in a Styleframe instance.
|
|
7
|
-
*
|
|
8
|
-
* @usage
|
|
9
|
-
* ```typescript
|
|
10
|
-
* import { styleframe } from "styleframe";
|
|
11
|
-
* import { useFontSize, useScale, useScalePowers, useMultiplier } from "styleframe/theme";
|
|
12
|
-
*
|
|
13
|
-
* const s = styleframe();
|
|
14
|
-
*
|
|
15
|
-
* const { scale } = useScale(s);
|
|
16
|
-
* const { fontSize } = useFontSize(s);
|
|
17
|
-
*
|
|
18
|
-
* const scalePowers = useScalePowers(s, scale, defaultScalePowerValues);
|
|
19
|
-
*
|
|
20
|
-
* const {
|
|
21
|
-
* fontSizeXs, // Variable<'font-size--xs'>
|
|
22
|
-
* fontSizeSm, // Variable<'font-size--sm'>
|
|
23
|
-
* fontSizeMd, // Variable<'font-size--md'>
|
|
24
|
-
* fontSizeLg, // Variable<'font-size--lg'>
|
|
25
|
-
* fontSizeXl, // Variable<'font-size--xl'>
|
|
26
|
-
* } = useMultiplier(s, fontSize, {
|
|
27
|
-
* xs: scalePowers[-2],
|
|
28
|
-
* sm: scalePowers[-1],
|
|
29
|
-
* md: scalePowers[0],
|
|
30
|
-
* lg: scalePowers[1],
|
|
31
|
-
* xl: scalePowers[2],
|
|
32
|
-
* });
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
export function useMultiplier<
|
|
36
|
-
Name extends string,
|
|
37
|
-
T extends Record<string | number, TokenValue>,
|
|
38
|
-
>(s: Styleframe, variable: Variable<Name>, values: T): ExportKeys<Name, T> {
|
|
39
|
-
return createUseVariable(variable.name, {
|
|
40
|
-
transform: (value) => {
|
|
41
|
-
return s.css`calc(${s.ref(variable)} * ${value})`;
|
|
42
|
-
},
|
|
43
|
-
})(s, values);
|
|
44
|
-
}
|
|
@@ -1,393 +0,0 @@
|
|
|
1
|
-
/** biome-ignore-all lint/suspicious/noApproximativeNumericConstant: scales are magic numbers */
|
|
2
|
-
import type { Variable } from "@styleframe/core";
|
|
3
|
-
import { styleframe } from "@styleframe/core";
|
|
4
|
-
import { consume } from "@styleframe/transpiler";
|
|
5
|
-
import { useScale } from "./useScale";
|
|
6
|
-
|
|
7
|
-
describe("useScale", () => {
|
|
8
|
-
it("should create all scale variables with correct names and values", () => {
|
|
9
|
-
const s = styleframe();
|
|
10
|
-
const {
|
|
11
|
-
scaleMinorSecond,
|
|
12
|
-
scaleMajorSecond,
|
|
13
|
-
scaleMinorThird,
|
|
14
|
-
scaleMajorThird,
|
|
15
|
-
scalePerfectFourth,
|
|
16
|
-
scaleAugmentedFourth,
|
|
17
|
-
scalePerfectFifth,
|
|
18
|
-
scaleGolden,
|
|
19
|
-
scale,
|
|
20
|
-
} = useScale(s);
|
|
21
|
-
|
|
22
|
-
expect(scaleMinorSecond).toEqual({
|
|
23
|
-
type: "variable",
|
|
24
|
-
name: "scale--minor-second",
|
|
25
|
-
value: 1.067,
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
expect(scaleMajorSecond).toEqual({
|
|
29
|
-
type: "variable",
|
|
30
|
-
name: "scale--major-second",
|
|
31
|
-
value: 1.125,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
expect(scaleMinorThird).toEqual({
|
|
35
|
-
type: "variable",
|
|
36
|
-
name: "scale--minor-third",
|
|
37
|
-
value: 1.2,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
expect(scaleMajorThird).toEqual({
|
|
41
|
-
type: "variable",
|
|
42
|
-
name: "scale--major-third",
|
|
43
|
-
value: 1.25,
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
expect(scalePerfectFourth).toEqual({
|
|
47
|
-
type: "variable",
|
|
48
|
-
name: "scale--perfect-fourth",
|
|
49
|
-
value: 1.333,
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
expect(scaleAugmentedFourth).toEqual({
|
|
53
|
-
type: "variable",
|
|
54
|
-
name: "scale--augmented-fourth",
|
|
55
|
-
value: 1.414,
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
expect(scalePerfectFifth).toEqual({
|
|
59
|
-
type: "variable",
|
|
60
|
-
name: "scale--perfect-fifth",
|
|
61
|
-
value: 1.5,
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
expect(scaleGolden).toEqual({
|
|
65
|
-
type: "variable",
|
|
66
|
-
name: "scale--golden",
|
|
67
|
-
value: 1.618,
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
expect(scale).toEqual({
|
|
71
|
-
type: "variable",
|
|
72
|
-
name: "scale",
|
|
73
|
-
value: {
|
|
74
|
-
type: "reference",
|
|
75
|
-
name: "scale--minor-third",
|
|
76
|
-
fallback: undefined,
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it("should add all scale variables to root", () => {
|
|
82
|
-
const s = styleframe();
|
|
83
|
-
useScale(s);
|
|
84
|
-
|
|
85
|
-
expect(s.root.variables).toHaveLength(9);
|
|
86
|
-
expect(s.root.variables[0]?.name).toBe("scale--minor-second");
|
|
87
|
-
expect(s.root.variables[1]?.name).toBe("scale--major-second");
|
|
88
|
-
expect(s.root.variables[2]?.name).toBe("scale--minor-third");
|
|
89
|
-
expect(s.root.variables[3]?.name).toBe("scale--major-third");
|
|
90
|
-
expect(s.root.variables[4]?.name).toBe("scale--perfect-fourth");
|
|
91
|
-
expect(s.root.variables[5]?.name).toBe("scale--augmented-fourth");
|
|
92
|
-
expect(s.root.variables[6]?.name).toBe("scale--perfect-fifth");
|
|
93
|
-
expect(s.root.variables[7]?.name).toBe("scale--golden");
|
|
94
|
-
expect(s.root.variables[8]?.name).toBe("scale");
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it("should return all scale variables in an object", () => {
|
|
98
|
-
const s = styleframe();
|
|
99
|
-
const scales = useScale(s);
|
|
100
|
-
|
|
101
|
-
expect(Object.keys(scales)).toEqual([
|
|
102
|
-
"scaleMinorSecond",
|
|
103
|
-
"scaleMajorSecond",
|
|
104
|
-
"scaleMinorThird",
|
|
105
|
-
"scaleMajorThird",
|
|
106
|
-
"scalePerfectFourth",
|
|
107
|
-
"scaleAugmentedFourth",
|
|
108
|
-
"scalePerfectFifth",
|
|
109
|
-
"scaleGolden",
|
|
110
|
-
"scale",
|
|
111
|
-
]);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it("should compile to correct CSS output using consume", () => {
|
|
115
|
-
const s = styleframe();
|
|
116
|
-
useScale(s);
|
|
117
|
-
|
|
118
|
-
const css = consume(s.root, s.options);
|
|
119
|
-
|
|
120
|
-
expect(css).toBe(`:root {
|
|
121
|
-
--scale--minor-second: 1.067;
|
|
122
|
-
--scale--major-second: 1.125;
|
|
123
|
-
--scale--minor-third: 1.2;
|
|
124
|
-
--scale--major-third: 1.25;
|
|
125
|
-
--scale--perfect-fourth: 1.333;
|
|
126
|
-
--scale--augmented-fourth: 1.414;
|
|
127
|
-
--scale--perfect-fifth: 1.5;
|
|
128
|
-
--scale--golden: 1.618;
|
|
129
|
-
--scale: var(--scale--minor-third);
|
|
130
|
-
}`);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it("should compile individual scale variable to correct CSS", () => {
|
|
134
|
-
const s = styleframe();
|
|
135
|
-
const { scaleGolden } = useScale(s);
|
|
136
|
-
|
|
137
|
-
const css = consume(scaleGolden, s.options);
|
|
138
|
-
|
|
139
|
-
expect(css).toBe("--scale--golden: 1.618;");
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("should not create duplicate variables when called multiple times", () => {
|
|
143
|
-
const s = styleframe();
|
|
144
|
-
const scales1 = useScale(s);
|
|
145
|
-
const scales2 = useScale(s);
|
|
146
|
-
|
|
147
|
-
// Should return the same variables (default: true behavior)
|
|
148
|
-
expect(scales1.scaleGolden).toBe(scales2.scaleGolden);
|
|
149
|
-
expect(scales1.scale).toBe(scales2.scale);
|
|
150
|
-
expect(s.root.variables).toHaveLength(9);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it("should allow scale variables to be used as references", () => {
|
|
154
|
-
const s = styleframe();
|
|
155
|
-
const { scaleGolden } = useScale(s);
|
|
156
|
-
|
|
157
|
-
const customScale = s.variable("custom-scale", s.ref(scaleGolden));
|
|
158
|
-
|
|
159
|
-
expect(customScale.value).toEqual({
|
|
160
|
-
type: "reference",
|
|
161
|
-
name: "scale--golden",
|
|
162
|
-
fallback: undefined,
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
const css = consume(s.root, s.options);
|
|
166
|
-
expect(css).toContain("--custom-scale: var(--scale--golden);");
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it("should work with selector overrides", () => {
|
|
170
|
-
const s = styleframe();
|
|
171
|
-
const { scaleMajorThird } = useScale(s);
|
|
172
|
-
|
|
173
|
-
s.selector(".custom-scale", ({ variable }) => {
|
|
174
|
-
variable(scaleMajorThird, 1.5);
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
const css = consume(s.root, s.options);
|
|
178
|
-
|
|
179
|
-
expect(css).toContain("--scale--major-third: 1.25;");
|
|
180
|
-
expect(css).toContain(".custom-scale");
|
|
181
|
-
expect(css).toContain("--scale--major-third: 1.5;");
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
describe("type safety", () => {
|
|
185
|
-
it("should preserve exact scale variable names in return type", () => {
|
|
186
|
-
const s = styleframe();
|
|
187
|
-
const scales = useScale(s);
|
|
188
|
-
|
|
189
|
-
// Type assertions to verify the generic types are preserved
|
|
190
|
-
const minorSecond: Variable<"scale--minor-second"> =
|
|
191
|
-
scales.scaleMinorSecond;
|
|
192
|
-
const majorSecond: Variable<"scale--major-second"> =
|
|
193
|
-
scales.scaleMajorSecond;
|
|
194
|
-
const minorThird: Variable<"scale--minor-third"> = scales.scaleMinorThird;
|
|
195
|
-
const majorThird: Variable<"scale--major-third"> = scales.scaleMajorThird;
|
|
196
|
-
const perfectFourth: Variable<"scale--perfect-fourth"> =
|
|
197
|
-
scales.scalePerfectFourth;
|
|
198
|
-
const augmentedFourth: Variable<"scale--augmented-fourth"> =
|
|
199
|
-
scales.scaleAugmentedFourth;
|
|
200
|
-
const perfectFifth: Variable<"scale--perfect-fifth"> =
|
|
201
|
-
scales.scalePerfectFifth;
|
|
202
|
-
const golden: Variable<"scale--golden"> = scales.scaleGolden;
|
|
203
|
-
const scale: Variable<"scale"> = scales.scale;
|
|
204
|
-
|
|
205
|
-
expect(minorSecond.name).toBe("scale--minor-second");
|
|
206
|
-
expect(majorSecond.name).toBe("scale--major-second");
|
|
207
|
-
expect(minorThird.name).toBe("scale--minor-third");
|
|
208
|
-
expect(majorThird.name).toBe("scale--major-third");
|
|
209
|
-
expect(perfectFourth.name).toBe("scale--perfect-fourth");
|
|
210
|
-
expect(augmentedFourth.name).toBe("scale--augmented-fourth");
|
|
211
|
-
expect(perfectFifth.name).toBe("scale--perfect-fifth");
|
|
212
|
-
expect(golden.name).toBe("scale--golden");
|
|
213
|
-
expect(scale.name).toBe("scale");
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
it("should have correct numeric value types", () => {
|
|
217
|
-
const s = styleframe();
|
|
218
|
-
const scales = useScale(s);
|
|
219
|
-
|
|
220
|
-
expect(typeof scales.scaleMinorSecond.value).toBe("number");
|
|
221
|
-
expect(typeof scales.scaleMajorSecond.value).toBe("number");
|
|
222
|
-
expect(typeof scales.scaleMinorThird.value).toBe("number");
|
|
223
|
-
expect(typeof scales.scaleMajorThird.value).toBe("number");
|
|
224
|
-
expect(typeof scales.scalePerfectFourth.value).toBe("number");
|
|
225
|
-
expect(typeof scales.scaleAugmentedFourth.value).toBe("number");
|
|
226
|
-
expect(typeof scales.scalePerfectFifth.value).toBe("number");
|
|
227
|
-
expect(typeof scales.scaleGolden.value).toBe("number");
|
|
228
|
-
expect(typeof scales.scale.value).toBe("object");
|
|
229
|
-
});
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
describe("default scale", () => {
|
|
233
|
-
it("should create a default scale variable referencing minor-third by default", () => {
|
|
234
|
-
const s = styleframe();
|
|
235
|
-
const { scale } = useScale(s);
|
|
236
|
-
|
|
237
|
-
expect(scale).toEqual({
|
|
238
|
-
type: "variable",
|
|
239
|
-
name: "scale",
|
|
240
|
-
value: {
|
|
241
|
-
type: "reference",
|
|
242
|
-
name: "scale--minor-third",
|
|
243
|
-
fallback: undefined,
|
|
244
|
-
},
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
it("should allow customizing the default scale", () => {
|
|
249
|
-
const s = styleframe();
|
|
250
|
-
const { scale } = useScale(s, {
|
|
251
|
-
default: "@perfect-fourth",
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
expect(scale.value).toEqual({
|
|
255
|
-
type: "reference",
|
|
256
|
-
name: "scale--perfect-fourth",
|
|
257
|
-
fallback: undefined,
|
|
258
|
-
});
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
it("should compile default scale to CSS correctly", () => {
|
|
262
|
-
const s = styleframe();
|
|
263
|
-
useScale(s, {
|
|
264
|
-
default: "@golden",
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
const css = consume(s.root, s.options);
|
|
268
|
-
|
|
269
|
-
expect(css).toContain("--scale: var(--scale--golden);");
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
it("should work with different default scales", () => {
|
|
273
|
-
const scales = [
|
|
274
|
-
"minor-second",
|
|
275
|
-
"major-second",
|
|
276
|
-
"minor-third",
|
|
277
|
-
"major-third",
|
|
278
|
-
"perfect-fourth",
|
|
279
|
-
"augmented-fourth",
|
|
280
|
-
"perfect-fifth",
|
|
281
|
-
"golden",
|
|
282
|
-
];
|
|
283
|
-
|
|
284
|
-
for (const scaleName of scales) {
|
|
285
|
-
const s = styleframe();
|
|
286
|
-
const { scale } = useScale(s, { default: `@${scaleName}` });
|
|
287
|
-
|
|
288
|
-
expect(scale.value).toEqual({
|
|
289
|
-
type: "reference",
|
|
290
|
-
name: `scale--${scaleName}`,
|
|
291
|
-
fallback: undefined,
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
|
-
});
|
|
296
|
-
|
|
297
|
-
describe("mathematical scale relationships", () => {
|
|
298
|
-
it("should have scales in ascending order", () => {
|
|
299
|
-
const s = styleframe();
|
|
300
|
-
const {
|
|
301
|
-
scaleMinorSecond,
|
|
302
|
-
scaleMajorSecond,
|
|
303
|
-
scaleMinorThird,
|
|
304
|
-
scaleMajorThird,
|
|
305
|
-
scalePerfectFourth,
|
|
306
|
-
scaleAugmentedFourth,
|
|
307
|
-
scalePerfectFifth,
|
|
308
|
-
scaleGolden,
|
|
309
|
-
} = useScale(s);
|
|
310
|
-
|
|
311
|
-
expect(scaleMinorSecond.value).toBeLessThan(
|
|
312
|
-
scaleMajorSecond.value as number,
|
|
313
|
-
);
|
|
314
|
-
expect(scaleMajorSecond.value).toBeLessThan(
|
|
315
|
-
scaleMinorThird.value as number,
|
|
316
|
-
);
|
|
317
|
-
expect(scaleMinorThird.value).toBeLessThan(
|
|
318
|
-
scaleMajorThird.value as number,
|
|
319
|
-
);
|
|
320
|
-
expect(scaleMajorThird.value).toBeLessThan(
|
|
321
|
-
scalePerfectFourth.value as number,
|
|
322
|
-
);
|
|
323
|
-
expect(scalePerfectFourth.value).toBeLessThan(
|
|
324
|
-
scaleAugmentedFourth.value as number,
|
|
325
|
-
);
|
|
326
|
-
expect(scaleAugmentedFourth.value).toBeLessThan(
|
|
327
|
-
scalePerfectFifth.value as number,
|
|
328
|
-
);
|
|
329
|
-
expect(scalePerfectFifth.value).toBeLessThan(scaleGolden.value as number);
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
it("should have golden ratio as the largest scale", () => {
|
|
333
|
-
const s = styleframe();
|
|
334
|
-
const scales = useScale(s);
|
|
335
|
-
const values = Object.values(scales)
|
|
336
|
-
.filter((v) => typeof v.value === "number")
|
|
337
|
-
.map((v) => v.value as number);
|
|
338
|
-
const maxValue = Math.max(...values);
|
|
339
|
-
|
|
340
|
-
expect(scales.scaleGolden.value).toBe(maxValue);
|
|
341
|
-
expect(scales.scaleGolden.value).toBe(1.618);
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
it("should have minor second as the smallest scale", () => {
|
|
345
|
-
const s = styleframe();
|
|
346
|
-
const scales = useScale(s);
|
|
347
|
-
const values = Object.values(scales)
|
|
348
|
-
.filter((v) => typeof v.value === "number")
|
|
349
|
-
.map((v) => v.value as number);
|
|
350
|
-
const minValue = Math.min(...values);
|
|
351
|
-
|
|
352
|
-
expect(scales.scaleMinorSecond.value).toBe(minValue);
|
|
353
|
-
expect(scales.scaleMinorSecond.value).toBe(1.067);
|
|
354
|
-
});
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
describe("practical usage", () => {
|
|
358
|
-
it("should work for creating modular typography scales", () => {
|
|
359
|
-
const s = styleframe();
|
|
360
|
-
const { scaleMajorThird } = useScale(s);
|
|
361
|
-
|
|
362
|
-
const baseSize = s.variable("font-size-base", "1rem");
|
|
363
|
-
const fontSizeH1 = s.variable(
|
|
364
|
-
"font-size-h1",
|
|
365
|
-
s.ref(baseSize, `calc(${s.ref(baseSize)} * ${s.ref(scaleMajorThird)})`),
|
|
366
|
-
);
|
|
367
|
-
|
|
368
|
-
expect(fontSizeH1.value).toEqual({
|
|
369
|
-
type: "reference",
|
|
370
|
-
name: "font-size-base",
|
|
371
|
-
fallback: `calc(${s.ref(baseSize)} * ${s.ref(scaleMajorThird)})`,
|
|
372
|
-
});
|
|
373
|
-
});
|
|
374
|
-
|
|
375
|
-
it("should work for creating spacing scales", () => {
|
|
376
|
-
const s = styleframe();
|
|
377
|
-
const { scaleGolden } = useScale(s);
|
|
378
|
-
|
|
379
|
-
const spacingBase = s.variable("spacing-base", "1rem");
|
|
380
|
-
s.variable(
|
|
381
|
-
"spacing-lg",
|
|
382
|
-
s.css`calc(${s.ref(spacingBase)} * ${s.ref(scaleGolden)})`,
|
|
383
|
-
);
|
|
384
|
-
|
|
385
|
-
const css = consume(s.root, s.options);
|
|
386
|
-
expect(css).toContain("--spacing-base: 1rem;");
|
|
387
|
-
expect(css).toContain("--scale--golden: 1.618;");
|
|
388
|
-
expect(css).toContain(
|
|
389
|
-
"--spacing-lg: calc(var(--spacing-base) * var(--scale--golden));",
|
|
390
|
-
);
|
|
391
|
-
});
|
|
392
|
-
});
|
|
393
|
-
});
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/** biome-ignore-all lint/suspicious/noApproximativeNumericConstant: Scale ratios are magic numbers */
|
|
2
|
-
import { createUseVariable } from "../utils";
|
|
3
|
-
|
|
4
|
-
export const defaultScaleValues = {
|
|
5
|
-
default: "@minor-third",
|
|
6
|
-
"minor-second": 1.067,
|
|
7
|
-
"major-second": 1.125,
|
|
8
|
-
"minor-third": 1.2,
|
|
9
|
-
"major-third": 1.25,
|
|
10
|
-
"perfect-fourth": 1.333,
|
|
11
|
-
"augmented-fourth": 1.414,
|
|
12
|
-
"perfect-fifth": 1.5,
|
|
13
|
-
golden: 1.618,
|
|
14
|
-
} as const;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Create a set of scale variables for use in a Styleframe instance.
|
|
18
|
-
*
|
|
19
|
-
* @usage
|
|
20
|
-
* ```typescript
|
|
21
|
-
* import { styleframe } from "styleframe";
|
|
22
|
-
* import { useScale } from "styleframe/theme";
|
|
23
|
-
*
|
|
24
|
-
* const s = styleframe();
|
|
25
|
-
*
|
|
26
|
-
* const {
|
|
27
|
-
* scaleMinorSecond,
|
|
28
|
-
* scaleMajorSecond,
|
|
29
|
-
* scaleMinorThird,
|
|
30
|
-
* scaleMajorThird,
|
|
31
|
-
* scalePerfectFourth,
|
|
32
|
-
* scaleAugmentedFourth,
|
|
33
|
-
* scalePerfectFifth,
|
|
34
|
-
* scaleGolden,
|
|
35
|
-
* scale,
|
|
36
|
-
* } = useScale(s, {
|
|
37
|
-
* default: 1.2,
|
|
38
|
-
* minorSecond: 1.067,
|
|
39
|
-
* majorSecond: 1.125,
|
|
40
|
-
* minorThird: 1.2,
|
|
41
|
-
* majorThird: 1.25,
|
|
42
|
-
* perfectFourth: 1.333,
|
|
43
|
-
* augmentedFourth: 1.414,
|
|
44
|
-
* perfectFifth: 1.5,
|
|
45
|
-
* golden: 1.618,
|
|
46
|
-
* });
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
export const useScale = createUseVariable("scale", {
|
|
51
|
-
defaults: defaultScaleValues,
|
|
52
|
-
});
|