@turntrout/subfont 1.3.2 → 1.3.3
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/lib/subfont.js +10 -0
- package/lib/warnAboutMissingGlyphs.js +30 -28
- package/package.json +1 -1
package/lib/subfont.js
CHANGED
|
@@ -52,6 +52,16 @@ module.exports = async function subfont(
|
|
|
52
52
|
);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
// Prevent postcss plugins (colormin, convert-values, etc.) invoked by
|
|
56
|
+
// cssnano from walking the filesystem for a "browserslist" config.
|
|
57
|
+
// Under pnpm, `node_modules/.bin/browserslist` is a shell shim that
|
|
58
|
+
// browserslist mis-parses as browser queries, throwing
|
|
59
|
+
// BrowserslistError and silently aborting CSS minification.
|
|
60
|
+
// Setting BROWSERSLIST short-circuits the walk entirely.
|
|
61
|
+
if (!process.env.BROWSERSLIST && !process.env.BROWSERSLIST_CONFIG) {
|
|
62
|
+
process.env.BROWSERSLIST = 'defaults';
|
|
63
|
+
}
|
|
64
|
+
|
|
55
65
|
const formats = ['woff2'];
|
|
56
66
|
|
|
57
67
|
function logToConsole(severity, ...args) {
|
|
@@ -60,43 +60,43 @@ async function warnAboutMissingGlyphs(
|
|
|
60
60
|
const isMissing = !characterSetLookup.has(codePoint);
|
|
61
61
|
|
|
62
62
|
if (isMissing) {
|
|
63
|
-
//
|
|
64
|
-
//
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
// Report only the first location plus a count of remaining
|
|
64
|
+
// occurrences. A character like U+200B can appear thousands of
|
|
65
|
+
// times on a page and per-occurrence lines drown the log.
|
|
66
|
+
let firstLocation;
|
|
67
|
+
let occurrences = 0;
|
|
67
68
|
if (char.length > 0) {
|
|
69
|
+
const sourceText = htmlOrSvgAsset.text;
|
|
68
70
|
let searchIdx = 0;
|
|
69
71
|
while (true) {
|
|
70
72
|
const charIdx = sourceText.indexOf(char, searchIdx);
|
|
71
73
|
if (charIdx === -1) break;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
+
occurrences++;
|
|
75
|
+
if (occurrences === 1) {
|
|
76
|
+
if (!linesAndColumns) {
|
|
77
|
+
linesAndColumns = new LinesAndColumns(sourceText);
|
|
78
|
+
}
|
|
79
|
+
const position = linesAndColumns.locationForIndex(charIdx);
|
|
80
|
+
firstLocation = `${htmlOrSvgAsset.urlOrDescription}:${
|
|
81
|
+
position.line + 1
|
|
82
|
+
}:${position.column + 1}`;
|
|
74
83
|
}
|
|
75
|
-
const position = linesAndColumns.locationForIndex(charIdx);
|
|
76
|
-
locations.push(
|
|
77
|
-
`${htmlOrSvgAsset.urlOrDescription}:${position.line + 1}:${
|
|
78
|
-
position.column + 1
|
|
79
|
-
}`
|
|
80
|
-
);
|
|
81
84
|
searchIdx = charIdx + char.length;
|
|
82
85
|
}
|
|
83
86
|
}
|
|
84
87
|
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
`${htmlOrSvgAsset.urlOrDescription} (generated content)`
|
|
88
|
-
);
|
|
88
|
+
if (!firstLocation) {
|
|
89
|
+
firstLocation = `${htmlOrSvgAsset.urlOrDescription} (generated content)`;
|
|
89
90
|
}
|
|
90
91
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
92
|
+
missingGlyphsErrors.push({
|
|
93
|
+
codePoint,
|
|
94
|
+
char,
|
|
95
|
+
htmlOrSvgAsset,
|
|
96
|
+
fontUsage,
|
|
97
|
+
location: firstLocation,
|
|
98
|
+
occurrences,
|
|
99
|
+
});
|
|
100
100
|
missedAny = true;
|
|
101
101
|
}
|
|
102
102
|
}
|
|
@@ -123,12 +123,14 @@ async function warnAboutMissingGlyphs(
|
|
|
123
123
|
|
|
124
124
|
if (missingGlyphsErrors.length) {
|
|
125
125
|
const errorLog = missingGlyphsErrors.map(
|
|
126
|
-
({ char, fontUsage, location }) =>
|
|
127
|
-
|
|
126
|
+
({ char, fontUsage, location, occurrences }) => {
|
|
127
|
+
const extra = occurrences > 1 ? ` (+${occurrences - 1} more)` : '';
|
|
128
|
+
return `- \\u{${char.codePointAt(0).toString(16)}} (${char}) in font-family '${
|
|
128
129
|
fontUsage.props['font-family']
|
|
129
130
|
}' (${fontUsage.props['font-weight']}/${
|
|
130
131
|
fontUsage.props['font-style']
|
|
131
|
-
}) at ${location}
|
|
132
|
+
}) at ${location}${extra}`;
|
|
133
|
+
}
|
|
132
134
|
);
|
|
133
135
|
|
|
134
136
|
const message = `Missing glyph fallback detected.
|
package/package.json
CHANGED