alpha2 0.4.6 → 0.5.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 +5 -4
- package/THIRD_PARTY_NOTICES.md +4 -0
- package/dist/abort.d.ts +12 -0
- package/dist/abort.js +48 -0
- package/dist/active-clock.d.ts +35 -0
- package/dist/active-clock.js +99 -0
- package/dist/assets.d.ts +51 -22
- package/dist/assets.js +8 -12
- package/dist/audio-layout.d.ts +52 -74
- package/dist/audio-layout.js +114 -148
- package/dist/audio-timeline.d.ts +89 -117
- package/dist/audio-timeline.js +102 -118
- package/dist/audio-worker.d.ts +12 -21
- package/dist/audio-worker.js +8 -13
- package/dist/audio-worklet-processor.js +45 -58
- package/dist/audio-worklet.d.ts +45 -76
- package/dist/audio-worklet.js +44 -79
- package/dist/audio.d.ts +15 -23
- package/dist/audio.js +9 -13
- package/dist/builder.d.ts +45 -63
- package/dist/builder.js +49 -45
- package/dist/capabilities.d.ts +99 -16
- package/dist/capabilities.js +2 -2
- package/dist/captions.d.ts +45 -22
- package/dist/captions.js +60 -15
- package/dist/chroma-siting.d.ts +24 -41
- package/dist/chroma-siting.js +38 -71
- package/dist/containers.d.ts +41 -30
- package/dist/containers.js +59 -27
- package/dist/decoder-fallback.d.ts +13 -0
- package/dist/decoder-fallback.js +38 -0
- package/dist/decoder-order.d.ts +24 -39
- package/dist/decoder-order.js +28 -42
- package/dist/edit.d.ts +77 -154
- package/dist/edit.js +98 -180
- package/dist/effects.d.ts +125 -176
- package/dist/effects.js +7 -9
- package/dist/export-destination.d.ts +25 -41
- package/dist/export-destination.js +20 -32
- package/dist/export-failure.d.ts +34 -59
- package/dist/export-failure.js +54 -48
- package/dist/export-metrics.d.ts +116 -0
- package/dist/export-metrics.js +74 -0
- package/dist/export-retry.d.ts +46 -29
- package/dist/export-retry.js +86 -51
- package/dist/exporter.d.ts +67 -116
- package/dist/exporter.js +133 -133
- package/dist/extensions.d.ts +69 -115
- package/dist/extensions.js +55 -82
- package/dist/frame-intake.d.ts +92 -0
- package/dist/frame-intake.js +114 -0
- package/dist/frame-supply.d.ts +96 -162
- package/dist/frame-supply.js +181 -171
- package/dist/frames.d.ts +23 -0
- package/dist/frames.js +34 -0
- package/dist/generated/project-schema.d.ts +712 -485
- package/dist/generated/project-schema.js +55 -2
- package/dist/generated/project-shape.js +276 -16
- package/dist/geometry.d.ts +28 -34
- package/dist/geometry.js +18 -23
- package/dist/gpu-recovery.d.ts +92 -0
- package/dist/gpu-recovery.js +135 -0
- package/dist/hdr-frames.d.ts +82 -67
- package/dist/hdr-frames.js +112 -49
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/json-text.d.ts +13 -23
- package/dist/json-text.js +10 -20
- package/dist/layout-values.d.ts +14 -22
- package/dist/layout-values.js +18 -21
- package/dist/layout.d.ts +48 -63
- package/dist/layout.js +37 -37
- package/dist/loudness.d.ts +27 -32
- package/dist/loudness.js +19 -23
- package/dist/media.d.ts +85 -237
- package/dist/media.js +133 -287
- package/dist/mediabunny.d.ts +178 -246
- package/dist/mediabunny.js +781 -583
- package/dist/paint.d.ts +23 -0
- package/dist/paint.js +37 -0
- package/dist/physical-frames.d.ts +5 -17
- package/dist/physical-frames.js +4 -11
- package/dist/player.d.ts +56 -47
- package/dist/player.js +155 -40
- package/dist/presented-frames.d.ts +2 -7
- package/dist/presented-frames.js +3 -8
- package/dist/project.d.ts +74 -118
- package/dist/project.js +384 -445
- package/dist/rate-control.d.ts +9 -23
- package/dist/rate-control.js +7 -18
- package/dist/renderer-choice.d.ts +41 -0
- package/dist/renderer-choice.js +82 -0
- package/dist/repacked-bytes.d.ts +0 -2
- package/dist/repacked-bytes.js +2 -5
- package/dist/robustness.d.ts +25 -37
- package/dist/robustness.js +71 -54
- package/dist/sha256.d.ts +5 -13
- package/dist/sha256.js +9 -24
- package/dist/text.d.ts +97 -71
- package/dist/text.js +33 -70
- package/dist/video-frames.d.ts +7 -25
- package/dist/video-frames.js +12 -29
- package/dist/waveform.d.ts +5 -11
- package/dist/waveform.js +4 -9
- package/dist/worker-error.d.ts +5 -20
- package/dist/worker-error.js +8 -25
- package/dist/worker.d.ts +82 -95
- package/dist/worker.js +235 -143
- package/package.json +26 -2
- package/wasm/alpha2_audio_worklet.wasm +0 -0
- package/wasm/alpha2_extensions.d.ts +26 -47
- package/wasm/alpha2_extensions.js +26 -47
- package/wasm/alpha2_extensions_bg.wasm +0 -0
- package/wasm/alpha2_wasm.d.ts +501 -587
- package/wasm/alpha2_wasm.js +661 -616
- package/wasm/alpha2_wasm_bg.wasm +0 -0
- package/wasm/alpha2_wasm_bg.wasm.d.ts +22 -12
- package/wasm/rust-crate-licenses.md +2 -2
- package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-070d94113471ef0a}/inline1.js +1 -0
- package/wasm/snippets/alpha2-wasm-070d94113471ef0a/inline2.js +82 -0
- package/wasm/snippets/alpha2-wasm-c62e60c964e88a52/inline2.js +0 -52
- /package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-070d94113471ef0a}/inline0.js +0 -0
- /package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-070d94113471ef0a}/inline3.js +0 -0
package/dist/layout-values.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* lists and grid lines, and CSS hex colors. Internal: `validateProject` and the layout builder use
|
|
5
|
-
* it.
|
|
2
|
+
* CSS value parsers for layout fields. Must match `alpha2_model::layout_values`, including error
|
|
3
|
+
* messages.
|
|
6
4
|
*/
|
|
7
|
-
/** A parsed value, or why the text is not one. */
|
|
8
5
|
export type Parsed<T> = {
|
|
9
6
|
readonly ok: true;
|
|
10
7
|
readonly value: T;
|
|
@@ -12,30 +9,29 @@ export type Parsed<T> = {
|
|
|
12
9
|
readonly ok: false;
|
|
13
10
|
readonly error: string;
|
|
14
11
|
};
|
|
15
|
-
/**
|
|
12
|
+
/** `fraction` is a fraction of the canvas's shorter side. */
|
|
16
13
|
export type LengthUnit = "fraction" | "px" | "percent";
|
|
17
|
-
/**
|
|
14
|
+
/** `value` is a 32-bit float. */
|
|
18
15
|
export interface Length {
|
|
19
16
|
readonly unit: LengthUnit;
|
|
20
17
|
readonly value: number;
|
|
21
18
|
}
|
|
22
19
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
20
|
+
* Parses a CSS number without an exponent, rounded through f64 to f32 as the engine does.
|
|
21
|
+
* Returns `undefined` when invalid or not finite.
|
|
25
22
|
*/
|
|
26
23
|
export declare function parseNumber(text: string): number | undefined;
|
|
27
|
-
/**
|
|
24
|
+
/** Parses a `LayoutSize` (no percent). */
|
|
28
25
|
export declare function parseSize(text: string): Parsed<Length>;
|
|
29
|
-
/**
|
|
26
|
+
/** Parses a `LayoutLength` (percent allowed). */
|
|
30
27
|
export declare function parseLength(text: string): Parsed<Length>;
|
|
31
|
-
/**
|
|
28
|
+
/** Parses `Insets` from the shorthand string, top first. */
|
|
32
29
|
export declare function parseInsets(text: string): Parsed<readonly [Length, Length, Length, Length]>;
|
|
33
|
-
/**
|
|
30
|
+
/** Parses a `LayoutOffset` from a CSS `translate` string; y defaults to 0. */
|
|
34
31
|
export declare function parseOffset(text: string): Parsed<{
|
|
35
32
|
readonly x: Length;
|
|
36
33
|
readonly y: Length;
|
|
37
34
|
}>;
|
|
38
|
-
/** One side of a track's size. */
|
|
39
35
|
export type TrackBreadth = {
|
|
40
36
|
readonly kind: "length";
|
|
41
37
|
readonly length: Length;
|
|
@@ -45,7 +41,6 @@ export type TrackBreadth = {
|
|
|
45
41
|
} | {
|
|
46
42
|
readonly kind: "auto" | "min-content" | "max-content";
|
|
47
43
|
};
|
|
48
|
-
/** One track's size. */
|
|
49
44
|
export type TrackSize = {
|
|
50
45
|
readonly kind: "breadth";
|
|
51
46
|
readonly breadth: TrackBreadth;
|
|
@@ -57,9 +52,7 @@ export type TrackSize = {
|
|
|
57
52
|
readonly kind: "fit-content";
|
|
58
53
|
readonly limit: Length;
|
|
59
54
|
};
|
|
60
|
-
/** How often `repeat()` repeats: a count, `auto-fill`, or `auto-fit`. */
|
|
61
55
|
export type RepeatCount = number | "auto-fill" | "auto-fit";
|
|
62
|
-
/** One entry of a track list. */
|
|
63
56
|
export type TrackComponent = {
|
|
64
57
|
readonly kind: "single";
|
|
65
58
|
readonly size: TrackSize;
|
|
@@ -68,9 +61,8 @@ export type TrackComponent = {
|
|
|
68
61
|
readonly count: RepeatCount;
|
|
69
62
|
readonly tracks: readonly TrackSize[];
|
|
70
63
|
};
|
|
71
|
-
/**
|
|
64
|
+
/** Parses a grid `TrackList`. */
|
|
72
65
|
export declare function parseTrackList(text: string): Parsed<TrackComponent[]>;
|
|
73
|
-
/** One edge of a grid placement: `auto`, a line, or a span. */
|
|
74
66
|
export type GridEdge = {
|
|
75
67
|
readonly kind: "auto";
|
|
76
68
|
} | {
|
|
@@ -80,17 +72,17 @@ export type GridEdge = {
|
|
|
80
72
|
readonly kind: "span";
|
|
81
73
|
readonly count: number;
|
|
82
74
|
};
|
|
83
|
-
/**
|
|
75
|
+
/** Parses a `GridPlacement` from a line number or its CSS string. */
|
|
84
76
|
export declare function parsePlacement(value: number | string): Parsed<{
|
|
85
77
|
readonly start: GridEdge;
|
|
86
78
|
readonly end: GridEdge;
|
|
87
79
|
}>;
|
|
88
|
-
/**
|
|
80
|
+
/** Straight (non-premultiplied) sRGB with alpha, components in `0..=1`. */
|
|
89
81
|
export interface Color {
|
|
90
82
|
readonly red: number;
|
|
91
83
|
readonly green: number;
|
|
92
84
|
readonly blue: number;
|
|
93
85
|
readonly alpha: number;
|
|
94
86
|
}
|
|
95
|
-
/**
|
|
87
|
+
/** Parses `#rgb`, `#rgba`, `#rrggbb` or `#rrggbbaa` into f32 components. */
|
|
96
88
|
export declare function parseHex(text: string): Parsed<Color>;
|
package/dist/layout-values.js
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* lists and grid lines, and CSS hex colors. Internal: `validateProject` and the layout builder use
|
|
5
|
-
* it.
|
|
2
|
+
* CSS value parsers for layout fields. Must match `alpha2_model::layout_values`, including error
|
|
3
|
+
* messages.
|
|
6
4
|
*/
|
|
7
5
|
const ok = (value) => ({ ok: true, value });
|
|
8
6
|
const refused = (error) => ({ ok: false, error });
|
|
9
7
|
const NUMBER = /^-?(\d+\.?\d*|\.\d+)$/;
|
|
10
8
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
9
|
+
* Parses a CSS number without an exponent, rounded through f64 to f32 as the engine does.
|
|
10
|
+
* Returns `undefined` when invalid or not finite.
|
|
13
11
|
*/
|
|
14
12
|
export function parseNumber(text) {
|
|
15
13
|
if (!NUMBER.test(text))
|
|
@@ -17,11 +15,10 @@ export function parseNumber(text) {
|
|
|
17
15
|
const value = Math.fround(Number(text));
|
|
18
16
|
return Number.isFinite(value) ? value : undefined;
|
|
19
17
|
}
|
|
20
|
-
/** The tokens of a CSS value: runs of characters between ASCII spaces. */
|
|
21
18
|
function tokens(text) {
|
|
22
19
|
return text.split(" ").filter((token) => token.length > 0);
|
|
23
20
|
}
|
|
24
|
-
/**
|
|
21
|
+
/** Matches Rust's `trim_matches(' ')`: ASCII spaces only. */
|
|
25
22
|
function trimSpaces(text) {
|
|
26
23
|
return text.replace(/^ +| +$/g, "");
|
|
27
24
|
}
|
|
@@ -36,7 +33,7 @@ function invalidLength(token, percent) {
|
|
|
36
33
|
: 'a number or "<n>px"';
|
|
37
34
|
return `invalid length "${token}"${hint}: write ${forms}`;
|
|
38
35
|
}
|
|
39
|
-
/**
|
|
36
|
+
/** `percent` says whether the field accepts a percent. */
|
|
40
37
|
function parseSizeToken(token, percent) {
|
|
41
38
|
if (token.endsWith("px")) {
|
|
42
39
|
const value = parseNumber(token.slice(0, -2));
|
|
@@ -54,11 +51,11 @@ function parseSizeToken(token, percent) {
|
|
|
54
51
|
? refused(invalidLength(token, percent))
|
|
55
52
|
: ok({ unit: "fraction", value });
|
|
56
53
|
}
|
|
57
|
-
/**
|
|
54
|
+
/** Parses a `LayoutSize` (no percent). */
|
|
58
55
|
export function parseSize(text) {
|
|
59
56
|
return parseSizeToken(trimSpaces(text), false);
|
|
60
57
|
}
|
|
61
|
-
/**
|
|
58
|
+
/** Parses a `LayoutLength` (percent allowed). */
|
|
62
59
|
export function parseLength(text) {
|
|
63
60
|
const trimmed = trimSpaces(text);
|
|
64
61
|
if (trimmed.endsWith("%")) {
|
|
@@ -70,7 +67,7 @@ export function parseLength(text) {
|
|
|
70
67
|
const size = parseSizeToken(trimmed, true);
|
|
71
68
|
return size.ok ? size : refused(invalidLength(text, true));
|
|
72
69
|
}
|
|
73
|
-
/**
|
|
70
|
+
/** Expands a one-to-four value CSS shorthand, top first. */
|
|
74
71
|
function shorthand(values) {
|
|
75
72
|
const [a, b, c, d] = values;
|
|
76
73
|
switch (values.length) {
|
|
@@ -86,7 +83,7 @@ function shorthand(values) {
|
|
|
86
83
|
return refused(`expected 1 to 4 lengths, got ${values.length}`);
|
|
87
84
|
}
|
|
88
85
|
}
|
|
89
|
-
/**
|
|
86
|
+
/** Parses `Insets` from the shorthand string, top first. */
|
|
90
87
|
export function parseInsets(text) {
|
|
91
88
|
const sides = [];
|
|
92
89
|
for (const token of tokens(text)) {
|
|
@@ -97,7 +94,7 @@ export function parseInsets(text) {
|
|
|
97
94
|
}
|
|
98
95
|
return shorthand(sides);
|
|
99
96
|
}
|
|
100
|
-
/**
|
|
97
|
+
/** Parses a `LayoutOffset` from a CSS `translate` string; y defaults to 0. */
|
|
101
98
|
export function parseOffset(text) {
|
|
102
99
|
const values = [];
|
|
103
100
|
for (const token of tokens(text)) {
|
|
@@ -143,7 +140,7 @@ function parseBreadth(token, max) {
|
|
|
143
140
|
? ok({ kind: "length", length: length.value })
|
|
144
141
|
: refused(unknownTrack(token));
|
|
145
142
|
}
|
|
146
|
-
/**
|
|
143
|
+
/** Mirrors the Rust `TrackParser`. */
|
|
147
144
|
class TrackParser {
|
|
148
145
|
text;
|
|
149
146
|
at = 0;
|
|
@@ -153,13 +150,13 @@ class TrackParser {
|
|
|
153
150
|
rest() {
|
|
154
151
|
return this.text.slice(this.at);
|
|
155
152
|
}
|
|
156
|
-
/** Skips spaces
|
|
153
|
+
/** Skips spaces and returns whether anything is left. */
|
|
157
154
|
skipSpaces() {
|
|
158
155
|
while (this.rest().startsWith(" "))
|
|
159
156
|
this.at += 1;
|
|
160
157
|
return this.rest().length > 0;
|
|
161
158
|
}
|
|
162
|
-
/**
|
|
159
|
+
/** Reads up to a space, comma or parenthesis. */
|
|
163
160
|
token() {
|
|
164
161
|
const rest = this.rest();
|
|
165
162
|
const match = /[ ,()]/.exec(rest);
|
|
@@ -270,7 +267,7 @@ class TrackParser {
|
|
|
270
267
|
return ok({ kind: "repeat", count, tracks });
|
|
271
268
|
}
|
|
272
269
|
}
|
|
273
|
-
/**
|
|
270
|
+
/** Parses a grid `TrackList`. */
|
|
274
271
|
export function parseTrackList(text) {
|
|
275
272
|
const parser = new TrackParser(text);
|
|
276
273
|
const components = [];
|
|
@@ -303,7 +300,7 @@ function invalidLine(text) {
|
|
|
303
300
|
? `named grid lines are not supported: "${trimmed}"`
|
|
304
301
|
: `invalid grid line "${trimmed}": write a line number, "span <n>", or "auto"`;
|
|
305
302
|
}
|
|
306
|
-
/**
|
|
303
|
+
/** Parses an i16 written as a CSS integer. */
|
|
307
304
|
function gridInteger(word) {
|
|
308
305
|
if (!/^-?\d+$/.test(word))
|
|
309
306
|
return undefined;
|
|
@@ -326,7 +323,7 @@ function parseEdge(text) {
|
|
|
326
323
|
}
|
|
327
324
|
return undefined;
|
|
328
325
|
}
|
|
329
|
-
/**
|
|
326
|
+
/** Parses a `GridPlacement` from a line number or its CSS string. */
|
|
330
327
|
export function parsePlacement(value) {
|
|
331
328
|
if (typeof value === "number") {
|
|
332
329
|
return Number.isInteger(value) && value >= -32768 && value <= 32767
|
|
@@ -349,7 +346,7 @@ export function parsePlacement(value) {
|
|
|
349
346
|
? refused(invalidLine(end))
|
|
350
347
|
: ok({ start: first, end: second });
|
|
351
348
|
}
|
|
352
|
-
/**
|
|
349
|
+
/** Parses `#rgb`, `#rgba`, `#rrggbb` or `#rrggbbaa` into f32 components. */
|
|
353
350
|
export function parseHex(text) {
|
|
354
351
|
const digits = text.startsWith("#") ? text.slice(1) : undefined;
|
|
355
352
|
if (digits === undefined ||
|
package/dist/layout.d.ts
CHANGED
|
@@ -1,83 +1,69 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* shapes, as a project's `{ "type": "layout" }` generator holds them.
|
|
2
|
+
* Builders and measurement for `{ "type": "layout" }` generators (CSS flexbox and grid boxes).
|
|
4
3
|
*
|
|
5
|
-
* {@link measureLayout}
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* canvas, `"50%"` a percent of the parent's content box. Text style (`font_family`, `font_size`,
|
|
12
|
-
* `font_weight`, `color`, `line_height`, `letter_spacing`, `text_align`, `outline`) may be set on
|
|
13
|
-
* any box and is inherited. Its
|
|
14
|
-
* output is a plain document that `validateProject` accepts; a CSS value string it cannot read
|
|
15
|
-
* throws, with the parser's message.
|
|
4
|
+
* {@link measureLayout} computes every box's position and overflow in wasm with the engine's fonts.
|
|
5
|
+
* The builders ({@link box}, {@link text}, {@link shape}, {@link layout}) take CSS-like props:
|
|
6
|
+
* plain values become constants, and tuples expand to sides objects or vectors. A number length is
|
|
7
|
+
* a fraction of the picture's shorter side, `"12px"` is project canvas pixels, and `"50%"` is a
|
|
8
|
+
* percent of the parent's content box. Text style props may be set on any box and are inherited.
|
|
9
|
+
* The output is a plain document; an unreadable CSS value string throws the parser's message.
|
|
16
10
|
*/
|
|
17
11
|
import type { PictureSize } from "./geometry.js";
|
|
18
|
-
import type { AlignContent, AlignItems, Animated, Display, FlexDirection, FlexWrap, Generator, GridAutoFlow, JustifyContent, LayoutNode, Overflow, Paint, Position, Rgba, ShapeItem, TextAlign,
|
|
19
|
-
/** The
|
|
12
|
+
import type { AlignContent, AlignItems, Animated, Display, FlexDirection, FlexWrap, Generator, GridAutoFlow, JustifyContent, LayoutNode, Overflow, Paint, Position, Rgba, ShapeItem, TextAlign, TextShadow, TextStroke, Ticks, Vec2 } from "./project.js";
|
|
13
|
+
/** The `WasmTextMeasurer` method {@link measureLayout} uses. */
|
|
20
14
|
export interface LayoutBinding {
|
|
21
15
|
measureLayout(generatorJson: string, width: number, height: number, time: number, canvasWidth?: number, canvasHeight?: number): string;
|
|
22
16
|
}
|
|
23
|
-
/**
|
|
17
|
+
/** Rectangle in picture fractions, `(0, 0)` top-left to `(1, 1)` bottom-right. */
|
|
24
18
|
export interface LayoutRect {
|
|
25
19
|
readonly left: number;
|
|
26
20
|
readonly top: number;
|
|
27
21
|
readonly right: number;
|
|
28
22
|
readonly bottom: number;
|
|
29
23
|
}
|
|
30
|
-
/**
|
|
24
|
+
/** A node's layout boxes, before the clip transform and node visuals. */
|
|
31
25
|
export interface NodeBounds {
|
|
32
|
-
/**
|
|
26
|
+
/** Path from the root, like `root.children[1]`. */
|
|
33
27
|
readonly at: string;
|
|
34
|
-
/** The border box. */
|
|
35
28
|
readonly border: LayoutRect;
|
|
36
|
-
/** The content box. */
|
|
37
29
|
readonly content: LayoutRect;
|
|
38
30
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
31
|
+
* Text is taller than the content box or splits a word, or an in-flow child reaches past the
|
|
32
|
+
* padding box. Rendering draws it anyway.
|
|
41
33
|
*/
|
|
42
34
|
readonly overflow: boolean;
|
|
43
|
-
/**
|
|
35
|
+
/** `null` for non-text nodes. */
|
|
44
36
|
readonly lineCount: number | null;
|
|
45
|
-
/**
|
|
46
|
-
* A text node's first and last lines' alphabetic baselines, as fractions of the picture's height:
|
|
47
|
-
* its content box's top plus its text's baselines. `null` for other nodes and empty text.
|
|
48
|
-
*/
|
|
37
|
+
/** `null` for non-text nodes and empty text. */
|
|
49
38
|
readonly baselines: Baselines | null;
|
|
50
39
|
}
|
|
51
|
-
/**
|
|
40
|
+
/** First and last alphabetic baselines, as fractions of the picture height. */
|
|
52
41
|
export interface Baselines {
|
|
53
42
|
readonly first: number;
|
|
54
43
|
readonly last: number;
|
|
55
44
|
}
|
|
56
|
-
/**
|
|
45
|
+
/** Every node's bounds, root first, in document order. */
|
|
57
46
|
export interface LayoutBounds {
|
|
58
47
|
readonly nodes: readonly NodeBounds[];
|
|
59
48
|
}
|
|
60
49
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* are pixels of `canvas`, the project canvas: `picture` itself by default, so a preview measured
|
|
65
|
-
* at half size passes the project's own size here.
|
|
50
|
+
* Lays out `generator` (or a bare root node) on `picture` at `time` with `binding`'s fonts. Measure
|
|
51
|
+
* at the drawn size, since lines can break differently at other sizes. `"<n>px"` lengths are pixels
|
|
52
|
+
* of `canvas`, which defaults to `picture`; pass the project size when measuring a scaled preview.
|
|
66
53
|
*
|
|
67
|
-
* @throws An `INVALID_INPUT` error for a layout the model rejects
|
|
68
|
-
*
|
|
69
|
-
* measurer
|
|
54
|
+
* @throws An `INVALID_INPUT` error for a layout the model rejects, a picture or canvas outside 1 to
|
|
55
|
+
* 16384 pixels a side, or a non-integer tick time; a text error when the layout has text and the
|
|
56
|
+
* measurer has no fonts.
|
|
70
57
|
*/
|
|
71
58
|
export declare function measureLayout(binding: LayoutBinding, generator: Generator | LayoutNode, picture: PictureSize, time?: Ticks, canvas?: PictureSize): LayoutBounds;
|
|
72
|
-
/** A value, or the document's animated form of it. */
|
|
73
59
|
export type Value<T> = T | Animated<T>;
|
|
74
|
-
/** A
|
|
60
|
+
/** A fraction of the picture's shorter side, or `"12px"`. No percent. */
|
|
75
61
|
export type Size = number | `${number}px`;
|
|
76
|
-
/** A
|
|
62
|
+
/** A {@link Size}, or a percent of the parent's content box. */
|
|
77
63
|
export type Length = Size | `${number}%`;
|
|
78
64
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
65
|
+
* One size for all sides, a CSS shorthand (`"8px 16px"`), a `[top, right, bottom, left]` tuple, or
|
|
66
|
+
* a sides object (missing sides are 0).
|
|
81
67
|
*/
|
|
82
68
|
export type Sides = number | string | readonly [Size, Size, Size, Size] | {
|
|
83
69
|
readonly top?: Size;
|
|
@@ -85,34 +71,37 @@ export type Sides = number | string | readonly [Size, Size, Size, Size] | {
|
|
|
85
71
|
readonly bottom?: Size;
|
|
86
72
|
readonly left?: Size;
|
|
87
73
|
};
|
|
88
|
-
/** A
|
|
74
|
+
/** A components object or CSS hex string (`"#1e2230"`). */
|
|
89
75
|
export type Color = Rgba;
|
|
90
|
-
/** A paint, or a color painted solid. */
|
|
91
76
|
export type Fill = Paint | Color;
|
|
92
|
-
/**
|
|
77
|
+
/** A CSS `translate` string (`"10px 20px"`), an `[x, y]` tuple, or `{ x, y }`. */
|
|
93
78
|
export type Offset = string | readonly [Size, Size] | {
|
|
94
79
|
readonly x: Size;
|
|
95
80
|
readonly y: Size;
|
|
96
81
|
};
|
|
97
|
-
/**
|
|
82
|
+
/** Text style, inherited by descendant boxes as in CSS. */
|
|
98
83
|
export interface TextStyleProps {
|
|
99
84
|
readonly font_family?: string;
|
|
100
85
|
readonly font_size?: Value<Size>;
|
|
101
|
-
/**
|
|
86
|
+
/** In `[1, 1000]`. Not animated. */
|
|
102
87
|
readonly font_weight?: number;
|
|
103
|
-
|
|
88
|
+
/** A color, or a gradient over the text's layout box. Not animated. */
|
|
89
|
+
readonly fill?: Fill;
|
|
104
90
|
readonly line_height?: number;
|
|
105
|
-
/** Space after each character
|
|
91
|
+
/** Space after each character as a fraction of the font size, in `[-0.5, 1]`. Not animated. */
|
|
106
92
|
readonly letter_spacing?: number;
|
|
107
93
|
readonly text_align?: TextAlign;
|
|
108
|
-
|
|
94
|
+
/** Innermost first; widths are fractions of the font size. */
|
|
95
|
+
readonly strokes?: readonly TextStroke[];
|
|
96
|
+
/** First on top; lengths are fractions of the font size. */
|
|
97
|
+
readonly shadows?: readonly TextShadow[];
|
|
109
98
|
}
|
|
110
|
-
/** A box's CSS fields, with
|
|
99
|
+
/** A box's CSS fields, with shorthand forms accepted. */
|
|
111
100
|
export interface BoxProps extends TextStyleProps {
|
|
112
101
|
readonly display?: Display;
|
|
113
102
|
readonly flex_direction?: FlexDirection;
|
|
114
103
|
readonly flex_wrap?: FlexWrap;
|
|
115
|
-
/**
|
|
104
|
+
/** CSS syntax, such as `"1fr 2fr"` or `"repeat(3, minmax(100px, 1fr))"`. */
|
|
116
105
|
readonly grid_template_columns?: string;
|
|
117
106
|
readonly grid_template_rows?: string;
|
|
118
107
|
readonly grid_auto_columns?: string;
|
|
@@ -146,7 +135,7 @@ export interface BoxProps extends TextStyleProps {
|
|
|
146
135
|
readonly flex_basis?: Value<Length>;
|
|
147
136
|
readonly align_self?: AlignItems;
|
|
148
137
|
readonly justify_self?: AlignItems;
|
|
149
|
-
/**
|
|
138
|
+
/** CSS syntax, such as `2`, `"1 / 3"` or `"span 2"`. */
|
|
150
139
|
readonly grid_column?: number | string;
|
|
151
140
|
readonly grid_row?: number | string;
|
|
152
141
|
readonly position?: Position;
|
|
@@ -162,21 +151,17 @@ export interface BoxProps extends TextStyleProps {
|
|
|
162
151
|
readonly scale?: Value<Vec2> | number | readonly [number, number];
|
|
163
152
|
readonly rotation_degrees?: Value<number>;
|
|
164
153
|
}
|
|
165
|
-
/** A layout generator whose root
|
|
154
|
+
/** A layout generator whose root covers the whole picture. */
|
|
166
155
|
export declare function layout(root: LayoutNode): Generator;
|
|
167
|
-
/** A box
|
|
156
|
+
/** A box, optionally holding `children`. */
|
|
168
157
|
export declare function box(props?: BoxProps, ...children: LayoutNode[]): LayoutNode;
|
|
169
|
-
/**
|
|
170
|
-
* A box holding one paragraph of text, wrapped at its content width and drawn in the style it
|
|
171
|
-
* sets or inherits.
|
|
172
|
-
*/
|
|
158
|
+
/** A box holding one paragraph of text, wrapped at its content width. */
|
|
173
159
|
export declare function text(content: Value<string>, props?: Omit<BoxProps, ContainerField>): LayoutNode;
|
|
174
160
|
/**
|
|
175
|
-
* A box holding shapes,
|
|
176
|
-
*
|
|
177
|
-
*
|
|
161
|
+
* A box holding shapes, with positions normalized to its content box and lengths as fractions of
|
|
162
|
+
* its shorter side. It has no intrinsic size, so give it `width` and `height`, an `aspect_ratio`,
|
|
163
|
+
* or `flex_grow`.
|
|
178
164
|
*/
|
|
179
165
|
export declare function shape(items: readonly ShapeItem[], props?: Omit<BoxProps, ContainerField>): LayoutNode;
|
|
180
|
-
/** The container fields a text or shape node may not take. */
|
|
181
166
|
type ContainerField = "display" | "flex_direction" | "flex_wrap" | "grid_template_columns" | "grid_template_rows" | "grid_auto_columns" | "grid_auto_rows" | "grid_auto_flow" | "gap" | "row_gap" | "column_gap" | "justify_content" | "align_items" | "align_content" | "justify_items";
|
|
182
167
|
export {};
|
package/dist/layout.js
CHANGED
|
@@ -1,30 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* shapes, as a project's `{ "type": "layout" }` generator holds them.
|
|
2
|
+
* Builders and measurement for `{ "type": "layout" }` generators (CSS flexbox and grid boxes).
|
|
4
3
|
*
|
|
5
|
-
* {@link measureLayout}
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* canvas, `"50%"` a percent of the parent's content box. Text style (`font_family`, `font_size`,
|
|
12
|
-
* `font_weight`, `color`, `line_height`, `letter_spacing`, `text_align`, `outline`) may be set on
|
|
13
|
-
* any box and is inherited. Its
|
|
14
|
-
* output is a plain document that `validateProject` accepts; a CSS value string it cannot read
|
|
15
|
-
* throws, with the parser's message.
|
|
4
|
+
* {@link measureLayout} computes every box's position and overflow in wasm with the engine's fonts.
|
|
5
|
+
* The builders ({@link box}, {@link text}, {@link shape}, {@link layout}) take CSS-like props:
|
|
6
|
+
* plain values become constants, and tuples expand to sides objects or vectors. A number length is
|
|
7
|
+
* a fraction of the picture's shorter side, `"12px"` is project canvas pixels, and `"50%"` is a
|
|
8
|
+
* percent of the parent's content box. Text style props may be set on any box and are inherited.
|
|
9
|
+
* The output is a plain document; an unreadable CSS value string throws the parser's message.
|
|
16
10
|
*/
|
|
17
11
|
import { parseHex, parseInsets, parseLength, parseOffset, parsePlacement, parseSize, parseTrackList, } from "./layout-values.js";
|
|
18
12
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* are pixels of `canvas`, the project canvas: `picture` itself by default, so a preview measured
|
|
23
|
-
* at half size passes the project's own size here.
|
|
13
|
+
* Lays out `generator` (or a bare root node) on `picture` at `time` with `binding`'s fonts. Measure
|
|
14
|
+
* at the drawn size, since lines can break differently at other sizes. `"<n>px"` lengths are pixels
|
|
15
|
+
* of `canvas`, which defaults to `picture`; pass the project size when measuring a scaled preview.
|
|
24
16
|
*
|
|
25
|
-
* @throws An `INVALID_INPUT` error for a layout the model rejects
|
|
26
|
-
*
|
|
27
|
-
* measurer
|
|
17
|
+
* @throws An `INVALID_INPUT` error for a layout the model rejects, a picture or canvas outside 1 to
|
|
18
|
+
* 16384 pixels a side, or a non-integer tick time; a text error when the layout has text and the
|
|
19
|
+
* measurer has no fonts.
|
|
28
20
|
*/
|
|
29
21
|
export function measureLayout(binding, generator, picture, time = 0, canvas = picture) {
|
|
30
22
|
const document = "type" in generator && generator.type === "layout"
|
|
@@ -32,27 +24,24 @@ export function measureLayout(binding, generator, picture, time = 0, canvas = pi
|
|
|
32
24
|
: layout(generator);
|
|
33
25
|
return JSON.parse(binding.measureLayout(JSON.stringify(document), picture.width, picture.height, time, canvas.width, canvas.height));
|
|
34
26
|
}
|
|
35
|
-
/** A layout generator whose root
|
|
27
|
+
/** A layout generator whose root covers the whole picture. */
|
|
36
28
|
export function layout(root) {
|
|
37
29
|
return { type: "layout", root };
|
|
38
30
|
}
|
|
39
|
-
/** A box
|
|
31
|
+
/** A box, optionally holding `children`. */
|
|
40
32
|
export function box(props = {}, ...children) {
|
|
41
33
|
return children.length > 0
|
|
42
34
|
? { ...boxFields(props), children }
|
|
43
35
|
: boxFields(props);
|
|
44
36
|
}
|
|
45
|
-
/**
|
|
46
|
-
* A box holding one paragraph of text, wrapped at its content width and drawn in the style it
|
|
47
|
-
* sets or inherits.
|
|
48
|
-
*/
|
|
37
|
+
/** A box holding one paragraph of text, wrapped at its content width. */
|
|
49
38
|
export function text(content, props = {}) {
|
|
50
39
|
return { ...boxFields(props), text: animated(content) };
|
|
51
40
|
}
|
|
52
41
|
/**
|
|
53
|
-
* A box holding shapes,
|
|
54
|
-
*
|
|
55
|
-
*
|
|
42
|
+
* A box holding shapes, with positions normalized to its content box and lengths as fractions of
|
|
43
|
+
* its shorter side. It has no intrinsic size, so give it `width` and `height`, an `aspect_ratio`,
|
|
44
|
+
* or `flex_grow`.
|
|
56
45
|
*/
|
|
57
46
|
export function shape(items, props = {}) {
|
|
58
47
|
return { ...boxFields(props), shape: { items } };
|
|
@@ -66,13 +55,13 @@ function isAnimated(value) {
|
|
|
66
55
|
function animated(value) {
|
|
67
56
|
return isAnimated(value) ? value : { mode: "constant", value };
|
|
68
57
|
}
|
|
69
|
-
/** `value
|
|
58
|
+
/** Returns `value`, or throws the parser's message. */
|
|
70
59
|
function checked(value, parsed) {
|
|
71
60
|
if (!parsed.ok)
|
|
72
61
|
throw new TypeError(parsed.error);
|
|
73
62
|
return value;
|
|
74
63
|
}
|
|
75
|
-
/**
|
|
64
|
+
/** Validates string lengths; numbers pass through. */
|
|
76
65
|
function lengthValue(value, percent) {
|
|
77
66
|
if (typeof value !== "string")
|
|
78
67
|
return value;
|
|
@@ -105,7 +94,7 @@ function offsetValue(value) {
|
|
|
105
94
|
const { x, y } = value;
|
|
106
95
|
return { x: lengthValue(x, false), y: lengthValue(y, false) };
|
|
107
96
|
}
|
|
108
|
-
/**
|
|
97
|
+
/** Wraps a plain value as a constant after `map`; animated values pass through unchanged. */
|
|
109
98
|
function field(value, map) {
|
|
110
99
|
return isAnimated(value) ? value : { mode: "constant", value: map(value) };
|
|
111
100
|
}
|
|
@@ -119,7 +108,7 @@ function scaleField(value) {
|
|
|
119
108
|
}
|
|
120
109
|
return animated(value);
|
|
121
110
|
}
|
|
122
|
-
/** `props`
|
|
111
|
+
/** Expands shorthands in `props` to document fields. */
|
|
123
112
|
function boxFields(props) {
|
|
124
113
|
const fields = {};
|
|
125
114
|
for (const [name, value] of Object.entries(props)) {
|
|
@@ -181,9 +170,21 @@ function boxFields(props) {
|
|
|
181
170
|
case "grid_row":
|
|
182
171
|
fields[name] = checked(value, parsePlacement(value));
|
|
183
172
|
break;
|
|
184
|
-
case "
|
|
173
|
+
case "fill":
|
|
185
174
|
fields[name] = fillValue(value);
|
|
186
175
|
break;
|
|
176
|
+
case "strokes":
|
|
177
|
+
fields[name] = value.map((stroke) => ({
|
|
178
|
+
...stroke,
|
|
179
|
+
color: fillValue(stroke.color),
|
|
180
|
+
}));
|
|
181
|
+
break;
|
|
182
|
+
case "shadows":
|
|
183
|
+
fields[name] = value.map((shadow) => ({
|
|
184
|
+
...shadow,
|
|
185
|
+
color: fillValue(shadow.color),
|
|
186
|
+
}));
|
|
187
|
+
break;
|
|
187
188
|
case "translate":
|
|
188
189
|
fields[name] = field(value, offsetValue);
|
|
189
190
|
break;
|
|
@@ -191,8 +192,7 @@ function boxFields(props) {
|
|
|
191
192
|
fields[name] = scaleField(value);
|
|
192
193
|
break;
|
|
193
194
|
default:
|
|
194
|
-
//
|
|
195
|
-
// anything else the model refuses by name.
|
|
195
|
+
// Written as is; the model rejects unknown fields by name.
|
|
196
196
|
fields[name] = value;
|
|
197
197
|
}
|
|
198
198
|
}
|