webfont 12.0.0 → 12.1.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/NOTICE.md +14 -2
- package/README.md +176 -15
- package/dist/browser.js +4 -0
- package/dist/cli.mjs +518 -253
- package/dist/index.js +1 -1
- package/dist/parseTemplateOption-5T7rSw5J.mjs +20 -0
- package/dist/parseTemplateOption-BmH_pcQh.js +1 -0
- package/dist/renderTemplates-DvRlS58E.mjs +93 -0
- package/dist/renderTemplates-zCYCzeOt.js +1 -0
- package/dist/src/browser.d.ts +2 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/lib/applyOptimizeSvgToGlyphs.d.ts +3 -0
- package/dist/src/lib/evenoddFillRule.d.ts +2 -0
- package/dist/src/lib/inputSource.d.ts +1 -4
- package/dist/src/lib/inputSourceUtils.d.ts +4 -0
- package/dist/src/lib/largeFontLigatures.d.ts +4 -0
- package/dist/src/lib/optimizeSvgGlyphs.d.ts +4 -0
- package/dist/src/lib/parseFormats.d.ts +4 -0
- package/dist/src/lib/parseTemplateOption.d.ts +2 -0
- package/dist/src/lib/runtimeEnvironment.d.ts +4 -0
- package/dist/src/lib/svgDiagnostics/diagnoseSvgContents.d.ts +12 -0
- package/dist/src/lib/svgFontOutput/emptyGlyphPaths.d.ts +3 -0
- package/dist/src/lib/svgTools/applySvgDiagnostics.d.ts +13 -0
- package/dist/src/lib/svgTools/applySvgTools.d.ts +14 -0
- package/dist/src/lib/svgTools/normalizeSvgToolsOptions.d.ts +2 -0
- package/dist/src/lib/svgicons2svgfont/index.d.ts +5 -0
- package/dist/src/lib/svgicons2svgfont/metadataFromSrcPath.d.ts +11 -0
- package/dist/src/lib/templateUnicodeRange.d.ts +4 -0
- package/dist/src/lib/ttfEncode.d.ts +5 -0
- package/dist/src/standalone/convertTtfInput.d.ts +3 -0
- package/dist/src/standalone/defaultOptions.d.ts +3 -0
- package/dist/src/standalone/generateSvgFont.d.ts +2 -0
- package/dist/src/standalone/getGlyphsDataFromInputs.d.ts +3 -0
- package/dist/src/standalone/glyphsData.d.ts +1 -1
- package/dist/src/standalone/index.d.ts +5 -0
- package/dist/src/standalone/inputMode.d.ts +3 -1
- package/dist/src/standalone/optionsFromGlyphs.d.ts +3 -0
- package/dist/src/standalone/renderTemplates.d.ts +10 -0
- package/dist/src/standalone/runSvgPipeline.d.ts +3 -0
- package/dist/src/standalone/validateWebfontOptions.d.ts +6 -0
- package/dist/src/standalone/webfontFromGlyphs.d.ts +3 -0
- package/dist/src/types/GlyphContentTransformFn.d.ts +2 -0
- package/dist/src/types/GlyphInput.d.ts +6 -0
- package/dist/src/types/InitialOptions.d.ts +2 -0
- package/dist/src/types/OptionsBase.d.ts +9 -1
- package/dist/src/types/RenderedTemplate.d.ts +7 -0
- package/dist/src/types/Result.d.ts +8 -0
- package/dist/src/types/SvgToolsOptions.d.ts +13 -0
- package/dist/src/types/TranscodedFont.d.ts +7 -0
- package/dist/src/types/WebfontFromGlyphsOptions.d.ts +11 -0
- package/dist/src/types/WebfontOptions.d.ts +12 -2
- package/dist/src/types/index.d.ts +2 -1
- package/package.json +16 -3
- package/templates/template.css.njk +6 -3
- package/templates/template.html.njk +15 -4
- package/templates/template.scss.njk +6 -3
- package/templates/template.styl.njk +6 -3
package/NOTICE.md
CHANGED
|
@@ -43,7 +43,18 @@ If you build a font from **`.svg` icons**, you must have the right to use those
|
|
|
43
43
|
|
|
44
44
|
Generated font files may be subject to the same restrictions as the source icons and to any third-party notices you embed via options such as `metadata` / `copyright`.
|
|
45
45
|
|
|
46
|
-
### 3.
|
|
46
|
+
### 3.3 TTF to webfont encoding
|
|
47
|
+
|
|
48
|
+
If you **encode** one or more `.ttf` files to `eot`, `woff`, or `woff2`, you are re-wrapping font data you already hold. That operation:
|
|
49
|
+
|
|
50
|
+
- does **not** make a restricted or commercial font free to use or share;
|
|
51
|
+
- does **not** bypass foundry EULAs or redistribution terms;
|
|
52
|
+
- preserves copyright/metadata embedded in the source TTF;
|
|
53
|
+
- does **not** merge multiple weights into one file — each input yields separate outputs.
|
|
54
|
+
|
|
55
|
+
**Only process fonts you are authorized to convert and redistribute** under their license.
|
|
56
|
+
|
|
57
|
+
### 3.4 WOFF / WOFF2 decompression
|
|
47
58
|
|
|
48
59
|
If you **decompress** one or more `.woff` or `.woff2` files (from disk or from an `http(s)` URL) to `.ttf` or `.otf`, you are extracting the **SFNT payload** inside each container. That operation:
|
|
49
60
|
|
|
@@ -54,7 +65,7 @@ If you **decompress** one or more `.woff` or `.woff2` files (from disk or from a
|
|
|
54
65
|
|
|
55
66
|
**Only process fonts you are authorized to use and download** under their license. For remote URLs, you must also have permission to fetch and store those bytes.
|
|
56
67
|
|
|
57
|
-
### 3.
|
|
68
|
+
### 3.5 Redistribution of output
|
|
58
69
|
|
|
59
70
|
Publishing, shipping, or sublicensing fonts produced or extracted with webfont (in apps, websites, PDFs, design assets, npm packages, etc.) is **your responsibility**. The MIT license on webfont does **not** apply to those font files.
|
|
60
71
|
|
|
@@ -105,6 +116,7 @@ webfont depends on the following **runtime** npm packages (direct dependencies).
|
|
|
105
116
|
| [nunjucks](https://github.com/mozilla/nunjucks) | BSD-2-Clause | CSS / SCSS / Styl templates |
|
|
106
117
|
| [p-limit](https://github.com/sindresorhus/p-limit) | MIT | Concurrency limiting |
|
|
107
118
|
| [resolve-from](https://github.com/sindresorhus/resolve-from) | MIT | Module resolution |
|
|
119
|
+
| [svgo](https://github.com/svg/svgo) | MIT | Optional SVG optimization (`optimizeSvg`) |
|
|
108
120
|
| [svg2ttf](https://github.com/fontello/svg2ttf) | MIT | SVG font → TTF |
|
|
109
121
|
| [svgicons2svgfont](https://github.com/nfroidure/svgicons2svgfont) | MIT | SVG icons → SVG font |
|
|
110
122
|
| [ttf2eot](https://github.com/fontello/ttf2eot) | MIT | TTF → EOT |
|
package/README.md
CHANGED
|
@@ -1,41 +1,47 @@
|
|
|
1
1
|
# webfont
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.org/package/webfont)
|
|
4
|
-
[](https://ci.appveyor.com/project/evilebottnawi/webfont)
|
|
4
|
+
[](https://github.com/itgalaxy/webfont/actions/workflows/pr.yml)
|
|
6
5
|
|
|
7
|
-
Generator of fonts from SVG icons, with
|
|
6
|
+
Generator of fonts from SVG icons, with separate modes to **encode** TTF to web formats and **decompress** WOFF/WOFF2 containers to the TTF or OTF inside.
|
|
8
7
|
|
|
9
8
|
See **[FEATURES.md](./FEATURES.md)** for the canonical capability list (what is stable, in progress, or planned).
|
|
10
9
|
|
|
11
10
|
**Legal / licensing:** [NOTICE.md](./NOTICE.md) — font copyright, disclaimers, attribution guidelines, and third-party library notices.
|
|
12
11
|
|
|
12
|
+
**Troubleshooting:** [TROUBLESHOOTING.md](./TROUBLESHOOTING.md) — common errors on the current release (including [icons that lose detail after export](./TROUBLESHOOTING.md#icon-details-missing-after-export) due to `fill-rule: evenodd`, #175).
|
|
13
|
+
|
|
14
|
+
**Migration:** [MIGRATION.md](./MIGRATION.md) — what changed between versions and how to upgrade.
|
|
15
|
+
|
|
13
16
|
## Features
|
|
14
17
|
|
|
15
18
|
- **SVG icon pipeline** (default): `.svg` icons → `svg`, `ttf`, `eot`, `woff`, `woff2` (not `otf`);
|
|
19
|
+
- **TTF encoding**: one or more `.ttf` files → `ttf` (pass-through), `eot`, `woff`, and/or `woff2` (auto-detected — no extra flag);
|
|
16
20
|
- **Webfont decompression**: one `.woff` or `.woff2` file → `ttf` and/or `otf` matching the **embedded SFNT flavor** (decompress only — not TTF ↔ OTF transcoding);
|
|
17
21
|
- Config files: `JavaScript`, `JSON`, or `YAML` via [cosmiconfig](https://github.com/cosmiconfig/cosmiconfig);
|
|
18
22
|
- Built-in and custom CSS templates (`css`, `scss`, [`styl`](https://github.com/itgalaxy/webfont/pull/164/));
|
|
19
|
-
- CLI and programmatic API;
|
|
23
|
+
- CLI and programmatic API (**Node.js build time only** — see [TROUBLESHOOTING](./TROUBLESHOOTING.md#cant-resolve-fs-webpack--react--vite-client-bundle));
|
|
20
24
|
- [Webpack plugin](https://github.com/itgalaxy/webfont-webpack-plugin).
|
|
21
25
|
|
|
22
26
|
## Input modes
|
|
23
27
|
|
|
24
|
-
webfont runs one of
|
|
28
|
+
webfont runs one of three pipelines depending on matched input files. They cannot be mixed in a single run.
|
|
25
29
|
|
|
26
30
|
| Mode | Input | Outputs | Notes |
|
|
27
31
|
|------|--------|---------|--------|
|
|
28
32
|
| **SVG icons** | One or more `.svg` files | `svg`, `ttf`, `eot`, `woff`, `woff2` | Default. Builds TrueType via `svg2ttf`. **`otf` is rejected** — use `ttf`. |
|
|
33
|
+
| **TTF encoding** | One or more `.ttf` files | `ttf`, `eot`, `woff`, and/or `woff2` per input | Auto-detected. Default when SVG-pipeline `formats` are still configured: `woff` + `woff2`. No templates. |
|
|
29
34
|
| **Webfont decompress** | One or more `.woff` / `.woff2` paths, globs, or `http(s)` URLs | `ttf` and/or `otf` per input | One output file per source (basename from filename; collisions get `-woff`/`-woff2`). Not a single merged font. |
|
|
30
35
|
|
|
31
36
|
**Not supported today**
|
|
32
37
|
|
|
33
38
|
- Renaming or re-wrapping without matching the real outline format (e.g. requesting `otf` when the WOFF2 holds TrueType).
|
|
34
39
|
- Converting TTF to OTF (or OTF to TTF) — use [FontForge](https://fontforge.org/) or similar.
|
|
35
|
-
-
|
|
40
|
+
- `.otf` as input for webfont encoding (TrueType `.ttf` only today).
|
|
41
|
+
- Templates, `glyphTransformFn`, `glyphContentTransformFn`, or merged multi-weight SFNT output in TTF encoding or webfont decompress mode.
|
|
36
42
|
- Globs that match extension-less or unsupported files together with fonts (the run fails instead of silently ignoring extras).
|
|
37
43
|
|
|
38
|
-
Every matched path must end in `.svg`, `.woff`, or `.woff2`. See [FEATURES.md](./FEATURES.md) for test-backed criteria.
|
|
44
|
+
Every matched path must end in `.svg`, `.ttf`, `.woff`, or `.woff2`. See [FEATURES.md](./FEATURES.md) for test-backed criteria.
|
|
39
45
|
|
|
40
46
|
### Font licensing
|
|
41
47
|
|
|
@@ -69,12 +75,16 @@ Full details, disclaimers, community attribution guidelines, and third-party lib
|
|
|
69
75
|
|
|
70
76
|
## Installation
|
|
71
77
|
|
|
78
|
+
Requires **Node.js** >= 24.14.0. Install as a dev dependency and run at **build time** (CLI, npm script, or bundler plugin) — not from browser/React client bundles.
|
|
79
|
+
|
|
72
80
|
```shell
|
|
73
81
|
npm install --save-dev webfont
|
|
74
82
|
```
|
|
75
83
|
|
|
76
84
|
## Usage
|
|
77
85
|
|
|
86
|
+
Node.js only — do not import from client-side app code ([#198](https://github.com/itgalaxy/webfont/issues/198)).
|
|
87
|
+
|
|
78
88
|
```js
|
|
79
89
|
import webfont from "webfont";
|
|
80
90
|
|
|
@@ -113,6 +123,30 @@ webfont({
|
|
|
113
123
|
});
|
|
114
124
|
```
|
|
115
125
|
|
|
126
|
+
### TTF encoding examples
|
|
127
|
+
|
|
128
|
+
```js
|
|
129
|
+
import webfont from "webfont";
|
|
130
|
+
|
|
131
|
+
// Single local TTF → WOFF + WOFF2 (default when formats unset)
|
|
132
|
+
const encoded = await webfont({
|
|
133
|
+
files: "path/to/font.ttf",
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// Explicit formats
|
|
137
|
+
const subset = await webfont({
|
|
138
|
+
files: "path/to/font.ttf",
|
|
139
|
+
formats: ["woff2"],
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// Batch: multiple TTF files in one run
|
|
143
|
+
const batch = await webfont({
|
|
144
|
+
files: ["fonts/Inter-Regular.ttf", "fonts/Inter-Bold.ttf"],
|
|
145
|
+
formats: ["woff", "woff2"],
|
|
146
|
+
});
|
|
147
|
+
// batch.transcodedFonts → [{ source, woff, woff2 }, …]
|
|
148
|
+
```
|
|
149
|
+
|
|
116
150
|
### Webfont decompress examples
|
|
117
151
|
|
|
118
152
|
```js
|
|
@@ -145,9 +179,10 @@ const remote = await webfont({
|
|
|
145
179
|
- Type: `string` | `array`
|
|
146
180
|
- Description: A file glob, or array of file globs. Ultimately passed to [fast-glob](https://github.com/mrmlnc/fast-glob) to figure out what files you want to get.
|
|
147
181
|
- **SVG mode**: one or more `.svg` icon paths or globs (default pipeline).
|
|
182
|
+
- **TTF encoding mode**: one or more `.ttf` paths or globs.
|
|
148
183
|
- **Webfont decompress mode**: one or more `.woff` / `.woff2` paths, globs, or `https://…` URLs (see [`formats`](#formats) and [Input modes](#input-modes)).
|
|
149
|
-
- Do not mix `.svg
|
|
150
|
-
- Every matched file must have a supported extension (`.svg`, `.woff`, `.woff2`); extension-less files such as `LICENSE` are not ignored when matched by a broad glob.
|
|
184
|
+
- Do not mix `.svg`, `.ttf`, and `.woff` / `.woff2` in the same run.
|
|
185
|
+
- Every matched file must have a supported extension (`.svg`, `.ttf`, `.woff`, `.woff2`); extension-less files such as `LICENSE` are not ignored when matched by a broad glob.
|
|
151
186
|
- `node_modules` and `bower_components` are always ignored.
|
|
152
187
|
|
|
153
188
|
#### `configFile`
|
|
@@ -170,18 +205,22 @@ const remote = await webfont({
|
|
|
170
205
|
#### `formats`
|
|
171
206
|
|
|
172
207
|
- Type: `array`
|
|
173
|
-
- Default: `['svg', 'ttf', 'eot', 'woff', 'woff2']` (SVG input). For WOFF/WOFF2 input, defaults to `['ttf']` when SVG-pipeline formats are still configured.
|
|
208
|
+
- Default: `['svg', 'ttf', 'eot', 'woff', 'woff2']` (SVG input). For TTF input, defaults to `['woff', 'woff2']` when SVG-pipeline formats are still configured. For WOFF/WOFF2 input, defaults to `['ttf']` when SVG-pipeline formats are still configured.
|
|
174
209
|
- Possible values: `svg`, `ttf`, `otf`, `eot`, `woff`, `woff2`
|
|
175
210
|
- Description: Font file types to generate.
|
|
176
211
|
- **SVG input**: `svg`, `ttf`, `eot`, `woff`, `woff2` only. **`otf` is not supported** (pipeline uses TrueType outlines).
|
|
212
|
+
- **TTF input**: `ttf`, `eot`, `woff`, and/or `woff2` only. **`svg` and `otf` are not produced** in this mode.
|
|
177
213
|
- **WOFF/WOFF2 input**: `ttf` and/or `otf` only — must match the decompressed SFNT flavor inside the file (not arbitrary transcoding). `eot`, `woff`, `woff2`, and `svg` are not produced in this mode.
|
|
178
214
|
- CLI: pass `-f` / `--formats` as a JSON array (for example `'["woff2"]'`) or as a comma-separated list (for example `woff2` or `svg, ttf, woff2`). Invalid format names throw an error.
|
|
215
|
+
- API and config files: `formats` must be an array of the values above; unknown names (for example `icon`) throw before the pipeline runs.
|
|
179
216
|
|
|
180
217
|
#### `template`
|
|
181
218
|
|
|
182
|
-
- Type: `string`
|
|
219
|
+
- Type: `string` or `string[]`
|
|
183
220
|
- Default: `null`
|
|
184
|
-
- Possible values: `css`, `scss`,
|
|
221
|
+
- Possible values: `css`, `scss`, `styl`, `html`, `json` (feel free to contribute more), or a path to a custom `.njk` template.
|
|
222
|
+
- Pass an **array** to generate multiple outputs in one run (for example `['html', 'scss']` for preview + styles, #158).
|
|
223
|
+
- CLI: pass `-t` / `--template` as a single name, a JSON array (`'["html","scss"]'`), or a comma-separated list (`html,scss`).
|
|
185
224
|
- Note: If you want to use a custom template use this option pass in a path `string` like this:
|
|
186
225
|
|
|
187
226
|
```js
|
|
@@ -221,14 +260,69 @@ const remote = await webfont({
|
|
|
221
260
|
#### `templateFontName`
|
|
222
261
|
|
|
223
262
|
- Type: `string`
|
|
224
|
-
- Default:
|
|
225
|
-
- Description:
|
|
263
|
+
- Default: Same as [`fontName`](#fontname) when not set.
|
|
264
|
+
- Description: CSS `font-family` name emitted by built-in templates (`fontFamily` in Nunjucks context). Output **font files** are always named after `fontName` (for example `icons-a.woff2`); built-in templates reference those files with `{{ fontName }}` in `url(...)` while `font-family` uses `{{ fontFamily }}` ([#331](https://github.com/itgalaxy/webfont/issues/331)).
|
|
265
|
+
|
|
266
|
+
#### `templateCacheString`
|
|
267
|
+
|
|
268
|
+
- Type: `string`
|
|
269
|
+
- Default: `Date.now()` at generation time
|
|
270
|
+
- Description: Query string appended to font `url(...)` values in built-in templates (before optional `&v=` hash). Use a fixed value (for example `v=1`) when you only need manual cache busting; pair with [`addHashInFontUrl`](#addhashinfonturl) for automatic content-based busting.
|
|
271
|
+
|
|
272
|
+
#### `addHashInFontUrl`
|
|
273
|
+
|
|
274
|
+
- Type: `boolean`
|
|
275
|
+
- Default: `false`
|
|
276
|
+
- Description: When `true` and a built-in `template` is used, append `&v=<md5>` to each font URL in the generated CSS/SCSS/Styl. The hash is derived from the SVG font output — it changes only when icon data changes. **Output filenames stay** `fontName.woff2`, `fontName.scss`, etc. (stable `@import` paths).
|
|
277
|
+
- CLI: `--addHashInFontUrl`
|
|
278
|
+
- Addresses browser cache issues without renaming font files on every build ([#125](https://github.com/itgalaxy/webfont/issues/125)).
|
|
279
|
+
|
|
280
|
+
**Example — stable `webfont.scss`, cache-busted font URLs:**
|
|
281
|
+
|
|
282
|
+
```shell
|
|
283
|
+
webfont "icons/*.svg" -d dist/icons -t scss --addHashInFontUrl
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
```js
|
|
287
|
+
import webfont from "webfont";
|
|
288
|
+
|
|
289
|
+
await webfont({
|
|
290
|
+
files: "src/icons/**/*.svg",
|
|
291
|
+
fontName: "webfont",
|
|
292
|
+
template: "scss",
|
|
293
|
+
templateFontPath: "./fonts/",
|
|
294
|
+
addHashInFontUrl: true,
|
|
295
|
+
});
|
|
296
|
+
// Writes dist/icons/webfont.scss and dist/icons/webfont.woff2 (fixed names).
|
|
297
|
+
// SCSS contains url("./fonts/webfont.woff2?...&v=<md5>") — hash updates when icons change.
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
Do **not** use `Math.random()` in `fontName` — that renames both font files and the stylesheet on every run.
|
|
301
|
+
|
|
302
|
+
#### `unicodeRange`
|
|
303
|
+
|
|
304
|
+
- Type: `boolean | string`
|
|
305
|
+
- Default: `false` (omit `unicode-range` from built-in templates)
|
|
306
|
+
- Description: When `true` and a built-in `template` is used, emit a `unicode-range` declaration in `@font-face` so the browser can load only the icon font that owns the code points on the page. With the default `startUnicode` (`0xEA01`), the range is derived from the minimum and maximum allocated code points (for example `U+EA01-EA03`). Pass a CSS value string (for example `U+EA01-EAFF`) to override the computed range. Set to `false` to omit the rule (default).
|
|
307
|
+
- CLI: `--unicode-range` to enable auto-computed range
|
|
308
|
+
- Helps when **multiple icon fonts** share a page ([#322](https://github.com/itgalaxy/webfont/issues/322)) — each `@font-face` can declare which private-use code points it owns so the browser skips downloading fonts that cannot render the glyphs in use.
|
|
309
|
+
- **Ligature trade-off:** computed `unicode-range` covers **private-use code points only** (ligature names are ignored when building the range). If you type icon names with OpenType ligatures (`font-feature-settings: "liga"`), a PUA-only `unicode-range` prevents the browser from applying the icon font to ASCII letters, so ligatures **do not render**. Prefer class + codepoint icons in production when `unicode-range` is enabled, or leave `unicodeRange` at the default `false` if you rely on ligature names.
|
|
226
310
|
|
|
227
311
|
#### `ligatures`
|
|
228
312
|
|
|
313
|
+
- Type: `boolean`
|
|
314
|
+
- Default: `false` (ligature glyphs are **not** added unless you opt in)
|
|
315
|
+
- Description: When `true`, each glyph gets a second unicode entry: the icon name with hyphens replaced by underscores (for example `phone-call` → `phone_call`). Browsers can map that character sequence to the icon glyph when OpenType ligatures are enabled (`font-feature-settings: "liga"`).
|
|
316
|
+
- CLI: `--ligatures` to enable ligature glyphs in the font.
|
|
317
|
+
- **Why off by default:** large icon sets (thousands of glyphs) produce huge GSUB tables. **Firefox on Windows** (DirectWrite) can hang or slow dramatically when ligatures are enabled ([#558](https://github.com/itgalaxy/webfont/issues/558)). Prefer **class + private-use codepoint** CSS for MDI-scale fonts. webfont prints a warning when glyph count exceeds 2000 with ligatures enabled.
|
|
318
|
+
|
|
319
|
+
#### `templateFontLigatures`
|
|
320
|
+
|
|
229
321
|
- Type: `boolean`
|
|
230
322
|
- Default: `true`
|
|
231
|
-
- Description:
|
|
323
|
+
- Description: When `true` and the built-in **`html`** preview template is used, the generated CSS enables `font-feature-settings: "liga"` on the **Ligature** section (`#icon-ligatures`) so ligature names render as icons instead of invisible/missing glyphs. If you also enable [`unicodeRange`](#unicoderange), the HTML template **omits** `unicode-range` on `@font-face` while ligature preview is on (ligature strings are ASCII; a PUA-only `unicode-range` would block the icon font for those characters). Set to `false` if you inject your own ligature CSS.
|
|
324
|
+
- CLI: `--no-template-font-ligatures` to omit the CSS rule.
|
|
325
|
+
- Requires [`ligatures`](#ligatures) enabled (`--ligatures` / `ligatures: true`). Class-based icons (`.font-name-icon::before` with a private-use codepoint) work without this option.
|
|
232
326
|
|
|
233
327
|
#### `glyphTransformFn`
|
|
234
328
|
|
|
@@ -260,6 +354,69 @@ const remote = await webfont({
|
|
|
260
354
|
});
|
|
261
355
|
```
|
|
262
356
|
|
|
357
|
+
#### `glyphContentTransformFn`
|
|
358
|
+
|
|
359
|
+
- Type: `function`
|
|
360
|
+
- Default: `null`
|
|
361
|
+
- Description: Transform each SVG glyph **before** font generation (SVG pipeline only). Use this hook to preprocess SVGs — for example stroke-based icons converted to filled paths. **webfont does not bundle preprocessors**; install tools such as [`svg-outline-stroke`](https://github.com/elrumordelaluz/outline-stroke) in **your** project and call them from this function (see [ADR 0011](docs/adr/0011-no-svg-outline-stroke-dependency.md)). `glyphTransformFn` only changes metadata; this hook receives the full `GlyphData` (`contents`, `srcPath`, optional `metadata`) and must return the new SVG string.
|
|
362
|
+
- Example (stroke icons, #144 — **install `svg-outline-stroke` in your app**, not in webfont):
|
|
363
|
+
|
|
364
|
+
```js
|
|
365
|
+
import outlineStroke from "svg-outline-stroke";
|
|
366
|
+
import webfont from "webfont";
|
|
367
|
+
|
|
368
|
+
await webfont({
|
|
369
|
+
files: "src/svg-icons/**/*.svg",
|
|
370
|
+
glyphContentTransformFn: async (glyph) => outlineStroke(glyph.contents),
|
|
371
|
+
});
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
For better trace quality with `svg-outline-stroke`, use a larger `width` / `height` / `viewBox` on the source SVG (see the library README).
|
|
375
|
+
|
|
376
|
+
#### `optimizeSvg`
|
|
377
|
+
|
|
378
|
+
- Type: `boolean`
|
|
379
|
+
- Default: `false`
|
|
380
|
+
- Description: When `true`, run a **conservative** [SVGO](https://github.com/svg/svgo) pass on each SVG **after** diagnostics and **before** `glyphContentTransformFn`. Removes editor cruft (comments, metadata, doctype) without rewriting paths or removing `viewBox`. Does **not** convert stroke-only artwork to fills — pair with [`glyphContentTransformFn`](#glyphcontenttransformfn) for stroke icons ([#327](https://github.com/itgalaxy/webfont/issues/327), [#724](https://github.com/itgalaxy/webfont/issues/724)).
|
|
381
|
+
- CLI: `--optimize-svg`
|
|
382
|
+
- Optional: `svgoConfig` — SVGO `Config` object; when `plugins` is set, it replaces the built-in conservative plugin list.
|
|
383
|
+
|
|
384
|
+
```js
|
|
385
|
+
import webfont from "webfont";
|
|
386
|
+
|
|
387
|
+
await webfont({
|
|
388
|
+
files: "src/icons/**/*.svg",
|
|
389
|
+
optimizeSvg: true,
|
|
390
|
+
glyphContentTransformFn: async (glyph) => {
|
|
391
|
+
// optional: stroke-to-fill after SVGO cleanup
|
|
392
|
+
return glyph.contents;
|
|
393
|
+
},
|
|
394
|
+
});
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
#### `svgTools` (alpha)
|
|
398
|
+
|
|
399
|
+
- Type: `{ diagnose?: boolean; onMessage?: (message: string) => void }`
|
|
400
|
+
- Default: `undefined` (disabled)
|
|
401
|
+
- Description: **Alpha.** Scan SVG sources for icon-font incompatibilities before font generation (SVG pipeline only). Does **not** modify SVGs — use [`glyphContentTransformFn`](#glyphcontenttransformfn) to preprocess (for example stroke-to-fill with [`svg-outline-stroke`](https://github.com/elrumordelaluz/outline-stroke), installed in your project). See [ADR 0011](docs/adr/0011-no-svg-outline-stroke-dependency.md).
|
|
402
|
+
- **`diagnose`:** log warnings for `fill-rule: evenodd`, stroke-only paths (`fill="none"` + `stroke`), and poorly supported elements (`<line>`, `<polyline>`, `<clipPath>`). Results are also returned on `result.svgDiagnostics` when enabled.
|
|
403
|
+
- **`onMessage`:** optional sink for diagnostic log lines (tests, custom UIs).
|
|
404
|
+
- CLI: `--svg-diagnose` (alpha).
|
|
405
|
+
- Example:
|
|
406
|
+
|
|
407
|
+
```js
|
|
408
|
+
import webfont from "webfont";
|
|
409
|
+
|
|
410
|
+
const result = await webfont({
|
|
411
|
+
files: "src/icons/**/*.svg",
|
|
412
|
+
svgTools: { diagnose: true },
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
console.log(result.svgDiagnostics);
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
See [TROUBLESHOOTING.md](./TROUBLESHOOTING.md) — “Icon details missing after export”.
|
|
419
|
+
|
|
263
420
|
#### `metadataProvider`
|
|
264
421
|
|
|
265
422
|
- Type: `function`
|
|
@@ -492,6 +649,10 @@ If you're using cross-env:
|
|
|
492
649
|
|
|
493
650
|
Tell me everything!.
|
|
494
651
|
|
|
652
|
+
--svg-diagnose
|
|
653
|
+
|
|
654
|
+
(Alpha) Scan SVG icons for icon-font incompatibilities and log warnings.
|
|
655
|
+
|
|
495
656
|
For "svgicons2svgfont":
|
|
496
657
|
|
|
497
658
|
--font-id
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
//#region src/browser.ts
|
|
2
|
+
var e = () => Promise.reject(/* @__PURE__ */ Error("webfont is Node.js-only (requires fs, globby, and other Node built-ins). Run it at build time via the CLI, a Node script, or the webfont-webpack-plugin — do not import it from client-side React/Vue code. See TROUBLESHOOTING.md (Can't resolve 'fs')."));
|
|
3
|
+
//#endregion
|
|
4
|
+
export { e as default, e as webfont };
|