webfont 11.2.26 → 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.
Files changed (80) hide show
  1. package/NOTICE.md +165 -0
  2. package/README.md +302 -34
  3. package/dist/browser.js +4 -0
  4. package/dist/cli.mjs +893 -0
  5. package/dist/index.js +1 -507
  6. package/dist/parseTemplateOption-5T7rSw5J.mjs +20 -0
  7. package/dist/parseTemplateOption-BmH_pcQh.js +1 -0
  8. package/dist/renderTemplates-DvRlS58E.mjs +93 -0
  9. package/dist/renderTemplates-zCYCzeOt.js +1 -0
  10. package/dist/src/browser.d.ts +2 -0
  11. package/dist/src/index.d.ts +4 -2
  12. package/dist/src/lib/applyOptimizeSvgToGlyphs.d.ts +3 -0
  13. package/dist/src/lib/evenoddFillRule.d.ts +2 -0
  14. package/dist/src/lib/execCLI/index.d.ts +3 -4
  15. package/dist/src/lib/inputSource.d.ts +2 -0
  16. package/dist/src/lib/inputSourceUtils.d.ts +4 -0
  17. package/dist/src/lib/largeFontLigatures.d.ts +4 -0
  18. package/dist/src/lib/optimizeSvgGlyphs.d.ts +4 -0
  19. package/dist/src/lib/p-limit/index.d.ts +2 -0
  20. package/dist/src/lib/parseFormats.d.ts +4 -0
  21. package/dist/src/lib/parseTemplateOption.d.ts +2 -0
  22. package/dist/src/lib/runtimeEnvironment.d.ts +4 -0
  23. package/dist/src/lib/sfnt/flavor.d.ts +2 -0
  24. package/dist/src/lib/svgDiagnostics/diagnoseSvgContents.d.ts +12 -0
  25. package/dist/src/lib/svgFontOutput/emptyGlyphPaths.d.ts +3 -0
  26. package/dist/src/lib/svgTools/applySvgDiagnostics.d.ts +13 -0
  27. package/dist/src/lib/svgTools/applySvgTools.d.ts +14 -0
  28. package/dist/src/lib/svgTools/normalizeSvgToolsOptions.d.ts +2 -0
  29. package/dist/src/lib/svgicons2svgfont/index.d.ts +14 -0
  30. package/dist/src/lib/svgicons2svgfont/metadataFromSrcPath.d.ts +11 -0
  31. package/dist/src/lib/templateUnicodeRange.d.ts +4 -0
  32. package/dist/src/lib/ttf2eot/index.d.ts +2 -0
  33. package/dist/src/lib/ttfEncode.d.ts +5 -0
  34. package/dist/src/standalone/convertTtfInput.d.ts +3 -0
  35. package/dist/src/standalone/convertWebfontInput.d.ts +3 -0
  36. package/dist/src/standalone/defaultOptions.d.ts +3 -0
  37. package/dist/src/standalone/fetchWebfontUrl.d.ts +1 -0
  38. package/dist/src/standalone/generateSvgFont.d.ts +2 -0
  39. package/dist/src/standalone/getGlyphsDataFromInputs.d.ts +3 -0
  40. package/dist/src/standalone/glyphsData.d.ts +2 -2
  41. package/dist/src/standalone/index.d.ts +8 -3
  42. package/dist/src/standalone/inputMode.d.ts +9 -0
  43. package/dist/src/standalone/options.d.ts +3 -3
  44. package/dist/src/standalone/optionsFromGlyphs.d.ts +3 -0
  45. package/dist/src/standalone/renderTemplates.d.ts +10 -0
  46. package/dist/src/standalone/runSvgPipeline.d.ts +3 -0
  47. package/dist/src/standalone/templateFonts.d.ts +3 -0
  48. package/dist/src/standalone/toTtf.d.ts +4 -0
  49. package/dist/src/standalone/validateWebfontOptions.d.ts +6 -0
  50. package/dist/src/standalone/webfontFromGlyphs.d.ts +3 -0
  51. package/dist/src/types/DecompressedFont.d.ts +5 -0
  52. package/dist/src/types/Format.d.ts +4 -4
  53. package/dist/src/types/GlyphContentTransformFn.d.ts +2 -0
  54. package/dist/src/types/GlyphData.d.ts +2 -2
  55. package/dist/src/types/GlyphInput.d.ts +6 -0
  56. package/dist/src/types/GlyphMetadata.d.ts +1 -1
  57. package/dist/src/types/GlyphTransformFn.d.ts +2 -2
  58. package/dist/src/types/InitialOptions.d.ts +7 -4
  59. package/dist/src/types/MetadataProvider.d.ts +5 -0
  60. package/dist/src/types/OptionsBase.d.ts +12 -3
  61. package/dist/src/types/RenderedTemplate.d.ts +7 -0
  62. package/dist/src/types/Result.d.ts +16 -5
  63. package/dist/src/types/ResultConfig.d.ts +4 -0
  64. package/dist/src/types/SvgToolsOptions.d.ts +13 -0
  65. package/dist/src/types/TranscodedFont.d.ts +7 -0
  66. package/dist/src/types/WebfontFromGlyphsOptions.d.ts +11 -0
  67. package/dist/src/types/WebfontOptions.d.ts +39 -3
  68. package/dist/src/types/index.d.ts +8 -6
  69. package/package.json +65 -57
  70. package/templates/template.css.njk +6 -3
  71. package/templates/template.html.njk +15 -4
  72. package/templates/template.scss.njk +6 -3
  73. package/templates/template.styl.njk +6 -3
  74. package/dist/cli.js +0 -801
  75. package/dist/jest.config.d.ts +0 -3
  76. package/dist/src/cli/index.d.ts +0 -1
  77. package/dist/src/cli/index.test.d.ts +0 -1
  78. package/dist/src/cli/meow/index.d.ts +0 -104
  79. package/dist/src/index.test.d.ts +0 -1
  80. package/dist/src/standalone/index.test.d.ts +0 -1
package/NOTICE.md ADDED
@@ -0,0 +1,165 @@
1
+ # webfont — Legal notice
2
+
3
+ This document covers **copyright and licensing for fonts you process**, **disclaimers** about using the webfont software, **community attribution guidelines**, and **third-party open-source components** bundled with or used by this project.
4
+
5
+ It does **not** replace the [MIT License](./LICENSE) for the webfont source code. If anything here conflicts with `LICENSE`, `LICENSE` governs the software itself.
6
+
7
+ **This is not legal advice.** When in doubt about a font or icon license, consult the rights holder or qualified counsel.
8
+
9
+ ---
10
+
11
+ ## 1. webfont software license
12
+
13
+ The **webfont** program (source code, CLI, and npm package) is licensed under the **[MIT License](./LICENSE)**.
14
+
15
+ Copyright (c) 2016–present [itgalaxy](https://github.com/itgalaxy).
16
+
17
+ You may use, copy, modify, and distribute the **software** under the terms of `LICENSE`, provided the copyright and permission notice are preserved in copies or substantial portions.
18
+
19
+ ---
20
+
21
+ ## 2. Disclaimer of warranties and limitation of liability
22
+
23
+ THE WEBFONT SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24
+
25
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+
27
+ **You are solely responsible** for how you use webfont, what files you pass into it, and what you do with the output.
28
+
29
+ ---
30
+
31
+ ## 3. Fonts and icons you provide (user content)
32
+
33
+ webfont is a **technical tool**. It does **not**:
34
+
35
+ - grant any copyright, trademark, or distribution rights in fonts or icons;
36
+ - change the license terms of input or output files;
37
+ - verify that you have permission to use, modify, decompress, convert, or redistribute any font or SVG;
38
+ - remove or replace copyright or license metadata embedded in font files (name tables, etc.).
39
+
40
+ ### 3.1 SVG icon input
41
+
42
+ If you build a font from **`.svg` icons**, you must have the right to use those artworks (your own work, licensed stock, client assets with permission, open-source icons under compatible terms, etc.).
43
+
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
+
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
58
+
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:
60
+
61
+ - does **not** make a restricted or commercial font free to use or share;
62
+ - does **not** bypass foundry EULAs, app terms of service, CDN hotlinking policies, or site download terms;
63
+ - may produce files that are **easier to reuse** than the original webfonts — compliance with the **original font license** remains your obligation;
64
+ - does **not** merge multiple weights into one font file — each input yields a separate output.
65
+
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.
67
+
68
+ ### 3.5 Redistribution of output
69
+
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.
71
+
72
+ ---
73
+
74
+ ## 4. Community attribution guidelines
75
+
76
+ These guidelines help the community use and reference webfont fairly. They are **social expectations**, not additional legal terms beyond `LICENSE`.
77
+
78
+ ### 4.1 Using webfont in your project
79
+
80
+ - **No attribution required** for normal use (install via npm, run in CI, internal tooling) under the MIT License.
81
+ - **Appreciated** when webfont is a visible part of a product, tutorial, or open-source repo: mention [webfont](https://github.com/itgalaxy/webfont) and link to the repository or [npm package](https://www.npmjs.com/package/webfont).
82
+
83
+ ### 4.2 Tutorials, posts, and courses
84
+
85
+ When documenting a workflow that centers on webfont, please:
86
+
87
+ - name the tool (**webfont**) and link to the official repo or npm page;
88
+ - distinguish **webfont the software** (MIT) from **fonts you demonstrate** (which may be proprietary);
89
+ - avoid implying **endorsement** by itgalaxy unless you have written permission.
90
+
91
+ ### 4.3 Forks, wrappers, and hosted services
92
+
93
+ If you redistribute webfont code, ship a fork, or offer a hosted “font converter” built on webfont:
94
+
95
+ - comply with the **MIT License** (retain copyright and permission notice);
96
+ - do **not** use the itgalaxy name, logo, or webfont branding to suggest official affiliation without permission;
97
+ - provide **your own** terms and privacy policy for user-uploaded fonts; make clear that **users** must have rights to their files.
98
+
99
+ ### 4.4 Citing underlying libraries
100
+
101
+ webfont builds on several open-source font libraries (see [Section 5](#5-third-party-open-source-dependencies)). If you publish academic work, a detailed case study, or compliance documentation that discusses **how** conversion is implemented, consider citing those libraries alongside webfont.
102
+
103
+ ---
104
+
105
+ ## 5. Third-party open-source dependencies
106
+
107
+ webfont depends on the following **runtime** npm packages (direct dependencies). Versions follow `package.json` / `package-lock.json` at release time.
108
+
109
+ | Package | Typical license | Role in webfont |
110
+ |---------|-----------------|-----------------|
111
+ | [cosmiconfig](https://github.com/cosmiconfig/cosmiconfig) | MIT | Configuration file discovery |
112
+ | [deepmerge](https://github.com/TehShrike/deepmerge) | MIT | Option merging |
113
+ | [fontverter](https://github.com/papandreou/fontverter) | BSD-3-Clause | WOFF/WOFF2 → SFNT decompression |
114
+ | [globby](https://github.com/sindresorhus/globby) | MIT | Input file globbing |
115
+ | [meow](https://github.com/sindresorhus/meow) | MIT | CLI argument parsing |
116
+ | [nunjucks](https://github.com/mozilla/nunjucks) | BSD-2-Clause | CSS / SCSS / Styl templates |
117
+ | [p-limit](https://github.com/sindresorhus/p-limit) | MIT | Concurrency limiting |
118
+ | [resolve-from](https://github.com/sindresorhus/resolve-from) | MIT | Module resolution |
119
+ | [svgo](https://github.com/svg/svgo) | MIT | Optional SVG optimization (`optimizeSvg`) |
120
+ | [svg2ttf](https://github.com/fontello/svg2ttf) | MIT | SVG font → TTF |
121
+ | [svgicons2svgfont](https://github.com/nfroidure/svgicons2svgfont) | MIT | SVG icons → SVG font |
122
+ | [ttf2eot](https://github.com/fontello/ttf2eot) | MIT | TTF → EOT |
123
+ | [ttf2woff](https://github.com/fontello/ttf2woff) | MIT | TTF → WOFF |
124
+ | [wawoff2](https://github.com/fontello/wawoff2) | MIT | TTF ↔ WOFF2 compression |
125
+ | [xml2js](https://github.com/Leonidas-from-XIV/node-xml2js) | MIT | SVG XML parsing |
126
+
127
+ Transitive dependencies (and their licenses) are recorded in `package-lock.json`. For a full license report after install, you can run:
128
+
129
+ ```shell
130
+ npx license-checker --production --direct
131
+ ```
132
+
133
+ (Third-party tool; not maintained by this project.)
134
+
135
+ ### BSD-licensed components
136
+
137
+ **fontverter** (BSD-3-Clause) and **nunjucks** (BSD-2-Clause) are subject to their own copyright notices and license terms. Redistributions of webfont that include source or substantial portions of those dependencies should preserve their respective notices as required by those licenses.
138
+
139
+ ---
140
+
141
+ ## 6. Test fixtures and examples
142
+
143
+ Font and SVG files under `src/fixtures/` are intended **for automated tests and documentation examples** only. They are not a grant of rights to use those assets outside this repository. Do not assume fixture fonts or icons are redistributable for your own products.
144
+
145
+ ---
146
+
147
+ ## 7. Keeping this document current
148
+
149
+ Update **NOTICE.md** in the same pull request when you:
150
+
151
+ - add or remove **runtime dependencies** that affect licensing or attribution;
152
+ - change **user-facing behavior** around font decompression or output formats in ways that affect legal expectations;
153
+ - publish new **community guidelines** for attribution or acceptable use.
154
+
155
+ See also [FEATURES.md](./FEATURES.md) (product capabilities) and [CONTRIBUTING.md](./CONTRIBUTING.md) (documentation expectations).
156
+
157
+ ---
158
+
159
+ ## 8. Questions and reports
160
+
161
+ - **Software bugs and features:** [GitHub Issues](https://github.com/itgalaxy/webfont/issues)
162
+ - **Code of conduct:** [CODE_OF_CONDUCT.md](./CODE_OF_CONDUCT.md)
163
+ - **License of the webfont source:** [LICENSE](./LICENSE)
164
+
165
+ For font licensing questions about **your** input files, contact the font foundry, vendor, or rights holder — maintainers cannot advise on third-party font EULAs.
package/README.md CHANGED
@@ -1,28 +1,64 @@
1
1
  # webfont
2
2
 
3
3
  [![NPM version](https://img.shields.io/npm/v/webfont.svg)](https://www.npmjs.org/package/webfont)
4
- [![Travis Build Status](https://img.shields.io/travis/itgalaxy/webfont/master.svg?label=build)](https://travis-ci.org/itgalaxy/webfont)
5
- [![Build status](https://ci.appveyor.com/api/projects/status/a8absovr2r44w1oc?svg=true)](https://ci.appveyor.com/project/evilebottnawi/webfont)
4
+ [![Node.js CI](https://github.com/itgalaxy/webfont/actions/workflows/pr.yml/badge.svg)](https://github.com/itgalaxy/webfont/actions/workflows/pr.yml)
6
5
 
7
- Generator of fonts from SVG icons.
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.
7
+
8
+ See **[FEATURES.md](./FEATURES.md)** for the canonical capability list (what is stable, in progress, or planned).
9
+
10
+ **Legal / licensing:** [NOTICE.md](./NOTICE.md) — font copyright, disclaimers, attribution guidelines, and third-party library notices.
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.
8
15
 
9
16
  ## Features
10
17
 
11
- - Supported font formats: `WOFF2`, `WOFF`, `EOT`, `TTF` and `SVG`;
12
- - Support config files: use a `JavaScript`, `JSON` or `YAML` file to specify configuration information for an entire directory and all of its subdirectories;
13
- - Support all popular browsers, including IE8+;
14
- - Allows using custom templates (example `css`, `scss`, [`styl`](https://github.com/itgalaxy/webfont/pull/164/) etc);
15
- - No extra dependencies as `gulp`, `grunt` or other big tools;
16
- - Tested on all platforms (`linux`, `windows` and `osx`);
17
- - CLI;
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);
20
+ - **Webfont decompression**: one `.woff` or `.woff2` file → `ttf` and/or `otf` matching the **embedded SFNT flavor** (decompress only — not TTF ↔ OTF transcoding);
21
+ - Config files: `JavaScript`, `JSON`, or `YAML` via [cosmiconfig](https://github.com/cosmiconfig/cosmiconfig);
22
+ - Built-in and custom CSS templates (`css`, `scss`, [`styl`](https://github.com/itgalaxy/webfont/pull/164/));
23
+ - CLI and programmatic API (**Node.js build time only** — see [TROUBLESHOOTING](./TROUBLESHOOTING.md#cant-resolve-fs-webpack--react--vite-client-bundle));
18
24
  - [Webpack plugin](https://github.com/itgalaxy/webfont-webpack-plugin).
19
25
 
26
+ ## Input modes
27
+
28
+ webfont runs one of three pipelines depending on matched input files. They cannot be mixed in a single run.
29
+
30
+ | Mode | Input | Outputs | Notes |
31
+ |------|--------|---------|--------|
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. |
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. |
35
+
36
+ **Not supported today**
37
+
38
+ - Renaming or re-wrapping without matching the real outline format (e.g. requesting `otf` when the WOFF2 holds TrueType).
39
+ - Converting TTF to OTF (or OTF to TTF) — use [FontForge](https://fontforge.org/) or similar.
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.
42
+ - Globs that match extension-less or unsupported files together with fonts (the run fails instead of silently ignoring extras).
43
+
44
+ Every matched path must end in `.svg`, `.ttf`, `.woff`, or `.woff2`. See [FEATURES.md](./FEATURES.md) for test-backed criteria.
45
+
46
+ ### Font licensing
47
+
48
+ webfont is a technical tool. **Decompressing or generating fonts does not grant you any rights to those fonts.** You must have permission to use, convert, and redistribute every input file and every output file under the applicable license (commercial fonts, app-bundled webfonts, client icons, etc.). The MIT license applies to **this software only**, not to fonts you pass through it.
49
+
50
+ Full details, disclaimers, community attribution guidelines, and third-party library notices: **[NOTICE.md](./NOTICE.md)**.
51
+
20
52
  ## Table Of Contents
21
53
 
22
54
  - [Webfont](#webfont)
55
+ - [Features](#features)
56
+ - [Input modes](#input-modes)
57
+ - [Font licensing](#font-licensing)
23
58
  - [Installation](#installation)
24
59
  - [Usage](#usage)
25
60
  - [Options](#options)
61
+ - [Result](#result)
26
62
  - [svgicons2svgfont](#svgicons2svgfont)
27
63
  - [Command Line Interface (CLI)](#command-line-interface)
28
64
  - [Installation](#cli-installation)
@@ -32,18 +68,23 @@ Generator of fonts from SVG icons.
32
68
  - [Roadmap](#roadmap)
33
69
  - [Contribution](#contribution)
34
70
  - [Changelog](#changelog)
71
+ - [Legal notice](#legal-notice)
35
72
  - [License](#license)
36
73
 
37
74
  ---
38
75
 
39
76
  ## Installation
40
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
+
41
80
  ```shell
42
81
  npm install --save-dev webfont
43
82
  ```
44
83
 
45
84
  ## Usage
46
85
 
86
+ Node.js only — do not import from client-side app code ([#198](https://github.com/itgalaxy/webfont/issues/198)).
87
+
47
88
  ```js
48
89
  import webfont from "webfont";
49
90
 
@@ -82,13 +123,67 @@ webfont({
82
123
  });
83
124
  ```
84
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
+
150
+ ### Webfont decompress examples
151
+
152
+ ```js
153
+ import webfont from "webfont";
154
+
155
+ // Single local file
156
+ const one = await webfont({
157
+ files: "path/to/font.woff2",
158
+ formats: ["ttf"],
159
+ });
160
+
161
+ // Batch: multiple files in one run (one TTF/OTF output per input)
162
+ const batch = await webfont({
163
+ files: ["fonts/Inter-Regular.woff2", "fonts/Inter-Bold.woff2"],
164
+ formats: ["ttf"],
165
+ });
166
+ // batch.decompressedFonts → [{ source, ttf }, …]
167
+
168
+ // Remote URL (http or https)
169
+ const remote = await webfont({
170
+ files: "https://cdn.example.com/fonts/Inter-Medium.woff2",
171
+ formats: ["ttf"],
172
+ });
173
+ ```
174
+
85
175
  ### Options
86
176
 
87
177
  #### `files`
88
178
 
89
179
  - Type: `string` | `array`
90
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.
91
- - Note: `node_modules` and `bower_components` are always ignored.
181
+ - **SVG mode**: one or more `.svg` icon paths or globs (default pipeline).
182
+ - **TTF encoding mode**: one or more `.ttf` paths or globs.
183
+ - **Webfont decompress mode**: one or more `.woff` / `.woff2` paths, globs, or `https://…` URLs (see [`formats`](#formats) and [Input modes](#input-modes)).
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.
186
+ - `node_modules` and `bower_components` are always ignored.
92
187
 
93
188
  #### `configFile`
94
189
 
@@ -99,6 +194,7 @@ webfont({
99
194
  2. a `.webfontrc` file (with or without filename extension: `.json`, `.yaml`, and `.js` are available)
100
195
  3. a `webfont.config.js` file exporting a JS `object`.
101
196
  The search will begin in the working directory and move up the directory tree until it finds a configuration file.
197
+ - Note: When a configuration file is discovered or loaded, the resolved absolute path is available on `result.config.filePath` (see [Result](#result)).
102
198
 
103
199
  #### `fontName`
104
200
 
@@ -108,16 +204,23 @@ webfont({
108
204
 
109
205
  #### `formats`
110
206
 
111
- - Type: `array`,
112
- - Default: `['svg', 'ttf', 'eot', 'woff', 'woff2']`,
113
- - Possible values: `svg, ttf, eot, woff, woff2`,
207
+ - Type: `array`
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.
209
+ - Possible values: `svg`, `ttf`, `otf`, `eot`, `woff`, `woff2`
114
210
  - Description: Font file types to generate.
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.
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.
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.
115
216
 
116
217
  #### `template`
117
218
 
118
- - Type: `string`
219
+ - Type: `string` or `string[]`
119
220
  - Default: `null`
120
- - Possible values: `css`, `scss`, [`styl`](https://github.com/itgalaxy/webfont/pull/164/) (feel free to contribute more).
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`).
121
224
  - Note: If you want to use a custom template use this option pass in a path `string` like this:
122
225
 
123
226
  ```js
@@ -157,8 +260,69 @@ webfont({
157
260
  #### `templateFontName`
158
261
 
159
262
  - Type: `string`
160
- - Default: Gets is from `fontName` if not set, but you can specify any value.
161
- - Description: Template font family name you want.
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.
310
+
311
+ #### `ligatures`
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
+
321
+ - Type: `boolean`
322
+ - Default: `true`
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.
162
326
 
163
327
  #### `glyphTransformFn`
164
328
 
@@ -190,12 +354,113 @@ webfont({
190
354
  });
191
355
  ```
192
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
+
420
+ #### `metadataProvider`
421
+
422
+ - Type: `function`
423
+ - Default: built-in metadata service (reads icon names and unicode from SVG files)
424
+ - 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
+
426
+ ```js
427
+ import webfont from "webfont";
428
+
429
+ webfont({
430
+ files: "src/svg-icons/**/*.svg",
431
+ metadataProvider: (srcPath, callback) => {
432
+ callback(null, { name: "custom-icon-name" });
433
+ },
434
+ });
435
+ ```
436
+
193
437
  #### `sort`
194
438
 
195
439
  - Type: `bool`
196
440
  - Default: `true`
197
441
  - Description: Whether you want to sort the icons sorted by name.
198
442
 
443
+ ### Result
444
+
445
+ `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.
446
+
447
+ #### `result.config.filePath`
448
+
449
+ - Type: `string` | `undefined`
450
+ - Description: Absolute path to the configuration file that was discovered (`search`) or loaded (`configFile` / CLI `--config`). Omitted when no configuration file was found and defaults were used.
451
+ - Note: Output-only metadata — not an input option. Do not set `filePath` in `.webfontrc`, `package.json`, or the `webfont()` call; values passed that way are ignored.
452
+ - Example:
453
+
454
+ ```js
455
+ const result = await webfont({
456
+ files: "src/svg-icons/**/*.svg",
457
+ });
458
+
459
+ if (result.config?.filePath) {
460
+ console.log(`Loaded config from ${result.config.filePath}`);
461
+ }
462
+ ```
463
+
199
464
  ---
200
465
 
201
466
  ## svgicons2svgfont
@@ -277,12 +542,6 @@ These can be appended to [webfont options](#options). These are passed directly
277
542
  - Description: The font [metadata](http://www.w3.org/TR/SVG/metadata.html).
278
543
  You can set any character data in, but this is the recommended place for a copyright mention.
279
544
 
280
- #### `svgicons2svgfont.log`
281
-
282
- - Type: `function`
283
- - Default: `console.log`
284
- - Description: Allows you to provide your own logging function. Set to `function(){}` to disable logging.
285
-
286
545
  ---
287
546
 
288
547
  ## Command Line Interface
@@ -296,7 +555,7 @@ Add the `cli` script to your `package.json` file's `scripts` object:
296
555
  ```json
297
556
  {
298
557
  "scripts": {
299
- "webfont": "node node_modules/webfont/dist/cli.js"
558
+ "webfont": "node node_modules/webfont/dist/cli.mjs"
300
559
  }
301
560
  }
302
561
  ```
@@ -306,7 +565,7 @@ If you're using cross-env:
306
565
  ```json
307
566
  {
308
567
  "scripts": {
309
- "webfont": "cross-env node_modules/webfont/dist/cli.js"
568
+ "webfont": "cross-env node_modules/webfont/dist/cli.mjs"
310
569
  }
311
570
  }
312
571
  ```
@@ -336,7 +595,7 @@ If you're using cross-env:
336
595
  The search will begin in the working directory and move up the
337
596
  directory tree until a configuration file is found.
338
597
 
339
- -f, --font-name
598
+ -u, --fontName
340
599
 
341
600
  The font family name you want, default: "webfont".
342
601
 
@@ -348,9 +607,12 @@ If you're using cross-env:
348
607
 
349
608
  Output the version number.
350
609
 
351
- -r, --formats
610
+ -f, --formats
352
611
 
353
- Only this formats generate.
612
+ Font formats to generate. Pass a JSON array (e.g. '["woff2"]') or a
613
+ comma-separated list (e.g. woff2 or svg, ttf, woff2).
614
+ SVG input: svg, ttf, eot, woff, woff2 (not otf).
615
+ WOFF/WOFF2 input: ttf and/or otf matching the embedded SFNT flavor.
354
616
 
355
617
  -d, --dest
356
618
 
@@ -387,6 +649,10 @@ If you're using cross-env:
387
649
 
388
650
  Tell me everything!.
389
651
 
652
+ --svg-diagnose
653
+
654
+ (Alpha) Scan SVG icons for icon-font incompatibilities and log warnings.
655
+
390
656
  For "svgicons2svgfont":
391
657
 
392
658
  --font-id
@@ -468,10 +734,8 @@ The CLI can exit the process with the following exit codes:
468
734
 
469
735
  ## Roadmap
470
736
 
471
- - The ability to generate from any type to any type;
472
- - More tests, include CLI test;
473
- - Improved docs;
474
- - Reduce package size (maybe implement `ttf2woff2` with native js library);
737
+ - Arbitrary format transcoding (e.g. TTF OTF outline conversion) — see [FEATURES.md](./FEATURES.md) (“Arbitrary format transcoding”, planned);
738
+ - Reduce package size (maybe implement `ttf2woff2` with a native JS library);
475
739
  - Improve performance (maybe use cache for this).
476
740
 
477
741
  ## Contribution
@@ -482,6 +746,10 @@ Feel free to push your code if you agree with publishing under the MIT license.
482
746
 
483
747
  Check our [Changelog](CHANGELOG.md)
484
748
 
749
+ ## Legal notice
750
+
751
+ Copyright, disclaimers, font licensing expectations (including WOFF/WOFF2 decompression), community attribution guidelines, and third-party open-source dependencies are documented in **[NOTICE.md](./NOTICE.md)**.
752
+
485
753
  ## License
486
754
 
487
- Check our [License](LICENSE)
755
+ The **webfont software** is licensed under the [MIT License](./LICENSE). That license does **not** apply to fonts or icons you process with the tool — see [NOTICE.md](./NOTICE.md).
@@ -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 };