webfont 12.3.0 → 12.4.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 +1 -1
- package/README.md +73 -6
- package/dist/cli.mjs +273 -255
- package/dist/index.js +1 -1
- package/dist/index.mjs +142 -132
- package/dist/src/lib/ttfEncode.d.mts +3 -0
- package/dist/src/lib/ttfEncode.d.ts +3 -0
- package/dist/src/standalone/inputMode.d.mts +1 -1
- package/dist/src/standalone/inputMode.d.ts +1 -1
- package/dist/src/types/TranscodedFont.d.mts +1 -0
- package/dist/src/types/TranscodedFont.d.ts +1 -0
- package/package.json +9 -1
package/dist/index.mjs
CHANGED
|
@@ -6,16 +6,17 @@ import r from "deepmerge";
|
|
|
6
6
|
import i from "path";
|
|
7
7
|
import { globby as a } from "globby";
|
|
8
8
|
import * as o from "fs/promises";
|
|
9
|
-
import s from "
|
|
10
|
-
import c from "
|
|
11
|
-
import l from "
|
|
12
|
-
import u from "
|
|
13
|
-
import
|
|
14
|
-
import f from "
|
|
15
|
-
import p from "
|
|
16
|
-
import
|
|
17
|
-
import te from "
|
|
18
|
-
import
|
|
9
|
+
import { createFont as s } from "fonteditor-core";
|
|
10
|
+
import c from "ttf2woff";
|
|
11
|
+
import l from "wawoff2";
|
|
12
|
+
import u from "ttf2eot";
|
|
13
|
+
import d from "fontverter";
|
|
14
|
+
import { createReadStream as f } from "fs";
|
|
15
|
+
import p from "xml2js";
|
|
16
|
+
import m from "p-limit";
|
|
17
|
+
import { SVGIcons2SVGFontStream as ee, fileSorter as te, getMetadataService as ne } from "svgicons2svgfont";
|
|
18
|
+
import re from "crypto";
|
|
19
|
+
import { optimize as h } from "svgo";
|
|
19
20
|
import { Readable as g } from "stream";
|
|
20
21
|
import _ from "svg2ttf";
|
|
21
22
|
//#region \0rolldown/runtime.js
|
|
@@ -28,59 +29,63 @@ var v = Object.create, y = Object.defineProperty, b = Object.getOwnPropertyDescr
|
|
|
28
29
|
}, E = (e, t, n) => (n = e == null ? {} : v(S(e)), T(t || !e || !e.__esModule ? y(n, "default", {
|
|
29
30
|
value: e,
|
|
30
31
|
enumerable: !0
|
|
31
|
-
}) : n, e)),
|
|
32
|
+
}) : n, e)), ie = /^https?:\/\//iu, D = (e) => ie.test(e), O = (e) => {
|
|
32
33
|
if (D(e)) try {
|
|
33
34
|
return i.extname(new URL(e).pathname).toLowerCase();
|
|
34
35
|
} catch {
|
|
35
36
|
return "";
|
|
36
37
|
}
|
|
37
38
|
return i.extname(e).toLowerCase();
|
|
38
|
-
},
|
|
39
|
+
}, ae = async (e) => (await Promise.all(e.map((e) => D(e) ? Promise.resolve([e]) : a(e)))).flat(), oe = 1330926671, se = 1953658213, ce = 65536, k = (e) => {
|
|
39
40
|
if (e.length < 4) throw Error("SFNT buffer is too short to read flavor");
|
|
40
41
|
let t = e.readUInt32BE(0);
|
|
41
|
-
if (t ===
|
|
42
|
-
if (t ===
|
|
42
|
+
if (t === oe) return "otf";
|
|
43
|
+
if (t === se || t === ce) return "ttf";
|
|
43
44
|
throw Error(`Unsupported SFNT flavor 0x${t.toString(16)}`);
|
|
44
|
-
},
|
|
45
|
+
}, le = (e) => Buffer.from(u(e)), A = (e) => le(e), j = (e, t = {}) => s(e, { type: "ttf" }).write({
|
|
46
|
+
type: "svg",
|
|
47
|
+
metadata: t.metadata
|
|
48
|
+
}), M = (e, t = {}) => Buffer.from(c(e, t).buffer), N = async (e) => Buffer.from(await l.compress(e)), P = /* @__PURE__ */ new Set([".woff", ".woff2"]), F = ".svg", I = ".ttf", L = [
|
|
45
49
|
"svg",
|
|
46
50
|
"ttf",
|
|
47
51
|
"eot",
|
|
48
52
|
"woff",
|
|
49
53
|
"woff2"
|
|
50
|
-
],
|
|
54
|
+
], R = (e) => e === F, z = (e) => e === I, B = (e) => P.has(e), V = (e) => R(e) || B(e) || z(e), H = (e) => {
|
|
51
55
|
if (e.length === 0) return "empty";
|
|
52
56
|
let t = e.map((e) => O(e));
|
|
53
|
-
if (!t.every(
|
|
54
|
-
let n = t.some(
|
|
57
|
+
if (!t.every(V)) return "empty";
|
|
58
|
+
let n = t.some(R), r = t.some(B), i = t.some(z);
|
|
55
59
|
return [
|
|
56
60
|
n,
|
|
57
61
|
r,
|
|
58
62
|
i
|
|
59
63
|
].filter(Boolean).length > 1 ? "mixed" : r ? "webfont" : i ? "ttf" : n ? "svg" : "empty";
|
|
60
|
-
},
|
|
64
|
+
}, U = (e) => {
|
|
61
65
|
if (e.includes("otf")) throw Error("OTF output is only supported when converting WOFF/WOFF2 input. Request \"ttf\" for SVG icons, or pass a .woff/.woff2 file.");
|
|
62
|
-
},
|
|
66
|
+
}, W = (e, t) => t === "svg" ? e.filter((e) => O(e) === F) : t === "webfont" ? e.filter((e) => P.has(O(e))) : t === "ttf" ? e.filter((e) => O(e) === I) : [], ue = /* @__PURE__ */ new Set([
|
|
63
67
|
"ttf",
|
|
68
|
+
"svg",
|
|
64
69
|
"eot",
|
|
65
70
|
"woff",
|
|
66
71
|
"woff2"
|
|
67
|
-
]),
|
|
68
|
-
let t = e.filter((e) =>
|
|
69
|
-
if (e.length ===
|
|
70
|
-
if (t.length === 0) throw Error("formats must include at least one of \"ttf\", \"eot\", \"woff\", or \"woff2\" when converting TTF input");
|
|
72
|
+
]), de = (e) => {
|
|
73
|
+
let t = e.filter((e) => ue.has(e));
|
|
74
|
+
if (e.length === L.length && L.every((t) => e.includes(t))) return ["woff", "woff2"];
|
|
75
|
+
if (t.length === 0) throw Error("formats must include at least one of \"svg\", \"ttf\", \"eot\", \"woff\", or \"woff2\" when converting TTF input");
|
|
71
76
|
return [...new Set(t)];
|
|
72
|
-
},
|
|
77
|
+
}, fe = (e) => {
|
|
73
78
|
let t = e.filter((e) => e === "ttf" || e === "otf");
|
|
74
|
-
if (e.length ===
|
|
79
|
+
if (e.length === L.length && L.every((t) => e.includes(t))) return ["ttf"];
|
|
75
80
|
if (t.length === 0) throw Error("formats must include \"ttf\" and/or \"otf\" when converting WOFF/WOFF2 input");
|
|
76
81
|
return [...new Set(t)];
|
|
77
|
-
},
|
|
82
|
+
}, pe = (e) => {
|
|
78
83
|
if (e.length === 0) throw Error("No TTF files matched");
|
|
79
|
-
},
|
|
84
|
+
}, me = (e) => {
|
|
80
85
|
if (e.template) throw Error("Templates are not supported when converting TTF input");
|
|
81
86
|
if (e.glyphTransformFn) throw Error("glyphTransformFn is not supported when converting TTF input");
|
|
82
87
|
if (e.glyphContentTransformFn) throw Error("glyphContentTransformFn is not supported when converting TTF input");
|
|
83
|
-
},
|
|
88
|
+
}, he = (e, t) => {
|
|
84
89
|
let n;
|
|
85
90
|
try {
|
|
86
91
|
n = k(e);
|
|
@@ -88,53 +93,58 @@ var v = Object.create, y = Object.defineProperty, b = Object.getOwnPropertyDescr
|
|
|
88
93
|
throw Error(`Input is not a valid TrueType font: ${t}`);
|
|
89
94
|
}
|
|
90
95
|
if (n !== "ttf") throw Error(`OpenType (OTF) input is not supported for webfont encoding. Use a .ttf file for ${t}.`);
|
|
91
|
-
},
|
|
96
|
+
}, G = (e) => {
|
|
97
|
+
if (typeof e.metadata == "string") return e.metadata;
|
|
98
|
+
}, ge = async (e, t, n, r) => {
|
|
92
99
|
if (n === "ttf") {
|
|
93
100
|
e.ttf = t;
|
|
94
101
|
return;
|
|
95
102
|
}
|
|
103
|
+
if (n === "svg") {
|
|
104
|
+
e.svg = j(t, { metadata: G(r) });
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
96
107
|
if (n === "eot") {
|
|
97
108
|
e.eot = A(t);
|
|
98
109
|
return;
|
|
99
110
|
}
|
|
100
111
|
if (n === "woff") {
|
|
101
|
-
|
|
102
|
-
typeof r.metadata == "string" && (n = r.metadata), e.woff = j(t, { metadata: n });
|
|
112
|
+
e.woff = M(t, { metadata: G(r) });
|
|
103
113
|
return;
|
|
104
114
|
}
|
|
105
|
-
e.woff2 = await
|
|
106
|
-
},
|
|
115
|
+
e.woff2 = await N(t);
|
|
116
|
+
}, _e = async (e, t, n, r) => {
|
|
107
117
|
if (D(e)) throw Error(`Remote TTF URLs are not supported. Download the file first: ${e}`);
|
|
108
118
|
r && console.log(`Encoding ${e}...`);
|
|
109
119
|
let i = await o.readFile(e);
|
|
110
|
-
|
|
120
|
+
he(i, e);
|
|
111
121
|
let a = { source: e };
|
|
112
|
-
return await Promise.all(t.map((e) =>
|
|
113
|
-
},
|
|
114
|
-
|
|
115
|
-
let n =
|
|
122
|
+
return await Promise.all(t.map((e) => ge(a, i, e, n))), a;
|
|
123
|
+
}, ve = async (e, t) => {
|
|
124
|
+
me(t), pe(e);
|
|
125
|
+
let n = de(t.formats), r = await Promise.all(e.map((e) => _e(e, n, t, t.verbose))), i = {
|
|
116
126
|
config: { ...t },
|
|
117
127
|
transcodedFonts: r
|
|
118
128
|
};
|
|
119
129
|
if (r.length === 1) {
|
|
120
130
|
let [e] = r;
|
|
121
|
-
i.ttf = e.ttf, i.eot = e.eot, i.woff = e.woff, i.woff2 = e.woff2;
|
|
131
|
+
i.svg = e.svg, i.ttf = e.ttf, i.eot = e.eot, i.woff = e.woff, i.woff2 = e.woff2;
|
|
122
132
|
}
|
|
123
133
|
return i;
|
|
124
|
-
},
|
|
134
|
+
}, ye = /* @__PURE__ */ w(((e, t) => {
|
|
125
135
|
t.exports = function(e) {
|
|
126
136
|
return !e || e.length < 8 ? !1 : e[0] === 119 && e[1] === 79 && e[2] === 70 && e[3] === 70 && e[4] === 0 && e[5] === 1 && e[6] === 0 && e[7] === 0 || e[4] === 79 && e[5] === 84 && e[6] === 84 && e[7] === 79;
|
|
127
137
|
};
|
|
128
|
-
})),
|
|
138
|
+
})), be = /* @__PURE__ */ w(((e, t) => {
|
|
129
139
|
t.exports = function(e) {
|
|
130
140
|
return !e || e.length < 8 ? !1 : e[0] === 119 && e[1] === 79 && e[2] === 70 && e[3] === 50 && e[4] === 0 && e[5] === 1 && e[6] === 0 && e[7] === 0;
|
|
131
141
|
};
|
|
132
|
-
})),
|
|
142
|
+
})), xe = /* @__PURE__ */ E(ye()), Se = /* @__PURE__ */ E(be()), Ce = (e, t) => {
|
|
133
143
|
let n = O(t);
|
|
134
|
-
if (n === ".woff2" && !(0,
|
|
135
|
-
if (n === ".woff" && !(0,
|
|
144
|
+
if (n === ".woff2" && !(0, Se.default)(e)) throw Error(`URL did not return a valid WOFF2 font: ${t}`);
|
|
145
|
+
if (n === ".woff" && !(0, xe.default)(e)) throw Error(`URL did not return a valid WOFF font: ${t}`);
|
|
136
146
|
if (e.length === 0) throw Error(`URL returned an empty response: ${t}`);
|
|
137
|
-
},
|
|
147
|
+
}, we = async (e) => {
|
|
138
148
|
let t;
|
|
139
149
|
try {
|
|
140
150
|
t = await fetch(e);
|
|
@@ -144,14 +154,14 @@ var v = Object.create, y = Object.defineProperty, b = Object.getOwnPropertyDescr
|
|
|
144
154
|
}
|
|
145
155
|
if (!t.ok) throw Error(`Failed to fetch font URL ${e}: HTTP ${t.status} ${t.statusText}`);
|
|
146
156
|
let n = await t.arrayBuffer(), r = Buffer.from(n);
|
|
147
|
-
return
|
|
148
|
-
},
|
|
157
|
+
return Ce(r, e), r;
|
|
158
|
+
}, Te = (e) => {
|
|
149
159
|
if (e.length === 0) throw Error("No WOFF or WOFF2 files matched");
|
|
150
|
-
},
|
|
160
|
+
}, Ee = (e) => {
|
|
151
161
|
if (e.template) throw Error("Templates are not supported when converting WOFF/WOFF2 input");
|
|
152
162
|
if (e.glyphTransformFn) throw Error("glyphTransformFn is not supported when converting WOFF/WOFF2 input");
|
|
153
163
|
if (e.glyphContentTransformFn) throw Error("glyphContentTransformFn is not supported when converting WOFF/WOFF2 input");
|
|
154
|
-
},
|
|
164
|
+
}, De = (e) => {
|
|
155
165
|
let { decompressed: t, sfnt: n, format: r, flavor: i, source: a } = e;
|
|
156
166
|
if (r === "ttf" && i !== "ttf") throw Error(`Input decompresses to OpenType (OTF). Request "otf" format instead of "ttf" for ${a}.`);
|
|
157
167
|
if (r === "otf" && i !== "otf") throw Error(`Input decompresses to TrueType (TTF). Request "ttf" format instead of "otf" for ${a}.`);
|
|
@@ -160,10 +170,10 @@ var v = Object.create, y = Object.defineProperty, b = Object.getOwnPropertyDescr
|
|
|
160
170
|
return;
|
|
161
171
|
}
|
|
162
172
|
t.otf = n;
|
|
163
|
-
},
|
|
173
|
+
}, Oe = (e) => D(e) ? we(e) : o.readFile(e), ke = async (e, t, n) => {
|
|
164
174
|
n && console.log(`Decompressing ${e}...`);
|
|
165
|
-
let r = await
|
|
166
|
-
for (let n of t)
|
|
175
|
+
let r = await Oe(e), i = Buffer.from(await d.convert(r, "sfnt")), a = k(i), o = { source: e };
|
|
176
|
+
for (let n of t) De({
|
|
167
177
|
decompressed: o,
|
|
168
178
|
sfnt: i,
|
|
169
179
|
format: n,
|
|
@@ -171,24 +181,24 @@ var v = Object.create, y = Object.defineProperty, b = Object.getOwnPropertyDescr
|
|
|
171
181
|
source: e
|
|
172
182
|
});
|
|
173
183
|
return o;
|
|
174
|
-
},
|
|
175
|
-
|
|
176
|
-
let n =
|
|
184
|
+
}, Ae = async (e, t) => {
|
|
185
|
+
Ee(t), Te(e);
|
|
186
|
+
let n = fe(t.formats), r = await Promise.all(e.map((e) => ke(e, n, t.verbose))), i = {
|
|
177
187
|
config: { ...t },
|
|
178
188
|
decompressedFonts: r
|
|
179
189
|
};
|
|
180
190
|
return r.length === 1 && (i.ttf = r[0].ttf, i.otf = r[0].otf), i;
|
|
181
|
-
},
|
|
191
|
+
}, je = m, Me = (e) => ({
|
|
182
192
|
prependUnicode: !!e.prependUnicode,
|
|
183
193
|
startUnicode: Number(e.startUnicode)
|
|
184
|
-
}),
|
|
194
|
+
}), Ne = (e) => {
|
|
185
195
|
if (e == null) return;
|
|
186
196
|
if (typeof e == "number") return Number.isFinite(e) ? e : void 0;
|
|
187
197
|
let t = e.trim();
|
|
188
198
|
if (t.length === 0) return;
|
|
189
199
|
let n = Number(t);
|
|
190
200
|
if (Number.isFinite(n)) return n;
|
|
191
|
-
},
|
|
201
|
+
}, Pe = (e) => ({
|
|
192
202
|
ascent: e.ascent,
|
|
193
203
|
centerHorizontally: e.centerHorizontally,
|
|
194
204
|
centerVertically: e.centerVertically,
|
|
@@ -201,14 +211,14 @@ var v = Object.create, y = Object.defineProperty, b = Object.getOwnPropertyDescr
|
|
|
201
211
|
fontWeight: e.fontWeight,
|
|
202
212
|
metadata: e.metadata,
|
|
203
213
|
normalize: e.normalize,
|
|
204
|
-
round:
|
|
205
|
-
}),
|
|
214
|
+
round: Ne(e.round)
|
|
215
|
+
}), Fe = (e) => e === void 0 ? [] : Array.isArray(e) ? e : [e], Ie = (e) => ({
|
|
206
216
|
name: e.name,
|
|
207
|
-
unicode:
|
|
208
|
-
}),
|
|
209
|
-
let n = t.metadataProvider ||
|
|
217
|
+
unicode: Fe(e.unicode)
|
|
218
|
+
}), Le = (e, t) => {
|
|
219
|
+
let n = t.metadataProvider || ne(Me(t)), r = new p.Parser(), i = je(t.maxConcurrency);
|
|
210
220
|
return Promise.all(e.map((e) => i(() => new Promise((t, n) => {
|
|
211
|
-
let i =
|
|
221
|
+
let i = f(e), a = "";
|
|
212
222
|
i.on("error", (e) => n(e)).on("data", (e) => {
|
|
213
223
|
a += e.toString();
|
|
214
224
|
}).on("end", () => a.length === 0 ? n(/* @__PURE__ */ Error(`Empty file ${e}`)) : r.parseString(a, (r) => r ? n(r) : t({
|
|
@@ -217,18 +227,18 @@ var v = Object.create, y = Object.defineProperty, b = Object.getOwnPropertyDescr
|
|
|
217
227
|
})));
|
|
218
228
|
})))).then((e) => {
|
|
219
229
|
let r = e;
|
|
220
|
-
t.sort && (r = e.sort((e, t) =>
|
|
230
|
+
t.sort && (r = e.sort((e, t) => te(e.srcPath, t.srcPath)));
|
|
221
231
|
let { ligatures: i } = t;
|
|
222
232
|
return Promise.all(r.map((e) => new Promise((t, r) => {
|
|
223
233
|
n(e.srcPath, (n, a) => {
|
|
224
234
|
if (n) return r(n);
|
|
225
235
|
if (!a) return r(/* @__PURE__ */ Error(`Missing metadata for ${e.srcPath}`));
|
|
226
|
-
let o =
|
|
236
|
+
let o = Ie(a);
|
|
227
237
|
return i && o.unicode.push(a.name.replace(/-/gu, "_")), e.metadata = o, t(e);
|
|
228
238
|
});
|
|
229
239
|
})));
|
|
230
240
|
});
|
|
231
|
-
},
|
|
241
|
+
}, Re = () => ({
|
|
232
242
|
centerHorizontally: !1,
|
|
233
243
|
centerVertically: !1,
|
|
234
244
|
descent: 0,
|
|
@@ -261,13 +271,13 @@ var v = Object.create, y = Object.defineProperty, b = Object.getOwnPropertyDescr
|
|
|
261
271
|
templateFontPath: "./",
|
|
262
272
|
unicodeRange: !1,
|
|
263
273
|
verbose: !1
|
|
264
|
-
}),
|
|
274
|
+
}), ze = (e) => {
|
|
265
275
|
if (!e?.files) throw Error("You must pass webfont a `files` glob");
|
|
266
276
|
return {
|
|
267
|
-
...
|
|
277
|
+
...Re(),
|
|
268
278
|
...e
|
|
269
279
|
};
|
|
270
|
-
},
|
|
280
|
+
}, Be = () => ({
|
|
271
281
|
multipass: !1,
|
|
272
282
|
plugins: [
|
|
273
283
|
"removeDoctype",
|
|
@@ -279,44 +289,44 @@ var v = Object.create, y = Object.defineProperty, b = Object.getOwnPropertyDescr
|
|
|
279
289
|
"cleanupAttrs",
|
|
280
290
|
"removeUnusedNS"
|
|
281
291
|
]
|
|
282
|
-
}),
|
|
283
|
-
let t =
|
|
292
|
+
}), Ve = (e) => {
|
|
293
|
+
let t = Be();
|
|
284
294
|
return e ? {
|
|
285
295
|
...t,
|
|
286
296
|
...e,
|
|
287
297
|
plugins: e.plugins ?? t.plugins
|
|
288
298
|
} : t;
|
|
289
|
-
},
|
|
290
|
-
...
|
|
299
|
+
}, He = (e, t, n) => h(e, {
|
|
300
|
+
...Ve(n),
|
|
291
301
|
path: t
|
|
292
|
-
}).data,
|
|
302
|
+
}).data, Ue = (e, t) => e.map((e) => ({
|
|
293
303
|
...e,
|
|
294
|
-
contents:
|
|
295
|
-
})),
|
|
304
|
+
contents: He(e.contents, e.srcPath, t)
|
|
305
|
+
})), We = (e, t) => t && e > 2e3, Ge = (e) => `Warning: ${e} glyphs with ligatures enabled may cause severe browser slowdown or hangs (especially Firefox on Windows). Ligatures are off by default; enable only if needed: --ligatures or ligatures: true. See TROUBLESHOOTING.md and https://github.com/itgalaxy/webfont/issues/558`, Ke = /<glyph\b([^>/]*)(?:\/>|>)/giu, qe = /\bglyph-name=["']([^"']+)["']/iu, Je = /\bd=["']([^"']*)["']/iu, Ye = (e) => {
|
|
296
306
|
let t = [];
|
|
297
|
-
for (let n of e.matchAll(
|
|
298
|
-
let e = n[1] ?? "", r =
|
|
299
|
-
r && (
|
|
307
|
+
for (let n of e.matchAll(Ke)) {
|
|
308
|
+
let e = n[1] ?? "", r = qe.exec(e);
|
|
309
|
+
r && (Je.exec(e)?.[1] ?? "").trim().length === 0 && t.push(r[1]);
|
|
300
310
|
}
|
|
301
311
|
return t;
|
|
302
|
-
},
|
|
312
|
+
}, Xe = (e, t) => {
|
|
303
313
|
for (let n of t) {
|
|
304
314
|
let t = n.metadata?.name;
|
|
305
315
|
if (t && (e === t || e.startsWith(`${t}-`))) return n.srcPath;
|
|
306
316
|
}
|
|
307
|
-
},
|
|
317
|
+
}, Ze = (e, t) => {
|
|
308
318
|
let n = /* @__PURE__ */ new Set(), r = [];
|
|
309
319
|
for (let i of e) {
|
|
310
|
-
let e =
|
|
320
|
+
let e = Xe(i, t), a = e ?? i;
|
|
311
321
|
n.has(a) || (n.add(a), e ? r.push(`${i} (${e})`) : r.push(i));
|
|
312
322
|
}
|
|
313
323
|
return r.join("; ");
|
|
314
|
-
},
|
|
315
|
-
let n =
|
|
324
|
+
}, Qe = (e, t) => {
|
|
325
|
+
let n = Ye(e);
|
|
316
326
|
if (n.length === 0) return;
|
|
317
|
-
let r =
|
|
327
|
+
let r = Ze(n, t);
|
|
318
328
|
throw Error(`Empty glyph path(s) in SVG font output for: ${r}. Stroke-only SVGs (fill="none" with stroke) often produce empty glyphs because svgicons2svgfont does not convert strokes. Convert strokes to filled paths in your design tool, preprocess with glyphContentTransformFn (for example svg-outline-stroke), or run with --svg-diagnose for compatibility warnings. See TROUBLESHOOTING.md ("Stroke-only SVGs produce blank icons").`);
|
|
319
|
-
},
|
|
329
|
+
}, $e = /fill-rule\s*:\s*evenodd|fill-rule\s*=\s*["']evenodd["']/iu, et = (e) => $e.test(e), tt = /\bstroke\s*=|\bstroke\s*:/iu, nt = /fill\s*=\s*["']none["']|fill\s*:\s*none/iu, rt = /<(line|polyline|clipPath)\b/iu, it = /<use\b/iu, at = (e) => tt.test(e) ? nt.test(e) : !1, ot = (e) => rt.test(e), st = (e) => it.test(e), K = (e, t) => {
|
|
320
330
|
switch (e) {
|
|
321
331
|
case "evenodd-fill-rule": return `[webfont:diagnose] ${t} uses fill-rule: evenodd. Icon fonts render glyphs with the nonzero fill rule, so holes and counter-shapes can disappear. See TROUBLESHOOTING.md ("Icon details missing after export").`;
|
|
322
332
|
case "stroke-only": return `[webfont:diagnose] ${t} uses stroke-based paths (fill="none"). svgicons2svgfont ignores stroke; outlines may render as solid shapes or lose detail. Preprocess with glyphContentTransformFn (for example svg-outline-stroke) before conversion. See TROUBLESHOOTING.md ("Icon details missing after export").`;
|
|
@@ -326,30 +336,30 @@ var v = Object.create, y = Object.defineProperty, b = Object.getOwnPropertyDescr
|
|
|
326
336
|
}
|
|
327
337
|
}, q = (e, t) => {
|
|
328
338
|
let n = [];
|
|
329
|
-
return
|
|
339
|
+
return et(t) && n.push({
|
|
330
340
|
code: "evenodd-fill-rule",
|
|
331
341
|
message: K("evenodd-fill-rule", e),
|
|
332
342
|
srcPath: e
|
|
333
|
-
}),
|
|
343
|
+
}), at(t) && n.push({
|
|
334
344
|
code: "stroke-only",
|
|
335
345
|
message: K("stroke-only", e),
|
|
336
346
|
srcPath: e
|
|
337
|
-
}),
|
|
347
|
+
}), ot(t) && n.push({
|
|
338
348
|
code: "unsupported-element",
|
|
339
349
|
message: K("unsupported-element", e),
|
|
340
350
|
srcPath: e
|
|
341
|
-
}),
|
|
351
|
+
}), st(t) && n.push({
|
|
342
352
|
code: "use-reference",
|
|
343
353
|
message: K("use-reference", e),
|
|
344
354
|
srcPath: e
|
|
345
355
|
}), n;
|
|
346
|
-
}, J = (e) => e.flatMap((e) => q(e.srcPath, e.contents)),
|
|
356
|
+
}, J = (e) => e.flatMap((e) => q(e.srcPath, e.contents)), ct = (e, t) => t.diagnose ? !0 : !!(t.verbose && e.code === "evenodd-fill-rule"), lt = (e) => {
|
|
347
357
|
if (!e || !e.diagnose) return;
|
|
348
358
|
let t = { diagnose: !0 };
|
|
349
359
|
return e.onMessage && (t.onMessage = e.onMessage), t;
|
|
350
|
-
},
|
|
351
|
-
let r =
|
|
352
|
-
for (let e of i)
|
|
360
|
+
}, ut = (e, t, n = {}) => {
|
|
361
|
+
let r = lt(t), i = J(e), { reporter: a, verbose: o = !1 } = n;
|
|
362
|
+
for (let e of i) ct(e, {
|
|
353
363
|
diagnose: r?.diagnose,
|
|
354
364
|
verbose: o
|
|
355
365
|
}) && a?.(e.message);
|
|
@@ -358,17 +368,17 @@ var v = Object.create, y = Object.defineProperty, b = Object.getOwnPropertyDescr
|
|
|
358
368
|
diagnostics: s,
|
|
359
369
|
glyphs: e
|
|
360
370
|
};
|
|
361
|
-
},
|
|
362
|
-
let { diagnostics: r, glyphs: i } =
|
|
371
|
+
}, dt = (e, t, n = {}) => {
|
|
372
|
+
let { diagnostics: r, glyphs: i } = ut(e, t, n);
|
|
363
373
|
return {
|
|
364
374
|
diagnostics: r,
|
|
365
375
|
glyphs: i
|
|
366
376
|
};
|
|
367
|
-
},
|
|
377
|
+
}, ft = (e, t) => {
|
|
368
378
|
let n = "";
|
|
369
379
|
return new Promise((r, i) => {
|
|
370
380
|
t.verbose && console.log("Generating SVG font...");
|
|
371
|
-
let a = new
|
|
381
|
+
let a = new ee(Pe(t)).on("finish", () => r(n)).on("data", (e) => {
|
|
372
382
|
n += e;
|
|
373
383
|
}).on("error", (e) => i(e));
|
|
374
384
|
e.forEach((e) => {
|
|
@@ -379,7 +389,7 @@ var v = Object.create, y = Object.defineProperty, b = Object.getOwnPropertyDescr
|
|
|
379
389
|
}, a.write(t);
|
|
380
390
|
}), a.end();
|
|
381
391
|
});
|
|
382
|
-
},
|
|
392
|
+
}, pt = (e, t = {}) => Buffer.from(_(e, t).buffer), mt = (e) => A(e), ht = (e, t) => M(e, t), gt = (e) => N(e), _t = async (e, t) => {
|
|
383
393
|
let n = (e) => {
|
|
384
394
|
if (t.svgTools?.onMessage) {
|
|
385
395
|
t.svgTools.onMessage(e);
|
|
@@ -388,11 +398,11 @@ var v = Object.create, y = Object.defineProperty, b = Object.getOwnPropertyDescr
|
|
|
388
398
|
(t.svgTools?.diagnose || t.verbose) && console.log(e);
|
|
389
399
|
}, r = !!(t.svgTools?.onMessage || t.svgTools?.diagnose || t.verbose), i;
|
|
390
400
|
r && (i = n);
|
|
391
|
-
let { diagnostics: a, glyphs: o } =
|
|
401
|
+
let { diagnostics: a, glyphs: o } = dt(e, t.svgTools, {
|
|
392
402
|
reporter: i,
|
|
393
403
|
verbose: t.verbose
|
|
394
404
|
}), s = o;
|
|
395
|
-
if (t.optimizeSvg && (s =
|
|
405
|
+
if (t.optimizeSvg && (s = Ue(s, t.svgoConfig)), t.glyphContentTransformFn) {
|
|
396
406
|
let e = t.glyphContentTransformFn;
|
|
397
407
|
s = await Promise.all(s.map(async (t) => {
|
|
398
408
|
let n = await e(t);
|
|
@@ -415,12 +425,12 @@ var v = Object.create, y = Object.defineProperty, b = Object.getOwnPropertyDescr
|
|
|
415
425
|
};
|
|
416
426
|
}));
|
|
417
427
|
}
|
|
418
|
-
|
|
428
|
+
We(s.length, t.ligatures) && console.log(Ge(s.length));
|
|
419
429
|
let c = {};
|
|
420
430
|
t.formatsOptions?.ttf && (c = t.formatsOptions.ttf);
|
|
421
|
-
let l = await
|
|
422
|
-
|
|
423
|
-
let u =
|
|
431
|
+
let l = await ft(s, t);
|
|
432
|
+
Qe(l, s);
|
|
433
|
+
let u = pt(l, c);
|
|
424
434
|
if (t.ttfPostProcess) {
|
|
425
435
|
let e = await t.ttfPostProcess(u, {
|
|
426
436
|
fontName: t.fontName,
|
|
@@ -431,17 +441,17 @@ var v = Object.create, y = Object.defineProperty, b = Object.getOwnPropertyDescr
|
|
|
431
441
|
let d = {
|
|
432
442
|
config: t,
|
|
433
443
|
glyphsData: s,
|
|
434
|
-
hash:
|
|
444
|
+
hash: re.createHash("md5").update(l).digest("hex"),
|
|
435
445
|
svg: l,
|
|
436
446
|
ttf: u
|
|
437
447
|
};
|
|
438
448
|
a.length > 0 && (d.svgDiagnostics = a);
|
|
439
449
|
let { formats: f } = t;
|
|
440
|
-
if (f.includes("eot") && (d.eot =
|
|
450
|
+
if (f.includes("eot") && (d.eot = mt(u)), f.includes("woff")) {
|
|
441
451
|
let e;
|
|
442
|
-
typeof t.metadata == "string" && (e = t.metadata), d.woff =
|
|
452
|
+
typeof t.metadata == "string" && (e = t.metadata), d.woff = ht(u, { metadata: e });
|
|
443
453
|
}
|
|
444
|
-
if (f.includes("woff2") && (d.woff2 = Buffer.from(await
|
|
454
|
+
if (f.includes("woff2") && (d.woff2 = Buffer.from(await gt(u))), t.template) {
|
|
445
455
|
let { renderTemplates: e } = await import("./renderTemplates-Biyrk6t-.mjs"), { templates: n, usedBuildInTemplate: r } = e(t, d, f);
|
|
446
456
|
n.length > 0 && (d.templates = n, d.template = n[0]?.content, d.usedBuildInTemplate = r);
|
|
447
457
|
}
|
|
@@ -453,24 +463,24 @@ var v = Object.create, y = Object.defineProperty, b = Object.getOwnPropertyDescr
|
|
|
453
463
|
"ttf",
|
|
454
464
|
"woff",
|
|
455
465
|
"woff2"
|
|
456
|
-
]),
|
|
457
|
-
if (typeof e != "string" || !Y.has(e)) throw Error(`Invalid format "${String(e)}". Expected one of: ${
|
|
466
|
+
]), vt = [...Y].join(", "), yt = (e) => {
|
|
467
|
+
if (typeof e != "string" || !Y.has(e)) throw Error(`Invalid format "${String(e)}". Expected one of: ${vt}`);
|
|
458
468
|
return e;
|
|
459
|
-
},
|
|
469
|
+
}, bt = (e) => {
|
|
460
470
|
if (e.length === 0) throw Error("formats must not be empty");
|
|
461
|
-
return e.map(
|
|
462
|
-
},
|
|
471
|
+
return e.map(yt);
|
|
472
|
+
}, xt = (e) => {
|
|
463
473
|
if (!Array.isArray(e)) throw Error("formats must be an array of format names (e.g. [\"woff2\", \"svg\"])");
|
|
464
|
-
return
|
|
465
|
-
},
|
|
474
|
+
return bt(e);
|
|
475
|
+
}, X = (e, t) => {
|
|
466
476
|
if (t !== void 0 && typeof t != "string") throw Error(`${e} must be a string`);
|
|
467
|
-
},
|
|
477
|
+
}, Z = (e, t) => {
|
|
468
478
|
if (t !== void 0 && typeof t != "boolean" && typeof t != "string") throw Error(`${e} must be a boolean or string`);
|
|
469
479
|
}, Q = (e, t) => {
|
|
470
480
|
if (t !== void 0 && typeof t != "boolean") throw Error(`${e} must be a boolean`);
|
|
471
|
-
},
|
|
481
|
+
}, St = (e, t) => {
|
|
472
482
|
if (t !== void 0 && (typeof t != "object" || !t || Array.isArray(t))) throw Error(`${e} must be an object`);
|
|
473
|
-
},
|
|
483
|
+
}, Ct = (e) => {
|
|
474
484
|
if (typeof e == "string") {
|
|
475
485
|
if (e.length === 0) throw Error("files must not be empty");
|
|
476
486
|
return;
|
|
@@ -481,7 +491,7 @@ var v = Object.create, y = Object.defineProperty, b = Object.getOwnPropertyDescr
|
|
|
481
491
|
return;
|
|
482
492
|
}
|
|
483
493
|
throw Error("files must be a string or an array of strings");
|
|
484
|
-
},
|
|
494
|
+
}, wt = (e) => (Ct(e.files), e.formats = xt(e.formats), X("fontName", e.fontName), Z("unicodeRange", e.unicodeRange), Q("optimizeSvg", e.optimizeSvg), St("svgoConfig", e.svgoConfig), Q("templateFontLigatures", e.templateFontLigatures), e.template !== void 0 && t(e.template), X("templateFontPath", e.templateFontPath), e), Tt = (e) => "filepath" in e, Et = async (e) => {
|
|
485
495
|
let t = n("webfont", { searchStrategy: "global" });
|
|
486
496
|
if (e.configFile) {
|
|
487
497
|
let n = i.resolve(process.cwd(), e.configFile);
|
|
@@ -489,35 +499,35 @@ var v = Object.create, y = Object.defineProperty, b = Object.getOwnPropertyDescr
|
|
|
489
499
|
}
|
|
490
500
|
return await t.search(process.cwd()) ?? {};
|
|
491
501
|
}, $ = async (e) => {
|
|
492
|
-
let t =
|
|
502
|
+
let t = ze(e);
|
|
493
503
|
delete t.filePath;
|
|
494
|
-
let n = await
|
|
495
|
-
|
|
504
|
+
let n = await Et({ configFile: t.configFile }), i;
|
|
505
|
+
Tt(n) && (t = r(t, n.config, { arrayMerge: (e, t) => t }), i = n.filepath), t = wt(t);
|
|
496
506
|
let a;
|
|
497
507
|
a = Array.isArray(t.files) ? t.files : [t.files];
|
|
498
|
-
let o = await
|
|
508
|
+
let o = await ae(a), s = H(o);
|
|
499
509
|
if (s === "mixed") throw Error("Cannot mix SVG icons, TTF fonts, and WOFF/WOFF2 files in the same run");
|
|
500
510
|
if (s === "empty") throw Error("Files glob patterns specified did not match any supported files");
|
|
501
511
|
if (s === "webfont") {
|
|
502
|
-
let e = await
|
|
512
|
+
let e = await Ae(W(o, s), t);
|
|
503
513
|
return i && (e.config = {
|
|
504
514
|
...t,
|
|
505
515
|
filePath: i
|
|
506
516
|
}), e;
|
|
507
517
|
}
|
|
508
518
|
if (s === "ttf") {
|
|
509
|
-
let e = await
|
|
519
|
+
let e = await ve(W(o, s), t);
|
|
510
520
|
return i && (e.config = {
|
|
511
521
|
...t,
|
|
512
522
|
filePath: i
|
|
513
523
|
}), e;
|
|
514
524
|
}
|
|
515
|
-
|
|
516
|
-
let c = await
|
|
525
|
+
U(t.formats);
|
|
526
|
+
let c = await _t(await Le(W(o, "svg"), t), t);
|
|
517
527
|
return i ? c.config = {
|
|
518
528
|
...t,
|
|
519
529
|
filePath: i
|
|
520
530
|
} : c.config = t, c;
|
|
521
|
-
},
|
|
531
|
+
}, Dt = $;
|
|
522
532
|
//#endregion
|
|
523
|
-
export {
|
|
533
|
+
export { Dt as default, J as diagnoseGlyphsData, q as diagnoseSvgContents, $ as webfont };
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export declare const encodeTtfToEot: (buffer: Buffer) => Buffer;
|
|
2
|
+
export declare const encodeTtfToSvg: (buffer: Buffer, options?: {
|
|
3
|
+
metadata?: string;
|
|
4
|
+
}) => string;
|
|
2
5
|
export declare const encodeTtfToWoff: (buffer: Buffer, options?: {
|
|
3
6
|
metadata?: string;
|
|
4
7
|
}) => Buffer;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export declare const encodeTtfToEot: (buffer: Buffer) => Buffer;
|
|
2
|
+
export declare const encodeTtfToSvg: (buffer: Buffer, options?: {
|
|
3
|
+
metadata?: string;
|
|
4
|
+
}) => string;
|
|
2
5
|
export declare const encodeTtfToWoff: (buffer: Buffer, options?: {
|
|
3
6
|
metadata?: string;
|
|
4
7
|
}) => Buffer;
|
|
@@ -4,6 +4,6 @@ export declare const classifyInputFiles: (filePaths: readonly string[]) => Input
|
|
|
4
4
|
export declare const assertSvgPipelineFormats: (formats: readonly Format[]) => void;
|
|
5
5
|
export declare const filterInputFilesByMode: (filePaths: readonly string[], mode: InputMode) => string[];
|
|
6
6
|
export type ConversionFormat = "otf" | "ttf";
|
|
7
|
-
export type TtfEncodeFormat = "eot" | "ttf" | "woff" | "woff2";
|
|
7
|
+
export type TtfEncodeFormat = "eot" | "svg" | "ttf" | "woff" | "woff2";
|
|
8
8
|
export declare const resolveTtfConversionFormats: (formats: readonly Format[]) => TtfEncodeFormat[];
|
|
9
9
|
export declare const resolveWebfontConversionFormats: (formats: readonly Format[]) => ConversionFormat[];
|
|
@@ -4,6 +4,6 @@ export declare const classifyInputFiles: (filePaths: readonly string[]) => Input
|
|
|
4
4
|
export declare const assertSvgPipelineFormats: (formats: readonly Format[]) => void;
|
|
5
5
|
export declare const filterInputFilesByMode: (filePaths: readonly string[], mode: InputMode) => string[];
|
|
6
6
|
export type ConversionFormat = "otf" | "ttf";
|
|
7
|
-
export type TtfEncodeFormat = "eot" | "ttf" | "woff" | "woff2";
|
|
7
|
+
export type TtfEncodeFormat = "eot" | "svg" | "ttf" | "woff" | "woff2";
|
|
8
8
|
export declare const resolveTtfConversionFormats: (formats: readonly Format[]) => TtfEncodeFormat[];
|
|
9
9
|
export declare const resolveWebfontConversionFormats: (formats: readonly Format[]) => ConversionFormat[];
|