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