webfont 12.2.0 → 12.3.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 +84 -1
- package/dist/cli.mjs +2 -2
- package/dist/src/index.d.mts +2 -0
- package/dist/src/index.d.ts +2 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -190,6 +190,71 @@ const remote = await webfont({
|
|
|
190
190
|
});
|
|
191
191
|
```
|
|
192
192
|
|
|
193
|
+
### Autohinting
|
|
194
|
+
|
|
195
|
+
webfont does not bundle a hinting engine — [`ttfautohint`](https://www.freetype.org/ttfautohint/) is a native binary, so it stays out of the core install. Run it yourself through the [`ttfPostProcess`](#ttfpostprocess) hook: it receives the generated **TTF before** WOFF/WOFF2/EOT are derived, so the hinted outlines flow into every format.
|
|
196
|
+
|
|
197
|
+
**Option A — npm wrapper (no system install).** The [`ttfautohint`](https://www.npmjs.com/package/ttfautohint) package ships a prebuilt binary and a Buffer API:
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
npm i -D ttfautohint
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
```js
|
|
204
|
+
import { webfont } from "webfont";
|
|
205
|
+
import TTFAutohint from "ttfautohint";
|
|
206
|
+
|
|
207
|
+
await webfont({
|
|
208
|
+
files: "src/svg-icons/**/*.svg",
|
|
209
|
+
formats: ["ttf", "woff", "woff2", "eot"],
|
|
210
|
+
// `icon: true` applies icon-font-tuned hinting metrics
|
|
211
|
+
ttfPostProcess: (ttf) => TTFAutohint.transform(ttf, { icon: true }),
|
|
212
|
+
});
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
`TTFAutohint.transform(buffer, options)` returns the hinted `Buffer`, which webfont uses as the TTF and as the source for the other formats.
|
|
216
|
+
|
|
217
|
+
**Option B — system binary (no extra npm dependency).** If `ttfautohint` is already installed (Homebrew, apt, …), pipe the buffer through it:
|
|
218
|
+
|
|
219
|
+
```js
|
|
220
|
+
import { execFileSync } from "node:child_process";
|
|
221
|
+
import { webfont } from "webfont";
|
|
222
|
+
|
|
223
|
+
const autohint = (ttf) =>
|
|
224
|
+
execFileSync("ttfautohint", ["-W", "-i", "-s", "-x", "24", "-l", "12", "-r", "48"], {
|
|
225
|
+
input: ttf,
|
|
226
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
await webfont({
|
|
230
|
+
files: "src/svg-icons/**/*.svg",
|
|
231
|
+
formats: ["ttf", "woff2"],
|
|
232
|
+
ttfPostProcess: (ttf) => autohint(ttf),
|
|
233
|
+
});
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
**CLI.** Flags can't carry a function, but webfont loads a JS config via cosmiconfig — put the hook in `webfont.config.js`:
|
|
237
|
+
|
|
238
|
+
```js
|
|
239
|
+
// webfont.config.js
|
|
240
|
+
const TTFAutohint = require("ttfautohint");
|
|
241
|
+
|
|
242
|
+
module.exports = {
|
|
243
|
+
files: "src/svg-icons/**/*.svg",
|
|
244
|
+
formats: ["ttf", "woff2"],
|
|
245
|
+
ttfPostProcess: (ttf) => TTFAutohint.transform(ttf, { icon: true }),
|
|
246
|
+
};
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
then run `webfont`.
|
|
250
|
+
|
|
251
|
+
Notes:
|
|
252
|
+
|
|
253
|
+
- The hook is **opt-in**; webfont core stays free of native dependencies.
|
|
254
|
+
- CI must have the binary available — the npm wrapper installs one; the system-binary option requires `ttfautohint` on `PATH`.
|
|
255
|
+
- The callback may be async: return a `Promise<Buffer | Uint8Array>` if your tool is asynchronous.
|
|
256
|
+
- See [#749](https://github.com/itgalaxy/webfont/issues/749) for autohinting tracking and a possible first-party companion package.
|
|
257
|
+
|
|
193
258
|
### Options
|
|
194
259
|
|
|
195
260
|
#### `files`
|
|
@@ -439,7 +504,7 @@ Do **not** use `Math.random()` in `fontName` — that renames both font files an
|
|
|
439
504
|
|
|
440
505
|
- Type: `function`
|
|
441
506
|
- 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)).
|
|
507
|
+
- 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)). See the [Autohinting](#autohinting) recipe for npm-wrapper, system-binary, and CLI variants.
|
|
443
508
|
- Example (autohinting — **install the hinting tool in your app**, not in webfont):
|
|
444
509
|
|
|
445
510
|
```js
|
|
@@ -480,6 +545,24 @@ Do **not** use `Math.random()` in `fontName` — that renames both font files an
|
|
|
480
545
|
|
|
481
546
|
`webfont()` resolves to an object with generated font buffers (and optional `template` output). The `config` property contains the **effective options** used for the run (defaults, discovered config, and any options you passed in), plus optional **output metadata** when a configuration file was found or loaded.
|
|
482
547
|
|
|
548
|
+
#### TypeScript
|
|
549
|
+
|
|
550
|
+
`Result` and `ResultConfig` are exported from the package entry, so you can annotate `webfont()` output directly instead of relying on `ReturnType` inference:
|
|
551
|
+
|
|
552
|
+
```ts
|
|
553
|
+
import { webfont, type Result, type ResultConfig } from "webfont";
|
|
554
|
+
|
|
555
|
+
const result: Result = await webfont({
|
|
556
|
+
files: "src/svg-icons/**/*.svg",
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
const config: ResultConfig | undefined = result.config;
|
|
560
|
+
|
|
561
|
+
if (config?.filePath) {
|
|
562
|
+
console.log(`Loaded config from ${config.filePath}`);
|
|
563
|
+
}
|
|
564
|
+
```
|
|
565
|
+
|
|
483
566
|
#### `result.config.filePath`
|
|
484
567
|
|
|
485
568
|
- Type: `string` | `undefined`
|
package/dist/cli.mjs
CHANGED
|
@@ -27,7 +27,7 @@ import { Readable as ge } from "stream";
|
|
|
27
27
|
import _e from "svg2ttf";
|
|
28
28
|
//#region package.json
|
|
29
29
|
var ve, ye, be, xe, Se, Ce, we, Te, Ee, De, p, m, h, g, _, v, y, b, x, S, C, w, T, E, Oe, ke, Ae = r((() => {
|
|
30
|
-
ve = "webfont", ye = "12.
|
|
30
|
+
ve = "webfont", ye = "12.3.0", be = "Generator of fonts from SVG icons; decompress WOFF/WOFF2 to embedded TTF/OTF (not TTF↔OTF transcoding)", xe = {
|
|
31
31
|
lib: "dist",
|
|
32
32
|
source: "src"
|
|
33
33
|
}, Se = [
|
|
@@ -71,7 +71,7 @@ var ve, ye, be, xe, Se, Ce, we, Te, Ee, De, p, m, h, g, _, v, y, b, x, S, C, w,
|
|
|
71
71
|
prebuild: "npm run clean && npm run lint",
|
|
72
72
|
prepare: "lefthook install",
|
|
73
73
|
predemo: "npm run build",
|
|
74
|
-
prepublishOnly: "npm run build && npm run test:package",
|
|
74
|
+
prepublishOnly: "npm whoami && npm run build && npm run test:package",
|
|
75
75
|
pretest: "npm run build",
|
|
76
76
|
prettify: "biome check --write .",
|
|
77
77
|
test: "vitest run src",
|
package/dist/src/index.d.mts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { webfont } from './standalone/index.mjs';
|
|
2
2
|
export { diagnoseGlyphsData, diagnoseSvgContents } from './lib/svgDiagnostics/diagnoseSvgContents.mjs';
|
|
3
3
|
export { webfont } from './standalone/index.mjs';
|
|
4
|
+
export type { Result } from './types/Result.mjs';
|
|
5
|
+
export type { ResultConfig } from './types/ResultConfig.mjs';
|
|
4
6
|
export type { SvgDiagnosticCode, SvgGlyphDiagnostic, SvgToolsOptions } from './types/SvgToolsOptions.mjs';
|
|
5
7
|
export default webfont;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { webfont } from './standalone';
|
|
2
2
|
export { diagnoseGlyphsData, diagnoseSvgContents } from './lib/svgDiagnostics/diagnoseSvgContents';
|
|
3
3
|
export { webfont } from './standalone';
|
|
4
|
+
export type { Result } from './types/Result';
|
|
5
|
+
export type { ResultConfig } from './types/ResultConfig';
|
|
4
6
|
export type { SvgDiagnosticCode, SvgGlyphDiagnostic, SvgToolsOptions } from './types/SvgToolsOptions';
|
|
5
7
|
export default webfont;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webfont",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.3.0",
|
|
4
4
|
"description": "Generator of fonts from SVG icons; decompress WOFF/WOFF2 to embedded TTF/OTF (not TTF↔OTF transcoding)",
|
|
5
5
|
"directories": {
|
|
6
6
|
"lib": "dist",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"prebuild": "npm run clean && npm run lint",
|
|
59
59
|
"prepare": "lefthook install",
|
|
60
60
|
"predemo": "npm run build",
|
|
61
|
-
"prepublishOnly": "npm run build && npm run test:package",
|
|
61
|
+
"prepublishOnly": "npm whoami && npm run build && npm run test:package",
|
|
62
62
|
"pretest": "npm run build",
|
|
63
63
|
"prettify": "biome check --write .",
|
|
64
64
|
"test": "vitest run src",
|