vite-plugin-capsize-radix 0.0.1 → 0.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/README.md +4 -2
- package/dist/index.cjs +231 -0
- package/dist/index.d.cts +13 -0
- package/dist/index.d.ts +13 -0
- package/{plugin.ts → dist/index.js} +60 -84
- package/package.json +32 -11
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Generate bulletproof typography css for [@radix-ui/themes](https://www.radix-ui.com/)
|
|
4
4
|
|
|
5
|
+
Now changing fonts is as easy as changing colors.
|
|
6
|
+
|
|
5
7
|
## Why
|
|
6
8
|
|
|
7
9
|
Getting custom fonts to look right is hard on the web — so most peoply
|
|
@@ -13,7 +15,7 @@ as the rest of your application.
|
|
|
13
15
|
https://github.com/KyleAMathews/vite-plugin-capsize-radix-ui/assets/71047/3ec5d6ca-bf00-4b79-8552-4e3da3454f52
|
|
14
16
|
|
|
15
17
|
Capsize makes fonts render the way you expect them to. With Capsize, if you
|
|
16
|
-
|
|
18
|
+
assign a font to occupy 16px of height, it _actually_ will.
|
|
17
19
|
|
|
18
20
|
This plugin glues Capsize with the fantastic Radix theming components.
|
|
19
21
|
|
|
@@ -43,7 +45,7 @@ export default defineConfig({
|
|
|
43
45
|
capsizeRadixPlugin({
|
|
44
46
|
// Import this file into your app.
|
|
45
47
|
outputPath: `./public/merriweather.css`,
|
|
46
|
-
// Pass in Capsize font metric objects
|
|
48
|
+
// Pass in Capsize font metric objects.
|
|
47
49
|
defaultFontStack: [merriweather, arial],
|
|
48
50
|
headingFontStack: [merriweatherSans, arial],
|
|
49
51
|
}),
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
radixCapsizePlugin: () => radixCapsizePlugin
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(src_exports);
|
|
36
|
+
var import_fs = __toESM(require("fs"), 1);
|
|
37
|
+
var import_core = require("@capsizecss/core");
|
|
38
|
+
var import_mustache = __toESM(require("mustache"), 1);
|
|
39
|
+
var import_segoeUI = __toESM(require("@capsizecss/metrics/segoeUI"), 1);
|
|
40
|
+
var import_appleSystem = __toESM(require("@capsizecss/metrics/appleSystem"), 1);
|
|
41
|
+
var import_roboto = __toESM(require("@capsizecss/metrics/roboto"), 1);
|
|
42
|
+
var import_ubuntu = __toESM(require("@capsizecss/metrics/ubuntu"), 1);
|
|
43
|
+
var import_notoSans = __toESM(require("@capsizecss/metrics/notoSans"), 1);
|
|
44
|
+
var template = `/* Auto-generated by scripts/generate-typography-styles.ts */
|
|
45
|
+
|
|
46
|
+
/* Override Radix variables */
|
|
47
|
+
.radix-themes {
|
|
48
|
+
--default-font-family: {{{defaultFontStack.fontFamily}}};
|
|
49
|
+
--em-font-family: {{{defaultFontStack.fontFamily}}};
|
|
50
|
+
--quote-font-family: {{{defaultFontStack.fontFamily}}};
|
|
51
|
+
--heading-font-family: {{{headingFontStack.fontFamily}}};
|
|
52
|
+
|
|
53
|
+
/* Mobile */
|
|
54
|
+
{{#mobileFontData}}
|
|
55
|
+
--font-size-{{{i}}}: {{{fontSize}}};
|
|
56
|
+
--line-height-{{{i}}}: {{{lineHeight}}};
|
|
57
|
+
{{/mobileFontData}}
|
|
58
|
+
|
|
59
|
+
/* Larger devices */
|
|
60
|
+
@media (min-width: 768px) {
|
|
61
|
+
{{#fontData}}
|
|
62
|
+
--font-size-{{{i}}}: {{{fontSize}}};
|
|
63
|
+
--line-height-{{{i}}}: {{{lineHeight}}};
|
|
64
|
+
{{/fontData}}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/* Otherwise links don't flow inline */
|
|
69
|
+
.rt-Link {
|
|
70
|
+
display: inline-block;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/* Default text styles */
|
|
74
|
+
{{{mobileTextStyles}}}
|
|
75
|
+
@media (min-width: 768px) {
|
|
76
|
+
{{{textStyles}}}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* Em text styles */
|
|
80
|
+
{{{mobileEmStyles}}}
|
|
81
|
+
@media (min-width: 768px) {
|
|
82
|
+
{{{emStyles}}}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/* Quote text styles */
|
|
86
|
+
{{{mobileQuoteStyles}}}
|
|
87
|
+
@media (min-width: 768px) {
|
|
88
|
+
{{{quoteStyles}}}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.rt-Em, .rt-Quote {
|
|
92
|
+
display: inline-block;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/* Class names for text elements */
|
|
96
|
+
{{#mobileFontData}}
|
|
97
|
+
{{{style}}}
|
|
98
|
+
{{/mobileFontData}}
|
|
99
|
+
@media (min-width: 768px) {
|
|
100
|
+
{{#fontData}}
|
|
101
|
+
{{{style}}}
|
|
102
|
+
{{/fontData}}
|
|
103
|
+
}
|
|
104
|
+
`;
|
|
105
|
+
async function generate(options) {
|
|
106
|
+
let defaultFontStack;
|
|
107
|
+
let headingFontStack;
|
|
108
|
+
if (!options.defaultFontStack) {
|
|
109
|
+
options.defaultFontStack = [import_appleSystem.default, import_segoeUI.default, import_roboto.default, import_ubuntu.default, import_notoSans.default];
|
|
110
|
+
defaultFontStack = (0, import_core.createFontStack)(options.defaultFontStack);
|
|
111
|
+
defaultFontStack.fontFamily += `, ui-sans-serif, system-ui, sans-serif`;
|
|
112
|
+
} else if (options.defaultFontStack) {
|
|
113
|
+
defaultFontStack = (0, import_core.createFontStack)(options.defaultFontStack);
|
|
114
|
+
}
|
|
115
|
+
if (options.headingFontStack) {
|
|
116
|
+
headingFontStack = (0, import_core.createFontStack)(options.headingFontStack);
|
|
117
|
+
} else {
|
|
118
|
+
headingFontStack = defaultFontStack;
|
|
119
|
+
}
|
|
120
|
+
const mobileFontData = [options.fontSizes[0], ...options.fontSizes].map(
|
|
121
|
+
(fontSize, i) => {
|
|
122
|
+
const lineGap = options.lineHeights[i - 1] - fontSize;
|
|
123
|
+
const style = (0, import_core.createStyleString)(
|
|
124
|
+
`rt-r-size-${i + 1}:not(.rt-DialogContent)`,
|
|
125
|
+
{
|
|
126
|
+
capHeight: fontSize,
|
|
127
|
+
lineGap,
|
|
128
|
+
fontMetrics: options.defaultFontStack[0]
|
|
129
|
+
}
|
|
130
|
+
);
|
|
131
|
+
return {
|
|
132
|
+
style,
|
|
133
|
+
...(0, import_core.createStyleObject)({
|
|
134
|
+
capHeight: fontSize,
|
|
135
|
+
lineGap,
|
|
136
|
+
fontMetrics: options.defaultFontStack[0]
|
|
137
|
+
}),
|
|
138
|
+
i: i + 1
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
);
|
|
142
|
+
const fontData = options.fontSizes.map((fontSize, i) => {
|
|
143
|
+
const lineGap = options.lineHeights[i] - fontSize;
|
|
144
|
+
const style = (0, import_core.createStyleString)(
|
|
145
|
+
`rt-r-size-${i + 1}:not(.rt-DialogContent)`,
|
|
146
|
+
{
|
|
147
|
+
capHeight: fontSize,
|
|
148
|
+
lineGap,
|
|
149
|
+
fontMetrics: options.defaultFontStack[0]
|
|
150
|
+
}
|
|
151
|
+
);
|
|
152
|
+
return {
|
|
153
|
+
style,
|
|
154
|
+
...(0, import_core.createStyleObject)({
|
|
155
|
+
capHeight: fontSize,
|
|
156
|
+
lineGap,
|
|
157
|
+
fontMetrics: options.defaultFontStack[0]
|
|
158
|
+
}),
|
|
159
|
+
i: i + 1
|
|
160
|
+
};
|
|
161
|
+
});
|
|
162
|
+
const mobileTextStyles = (0, import_core.createStyleString)(`rt-Text`, {
|
|
163
|
+
capHeight: options.fontSizes[1],
|
|
164
|
+
lineGap: options.lineHeights[1] - options.fontSizes[1],
|
|
165
|
+
fontMetrics: options.defaultFontStack[0]
|
|
166
|
+
});
|
|
167
|
+
const mobileEmStyles = (0, import_core.createStyleString)(`rt-Em`, {
|
|
168
|
+
capHeight: options.fontSizes[1],
|
|
169
|
+
lineGap: options.lineHeights[1] - options.fontSizes[1],
|
|
170
|
+
fontMetrics: options.defaultFontStack[0]
|
|
171
|
+
});
|
|
172
|
+
const mobileQuoteStyles = (0, import_core.createStyleString)(`rt-Quote`, {
|
|
173
|
+
capHeight: options.fontSizes[1],
|
|
174
|
+
lineGap: options.lineHeights[1] - options.fontSizes[1],
|
|
175
|
+
fontMetrics: options.defaultFontStack[0]
|
|
176
|
+
});
|
|
177
|
+
const textStyles = (0, import_core.createStyleString)(`rt-Text`, {
|
|
178
|
+
capHeight: options.fontSizes[2],
|
|
179
|
+
lineGap: options.lineHeights[2] - options.fontSizes[2],
|
|
180
|
+
fontMetrics: options.defaultFontStack[0]
|
|
181
|
+
});
|
|
182
|
+
const emStyles = (0, import_core.createStyleString)(`rt-Em`, {
|
|
183
|
+
capHeight: options.fontSizes[2],
|
|
184
|
+
lineGap: options.lineHeights[2] - options.fontSizes[2],
|
|
185
|
+
fontMetrics: options.defaultFontStack[0]
|
|
186
|
+
});
|
|
187
|
+
const quoteStyles = (0, import_core.createStyleString)(`rt-Quote`, {
|
|
188
|
+
capHeight: options.fontSizes[2],
|
|
189
|
+
lineGap: options.lineHeights[2] - options.fontSizes[2],
|
|
190
|
+
fontMetrics: options.defaultFontStack[0]
|
|
191
|
+
});
|
|
192
|
+
import_fs.default.writeFileSync(
|
|
193
|
+
options.outputPath,
|
|
194
|
+
import_mustache.default.render(template, {
|
|
195
|
+
headingFontStack,
|
|
196
|
+
defaultFontStack,
|
|
197
|
+
mobileFontData,
|
|
198
|
+
fontData,
|
|
199
|
+
mobileTextStyles,
|
|
200
|
+
textStyles,
|
|
201
|
+
mobileEmStyles,
|
|
202
|
+
emStyles,
|
|
203
|
+
mobileQuoteStyles,
|
|
204
|
+
quoteStyles
|
|
205
|
+
})
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
function radixCapsizePlugin({
|
|
209
|
+
outputPath,
|
|
210
|
+
fontSizes = [9, 11, 12, 14, 18, 24, 36, 48, 64],
|
|
211
|
+
lineHeights = [21, 24, 26, 27, 29, 36, 44, 52, 64],
|
|
212
|
+
defaultFontStack,
|
|
213
|
+
headingFontStack
|
|
214
|
+
}) {
|
|
215
|
+
return {
|
|
216
|
+
name: `radix-capsize-plugin`,
|
|
217
|
+
buildStart() {
|
|
218
|
+
generate({
|
|
219
|
+
outputPath,
|
|
220
|
+
fontSizes,
|
|
221
|
+
lineHeights,
|
|
222
|
+
defaultFontStack,
|
|
223
|
+
headingFontStack
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
229
|
+
0 && (module.exports = {
|
|
230
|
+
radixCapsizePlugin
|
|
231
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
import { FontMetrics } from '@capsizecss/core';
|
|
3
|
+
|
|
4
|
+
interface Options {
|
|
5
|
+
outputPath: string;
|
|
6
|
+
fontSizes?: number[];
|
|
7
|
+
lineHeights?: number[];
|
|
8
|
+
defaultFontStack?: FontMetrics[];
|
|
9
|
+
headingFontStack?: FontMetrics[];
|
|
10
|
+
}
|
|
11
|
+
declare function radixCapsizePlugin({ outputPath, fontSizes, lineHeights, defaultFontStack, headingFontStack, }: Options): Plugin;
|
|
12
|
+
|
|
13
|
+
export { radixCapsizePlugin };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
import { FontMetrics } from '@capsizecss/core';
|
|
3
|
+
|
|
4
|
+
interface Options {
|
|
5
|
+
outputPath: string;
|
|
6
|
+
fontSizes?: number[];
|
|
7
|
+
lineHeights?: number[];
|
|
8
|
+
defaultFontStack?: FontMetrics[];
|
|
9
|
+
headingFontStack?: FontMetrics[];
|
|
10
|
+
}
|
|
11
|
+
declare function radixCapsizePlugin({ outputPath, fontSizes, lineHeights, defaultFontStack, headingFontStack, }: Options): Plugin;
|
|
12
|
+
|
|
13
|
+
export { radixCapsizePlugin };
|
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
import fs from "fs"
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import fs from "fs";
|
|
3
3
|
import {
|
|
4
4
|
createStyleObject,
|
|
5
5
|
createStyleString,
|
|
6
|
-
createFontStack
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
import ubuntu from "@capsizecss/metrics/ubuntu"
|
|
16
|
-
import cantarell from "@capsizecss/metrics/cantarell"
|
|
17
|
-
import notoSans from "@capsizecss/metrics/notoSans"
|
|
18
|
-
|
|
19
|
-
const template = `/* Auto-generated by scripts/generate-typography-styles.ts */
|
|
6
|
+
createFontStack
|
|
7
|
+
} from "@capsizecss/core";
|
|
8
|
+
import Mustache from "mustache";
|
|
9
|
+
import segoeUI from "@capsizecss/metrics/segoeUI";
|
|
10
|
+
import appleSystem from "@capsizecss/metrics/appleSystem";
|
|
11
|
+
import roboto from "@capsizecss/metrics/roboto";
|
|
12
|
+
import ubuntu from "@capsizecss/metrics/ubuntu";
|
|
13
|
+
import notoSans from "@capsizecss/metrics/notoSans";
|
|
14
|
+
var template = `/* Auto-generated by scripts/generate-typography-styles.ts */
|
|
20
15
|
|
|
21
16
|
/* Override Radix variables */
|
|
22
17
|
.radix-themes {
|
|
@@ -76,109 +71,94 @@ const template = `/* Auto-generated by scripts/generate-typography-styles.ts */
|
|
|
76
71
|
{{{style}}}
|
|
77
72
|
{{/fontData}}
|
|
78
73
|
}
|
|
79
|
-
|
|
80
|
-
|
|
74
|
+
`;
|
|
81
75
|
async function generate(options) {
|
|
82
|
-
let defaultFontStack
|
|
83
|
-
let headingFontStack
|
|
84
|
-
if (options.defaultFontStack) {
|
|
85
|
-
defaultFontStack =
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
roboto,
|
|
91
|
-
ubuntu,
|
|
92
|
-
cantarell,
|
|
93
|
-
notoSans,
|
|
94
|
-
]
|
|
95
|
-
defaultFontStack = createFontStack(options.defaultFontStack)
|
|
96
|
-
|
|
97
|
-
// We prefer to determanistically pick the font w/ the stack above so then the font trimmings work
|
|
98
|
-
// but we if we can't, we'll fall back to these.
|
|
99
|
-
defaultFontStack.fontFamily += `, ui-sans-serif, system-ui, sans-serif`
|
|
76
|
+
let defaultFontStack;
|
|
77
|
+
let headingFontStack;
|
|
78
|
+
if (!options.defaultFontStack) {
|
|
79
|
+
options.defaultFontStack = [appleSystem, segoeUI, roboto, ubuntu, notoSans];
|
|
80
|
+
defaultFontStack = createFontStack(options.defaultFontStack);
|
|
81
|
+
defaultFontStack.fontFamily += `, ui-sans-serif, system-ui, sans-serif`;
|
|
82
|
+
} else if (options.defaultFontStack) {
|
|
83
|
+
defaultFontStack = createFontStack(options.defaultFontStack);
|
|
100
84
|
}
|
|
101
85
|
if (options.headingFontStack) {
|
|
102
|
-
headingFontStack = createFontStack(options.headingFontStack)
|
|
86
|
+
headingFontStack = createFontStack(options.headingFontStack);
|
|
103
87
|
} else {
|
|
104
|
-
headingFontStack = defaultFontStack
|
|
88
|
+
headingFontStack = defaultFontStack;
|
|
105
89
|
}
|
|
106
|
-
|
|
107
90
|
const mobileFontData = [options.fontSizes[0], ...options.fontSizes].map(
|
|
108
91
|
(fontSize, i) => {
|
|
109
|
-
const lineGap = options.lineHeights[i - 1] - fontSize
|
|
92
|
+
const lineGap = options.lineHeights[i - 1] - fontSize;
|
|
110
93
|
const style = createStyleString(
|
|
111
94
|
`rt-r-size-${i + 1}:not(.rt-DialogContent)`,
|
|
112
95
|
{
|
|
113
96
|
capHeight: fontSize,
|
|
114
97
|
lineGap,
|
|
115
|
-
fontMetrics: options.defaultFontStack[0]
|
|
98
|
+
fontMetrics: options.defaultFontStack[0]
|
|
116
99
|
}
|
|
117
|
-
)
|
|
100
|
+
);
|
|
118
101
|
return {
|
|
119
102
|
style,
|
|
120
103
|
...createStyleObject({
|
|
121
104
|
capHeight: fontSize,
|
|
122
105
|
lineGap,
|
|
123
|
-
fontMetrics: options.defaultFontStack[0]
|
|
106
|
+
fontMetrics: options.defaultFontStack[0]
|
|
124
107
|
}),
|
|
125
|
-
i: i + 1
|
|
126
|
-
}
|
|
108
|
+
i: i + 1
|
|
109
|
+
};
|
|
127
110
|
}
|
|
128
|
-
)
|
|
111
|
+
);
|
|
129
112
|
const fontData = options.fontSizes.map((fontSize, i) => {
|
|
130
|
-
const lineGap = options.lineHeights[i] - fontSize
|
|
113
|
+
const lineGap = options.lineHeights[i] - fontSize;
|
|
131
114
|
const style = createStyleString(
|
|
132
115
|
`rt-r-size-${i + 1}:not(.rt-DialogContent)`,
|
|
133
116
|
{
|
|
134
117
|
capHeight: fontSize,
|
|
135
118
|
lineGap,
|
|
136
|
-
fontMetrics: options.defaultFontStack[0]
|
|
119
|
+
fontMetrics: options.defaultFontStack[0]
|
|
137
120
|
}
|
|
138
|
-
)
|
|
121
|
+
);
|
|
139
122
|
return {
|
|
140
123
|
style,
|
|
141
124
|
...createStyleObject({
|
|
142
125
|
capHeight: fontSize,
|
|
143
126
|
lineGap,
|
|
144
|
-
fontMetrics: options.defaultFontStack[0]
|
|
127
|
+
fontMetrics: options.defaultFontStack[0]
|
|
145
128
|
}),
|
|
146
|
-
i: i + 1
|
|
147
|
-
}
|
|
148
|
-
})
|
|
149
|
-
|
|
129
|
+
i: i + 1
|
|
130
|
+
};
|
|
131
|
+
});
|
|
150
132
|
const mobileTextStyles = createStyleString(`rt-Text`, {
|
|
151
133
|
capHeight: options.fontSizes[1],
|
|
152
134
|
lineGap: options.lineHeights[1] - options.fontSizes[1],
|
|
153
|
-
fontMetrics: options.defaultFontStack[0]
|
|
154
|
-
})
|
|
135
|
+
fontMetrics: options.defaultFontStack[0]
|
|
136
|
+
});
|
|
155
137
|
const mobileEmStyles = createStyleString(`rt-Em`, {
|
|
156
138
|
capHeight: options.fontSizes[1],
|
|
157
139
|
lineGap: options.lineHeights[1] - options.fontSizes[1],
|
|
158
|
-
fontMetrics: options.defaultFontStack[0]
|
|
159
|
-
})
|
|
140
|
+
fontMetrics: options.defaultFontStack[0]
|
|
141
|
+
});
|
|
160
142
|
const mobileQuoteStyles = createStyleString(`rt-Quote`, {
|
|
161
143
|
capHeight: options.fontSizes[1],
|
|
162
144
|
lineGap: options.lineHeights[1] - options.fontSizes[1],
|
|
163
|
-
fontMetrics: options.defaultFontStack[0]
|
|
164
|
-
})
|
|
165
|
-
|
|
145
|
+
fontMetrics: options.defaultFontStack[0]
|
|
146
|
+
});
|
|
166
147
|
const textStyles = createStyleString(`rt-Text`, {
|
|
167
148
|
capHeight: options.fontSizes[2],
|
|
168
149
|
lineGap: options.lineHeights[2] - options.fontSizes[2],
|
|
169
|
-
fontMetrics: options.defaultFontStack[0]
|
|
170
|
-
})
|
|
150
|
+
fontMetrics: options.defaultFontStack[0]
|
|
151
|
+
});
|
|
171
152
|
const emStyles = createStyleString(`rt-Em`, {
|
|
172
153
|
capHeight: options.fontSizes[2],
|
|
173
154
|
lineGap: options.lineHeights[2] - options.fontSizes[2],
|
|
174
|
-
fontMetrics: options.defaultFontStack[0]
|
|
175
|
-
})
|
|
155
|
+
fontMetrics: options.defaultFontStack[0]
|
|
156
|
+
});
|
|
176
157
|
const quoteStyles = createStyleString(`rt-Quote`, {
|
|
177
158
|
capHeight: options.fontSizes[2],
|
|
178
159
|
lineGap: options.lineHeights[2] - options.fontSizes[2],
|
|
179
|
-
fontMetrics: options.defaultFontStack[0]
|
|
180
|
-
})
|
|
181
|
-
|
|
160
|
+
fontMetrics: options.defaultFontStack[0]
|
|
161
|
+
});
|
|
182
162
|
fs.writeFileSync(
|
|
183
163
|
options.outputPath,
|
|
184
164
|
Mustache.render(template, {
|
|
@@ -191,24 +171,17 @@ async function generate(options) {
|
|
|
191
171
|
mobileEmStyles,
|
|
192
172
|
emStyles,
|
|
193
173
|
mobileQuoteStyles,
|
|
194
|
-
quoteStyles
|
|
174
|
+
quoteStyles
|
|
195
175
|
})
|
|
196
|
-
)
|
|
176
|
+
);
|
|
197
177
|
}
|
|
198
|
-
|
|
199
|
-
export function radixCapsizePlugin({
|
|
178
|
+
function radixCapsizePlugin({
|
|
200
179
|
outputPath,
|
|
201
180
|
fontSizes = [9, 11, 12, 14, 18, 24, 36, 48, 64],
|
|
202
181
|
lineHeights = [21, 24, 26, 27, 29, 36, 44, 52, 64],
|
|
203
182
|
defaultFontStack,
|
|
204
|
-
headingFontStack
|
|
205
|
-
}
|
|
206
|
-
outputPath: string
|
|
207
|
-
fontSizes?: number[]
|
|
208
|
-
lineHeights?: number[]
|
|
209
|
-
defaultFontStack?: FontMetrics[]
|
|
210
|
-
headingFontStack?: FontMetrics[]
|
|
211
|
-
}): Plugin {
|
|
183
|
+
headingFontStack
|
|
184
|
+
}) {
|
|
212
185
|
return {
|
|
213
186
|
name: `radix-capsize-plugin`,
|
|
214
187
|
buildStart() {
|
|
@@ -217,8 +190,11 @@ export function radixCapsizePlugin({
|
|
|
217
190
|
fontSizes,
|
|
218
191
|
lineHeights,
|
|
219
192
|
defaultFontStack,
|
|
220
|
-
headingFontStack
|
|
221
|
-
})
|
|
222
|
-
}
|
|
223
|
-
}
|
|
193
|
+
headingFontStack
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
};
|
|
224
197
|
}
|
|
198
|
+
export {
|
|
199
|
+
radixCapsizePlugin
|
|
200
|
+
};
|
package/package.json
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-capsize-radix",
|
|
3
3
|
"description": "Great Typography with Radix & Capsize",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.2",
|
|
5
5
|
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@capsizecss/core": "^4.1.0"
|
|
8
|
-
"@capsizecss/metrics": "^2.2.0",
|
|
9
|
-
"@types/mustache": "^4.2.5",
|
|
10
|
-
"mustache": "^4.2.0"
|
|
7
|
+
"@capsizecss/core": "^4.1.0"
|
|
11
8
|
},
|
|
12
9
|
"devDependencies": {
|
|
10
|
+
"@capsizecss/metrics": "^2.2.0",
|
|
13
11
|
"@capsizecss/unpack": "^2.1.0",
|
|
12
|
+
"@types/mustache": "^4.2.5",
|
|
14
13
|
"@typescript-eslint/eslint-plugin": "^7.4.0",
|
|
15
14
|
"@typescript-eslint/parser": "^7.4.0",
|
|
16
15
|
"eslint": "^8.57.0",
|
|
@@ -20,7 +19,10 @@
|
|
|
20
19
|
"eslint-plugin-react": "^7.34.1",
|
|
21
20
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
22
21
|
"eslint-plugin-react-refresh": "^0.4.6",
|
|
22
|
+
"mustache": "^4.2.0",
|
|
23
23
|
"prettier": "^3.2.5",
|
|
24
|
+
"shx": "^0.3.4",
|
|
25
|
+
"tsup": "^8.0.2",
|
|
24
26
|
"typescript": "^5.4.3",
|
|
25
27
|
"vite": "^5.2.6",
|
|
26
28
|
"vitest": "^1.4.0"
|
|
@@ -30,12 +32,17 @@
|
|
|
30
32
|
},
|
|
31
33
|
"exports": {
|
|
32
34
|
".": {
|
|
33
|
-
"types":
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
"types": {
|
|
36
|
+
"import": "./dist/index.d.ts",
|
|
37
|
+
"require": "./dist/index.d.cts"
|
|
38
|
+
},
|
|
39
|
+
"import": "./dist/index.js",
|
|
40
|
+
"require": "./dist/index.cjs"
|
|
41
|
+
},
|
|
42
|
+
"./package.json": "./package.json"
|
|
36
43
|
},
|
|
37
44
|
"files": [
|
|
38
|
-
"
|
|
45
|
+
"dist"
|
|
39
46
|
],
|
|
40
47
|
"keywords": [
|
|
41
48
|
"capsizecss",
|
|
@@ -44,10 +51,24 @@
|
|
|
44
51
|
"vite-plugin"
|
|
45
52
|
],
|
|
46
53
|
"license": "MIT",
|
|
47
|
-
"main": "index.
|
|
54
|
+
"main": "./dist/index.cjs",
|
|
55
|
+
"module": "./dist/index.js",
|
|
48
56
|
"scripts": {
|
|
57
|
+
"build": "npm run clean && tsup --external @capsizecss/core --external mustache --external @capsizecss/metrics",
|
|
58
|
+
"check": "tsc",
|
|
59
|
+
"clean": "shx rm -rf dist *.d.ts",
|
|
49
60
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
50
61
|
},
|
|
62
|
+
"tsup": {
|
|
63
|
+
"entry": [
|
|
64
|
+
"src/index.ts"
|
|
65
|
+
],
|
|
66
|
+
"format": [
|
|
67
|
+
"esm",
|
|
68
|
+
"cjs"
|
|
69
|
+
],
|
|
70
|
+
"dts": true
|
|
71
|
+
},
|
|
51
72
|
"type": "module",
|
|
52
|
-
"types": "./
|
|
73
|
+
"types": "./dist/index.d.ts"
|
|
53
74
|
}
|