webfont 12.0.0 → 12.1.1
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 +199 -20
- package/dist/browser.js +4 -0
- package/dist/cli.mjs +850 -495
- package/dist/index.js +1 -1
- package/dist/index.mjs +513 -0
- package/dist/parseTemplateOption-BmH_pcQh.js +1 -0
- package/dist/parseTemplateOption-Bvbie1SQ.mjs +19 -0
- package/dist/parseTemplateOption-DLNu6PPx.mjs +38 -0
- package/dist/renderTemplates-Biyrk6t-.mjs +92 -0
- package/dist/renderTemplates-CXVKq3Op.mjs +102 -0
- package/dist/renderTemplates-zCYCzeOt.js +1 -0
- package/dist/src/browser.d.mts +2 -0
- package/dist/src/browser.d.ts +2 -0
- package/dist/src/index.d.mts +5 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/lib/applyOptimizeSvgToGlyphs.d.mts +3 -0
- package/dist/src/lib/applyOptimizeSvgToGlyphs.d.ts +3 -0
- package/dist/src/lib/evenoddFillRule.d.mts +2 -0
- package/dist/src/lib/evenoddFillRule.d.ts +2 -0
- package/dist/src/lib/execCLI/index.d.mts +24 -0
- package/dist/src/lib/inputSource.d.mts +2 -0
- package/dist/src/lib/inputSource.d.ts +1 -4
- package/dist/src/lib/inputSourceUtils.d.mts +4 -0
- package/dist/src/lib/inputSourceUtils.d.ts +4 -0
- package/dist/src/lib/largeFontLigatures.d.mts +4 -0
- package/dist/src/lib/largeFontLigatures.d.ts +4 -0
- package/dist/src/lib/optimizeSvgGlyphs.d.mts +4 -0
- package/dist/src/lib/optimizeSvgGlyphs.d.ts +4 -0
- package/dist/src/lib/p-limit/index.d.mts +2 -0
- package/dist/src/lib/parseFormats.d.mts +4 -0
- package/dist/src/lib/parseFormats.d.ts +4 -0
- package/dist/src/lib/parseTemplateOption.d.mts +2 -0
- package/dist/src/lib/parseTemplateOption.d.ts +2 -0
- package/dist/src/lib/runtimeEnvironment.d.mts +4 -0
- package/dist/src/lib/runtimeEnvironment.d.ts +4 -0
- package/dist/src/lib/sfnt/flavor.d.mts +2 -0
- package/dist/src/lib/svgDiagnostics/diagnoseSvgContents.d.mts +13 -0
- package/dist/src/lib/svgDiagnostics/diagnoseSvgContents.d.ts +13 -0
- package/dist/src/lib/svgFontOutput/emptyGlyphPaths.d.mts +3 -0
- package/dist/src/lib/svgFontOutput/emptyGlyphPaths.d.ts +3 -0
- package/dist/src/lib/svgTools/applySvgDiagnostics.d.mts +13 -0
- package/dist/src/lib/svgTools/applySvgDiagnostics.d.ts +13 -0
- package/dist/src/lib/svgTools/applySvgTools.d.mts +14 -0
- package/dist/src/lib/svgTools/applySvgTools.d.ts +14 -0
- package/dist/src/lib/svgTools/normalizeSvgToolsOptions.d.mts +2 -0
- package/dist/src/lib/svgTools/normalizeSvgToolsOptions.d.ts +2 -0
- package/dist/src/lib/svgicons2svgfont/index.d.mts +14 -0
- package/dist/src/lib/svgicons2svgfont/index.d.ts +5 -0
- package/dist/src/lib/svgicons2svgfont/metadataFromSrcPath.d.mts +11 -0
- package/dist/src/lib/svgicons2svgfont/metadataFromSrcPath.d.ts +11 -0
- package/dist/src/lib/templateUnicodeRange.d.mts +4 -0
- package/dist/src/lib/templateUnicodeRange.d.ts +4 -0
- package/dist/src/lib/ttf2eot/index.d.mts +2 -0
- package/dist/src/lib/ttfEncode.d.mts +5 -0
- package/dist/src/lib/ttfEncode.d.ts +5 -0
- package/dist/src/standalone/convertTtfInput.d.mts +3 -0
- package/dist/src/standalone/convertTtfInput.d.ts +3 -0
- package/dist/src/standalone/convertWebfontInput.d.mts +3 -0
- package/dist/src/standalone/defaultOptions.d.mts +3 -0
- package/dist/src/standalone/defaultOptions.d.ts +3 -0
- package/dist/src/standalone/fetchWebfontUrl.d.mts +1 -0
- package/dist/src/standalone/generateSvgFont.d.mts +2 -0
- package/dist/src/standalone/generateSvgFont.d.ts +2 -0
- package/dist/src/standalone/getGlyphsDataFromInputs.d.mts +3 -0
- package/dist/src/standalone/getGlyphsDataFromInputs.d.ts +3 -0
- package/dist/src/standalone/glyphsData.d.mts +4 -0
- package/dist/src/standalone/glyphsData.d.ts +1 -1
- package/dist/src/standalone/index.d.mts +10 -0
- package/dist/src/standalone/index.d.ts +5 -0
- package/dist/src/standalone/inputMode.d.mts +9 -0
- package/dist/src/standalone/inputMode.d.ts +3 -1
- package/dist/src/standalone/options.d.mts +5 -0
- package/dist/src/standalone/optionsFromGlyphs.d.mts +3 -0
- package/dist/src/standalone/optionsFromGlyphs.d.ts +3 -0
- package/dist/src/standalone/renderTemplates.d.mts +10 -0
- package/dist/src/standalone/renderTemplates.d.ts +10 -0
- package/dist/src/standalone/runSvgPipeline.d.mts +3 -0
- package/dist/src/standalone/runSvgPipeline.d.ts +3 -0
- package/dist/src/standalone/templateFonts.d.mts +3 -0
- package/dist/src/standalone/toTtf.d.mts +4 -0
- package/dist/src/standalone/validateWebfontOptions.d.mts +6 -0
- package/dist/src/standalone/validateWebfontOptions.d.ts +6 -0
- package/dist/src/standalone/webfontFromGlyphs.d.mts +3 -0
- package/dist/src/standalone/webfontFromGlyphs.d.ts +3 -0
- package/dist/src/types/DecompressedFont.d.mts +5 -0
- package/dist/src/types/Format.d.mts +9 -0
- package/dist/src/types/GlyphContentTransformFn.d.mts +2 -0
- package/dist/src/types/GlyphContentTransformFn.d.ts +2 -0
- package/dist/src/types/GlyphData.d.mts +6 -0
- package/dist/src/types/GlyphInput.d.mts +6 -0
- package/dist/src/types/GlyphInput.d.ts +6 -0
- package/dist/src/types/GlyphMetadata.d.mts +10 -0
- package/dist/src/types/GlyphTransformFn.d.mts +2 -0
- package/dist/src/types/InitialOptions.d.mts +10 -0
- package/dist/src/types/InitialOptions.d.ts +2 -0
- package/dist/src/types/MetadataProvider.d.mts +5 -0
- package/dist/src/types/OptionsBase.d.mts +39 -0
- package/dist/src/types/OptionsBase.d.ts +9 -1
- package/dist/src/types/RenderedTemplate.d.mts +7 -0
- package/dist/src/types/RenderedTemplate.d.ts +7 -0
- package/dist/src/types/Result.d.mts +26 -0
- package/dist/src/types/Result.d.ts +8 -0
- package/dist/src/types/ResultConfig.d.mts +4 -0
- package/dist/src/types/SvgToolsOptions.d.mts +13 -0
- package/dist/src/types/SvgToolsOptions.d.ts +13 -0
- package/dist/src/types/TranscodedFont.d.mts +7 -0
- package/dist/src/types/TranscodedFont.d.ts +7 -0
- package/dist/src/types/WebfontFromGlyphsOptions.d.mts +11 -0
- package/dist/src/types/WebfontFromGlyphsOptions.d.ts +11 -0
- package/dist/src/types/WebfontOptions.d.mts +43 -0
- package/dist/src/types/WebfontOptions.d.ts +12 -2
- package/dist/src/types/index.d.mts +8 -0
- package/dist/src/types/index.d.ts +2 -1
- package/dist/templates/index.d.mts +19 -0
- package/package.json +42 -11
- 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,14 +75,36 @@ Full details, disclaimers, community attribution guidelines, and third-party lib
|
|
|
69
75
|
|
|
70
76
|
## Installation
|
|
71
77
|
|
|
78
|
+
Requires **Node.js** >= 24.14.0 (aligned with `svgicons2svgfont@16`). CI tests on Node 24.x and 26.x. 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
|
+
|
|
88
|
+
### Import (ESM and CommonJS)
|
|
89
|
+
|
|
90
|
+
Use the **named export** — required for native ESM and recommended since webfont **10+**:
|
|
91
|
+
|
|
78
92
|
```js
|
|
79
|
-
import webfont from "webfont";
|
|
93
|
+
import { webfont } from "webfont";
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
CommonJS:
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
const { webfont } = require("webfont");
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
`import webfont from "webfont"` is callable in versions that ship the ESM build (**12.x+**), where the default export is the `webfont` function itself ([#618](https://github.com/itgalaxy/webfont/issues/618)). On older releases the default import resolved to the whole `module.exports` object and threw `TypeError: webfont is not a function` under `"type": "module"`. The named import remains the recommended form for new code. See the [migration notes](./docs/migration/issue-0618-esm-default-import.md).
|
|
103
|
+
|
|
104
|
+
### Basic example
|
|
105
|
+
|
|
106
|
+
```js
|
|
107
|
+
import { webfont } from "webfont";
|
|
80
108
|
|
|
81
109
|
webfont({
|
|
82
110
|
files: "src/svg-icons/**/*.svg",
|
|
@@ -96,7 +124,7 @@ webfont({
|
|
|
96
124
|
or
|
|
97
125
|
|
|
98
126
|
```js
|
|
99
|
-
const webfont = require("webfont")
|
|
127
|
+
const { webfont } = require("webfont");
|
|
100
128
|
|
|
101
129
|
webfont({
|
|
102
130
|
files: "src/svg-icons/**/*.svg",
|
|
@@ -113,10 +141,34 @@ webfont({
|
|
|
113
141
|
});
|
|
114
142
|
```
|
|
115
143
|
|
|
144
|
+
### TTF encoding examples
|
|
145
|
+
|
|
146
|
+
```js
|
|
147
|
+
import { webfont } from "webfont";
|
|
148
|
+
|
|
149
|
+
// Single local TTF → WOFF + WOFF2 (default when formats unset)
|
|
150
|
+
const encoded = await webfont({
|
|
151
|
+
files: "path/to/font.ttf",
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
// Explicit formats
|
|
155
|
+
const subset = await webfont({
|
|
156
|
+
files: "path/to/font.ttf",
|
|
157
|
+
formats: ["woff2"],
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// Batch: multiple TTF files in one run
|
|
161
|
+
const batch = await webfont({
|
|
162
|
+
files: ["fonts/Inter-Regular.ttf", "fonts/Inter-Bold.ttf"],
|
|
163
|
+
formats: ["woff", "woff2"],
|
|
164
|
+
});
|
|
165
|
+
// batch.transcodedFonts → [{ source, woff, woff2 }, …]
|
|
166
|
+
```
|
|
167
|
+
|
|
116
168
|
### Webfont decompress examples
|
|
117
169
|
|
|
118
170
|
```js
|
|
119
|
-
import webfont from "webfont";
|
|
171
|
+
import { webfont } from "webfont";
|
|
120
172
|
|
|
121
173
|
// Single local file
|
|
122
174
|
const one = await webfont({
|
|
@@ -145,9 +197,10 @@ const remote = await webfont({
|
|
|
145
197
|
- Type: `string` | `array`
|
|
146
198
|
- 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
199
|
- **SVG mode**: one or more `.svg` icon paths or globs (default pipeline).
|
|
200
|
+
- **TTF encoding mode**: one or more `.ttf` paths or globs.
|
|
148
201
|
- **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.
|
|
202
|
+
- Do not mix `.svg`, `.ttf`, and `.woff` / `.woff2` in the same run.
|
|
203
|
+
- 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
204
|
- `node_modules` and `bower_components` are always ignored.
|
|
152
205
|
|
|
153
206
|
#### `configFile`
|
|
@@ -170,18 +223,22 @@ const remote = await webfont({
|
|
|
170
223
|
#### `formats`
|
|
171
224
|
|
|
172
225
|
- 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.
|
|
226
|
+
- 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
227
|
- Possible values: `svg`, `ttf`, `otf`, `eot`, `woff`, `woff2`
|
|
175
228
|
- Description: Font file types to generate.
|
|
176
229
|
- **SVG input**: `svg`, `ttf`, `eot`, `woff`, `woff2` only. **`otf` is not supported** (pipeline uses TrueType outlines).
|
|
230
|
+
- **TTF input**: `ttf`, `eot`, `woff`, and/or `woff2` only. **`svg` and `otf` are not produced** in this mode.
|
|
177
231
|
- **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
232
|
- 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.
|
|
233
|
+
- API and config files: `formats` must be an array of the values above; unknown names (for example `icon`) throw before the pipeline runs.
|
|
179
234
|
|
|
180
235
|
#### `template`
|
|
181
236
|
|
|
182
|
-
- Type: `string`
|
|
237
|
+
- Type: `string` or `string[]`
|
|
183
238
|
- Default: `null`
|
|
184
|
-
- Possible values: `css`, `scss`,
|
|
239
|
+
- Possible values: `css`, `scss`, `styl`, `html`, `json` (feel free to contribute more), or a path to a custom `.njk` template.
|
|
240
|
+
- Pass an **array** to generate multiple outputs in one run (for example `['html', 'scss']` for preview + styles, #158).
|
|
241
|
+
- CLI: pass `-t` / `--template` as a single name, a JSON array (`'["html","scss"]'`), or a comma-separated list (`html,scss`).
|
|
185
242
|
- Note: If you want to use a custom template use this option pass in a path `string` like this:
|
|
186
243
|
|
|
187
244
|
```js
|
|
@@ -221,14 +278,69 @@ const remote = await webfont({
|
|
|
221
278
|
#### `templateFontName`
|
|
222
279
|
|
|
223
280
|
- Type: `string`
|
|
224
|
-
- Default:
|
|
225
|
-
- Description:
|
|
281
|
+
- Default: Same as [`fontName`](#fontname) when not set.
|
|
282
|
+
- 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)).
|
|
283
|
+
|
|
284
|
+
#### `templateCacheString`
|
|
285
|
+
|
|
286
|
+
- Type: `string`
|
|
287
|
+
- Default: `Date.now()` at generation time
|
|
288
|
+
- 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.
|
|
289
|
+
|
|
290
|
+
#### `addHashInFontUrl`
|
|
291
|
+
|
|
292
|
+
- Type: `boolean`
|
|
293
|
+
- Default: `false`
|
|
294
|
+
- 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).
|
|
295
|
+
- CLI: `--addHashInFontUrl`
|
|
296
|
+
- Addresses browser cache issues without renaming font files on every build ([#125](https://github.com/itgalaxy/webfont/issues/125)).
|
|
297
|
+
|
|
298
|
+
**Example — stable `webfont.scss`, cache-busted font URLs:**
|
|
299
|
+
|
|
300
|
+
```shell
|
|
301
|
+
webfont "icons/*.svg" -d dist/icons -t scss --addHashInFontUrl
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
```js
|
|
305
|
+
import { webfont } from "webfont";
|
|
306
|
+
|
|
307
|
+
await webfont({
|
|
308
|
+
files: "src/icons/**/*.svg",
|
|
309
|
+
fontName: "webfont",
|
|
310
|
+
template: "scss",
|
|
311
|
+
templateFontPath: "./fonts/",
|
|
312
|
+
addHashInFontUrl: true,
|
|
313
|
+
});
|
|
314
|
+
// Writes dist/icons/webfont.scss and dist/icons/webfont.woff2 (fixed names).
|
|
315
|
+
// SCSS contains url("./fonts/webfont.woff2?...&v=<md5>") — hash updates when icons change.
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
Do **not** use `Math.random()` in `fontName` — that renames both font files and the stylesheet on every run.
|
|
319
|
+
|
|
320
|
+
#### `unicodeRange`
|
|
321
|
+
|
|
322
|
+
- Type: `boolean | string`
|
|
323
|
+
- Default: `false` (omit `unicode-range` from built-in templates)
|
|
324
|
+
- 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).
|
|
325
|
+
- CLI: `--unicode-range` to enable auto-computed range
|
|
326
|
+
- 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.
|
|
327
|
+
- **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
328
|
|
|
227
329
|
#### `ligatures`
|
|
228
330
|
|
|
331
|
+
- Type: `boolean`
|
|
332
|
+
- Default: `false` (ligature glyphs are **not** added unless you opt in)
|
|
333
|
+
- 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"`).
|
|
334
|
+
- CLI: `--ligatures` to enable ligature glyphs in the font.
|
|
335
|
+
- **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.
|
|
336
|
+
|
|
337
|
+
#### `templateFontLigatures`
|
|
338
|
+
|
|
229
339
|
- Type: `boolean`
|
|
230
340
|
- Default: `true`
|
|
231
|
-
- Description:
|
|
341
|
+
- 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.
|
|
342
|
+
- CLI: `--no-template-font-ligatures` to omit the CSS rule.
|
|
343
|
+
- Requires [`ligatures`](#ligatures) enabled (`--ligatures` / `ligatures: true`). Class-based icons (`.font-name-icon::before` with a private-use codepoint) work without this option.
|
|
232
344
|
|
|
233
345
|
#### `glyphTransformFn`
|
|
234
346
|
|
|
@@ -238,7 +350,7 @@ const remote = await webfont({
|
|
|
238
350
|
- Example:
|
|
239
351
|
|
|
240
352
|
```js
|
|
241
|
-
import webfont from "webfont";
|
|
353
|
+
import { webfont } from "webfont";
|
|
242
354
|
|
|
243
355
|
webfont({
|
|
244
356
|
files: "src/svg-icons/**/*.svg",
|
|
@@ -260,6 +372,69 @@ const remote = await webfont({
|
|
|
260
372
|
});
|
|
261
373
|
```
|
|
262
374
|
|
|
375
|
+
#### `glyphContentTransformFn`
|
|
376
|
+
|
|
377
|
+
- Type: `function`
|
|
378
|
+
- Default: `null`
|
|
379
|
+
- 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.
|
|
380
|
+
- Example (stroke icons, #144 — **install `svg-outline-stroke` in your app**, not in webfont):
|
|
381
|
+
|
|
382
|
+
```js
|
|
383
|
+
import outlineStroke from "svg-outline-stroke";
|
|
384
|
+
import { webfont } from "webfont";
|
|
385
|
+
|
|
386
|
+
await webfont({
|
|
387
|
+
files: "src/svg-icons/**/*.svg",
|
|
388
|
+
glyphContentTransformFn: async (glyph) => outlineStroke(glyph.contents),
|
|
389
|
+
});
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
For better trace quality with `svg-outline-stroke`, use a larger `width` / `height` / `viewBox` on the source SVG (see the library README).
|
|
393
|
+
|
|
394
|
+
#### `optimizeSvg`
|
|
395
|
+
|
|
396
|
+
- Type: `boolean`
|
|
397
|
+
- Default: `false`
|
|
398
|
+
- 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)).
|
|
399
|
+
- CLI: `--optimize-svg`
|
|
400
|
+
- Optional: `svgoConfig` — SVGO `Config` object; when `plugins` is set, it replaces the built-in conservative plugin list.
|
|
401
|
+
|
|
402
|
+
```js
|
|
403
|
+
import { webfont } from "webfont";
|
|
404
|
+
|
|
405
|
+
await webfont({
|
|
406
|
+
files: "src/icons/**/*.svg",
|
|
407
|
+
optimizeSvg: true,
|
|
408
|
+
glyphContentTransformFn: async (glyph) => {
|
|
409
|
+
// optional: stroke-to-fill after SVGO cleanup
|
|
410
|
+
return glyph.contents;
|
|
411
|
+
},
|
|
412
|
+
});
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
#### `svgTools` (alpha)
|
|
416
|
+
|
|
417
|
+
- Type: `{ diagnose?: boolean; onMessage?: (message: string) => void }`
|
|
418
|
+
- Default: `undefined` (disabled)
|
|
419
|
+
- 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).
|
|
420
|
+
- **`diagnose`:** log warnings for `fill-rule: evenodd`, stroke-only paths (`fill="none"` + `stroke`), `<use>` symbol references ([#612](https://github.com/itgalaxy/webfont/issues/612)), and poorly supported elements (`<line>`, `<polyline>`, `<clipPath>`). Results are also returned on `result.svgDiagnostics` when enabled.
|
|
421
|
+
- **`onMessage`:** optional sink for diagnostic log lines (tests, custom UIs).
|
|
422
|
+
- CLI: `--svg-diagnose` (alpha).
|
|
423
|
+
- Example:
|
|
424
|
+
|
|
425
|
+
```js
|
|
426
|
+
import { webfont } from "webfont";
|
|
427
|
+
|
|
428
|
+
const result = await webfont({
|
|
429
|
+
files: "src/icons/**/*.svg",
|
|
430
|
+
svgTools: { diagnose: true },
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
console.log(result.svgDiagnostics);
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
See [TROUBLESHOOTING.md](./TROUBLESHOOTING.md) — “Icon details missing after export”.
|
|
437
|
+
|
|
263
438
|
#### `metadataProvider`
|
|
264
439
|
|
|
265
440
|
- Type: `function`
|
|
@@ -267,7 +442,7 @@ const remote = await webfont({
|
|
|
267
442
|
- Description: Custom callback to resolve glyph metadata for each source file. Receives the file path and a Node-style callback `(error, metadata)` where `metadata` is `{ name: string, unicode?: string | string[] }`. When omitted, webfont uses its default metadata reader.
|
|
268
443
|
|
|
269
444
|
```js
|
|
270
|
-
import webfont from "webfont";
|
|
445
|
+
import { webfont } from "webfont";
|
|
271
446
|
|
|
272
447
|
webfont({
|
|
273
448
|
files: "src/svg-icons/**/*.svg",
|
|
@@ -492,6 +667,10 @@ If you're using cross-env:
|
|
|
492
667
|
|
|
493
668
|
Tell me everything!.
|
|
494
669
|
|
|
670
|
+
--svg-diagnose
|
|
671
|
+
|
|
672
|
+
(Alpha) Scan SVG icons for icon-font incompatibilities and log warnings.
|
|
673
|
+
|
|
495
674
|
For "svgicons2svgfont":
|
|
496
675
|
|
|
497
676
|
--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 };
|