@weasel-js/font 1.13.0 → 1.14.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.
@@ -1,6 +1,13 @@
1
1
  import { parseBmFont, cssFamilyName, faceMetricsFromTables } from './chunk-XQPRAGHF.js';
2
2
  import { createEmitter, createReflectable } from '@weasel-js/registry';
3
3
 
4
+ // src/textureCacheKey.ts
5
+ var last = { family: "", weight: NaN, style: "", key: "" };
6
+ function textureCacheKey(family, weight, style) {
7
+ if (last.family === family && last.weight === weight && last.style === style) return last.key;
8
+ last = { family, weight, style, key: `${family}|${weight}|${style}` };
9
+ return last.key;
10
+ }
4
11
  var ready = createEmitter();
5
12
  var generation = 0;
6
13
  function glyphGeneration() {
@@ -116,10 +123,10 @@ var PageSet = class {
116
123
  seen.set(pageIndex, page.version);
117
124
  return true;
118
125
  }
119
- const last = seen.get(pageIndex) ?? 0;
120
- if (last >= page.version) return true;
126
+ const last2 = seen.get(pageIndex) ?? 0;
127
+ if (last2 >= page.version) return true;
121
128
  for (const patch of page.patches) {
122
- if (patch.seq <= last) continue;
129
+ if (patch.seq <= last2) continue;
123
130
  const tight = new Uint8Array(patch.w * patch.h * n);
124
131
  for (let row = 0; row < patch.h; row++) {
125
132
  const src = ((patch.y + row) * PAGE_SIZE + patch.x) * n;
@@ -1231,8 +1238,8 @@ function closeContours(d) {
1231
1238
  function closeOne(contour) {
1232
1239
  const trimmed = contour.trimEnd();
1233
1240
  if (trimmed.length === 0) return "";
1234
- const last = trimmed[trimmed.length - 1];
1235
- return last === "Z" || last === "z" ? trimmed : `${trimmed}Z`;
1241
+ const last2 = trimmed[trimmed.length - 1];
1242
+ return last2 === "Z" || last2 === "z" ? trimmed : `${trimmed}Z`;
1236
1243
  }
1237
1244
  function glyphOutline(family, weight, style, cp) {
1238
1245
  const slot = slots.get(slotKey(family, weight, style));
@@ -1337,11 +1344,21 @@ function _resetFontOutlinesForTests() {
1337
1344
  slots.clear();
1338
1345
  warned2.clear();
1339
1346
  }
1340
- var registry = createReflectable();
1341
- var fontRegistry = registry.reflection;
1347
+
1348
+ // src/variantKey.ts
1349
+ var variantKeys = /* @__PURE__ */ new Map();
1342
1350
  function variantKey(weight, style) {
1343
- return `${weight}|${style}`;
1351
+ let byWeight = variantKeys.get(style);
1352
+ if (byWeight === void 0) variantKeys.set(style, byWeight = /* @__PURE__ */ new Map());
1353
+ let key = byWeight.get(weight);
1354
+ if (key === void 0) {
1355
+ key = `${weight}|${style}`;
1356
+ if (byWeight.size < 1024) byWeight.set(weight, key);
1357
+ }
1358
+ return key;
1344
1359
  }
1360
+ var registry = createReflectable();
1361
+ var fontRegistry = registry.reflection;
1345
1362
  function normalizeVariant(v) {
1346
1363
  return {
1347
1364
  weight: v.weight ?? 400,
@@ -1529,9 +1546,6 @@ function ensureFontTexture(family, weight, style, textureCache) {
1529
1546
  textureCache.upload(textureCacheKey(family, weight, style), entry.bitmap);
1530
1547
  return true;
1531
1548
  }
1532
- function textureCacheKey(family, weight, style) {
1533
- return `${family}|${weight}|${style}`;
1534
- }
1535
1549
  function markAllFontsNotUploaded() {
1536
1550
  }
1537
1551
  function missResolveResult(family, weight, style, suppressWarn = false) {
@@ -1660,7 +1674,7 @@ function resolveGlyphFallback(family, weight, style) {
1660
1674
  function resolveFontVariantInternal(family, weight, style, suppressWarn) {
1661
1675
  wakeDeclared(family, weight, style);
1662
1676
  const exactKey = variantKey(weight, style);
1663
- if (loads.has(`${family}|${exactKey}`) && !registry.get(family)?.has(exactKey)) {
1677
+ if (loads.size > 0 && loads.has(`${family}|${exactKey}`) && !registry.get(family)?.has(exactKey)) {
1664
1678
  return pendingMiss(family, weight, style);
1665
1679
  }
1666
1680
  const familyMap = registry.get(family);
@@ -1860,5 +1874,5 @@ function _resetDomFacesForTests() {
1860
1874
  }
1861
1875
 
1862
1876
  export { BAKE_SIZE, DEFAULT_BAKE_BUDGET, MAX_SHARP_LEVEL, PAGE_SIZE, SDF_RADIUS, __setGlyphRasterizerForTests, _getPagesForTests, _resetDomFacesForTests, _resetDynamicFontsForTests, _resetFallbackForTests, _resetFontOutlinesForTests, _resetFontRegistryForTests, claimFallbackWarning, colorPageTextureId, createOpenTypeParser, cssFontFamily, cssFontFamilyLoading, dynamicPageTextureId, ensureFontTexture, faceGeneration, faceMetricsFor, fallbackWarningClaimed, fontOutlineRegistry, fontPending, fontRegistry, getDefaultFontFamily, getFont, getFontFallbackPolicy, glyphGeneration, glyphOutline, hasFontOutlines, isCanvasFont, listCanvasFonts, listFontOutlines, listFontWeights, listFonts, loadFontOutlines, markAllFontsNotUploaded, outlineMetrics, outlineStatus, refreshCanvasFont, registerCanvasFont, registerFont, registerFontOutlines, resetBakeBudget, resolveFontVariant, resolveGlyphFallback, setDefaultFontFamily, setFontFallbackPolicy, sharpColorPageTextureId, sharperColorGlyph, subscribeGlyphReady, syncColorPageTexture, syncDynamicPageTexture, syncSharpColorPageTexture, textureCacheKey, unregisterCanvasFont, unregisterFontOutlines, warmFonts };
1863
- //# sourceMappingURL=chunk-GQJL6VVQ.js.map
1864
- //# sourceMappingURL=chunk-GQJL6VVQ.js.map
1877
+ //# sourceMappingURL=chunk-EQD3U7KB.js.map
1878
+ //# sourceMappingURL=chunk-EQD3U7KB.js.map