vite-plugin-capsize-radix 0.1.2 → 0.1.4

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
@@ -99,11 +99,11 @@ to be slightly smaller than on desktop. We do that by shifting the text a size s
99
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
100
  ```ts
101
101
  ;[
102
- { fontSize: 9, lineHeight: 21 },
102
+ { fontSize: 9, lineHeight: 19 },
103
103
  { fontSize: 11, lineHeight: 23 },
104
104
  { fontSize: 12, lineHeight: 25 },
105
- { fontSize: 14, lineHeight: 27 },
106
- { fontSize: 18, lineHeight: 29 },
105
+ { fontSize: 14, lineHeight: 28 },
106
+ { fontSize: 18, lineHeight: 30 },
107
107
  { fontSize: 24, lineHeight: 36 },
108
108
  { fontSize: 36, lineHeight: 44 },
109
109
  { fontSize: 48, lineHeight: 52 },
package/dist/index.js CHANGED
@@ -36,6 +36,7 @@ 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"));
39
+ var import_path = __toESM(require("path"));
39
40
  var import_segoeUI = __toESM(require("@capsizecss/metrics/segoeUI"));
40
41
  var import_appleSystem = __toESM(require("@capsizecss/metrics/appleSystem"));
41
42
  var import_roboto = __toESM(require("@capsizecss/metrics/roboto"));
@@ -46,6 +47,11 @@ var TEXT_SELECTOR_PLACEHOLDER = `__CAPSIZE_TEXT__`;
46
47
  var TEXT_SELECTOR_REPLACEMENT = `:where(${TEXT_ELEMENTS})`;
47
48
  var template = `/* Auto-generated by vite-plugin-capsize-radix */
48
49
 
50
+ /* Fallback font-face rules for metric-adjusted fallbacks */
51
+ {{{defaultFontFamily.fontFaces}}}
52
+ {{{headingFontFamily.fontFaces}}}
53
+ {{{codingFontFamily.fontFaces}}}
54
+
49
55
  /* Override Radix variables */
50
56
  .radix-themes {
51
57
  --default-font-family: {{{defaultFontFamily.fontFamily}}};
@@ -122,9 +128,39 @@ var template = `/* Auto-generated by vite-plugin-capsize-radix */
122
128
  {{/fontData}}
123
129
  }
124
130
  `;
125
- async function generate(options) {
131
+ function validateOptions(options) {
132
+ if (!options.outputPath) {
133
+ throw new Error(`[capsize-radix] outputPath is required`);
134
+ }
135
+ if (options.textStyles.length < 3) {
136
+ throw new Error(
137
+ `[capsize-radix] textStyles must have at least 3 entries (found ${options.textStyles.length})`
138
+ );
139
+ }
140
+ for (let i = 0; i < options.textStyles.length; i++) {
141
+ const style = options.textStyles[i];
142
+ if (typeof style.fontSize !== `number` || style.fontSize <= 0) {
143
+ throw new Error(
144
+ `[capsize-radix] textStyles[${i}].fontSize must be a positive number`
145
+ );
146
+ }
147
+ if (typeof style.lineHeight !== `number` || style.lineHeight <= 0) {
148
+ throw new Error(
149
+ `[capsize-radix] textStyles[${i}].lineHeight must be a positive number`
150
+ );
151
+ }
152
+ }
153
+ const outputDir = import_path.default.dirname(options.outputPath);
154
+ if (!import_fs.default.existsSync(outputDir)) {
155
+ throw new Error(
156
+ `[capsize-radix] Output directory does not exist: ${outputDir}`
157
+ );
158
+ }
159
+ }
160
+ function generate(options) {
161
+ validateOptions(options);
126
162
  let defaultFontFamily;
127
- let headingFontFamiliy;
163
+ let headingFontFamily;
128
164
  let codingFontFamily;
129
165
  if (!options.defaultFontStack) {
130
166
  options.defaultFontStack = [
@@ -136,13 +172,13 @@ async function generate(options) {
136
172
  ];
137
173
  defaultFontFamily = (0, import_core.createFontStack)(options.defaultFontStack);
138
174
  defaultFontFamily.fontFamily += `, ui-sans-serif, system-ui, sans-serif`;
139
- } else if (options.defaultFontStack) {
175
+ } else {
140
176
  defaultFontFamily = (0, import_core.createFontStack)(options.defaultFontStack);
141
177
  }
142
178
  if (options.headingFontStack) {
143
- headingFontFamiliy = (0, import_core.createFontStack)(options.headingFontStack);
179
+ headingFontFamily = (0, import_core.createFontStack)(options.headingFontStack);
144
180
  } else {
145
- headingFontFamiliy = defaultFontFamily;
181
+ headingFontFamily = defaultFontFamily;
146
182
  }
147
183
  if (options.codingFontStack) {
148
184
  codingFontFamily = (0, import_core.createFontStack)(options.codingFontStack);
@@ -272,7 +308,7 @@ async function generate(options) {
272
308
  fontMetrics: options.codingFontStack[0]
273
309
  });
274
310
  const output = import_mustache.default.render(template, {
275
- headingFontFamiliy,
311
+ headingFontFamily,
276
312
  defaultFontFamily,
277
313
  codingFontFamily,
278
314
  mobileFontData,
@@ -293,7 +329,14 @@ async function generate(options) {
293
329
  placeholderRegex,
294
330
  TEXT_SELECTOR_REPLACEMENT
295
331
  );
296
- import_fs.default.writeFileSync(options.outputPath, finalOutput);
332
+ try {
333
+ import_fs.default.writeFileSync(options.outputPath, finalOutput);
334
+ } catch (error) {
335
+ const message = error instanceof Error ? error.message : String(error);
336
+ throw new Error(
337
+ `[capsize-radix] Failed to write CSS to ${options.outputPath}: ${message}`
338
+ );
339
+ }
297
340
  }
298
341
  function capsizeRadixPlugin({
299
342
  outputPath,
package/dist/index.mjs CHANGED
@@ -6,6 +6,7 @@ import {
6
6
  createFontStack
7
7
  } from "@capsizecss/core";
8
8
  import Mustache from "mustache";
9
+ import path from "path";
9
10
  import segoeUI from "@capsizecss/metrics/segoeUI";
10
11
  import appleSystem from "@capsizecss/metrics/appleSystem";
11
12
  import roboto from "@capsizecss/metrics/roboto";
@@ -16,6 +17,11 @@ var TEXT_SELECTOR_PLACEHOLDER = `__CAPSIZE_TEXT__`;
16
17
  var TEXT_SELECTOR_REPLACEMENT = `:where(${TEXT_ELEMENTS})`;
17
18
  var template = `/* Auto-generated by vite-plugin-capsize-radix */
18
19
 
20
+ /* Fallback font-face rules for metric-adjusted fallbacks */
21
+ {{{defaultFontFamily.fontFaces}}}
22
+ {{{headingFontFamily.fontFaces}}}
23
+ {{{codingFontFamily.fontFaces}}}
24
+
19
25
  /* Override Radix variables */
20
26
  .radix-themes {
21
27
  --default-font-family: {{{defaultFontFamily.fontFamily}}};
@@ -92,9 +98,39 @@ var template = `/* Auto-generated by vite-plugin-capsize-radix */
92
98
  {{/fontData}}
93
99
  }
94
100
  `;
95
- async function generate(options) {
101
+ function validateOptions(options) {
102
+ if (!options.outputPath) {
103
+ throw new Error(`[capsize-radix] outputPath is required`);
104
+ }
105
+ if (options.textStyles.length < 3) {
106
+ throw new Error(
107
+ `[capsize-radix] textStyles must have at least 3 entries (found ${options.textStyles.length})`
108
+ );
109
+ }
110
+ for (let i = 0; i < options.textStyles.length; i++) {
111
+ const style = options.textStyles[i];
112
+ if (typeof style.fontSize !== `number` || style.fontSize <= 0) {
113
+ throw new Error(
114
+ `[capsize-radix] textStyles[${i}].fontSize must be a positive number`
115
+ );
116
+ }
117
+ if (typeof style.lineHeight !== `number` || style.lineHeight <= 0) {
118
+ throw new Error(
119
+ `[capsize-radix] textStyles[${i}].lineHeight must be a positive number`
120
+ );
121
+ }
122
+ }
123
+ const outputDir = path.dirname(options.outputPath);
124
+ if (!fs.existsSync(outputDir)) {
125
+ throw new Error(
126
+ `[capsize-radix] Output directory does not exist: ${outputDir}`
127
+ );
128
+ }
129
+ }
130
+ function generate(options) {
131
+ validateOptions(options);
96
132
  let defaultFontFamily;
97
- let headingFontFamiliy;
133
+ let headingFontFamily;
98
134
  let codingFontFamily;
99
135
  if (!options.defaultFontStack) {
100
136
  options.defaultFontStack = [
@@ -106,13 +142,13 @@ async function generate(options) {
106
142
  ];
107
143
  defaultFontFamily = createFontStack(options.defaultFontStack);
108
144
  defaultFontFamily.fontFamily += `, ui-sans-serif, system-ui, sans-serif`;
109
- } else if (options.defaultFontStack) {
145
+ } else {
110
146
  defaultFontFamily = createFontStack(options.defaultFontStack);
111
147
  }
112
148
  if (options.headingFontStack) {
113
- headingFontFamiliy = createFontStack(options.headingFontStack);
149
+ headingFontFamily = createFontStack(options.headingFontStack);
114
150
  } else {
115
- headingFontFamiliy = defaultFontFamily;
151
+ headingFontFamily = defaultFontFamily;
116
152
  }
117
153
  if (options.codingFontStack) {
118
154
  codingFontFamily = createFontStack(options.codingFontStack);
@@ -242,7 +278,7 @@ async function generate(options) {
242
278
  fontMetrics: options.codingFontStack[0]
243
279
  });
244
280
  const output = Mustache.render(template, {
245
- headingFontFamiliy,
281
+ headingFontFamily,
246
282
  defaultFontFamily,
247
283
  codingFontFamily,
248
284
  mobileFontData,
@@ -263,7 +299,14 @@ async function generate(options) {
263
299
  placeholderRegex,
264
300
  TEXT_SELECTOR_REPLACEMENT
265
301
  );
266
- fs.writeFileSync(options.outputPath, finalOutput);
302
+ try {
303
+ fs.writeFileSync(options.outputPath, finalOutput);
304
+ } catch (error) {
305
+ const message = error instanceof Error ? error.message : String(error);
306
+ throw new Error(
307
+ `[capsize-radix] Failed to write CSS to ${options.outputPath}: ${message}`
308
+ );
309
+ }
267
310
  }
268
311
  function capsizeRadixPlugin({
269
312
  outputPath,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "vite-plugin-capsize-radix",
3
3
  "description": "Great Typography with Radix & Capsize",
4
- "version": "0.1.2",
4
+ "version": "0.1.4",
5
5
  "author": "Kyle Mathews <mathews.kyle@gmail.com>",
6
6
  "dependencies": {
7
7
  "@capsizecss/core": "^4.1.3",