webfont 12.1.0 → 12.2.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/README.md +58 -12
- package/dist/cli.mjs +875 -772
- package/dist/index.js +1 -1
- package/dist/index.mjs +523 -0
- package/dist/{parseTemplateOption-5T7rSw5J.mjs → parseTemplateOption-Bvbie1SQ.mjs} +0 -1
- package/dist/parseTemplateOption-DLNu6PPx.mjs +38 -0
- package/dist/{renderTemplates-DvRlS58E.mjs → renderTemplates-Biyrk6t-.mjs} +16 -17
- package/dist/renderTemplates-CXVKq3Op.mjs +102 -0
- package/dist/src/browser.d.mts +2 -0
- package/dist/src/index.d.mts +5 -0
- package/dist/src/lib/applyOptimizeSvgToGlyphs.d.mts +3 -0
- package/dist/src/lib/evenoddFillRule.d.mts +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/inputSourceUtils.d.mts +4 -0
- package/dist/src/lib/largeFontLigatures.d.mts +4 -0
- package/dist/src/lib/optimizeSvgGlyphs.d.mts +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/parseTemplateOption.d.mts +2 -0
- package/dist/src/lib/runtimeEnvironment.d.mts +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 +1 -0
- package/dist/src/lib/svgFontOutput/emptyGlyphPaths.d.mts +3 -0
- package/dist/src/lib/svgTools/applySvgDiagnostics.d.mts +13 -0
- package/dist/src/lib/svgTools/applySvgTools.d.mts +14 -0
- package/dist/src/lib/svgTools/normalizeSvgToolsOptions.d.mts +2 -0
- package/dist/src/lib/svgicons2svgfont/index.d.mts +14 -0
- package/dist/src/lib/svgicons2svgfont/metadataFromSrcPath.d.mts +11 -0
- package/dist/src/lib/templateUnicodeRange.d.mts +4 -0
- package/dist/src/lib/ttf2eot/index.d.mts +2 -0
- package/dist/src/lib/ttfEncode.d.mts +5 -0
- package/dist/src/standalone/convertTtfInput.d.mts +3 -0
- package/dist/src/standalone/convertWebfontInput.d.mts +3 -0
- package/dist/src/standalone/defaultOptions.d.mts +3 -0
- package/dist/src/standalone/fetchWebfontUrl.d.mts +1 -0
- package/dist/src/standalone/generateSvgFont.d.mts +2 -0
- package/dist/src/standalone/getGlyphsDataFromInputs.d.mts +3 -0
- package/dist/src/standalone/glyphsData.d.mts +4 -0
- package/dist/src/standalone/index.d.mts +10 -0
- package/dist/src/standalone/inputMode.d.mts +9 -0
- package/dist/src/standalone/options.d.mts +5 -0
- package/dist/src/standalone/optionsFromGlyphs.d.mts +3 -0
- package/dist/src/standalone/renderTemplates.d.mts +10 -0
- package/dist/src/standalone/runSvgPipeline.d.mts +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/webfontFromGlyphs.d.mts +3 -0
- package/dist/src/types/DecompressedFont.d.mts +5 -0
- package/dist/src/types/Format.d.mts +11 -0
- package/dist/src/types/Format.d.ts +5 -3
- package/dist/src/types/GlyphContentTransformFn.d.mts +2 -0
- package/dist/src/types/GlyphData.d.mts +6 -0
- package/dist/src/types/GlyphInput.d.mts +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 +12 -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 +41 -0
- package/dist/src/types/OptionsBase.d.ts +3 -1
- package/dist/src/types/RenderedTemplate.d.mts +7 -0
- package/dist/src/types/Result.d.mts +26 -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 +1 -1
- package/dist/src/types/TranscodedFont.d.mts +7 -0
- package/dist/src/types/TtfPostProcessFn.d.mts +12 -0
- package/dist/src/types/TtfPostProcessFn.d.ts +12 -0
- package/dist/src/types/WebfontFromGlyphsOptions.d.mts +11 -0
- package/dist/src/types/WebfontOptions.d.mts +44 -0
- package/dist/src/types/WebfontOptions.d.ts +1 -0
- package/dist/src/types/index.d.mts +9 -0
- package/dist/src/types/index.d.ts +1 -0
- package/package.json +38 -18
- package/dist/templates/index.d.ts +0 -19
package/README.md
CHANGED
|
@@ -75,7 +75,7 @@ Full details, disclaimers, community attribution guidelines, and third-party lib
|
|
|
75
75
|
|
|
76
76
|
## Installation
|
|
77
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.
|
|
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
79
|
|
|
80
80
|
```shell
|
|
81
81
|
npm install --save-dev webfont
|
|
@@ -85,8 +85,26 @@ npm install --save-dev webfont
|
|
|
85
85
|
|
|
86
86
|
Node.js only — do not import from client-side app code ([#198](https://github.com/itgalaxy/webfont/issues/198)).
|
|
87
87
|
|
|
88
|
+
### Import (ESM and CommonJS)
|
|
89
|
+
|
|
90
|
+
Use the **named export** — required for native ESM and recommended since webfont **10+**:
|
|
91
|
+
|
|
92
|
+
```js
|
|
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
|
+
|
|
88
106
|
```js
|
|
89
|
-
import webfont from "webfont";
|
|
107
|
+
import { webfont } from "webfont";
|
|
90
108
|
|
|
91
109
|
webfont({
|
|
92
110
|
files: "src/svg-icons/**/*.svg",
|
|
@@ -106,7 +124,7 @@ webfont({
|
|
|
106
124
|
or
|
|
107
125
|
|
|
108
126
|
```js
|
|
109
|
-
const webfont = require("webfont")
|
|
127
|
+
const { webfont } = require("webfont");
|
|
110
128
|
|
|
111
129
|
webfont({
|
|
112
130
|
files: "src/svg-icons/**/*.svg",
|
|
@@ -126,7 +144,7 @@ webfont({
|
|
|
126
144
|
### TTF encoding examples
|
|
127
145
|
|
|
128
146
|
```js
|
|
129
|
-
import webfont from "webfont";
|
|
147
|
+
import { webfont } from "webfont";
|
|
130
148
|
|
|
131
149
|
// Single local TTF → WOFF + WOFF2 (default when formats unset)
|
|
132
150
|
const encoded = await webfont({
|
|
@@ -150,7 +168,7 @@ const batch = await webfont({
|
|
|
150
168
|
### Webfont decompress examples
|
|
151
169
|
|
|
152
170
|
```js
|
|
153
|
-
import webfont from "webfont";
|
|
171
|
+
import { webfont } from "webfont";
|
|
154
172
|
|
|
155
173
|
// Single local file
|
|
156
174
|
const one = await webfont({
|
|
@@ -284,7 +302,7 @@ webfont "icons/*.svg" -d dist/icons -t scss --addHashInFontUrl
|
|
|
284
302
|
```
|
|
285
303
|
|
|
286
304
|
```js
|
|
287
|
-
import webfont from "webfont";
|
|
305
|
+
import { webfont } from "webfont";
|
|
288
306
|
|
|
289
307
|
await webfont({
|
|
290
308
|
files: "src/icons/**/*.svg",
|
|
@@ -332,7 +350,7 @@ Do **not** use `Math.random()` in `fontName` — that renames both font files an
|
|
|
332
350
|
- Example:
|
|
333
351
|
|
|
334
352
|
```js
|
|
335
|
-
import webfont from "webfont";
|
|
353
|
+
import { webfont } from "webfont";
|
|
336
354
|
|
|
337
355
|
webfont({
|
|
338
356
|
files: "src/svg-icons/**/*.svg",
|
|
@@ -363,7 +381,7 @@ Do **not** use `Math.random()` in `fontName` — that renames both font files an
|
|
|
363
381
|
|
|
364
382
|
```js
|
|
365
383
|
import outlineStroke from "svg-outline-stroke";
|
|
366
|
-
import webfont from "webfont";
|
|
384
|
+
import { webfont } from "webfont";
|
|
367
385
|
|
|
368
386
|
await webfont({
|
|
369
387
|
files: "src/svg-icons/**/*.svg",
|
|
@@ -382,7 +400,7 @@ Do **not** use `Math.random()` in `fontName` — that renames both font files an
|
|
|
382
400
|
- Optional: `svgoConfig` — SVGO `Config` object; when `plugins` is set, it replaces the built-in conservative plugin list.
|
|
383
401
|
|
|
384
402
|
```js
|
|
385
|
-
import webfont from "webfont";
|
|
403
|
+
import { webfont } from "webfont";
|
|
386
404
|
|
|
387
405
|
await webfont({
|
|
388
406
|
files: "src/icons/**/*.svg",
|
|
@@ -399,13 +417,13 @@ Do **not** use `Math.random()` in `fontName` — that renames both font files an
|
|
|
399
417
|
- Type: `{ diagnose?: boolean; onMessage?: (message: string) => void }`
|
|
400
418
|
- Default: `undefined` (disabled)
|
|
401
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).
|
|
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.
|
|
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.
|
|
403
421
|
- **`onMessage`:** optional sink for diagnostic log lines (tests, custom UIs).
|
|
404
422
|
- CLI: `--svg-diagnose` (alpha).
|
|
405
423
|
- Example:
|
|
406
424
|
|
|
407
425
|
```js
|
|
408
|
-
import webfont from "webfont";
|
|
426
|
+
import { webfont } from "webfont";
|
|
409
427
|
|
|
410
428
|
const result = await webfont({
|
|
411
429
|
files: "src/icons/**/*.svg",
|
|
@@ -417,6 +435,24 @@ Do **not** use `Math.random()` in `fontName` — that renames both font files an
|
|
|
417
435
|
|
|
418
436
|
See [TROUBLESHOOTING.md](./TROUBLESHOOTING.md) — “Icon details missing after export”.
|
|
419
437
|
|
|
438
|
+
#### `ttfPostProcess`
|
|
439
|
+
|
|
440
|
+
- Type: `function`
|
|
441
|
+
- Default: `undefined`
|
|
442
|
+
- Description: Post-process the generated **TTF** buffer **after** it is built and **before** webfont derives WOFF/WOFF2/EOT from it (SVG pipeline only). The callback receives `(ttf, { fontName, formats })` and returns the new font bytes (`Buffer` or `Uint8Array`, sync or async). Every derived format is produced from the returned buffer. This is a **caller-owned** extension point — webfont bundles nothing here, so optional/native steps such as **autohinting** (`ttfautohint`) live in **your** project or a separate package, keeping the core free of native dependencies (same philosophy as [`glyphContentTransformFn`](#glyphcontenttransformfn) and [ADR 0011](docs/adr/0011-no-svg-outline-stroke-dependency.md); see [#749](https://github.com/itgalaxy/webfont/issues/749)).
|
|
443
|
+
- Example (autohinting — **install the hinting tool in your app**, not in webfont):
|
|
444
|
+
|
|
445
|
+
```js
|
|
446
|
+
import { webfont } from "webfont";
|
|
447
|
+
import { autohint } from "some-ttfautohint-wrapper";
|
|
448
|
+
|
|
449
|
+
await webfont({
|
|
450
|
+
files: "src/svg-icons/**/*.svg",
|
|
451
|
+
formats: ["ttf", "woff2"],
|
|
452
|
+
ttfPostProcess: async (ttf) => autohint(ttf),
|
|
453
|
+
});
|
|
454
|
+
```
|
|
455
|
+
|
|
420
456
|
#### `metadataProvider`
|
|
421
457
|
|
|
422
458
|
- Type: `function`
|
|
@@ -424,7 +460,7 @@ Do **not** use `Math.random()` in `fontName` — that renames both font files an
|
|
|
424
460
|
- 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.
|
|
425
461
|
|
|
426
462
|
```js
|
|
427
|
-
import webfont from "webfont";
|
|
463
|
+
import { webfont } from "webfont";
|
|
428
464
|
|
|
429
465
|
webfont({
|
|
430
466
|
files: "src/svg-icons/**/*.svg",
|
|
@@ -505,6 +541,12 @@ These can be appended to [webfont options](#options). These are passed directly
|
|
|
505
541
|
- Default: `false`
|
|
506
542
|
- Description: Calculate the bounds of a glyph and center it horizontally.
|
|
507
543
|
|
|
544
|
+
#### `svgicons2svgfont.centerVertically`
|
|
545
|
+
|
|
546
|
+
- Type: `boolean`
|
|
547
|
+
- Default: `false`
|
|
548
|
+
- Description: Center the glyphs vertically in the generated font.
|
|
549
|
+
|
|
508
550
|
#### `svgicons2svgfont.normalize`
|
|
509
551
|
|
|
510
552
|
- Type: `boolean`
|
|
@@ -675,6 +717,10 @@ If you're using cross-env:
|
|
|
675
717
|
|
|
676
718
|
Calculate the bounds of a glyph and center it horizontally.
|
|
677
719
|
|
|
720
|
+
--center-vertically
|
|
721
|
+
|
|
722
|
+
Center the glyphs vertically in the generated font.
|
|
723
|
+
|
|
678
724
|
--normalize
|
|
679
725
|
|
|
680
726
|
Normalize icons by scaling them to the height of the highest icon.
|