fontaine 0.7.0 → 0.8.0

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/dist/index.cjs CHANGED
@@ -6,12 +6,16 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
8
  var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
- key = keys[i];
11
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
- get: ((k) => from[k]).bind(null, key),
13
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
- });
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
15
19
  }
16
20
  return to;
17
21
  };
@@ -24,7 +28,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
28
  let css_tree = require("css-tree");
25
29
  let magic_regexp = require("magic-regexp");
26
30
  let node_url = require("node:url");
27
- let __capsizecss_unpack = require("@capsizecss/unpack");
31
+ let _capsizecss_unpack = require("@capsizecss/unpack");
32
+ let _capsizecss_unpack_fs = require("@capsizecss/unpack/fs");
28
33
  let ufo = require("ufo");
29
34
  let magic_string = require("magic-string");
30
35
  magic_string = __toESM(magic_string);
@@ -136,7 +141,7 @@ function generateFallbackName(name) {
136
141
  * @returns {string} - The full `@font-face` CSS declaration.
137
142
  */
138
143
  function generateFontFace(metrics, fallback) {
139
- const { name: fallbackName, font: fallbackFontName, metrics: fallbackMetrics,...properties } = fallback;
144
+ const { name: fallbackName, font: fallbackFontName, metrics: fallbackMetrics, ...properties } = fallback;
140
145
  const preferredFontXAvgRatio = metrics.xWidthAvg / metrics.unitsPerEm;
141
146
  const fallbackFontXAvgRatio = fallbackMetrics ? fallbackMetrics.xWidthAvg / fallbackMetrics.unitsPerEm : 1;
142
147
  const sizeAdjust = fallbackMetrics && preferredFontXAvgRatio && fallbackFontXAvgRatio ? preferredFontXAvgRatio / fallbackFontXAvgRatio : 1;
@@ -277,10 +282,10 @@ async function readMetrics(_source) {
277
282
  const { protocol } = (0, ufo.parseURL)(source);
278
283
  if (!protocol) return null;
279
284
  let metrics;
280
- if (protocol === "file:") metrics = await (0, __capsizecss_unpack.fromFile)((0, node_url.fileURLToPath)(source));
285
+ if (protocol === "file:") metrics = await (0, _capsizecss_unpack_fs.fromFile)((0, node_url.fileURLToPath)(source));
281
286
  else if (urlRequestCache.has(source)) metrics = await urlRequestCache.get(source);
282
287
  else {
283
- const requestPromise = (0, __capsizecss_unpack.fromUrl)(source);
288
+ const requestPromise = (0, _capsizecss_unpack.fromUrl)(source);
284
289
  urlRequestCache.set(source, requestPromise);
285
290
  metrics = await requestPromise;
286
291
  }
package/dist/index.d.cts CHANGED
@@ -40,12 +40,12 @@ type FontFaceMetrics = Pick<Font, "ascent" | "descent" | "lineGap" | "unitsPerEm
40
40
  declare function generateFontFace(metrics: FontFaceMetrics, fallback: FallbackOptions): string;
41
41
  //#endregion
42
42
  //#region src/fallbacks.d.ts
43
- type FontCategory = "sans-serif" | "serif" | "monospace" | "display" | "handwriting";
43
+ type FontCategory = "sans-serif" | "serif" | "monospace" | "display" | "handwriting" | "cursive" | "fantasy" | "system-ui" | "ui-serif" | "ui-sans-serif" | "ui-monospace" | "ui-rounded" | "emoji" | "math" | "fangsong";
44
44
  /**
45
45
  * Default fallback font stacks for each font category.
46
46
  * These are system fonts that work across different platforms.
47
47
  */
48
- declare const DEFAULT_CATEGORY_FALLBACKS: Record<FontCategory, string[]>;
48
+ declare const DEFAULT_CATEGORY_FALLBACKS: Partial<Record<FontCategory, string[]>>;
49
49
  interface ResolveCategoryFallbacksOptions {
50
50
  /** Font family name to resolve fallbacks for */
51
51
  fontFamily: string;
package/dist/index.d.mts CHANGED
@@ -41,12 +41,12 @@ type FontFaceMetrics = Pick<Font, "ascent" | "descent" | "lineGap" | "unitsPerEm
41
41
  declare function generateFontFace(metrics: FontFaceMetrics, fallback: FallbackOptions): string;
42
42
  //#endregion
43
43
  //#region src/fallbacks.d.ts
44
- type FontCategory = "sans-serif" | "serif" | "monospace" | "display" | "handwriting";
44
+ type FontCategory = "sans-serif" | "serif" | "monospace" | "display" | "handwriting" | "cursive" | "fantasy" | "system-ui" | "ui-serif" | "ui-sans-serif" | "ui-monospace" | "ui-rounded" | "emoji" | "math" | "fangsong";
45
45
  /**
46
46
  * Default fallback font stacks for each font category.
47
47
  * These are system fonts that work across different platforms.
48
48
  */
49
- declare const DEFAULT_CATEGORY_FALLBACKS: Record<FontCategory, string[]>;
49
+ declare const DEFAULT_CATEGORY_FALLBACKS: Partial<Record<FontCategory, string[]>>;
50
50
  interface ResolveCategoryFallbacksOptions {
51
51
  /** Font family name to resolve fallbacks for */
52
52
  fontFamily: string;
package/dist/index.mjs CHANGED
@@ -1,7 +1,8 @@
1
1
  import { generate, parse, walk } from "css-tree";
2
2
  import { anyOf, char, charIn, createRegExp, exactly, oneOrMore } from "magic-regexp";
3
3
  import { fileURLToPath, pathToFileURL } from "node:url";
4
- import { fromFile, fromUrl } from "@capsizecss/unpack";
4
+ import { fromUrl } from "@capsizecss/unpack";
5
+ import { fromFile } from "@capsizecss/unpack/fs";
5
6
  import { parseURL } from "ufo";
6
7
  import MagicString from "magic-string";
7
8
  import { isAbsolute } from "pathe";
@@ -112,7 +113,7 @@ function generateFallbackName(name) {
112
113
  * @returns {string} - The full `@font-face` CSS declaration.
113
114
  */
114
115
  function generateFontFace(metrics, fallback) {
115
- const { name: fallbackName, font: fallbackFontName, metrics: fallbackMetrics,...properties } = fallback;
116
+ const { name: fallbackName, font: fallbackFontName, metrics: fallbackMetrics, ...properties } = fallback;
116
117
  const preferredFontXAvgRatio = metrics.xWidthAvg / metrics.unitsPerEm;
117
118
  const fallbackFontXAvgRatio = fallbackMetrics ? fallbackMetrics.xWidthAvg / fallbackMetrics.unitsPerEm : 1;
118
119
  const sizeAdjust = fallbackMetrics && preferredFontXAvgRatio && fallbackFontXAvgRatio ? preferredFontXAvgRatio / fallbackFontXAvgRatio : 1;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "fontaine",
3
3
  "type": "module",
4
- "version": "0.7.0",
4
+ "version": "0.8.0",
5
5
  "description": "Automatic font fallback based on font metrics",
6
6
  "author": {
7
7
  "name": "Daniel Roe",
@@ -40,7 +40,7 @@
40
40
  "node": ">=18.12.0"
41
41
  },
42
42
  "dependencies": {
43
- "@capsizecss/unpack": "^3.0.0",
43
+ "@capsizecss/unpack": "^4.0.0",
44
44
  "css-tree": "^3.1.0",
45
45
  "magic-regexp": "^0.10.0",
46
46
  "magic-string": "^0.30.21",
@@ -49,18 +49,18 @@
49
49
  "unplugin": "^2.3.10"
50
50
  },
51
51
  "devDependencies": {
52
- "@capsizecss/metrics": "3.5.0",
52
+ "@capsizecss/metrics": "3.6.2",
53
53
  "@types/css-tree": "2.3.11",
54
- "@types/node": "24.10.0",
54
+ "@types/node": "24.10.8",
55
55
  "@types/serve-handler": "6.1.4",
56
- "@vitest/coverage-v8": "4.0.7",
57
- "eslint": "9.39.1",
56
+ "@vitest/coverage-v8": "4.0.17",
57
+ "eslint": "9.39.2",
58
58
  "get-port-please": "3.2.0",
59
59
  "serve-handler": "6.1.6",
60
- "tsdown": "0.16.0",
60
+ "tsdown": "0.19.0",
61
61
  "typescript": "5.9.3",
62
- "vite": "7.2.1",
63
- "vitest": "4.0.7"
62
+ "vite": "7.3.1",
63
+ "vitest": "4.0.17"
64
64
  },
65
65
  "scripts": {
66
66
  "build": "tsdown",
@@ -68,7 +68,8 @@
68
68
  "demo": "vite dev playground",
69
69
  "demo:dev": "pnpm demo --config test/vite.config.mjs",
70
70
  "lint": "eslint .",
71
- "release": "pnpm test && bumpp && npm publish",
72
- "test": "vitest run"
71
+ "test": "pnpm test:unit && pnpm test:types",
72
+ "test:types": "tsc --noEmit",
73
+ "test:unit": "vitest run"
73
74
  }
74
75
  }