vite-plugin-capsize-radix 0.1.1 → 0.1.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 CHANGED
@@ -31,6 +31,7 @@ if you're interested on collaborating on one.
31
31
  ### Add to vite.config.ts
32
32
 
33
33
  A sample React config:
34
+
34
35
  ```ts
35
36
  import { defineConfig } from "vite"
36
37
  import react from "@vitejs/plugin-react-swc"
@@ -51,11 +52,12 @@ export default defineConfig({
51
52
  headingFontStack: [merriweatherSans, arial],
52
53
  codingFontStack: [sourceCodePro, arial],
53
54
  }),
54
- ]
55
+ ],
55
56
  })
56
57
  ```
57
58
 
58
59
  ### Using with Radix UI
60
+
59
61
  This plugin overrides all typography related CSS for Radix so you can simply
60
62
  use their typography components as normal (e.g. `<Heading>`, `<Text>`, `<Strong>`, etc)
61
63
 
@@ -87,26 +89,27 @@ Capsize has precalculated metrics for system and many open source fonts. If you'
87
89
  using a custom font, you can calculate the font metrics using their [@capsizecss/unpack](https://github.com/seek-oss/capsize?tab=readme-ov-file#unpack) package.
88
90
 
89
91
  ## Responsive styles
92
+
90
93
  This plugin automatically generates responsive styles. Typically you want your mobile font-size
91
94
  to be slightly smaller than on desktop. We do that by shifting the text a size smaller on mobile.
92
95
 
93
96
  ## Parameters:
94
97
 
95
- * __outputPath (string): Required__. The file path where the generated CSS or design tokens should be saved.
96
- * __textStyles (TextStyle[]): Optional__. An array of objects, each representing a text style. Each object contains two properties: `fontSize` and `lineHeight`, which are numerical values, pixels for `fontSize` and pixels or relative value for `lineHeight`. Defaults to:
97
- ```ts
98
- [
99
- { fontSize: 9, lineHeight: 21 },
100
- { fontSize: 11, lineHeight: 23 },
101
- { fontSize: 12, lineHeight: 25 },
102
- { fontSize: 14, lineHeight: 27 },
103
- { fontSize: 18, lineHeight: 29 },
104
- { fontSize: 24, lineHeight: 36 },
105
- { fontSize: 36, lineHeight: 44 },
106
- { fontSize: 48, lineHeight: 52 },
107
- { fontSize: 64, lineHeight: 64 }
108
- ]
109
- ```
110
- * __defaultFontStack (FontMetrics[]): Optional__. An array of `FontMetrics` objects. Defaults to a System Font stack.
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`.
98
+ - **outputPath (string): Required**. The file path where the generated CSS or design tokens should be saved.
99
+ - **textStyles (TextStyle[]): Optional**. An array of objects, each representing a text style. Each object contains two properties: `fontSize` and `lineHeight`, which are numerical values, pixels for `fontSize` and pixels or relative value for `lineHeight`. Defaults to:
100
+ ```ts
101
+ ;[
102
+ { fontSize: 9, lineHeight: 21 },
103
+ { fontSize: 11, lineHeight: 23 },
104
+ { fontSize: 12, lineHeight: 25 },
105
+ { fontSize: 14, lineHeight: 27 },
106
+ { fontSize: 18, lineHeight: 29 },
107
+ { fontSize: 24, lineHeight: 36 },
108
+ { fontSize: 36, lineHeight: 44 },
109
+ { fontSize: 48, lineHeight: 52 },
110
+ { fontSize: 64, lineHeight: 64 },
111
+ ]
112
+ ```
113
+ - **defaultFontStack (FontMetrics[]): Optional**. An array of `FontMetrics` objects. Defaults to a System Font stack.
114
+ - **headingFontStack (FontMetrics[]): Optional**. An array of `FontMetrics` objects. Defaults to your `defaultFontStack`.
115
+ - **codingFontStack (FontMetrics[]): Optional**. An array of `FontMetrics` objects. Defaults to your `defaultFontStack`.
package/dist/index.js CHANGED
@@ -41,6 +41,9 @@ var import_appleSystem = __toESM(require("@capsizecss/metrics/appleSystem"));
41
41
  var import_roboto = __toESM(require("@capsizecss/metrics/roboto"));
42
42
  var import_ubuntu = __toESM(require("@capsizecss/metrics/ubuntu"));
43
43
  var import_notoSans = __toESM(require("@capsizecss/metrics/notoSans"));
44
+ var TEXT_ELEMENTS = `.rt-Text, .rt-Heading, .rt-Em, .rt-Quote, .rt-Link`;
45
+ var TEXT_SELECTOR_PLACEHOLDER = `__CAPSIZE_TEXT__`;
46
+ var TEXT_SELECTOR_REPLACEMENT = `:where(${TEXT_ELEMENTS})`;
44
47
  var template = `/* Auto-generated by vite-plugin-capsize-radix */
45
48
 
46
49
  /* Override Radix variables */
@@ -109,7 +112,7 @@ var template = `/* Auto-generated by vite-plugin-capsize-radix */
109
112
  display: inline-block;
110
113
  }
111
114
 
112
- /* Class names for text elements */
115
+ /* Size variants for text elements only */
113
116
  {{#mobileFontData}}
114
117
  {{{style}}}
115
118
  {{/mobileFontData}}
@@ -154,7 +157,7 @@ async function generate(options) {
154
157
  ].map(({ fontSize, lineHeight }, i) => {
155
158
  const lineGap = lineHeight - fontSize;
156
159
  const style = (0, import_core.createStyleString)(
157
- `rt-r-size-${i + 1}:not(.rt-DialogContent)`,
160
+ `${TEXT_SELECTOR_PLACEHOLDER}.rt-r-size-${i + 1}`,
158
161
  {
159
162
  capHeight: fontSize,
160
163
  lineGap,
@@ -194,7 +197,7 @@ async function generate(options) {
194
197
  const fontData = options.textStyles.map(({ fontSize, lineHeight }, i) => {
195
198
  const lineGap = lineHeight - fontSize;
196
199
  const style = (0, import_core.createStyleString)(
197
- `rt-r-size-${i + 1}:not(.rt-DialogContent)`,
200
+ `${TEXT_SELECTOR_PLACEHOLDER}.rt-r-size-${i + 1}`,
198
201
  {
199
202
  capHeight: fontSize,
200
203
  lineGap,
@@ -268,26 +271,29 @@ async function generate(options) {
268
271
  lineGap: options.textStyles[2].lineHeight - options.textStyles[2].fontSize,
269
272
  fontMetrics: options.codingFontStack[0]
270
273
  });
271
- import_fs.default.writeFileSync(
272
- options.outputPath,
273
- import_mustache.default.render(template, {
274
- headingFontFamiliy,
275
- defaultFontFamily,
276
- codingFontFamily,
277
- mobileFontData,
278
- fontData,
279
- mobileCodeFontData,
280
- codeFontData,
281
- mobileTextStyles,
282
- textStyles,
283
- mobileEmStyles,
284
- emStyles,
285
- mobileQuoteStyles,
286
- quoteStyles,
287
- mobileCodeStyles,
288
- codeStyles
289
- })
274
+ const output = import_mustache.default.render(template, {
275
+ headingFontFamiliy,
276
+ defaultFontFamily,
277
+ codingFontFamily,
278
+ mobileFontData,
279
+ fontData,
280
+ mobileCodeFontData,
281
+ codeFontData,
282
+ mobileTextStyles,
283
+ textStyles,
284
+ mobileEmStyles,
285
+ emStyles,
286
+ mobileQuoteStyles,
287
+ quoteStyles,
288
+ mobileCodeStyles,
289
+ codeStyles
290
+ });
291
+ const placeholderRegex = new RegExp(`\\.${TEXT_SELECTOR_PLACEHOLDER}`, `g`);
292
+ const finalOutput = output.replace(
293
+ placeholderRegex,
294
+ TEXT_SELECTOR_REPLACEMENT
290
295
  );
296
+ import_fs.default.writeFileSync(options.outputPath, finalOutput);
291
297
  }
292
298
  function capsizeRadixPlugin({
293
299
  outputPath,
package/dist/index.mjs CHANGED
@@ -11,6 +11,9 @@ import appleSystem from "@capsizecss/metrics/appleSystem";
11
11
  import roboto from "@capsizecss/metrics/roboto";
12
12
  import ubuntu from "@capsizecss/metrics/ubuntu";
13
13
  import notoSans from "@capsizecss/metrics/notoSans";
14
+ var TEXT_ELEMENTS = `.rt-Text, .rt-Heading, .rt-Em, .rt-Quote, .rt-Link`;
15
+ var TEXT_SELECTOR_PLACEHOLDER = `__CAPSIZE_TEXT__`;
16
+ var TEXT_SELECTOR_REPLACEMENT = `:where(${TEXT_ELEMENTS})`;
14
17
  var template = `/* Auto-generated by vite-plugin-capsize-radix */
15
18
 
16
19
  /* Override Radix variables */
@@ -79,7 +82,7 @@ var template = `/* Auto-generated by vite-plugin-capsize-radix */
79
82
  display: inline-block;
80
83
  }
81
84
 
82
- /* Class names for text elements */
85
+ /* Size variants for text elements only */
83
86
  {{#mobileFontData}}
84
87
  {{{style}}}
85
88
  {{/mobileFontData}}
@@ -124,7 +127,7 @@ async function generate(options) {
124
127
  ].map(({ fontSize, lineHeight }, i) => {
125
128
  const lineGap = lineHeight - fontSize;
126
129
  const style = createStyleString(
127
- `rt-r-size-${i + 1}:not(.rt-DialogContent)`,
130
+ `${TEXT_SELECTOR_PLACEHOLDER}.rt-r-size-${i + 1}`,
128
131
  {
129
132
  capHeight: fontSize,
130
133
  lineGap,
@@ -164,7 +167,7 @@ async function generate(options) {
164
167
  const fontData = options.textStyles.map(({ fontSize, lineHeight }, i) => {
165
168
  const lineGap = lineHeight - fontSize;
166
169
  const style = createStyleString(
167
- `rt-r-size-${i + 1}:not(.rt-DialogContent)`,
170
+ `${TEXT_SELECTOR_PLACEHOLDER}.rt-r-size-${i + 1}`,
168
171
  {
169
172
  capHeight: fontSize,
170
173
  lineGap,
@@ -238,26 +241,29 @@ async function generate(options) {
238
241
  lineGap: options.textStyles[2].lineHeight - options.textStyles[2].fontSize,
239
242
  fontMetrics: options.codingFontStack[0]
240
243
  });
241
- fs.writeFileSync(
242
- options.outputPath,
243
- Mustache.render(template, {
244
- headingFontFamiliy,
245
- defaultFontFamily,
246
- codingFontFamily,
247
- mobileFontData,
248
- fontData,
249
- mobileCodeFontData,
250
- codeFontData,
251
- mobileTextStyles,
252
- textStyles,
253
- mobileEmStyles,
254
- emStyles,
255
- mobileQuoteStyles,
256
- quoteStyles,
257
- mobileCodeStyles,
258
- codeStyles
259
- })
244
+ const output = Mustache.render(template, {
245
+ headingFontFamiliy,
246
+ defaultFontFamily,
247
+ codingFontFamily,
248
+ mobileFontData,
249
+ fontData,
250
+ mobileCodeFontData,
251
+ codeFontData,
252
+ mobileTextStyles,
253
+ textStyles,
254
+ mobileEmStyles,
255
+ emStyles,
256
+ mobileQuoteStyles,
257
+ quoteStyles,
258
+ mobileCodeStyles,
259
+ codeStyles
260
+ });
261
+ const placeholderRegex = new RegExp(`\\.${TEXT_SELECTOR_PLACEHOLDER}`, `g`);
262
+ const finalOutput = output.replace(
263
+ placeholderRegex,
264
+ TEXT_SELECTOR_REPLACEMENT
260
265
  );
266
+ fs.writeFileSync(options.outputPath, finalOutput);
261
267
  }
262
268
  function capsizeRadixPlugin({
263
269
  outputPath,
package/package.json CHANGED
@@ -1,31 +1,32 @@
1
1
  {
2
2
  "name": "vite-plugin-capsize-radix",
3
3
  "description": "Great Typography with Radix & Capsize",
4
- "version": "0.1.1",
4
+ "version": "0.1.2",
5
5
  "author": "Kyle Mathews <mathews.kyle@gmail.com>",
6
6
  "dependencies": {
7
- "@capsizecss/core": "^4.1.0",
8
- "@capsizecss/metrics": "^3.4.0",
7
+ "@capsizecss/core": "^4.1.3",
8
+ "@capsizecss/metrics": "^3.6.2",
9
9
  "mustache": "^4.2.0"
10
10
  },
11
11
  "devDependencies": {
12
- "@capsizecss/unpack": "^2.1.0",
13
- "@types/mustache": "^4.2.5",
12
+ "@capsizecss/unpack": "^2.4.0",
13
+ "@types/mustache": "^4.2.6",
14
+ "@types/node": "^25.0.3",
14
15
  "@typescript-eslint/eslint-plugin": "^7.4.0",
15
16
  "@typescript-eslint/parser": "^7.4.0",
16
17
  "eslint": "^8.57.0",
17
- "eslint-config-prettier": "^9.1.0",
18
+ "eslint-config-prettier": "^9.1.2",
18
19
  "eslint-config-react": "^1.1.7",
19
- "eslint-plugin-prettier": "^5.1.3",
20
- "eslint-plugin-react": "^7.34.1",
20
+ "eslint-plugin-prettier": "^5.5.4",
21
+ "eslint-plugin-react": "^7.37.5",
21
22
  "eslint-plugin-react-hooks": "^4.6.0",
22
- "eslint-plugin-react-refresh": "^0.4.6",
23
- "prettier": "^3.2.5",
23
+ "eslint-plugin-react-refresh": "^0.4.26",
24
+ "prettier": "^3.7.4",
24
25
  "shx": "^0.3.4",
25
- "tsup": "^8.0.2",
26
- "typescript": "^5.4.3",
27
- "vite": "^6.2.3",
28
- "vitest": "^3.0.9"
26
+ "tsup": "^8.5.1",
27
+ "typescript": "^5.9.3",
28
+ "vite": "^6.4.1",
29
+ "vitest": "^3.2.4"
29
30
  },
30
31
  "directories": {
31
32
  "example": "example"
@@ -53,13 +54,6 @@
53
54
  "license": "MIT",
54
55
  "main": "./dist/index.js",
55
56
  "module": "./dist/index.mjs",
56
- "scripts": {
57
- "build": "pnpm run clean && tsup --external @capsizecss/core --external mustache --external @capsizecss/metrics",
58
- "check": "tsc",
59
- "clean": "shx rm -rf dist *.d.ts",
60
- "prepublishOnly": "pnpm run build",
61
- "test": "echo \"Error: no test specified\" && exit 1"
62
- },
63
57
  "tsup": {
64
58
  "entry": [
65
59
  "src/index.ts"
@@ -70,5 +64,14 @@
70
64
  ],
71
65
  "dts": true
72
66
  },
73
- "types": "./dist/index.d.ts"
74
- }
67
+ "types": "./dist/index.d.ts",
68
+ "scripts": {
69
+ "build": "pnpm run clean && tsup --external @capsizecss/core --external mustache --external @capsizecss/metrics",
70
+ "check": "tsc",
71
+ "clean": "shx rm -rf dist *.d.ts",
72
+ "lint": "eslint src tests --ext .ts,.tsx",
73
+ "format": "prettier --write .",
74
+ "format:check": "prettier --check .",
75
+ "test": "vitest run"
76
+ }
77
+ }