vite-plugin-capsize-radix 0.0.9 → 0.1.1
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/README.md +20 -8
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +129 -43
- package/dist/index.mjs +126 -40
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -6,11 +6,11 @@ Now changing fonts is as easy as changing colors.
|
|
|
6
6
|
|
|
7
7
|
## Why
|
|
8
8
|
|
|
9
|
-
Getting
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
so changing fonts is as easy as changing
|
|
13
|
-
|
|
9
|
+
Getting fonts to look right on the web is [_hard_](https://fantasai.inkedblade.net/style/talks/atypi-2021/atypi-2021-precise-text-alignment.mp4) — so most peoply rely on
|
|
10
|
+
a few typography frameworks and fonts. But it doesn't have to be that way.
|
|
11
|
+
[Capsize](https://seek-oss.github.io/capsize/) fixes text sizing and layout
|
|
12
|
+
allowing for precise text alignment so changing fonts is as easy as changing
|
|
13
|
+
colors.
|
|
14
14
|
|
|
15
15
|
https://github.com/KyleAMathews/vite-plugin-capsize-radix-ui/assets/71047/3ec5d6ca-bf00-4b79-8552-4e3da3454f52
|
|
16
16
|
|
|
@@ -37,17 +37,19 @@ import react from "@vitejs/plugin-react-swc"
|
|
|
37
37
|
import { capsizeRadixPlugin } from "vite-plugin-capsize-radix"
|
|
38
38
|
import merriweather from "@capsizecss/metrics/merriweather"
|
|
39
39
|
import merriweatherSans from "@capsizecss/metrics/merriweatherSans"
|
|
40
|
+
import sourceCodePro from "@capsizecss/metrics/sourceCodePro"
|
|
40
41
|
import arial from "@capsizecss/metrics/arial"
|
|
41
42
|
|
|
42
43
|
export default defineConfig({
|
|
43
44
|
plugins: [
|
|
44
45
|
react(),
|
|
45
46
|
capsizeRadixPlugin({
|
|
46
|
-
// Import this file into your app.
|
|
47
|
+
// Import this file into your app after you import Radix's CSS.
|
|
47
48
|
outputPath: `./public/merriweather.css`,
|
|
48
49
|
// Pass in Capsize font metric objects.
|
|
49
50
|
defaultFontStack: [merriweather, arial],
|
|
50
51
|
headingFontStack: [merriweatherSans, arial],
|
|
52
|
+
codingFontStack: [sourceCodePro, arial],
|
|
51
53
|
}),
|
|
52
54
|
]
|
|
53
55
|
})
|
|
@@ -57,6 +59,10 @@ export default defineConfig({
|
|
|
57
59
|
This plugin overrides all typography related CSS for Radix so you can simply
|
|
58
60
|
use their typography components as normal (e.g. `<Heading>`, `<Text>`, `<Strong>`, etc)
|
|
59
61
|
|
|
62
|
+
The plugin sets the variables for Radix's Type scale and Font family for Radix.
|
|
63
|
+
It doesn't set Font weight. It sets the strong, em, and quote to use the default font family.
|
|
64
|
+
You can set the default, heading, and coding font stacks separately.
|
|
65
|
+
|
|
60
66
|
See e.g. the [documentation for `<Text>`](https://www.radix-ui.com/themes/docs/components/text).
|
|
61
67
|
|
|
62
68
|
They all share a `size` prop from "1" to "10". This corresponds to the optional
|
|
@@ -64,6 +70,11 @@ They all share a `size` prop from "1" to "10". This corresponds to the optional
|
|
|
64
70
|
the array, etc. `<Text>` defaults to `size="2"` and `<Heading>` defaults to
|
|
65
71
|
`size="6"`.
|
|
66
72
|
|
|
73
|
+
As Capsize trims _all_ space around text, you'll find that `<Flex gap="[space]">` becomes
|
|
74
|
+
your best friend for controlling spacing between elements e.g.
|
|
75
|
+
|
|
76
|
+
<img width="669" alt="Screenshot 2024-03-28 at 10 44 10 AM" src="https://github.com/KyleAMathews/vite-plugin-capsize-radix-ui/assets/71047/b8552d58-4e2d-42d6-9b7b-a595466c2725">
|
|
77
|
+
|
|
67
78
|
### Fallback fonts
|
|
68
79
|
|
|
69
80
|
Another great freebie Capsize gives you is it automatically generates CSS for
|
|
@@ -86,8 +97,8 @@ to be slightly smaller than on desktop. We do that by shifting the text a size s
|
|
|
86
97
|
```ts
|
|
87
98
|
[
|
|
88
99
|
{ fontSize: 9, lineHeight: 21 },
|
|
89
|
-
{ fontSize: 11, lineHeight:
|
|
90
|
-
{ fontSize: 12, lineHeight:
|
|
100
|
+
{ fontSize: 11, lineHeight: 23 },
|
|
101
|
+
{ fontSize: 12, lineHeight: 25 },
|
|
91
102
|
{ fontSize: 14, lineHeight: 27 },
|
|
92
103
|
{ fontSize: 18, lineHeight: 29 },
|
|
93
104
|
{ fontSize: 24, lineHeight: 36 },
|
|
@@ -98,3 +109,4 @@ to be slightly smaller than on desktop. We do that by shifting the text a size s
|
|
|
98
109
|
```
|
|
99
110
|
* __defaultFontStack (FontMetrics[]): Optional__. An array of `FontMetrics` objects. Defaults to a System Font stack.
|
|
100
111
|
* __headingFontStack (FontMetrics[]): Optional__. An array of `FontMetrics` objects. Defaults to your `defaultFontStack`.
|
|
112
|
+
* __codingFontStack (FontMetrics[]): Optional__. An array of `FontMetrics` objects. Defaults to your `defaultFontStack`.
|
package/dist/index.d.mts
CHANGED
|
@@ -10,7 +10,8 @@ interface Options {
|
|
|
10
10
|
textStyles?: TextStyle[];
|
|
11
11
|
defaultFontStack?: FontMetrics[];
|
|
12
12
|
headingFontStack?: FontMetrics[];
|
|
13
|
+
codingFontStack?: FontMetrics[];
|
|
13
14
|
}
|
|
14
|
-
declare function capsizeRadixPlugin({ outputPath, textStyles, defaultFontStack, headingFontStack, }: Options): Plugin;
|
|
15
|
+
declare function capsizeRadixPlugin({ outputPath, textStyles, defaultFontStack, headingFontStack, codingFontStack, }: Options): Plugin;
|
|
15
16
|
|
|
16
17
|
export { capsizeRadixPlugin };
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,8 @@ interface Options {
|
|
|
10
10
|
textStyles?: TextStyle[];
|
|
11
11
|
defaultFontStack?: FontMetrics[];
|
|
12
12
|
headingFontStack?: FontMetrics[];
|
|
13
|
+
codingFontStack?: FontMetrics[];
|
|
13
14
|
}
|
|
14
|
-
declare function capsizeRadixPlugin({ outputPath, textStyles, defaultFontStack, headingFontStack, }: Options): Plugin;
|
|
15
|
+
declare function capsizeRadixPlugin({ outputPath, textStyles, defaultFontStack, headingFontStack, codingFontStack, }: Options): Plugin;
|
|
15
16
|
|
|
16
17
|
export { capsizeRadixPlugin };
|
package/dist/index.js
CHANGED
|
@@ -28,11 +28,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
30
|
// src/index.ts
|
|
31
|
-
var
|
|
32
|
-
__export(
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
33
|
capsizeRadixPlugin: () => capsizeRadixPlugin
|
|
34
34
|
});
|
|
35
|
-
module.exports = __toCommonJS(
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
36
|
var import_fs = __toESM(require("fs"));
|
|
37
37
|
var import_core = require("@capsizecss/core");
|
|
38
38
|
var import_mustache = __toESM(require("mustache"));
|
|
@@ -45,10 +45,11 @@ var template = `/* Auto-generated by vite-plugin-capsize-radix */
|
|
|
45
45
|
|
|
46
46
|
/* Override Radix variables */
|
|
47
47
|
.radix-themes {
|
|
48
|
-
--default-font-family: {{{
|
|
49
|
-
--em-font-family: {{{
|
|
50
|
-
--quote-font-family: {{{
|
|
51
|
-
--heading-font-family: {{{
|
|
48
|
+
--default-font-family: {{{defaultFontFamily.fontFamily}}};
|
|
49
|
+
--em-font-family: {{{defaultFontFamily.fontFamily}}};
|
|
50
|
+
--quote-font-family: {{{defaultFontFamily.fontFamily}}};
|
|
51
|
+
--heading-font-family: {{{headingFontFamily.fontFamily}}};
|
|
52
|
+
--code-font-family: {{{codingFontFamily.fontFamily}}};
|
|
52
53
|
|
|
53
54
|
/* Mobile */
|
|
54
55
|
{{#mobileFontData}}
|
|
@@ -88,7 +89,23 @@ var template = `/* Auto-generated by vite-plugin-capsize-radix */
|
|
|
88
89
|
{{{quoteStyles}}}
|
|
89
90
|
}
|
|
90
91
|
|
|
91
|
-
|
|
92
|
+
/* Code text styles */
|
|
93
|
+
{{{mobileCodeStyles}}}
|
|
94
|
+
@media (min-width: 768px) {
|
|
95
|
+
{{{codeStyles}}}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/* Code size variants */
|
|
99
|
+
{{#mobileCodeFontData}}
|
|
100
|
+
{{{style}}}
|
|
101
|
+
{{/mobileCodeFontData}}
|
|
102
|
+
@media (min-width: 768px) {
|
|
103
|
+
{{#codeFontData}}
|
|
104
|
+
{{{style}}}
|
|
105
|
+
{{/codeFontData}}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.rt-Em, .rt-Quote, .rt-Code {
|
|
92
109
|
display: inline-block;
|
|
93
110
|
}
|
|
94
111
|
|
|
@@ -103,42 +120,77 @@ var template = `/* Auto-generated by vite-plugin-capsize-radix */
|
|
|
103
120
|
}
|
|
104
121
|
`;
|
|
105
122
|
async function generate(options) {
|
|
106
|
-
let
|
|
107
|
-
let
|
|
123
|
+
let defaultFontFamily;
|
|
124
|
+
let headingFontFamiliy;
|
|
125
|
+
let codingFontFamily;
|
|
108
126
|
if (!options.defaultFontStack) {
|
|
109
|
-
options.defaultFontStack = [
|
|
110
|
-
|
|
111
|
-
|
|
127
|
+
options.defaultFontStack = [
|
|
128
|
+
import_appleSystem.default,
|
|
129
|
+
import_segoeUI.default,
|
|
130
|
+
import_roboto.default,
|
|
131
|
+
import_ubuntu.default,
|
|
132
|
+
import_notoSans.default
|
|
133
|
+
];
|
|
134
|
+
defaultFontFamily = (0, import_core.createFontStack)(options.defaultFontStack);
|
|
135
|
+
defaultFontFamily.fontFamily += `, ui-sans-serif, system-ui, sans-serif`;
|
|
112
136
|
} else if (options.defaultFontStack) {
|
|
113
|
-
|
|
137
|
+
defaultFontFamily = (0, import_core.createFontStack)(options.defaultFontStack);
|
|
114
138
|
}
|
|
115
139
|
if (options.headingFontStack) {
|
|
116
|
-
|
|
140
|
+
headingFontFamiliy = (0, import_core.createFontStack)(options.headingFontStack);
|
|
117
141
|
} else {
|
|
118
|
-
|
|
142
|
+
headingFontFamiliy = defaultFontFamily;
|
|
119
143
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
144
|
+
if (options.codingFontStack) {
|
|
145
|
+
codingFontFamily = (0, import_core.createFontStack)(options.codingFontStack);
|
|
146
|
+
} else {
|
|
147
|
+
options.codingFontStack = [import_appleSystem.default];
|
|
148
|
+
codingFontFamily = (0, import_core.createFontStack)(options.codingFontStack);
|
|
149
|
+
codingFontFamily.fontFamily += `, ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, 'DejaVu Sans Mono', monospace`;
|
|
150
|
+
}
|
|
151
|
+
const mobileFontData = [
|
|
152
|
+
options.textStyles[0],
|
|
153
|
+
...options.textStyles.slice(1)
|
|
154
|
+
].map(({ fontSize, lineHeight }, i) => {
|
|
155
|
+
const lineGap = lineHeight - fontSize;
|
|
156
|
+
const style = (0, import_core.createStyleString)(
|
|
157
|
+
`rt-r-size-${i + 1}:not(.rt-DialogContent)`,
|
|
158
|
+
{
|
|
159
|
+
capHeight: fontSize,
|
|
160
|
+
lineGap,
|
|
161
|
+
fontMetrics: options.defaultFontStack[0]
|
|
162
|
+
}
|
|
163
|
+
);
|
|
164
|
+
return {
|
|
165
|
+
style,
|
|
166
|
+
...(0, import_core.createStyleObject)({
|
|
167
|
+
capHeight: fontSize,
|
|
168
|
+
lineGap,
|
|
169
|
+
fontMetrics: options.defaultFontStack[0]
|
|
170
|
+
}),
|
|
171
|
+
i: i + 1
|
|
172
|
+
};
|
|
173
|
+
});
|
|
174
|
+
const mobileCodeFontData = [
|
|
175
|
+
options.textStyles[0],
|
|
176
|
+
...options.textStyles.slice(1)
|
|
177
|
+
].map(({ fontSize, lineHeight }, i) => {
|
|
178
|
+
const lineGap = lineHeight - fontSize;
|
|
179
|
+
const style = (0, import_core.createStyleString)(`rt-Code.rt-r-size-${i + 1}`, {
|
|
180
|
+
capHeight: fontSize * 0.95,
|
|
181
|
+
lineGap,
|
|
182
|
+
fontMetrics: options.codingFontStack[0]
|
|
183
|
+
});
|
|
184
|
+
return {
|
|
185
|
+
style,
|
|
186
|
+
...(0, import_core.createStyleObject)({
|
|
187
|
+
capHeight: fontSize * 0.95,
|
|
188
|
+
lineGap,
|
|
189
|
+
fontMetrics: options.codingFontStack[0]
|
|
190
|
+
}),
|
|
191
|
+
i: i + 1
|
|
192
|
+
};
|
|
193
|
+
});
|
|
142
194
|
const fontData = options.textStyles.map(({ fontSize, lineHeight }, i) => {
|
|
143
195
|
const lineGap = lineHeight - fontSize;
|
|
144
196
|
const style = (0, import_core.createStyleString)(
|
|
@@ -159,6 +211,23 @@ async function generate(options) {
|
|
|
159
211
|
i: i + 1
|
|
160
212
|
};
|
|
161
213
|
});
|
|
214
|
+
const codeFontData = options.textStyles.map(({ fontSize, lineHeight }, i) => {
|
|
215
|
+
const lineGap = lineHeight - fontSize;
|
|
216
|
+
const style = (0, import_core.createStyleString)(`rt-Code.rt-r-size-${i + 1}`, {
|
|
217
|
+
capHeight: fontSize,
|
|
218
|
+
lineGap,
|
|
219
|
+
fontMetrics: options.codingFontStack[0]
|
|
220
|
+
});
|
|
221
|
+
return {
|
|
222
|
+
style,
|
|
223
|
+
...(0, import_core.createStyleObject)({
|
|
224
|
+
capHeight: fontSize,
|
|
225
|
+
lineGap,
|
|
226
|
+
fontMetrics: options.codingFontStack[0]
|
|
227
|
+
}),
|
|
228
|
+
i: i + 1
|
|
229
|
+
};
|
|
230
|
+
});
|
|
162
231
|
const mobileTextStyles = (0, import_core.createStyleString)(`rt-Text`, {
|
|
163
232
|
capHeight: options.textStyles[1].fontSize,
|
|
164
233
|
lineGap: options.textStyles[1].lineHeight - options.textStyles[1].fontSize,
|
|
@@ -174,6 +243,11 @@ async function generate(options) {
|
|
|
174
243
|
lineGap: options.textStyles[1].lineHeight - options.textStyles[1].fontSize,
|
|
175
244
|
fontMetrics: options.defaultFontStack[0]
|
|
176
245
|
});
|
|
246
|
+
const mobileCodeStyles = (0, import_core.createStyleString)(`rt-Code`, {
|
|
247
|
+
capHeight: options.textStyles[1].fontSize * 0.95,
|
|
248
|
+
lineGap: options.textStyles[1].lineHeight - options.textStyles[1].fontSize,
|
|
249
|
+
fontMetrics: options.codingFontStack[0]
|
|
250
|
+
});
|
|
177
251
|
const textStyles = (0, import_core.createStyleString)(`rt-Text`, {
|
|
178
252
|
capHeight: options.textStyles[2].fontSize,
|
|
179
253
|
lineGap: options.textStyles[2].lineHeight - options.textStyles[2].fontSize,
|
|
@@ -189,19 +263,29 @@ async function generate(options) {
|
|
|
189
263
|
lineGap: options.textStyles[2].lineHeight - options.textStyles[2].fontSize,
|
|
190
264
|
fontMetrics: options.defaultFontStack[0]
|
|
191
265
|
});
|
|
266
|
+
const codeStyles = (0, import_core.createStyleString)(`rt-Code`, {
|
|
267
|
+
capHeight: options.textStyles[2].fontSize * 0.95,
|
|
268
|
+
lineGap: options.textStyles[2].lineHeight - options.textStyles[2].fontSize,
|
|
269
|
+
fontMetrics: options.codingFontStack[0]
|
|
270
|
+
});
|
|
192
271
|
import_fs.default.writeFileSync(
|
|
193
272
|
options.outputPath,
|
|
194
273
|
import_mustache.default.render(template, {
|
|
195
|
-
|
|
196
|
-
|
|
274
|
+
headingFontFamiliy,
|
|
275
|
+
defaultFontFamily,
|
|
276
|
+
codingFontFamily,
|
|
197
277
|
mobileFontData,
|
|
198
278
|
fontData,
|
|
279
|
+
mobileCodeFontData,
|
|
280
|
+
codeFontData,
|
|
199
281
|
mobileTextStyles,
|
|
200
282
|
textStyles,
|
|
201
283
|
mobileEmStyles,
|
|
202
284
|
emStyles,
|
|
203
285
|
mobileQuoteStyles,
|
|
204
|
-
quoteStyles
|
|
286
|
+
quoteStyles,
|
|
287
|
+
mobileCodeStyles,
|
|
288
|
+
codeStyles
|
|
205
289
|
})
|
|
206
290
|
);
|
|
207
291
|
}
|
|
@@ -219,7 +303,8 @@ function capsizeRadixPlugin({
|
|
|
219
303
|
{ fontSize: 64, lineHeight: 64 }
|
|
220
304
|
],
|
|
221
305
|
defaultFontStack,
|
|
222
|
-
headingFontStack
|
|
306
|
+
headingFontStack,
|
|
307
|
+
codingFontStack
|
|
223
308
|
}) {
|
|
224
309
|
return {
|
|
225
310
|
name: `radix-capsize-plugin`,
|
|
@@ -228,7 +313,8 @@ function capsizeRadixPlugin({
|
|
|
228
313
|
outputPath,
|
|
229
314
|
textStyles,
|
|
230
315
|
defaultFontStack,
|
|
231
|
-
headingFontStack
|
|
316
|
+
headingFontStack,
|
|
317
|
+
codingFontStack
|
|
232
318
|
});
|
|
233
319
|
}
|
|
234
320
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -15,10 +15,11 @@ var template = `/* Auto-generated by vite-plugin-capsize-radix */
|
|
|
15
15
|
|
|
16
16
|
/* Override Radix variables */
|
|
17
17
|
.radix-themes {
|
|
18
|
-
--default-font-family: {{{
|
|
19
|
-
--em-font-family: {{{
|
|
20
|
-
--quote-font-family: {{{
|
|
21
|
-
--heading-font-family: {{{
|
|
18
|
+
--default-font-family: {{{defaultFontFamily.fontFamily}}};
|
|
19
|
+
--em-font-family: {{{defaultFontFamily.fontFamily}}};
|
|
20
|
+
--quote-font-family: {{{defaultFontFamily.fontFamily}}};
|
|
21
|
+
--heading-font-family: {{{headingFontFamily.fontFamily}}};
|
|
22
|
+
--code-font-family: {{{codingFontFamily.fontFamily}}};
|
|
22
23
|
|
|
23
24
|
/* Mobile */
|
|
24
25
|
{{#mobileFontData}}
|
|
@@ -58,7 +59,23 @@ var template = `/* Auto-generated by vite-plugin-capsize-radix */
|
|
|
58
59
|
{{{quoteStyles}}}
|
|
59
60
|
}
|
|
60
61
|
|
|
61
|
-
|
|
62
|
+
/* Code text styles */
|
|
63
|
+
{{{mobileCodeStyles}}}
|
|
64
|
+
@media (min-width: 768px) {
|
|
65
|
+
{{{codeStyles}}}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/* Code size variants */
|
|
69
|
+
{{#mobileCodeFontData}}
|
|
70
|
+
{{{style}}}
|
|
71
|
+
{{/mobileCodeFontData}}
|
|
72
|
+
@media (min-width: 768px) {
|
|
73
|
+
{{#codeFontData}}
|
|
74
|
+
{{{style}}}
|
|
75
|
+
{{/codeFontData}}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.rt-Em, .rt-Quote, .rt-Code {
|
|
62
79
|
display: inline-block;
|
|
63
80
|
}
|
|
64
81
|
|
|
@@ -73,42 +90,77 @@ var template = `/* Auto-generated by vite-plugin-capsize-radix */
|
|
|
73
90
|
}
|
|
74
91
|
`;
|
|
75
92
|
async function generate(options) {
|
|
76
|
-
let
|
|
77
|
-
let
|
|
93
|
+
let defaultFontFamily;
|
|
94
|
+
let headingFontFamiliy;
|
|
95
|
+
let codingFontFamily;
|
|
78
96
|
if (!options.defaultFontStack) {
|
|
79
|
-
options.defaultFontStack = [
|
|
80
|
-
|
|
81
|
-
|
|
97
|
+
options.defaultFontStack = [
|
|
98
|
+
appleSystem,
|
|
99
|
+
segoeUI,
|
|
100
|
+
roboto,
|
|
101
|
+
ubuntu,
|
|
102
|
+
notoSans
|
|
103
|
+
];
|
|
104
|
+
defaultFontFamily = createFontStack(options.defaultFontStack);
|
|
105
|
+
defaultFontFamily.fontFamily += `, ui-sans-serif, system-ui, sans-serif`;
|
|
82
106
|
} else if (options.defaultFontStack) {
|
|
83
|
-
|
|
107
|
+
defaultFontFamily = createFontStack(options.defaultFontStack);
|
|
84
108
|
}
|
|
85
109
|
if (options.headingFontStack) {
|
|
86
|
-
|
|
110
|
+
headingFontFamiliy = createFontStack(options.headingFontStack);
|
|
87
111
|
} else {
|
|
88
|
-
|
|
112
|
+
headingFontFamiliy = defaultFontFamily;
|
|
89
113
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
114
|
+
if (options.codingFontStack) {
|
|
115
|
+
codingFontFamily = createFontStack(options.codingFontStack);
|
|
116
|
+
} else {
|
|
117
|
+
options.codingFontStack = [appleSystem];
|
|
118
|
+
codingFontFamily = createFontStack(options.codingFontStack);
|
|
119
|
+
codingFontFamily.fontFamily += `, ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, 'DejaVu Sans Mono', monospace`;
|
|
120
|
+
}
|
|
121
|
+
const mobileFontData = [
|
|
122
|
+
options.textStyles[0],
|
|
123
|
+
...options.textStyles.slice(1)
|
|
124
|
+
].map(({ fontSize, lineHeight }, i) => {
|
|
125
|
+
const lineGap = lineHeight - fontSize;
|
|
126
|
+
const style = createStyleString(
|
|
127
|
+
`rt-r-size-${i + 1}:not(.rt-DialogContent)`,
|
|
128
|
+
{
|
|
129
|
+
capHeight: fontSize,
|
|
130
|
+
lineGap,
|
|
131
|
+
fontMetrics: options.defaultFontStack[0]
|
|
132
|
+
}
|
|
133
|
+
);
|
|
134
|
+
return {
|
|
135
|
+
style,
|
|
136
|
+
...createStyleObject({
|
|
137
|
+
capHeight: fontSize,
|
|
138
|
+
lineGap,
|
|
139
|
+
fontMetrics: options.defaultFontStack[0]
|
|
140
|
+
}),
|
|
141
|
+
i: i + 1
|
|
142
|
+
};
|
|
143
|
+
});
|
|
144
|
+
const mobileCodeFontData = [
|
|
145
|
+
options.textStyles[0],
|
|
146
|
+
...options.textStyles.slice(1)
|
|
147
|
+
].map(({ fontSize, lineHeight }, i) => {
|
|
148
|
+
const lineGap = lineHeight - fontSize;
|
|
149
|
+
const style = createStyleString(`rt-Code.rt-r-size-${i + 1}`, {
|
|
150
|
+
capHeight: fontSize * 0.95,
|
|
151
|
+
lineGap,
|
|
152
|
+
fontMetrics: options.codingFontStack[0]
|
|
153
|
+
});
|
|
154
|
+
return {
|
|
155
|
+
style,
|
|
156
|
+
...createStyleObject({
|
|
157
|
+
capHeight: fontSize * 0.95,
|
|
158
|
+
lineGap,
|
|
159
|
+
fontMetrics: options.codingFontStack[0]
|
|
160
|
+
}),
|
|
161
|
+
i: i + 1
|
|
162
|
+
};
|
|
163
|
+
});
|
|
112
164
|
const fontData = options.textStyles.map(({ fontSize, lineHeight }, i) => {
|
|
113
165
|
const lineGap = lineHeight - fontSize;
|
|
114
166
|
const style = createStyleString(
|
|
@@ -129,6 +181,23 @@ async function generate(options) {
|
|
|
129
181
|
i: i + 1
|
|
130
182
|
};
|
|
131
183
|
});
|
|
184
|
+
const codeFontData = options.textStyles.map(({ fontSize, lineHeight }, i) => {
|
|
185
|
+
const lineGap = lineHeight - fontSize;
|
|
186
|
+
const style = createStyleString(`rt-Code.rt-r-size-${i + 1}`, {
|
|
187
|
+
capHeight: fontSize,
|
|
188
|
+
lineGap,
|
|
189
|
+
fontMetrics: options.codingFontStack[0]
|
|
190
|
+
});
|
|
191
|
+
return {
|
|
192
|
+
style,
|
|
193
|
+
...createStyleObject({
|
|
194
|
+
capHeight: fontSize,
|
|
195
|
+
lineGap,
|
|
196
|
+
fontMetrics: options.codingFontStack[0]
|
|
197
|
+
}),
|
|
198
|
+
i: i + 1
|
|
199
|
+
};
|
|
200
|
+
});
|
|
132
201
|
const mobileTextStyles = createStyleString(`rt-Text`, {
|
|
133
202
|
capHeight: options.textStyles[1].fontSize,
|
|
134
203
|
lineGap: options.textStyles[1].lineHeight - options.textStyles[1].fontSize,
|
|
@@ -144,6 +213,11 @@ async function generate(options) {
|
|
|
144
213
|
lineGap: options.textStyles[1].lineHeight - options.textStyles[1].fontSize,
|
|
145
214
|
fontMetrics: options.defaultFontStack[0]
|
|
146
215
|
});
|
|
216
|
+
const mobileCodeStyles = createStyleString(`rt-Code`, {
|
|
217
|
+
capHeight: options.textStyles[1].fontSize * 0.95,
|
|
218
|
+
lineGap: options.textStyles[1].lineHeight - options.textStyles[1].fontSize,
|
|
219
|
+
fontMetrics: options.codingFontStack[0]
|
|
220
|
+
});
|
|
147
221
|
const textStyles = createStyleString(`rt-Text`, {
|
|
148
222
|
capHeight: options.textStyles[2].fontSize,
|
|
149
223
|
lineGap: options.textStyles[2].lineHeight - options.textStyles[2].fontSize,
|
|
@@ -159,19 +233,29 @@ async function generate(options) {
|
|
|
159
233
|
lineGap: options.textStyles[2].lineHeight - options.textStyles[2].fontSize,
|
|
160
234
|
fontMetrics: options.defaultFontStack[0]
|
|
161
235
|
});
|
|
236
|
+
const codeStyles = createStyleString(`rt-Code`, {
|
|
237
|
+
capHeight: options.textStyles[2].fontSize * 0.95,
|
|
238
|
+
lineGap: options.textStyles[2].lineHeight - options.textStyles[2].fontSize,
|
|
239
|
+
fontMetrics: options.codingFontStack[0]
|
|
240
|
+
});
|
|
162
241
|
fs.writeFileSync(
|
|
163
242
|
options.outputPath,
|
|
164
243
|
Mustache.render(template, {
|
|
165
|
-
|
|
166
|
-
|
|
244
|
+
headingFontFamiliy,
|
|
245
|
+
defaultFontFamily,
|
|
246
|
+
codingFontFamily,
|
|
167
247
|
mobileFontData,
|
|
168
248
|
fontData,
|
|
249
|
+
mobileCodeFontData,
|
|
250
|
+
codeFontData,
|
|
169
251
|
mobileTextStyles,
|
|
170
252
|
textStyles,
|
|
171
253
|
mobileEmStyles,
|
|
172
254
|
emStyles,
|
|
173
255
|
mobileQuoteStyles,
|
|
174
|
-
quoteStyles
|
|
256
|
+
quoteStyles,
|
|
257
|
+
mobileCodeStyles,
|
|
258
|
+
codeStyles
|
|
175
259
|
})
|
|
176
260
|
);
|
|
177
261
|
}
|
|
@@ -189,7 +273,8 @@ function capsizeRadixPlugin({
|
|
|
189
273
|
{ fontSize: 64, lineHeight: 64 }
|
|
190
274
|
],
|
|
191
275
|
defaultFontStack,
|
|
192
|
-
headingFontStack
|
|
276
|
+
headingFontStack,
|
|
277
|
+
codingFontStack
|
|
193
278
|
}) {
|
|
194
279
|
return {
|
|
195
280
|
name: `radix-capsize-plugin`,
|
|
@@ -198,7 +283,8 @@ function capsizeRadixPlugin({
|
|
|
198
283
|
outputPath,
|
|
199
284
|
textStyles,
|
|
200
285
|
defaultFontStack,
|
|
201
|
-
headingFontStack
|
|
286
|
+
headingFontStack,
|
|
287
|
+
codingFontStack
|
|
202
288
|
});
|
|
203
289
|
}
|
|
204
290
|
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-capsize-radix",
|
|
3
3
|
"description": "Great Typography with Radix & Capsize",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.1.1",
|
|
5
5
|
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@capsizecss/core": "^4.1.0",
|
|
8
|
-
"@capsizecss/metrics": "^
|
|
8
|
+
"@capsizecss/metrics": "^3.4.0",
|
|
9
9
|
"mustache": "^4.2.0"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"shx": "^0.3.4",
|
|
25
25
|
"tsup": "^8.0.2",
|
|
26
26
|
"typescript": "^5.4.3",
|
|
27
|
-
"vite": "^
|
|
28
|
-
"vitest": "^
|
|
27
|
+
"vite": "^6.2.3",
|
|
28
|
+
"vitest": "^3.0.9"
|
|
29
29
|
},
|
|
30
30
|
"directories": {
|
|
31
31
|
"example": "example"
|
|
@@ -54,10 +54,10 @@
|
|
|
54
54
|
"main": "./dist/index.js",
|
|
55
55
|
"module": "./dist/index.mjs",
|
|
56
56
|
"scripts": {
|
|
57
|
-
"build": "
|
|
57
|
+
"build": "pnpm run clean && tsup --external @capsizecss/core --external mustache --external @capsizecss/metrics",
|
|
58
58
|
"check": "tsc",
|
|
59
59
|
"clean": "shx rm -rf dist *.d.ts",
|
|
60
|
-
"prepublishOnly": "
|
|
60
|
+
"prepublishOnly": "pnpm run build",
|
|
61
61
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
62
62
|
},
|
|
63
63
|
"tsup": {
|