@weasel-js/text 1.13.0-rc.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.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { S as StyledRun, T as TextStyle, L as LaidOutRuns, R as ResolvedTextStyle, a as ResolvedRun, b as LayoutRunsOpts, c as TextPaint } from './test-seams-B0BDm36M.js';
2
- export { B as BidiAnalysis, d as BidiReordering, e as BidiResolver, D as DEFAULT_TEXT_FILL, f as DEFAULT_TEXT_STYLE, F as FontVariantCaps, g as LAYOUT_CACHE_STRUCTURAL_LIMIT, h as LAYOUT_CACHE_VARIANT_LIMIT, i as LaidOutCell, j as LaidOutLineBox, M as MARKDOWN_RUN_GRAMMAR, P as PlacedGlyph, k as RunFlag, l as RunGrammar, m as RunMarker, n as RunSourceMap, o as SCRIPT_METRICS, p as SMALL_CAPS_SCALE, q as ScriptPreset, r as SmallCapsText, s as TextAlign, t as TextDirection, u as TextTransform, v as TransformedRunText, w as cachedLayoutRuns, x as fontString, y as isBoldWeight, z as isSmallCapsLetter, A as layoutRuns, C as markdownToRuns, E as numericWeight, G as paragraphDirection, H as registerBidi, I as resolveAlign, J as resolveRunFace, K as resolveRuns, N as resolveTextStyle, O as runsToMarkdown, Q as runsToPlainText, U as scriptMetrics, V as scriptMetricsFor, W as smallCapsScale, X as smallCapsScaleFor, Y as smallCapsText, Z as toRuns, _ as transformRunTexts } from './test-seams-B0BDm36M.js';
3
- import { FaceRuleMetrics, FaceMetrics, FontStyle, BmFontChar, ResolveResult } from '@weasel-js/font';
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-DHGfE_6p.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 runsToMarkdown, Z as runsToPlainText, _ as scriptMetrics, $ as scriptMetricsFor, a0 as smallCapsScale, a1 as smallCapsScaleFor, a2 as smallCapsText, a3 as toRuns, a4 as transformRunTexts } from './test-seams-DHGfE_6p.js';
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';
6
6
  import { Mixed } from '@weasel-js/registry';
@@ -132,17 +132,30 @@ interface TextPoseLayout {
132
132
  declare function layoutTextPose(pose: TextPose, scale?: number): TextPoseLayout;
133
133
 
134
134
  /**
135
- * What to draw for laid-out text: which tier paints each glyph, which glyphs
136
- * can be staged together, and the decoration rules. Layout places the glyphs
137
- * and knows nothing of this; no decision here moves one.
135
+ * Where the shaping engine arrives, the way the bidi engine does
136
+ * (`bidiRegistry.ts`): registered once, found by every layout.
137
+ */
138
+
139
+ /**
140
+ * Give every text layout a shaping engine: `registerShaper(await
141
+ * loadShaper())`, with `loadShaper` from `@weasel-js/text-shaping`. `layoutRuns` uses
142
+ * it whenever its options carry none. Pass `null`, or call the function
143
+ * returned, to take it out again.
138
144
  *
139
- * Underline, strikethrough and overline come out as solid rectangles built
140
- * from pen positions, not from quad extents: quads exist only for glyphs with
141
- * ink, so a decorated stretch's spaces would punch holes in a rule derived
142
- * from them.
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.
143
149
  */
150
+ declare function registerShaper(shaper: TextShaper | null): () => void;
144
151
 
145
- /** One textured glyph quad, relative to the text's own top-left. */
152
+ /**
153
+ * A glyph quad as painting packs it: the numbers `LaidOutGroup.quadData`
154
+ * holds for each atlas glyph, and the object view a reader can ask for instead.
155
+ */
156
+
157
+ /** One textured glyph quad, relative to the text's own top-left: what
158
+ * `LaidOutGroup.quads` holds, read out of `quadData`. */
146
159
  interface LaidOutQuad {
147
160
  x0: number;
148
161
  y0: number;
@@ -154,10 +167,29 @@ interface LaidOutQuad {
154
167
  v1: number;
155
168
  /** The glyph's baseline. The synthetic-italic skew leans vertices about it. */
156
169
  baselineY: number;
170
+ /** The glyph's pen on that baseline, which it turns about. */
171
+ penX: number;
172
+ /** Degrees the quad turns, clockwise about `(penX, baselineY)`, after the
173
+ * skew. 0 is upright. */
174
+ rotate: number;
157
175
  /** On a `'color'` group's quads, the glyph's record, which a renderer drawing
158
176
  * it larger than its bake asks for a sharper one (`sharperColorGlyph`). */
159
177
  colorGlyph?: BmFontChar;
160
178
  }
179
+ /** Numbers per quad in `LaidOutGroup.quadData`. */
180
+ declare const QUAD_STRIDE = 11;
181
+
182
+ /**
183
+ * What to draw for laid-out text: which tier paints each glyph, which glyphs
184
+ * can be staged together, and the decoration rules. Layout places the glyphs
185
+ * and knows nothing of this; no decision here moves one.
186
+ *
187
+ * Underline, strikethrough and overline come out as solid rectangles built
188
+ * from pen positions, not from quad extents: quads exist only for glyphs with
189
+ * ink, so a decorated stretch's spaces would punch holes in a rule derived
190
+ * from them.
191
+ */
192
+
161
193
  /**
162
194
  * One glyph the renderer should tessellate rather than sample.
163
195
  *
@@ -176,6 +208,9 @@ interface LaidOutOutlineGlyph {
176
208
  baselineY: number;
177
209
  /** World units per em — the glyph's `fontSize`, since em space is unit-scale. */
178
210
  scale: number;
211
+ /** Degrees the glyph turns, clockwise about the pen, after any synthetic
212
+ * italic shear. Absent is upright. */
213
+ rotate?: number;
179
214
  }
180
215
  /**
181
216
  * Glyphs that share a resolved face, glyph source and paint, so a renderer
@@ -213,8 +248,15 @@ interface LaidOutGroup {
213
248
  * run onto the outline tier at any size. A run the tier cannot serve at all
214
249
  * (no registered outlines) stays on the atlas, unstroked. */
215
250
  stroke?: Stroke;
216
- /** Textured glyph quads. Always empty for an `'outline'` group. */
217
- quads: LaidOutQuad[];
251
+ /** Textured glyph quads, {@link QUAD_STRIDE} numbers each, in
252
+ * `LaidOutQuad`'s field order: `x0 y0 x1 y1 u0 v0 u1 v1 baselineY penX rotate`. What
253
+ * a painter reads; `quads` is a view of it. Empty for an `'outline'` group. */
254
+ quadData: readonly number[];
255
+ /** On a `'color'` group, each quad's glyph record, which a renderer drawing
256
+ * it larger than its bake asks for a sharper one (`sharperColorGlyph`). */
257
+ colorGlyphs?: readonly BmFontChar[];
258
+ /** The same quads as objects, built on first read. */
259
+ readonly quads: LaidOutQuad[];
218
260
  /** Outline geometry. Always empty for an `'atlas'` / `'canvas'` group. */
219
261
  glyphs: LaidOutOutlineGlyph[];
220
262
  }
@@ -261,9 +303,11 @@ declare function paintRuns(laid: LaidOutRuns, runs: readonly ResolvedRun[], opts
261
303
  * threshold's effect, and the glyphs available are what they were. `laid` must
262
304
  * be the layout of `runs`, as for `paintRuns`.
263
305
  *
264
- * **The result is shared and must be treated as immutable.**
306
+ * **The result is shared and must be treated as immutable.** `use` is as for
307
+ * `cachedLayoutRuns`: a `'read'` painting's quads go back to the pool with its
308
+ * layout.
265
309
  */
266
- declare function cachedPaintRuns(laid: LaidOutRuns, runs: readonly ResolvedRun[], opts?: PaintRunsOpts): PaintedRuns;
310
+ declare function cachedPaintRuns(laid: LaidOutRuns, runs: readonly ResolvedRun[], opts?: PaintRunsOpts, use?: CacheUse): PaintedRuns;
267
311
 
268
312
  /**
269
313
  * Wrap-aware text measurement for a 2D context. Lines end where `layoutRuns`
@@ -661,6 +705,10 @@ declare function setFlagOverRange(runs: readonly StyledRun[], style: TextStyle,
661
705
  */
662
706
  declare const SYNTHETIC_ITALIC_RADIANS = 0.2094;
663
707
 
708
+ /** A glyph turned `rotate` degrees, clockwise with y down, as the cosine and
709
+ * sine its points turn by: `x' = x·cos − y·sin`, `y' = x·sin + y·cos`. */
710
+ declare function glyphTurn(rotate: number | undefined): readonly [number, number];
711
+
664
712
  /**
665
713
  * Synthetic bold as geometry. The renderer fakes a missing bold face by
666
714
  * dropping the distance-field threshold, which moves every edge of the glyph
@@ -716,6 +764,13 @@ declare class TextOutlinesError extends Error {
716
764
  readonly style: FontStyle;
717
765
  constructor(reason: TextOutlinesFailure, family: string, weight: number, style: FontStyle, detail: string, caller?: string);
718
766
  }
767
+ /**
768
+ * `d`, the em-space outline data of `g`'s glyph, set where the renderer's
769
+ * outline tier draws it: wound positive, grown for synthetic bold, sheared
770
+ * for synthetic italic, turned by `g.rotate`, at the pen `(g.x + dx, g.baselineY + dy)`. For a
771
+ * caller reading `d` from a source of its own rather than the registered face.
772
+ */
773
+ declare function glyphOutlineAt(d: string, g: PlacedGlyph, dx: number, dy: number): PolygonPath;
719
774
 
720
775
  /**
721
776
  * Text as path geometry: the glyph outlines a text node draws, placed in
@@ -800,6 +855,22 @@ interface TextCluster {
800
855
  paths: TextPaintPath[];
801
856
  /** Height of the x-height's middle above the baseline. */
802
857
  middle: number;
858
+ /** The decoration rules crossing the slot, cut to it, in the frame `paths` use; underline, then strikethrough, then
859
+ * overline. A rule running on into the next slot ends at `advance` here and starts at 0 there. */
860
+ rules: TextClusterRule[];
861
+ }
862
+ /** The stretch of one decoration rule inside a cluster's slot. */
863
+ interface TextClusterRule {
864
+ kind: DecorationKind;
865
+ /** Its ends along the slot, 0..`advance`. */
866
+ x0: number;
867
+ x1: number;
868
+ /** Its top and bottom edges, y down from the baseline. */
869
+ y0: number;
870
+ y1: number;
871
+ /** The paint its run wears, as the cluster's `paths` carry it. */
872
+ fill: Fill | null;
873
+ stroke?: Stroke;
803
874
  }
804
875
  /** Options for {@link textClusters}. */
805
876
  interface TextClustersOptions extends TextToPathOptions {
@@ -813,13 +884,18 @@ interface TextClustersOptions extends TextToPathOptions {
813
884
  * laid at the node's box origin with no pose applied; the lines after it are
814
885
  * dropped. The slots tile the
815
886
  * line: each cluster's `advance` runs to the next one's `x`, so the kerning
816
- * between two clusters belongs to the left one. Decoration rules are left out.
887
+ * between two clusters belongs to the left one. A decoration rule is cut into
888
+ * the slots it crosses (`rules`).
817
889
  *
818
890
  * Throws `TextOutlinesError` as `textToPath` does, except that a color
819
891
  * glyph, or one drawn by a fallback face with no outlines, keeps its slot
820
892
  * with no `paths`. Only a code point that inks its slot is drawn, so a color
821
893
  * cluster's leading code points stay blank too.
894
+ *
895
+ * Remembered per `data` object: the same `data`, `width` and `scale` hand
896
+ * back the same array until a face or glyph changes, so treat `data` as
897
+ * immutable and don't mutate the result. A throw is not remembered.
822
898
  */
823
899
  declare function textClusters(data: TextOutlineSource, opts?: TextClustersOptions): TextCluster[];
824
900
 
825
- export { BREAK_ALLOWED, BREAK_MANDATORY, DEFAULT_DECORATION_METRICS, type DecorationKind, type FaceMetricsFn, type FitTextPoseOptions, type FlagKey, type LabelOptions, type LaidOutDecoration, type LaidOutGroup, type LaidOutOutlineGlyph, type LaidOutQuad, LaidOutRuns, type LayoutLine, type LayoutResult, LayoutRunsOpts, type MarkdownFontOptions, type MeasureFn, type MeasureTextBoundsOpts, type MeasuredSpan, type MeasuredText, NO_BREAK, type PaintRunsOpts, type PaintedRuns, type PointInTextPoseOpts, type PositionedRun, type RangeStyle, ResolvedRun, ResolvedTextStyle, type RunStylePatch, SYNTHETIC_ITALIC_RADIANS, type SetFlagResult, type StyleKey, StyledRun, type TextCluster, type TextClustersOptions, type TextLineBoxesOpts, type TextNodeSource, type TextOutlineSource, TextOutlinesError, type TextOutlinesFailure, TextPaint, type TextPaintPath, type TextPose, type TextPoseLayout, type TextPoseLayoutInput, type TextRenderer, TextStyle, type TextToPathOptions, type TextVerticalAlign, applyStyleToRange, cachedPaintRuns, caretIndexAt, createMarkdownRenderer, decorationMetrics, defaultLabelTextRenderer, effectiveRangeStyle, emboldenGlyphD, fitTextPose, isHardLineBreak, isTextData, layoutMarkdown, layoutTextPose, lineBreakOpportunities, loadTextOutlines, measureText, measureTextBounds, measuredWidth, nodeHasFlag, paintRuns, patchRangeStyle, pointInTextPose, rangeWeight, renderLabel, runsCarryStyling, setFlagOverRange, styleAtRange, supersededKey, syntheticBoldOffset, textClusters, textLineBoxes, textPoseLayoutInput, textToPath, textToPathsByPaint, unboldPatch, verticalAlignOffset };
901
+ export { BREAK_ALLOWED, BREAK_MANDATORY, CacheUse, DEFAULT_DECORATION_METRICS, type DecorationKind, type FaceMetricsFn, type FitTextPoseOptions, type FlagKey, type LabelOptions, type LaidOutDecoration, type LaidOutGroup, type LaidOutOutlineGlyph, type LaidOutQuad, LaidOutRuns, type LayoutLine, type LayoutResult, LayoutRunsOpts, type MarkdownFontOptions, type MeasureFn, type MeasureTextBoundsOpts, type MeasuredSpan, type MeasuredText, NO_BREAK, type PaintRunsOpts, type PaintedRuns, PlacedGlyph, type PointInTextPoseOpts, type PositionedRun, QUAD_STRIDE, type RangeStyle, ResolvedRun, ResolvedTextStyle, type RunStylePatch, SYNTHETIC_ITALIC_RADIANS, type SetFlagResult, type StyleKey, StyledRun, type TextCluster, type TextClusterRule, type TextClustersOptions, type TextLineBoxesOpts, type TextNodeSource, type TextOutlineSource, TextOutlinesError, type TextOutlinesFailure, TextPaint, type TextPaintPath, type TextPose, type TextPoseLayout, type TextPoseLayoutInput, type TextRenderer, TextShaper, TextStyle, type TextToPathOptions, type TextVerticalAlign, applyStyleToRange, cachedPaintRuns, caretIndexAt, createMarkdownRenderer, decorationMetrics, defaultLabelTextRenderer, effectiveRangeStyle, emboldenGlyphD, fitTextPose, glyphOutlineAt, glyphTurn, isHardLineBreak, isTextData, layoutMarkdown, layoutTextPose, lineBreakOpportunities, loadTextOutlines, measureText, measureTextBounds, measuredWidth, nodeHasFlag, paintRuns, patchRangeStyle, pointInTextPose, rangeWeight, registerShaper, renderLabel, runsCarryStyling, setFlagOverRange, styleAtRange, supersededKey, syntheticBoldOffset, textClusters, textLineBoxes, textPoseLayoutInput, textToPath, textToPathsByPaint, unboldPatch, verticalAlignOffset };