@weasel-js/text 1.14.2 → 1.15.1

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/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as StyledRun, T as TextStyle, L as LaidOutRuns, R as ResolvedTextStyle, a as ResolvedRun, b as LayoutRunsOpts, c as TextShaper, C as CacheUse, d as TextPaint, P as PlacedGlyph } from './test-seams-D6uEFbAw.js';
2
- export { B as BidiAnalysis, e as BidiReordering, f as BidiResolver, D as DEFAULT_TEXT_FILL, g as DEFAULT_TEXT_STYLE, F as FontVariantCaps, h as LAYOUT_CACHE_STRUCTURAL_LIMIT, i as LAYOUT_CACHE_VARIANT_LIMIT, j as LaidOutCell, k as LaidOutLineBox, M as MARKDOWN_RUN_GRAMMAR, l as RunFlag, m as RunGrammar, n as RunMarker, o as RunSourceMap, p as SCRIPT_METRICS, q as SMALL_CAPS_SCALE, r as ScriptPreset, s as ShapedCluster, t as ShapedGlyph, u as SmallCapsText, v as TextAlign, w as TextDirection, x as TextTransform, y as TransformedRunText, z as cachedLayoutRuns, A as dropRuns, E as fontString, G as halfLeadingFor, H as isBoldWeight, I as isSmallCapsLetter, J as layoutRuns, K as markdownToRuns, N as numericWeight, O as paragraphDirection, Q as registerBidi, U as resolveAlign, V as resolveRunFace, W as resolveRuns, X as resolveTextStyle, Y as resolveTextStyleInto, Z as runsToMarkdown, _ as runsToPlainText, $ as scriptMetrics, a0 as scriptMetricsFor, a1 as smallCapsScale, a2 as smallCapsScaleFor, a3 as smallCapsText, a4 as toRuns, a5 as transformRunTexts } from './test-seams-D6uEFbAw.js';
1
+ import { S as StyledRun, T as TextStyle, L as LaidOutRuns, R as ResolvedTextStyle, a as ResolvedRun, b as LayoutRunsOpts, c as TextShaper, C as CacheUse, d as TextPaint, P as PlacedGlyph } from './test-seams-B2R_EedN.js';
2
+ export { B as BidiAnalysis, e as BidiReordering, f as BidiResolver, D as DEFAULT_TEXT_FILL, g as DEFAULT_TEXT_STYLE, F as FontVariantCaps, h as LAYOUT_CACHE_STRUCTURAL_LIMIT, i as LAYOUT_CACHE_VARIANT_LIMIT, j as LaidOutCell, k as LaidOutLineBox, M as MARKDOWN_RUN_GRAMMAR, l as RunFlag, m as RunGrammar, n as RunMarker, o as RunSourceMap, p as SCRIPT_METRICS, q as SMALL_CAPS_SCALE, r as ScriptPreset, s as ShapedCluster, t as ShapedGlyph, u as SmallCapsText, v as TextAlign, w as TextDirection, x as TextTransform, y as TransformedRunText, z as cachedLayoutRuns, A as clearRuns, E as dropRuns, G as fontString, H as halfLeadingFor, I as isBoldWeight, J as isSmallCapsLetter, K as layoutRuns, N as markdownToRuns, O as numericWeight, Q as paragraphDirection, U as registerBidi, V as registeredBidi, W as resolveAlign, X as resolveRunFace, Y as resolveRuns, Z as resolveRunsInto, _ as resolveTextStyle, $ as resolveTextStyleInto, a0 as runsToMarkdown, a1 as runsToPlainText, a2 as scriptMetrics, a3 as scriptMetricsFor, a4 as smallCapsScale, a5 as smallCapsScaleFor, a6 as smallCapsText, a7 as toRuns, a8 as transformRunTexts, a9 as warnRtlWithoutEngine } from './test-seams-B2R_EedN.js';
3
3
  import { FaceRuleMetrics, FaceMetrics, BmFontChar, FontStyle, ResolveResult } from '@weasel-js/font';
4
4
  import { Fill, Stroke } from '@weasel-js/paint';
5
5
  import { Rect, PolygonPath, PathInWorldPose } from '@weasel-js/geom';
@@ -142,10 +142,13 @@ declare function layoutTextPose(pose: TextPose, scale?: number): TextPoseLayout;
142
142
  * it whenever its options carry none. Pass `null`, or call the function
143
143
  * returned, to take it out again.
144
144
  *
145
- * Shaping reaches the text whose face was registered with
146
- * `registerFontOutlines` from TrueType or OpenType bytes: those are the faces
147
- * whose glyphs are drawn by index. Text drawn from a baked or canvas atlas,
148
- * whose glyphs are looked up by code point, is laid out as before.
145
+ * Shaping reaches the text whose face has TrueType or OpenType bytes behind
146
+ * it: a face registered with `registerFontOutlines` alone, or a baked or
147
+ * canvas atlas face whose exact variant is also registered there. The atlas
148
+ * must be cut from that same file, or its advances disagree with the
149
+ * shaper's. On an atlas face, a cluster the shaping left as its code point's
150
+ * own glyph draws from the atlas as before; the rest draw from the shaper's
151
+ * glyphs.
149
152
  */
150
153
  declare function registerShaper(shaper: TextShaper | null): () => void;
151
154
 
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { DEFAULT_TAB_SIZE, shapesWithFeature, resolveTextStyle, cachedLayoutRuns, graphemeCount, wrapLines, hangs, emboldenGlyph, layoutRuns, lineDecorations, runFaces, tabAdvance, widthWithTabs, DECORATION_KINDS, decorationRule, faceOutlineD, hasGlyphQuad } from './chunk-5BJN6MC6.js';
2
- export { BREAK_ALLOWED, BREAK_MANDATORY, DEFAULT_DECORATION_METRICS, DEFAULT_TEXT_FILL, DEFAULT_TEXT_STYLE, LAYOUT_CACHE_STRUCTURAL_LIMIT, LAYOUT_CACHE_VARIANT_LIMIT, NO_BREAK, QUAD_STRIDE, cachedLayoutRuns, cachedPaintRuns, decorationMetrics, dropRuns, emboldenGlyphD, fontString, isHardLineBreak, layoutRuns, lineBreakOpportunities, paintRuns, paragraphDirection, registerBidi, registerShaper, resolveAlign, resolveTextStyle, resolveTextStyleInto, syntheticBoldOffset } from './chunk-5BJN6MC6.js';
1
+ import { DEFAULT_TAB_SIZE, shapesWithFeature, resolveTextStyle, cachedLayoutRuns, graphemeCount, wrapLines, hangs, emboldenGlyph, layoutRuns, lineDecorations, runFaces, tabAdvance, widthWithTabs, DECORATION_KINDS, decorationRule, faceOutlineD, hasGlyphQuad } from './chunk-WUFANHTE.js';
2
+ export { BREAK_ALLOWED, BREAK_MANDATORY, DEFAULT_DECORATION_METRICS, DEFAULT_TEXT_FILL, DEFAULT_TEXT_STYLE, LAYOUT_CACHE_STRUCTURAL_LIMIT, LAYOUT_CACHE_VARIANT_LIMIT, NO_BREAK, QUAD_STRIDE, cachedLayoutRuns, cachedPaintRuns, clearRuns, decorationMetrics, dropRuns, emboldenGlyphD, fontString, isHardLineBreak, layoutRuns, lineBreakOpportunities, paintRuns, paragraphDirection, registerBidi, registerShaper, registeredBidi, resolveAlign, resolveTextStyle, resolveTextStyleInto, syntheticBoldOffset, warnRtlWithoutEngine } from './chunk-WUFANHTE.js';
3
3
  import { resolveScreenLength, paintKey, strokeKey } from '@weasel-js/paint';
4
- import { faceMetricsOf, resolveFontVariant, loadFontOutlines, glyphGeneration, faceMetricsFor, outlineStatus, cssFamilyName } from '@weasel-js/font';
4
+ import { faceMetricsOf, cachedFontVariant, loadFontOutlines, glyphGeneration, faceMetricsFor, outlineStatus, cssFamilyName } from '@weasel-js/font';
5
5
  import { MIXED, deepEqual } from '@weasel-js/registry';
6
6
  export { MIXED } from '@weasel-js/registry';
7
7
  import { transformPath, joinPaths, pathFromD, pathSignedArea, reversePath, poseFrameOf, originFor, coordsFrom, PATH_M, PATH_L, PATH_Z } from '@weasel-js/geom';
@@ -262,7 +262,7 @@ function smallCapsScale(face) {
262
262
  return x / cap;
263
263
  }
264
264
  function smallCapsScaleFor(family, weight, style) {
265
- return smallCapsScale(faceMetricsOf(resolveFontVariant(family, weight, style)));
265
+ return smallCapsScale(faceMetricsOf(cachedFontVariant(family, weight, style)));
266
266
  }
267
267
  function isSmallCapsLetter(ch, lang) {
268
268
  return ch.toLocaleUpperCase(caseLocale(lang)) !== ch;
@@ -317,10 +317,10 @@ function scriptMetrics(face) {
317
317
  return out;
318
318
  }
319
319
  function scriptMetricsFor(family, weight, style) {
320
- return scriptMetrics(faceMetricsOf(resolveFontVariant(family, weight, style)));
320
+ return scriptMetrics(faceMetricsOf(cachedFontVariant(family, weight, style)));
321
321
  }
322
322
  function halfLeadingFor(family, weight, style, fontSize, lineHeight) {
323
- const m = faceMetricsOf(resolveFontVariant(family, weight, style));
323
+ const m = faceMetricsOf(cachedFontVariant(family, weight, style));
324
324
  if (m?.ascent === void 0 || m.descent === void 0) return void 0;
325
325
  return (lineHeight - m.ascent - m.descent) / 2 * fontSize;
326
326
  }
@@ -342,7 +342,10 @@ function resolveRunFace(run, style) {
342
342
  };
343
343
  }
344
344
  function resolveRuns(runs, style, viewScale = 1) {
345
- const out = new Array(runs.length);
345
+ return resolveRunsInto(new Array(runs.length), runs, style, viewScale);
346
+ }
347
+ function resolveRunsInto(out, runs, style, viewScale = 1) {
348
+ if (out.length !== runs.length) out.length = runs.length;
346
349
  let transformed = false;
347
350
  for (const r of runs) if ((r.textTransform ?? style.textTransform) !== "none") transformed = true;
348
351
  const shown = transformed ? transformRunTexts(
@@ -376,26 +379,53 @@ function resolveRuns(runs, style, viewScale = 1) {
376
379
  }
377
380
  }
378
381
  const lang = run.lang ?? style.lang;
382
+ const fill = run.fill !== void 0 ? run.fill : style.fill;
383
+ const letterSpacing = run.letterSpacing !== void 0 ? resolveScreenLength(run.letterSpacing, viewScale) : style.letterSpacing;
384
+ const underline = run.underline || style.underline;
385
+ const strikethrough = run.strikethrough || style.strikethrough;
386
+ const overline = run.overline || style.overline;
387
+ const stroke = run.stroke ?? style.stroke;
388
+ const rotate = run.rotate && Number.isFinite(run.rotate) ? run.rotate : void 0;
389
+ const prev = out[i];
390
+ if (prev !== void 0 && prev.srcMap !== void 0 === (srcMap !== void 0) && prev.sizeMap !== void 0 === (sizeMap !== void 0) && prev.stroke !== void 0 === (stroke !== void 0) && prev.strutSize !== void 0 === relative && prev.rotate !== void 0 === (rotate !== void 0) && prev.fontFeatures !== void 0 === (fontFeatures !== void 0) && prev.lang !== void 0 === !!lang) {
391
+ prev.text = text;
392
+ prev.fontFamily = fontFamily;
393
+ prev.fontSize = fontSize;
394
+ prev.fontWeight = fontWeight;
395
+ prev.fontStyle = fontStyle;
396
+ prev.fill = fill;
397
+ prev.letterSpacing = letterSpacing;
398
+ prev.underline = underline;
399
+ prev.strikethrough = strikethrough;
400
+ prev.overline = overline;
401
+ prev.baselineShift = shiftEm * style.fontSize;
402
+ if (srcMap) prev.srcMap = srcMap;
403
+ if (sizeMap) prev.sizeMap = sizeMap;
404
+ if (stroke !== void 0) prev.stroke = stroke;
405
+ if (relative) prev.strutSize = style.fontSize;
406
+ if (rotate !== void 0) prev.rotate = rotate;
407
+ if (fontFeatures) prev.fontFeatures = fontFeatures;
408
+ if (lang) prev.lang = lang;
409
+ continue;
410
+ }
379
411
  const r = {
380
412
  text,
381
413
  fontFamily,
382
414
  fontSize,
383
415
  fontWeight,
384
416
  fontStyle,
385
- fill: run.fill !== void 0 ? run.fill : style.fill,
386
- letterSpacing: run.letterSpacing !== void 0 ? resolveScreenLength(run.letterSpacing, viewScale) : style.letterSpacing,
387
- // `||`, not `??`: run-level decorations are additive over the node style.
388
- underline: run.underline || style.underline,
389
- strikethrough: run.strikethrough || style.strikethrough,
390
- overline: run.overline || style.overline,
417
+ fill,
418
+ letterSpacing,
419
+ underline,
420
+ strikethrough,
421
+ overline,
391
422
  baselineShift: shiftEm * style.fontSize
392
423
  };
393
424
  if (srcMap) r.srcMap = srcMap;
394
425
  if (sizeMap) r.sizeMap = sizeMap;
395
- const stroke = run.stroke ?? style.stroke;
396
426
  if (stroke !== void 0) r.stroke = stroke;
397
427
  if (relative) r.strutSize = style.fontSize;
398
- if (run.rotate && Number.isFinite(run.rotate)) r.rotate = run.rotate;
428
+ if (rotate !== void 0) r.rotate = rotate;
399
429
  if (fontFeatures) r.fontFeatures = fontFeatures;
400
430
  if (lang) r.lang = lang;
401
431
  out[i] = r;
@@ -1110,7 +1140,7 @@ function assertOutlinable(run, caller) {
1110
1140
  void loadFontOutlines(fontFamily, { weight: fontWeight, style: fontStyle });
1111
1141
  fail("outlines-loading", "its outlines have not loaded yet; await loadTextOutlines first.");
1112
1142
  }
1113
- const r = resolveFontVariant(fontFamily, fontWeight, fontStyle);
1143
+ const r = cachedFontVariant(fontFamily, fontWeight, fontStyle);
1114
1144
  const { family, weight, style } = r.resolved;
1115
1145
  if (r.source === "outline") return;
1116
1146
  const status = outlineStatus(family, weight, style);
@@ -1200,7 +1230,7 @@ function facesOf(runs) {
1200
1230
  };
1201
1231
  for (const r of runs) {
1202
1232
  add(r.fontFamily, r.fontWeight, r.fontStyle);
1203
- const { family, weight, style } = resolveFontVariant(r.fontFamily, r.fontWeight, r.fontStyle).resolved;
1233
+ const { family, weight, style } = cachedFontVariant(r.fontFamily, r.fontWeight, r.fontStyle).resolved;
1204
1234
  add(family, weight, style);
1205
1235
  }
1206
1236
  return [...out.values()];
@@ -1358,6 +1388,6 @@ function clustersOf(data, width, scale) {
1358
1388
  });
1359
1389
  }
1360
1390
 
1361
- export { MARKDOWN_RUN_GRAMMAR, SCRIPT_METRICS, SMALL_CAPS_SCALE, SYNTHETIC_ITALIC_RADIANS, TextOutlinesError, applyStyleToRange, caretIndexAt, createMarkdownRenderer, defaultLabelTextRenderer, effectiveRangeStyle, fitTextPose, glyphOutlineAt, glyphTurn, halfLeadingFor, isBoldWeight, isSmallCapsLetter, isTextData, layoutMarkdown, layoutTextPose, loadTextOutlines, markdownToRuns, measureText, measureTextBounds, measuredWidth, nodeHasFlag, numericWeight, patchRangeStyle, pointInTextPose, rangeWeight, renderLabel, resolveRunFace, resolveRuns, runsCarryStyling, runsToMarkdown, runsToPlainText, scriptMetrics, scriptMetricsFor, setFlagOverRange, smallCapsScale, smallCapsScaleFor, smallCapsText, styleAtRange, supersededKey, textClusters, textLineBoxes, textPoseLayoutInput, textToPath, textToPathsByPaint, toRuns, transformRunTexts, unboldPatch, verticalAlignOffset };
1391
+ export { MARKDOWN_RUN_GRAMMAR, SCRIPT_METRICS, SMALL_CAPS_SCALE, SYNTHETIC_ITALIC_RADIANS, TextOutlinesError, applyStyleToRange, caretIndexAt, createMarkdownRenderer, defaultLabelTextRenderer, effectiveRangeStyle, fitTextPose, glyphOutlineAt, glyphTurn, halfLeadingFor, isBoldWeight, isSmallCapsLetter, isTextData, layoutMarkdown, layoutTextPose, loadTextOutlines, markdownToRuns, measureText, measureTextBounds, measuredWidth, nodeHasFlag, numericWeight, patchRangeStyle, pointInTextPose, rangeWeight, renderLabel, resolveRunFace, resolveRuns, resolveRunsInto, runsCarryStyling, runsToMarkdown, runsToPlainText, scriptMetrics, scriptMetricsFor, setFlagOverRange, smallCapsScale, smallCapsScaleFor, smallCapsText, styleAtRange, supersededKey, textClusters, textLineBoxes, textPoseLayoutInput, textToPath, textToPathsByPaint, toRuns, transformRunTexts, unboldPatch, verticalAlignOffset };
1362
1392
  //# sourceMappingURL=index.js.map
1363
1393
  //# sourceMappingURL=index.js.map