fontaine 0.8.1 → 0.8.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/dist/index.cjs CHANGED
@@ -21,7 +21,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  enumerable: true
22
22
  }) : target, mod));
23
23
  //#endregion
24
- const require_metrics = require("./metrics-Djy62vbF.cjs");
24
+ const require_metrics = require("./metrics-ChAPPk2j.cjs");
25
25
  let css_tree = require("css-tree");
26
26
  let magic_regexp = require("magic-regexp");
27
27
  let pathe = require("pathe");
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as resolveCategoryFallbacks, c as generateFontFace, d as withoutQueryOrFragment, f as withoutQuotes, i as DEFAULT_CATEGORY_FALLBACKS, l as genericCSSFamilies, n as readMetrics, o as cssWideKeywords, r as readMetricsForSource, s as generateFallbackName, t as getMetricsForFamily, u as parseFontFace } from "./metrics-COa8ZSHq.mjs";
1
+ import { a as resolveCategoryFallbacks, c as generateFontFace, d as withoutQueryOrFragment, f as withoutQuotes, i as DEFAULT_CATEGORY_FALLBACKS, l as genericCSSFamilies, n as readMetrics, o as cssWideKeywords, r as readMetricsForSource, s as generateFallbackName, t as getMetricsForFamily, u as parseFontFace } from "./metrics-DgPzfV2U.mjs";
2
2
  import { createRequire } from "node:module";
3
3
  import { parse, walk } from "css-tree";
4
4
  import { anyOf, char, createRegExp, exactly, oneOrMore } from "magic-regexp";
@@ -52,6 +52,52 @@ const genericCSSFamilies = /* @__PURE__ */ new Set([
52
52
  "math",
53
53
  "fangsong"
54
54
  ]);
55
+ const genericFamilyLocals = {
56
+ "serif": [
57
+ "Times New Roman",
58
+ "Tinos",
59
+ "Liberation Serif",
60
+ "DejaVu Serif",
61
+ "Times"
62
+ ],
63
+ "sans-serif": [
64
+ "Arial",
65
+ "Arimo",
66
+ "Liberation Sans",
67
+ "DejaVu Sans",
68
+ "Helvetica"
69
+ ],
70
+ "monospace": [
71
+ "Courier New",
72
+ "Cousine",
73
+ "Liberation Mono",
74
+ "DejaVu Sans Mono",
75
+ "Menlo"
76
+ ],
77
+ "system-ui": [
78
+ "Segoe UI",
79
+ "Roboto",
80
+ "Helvetica Neue",
81
+ "Cantarell",
82
+ "Ubuntu",
83
+ "Noto Sans"
84
+ ],
85
+ "cursive": [
86
+ "Comic Sans MS",
87
+ "Apple Chancery",
88
+ "Segoe Script",
89
+ "URW Chancery L"
90
+ ],
91
+ "fantasy": [
92
+ "Impact",
93
+ "Papyrus",
94
+ "Luminari"
95
+ ]
96
+ };
97
+ genericFamilyLocals["ui-serif"] = genericFamilyLocals.serif;
98
+ genericFamilyLocals["ui-sans-serif"] = genericFamilyLocals["sans-serif"];
99
+ genericFamilyLocals["ui-monospace"] = genericFamilyLocals.monospace;
100
+ genericFamilyLocals["ui-rounded"] = genericFamilyLocals["system-ui"];
55
101
  const fontProperties = /* @__PURE__ */ new Set([
56
102
  "font-weight",
57
103
  "font-style",
@@ -144,7 +190,7 @@ function generateFontFace(metrics, fallback) {
144
190
  const lineGapOverride = metrics.lineGap / adjustedEmSquare;
145
191
  return `@font-face {\n${toCSS({
146
192
  "font-family": JSON.stringify(fallbackName),
147
- "src": `local(${JSON.stringify(fallbackFontName)})`,
193
+ "src": renderLocalSrc(fallbackFontName),
148
194
  "size-adjust": toPercentage(sizeAdjust),
149
195
  "ascent-override": toPercentage(ascentOverride),
150
196
  "descent-override": toPercentage(descentOverride),
@@ -152,6 +198,9 @@ function generateFontFace(metrics, fallback) {
152
198
  ...properties
153
199
  })}\n}\n`;
154
200
  }
201
+ function renderLocalSrc(font) {
202
+ return (genericFamilyLocals[withoutQuotes(font).toLowerCase()] || [font]).map((local) => `local(${JSON.stringify(local)})`).join(", ");
203
+ }
155
204
  //#endregion
156
205
  //#region src/fallbacks.ts
157
206
  /**
@@ -52,6 +52,52 @@ const genericCSSFamilies = /* @__PURE__ */ new Set([
52
52
  "math",
53
53
  "fangsong"
54
54
  ]);
55
+ const genericFamilyLocals = {
56
+ "serif": [
57
+ "Times New Roman",
58
+ "Tinos",
59
+ "Liberation Serif",
60
+ "DejaVu Serif",
61
+ "Times"
62
+ ],
63
+ "sans-serif": [
64
+ "Arial",
65
+ "Arimo",
66
+ "Liberation Sans",
67
+ "DejaVu Sans",
68
+ "Helvetica"
69
+ ],
70
+ "monospace": [
71
+ "Courier New",
72
+ "Cousine",
73
+ "Liberation Mono",
74
+ "DejaVu Sans Mono",
75
+ "Menlo"
76
+ ],
77
+ "system-ui": [
78
+ "Segoe UI",
79
+ "Roboto",
80
+ "Helvetica Neue",
81
+ "Cantarell",
82
+ "Ubuntu",
83
+ "Noto Sans"
84
+ ],
85
+ "cursive": [
86
+ "Comic Sans MS",
87
+ "Apple Chancery",
88
+ "Segoe Script",
89
+ "URW Chancery L"
90
+ ],
91
+ "fantasy": [
92
+ "Impact",
93
+ "Papyrus",
94
+ "Luminari"
95
+ ]
96
+ };
97
+ genericFamilyLocals["ui-serif"] = genericFamilyLocals.serif;
98
+ genericFamilyLocals["ui-sans-serif"] = genericFamilyLocals["sans-serif"];
99
+ genericFamilyLocals["ui-monospace"] = genericFamilyLocals.monospace;
100
+ genericFamilyLocals["ui-rounded"] = genericFamilyLocals["system-ui"];
55
101
  const fontProperties = /* @__PURE__ */ new Set([
56
102
  "font-weight",
57
103
  "font-style",
@@ -144,7 +190,7 @@ function generateFontFace(metrics, fallback) {
144
190
  const lineGapOverride = metrics.lineGap / adjustedEmSquare;
145
191
  return `@font-face {\n${toCSS({
146
192
  "font-family": JSON.stringify(fallbackName),
147
- "src": `local(${JSON.stringify(fallbackFontName)})`,
193
+ "src": renderLocalSrc(fallbackFontName),
148
194
  "size-adjust": toPercentage(sizeAdjust),
149
195
  "ascent-override": toPercentage(ascentOverride),
150
196
  "descent-override": toPercentage(descentOverride),
@@ -152,6 +198,9 @@ function generateFontFace(metrics, fallback) {
152
198
  ...properties
153
199
  })}\n}\n`;
154
200
  }
201
+ function renderLocalSrc(font) {
202
+ return (genericFamilyLocals[withoutQuotes(font).toLowerCase()] || [font]).map((local) => `local(${JSON.stringify(local)})`).join(", ");
203
+ }
155
204
  //#endregion
156
205
  //#region src/fallbacks.ts
157
206
  /**
package/dist/postcss.cjs CHANGED
@@ -1,4 +1,4 @@
1
- const require_metrics = require("./metrics-Djy62vbF.cjs");
1
+ const require_metrics = require("./metrics-ChAPPk2j.cjs");
2
2
  let css_tree = require("css-tree");
3
3
  //#region src/postcss.ts
4
4
  const supportedExtensions = [
package/dist/postcss.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as resolveCategoryFallbacks, c as generateFontFace, d as withoutQueryOrFragment, f as withoutQuotes, l as genericCSSFamilies, o as cssWideKeywords, r as readMetricsForSource, s as generateFallbackName, t as getMetricsForFamily, u as parseFontFace } from "./metrics-COa8ZSHq.mjs";
1
+ import { a as resolveCategoryFallbacks, c as generateFontFace, d as withoutQueryOrFragment, f as withoutQuotes, l as genericCSSFamilies, o as cssWideKeywords, r as readMetricsForSource, s as generateFallbackName, t as getMetricsForFamily, u as parseFontFace } from "./metrics-DgPzfV2U.mjs";
2
2
  import { parse } from "css-tree";
3
3
  //#region src/postcss.ts
4
4
  const supportedExtensions = [
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "fontaine",
3
3
  "type": "module",
4
- "version": "0.8.1",
4
+ "version": "0.8.2",
5
5
  "description": "Automatic font fallback based on font metrics",
6
6
  "author": {
7
7
  "name": "Daniel Roe",
@@ -71,15 +71,15 @@
71
71
  "@types/css-tree": "3.2.0",
72
72
  "@types/node": "24.13.3",
73
73
  "@types/serve-handler": "6.1.4",
74
- "@vitest/coverage-v8": "4.1.11",
75
- "eslint": "10.8.1",
74
+ "@vitest/coverage-v8": "5.0.0",
75
+ "eslint": "10.10.0",
76
76
  "get-port-please": "3.2.0",
77
77
  "postcss": "8.5.26",
78
78
  "serve-handler": "6.1.7",
79
79
  "tsdown": "0.22.14",
80
80
  "typescript": "6.0.3",
81
- "vite": "8.2.2",
82
- "vitest": "4.1.11"
81
+ "vite": "8.3.0",
82
+ "vitest": "5.0.0"
83
83
  },
84
84
  "scripts": {
85
85
  "build": "tsdown",