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.
- package/NOTICE.md +165 -0
- package/README.md +302 -34
- package/dist/browser.js +4 -0
- package/dist/cli.mjs +893 -0
- package/dist/index.js +1 -507
- package/dist/parseTemplateOption-5T7rSw5J.mjs +20 -0
- package/dist/parseTemplateOption-BmH_pcQh.js +1 -0
- package/dist/renderTemplates-DvRlS58E.mjs +93 -0
- package/dist/renderTemplates-zCYCzeOt.js +1 -0
- package/dist/src/browser.d.ts +2 -0
- package/dist/src/index.d.ts +4 -2
- package/dist/src/lib/applyOptimizeSvgToGlyphs.d.ts +3 -0
- package/dist/src/lib/evenoddFillRule.d.ts +2 -0
- package/dist/src/lib/execCLI/index.d.ts +3 -4
- package/dist/src/lib/inputSource.d.ts +2 -0
- package/dist/src/lib/inputSourceUtils.d.ts +4 -0
- package/dist/src/lib/largeFontLigatures.d.ts +4 -0
- package/dist/src/lib/optimizeSvgGlyphs.d.ts +4 -0
- package/dist/src/lib/p-limit/index.d.ts +2 -0
- package/dist/src/lib/parseFormats.d.ts +4 -0
- package/dist/src/lib/parseTemplateOption.d.ts +2 -0
- package/dist/src/lib/runtimeEnvironment.d.ts +4 -0
- package/dist/src/lib/sfnt/flavor.d.ts +2 -0
- package/dist/src/lib/svgDiagnostics/diagnoseSvgContents.d.ts +12 -0
- package/dist/src/lib/svgFontOutput/emptyGlyphPaths.d.ts +3 -0
- package/dist/src/lib/svgTools/applySvgDiagnostics.d.ts +13 -0
- package/dist/src/lib/svgTools/applySvgTools.d.ts +14 -0
- package/dist/src/lib/svgTools/normalizeSvgToolsOptions.d.ts +2 -0
- package/dist/src/lib/svgicons2svgfont/index.d.ts +14 -0
- package/dist/src/lib/svgicons2svgfont/metadataFromSrcPath.d.ts +11 -0
- package/dist/src/lib/templateUnicodeRange.d.ts +4 -0
- package/dist/src/lib/ttf2eot/index.d.ts +2 -0
- package/dist/src/lib/ttfEncode.d.ts +5 -0
- package/dist/src/standalone/convertTtfInput.d.ts +3 -0
- package/dist/src/standalone/convertWebfontInput.d.ts +3 -0
- package/dist/src/standalone/defaultOptions.d.ts +3 -0
- package/dist/src/standalone/fetchWebfontUrl.d.ts +1 -0
- package/dist/src/standalone/generateSvgFont.d.ts +2 -0
- package/dist/src/standalone/getGlyphsDataFromInputs.d.ts +3 -0
- package/dist/src/standalone/glyphsData.d.ts +2 -2
- package/dist/src/standalone/index.d.ts +8 -3
- package/dist/src/standalone/inputMode.d.ts +9 -0
- package/dist/src/standalone/options.d.ts +3 -3
- package/dist/src/standalone/optionsFromGlyphs.d.ts +3 -0
- package/dist/src/standalone/renderTemplates.d.ts +10 -0
- package/dist/src/standalone/runSvgPipeline.d.ts +3 -0
- package/dist/src/standalone/templateFonts.d.ts +3 -0
- package/dist/src/standalone/toTtf.d.ts +4 -0
- package/dist/src/standalone/validateWebfontOptions.d.ts +6 -0
- package/dist/src/standalone/webfontFromGlyphs.d.ts +3 -0
- package/dist/src/types/DecompressedFont.d.ts +5 -0
- package/dist/src/types/Format.d.ts +4 -4
- package/dist/src/types/GlyphContentTransformFn.d.ts +2 -0
- package/dist/src/types/GlyphData.d.ts +2 -2
- package/dist/src/types/GlyphInput.d.ts +6 -0
- package/dist/src/types/GlyphMetadata.d.ts +1 -1
- package/dist/src/types/GlyphTransformFn.d.ts +2 -2
- package/dist/src/types/InitialOptions.d.ts +7 -4
- package/dist/src/types/MetadataProvider.d.ts +5 -0
- package/dist/src/types/OptionsBase.d.ts +12 -3
- package/dist/src/types/RenderedTemplate.d.ts +7 -0
- package/dist/src/types/Result.d.ts +16 -5
- package/dist/src/types/ResultConfig.d.ts +4 -0
- package/dist/src/types/SvgToolsOptions.d.ts +13 -0
- package/dist/src/types/TranscodedFont.d.ts +7 -0
- package/dist/src/types/WebfontFromGlyphsOptions.d.ts +11 -0
- package/dist/src/types/WebfontOptions.d.ts +39 -3
- package/dist/src/types/index.d.ts +8 -6
- package/package.json +65 -57
- package/templates/template.css.njk +6 -3
- package/templates/template.html.njk +15 -4
- package/templates/template.scss.njk +6 -3
- package/templates/template.styl.njk +6 -3
- package/dist/cli.js +0 -801
- package/dist/jest.config.d.ts +0 -3
- package/dist/src/cli/index.d.ts +0 -1
- package/dist/src/cli/index.test.d.ts +0 -1
- package/dist/src/cli/meow/index.d.ts +0 -104
- package/dist/src/index.test.d.ts +0 -1
- package/dist/src/standalone/index.test.d.ts +0 -1
package/dist/index.js
CHANGED
|
@@ -1,507 +1 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var path$1 = require('path');
|
|
6
|
-
var stream = require('stream');
|
|
7
|
-
var SVGIcons2SVGFontStream = require('svgicons2svgfont');
|
|
8
|
-
var cosmiconfig = require('cosmiconfig');
|
|
9
|
-
var crypto = require('crypto');
|
|
10
|
-
var deepmerge = require('deepmerge');
|
|
11
|
-
var require$$1 = require('fs');
|
|
12
|
-
var pLimit = require('p-limit');
|
|
13
|
-
var xml2js = require('xml2js');
|
|
14
|
-
var globby = require('globby');
|
|
15
|
-
var nunjucks = require('nunjucks');
|
|
16
|
-
var svg2ttf = require('svg2ttf');
|
|
17
|
-
var ttf2eot = require('ttf2eot');
|
|
18
|
-
var ttf2woff = require('ttf2woff');
|
|
19
|
-
var wawoff2 = require('wawoff2');
|
|
20
|
-
|
|
21
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
22
|
-
|
|
23
|
-
var path__default = /*#__PURE__*/_interopDefaultLegacy(path$1);
|
|
24
|
-
var SVGIcons2SVGFontStream__default = /*#__PURE__*/_interopDefaultLegacy(SVGIcons2SVGFontStream);
|
|
25
|
-
var cosmiconfig__default = /*#__PURE__*/_interopDefaultLegacy(cosmiconfig);
|
|
26
|
-
var crypto__default = /*#__PURE__*/_interopDefaultLegacy(crypto);
|
|
27
|
-
var deepmerge__default = /*#__PURE__*/_interopDefaultLegacy(deepmerge);
|
|
28
|
-
var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
|
|
29
|
-
var pLimit__default = /*#__PURE__*/_interopDefaultLegacy(pLimit);
|
|
30
|
-
var xml2js__default = /*#__PURE__*/_interopDefaultLegacy(xml2js);
|
|
31
|
-
var globby__default = /*#__PURE__*/_interopDefaultLegacy(globby);
|
|
32
|
-
var nunjucks__default = /*#__PURE__*/_interopDefaultLegacy(nunjucks);
|
|
33
|
-
var svg2ttf__default = /*#__PURE__*/_interopDefaultLegacy(svg2ttf);
|
|
34
|
-
var ttf2eot__default = /*#__PURE__*/_interopDefaultLegacy(ttf2eot);
|
|
35
|
-
var ttf2woff__default = /*#__PURE__*/_interopDefaultLegacy(ttf2woff);
|
|
36
|
-
var wawoff2__default = /*#__PURE__*/_interopDefaultLegacy(wawoff2);
|
|
37
|
-
|
|
38
|
-
/*! *****************************************************************************
|
|
39
|
-
Copyright (c) Microsoft Corporation.
|
|
40
|
-
|
|
41
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
42
|
-
purpose with or without fee is hereby granted.
|
|
43
|
-
|
|
44
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
45
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
46
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
47
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
48
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
49
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
50
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
51
|
-
***************************************************************************** */
|
|
52
|
-
|
|
53
|
-
var __assign = function() {
|
|
54
|
-
__assign = Object.assign || function __assign(t) {
|
|
55
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
56
|
-
s = arguments[i];
|
|
57
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
58
|
-
}
|
|
59
|
-
return t;
|
|
60
|
-
};
|
|
61
|
-
return __assign.apply(this, arguments);
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
65
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
66
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
67
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
68
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
69
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
70
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function __generator(thisArg, body) {
|
|
75
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
76
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
77
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
78
|
-
function step(op) {
|
|
79
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
80
|
-
while (_) try {
|
|
81
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
82
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
83
|
-
switch (op[0]) {
|
|
84
|
-
case 0: case 1: t = op; break;
|
|
85
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
86
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
87
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
88
|
-
default:
|
|
89
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
90
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
91
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
92
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
93
|
-
if (t[2]) _.ops.pop();
|
|
94
|
-
_.trys.pop(); continue;
|
|
95
|
-
}
|
|
96
|
-
op = body.call(thisArg, _);
|
|
97
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
98
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
var getTemplateDirectory = function () { return path__default['default'].resolve(__dirname, "../templates"); };
|
|
103
|
-
var getTemplateFilePath = function (template) {
|
|
104
|
-
var templateDirectory = getTemplateDirectory();
|
|
105
|
-
return templateDirectory + "/template." + template + ".njk";
|
|
106
|
-
};
|
|
107
|
-
var getBuiltInTemplates = function () {
|
|
108
|
-
var templateDirectory = getTemplateDirectory();
|
|
109
|
-
return {
|
|
110
|
-
css: { path: path__default['default'].join(templateDirectory, "template.css.njk") },
|
|
111
|
-
html: { path: path__default['default'].join(templateDirectory, "template.html.njk") },
|
|
112
|
-
json: { path: path__default['default'].join(templateDirectory, "template.json.njk") },
|
|
113
|
-
scss: { path: path__default['default'].join(templateDirectory, "template.scss.njk") },
|
|
114
|
-
styl: { path: path__default['default'].join(templateDirectory, "template.styl.njk") }
|
|
115
|
-
};
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
/* eslint-disable complexity */
|
|
119
|
-
|
|
120
|
-
const testExpression = /(^|\/|\\)(?:((?:u[0-9a-f]{4,6},?)+)-)(.+)\.svg$/i;
|
|
121
|
-
|
|
122
|
-
function fileSorter(fileA, fileB) {
|
|
123
|
-
const hasUnicodeA = testExpression.test(fileA);
|
|
124
|
-
const hasUnicodeB = testExpression.test(fileB);
|
|
125
|
-
|
|
126
|
-
if (hasUnicodeA == hasUnicodeB) {
|
|
127
|
-
// just compare alphabetically
|
|
128
|
-
const fileA_ = fileA.substr(0, fileA.lastIndexOf('.'));
|
|
129
|
-
const fileB_ = fileB.substr(0, fileB.lastIndexOf('.'));
|
|
130
|
-
return fileA_ < fileB_ ? -1 : 1;
|
|
131
|
-
} else {
|
|
132
|
-
// map true to 0, because we want it to be first
|
|
133
|
-
return (hasUnicodeA ? 0 : 1) - (hasUnicodeB ? 0 : 1);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
var filesorter = fileSorter;
|
|
138
|
-
|
|
139
|
-
/* eslint-disable prefer-template,newline-per-chained-call,complexity */
|
|
140
|
-
|
|
141
|
-
const path = path__default['default'];
|
|
142
|
-
const fs = require$$1__default['default'];
|
|
143
|
-
|
|
144
|
-
function getMetadataService(options = {}) {
|
|
145
|
-
let usedUnicodes = [];
|
|
146
|
-
|
|
147
|
-
// Default options
|
|
148
|
-
options.prependUnicode = !!options.prependUnicode;
|
|
149
|
-
options.startUnicode =
|
|
150
|
-
'number' === typeof options.startUnicode ? options.startUnicode : 0xea01;
|
|
151
|
-
options.log = options.log || console.log; // eslint-disable-line
|
|
152
|
-
options.err = options.err || console.err; // eslint-disable-line
|
|
153
|
-
|
|
154
|
-
// Throw on old options usage
|
|
155
|
-
if ('undefined' !== typeof options.appendUnicode) {
|
|
156
|
-
throw new Error(
|
|
157
|
-
'The "appendUnicode" option was renamed "prependUnicode".' +
|
|
158
|
-
' See https://github.com/nfroidure/gulp-svgicons2svgfont/issues/33'
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return function getMetadataFromFile(file, cb) {
|
|
163
|
-
const basename = path.basename(file);
|
|
164
|
-
const metadata = {
|
|
165
|
-
path: file,
|
|
166
|
-
name: '',
|
|
167
|
-
unicode: [],
|
|
168
|
-
renamed: false,
|
|
169
|
-
};
|
|
170
|
-
const matches = basename.match(/^(?:((?:u[0-9a-f]{4,6},?)+)-)?(.+)\.svg$/i);
|
|
171
|
-
|
|
172
|
-
metadata.name =
|
|
173
|
-
matches && matches[2] ? matches[2] : 'icon' + options.startUnicode;
|
|
174
|
-
if (matches && matches[1]) {
|
|
175
|
-
metadata.unicode = matches[1].split(',').map((match) => {
|
|
176
|
-
match = match.substr(1);
|
|
177
|
-
return match
|
|
178
|
-
.split('u')
|
|
179
|
-
.map((code) => String.fromCodePoint(parseInt(code, 16)))
|
|
180
|
-
.join('');
|
|
181
|
-
});
|
|
182
|
-
if (-1 !== usedUnicodes.indexOf(metadata.unicode[0])) {
|
|
183
|
-
cb(
|
|
184
|
-
new Error(
|
|
185
|
-
'The unicode codepoint of the glyph ' +
|
|
186
|
-
metadata.name +
|
|
187
|
-
' seems to be already used by another glyph.'
|
|
188
|
-
)
|
|
189
|
-
);
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
usedUnicodes.push(...metadata.unicode);
|
|
193
|
-
} else {
|
|
194
|
-
do {
|
|
195
|
-
metadata.unicode[0] = String.fromCodePoint(options.startUnicode++);
|
|
196
|
-
} while (usedUnicodes.includes(metadata.unicode[0]));
|
|
197
|
-
usedUnicodes.push(metadata.unicode[0]);
|
|
198
|
-
if (options.prependUnicode) {
|
|
199
|
-
metadata.renamed = true;
|
|
200
|
-
metadata.path = path.join(
|
|
201
|
-
path.dirname(file),
|
|
202
|
-
'u' +
|
|
203
|
-
metadata.unicode[0].codePointAt(0).toString(16).toUpperCase() +
|
|
204
|
-
'-' +
|
|
205
|
-
basename
|
|
206
|
-
);
|
|
207
|
-
fs.rename(file, metadata.path, (err) => {
|
|
208
|
-
if (err) {
|
|
209
|
-
cb(
|
|
210
|
-
new Error(
|
|
211
|
-
'Could not save codepoint: ' +
|
|
212
|
-
'u' +
|
|
213
|
-
metadata.unicode[0]
|
|
214
|
-
.codePointAt(0)
|
|
215
|
-
.toString(16)
|
|
216
|
-
.toUpperCase() +
|
|
217
|
-
' for ' +
|
|
218
|
-
basename
|
|
219
|
-
)
|
|
220
|
-
);
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
cb(null, metadata);
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
if (!metadata.renamed) {
|
|
228
|
-
setImmediate(() => cb(null, metadata));
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
var metadata = getMetadataService;
|
|
234
|
-
|
|
235
|
-
var getGlyphsData = function (files, options) {
|
|
236
|
-
var metadataProvider = options.metadataProvider ||
|
|
237
|
-
metadata({
|
|
238
|
-
prependUnicode: options.prependUnicode,
|
|
239
|
-
startUnicode: options.startUnicode
|
|
240
|
-
});
|
|
241
|
-
var xmlParser = new xml2js__default['default'].Parser();
|
|
242
|
-
var throttle = pLimit__default['default'](options.maxConcurrency);
|
|
243
|
-
return Promise.all(files.map(function (srcPath) { return throttle(function () { return new Promise(function (resolve, reject) {
|
|
244
|
-
var glyph = require$$1.createReadStream(srcPath);
|
|
245
|
-
var glyphContents = "";
|
|
246
|
-
// eslint-disable-next-line no-promise-executor-return
|
|
247
|
-
return glyph.
|
|
248
|
-
on("error", function (glyphError) { return reject(glyphError); }).
|
|
249
|
-
on("data", function (data) {
|
|
250
|
-
glyphContents += data.toString();
|
|
251
|
-
}).
|
|
252
|
-
on("end", function () {
|
|
253
|
-
// Maybe bug in xml2js
|
|
254
|
-
if (glyphContents.length === 0) {
|
|
255
|
-
return reject(new Error("Empty file " + srcPath));
|
|
256
|
-
}
|
|
257
|
-
return xmlParser.parseString(glyphContents, function (error) {
|
|
258
|
-
if (error) {
|
|
259
|
-
return reject(error);
|
|
260
|
-
}
|
|
261
|
-
var glyphData = {
|
|
262
|
-
contents: glyphContents,
|
|
263
|
-
srcPath: srcPath
|
|
264
|
-
};
|
|
265
|
-
return resolve(glyphData);
|
|
266
|
-
});
|
|
267
|
-
});
|
|
268
|
-
}); }); })).then(function (glyphsData) {
|
|
269
|
-
var sortedGlyphsData = glyphsData;
|
|
270
|
-
if (options.sort) {
|
|
271
|
-
var sortCallback = function (fileA, fileB) { return filesorter(fileA.srcPath, fileB.srcPath); };
|
|
272
|
-
sortedGlyphsData = glyphsData.sort(sortCallback);
|
|
273
|
-
}
|
|
274
|
-
return Promise.all(sortedGlyphsData.map(function (glyphData) { return new Promise(function (resolve, reject) {
|
|
275
|
-
metadataProvider(glyphData.srcPath, function (error, metadata) {
|
|
276
|
-
if (error) {
|
|
277
|
-
return reject(error);
|
|
278
|
-
}
|
|
279
|
-
metadata.unicode.push(metadata.name.replace(/-/gu, "_"));
|
|
280
|
-
glyphData.metadata = metadata;
|
|
281
|
-
return resolve(glyphData);
|
|
282
|
-
});
|
|
283
|
-
}); }));
|
|
284
|
-
});
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
var getOptions = function (initialOptions) {
|
|
288
|
-
if (!initialOptions || !initialOptions.files) {
|
|
289
|
-
throw new Error("You must pass webfont a `files` glob");
|
|
290
|
-
}
|
|
291
|
-
return __assign({ centerHorizontally: false, descent: 0, fixedWidth: false, fontHeight: null, fontId: null, fontName: "webfont", fontStyle: "", fontWeight: "", formats: ["svg", "ttf", "eot", "woff", "woff2"], formatsOptions: {
|
|
292
|
-
ttf: {
|
|
293
|
-
copyright: null,
|
|
294
|
-
ts: null,
|
|
295
|
-
version: null
|
|
296
|
-
}
|
|
297
|
-
}, glyphTransformFn: null,
|
|
298
|
-
/*
|
|
299
|
-
* Maybe allow setup from CLI
|
|
300
|
-
* This is usually less than file read maximums while staying performance
|
|
301
|
-
*/
|
|
302
|
-
maxConcurrency: 100, metadata: null, metadataProvider: null, normalize: false, prependUnicode: false, round: 10e12, sort: true, startUnicode: 0xea01, template: null, templateCacheString: null, templateClassName: null, templateFontName: null, templateFontPath: "./", verbose: false }, initialOptions);
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
var buildConfig = function (options) { return __awaiter(void 0, void 0, void 0, function () {
|
|
306
|
-
var searchPath, configPath, configExplorer, config;
|
|
307
|
-
return __generator(this, function (_a) {
|
|
308
|
-
switch (_a.label) {
|
|
309
|
-
case 0:
|
|
310
|
-
searchPath = process.cwd();
|
|
311
|
-
configPath = null;
|
|
312
|
-
if (options.configFile) {
|
|
313
|
-
searchPath = null;
|
|
314
|
-
configPath = path__default['default'].resolve(process.cwd(), options.configFile);
|
|
315
|
-
}
|
|
316
|
-
configExplorer = cosmiconfig__default['default']("webfont");
|
|
317
|
-
return [4 /*yield*/, configExplorer.search(searchPath)];
|
|
318
|
-
case 1:
|
|
319
|
-
config = _a.sent();
|
|
320
|
-
if (!configPath) return [3 /*break*/, 3];
|
|
321
|
-
return [4 /*yield*/, configExplorer.load(configPath)];
|
|
322
|
-
case 2:
|
|
323
|
-
config = _a.sent();
|
|
324
|
-
_a.label = 3;
|
|
325
|
-
case 3:
|
|
326
|
-
if (!config) {
|
|
327
|
-
return [2 /*return*/, {}];
|
|
328
|
-
}
|
|
329
|
-
return [2 /*return*/, config];
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
}); };
|
|
333
|
-
var toSvg = function (glyphsData, options) {
|
|
334
|
-
var result = "";
|
|
335
|
-
return new Promise(function (resolve, reject) {
|
|
336
|
-
var log = function () {
|
|
337
|
-
Function.prototype();
|
|
338
|
-
};
|
|
339
|
-
if (options.verbose) {
|
|
340
|
-
// eslint-disable-next-line no-console
|
|
341
|
-
log = console.log.bind(console);
|
|
342
|
-
}
|
|
343
|
-
var fontStream = new SVGIcons2SVGFontStream__default['default']({
|
|
344
|
-
ascent: options.ascent,
|
|
345
|
-
centerHorizontally: options.centerHorizontally,
|
|
346
|
-
descent: options.descent,
|
|
347
|
-
fixedWidth: options.fixedWidth,
|
|
348
|
-
fontHeight: options.fontHeight,
|
|
349
|
-
fontId: options.fontId,
|
|
350
|
-
fontName: options.fontName,
|
|
351
|
-
fontStyle: options.fontStyle,
|
|
352
|
-
fontWeight: options.fontWeight,
|
|
353
|
-
log: log,
|
|
354
|
-
metadata: options.metadata,
|
|
355
|
-
normalize: options.normalize,
|
|
356
|
-
round: options.round
|
|
357
|
-
}).
|
|
358
|
-
on("finish", function () { return resolve(result); }).
|
|
359
|
-
on("data", function (data) {
|
|
360
|
-
result += data;
|
|
361
|
-
}).
|
|
362
|
-
on("error", function (error) { return reject(error); });
|
|
363
|
-
glyphsData.forEach(function (glyphData) {
|
|
364
|
-
var glyphStream = new stream.Readable();
|
|
365
|
-
glyphStream.push(glyphData.contents);
|
|
366
|
-
glyphStream.push(null);
|
|
367
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
368
|
-
// @ts-ignore
|
|
369
|
-
glyphStream.metadata = glyphData.metadata;
|
|
370
|
-
fontStream.write(glyphStream);
|
|
371
|
-
});
|
|
372
|
-
fontStream.end();
|
|
373
|
-
});
|
|
374
|
-
};
|
|
375
|
-
var toTtf = function (buffer, options) { return Buffer.from(svg2ttf__default['default'](buffer, options).buffer); };
|
|
376
|
-
var toEot = function (buffer) { return Buffer.from(ttf2eot__default['default'](buffer).buffer); };
|
|
377
|
-
var toWoff = function (buffer, options) { return Buffer.from(ttf2woff__default['default'](buffer, options).buffer); };
|
|
378
|
-
var toWoff2 = function (buffer) { return wawoff2__default['default'].compress(buffer); };
|
|
379
|
-
var webfont = function (initialOptions) { return __awaiter(void 0, void 0, void 0, function () {
|
|
380
|
-
var options, config, foundFiles, filteredFiles, glyphsData, transformedGlyphs, ttfOptions, svg, ttf, result, _a, builtInTemplates, templateFilePath, builtInPath, resolvedTemplateFilePath, hashOption, nunjucksOptions;
|
|
381
|
-
return __generator(this, function (_b) {
|
|
382
|
-
switch (_b.label) {
|
|
383
|
-
case 0:
|
|
384
|
-
options = getOptions(initialOptions);
|
|
385
|
-
return [4 /*yield*/, buildConfig({
|
|
386
|
-
configFile: options.configFile
|
|
387
|
-
})];
|
|
388
|
-
case 1:
|
|
389
|
-
config = _b.sent();
|
|
390
|
-
if (Object.keys(config).length > 0) {
|
|
391
|
-
options = deepmerge__default['default'](options, config.config, {
|
|
392
|
-
arrayMerge: function (_destinationArray, sourceArray) { return sourceArray; }
|
|
393
|
-
});
|
|
394
|
-
options.filePath = config.filepath;
|
|
395
|
-
}
|
|
396
|
-
return [4 /*yield*/, globby__default['default']([].concat(options.files))];
|
|
397
|
-
case 2:
|
|
398
|
-
foundFiles = _b.sent();
|
|
399
|
-
filteredFiles = foundFiles.filter(function (foundFile) { return path__default['default'].extname(foundFile) === ".svg"; });
|
|
400
|
-
if (filteredFiles.length === 0) {
|
|
401
|
-
throw new Error("Files glob patterns specified did not match any files");
|
|
402
|
-
}
|
|
403
|
-
return [4 /*yield*/, getGlyphsData(filteredFiles, options)];
|
|
404
|
-
case 3:
|
|
405
|
-
glyphsData = _b.sent();
|
|
406
|
-
if (!(options.glyphTransformFn && typeof options.glyphTransformFn === "function")) return [3 /*break*/, 5];
|
|
407
|
-
transformedGlyphs = glyphsData.map(function (glyphData) { return __awaiter(void 0, void 0, void 0, function () {
|
|
408
|
-
var metadata;
|
|
409
|
-
return __generator(this, function (_a) {
|
|
410
|
-
switch (_a.label) {
|
|
411
|
-
case 0: return [4 /*yield*/, options.glyphTransformFn(glyphData.metadata)];
|
|
412
|
-
case 1:
|
|
413
|
-
metadata = _a.sent();
|
|
414
|
-
return [2 /*return*/, __assign(__assign({}, glyphData), { metadata: metadata })];
|
|
415
|
-
}
|
|
416
|
-
});
|
|
417
|
-
}); });
|
|
418
|
-
return [4 /*yield*/, Promise.all(transformedGlyphs)];
|
|
419
|
-
case 4:
|
|
420
|
-
glyphsData = _b.sent();
|
|
421
|
-
_b.label = 5;
|
|
422
|
-
case 5:
|
|
423
|
-
ttfOptions = {};
|
|
424
|
-
if (options.formatsOptions && options.formatsOptions.ttf) {
|
|
425
|
-
ttfOptions = options.formatsOptions.ttf;
|
|
426
|
-
}
|
|
427
|
-
return [4 /*yield*/, toSvg(glyphsData, options)];
|
|
428
|
-
case 6:
|
|
429
|
-
svg = _b.sent();
|
|
430
|
-
ttf = toTtf(svg, ttfOptions);
|
|
431
|
-
result = {
|
|
432
|
-
glyphsData: glyphsData,
|
|
433
|
-
hash: crypto__default['default'].createHash("md5").update(svg).
|
|
434
|
-
digest("hex"),
|
|
435
|
-
svg: svg,
|
|
436
|
-
ttf: ttf
|
|
437
|
-
};
|
|
438
|
-
if (options.formats.includes("eot")) {
|
|
439
|
-
result.eot = toEot(ttf);
|
|
440
|
-
}
|
|
441
|
-
if (options.formats.includes("woff")) {
|
|
442
|
-
result.woff = toWoff(ttf, { metadata: options.metadata });
|
|
443
|
-
}
|
|
444
|
-
if (!options.formats.includes("woff2")) return [3 /*break*/, 8];
|
|
445
|
-
_a = result;
|
|
446
|
-
return [4 /*yield*/, toWoff2(ttf)];
|
|
447
|
-
case 7:
|
|
448
|
-
_a.woff2 = _b.sent();
|
|
449
|
-
_b.label = 8;
|
|
450
|
-
case 8:
|
|
451
|
-
if (options.template) {
|
|
452
|
-
builtInTemplates = getBuiltInTemplates();
|
|
453
|
-
templateFilePath = void 0;
|
|
454
|
-
if (Object.keys(builtInTemplates).includes(options.template)) {
|
|
455
|
-
result.usedBuildInTemplate = true;
|
|
456
|
-
builtInPath = path__default['default'].resolve(__dirname, "../..");
|
|
457
|
-
nunjucks__default['default'].configure(builtInPath);
|
|
458
|
-
templateFilePath = getTemplateFilePath(options.template);
|
|
459
|
-
}
|
|
460
|
-
else {
|
|
461
|
-
resolvedTemplateFilePath = path__default['default'].resolve(options.template);
|
|
462
|
-
nunjucks__default['default'].configure(path__default['default'].dirname(resolvedTemplateFilePath));
|
|
463
|
-
templateFilePath = path__default['default'].resolve(resolvedTemplateFilePath);
|
|
464
|
-
}
|
|
465
|
-
hashOption = {};
|
|
466
|
-
if (options.addHashInFontUrl) {
|
|
467
|
-
hashOption = { hash: result.hash };
|
|
468
|
-
}
|
|
469
|
-
nunjucksOptions = deepmerge__default['default'].all([
|
|
470
|
-
{
|
|
471
|
-
glyphs: result.glyphsData.map(function (glyph) { return glyph.metadata; })
|
|
472
|
-
},
|
|
473
|
-
options,
|
|
474
|
-
{
|
|
475
|
-
cacheString: options.templateCacheString || Date.now(),
|
|
476
|
-
className: options.templateClassName || options.fontName,
|
|
477
|
-
fontName: options.templateFontName || options.fontName,
|
|
478
|
-
fontPath: options.templateFontPath.replace(/\/?$/u, "/")
|
|
479
|
-
},
|
|
480
|
-
hashOption,
|
|
481
|
-
{
|
|
482
|
-
fonts: Object.fromEntries(new Map(options.formats.map(function (format) { return [
|
|
483
|
-
format, function () {
|
|
484
|
-
if (format === "woff2") {
|
|
485
|
-
return Buffer.from(result.woff2).toString("base64");
|
|
486
|
-
}
|
|
487
|
-
return result[format].toString("base64");
|
|
488
|
-
},
|
|
489
|
-
]; })))
|
|
490
|
-
},
|
|
491
|
-
]);
|
|
492
|
-
result.template = nunjucks__default['default'].render(templateFilePath, nunjucksOptions);
|
|
493
|
-
}
|
|
494
|
-
if (!options.formats.includes("svg")) {
|
|
495
|
-
delete result.svg;
|
|
496
|
-
}
|
|
497
|
-
if (!options.formats.includes("ttf")) {
|
|
498
|
-
delete result.ttf;
|
|
499
|
-
}
|
|
500
|
-
result.config = options;
|
|
501
|
-
return [2 /*return*/, result];
|
|
502
|
-
}
|
|
503
|
-
});
|
|
504
|
-
}); };
|
|
505
|
-
|
|
506
|
-
exports['default'] = webfont;
|
|
507
|
-
exports.webfont = webfont;
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./parseTemplateOption-BmH_pcQh.js");let t=require("cosmiconfig"),n=require("deepmerge");n=e.r(n);let r=require("path");r=e.r(r);let i=require("globby"),a=require("fs/promises");a=e.r(a);let o=require("ttf2woff");o=e.r(o);let s=require("wawoff2");s=e.r(s);let c=require("ttf2eot");c=e.r(c);let l=require("fontverter");l=e.r(l);let u=require("fs"),d=require("xml2js");d=e.r(d);let f=require("p-limit");f=e.r(f);let p=require("svgicons2svgfont"),m=require("crypto");m=e.r(m);let ee=require("svgo"),te=require("stream"),h=require("svg2ttf");h=e.r(h);var ne=/^https?:\/\//iu,g=e=>ne.test(e),_=e=>{if(g(e))try{return r.default.extname(new URL(e).pathname).toLowerCase()}catch{return``}return r.default.extname(e).toLowerCase()},v=async e=>(await Promise.all(e.map(e=>g(e)?Promise.resolve([e]):(0,i.globby)(e)))).flat(),re=1330926671,ie=1953658213,ae=65536,y=e=>{if(e.length<4)throw Error(`SFNT buffer is too short to read flavor`);let t=e.readUInt32BE(0);if(t===re)return`otf`;if(t===ie||t===ae)return`ttf`;throw Error(`Unsupported SFNT flavor 0x${t.toString(16)}`)},oe=e=>Buffer.from((0,c.default)(e)),b=e=>oe(e),x=(e,t={})=>Buffer.from((0,o.default)(e,t).buffer),S=async e=>Buffer.from(await s.default.compress(e)),C=new Set([`.woff`,`.woff2`]),w=`.svg`,T=`.ttf`,E=[`svg`,`ttf`,`eot`,`woff`,`woff2`],D=e=>e===w,O=e=>e===T,k=e=>C.has(e),se=e=>D(e)||k(e)||O(e),ce=e=>{if(e.length===0)return`empty`;let t=e.map(e=>_(e));if(!t.every(se))return`empty`;let n=t.some(D),r=t.some(k),i=t.some(O);return[n,r,i].filter(Boolean).length>1?`mixed`:r?`webfont`:i?`ttf`:n?`svg`:`empty`},A=e=>{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.`)},j=(e,t)=>t===`svg`?e.filter(e=>_(e)===w):t===`webfont`?e.filter(e=>C.has(_(e))):t===`ttf`?e.filter(e=>_(e)===T):[],M=new Set([`ttf`,`eot`,`woff`,`woff2`]),N=e=>{let t=e.filter(e=>M.has(e));if(e.length===E.length&&E.every(t=>e.includes(t)))return[`woff`,`woff2`];if(t.length===0)throw Error(`formats must include at least one of "ttf", "eot", "woff", or "woff2" when converting TTF input`);return[...new Set(t)]},P=e=>{let t=e.filter(e=>e===`ttf`||e===`otf`);if(e.length===E.length&&E.every(t=>e.includes(t)))return[`ttf`];if(t.length===0)throw Error(`formats must include "ttf" and/or "otf" when converting WOFF/WOFF2 input`);return[...new Set(t)]},F=e=>{if(e.length===0)throw Error(`No TTF files matched`)},I=e=>{if(e.template)throw Error(`Templates are not supported when converting TTF input`);if(e.glyphTransformFn)throw Error(`glyphTransformFn is not supported when converting TTF input`);if(e.glyphContentTransformFn)throw Error(`glyphContentTransformFn is not supported when converting TTF input`)},L=(e,t)=>{let n;try{n=y(e)}catch{throw Error(`Input is not a valid TrueType font: ${t}`)}if(n!==`ttf`)throw Error(`OpenType (OTF) input is not supported for webfont encoding. Use a .ttf file for ${t}.`)},R=async(e,t,n,r)=>{if(n===`ttf`){e.ttf=t;return}if(n===`eot`){e.eot=b(t);return}if(n===`woff`){let n;typeof r.metadata==`string`&&(n=r.metadata),e.woff=x(t,{metadata:n});return}e.woff2=await S(t)},z=async(e,t,n,r)=>{if(g(e))throw Error(`Remote TTF URLs are not supported. Download the file first: ${e}`);r&&console.log(`Encoding ${e}...`);let i=await a.readFile(e);L(i,e);let o={source:e};return await Promise.all(t.map(e=>R(o,i,e,n))),o},B=async(e,t)=>{I(t),F(e);let n=N(t.formats),r=await Promise.all(e.map(e=>z(e,n,t,t.verbose))),i={config:{...t},transcodedFonts:r};if(r.length===1){let[e]=r;i.ttf=e.ttf,i.eot=e.eot,i.woff=e.woff,i.woff2=e.woff2}return i},V=e.n(((e,t)=>{t.exports=function(e){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}})),H=e.n(((e,t)=>{t.exports=function(e){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}})),U=e.r(V()),W=e.r(H()),G=(e,t)=>{let n=_(t);if(n===`.woff2`&&!(0,W.default)(e))throw Error(`URL did not return a valid WOFF2 font: ${t}`);if(n===`.woff`&&!(0,U.default)(e))throw Error(`URL did not return a valid WOFF font: ${t}`);if(e.length===0)throw Error(`URL returned an empty response: ${t}`)},le=async e=>{let t;try{t=await fetch(e)}catch(t){let n=String(t);throw t instanceof Error&&(n=t.message),Error(`Failed to fetch font URL ${e}: ${n}`)}if(!t.ok)throw Error(`Failed to fetch font URL ${e}: HTTP ${t.status} ${t.statusText}`);let n=await t.arrayBuffer(),r=Buffer.from(n);return G(r,e),r},ue=e=>{if(e.length===0)throw Error(`No WOFF or WOFF2 files matched`)},de=e=>{if(e.template)throw Error(`Templates are not supported when converting WOFF/WOFF2 input`);if(e.glyphTransformFn)throw Error(`glyphTransformFn is not supported when converting WOFF/WOFF2 input`);if(e.glyphContentTransformFn)throw Error(`glyphContentTransformFn is not supported when converting WOFF/WOFF2 input`)},fe=e=>{let{decompressed:t,sfnt:n,format:r,flavor:i,source:a}=e;if(r===`ttf`&&i!==`ttf`)throw Error(`Input decompresses to OpenType (OTF). Request "otf" format instead of "ttf" for ${a}.`);if(r===`otf`&&i!==`otf`)throw Error(`Input decompresses to TrueType (TTF). Request "ttf" format instead of "otf" for ${a}.`);if(r===`ttf`){t.ttf=n;return}t.otf=n},pe=e=>g(e)?le(e):a.readFile(e),me=async(e,t,n)=>{n&&console.log(`Decompressing ${e}...`);let r=await pe(e),i=Buffer.from(await l.default.convert(r,`sfnt`)),a=y(i),o={source:e};for(let n of t)fe({decompressed:o,sfnt:i,format:n,flavor:a,source:e});return o},he=async(e,t)=>{de(t),ue(e);let n=P(t.formats),r=await Promise.all(e.map(e=>me(e,n,t.verbose))),i={config:{...t},decompressedFonts:r};return r.length===1&&(i.ttf=r[0].ttf,i.otf=r[0].otf),i},ge=f.default,_e=e=>({prependUnicode:!!e.prependUnicode,startUnicode:Number(e.startUnicode)}),ve=e=>{if(e==null)return;if(typeof e==`number`)return Number.isFinite(e)?e:void 0;let t=e.trim();if(t.length===0)return;let n=Number(t);if(Number.isFinite(n))return n},ye=e=>({ascent:e.ascent,centerHorizontally:e.centerHorizontally,descent:e.descent,fixedWidth:e.fixedWidth,fontHeight:e.fontHeight,fontId:e.fontId,fontName:e.fontName,fontStyle:e.fontStyle,fontWeight:e.fontWeight,metadata:e.metadata,normalize:e.normalize,round:ve(e.round)}),be=e=>e===void 0?[]:Array.isArray(e)?e:[e],xe=e=>({name:e.name,unicode:be(e.unicode)}),Se=(e,t)=>{let n=t.metadataProvider||(0,p.getMetadataService)(_e(t)),r=new d.default.Parser,i=ge(t.maxConcurrency);return Promise.all(e.map(e=>i(()=>new Promise((t,n)=>{let i=(0,u.createReadStream)(e),a=``;i.on(`error`,e=>n(e)).on(`data`,e=>{a+=e.toString()}).on(`end`,()=>a.length===0?n(Error(`Empty file ${e}`)):r.parseString(a,r=>r?n(r):t({contents:a,srcPath:e})))})))).then(e=>{let r=e;t.sort&&(r=e.sort((e,t)=>(0,p.fileSorter)(e.srcPath,t.srcPath)));let{ligatures:i}=t;return Promise.all(r.map(e=>new Promise((t,r)=>{n(e.srcPath,(n,a)=>{if(n)return r(n);if(!a)return r(Error(`Missing metadata for ${e.srcPath}`));let o=xe(a);return i&&o.unicode.push(a.name.replace(/-/gu,`_`)),e.metadata=o,t(e)})})))})},Ce=()=>({centerHorizontally:!1,descent:0,fixedWidth:!1,fontHeight:void 0,fontId:void 0,fontName:`webfont`,fontStyle:``,fontWeight:``,formats:[`svg`,`ttf`,`eot`,`woff`,`woff2`],formatsOptions:{ttf:{copyright:null,ts:null,version:null}},ligatures:!1,maxConcurrency:100,metadata:void 0,normalize:!1,prependUnicode:!1,round:0x9184e72a000,sort:!0,startUnicode:59905,templateFontPath:`./`,unicodeRange:!1,verbose:!1}),we=e=>{if(!e?.files)throw Error("You must pass webfont a `files` glob");return{...Ce(),...e}},Te=()=>({multipass:!1,plugins:[`removeDoctype`,`removeXMLProcInst`,`removeComments`,`removeMetadata`,`removeEditorsNSData`,`removeDesc`,`cleanupAttrs`,`removeUnusedNS`]}),Ee=e=>{let t=Te();return e?{...t,...e,plugins:e.plugins??t.plugins}:t},De=(e,t,n)=>(0,ee.optimize)(e,{...Ee(n),path:t}).data,Oe=(e,t)=>e.map(e=>({...e,contents:De(e.contents,e.srcPath,t)})),ke=(e,t)=>t&&e>2e3,Ae=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`,je=/<glyph\b([^>/]*)(?:\/>|>)/giu,Me=/\bglyph-name=["']([^"']+)["']/iu,Ne=/\bd=["']([^"']*)["']/iu,Pe=e=>{let t=[];for(let n of e.matchAll(je)){let e=n[1]??``,r=Me.exec(e);r&&(Ne.exec(e)?.[1]??``).trim().length===0&&t.push(r[1])}return t},Fe=(e,t)=>{for(let n of t){let t=n.metadata?.name;if(t&&(e===t||e.startsWith(`${t}-`)))return n.srcPath}},Ie=(e,t)=>{let n=new Set,r=[];for(let i of e){let e=Fe(i,t),a=e??i;n.has(a)||(n.add(a),e?r.push(`${i} (${e})`):r.push(i))}return r.join(`; `)},Le=(e,t)=>{let n=Pe(e);if(n.length===0)return;let r=Ie(n,t);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").`)},Re=/fill-rule\s*:\s*evenodd|fill-rule\s*=\s*["']evenodd["']/iu,ze=e=>Re.test(e),Be=/\bstroke\s*=|\bstroke\s*:/iu,Ve=/fill\s*=\s*["']none["']|fill\s*:\s*none/iu,He=/<(line|polyline|clipPath)\b/iu,Ue=e=>Be.test(e)?Ve.test(e):!1,We=e=>He.test(e),K=(e,t)=>{switch(e){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").`;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").`;case`unsupported-element`:return`[webfont:diagnose] ${t} contains <line>, <polyline>, or <clipPath>. These elements are poorly supported in icon fonts; results may differ from the browser preview. Convert to filled paths or preprocess with glyphContentTransformFn.`;default:return e}},q=(e,t)=>{let n=[];return ze(t)&&n.push({code:`evenodd-fill-rule`,message:K(`evenodd-fill-rule`,e),srcPath:e}),Ue(t)&&n.push({code:`stroke-only`,message:K(`stroke-only`,e),srcPath:e}),We(t)&&n.push({code:`unsupported-element`,message:K(`unsupported-element`,e),srcPath:e}),n},J=e=>e.flatMap(e=>q(e.srcPath,e.contents)),Ge=(e,t)=>t.diagnose?!0:!!(t.verbose&&e.code===`evenodd-fill-rule`),Ke=e=>{if(!e||!e.diagnose)return;let t={diagnose:!0};return e.onMessage&&(t.onMessage=e.onMessage),t},qe=(e,t,n={})=>{let r=Ke(t),i=J(e),{reporter:a,verbose:o=!1}=n;for(let e of i)Ge(e,{diagnose:r?.diagnose,verbose:o})&&a?.(e.message);let s=[];return r?.diagnose&&(s=i),{diagnostics:s,glyphs:e}},Je=(e,t,n={})=>{let{diagnostics:r,glyphs:i}=qe(e,t,n);return{diagnostics:r,glyphs:i}},Ye=(e,t)=>{let n=``;return new Promise((r,i)=>{t.verbose&&console.log(`Generating SVG font...`);let a=new p.SVGIcons2SVGFontStream(ye(t)).on(`finish`,()=>r(n)).on(`data`,e=>{n+=e}).on(`error`,e=>i(e));e.forEach(e=>{let t=new te.Readable;t.push(e.contents),t.push(null),t.metadata=e.metadata??{name:``,unicode:[]},a.write(t)}),a.end()})},Xe=(e,t={})=>Buffer.from((0,h.default)(e,t).buffer),Ze=e=>b(e),Qe=(e,t)=>x(e,t),Y=e=>S(e),$e=async(e,t)=>{let n=e=>{if(t.svgTools?.onMessage){t.svgTools.onMessage(e);return}(t.svgTools?.diagnose||t.verbose)&&console.log(e)},r=!!(t.svgTools?.onMessage||t.svgTools?.diagnose||t.verbose),i;r&&(i=n);let{diagnostics:a,glyphs:o}=Je(e,t.svgTools,{reporter:i,verbose:t.verbose}),s=o;if(t.optimizeSvg&&(s=Oe(s,t.svgoConfig)),t.glyphContentTransformFn){let e=t.glyphContentTransformFn;s=await Promise.all(s.map(async t=>{let n=await e(t);return{...t,contents:n}}))}if(t.glyphTransformFn){let e=t.glyphTransformFn;s=await Promise.all(s.map(async t=>{let n=await e(t.metadata??{name:``,unicode:[]});return{...t,metadata:n}}))}ke(s.length,t.ligatures)&&console.log(Ae(s.length));let c={};t.formatsOptions?.ttf&&(c=t.formatsOptions.ttf);let l=await Ye(s,t);Le(l,s);let u=Xe(l,c),d={config:t,glyphsData:s,hash:m.default.createHash(`md5`).update(l).digest(`hex`),svg:l,ttf:u};a.length>0&&(d.svgDiagnostics=a);let{formats:f}=t;if(f.includes(`eot`)&&(d.eot=Ze(u)),f.includes(`woff`)){let e;typeof t.metadata==`string`&&(e=t.metadata),d.woff=Qe(u,{metadata:e})}if(f.includes(`woff2`)&&(d.woff2=Buffer.from(await Y(u))),t.template){let{renderTemplates:e}=await Promise.resolve().then(()=>require("./renderTemplates-zCYCzeOt.js")),{templates:n,usedBuildInTemplate:r}=e(t,d,f);n.length>0&&(d.templates=n,d.template=n[0]?.content,d.usedBuildInTemplate=r)}return f.includes(`svg`)||delete d.svg,f.includes(`ttf`)||delete d.ttf,f.includes(`otf`)||delete d.otf,d},X=new Set([`eot`,`otf`,`svg`,`ttf`,`woff`,`woff2`]),et=[...X].join(`, `),tt=e=>{if(typeof e!=`string`||!X.has(e))throw Error(`Invalid format "${String(e)}". Expected one of: ${et}`);return e},nt=e=>{if(e.length===0)throw Error(`formats must not be empty`);return e.map(tt)},rt=e=>{if(!Array.isArray(e))throw Error(`formats must be an array of format names (e.g. ["woff2", "svg"])`);return nt(e)},Z=(e,t)=>{if(t!==void 0&&typeof t!=`string`)throw Error(`${e} must be a string`)},it=(e,t)=>{if(t!==void 0&&typeof t!=`boolean`&&typeof t!=`string`)throw Error(`${e} must be a boolean or string`)},Q=(e,t)=>{if(t!==void 0&&typeof t!=`boolean`)throw Error(`${e} must be a boolean`)},at=(e,t)=>{if(t!==void 0&&(typeof t!=`object`||!t||Array.isArray(t)))throw Error(`${e} must be an object`)},ot=e=>{if(typeof e==`string`){if(e.length===0)throw Error(`files must not be empty`);return}if(Array.isArray(e)){if(e.length===0)throw Error(`files must not be empty`);if(!e.every(e=>typeof e==`string`))throw Error(`files must be a string or an array of strings`);return}throw Error(`files must be a string or an array of strings`)},st=t=>(ot(t.files),t.formats=rt(t.formats),Z(`fontName`,t.fontName),it(`unicodeRange`,t.unicodeRange),Q(`optimizeSvg`,t.optimizeSvg),at(`svgoConfig`,t.svgoConfig),Q(`templateFontLigatures`,t.templateFontLigatures),t.template!==void 0&&e.t(t.template),Z(`templateFontPath`,t.templateFontPath),t),ct=e=>`filepath`in e,lt=async e=>{let n=(0,t.cosmiconfig)(`webfont`,{searchStrategy:`global`});if(e.configFile){let t=r.default.resolve(process.cwd(),e.configFile);return await n.load(t)??{}}return await n.search(process.cwd())??{}},$=async e=>{let t=we(e);delete t.filePath;let r=await lt({configFile:t.configFile}),i;ct(r)&&(t=(0,n.default)(t,r.config,{arrayMerge:(e,t)=>t}),i=r.filepath),t=st(t);let a;a=Array.isArray(t.files)?t.files:[t.files];let o=await v(a),s=ce(o);if(s===`mixed`)throw Error(`Cannot mix SVG icons, TTF fonts, and WOFF/WOFF2 files in the same run`);if(s===`empty`)throw Error(`Files glob patterns specified did not match any supported files`);if(s===`webfont`){let e=await he(j(o,s),t);return i&&(e.config={...t,filePath:i}),e}if(s===`ttf`){let e=await B(j(o,s),t);return i&&(e.config={...t,filePath:i}),e}A(t.formats);let c=await $e(await Se(j(o,`svg`),t),t);return i?c.config={...t,filePath:i}:c.config=t,c},ut=$;exports.default=ut,exports.diagnoseGlyphsData=J,exports.diagnoseSvgContents=q,exports.webfont=$;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { fileURLToPath as e } from "node:url";
|
|
3
|
+
e(import.meta.url), e(new URL(".", import.meta.url));
|
|
4
|
+
//#region src/lib/parseTemplateOption.ts
|
|
5
|
+
var t = (e) => {
|
|
6
|
+
if (e == null) return [];
|
|
7
|
+
if (typeof e == "string") {
|
|
8
|
+
let t = e.trim();
|
|
9
|
+
if (t.length === 0) throw Error("template must not be empty");
|
|
10
|
+
return [t];
|
|
11
|
+
}
|
|
12
|
+
if (Array.isArray(e)) {
|
|
13
|
+
if (e.length === 0) throw Error("template must not be empty");
|
|
14
|
+
if (!e.every((e) => typeof e == "string" && e.trim().length > 0)) throw Error("template must be a string or an array of non-empty strings");
|
|
15
|
+
return e.map((e) => e.trim());
|
|
16
|
+
}
|
|
17
|
+
throw Error("template must be a string or an array of strings");
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
export { t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,a)=>(a=n==null?{}:e(i(n)),s(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n)),l=e=>{if(e==null)return[];if(typeof e==`string`){let t=e.trim();if(t.length===0)throw Error(`template must not be empty`);return[t]}if(Array.isArray(e)){if(e.length===0)throw Error(`template must not be empty`);if(!e.every(e=>typeof e==`string`&&e.trim().length>0))throw Error(`template must be a string or an array of non-empty strings`);return e.map(e=>e.trim())}throw Error(`template must be a string or an array of strings`)};Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return l}});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { fileURLToPath as e } from "node:url";
|
|
3
|
+
e(import.meta.url);
|
|
4
|
+
const t = e(new URL(".", import.meta.url));
|
|
5
|
+
import { t as n } from "./parseTemplateOption-5T7rSw5J.mjs";
|
|
6
|
+
import r from "path";
|
|
7
|
+
import i from "deepmerge";
|
|
8
|
+
import a from "nunjucks";
|
|
9
|
+
//#region templates/index.ts
|
|
10
|
+
var o = () => r.resolve(t, "../templates"), s = (e) => `${o()}/template.${e}.njk`, c = () => {
|
|
11
|
+
let e = o();
|
|
12
|
+
return {
|
|
13
|
+
css: { path: r.join(e, "template.css.njk") },
|
|
14
|
+
html: { path: r.join(e, "template.html.njk") },
|
|
15
|
+
json: { path: r.join(e, "template.json.njk") },
|
|
16
|
+
scss: { path: r.join(e, "template.scss.njk") },
|
|
17
|
+
styl: { path: r.join(e, "template.styl.njk") }
|
|
18
|
+
};
|
|
19
|
+
}, l = (e) => {
|
|
20
|
+
let t = 4;
|
|
21
|
+
return e > 65535 && (t = 6), e.toString(16).toUpperCase().padStart(t, "0");
|
|
22
|
+
}, u = (e) => {
|
|
23
|
+
if (e.length === 0 || e.length > 2) return;
|
|
24
|
+
let t = e.codePointAt(0);
|
|
25
|
+
if (t !== void 0 && !(e.length > 1 && t < 128)) return t;
|
|
26
|
+
}, d = (e) => {
|
|
27
|
+
let t = [];
|
|
28
|
+
for (let n of e) for (let e of n.unicode ?? []) {
|
|
29
|
+
let n = u(e);
|
|
30
|
+
n !== void 0 && t.push(n);
|
|
31
|
+
}
|
|
32
|
+
return t;
|
|
33
|
+
}, f = (e) => {
|
|
34
|
+
let t = d(e);
|
|
35
|
+
if (t.length === 0) return;
|
|
36
|
+
let n = Math.min(...t), r = Math.max(...t);
|
|
37
|
+
return n === r ? `U+${l(n)}` : `U+${l(n)}-${l(r)}`;
|
|
38
|
+
}, p = (e, t) => {
|
|
39
|
+
if (!(e === !1 || e === void 0)) return typeof e == "string" ? e : f(t);
|
|
40
|
+
}, m = (e, t) => {
|
|
41
|
+
if (e === "woff2") {
|
|
42
|
+
if (!t.woff2) throw Error("Missing woff2 buffer for template rendering");
|
|
43
|
+
return Buffer.from(t.woff2).toString("base64");
|
|
44
|
+
}
|
|
45
|
+
let n = t[e];
|
|
46
|
+
if (!n) throw Error(`Missing ${e} buffer for template rendering`);
|
|
47
|
+
return n.toString("base64");
|
|
48
|
+
}, h = (e, o, l) => {
|
|
49
|
+
let u = n(e.template);
|
|
50
|
+
if (u.length === 0) return {
|
|
51
|
+
templates: [],
|
|
52
|
+
usedBuildInTemplate: !1
|
|
53
|
+
};
|
|
54
|
+
let d = c(), f = [], h = !1, g = {};
|
|
55
|
+
e.addHashInFontUrl && (g = { hash: o.hash });
|
|
56
|
+
let _ = o.glyphsData?.map((e) => e.metadata).filter((e) => e !== void 0) ?? [], v = i.all([
|
|
57
|
+
{ glyphs: _ },
|
|
58
|
+
e,
|
|
59
|
+
{
|
|
60
|
+
cacheString: e.templateCacheString || Date.now(),
|
|
61
|
+
className: e.templateClassName || e.fontName,
|
|
62
|
+
fontFamily: e.templateFontName || e.fontName,
|
|
63
|
+
fontPath: e.templateFontPath.replace(/\/?$/u, "/"),
|
|
64
|
+
svgFontId: e.fontId || e.fontName
|
|
65
|
+
},
|
|
66
|
+
g,
|
|
67
|
+
{ fonts: Object.fromEntries(new Map(l.map((e) => [e, () => m(e, o)]))) },
|
|
68
|
+
{ unicodeRange: p(e.unicodeRange, _) },
|
|
69
|
+
{ templateFontLigatures: e.templateFontLigatures !== !1 }
|
|
70
|
+
]);
|
|
71
|
+
for (let e of u) {
|
|
72
|
+
let n, i;
|
|
73
|
+
if (Object.keys(d).includes(e)) {
|
|
74
|
+
h = !0, i = e;
|
|
75
|
+
let o = r.resolve(t, "../..");
|
|
76
|
+
a.configure(o), n = s(e);
|
|
77
|
+
} else {
|
|
78
|
+
let t = r.resolve(e);
|
|
79
|
+
a.configure(r.dirname(t)), n = r.resolve(t);
|
|
80
|
+
}
|
|
81
|
+
f.push({
|
|
82
|
+
template: e,
|
|
83
|
+
content: a.render(n, v),
|
|
84
|
+
builtIn: i
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
templates: f,
|
|
89
|
+
usedBuildInTemplate: h
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
//#endregion
|
|
93
|
+
export { h as renderTemplates };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require("./parseTemplateOption-BmH_pcQh.js");let t=require("deepmerge");t=e.r(t);let n=require("path");n=e.r(n);let r=require("nunjucks");r=e.r(r);var i=()=>n.default.resolve(__dirname,`../templates`),a=e=>`${i()}/template.${e}.njk`,o=()=>{let e=i();return{css:{path:n.default.join(e,`template.css.njk`)},html:{path:n.default.join(e,`template.html.njk`)},json:{path:n.default.join(e,`template.json.njk`)},scss:{path:n.default.join(e,`template.scss.njk`)},styl:{path:n.default.join(e,`template.styl.njk`)}}},s=e=>{let t=4;return e>65535&&(t=6),e.toString(16).toUpperCase().padStart(t,`0`)},c=e=>{if(e.length===0||e.length>2)return;let t=e.codePointAt(0);if(t!==void 0&&!(e.length>1&&t<128))return t},l=e=>{let t=[];for(let n of e)for(let e of n.unicode??[]){let n=c(e);n!==void 0&&t.push(n)}return t},u=e=>{let t=l(e);if(t.length===0)return;let n=Math.min(...t),r=Math.max(...t);return n===r?`U+${s(n)}`:`U+${s(n)}-${s(r)}`},d=(e,t)=>{if(!(e===!1||e===void 0))return typeof e==`string`?e:u(t)},f=(e,t)=>{if(e===`woff2`){if(!t.woff2)throw Error(`Missing woff2 buffer for template rendering`);return Buffer.from(t.woff2).toString(`base64`)}let n=t[e];if(!n)throw Error(`Missing ${e} buffer for template rendering`);return n.toString(`base64`)},p=(i,s,c)=>{let l=e.t(i.template);if(l.length===0)return{templates:[],usedBuildInTemplate:!1};let u=o(),p=[],m=!1,h={};i.addHashInFontUrl&&(h={hash:s.hash});let g=s.glyphsData?.map(e=>e.metadata).filter(e=>e!==void 0)??[],_=t.default.all([{glyphs:g},i,{cacheString:i.templateCacheString||Date.now(),className:i.templateClassName||i.fontName,fontFamily:i.templateFontName||i.fontName,fontPath:i.templateFontPath.replace(/\/?$/u,`/`),svgFontId:i.fontId||i.fontName},h,{fonts:Object.fromEntries(new Map(c.map(e=>[e,()=>f(e,s)])))},{unicodeRange:d(i.unicodeRange,g)},{templateFontLigatures:i.templateFontLigatures!==!1}]);for(let e of l){let t,i;if(Object.keys(u).includes(e)){m=!0,i=e;let o=n.default.resolve(__dirname,`../..`);r.default.configure(o),t=a(e)}else{let i=n.default.resolve(e);r.default.configure(n.default.dirname(i)),t=n.default.resolve(i)}p.push({template:e,content:r.default.render(t,_),builtIn:i})}return{templates:p,usedBuildInTemplate:m}};exports.renderTemplates=p;
|