@weasel-js/text 1.9.3 → 1.10.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/README.md +11 -9
- package/dist/{chunk-L6UJ4RQK.js → chunk-Z6YRJ33J.js} +481 -649
- package/dist/chunk-Z6YRJ33J.js.map +1 -0
- package/dist/index.d.ts +519 -52
- package/dist/index.js +796 -21
- package/dist/index.js.map +1 -1
- package/dist/{test-seams-DbGu8K5F.d.ts → test-seams-CuLNcDew.d.ts} +214 -348
- package/dist/test-seams.d.ts +1 -1
- package/dist/test-seams.js +1 -1
- package/package.json +6 -5
- package/dist/chunk-L6UJ4RQK.js.map +0 -1
package/README.md
CHANGED
|
@@ -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
|
-
|
|
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
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|