@xingwangzhe/stalux 1.30.1 → 1.30.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/README.md +2 -0
- package/package.json +1 -1
- package/src/internal/font-slices.ts +14 -1
package/README.md
CHANGED
|
@@ -105,6 +105,8 @@ bun run dev
|
|
|
105
105
|
|
|
106
106
|
Stalux ships with LXGW WenKai and a variable code font (Google Sans Code). During the build, the Rust/N-API package `@xingwangzhe/cjk-font-split-native` creates one content-addressed WOFF2 subset from each page's visible or expandable CJK text. The browser downloads only the page subset; repeated character sets share the same file. CJK text inside code and MathML is covered too.
|
|
107
107
|
|
|
108
|
+
Arabic digits `0-9` are always reserved in every subset (`RESERVED_GLYPHS`), even on pages without any visible number. Digits produced at runtime by client scripts — clocks, counters, dates, injected values — never appear in the built HTML, so reserving them keeps numbers from falling back to a system font. Callers can append more characters through the optional `extraChars` argument of `writePageFontSubset`.
|
|
109
|
+
|
|
108
110
|
The subset CSS uses an exact per-character `unicode-range` and `font-display: swap`, so visible text and the downloaded glyphs stay aligned. The variable code font continues to use Astro's local Fonts API.
|
|
109
111
|
|
|
110
112
|
The persistent BLAKE3 cache key includes font bytes, face index, normalized character set, and algorithm version. Cache files live under `node_modules/.astro/` and are reused across pages and incremental builds. Font inputs are read locally; builds do not fetch fonts from the network.
|
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;
|