@weasel-js/text 1.14.2 → 1.15.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,5 +1,5 @@
1
1
  import { isSolidPaint, resolveFill, resolveScreenLength, fillHasInk, strokeHasInk, paintKey, strokeKey } from '@weasel-js/paint';
2
- import { cssFamilyName, resolveFontVariant, syntheticBoldGrowth, glyphOutline, faceMetricsOf, glyphGeneration, faceGeneration, metricsOf, warnNoMetrics, resolveColorCluster, glyphIn, resolveGlyph } from '@weasel-js/font';
2
+ import { cssFamilyName, cachedFontVariant, syntheticBoldGrowth, glyphOutline, faceMetricsOf, glyphGeneration, faceGeneration, metricsOf, warnNoMetrics, resolveColorCluster, glyphIn, resolveGlyph } from '@weasel-js/font';
3
3
  import { mergeRegion, growRegion, pathToD, pathFromD } from '@weasel-js/geom';
4
4
 
5
5
  var __defProp = Object.defineProperty;
@@ -147,7 +147,7 @@ function shapeableBytes(resolved2) {
147
147
  }
148
148
  function shapesWithFeature(family, weight, style, tag, shaper = registered) {
149
149
  if (shaper === null) return false;
150
- const bytes = shapeableBytes(resolveFontVariant(family, weight, style));
150
+ const bytes = shapeableBytes(cachedFontVariant(family, weight, style));
151
151
  return bytes !== null && shaper.hasFeature(bytes, tag);
152
152
  }
153
153
 
@@ -649,7 +649,7 @@ function within(ranges, cp2) {
649
649
  return false;
650
650
  }
651
651
  var warnedLogicalRtl = false;
652
- function warnRtlWithoutEngine(codePoints) {
652
+ function warnRtlWithoutEngine(codePoints, who = "weasel layoutRuns") {
653
653
  if (warnedLogicalRtl) return;
654
654
  for (let i = 0; i < codePoints.length; i++) {
655
655
  const cp2 = codePoints[i];
@@ -658,7 +658,7 @@ function warnRtlWithoutEngine(codePoints) {
658
658
  console.warn(
659
659
  // Naming the import in `from "<pkg>"` form would trip labkit's
660
660
  // consumer smoke test, which greps dist for that exact shape.
661
- "weasel layoutRuns: this text contains right-to-left characters but no `bidi` engine is registered, so it is being laid out in logical order \u2014 the glyphs will appear reversed. Import `bidi` out of the `@weasel-js/bidi` package and call `registerBidi(bidi)` once at startup."
661
+ `${who}: this text contains right-to-left characters but no \`bidi\` engine is registered, so it is being laid out in logical order \u2014 the glyphs will appear reversed. Import \`bidi\` out of the \`@weasel-js/bidi\` package and call \`registerBidi(bidi)\` once at startup.`
662
662
  );
663
663
  return;
664
664
  }
@@ -1197,7 +1197,7 @@ function measureRuns(runs, tabSize, pool, into, shaper = null) {
1197
1197
  let srcIndex = 0;
1198
1198
  for (let runIndex = 0; runIndex < runs.length; runIndex++) {
1199
1199
  const run = runs[runIndex];
1200
- const resolved2 = resolveFontVariant(run.fontFamily, run.fontWeight, run.fontStyle);
1200
+ const resolved2 = cachedFontVariant(run.fontFamily, run.fontWeight, run.fontStyle);
1201
1201
  const metrics = metricsOf(resolved2);
1202
1202
  if (!metrics) {
1203
1203
  warnNoMetrics(run.fontFamily, run.fontWeight, run.fontStyle);
@@ -1588,7 +1588,7 @@ function resolveLayoutOpts(opts, out = {
1588
1588
  tabSize: 0
1589
1589
  }) {
1590
1590
  out.maxWidth = opts.maxWidth;
1591
- out.alignWidth = opts.alignWidth ?? opts.maxWidth;
1591
+ storeAlignWidth(out, opts);
1592
1592
  out.lineHeight = opts.lineHeight;
1593
1593
  out.align = opts.align;
1594
1594
  out.justify = opts.justify === true || opts.align === "justify";
@@ -1598,6 +1598,10 @@ function resolveLayoutOpts(opts, out = {
1598
1598
  out.tabSize = opts.tabSize ?? DEFAULT_TAB_SIZE;
1599
1599
  return out;
1600
1600
  }
1601
+ function storeAlignWidth(out, opts) {
1602
+ if (opts.alignWidth === void 0) out.alignWidth = opts.maxWidth;
1603
+ else out.alignWidth = opts.alignWidth;
1604
+ }
1601
1605
  function layoutBidi(opts) {
1602
1606
  return opts.bidi ?? registeredBidi();
1603
1607
  }
@@ -1894,7 +1898,7 @@ function faceOutlineD(g) {
1894
1898
  return glyphOutline(family, weight, style, g.cp);
1895
1899
  }
1896
1900
  function runFaces(runs) {
1897
- const faces = runs.map((r) => faceMetricsOf(resolveFontVariant(r.fontFamily, r.fontWeight, r.fontStyle)));
1901
+ const faces = runs.map((r) => faceMetricsOf(cachedFontVariant(r.fontFamily, r.fontWeight, r.fontStyle)));
1898
1902
  return (run) => faces[run];
1899
1903
  }
1900
1904
  var isDecorated = (r) => r.underline || r.strikethrough || r.overline;
@@ -1990,7 +1994,8 @@ function entryFor(runs) {
1990
1994
  painting: null,
1991
1995
  paintedOn: null,
1992
1996
  paintedStamp: 0,
1993
- paintMin: void 0
1997
+ paintMin: void 0,
1998
+ listed: null
1994
1999
  };
1995
2000
  entries.set(runs, e);
1996
2001
  }
@@ -2001,11 +2006,15 @@ function dropEntry(runs) {
2001
2006
  if (e !== void 0) entries.delete(runs);
2002
2007
  return e;
2003
2008
  }
2004
- function giveEntry(e) {
2009
+ function emptyEntry(e) {
2005
2010
  e.generation = -1;
2006
2011
  e.painting = null;
2007
2012
  e.paintedOn = null;
2008
2013
  e.paintMin = void 0;
2014
+ e.listed = null;
2015
+ }
2016
+ function giveEntry(e) {
2017
+ emptyEntry(e);
2009
2018
  if (spare2.length < SPARE_MAX2) spare2.push(e);
2010
2019
  }
2011
2020
  function _resetRunsEntriesForTests() {
@@ -2104,12 +2113,16 @@ function cachedPaintRuns(laid, runs, opts = {}, use = "keep") {
2104
2113
  if (list.length >= PAINT_CACHE_VARIANT_LIMIT) list.shift();
2105
2114
  list.push(p);
2106
2115
  const e = mine ?? entryFor(runs);
2116
+ if (e.painting !== null && e.painting !== p) settlePainting(e.painting, runs);
2107
2117
  e.paintedOn = laid;
2108
2118
  e.paintedStamp = stamp;
2109
2119
  e.painting = p;
2110
2120
  e.paintMin = min;
2111
2121
  return handOut(p, use);
2112
2122
  }
2123
+ function settlePainting(p, runs) {
2124
+ if (p.runs === runs) keyOf(p);
2125
+ }
2113
2126
  function handOut(p, use) {
2114
2127
  if (use === "keep") p.pinned = true;
2115
2128
  return p.painted;
@@ -2183,7 +2196,7 @@ function disown(vs) {
2183
2196
  var NO_LAYOUT = { lines: [], bounds: { width: 0, height: 0 } };
2184
2197
  function fill(v, opts, bidi, laid) {
2185
2198
  v.maxWidth = opts.maxWidth;
2186
- v.alignWidth = opts.alignWidth ?? opts.maxWidth;
2199
+ storeAlignWidth(v, opts);
2187
2200
  v.lineHeight = opts.lineHeight;
2188
2201
  v.align = opts.align;
2189
2202
  v.justify = opts.justify === true || opts.align === "justify";
@@ -2197,9 +2210,9 @@ function fill(v, opts, bidi, laid) {
2197
2210
  function variant(opts, bidi, laid) {
2198
2211
  const spare4 = spareVariants.pop();
2199
2212
  if (spare4 !== void 0) return fill(spare4, opts, bidi, laid);
2200
- return {
2213
+ const v = {
2201
2214
  maxWidth: opts.maxWidth,
2202
- alignWidth: opts.alignWidth ?? opts.maxWidth,
2215
+ alignWidth: opts.maxWidth,
2203
2216
  lineHeight: opts.lineHeight,
2204
2217
  align: opts.align,
2205
2218
  justify: opts.justify === true || opts.align === "justify",
@@ -2209,6 +2222,8 @@ function variant(opts, bidi, laid) {
2209
2222
  shaper: layoutShaper(opts),
2210
2223
  laid
2211
2224
  };
2225
+ storeAlignWidth(v, opts);
2226
+ return v;
2212
2227
  }
2213
2228
  function mix(h, n) {
2214
2229
  return Math.imul(h ^ n, 16777619);
@@ -2279,7 +2294,7 @@ function cachedLayoutRuns(runs, opts, use = "keep") {
2279
2294
  return handOut2(v.laid, use);
2280
2295
  }
2281
2296
  }
2282
- const laid = structuralLayout(runs, opts, bidi, fonts);
2297
+ const laid = structuralLayout(runs, opts, bidi, fonts, entry);
2283
2298
  const vs = entry.variants;
2284
2299
  if (vs.length >= LAYOUT_CACHE_VARIANT_LIMIT) disown(vs);
2285
2300
  vs.unshift(variant(opts, bidi, laid));
@@ -2293,9 +2308,12 @@ function dropRuns(runs) {
2293
2308
  disown(entry.variants);
2294
2309
  giveEntry(entry);
2295
2310
  }
2296
- function structuralLayout(runs, opts, bidi, fonts) {
2311
+ function structuralLayout(runs, opts, bidi, fonts, entry) {
2297
2312
  if (structuralGeneration !== fonts) {
2298
- for (const s of structural) unlist(s);
2313
+ for (const s of structural) {
2314
+ unlist(s);
2315
+ s.runs = NO_RUNS;
2316
+ }
2299
2317
  structural = [];
2300
2318
  structuralGeneration = fonts;
2301
2319
  }
@@ -2316,11 +2334,29 @@ function structuralLayout(runs, opts, bidi, fonts) {
2316
2334
  filled.hash = hash;
2317
2335
  filled.runs = runs;
2318
2336
  filled.used = ++clock;
2337
+ entry.listed = filled;
2319
2338
  const cols = columnsOf(laid);
2320
2339
  if (cols !== null) cols.listed = true;
2321
2340
  if (!full) structural.push(filled);
2322
2341
  return laid;
2323
2342
  }
2343
+ function clearRuns(runs) {
2344
+ const entry = entryOf(runs);
2345
+ if (entry === void 0) return;
2346
+ const s = entry.listed;
2347
+ if (s !== null && s.runs === runs) {
2348
+ unlist(s);
2349
+ s.laid = NO_LAYOUT;
2350
+ s.runs = NO_RUNS;
2351
+ s.hash = -1;
2352
+ s.used = 0;
2353
+ }
2354
+ const p = entry.painting;
2355
+ disown(entry.variants);
2356
+ if (p !== null) settlePainting(p, runs);
2357
+ emptyEntry(entry);
2358
+ }
2359
+ var NO_RUNS = [];
2324
2360
  function structuralEntry(opts, bidi, laid) {
2325
2361
  return fill({
2326
2362
  maxWidth: 0,
@@ -2351,6 +2387,6 @@ function _resetLayoutCacheForTests() {
2351
2387
  clock = 0;
2352
2388
  }
2353
2389
 
2354
- export { BREAK_ALLOWED, BREAK_MANDATORY, DECORATION_KINDS, DEFAULT_DECORATION_METRICS, DEFAULT_TAB_SIZE, DEFAULT_TEXT_FILL, DEFAULT_TEXT_STYLE, LAYOUT_CACHE_STRUCTURAL_LIMIT, LAYOUT_CACHE_VARIANT_LIMIT, NO_BREAK, QUAD_STRIDE, _resetBidiWarningForTests, _resetLayoutCacheForTests, cachedLayoutRuns, cachedPaintRuns, decorationMetrics, decorationRule, dropRuns, emboldenGlyph, emboldenGlyphD, faceOutlineD, fontString, graphemeCount, hangs, hasGlyphQuad, isHardLineBreak, layoutRuns, lineBreakOpportunities, lineDecorations, paintRuns, paragraphDirection, registerBidi, registerShaper, resolveAlign, resolveTextStyle, resolveTextStyleInto, runFaces, shapesWithFeature, syntheticBoldOffset, tabAdvance, widthWithTabs, wrapLines };
2355
- //# sourceMappingURL=chunk-5BJN6MC6.js.map
2356
- //# sourceMappingURL=chunk-5BJN6MC6.js.map
2390
+ export { BREAK_ALLOWED, BREAK_MANDATORY, DECORATION_KINDS, DEFAULT_DECORATION_METRICS, DEFAULT_TAB_SIZE, DEFAULT_TEXT_FILL, DEFAULT_TEXT_STYLE, LAYOUT_CACHE_STRUCTURAL_LIMIT, LAYOUT_CACHE_VARIANT_LIMIT, NO_BREAK, QUAD_STRIDE, _resetBidiWarningForTests, _resetLayoutCacheForTests, cachedLayoutRuns, cachedPaintRuns, clearRuns, decorationMetrics, decorationRule, dropRuns, emboldenGlyph, emboldenGlyphD, faceOutlineD, fontString, graphemeCount, hangs, hasGlyphQuad, isHardLineBreak, layoutRuns, lineBreakOpportunities, lineDecorations, paintRuns, paragraphDirection, registerBidi, registerShaper, registeredBidi, resolveAlign, resolveTextStyle, resolveTextStyleInto, runFaces, shapesWithFeature, syntheticBoldOffset, tabAdvance, warnRtlWithoutEngine, widthWithTabs, wrapLines };
2391
+ //# sourceMappingURL=chunk-ZNSU5C43.js.map
2392
+ //# sourceMappingURL=chunk-ZNSU5C43.js.map