@weasel-js/text 1.9.4 → 1.10.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/README.md CHANGED
@@ -7,7 +7,7 @@ here knows about a scene graph, a renderer or React.
7
7
 
8
8
  Part of [weasel](https://github.com/orochi235/weasel), a domain-agnostic 2D
9
9
  scene-graph canvas kit for React. See the
10
- [API reference](https://orochi235.github.io/weasel/api/).
10
+ [API reference](https://orochi235.github.io/weasel/#pkg/text).
11
11
 
12
12
  ## Install
13
13
 
@@ -17,23 +17,25 @@ npm install @weasel-js/text
17
17
 
18
18
  ## Usage
19
19
 
20
- `layoutRuns` is the glyph walk: it takes fully-resolved runs and returns
21
- positioned geometry, grouped so that one group is one draw call.
20
+ `layoutRuns` is the glyph walk: it takes fully-resolved runs and returns the
21
+ lines they wrap into, with every glyph placed. `paintRuns` turns that into what
22
+ to draw: the glyphs gathered into groups that share a face and a paint, and the
23
+ decoration rules. Paint is read only there, so recoloring text reuses its layout.
22
24
 
23
25
  ```ts
24
- import { toRuns, resolveTextStyle, resolveRuns, layoutRuns } from '@weasel-js/text';
26
+ import { toRuns, resolveTextStyle, resolveRuns, layoutRuns, paintRuns } from '@weasel-js/text';
25
27
 
26
28
  const style = resolveTextStyle({ fontFamily: 'inter', fontSize: 64 });
27
- const { groups, lines, bounds } = layoutRuns(resolveRuns(toRuns('Hello'), style), {
28
- maxWidth: 900,
29
- lineHeight: 1.2,
30
- align: 'center',
31
- });
29
+ const runs = resolveRuns(toRuns('Hello'), style);
30
+ const laid = layoutRuns(runs, { maxWidth: 900, lineHeight: 1.2, align: 'center' });
31
+ const { lines, bounds } = laid;
32
+ const { groups, decorations } = paintRuns(laid, runs);
32
33
  ```
33
34
 
34
35
  A group carries either textured quads (from a baked MSDF atlas) or outline
35
36
  glyphs — em-space SVG path data plus the pen position, baseline and scale to
36
- place it — for a consumer that tessellates its own geometry.
37
+ place it — for a consumer that tessellates its own geometry. `cachedLayoutRuns`
38
+ and `cachedPaintRuns` are the same two calls, memoized.
37
39
 
38
40
  Metrics come from whichever tier resolved the family: a baked MSDF atlas, or —
39
41
  for a family registered with `registerFontOutlines` and no atlas — the parsed