@xingwangzhe/stalux 1.5.3 → 1.5.4
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-subset.ts +46 -61
package/package.json
CHANGED
|
@@ -357,79 +357,64 @@ export async function runFontSubsetting(
|
|
|
357
357
|
const postMap: Record<string, string> = {};
|
|
358
358
|
|
|
359
359
|
let subsetCount = 0;
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
.
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
360
|
+
|
|
361
|
+
if (!skipPerRoute) {
|
|
362
|
+
for (const [hash, routes] of groups) {
|
|
363
|
+
const filename = `subset-${hash}.ttf`;
|
|
364
|
+
const outPath = join(outDir, filename);
|
|
365
|
+
if (!existsSync(outPath)) {
|
|
366
|
+
const route = routeSets.find((r) => r.hash === hash);
|
|
367
|
+
const chars = route?.chars ?? "";
|
|
368
|
+
const uniqueChars = chars
|
|
369
|
+
.split("")
|
|
370
|
+
.filter((ch) => !commonChars.includes(ch))
|
|
371
|
+
.join("");
|
|
372
|
+
if (uniqueChars.length > 0) {
|
|
373
|
+
const glyphs = get_glyph_ids(uniqueChars, "stalux", "normal", 400);
|
|
374
|
+
if (glyphs.length > 0) {
|
|
375
|
+
const result = subset_font_full("stalux", "normal", 400, 0, glyphs);
|
|
376
|
+
writeFileSync(outPath, result.fontBytes);
|
|
377
|
+
subsetCount++;
|
|
378
|
+
logger.info(
|
|
379
|
+
` subset ${subsetCount}: ${(result.fontBytes.length / 1024).toFixed(1)} KB → ${filename}`,
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
382
|
}
|
|
383
383
|
}
|
|
384
|
-
}
|
|
385
384
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
385
|
+
// Generate per-route CSS (each route gets its own CSS file)
|
|
386
|
+
// If no unique chars, reference the common TTF as fallback
|
|
387
|
+
const refTtf = existsSync(outPath) ? filename : commonFilename;
|
|
389
388
|
for (const route of routes) {
|
|
390
389
|
const cssContent = `/* Auto-generated font subset for route: ${route} */
|
|
391
390
|
@font-face {
|
|
392
391
|
font-family: "LXGW WenKai Subset";
|
|
393
|
-
src: url("/fonts/${
|
|
392
|
+
src: url("/fonts/${refTtf}") format("truetype");
|
|
394
393
|
font-display: swap;
|
|
395
394
|
}
|
|
396
395
|
`;
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
postMap[abbrlink] = cssFilename;
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
} else {
|
|
409
|
-
// CSS already generated, just map
|
|
410
|
-
for (const route of routes) {
|
|
411
|
-
const cssFilename =
|
|
412
|
-
routes.length === 1
|
|
413
|
-
? `subset-${route.replace("/", "-")}.css`
|
|
414
|
-
: `subset-group-${hash}.css`;
|
|
415
|
-
routeMap[route] = cssFilename;
|
|
416
|
-
if (route.startsWith("posts/")) {
|
|
417
|
-
postMap[route.replace("posts/", "")] = cssFilename;
|
|
418
|
-
}
|
|
396
|
+
const cssName = route.replace("/", "-");
|
|
397
|
+
const cssFilename = `subset-${cssName}.css`;
|
|
398
|
+
writeFileSync(join(outDir, cssFilename), cssContent);
|
|
399
|
+
routeMap[route] = cssFilename;
|
|
400
|
+
|
|
401
|
+
if (route.startsWith("posts/")) {
|
|
402
|
+
const abbrlink = route.replace("posts/", "");
|
|
403
|
+
postMap[abbrlink] = cssFilename;
|
|
419
404
|
}
|
|
420
405
|
}
|
|
421
406
|
}
|
|
422
|
-
}
|
|
423
407
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
408
|
+
// 6. Generate manifest
|
|
409
|
+
const manifest: FontManifest = {
|
|
410
|
+
common: commonFilename,
|
|
411
|
+
routes: routeMap,
|
|
412
|
+
posts: postMap,
|
|
413
|
+
};
|
|
414
|
+
writeFileSync(join(outDir, "manifest.json"), JSON.stringify(manifest, null, 2));
|
|
415
|
+
|
|
416
|
+
logger.info(
|
|
417
|
+
`Font subsetting done: ${subsetCount} route subsets + common (${(fontBuffer.length / 1024 / 1024).toFixed(1)} MB → variable)`,
|
|
418
|
+
);
|
|
419
|
+
}
|
|
435
420
|
}
|