@xingwangzhe/stalux 1.30.1 → 1.30.2
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/package.json +1 -1
- package/src/internal/font-slices.ts +14 -1
package/package.json
CHANGED
|
@@ -34,6 +34,17 @@ const CODE_FONT_ITALIC_INPUT = "src/assets/fonts/GoogleSansCode-Italic.woff2";
|
|
|
34
34
|
|
|
35
35
|
const PAGE_SLICE_OUT_DIR = "node_modules/.astro/stalux-page-fonts";
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Characters always reserved in every page subset, regardless of page content.
|
|
39
|
+
*
|
|
40
|
+
* Digits are extracted from rendered text nodes, so any number produced at
|
|
41
|
+
* runtime (clock, counters, dates, values injected by client scripts) or
|
|
42
|
+
* carried only in attributes would fall outside the subset and render as
|
|
43
|
+
* fallback glyphs — a visible "font splitting" bug. Reserving 0-9 costs
|
|
44
|
+
* ~10 glyphs per page and makes digit rendering unconditional.
|
|
45
|
+
*/
|
|
46
|
+
export const RESERVED_GLYPHS = "0123456789";
|
|
47
|
+
|
|
37
48
|
// ---------------------------------------------------------------------------
|
|
38
49
|
// Types
|
|
39
50
|
// ---------------------------------------------------------------------------
|
|
@@ -242,6 +253,7 @@ export function writePageFontSubset(
|
|
|
242
253
|
cacheDir: string,
|
|
243
254
|
publicUrlPrefix = "/_astro/fonts/",
|
|
244
255
|
linkedStylesheetText = "",
|
|
256
|
+
extraChars = "",
|
|
245
257
|
): PageFontSubset | undefined {
|
|
246
258
|
const document = parse(html);
|
|
247
259
|
const body = findBody(document);
|
|
@@ -254,7 +266,8 @@ export function writePageFontSubset(
|
|
|
254
266
|
linkedStylesheetText,
|
|
255
267
|
];
|
|
256
268
|
collectBodyText(body, bodyText);
|
|
257
|
-
const
|
|
269
|
+
const glyphSource = `${RESERVED_GLYPHS}${extraChars}${bodyText.join("")}`;
|
|
270
|
+
const chars = [...new Set([...glyphSource].filter((char) => !/\p{C}/u.test(char)))].sort(
|
|
258
271
|
(a, b) => (a.codePointAt(0) as number) - (b.codePointAt(0) as number),
|
|
259
272
|
);
|
|
260
273
|
if (chars.length === 0) return undefined;
|