@weasel-js/text 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.
- package/dist/chunk-FODNMBHI.js +2256 -0
- package/dist/chunk-FODNMBHI.js.map +1 -0
- package/dist/index.d.ts +83 -17
- package/dist/index.js +158 -400
- package/dist/index.js.map +1 -1
- package/dist/{test-seams-B0BDm36M.d.ts → test-seams-DHGfE_6p.d.ts} +180 -22
- package/dist/test-seams.d.ts +1 -1
- package/dist/test-seams.js +1 -1
- package/package.json +6 -6
- package/dist/chunk-DOTR55MR.js +0 -1199
- package/dist/chunk-DOTR55MR.js.map +0 -1
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-
|
|
2
|
-
export { B as BidiAnalysis,
|
|
3
|
-
import { FaceRuleMetrics, FaceMetrics,
|
|
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,14 +132,26 @@ interface TextPoseLayout {
|
|
|
132
132
|
declare function layoutTextPose(pose: TextPose, scale?: number): TextPoseLayout;
|
|
133
133
|
|
|
134
134
|
/**
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
|
|
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
|
-
*
|
|
140
|
-
* from
|
|
141
|
-
*
|
|
142
|
-
*
|
|
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.
|
|
149
|
+
*/
|
|
150
|
+
declare function registerShaper(shaper: TextShaper | null): () => void;
|
|
151
|
+
|
|
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.
|
|
143
155
|
*/
|
|
144
156
|
|
|
145
157
|
/** One textured glyph quad, relative to the text's own top-left: what
|
|
@@ -155,10 +167,29 @@ interface LaidOutQuad {
|
|
|
155
167
|
v1: number;
|
|
156
168
|
/** The glyph's baseline. The synthetic-italic skew leans vertices about it. */
|
|
157
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;
|
|
158
175
|
/** On a `'color'` group's quads, the glyph's record, which a renderer drawing
|
|
159
176
|
* it larger than its bake asks for a sharper one (`sharperColorGlyph`). */
|
|
160
177
|
colorGlyph?: BmFontChar;
|
|
161
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
|
+
|
|
162
193
|
/**
|
|
163
194
|
* One glyph the renderer should tessellate rather than sample.
|
|
164
195
|
*
|
|
@@ -177,6 +208,9 @@ interface LaidOutOutlineGlyph {
|
|
|
177
208
|
baselineY: number;
|
|
178
209
|
/** World units per em — the glyph's `fontSize`, since em space is unit-scale. */
|
|
179
210
|
scale: number;
|
|
211
|
+
/** Degrees the glyph turns, clockwise about the pen, after any synthetic
|
|
212
|
+
* italic shear. Absent is upright. */
|
|
213
|
+
rotate?: number;
|
|
180
214
|
}
|
|
181
215
|
/**
|
|
182
216
|
* Glyphs that share a resolved face, glyph source and paint, so a renderer
|
|
@@ -215,7 +249,7 @@ interface LaidOutGroup {
|
|
|
215
249
|
* (no registered outlines) stays on the atlas, unstroked. */
|
|
216
250
|
stroke?: Stroke;
|
|
217
251
|
/** Textured glyph quads, {@link QUAD_STRIDE} numbers each, in
|
|
218
|
-
* `LaidOutQuad`'s field order: `x0 y0 x1 y1 u0 v0 u1 v1 baselineY`. What
|
|
252
|
+
* `LaidOutQuad`'s field order: `x0 y0 x1 y1 u0 v0 u1 v1 baselineY penX rotate`. What
|
|
219
253
|
* a painter reads; `quads` is a view of it. Empty for an `'outline'` group. */
|
|
220
254
|
quadData: readonly number[];
|
|
221
255
|
/** On a `'color'` group, each quad's glyph record, which a renderer drawing
|
|
@@ -258,8 +292,6 @@ interface PaintedRuns {
|
|
|
258
292
|
* strikethrough then overline. Empty when nothing is decorated. */
|
|
259
293
|
decorations: LaidOutDecoration[];
|
|
260
294
|
}
|
|
261
|
-
/** Numbers per quad in `LaidOutGroup.quadData`. */
|
|
262
|
-
declare const QUAD_STRIDE = 9;
|
|
263
295
|
/**
|
|
264
296
|
* Derive what to draw for `laid`, the layout of `runs` — or of runs that
|
|
265
297
|
* differ from them only in paint and decoration, which a layout does not read.
|
|
@@ -271,9 +303,11 @@ declare function paintRuns(laid: LaidOutRuns, runs: readonly ResolvedRun[], opts
|
|
|
271
303
|
* threshold's effect, and the glyphs available are what they were. `laid` must
|
|
272
304
|
* be the layout of `runs`, as for `paintRuns`.
|
|
273
305
|
*
|
|
274
|
-
* **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.
|
|
275
309
|
*/
|
|
276
|
-
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;
|
|
277
311
|
|
|
278
312
|
/**
|
|
279
313
|
* Wrap-aware text measurement for a 2D context. Lines end where `layoutRuns`
|
|
@@ -671,6 +705,10 @@ declare function setFlagOverRange(runs: readonly StyledRun[], style: TextStyle,
|
|
|
671
705
|
*/
|
|
672
706
|
declare const SYNTHETIC_ITALIC_RADIANS = 0.2094;
|
|
673
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
|
+
|
|
674
712
|
/**
|
|
675
713
|
* Synthetic bold as geometry. The renderer fakes a missing bold face by
|
|
676
714
|
* dropping the distance-field threshold, which moves every edge of the glyph
|
|
@@ -726,6 +764,13 @@ declare class TextOutlinesError extends Error {
|
|
|
726
764
|
readonly style: FontStyle;
|
|
727
765
|
constructor(reason: TextOutlinesFailure, family: string, weight: number, style: FontStyle, detail: string, caller?: string);
|
|
728
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;
|
|
729
774
|
|
|
730
775
|
/**
|
|
731
776
|
* Text as path geometry: the glyph outlines a text node draws, placed in
|
|
@@ -810,6 +855,22 @@ interface TextCluster {
|
|
|
810
855
|
paths: TextPaintPath[];
|
|
811
856
|
/** Height of the x-height's middle above the baseline. */
|
|
812
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;
|
|
813
874
|
}
|
|
814
875
|
/** Options for {@link textClusters}. */
|
|
815
876
|
interface TextClustersOptions extends TextToPathOptions {
|
|
@@ -823,13 +884,18 @@ interface TextClustersOptions extends TextToPathOptions {
|
|
|
823
884
|
* laid at the node's box origin with no pose applied; the lines after it are
|
|
824
885
|
* dropped. The slots tile the
|
|
825
886
|
* line: each cluster's `advance` runs to the next one's `x`, so the kerning
|
|
826
|
-
* between two clusters belongs to the left one.
|
|
887
|
+
* between two clusters belongs to the left one. A decoration rule is cut into
|
|
888
|
+
* the slots it crosses (`rules`).
|
|
827
889
|
*
|
|
828
890
|
* Throws `TextOutlinesError` as `textToPath` does, except that a color
|
|
829
891
|
* glyph, or one drawn by a fallback face with no outlines, keeps its slot
|
|
830
892
|
* with no `paths`. Only a code point that inks its slot is drawn, so a color
|
|
831
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.
|
|
832
898
|
*/
|
|
833
899
|
declare function textClusters(data: TextOutlineSource, opts?: TextClustersOptions): TextCluster[];
|
|
834
900
|
|
|
835
|
-
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, QUAD_STRIDE, 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 };
|