alpha2 0.3.1 → 0.4.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.
@@ -0,0 +1,96 @@
1
+ /**
2
+ * The CSS value forms a layout reads, parsed as `alpha2_model::layout_values` parses them, with
3
+ * the same messages: lengths (a number, `"<n>px"`, `"<n>%"`), the four-side shorthand, grid track
4
+ * lists and grid lines, and CSS hex colors. Internal: `validateProject` and the layout builder use
5
+ * it.
6
+ */
7
+ /** A parsed value, or why the text is not one. */
8
+ export type Parsed<T> = {
9
+ readonly ok: true;
10
+ readonly value: T;
11
+ } | {
12
+ readonly ok: false;
13
+ readonly error: string;
14
+ };
15
+ /** A length's unit: a fraction of the shorter side, canvas pixels, or a percent. */
16
+ export type LengthUnit = "fraction" | "px" | "percent";
17
+ /** A length as the engine reads it: its unit and its 32-bit value. */
18
+ export interface Length {
19
+ readonly unit: LengthUnit;
20
+ readonly value: number;
21
+ }
22
+ /**
23
+ * A CSS number without an exponent, read as a JSON number is: through 64 bits to the nearest
24
+ * 32-bit float. `undefined` when it is not one or is not finite.
25
+ */
26
+ export declare function parseNumber(text: string): number | undefined;
27
+ /** A length that may not be a percent (`LayoutSize`), from its string form. */
28
+ export declare function parseSize(text: string): Parsed<Length>;
29
+ /** A length that may be a percent (`LayoutLength`), from its string form. */
30
+ export declare function parseLength(text: string): Parsed<Length>;
31
+ /** Padding or margin sides (`Insets`), top first, from the shorthand string. */
32
+ export declare function parseInsets(text: string): Parsed<readonly [Length, Length, Length, Length]>;
33
+ /** A translation (`LayoutOffset`) from the CSS `translate` string: x, then y (0 when missing). */
34
+ export declare function parseOffset(text: string): Parsed<{
35
+ readonly x: Length;
36
+ readonly y: Length;
37
+ }>;
38
+ /** One side of a track's size. */
39
+ export type TrackBreadth = {
40
+ readonly kind: "length";
41
+ readonly length: Length;
42
+ } | {
43
+ readonly kind: "fr";
44
+ readonly share: number;
45
+ } | {
46
+ readonly kind: "auto" | "min-content" | "max-content";
47
+ };
48
+ /** One track's size. */
49
+ export type TrackSize = {
50
+ readonly kind: "breadth";
51
+ readonly breadth: TrackBreadth;
52
+ } | {
53
+ readonly kind: "minmax";
54
+ readonly min: TrackBreadth;
55
+ readonly max: TrackBreadth;
56
+ } | {
57
+ readonly kind: "fit-content";
58
+ readonly limit: Length;
59
+ };
60
+ /** How often `repeat()` repeats: a count, `auto-fill`, or `auto-fit`. */
61
+ export type RepeatCount = number | "auto-fill" | "auto-fit";
62
+ /** One entry of a track list. */
63
+ export type TrackComponent = {
64
+ readonly kind: "single";
65
+ readonly size: TrackSize;
66
+ } | {
67
+ readonly kind: "repeat";
68
+ readonly count: RepeatCount;
69
+ readonly tracks: readonly TrackSize[];
70
+ };
71
+ /** A grid track list (`TrackList`), from its CSS string. */
72
+ export declare function parseTrackList(text: string): Parsed<TrackComponent[]>;
73
+ /** One edge of a grid placement: `auto`, a line, or a span. */
74
+ export type GridEdge = {
75
+ readonly kind: "auto";
76
+ } | {
77
+ readonly kind: "line";
78
+ readonly line: number;
79
+ } | {
80
+ readonly kind: "span";
81
+ readonly count: number;
82
+ };
83
+ /** Where a grid item lies on one axis (`GridPlacement`), from a line number or its CSS string. */
84
+ export declare function parsePlacement(value: number | string): Parsed<{
85
+ readonly start: GridEdge;
86
+ readonly end: GridEdge;
87
+ }>;
88
+ /** A straight sRGB color with alpha, each component in `0..=1`. */
89
+ export interface Color {
90
+ readonly red: number;
91
+ readonly green: number;
92
+ readonly blue: number;
93
+ readonly alpha: number;
94
+ }
95
+ /** The color a CSS hex string names (`#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`), as 32-bit floats. */
96
+ export declare function parseHex(text: string): Parsed<Color>;
@@ -0,0 +1,370 @@
1
+ /**
2
+ * The CSS value forms a layout reads, parsed as `alpha2_model::layout_values` parses them, with
3
+ * the same messages: lengths (a number, `"<n>px"`, `"<n>%"`), the four-side shorthand, grid track
4
+ * lists and grid lines, and CSS hex colors. Internal: `validateProject` and the layout builder use
5
+ * it.
6
+ */
7
+ const ok = (value) => ({ ok: true, value });
8
+ const refused = (error) => ({ ok: false, error });
9
+ const NUMBER = /^-?(\d+\.?\d*|\.\d+)$/;
10
+ /**
11
+ * A CSS number without an exponent, read as a JSON number is: through 64 bits to the nearest
12
+ * 32-bit float. `undefined` when it is not one or is not finite.
13
+ */
14
+ export function parseNumber(text) {
15
+ if (!NUMBER.test(text))
16
+ return undefined;
17
+ const value = Math.fround(Number(text));
18
+ return Number.isFinite(value) ? value : undefined;
19
+ }
20
+ /** The tokens of a CSS value: runs of characters between ASCII spaces. */
21
+ function tokens(text) {
22
+ return text.split(" ").filter((token) => token.length > 0);
23
+ }
24
+ /** Strips ASCII spaces from both ends, as Rust's `trim_matches(' ')` does. */
25
+ function trimSpaces(text) {
26
+ return text.replace(/^ +| +$/g, "");
27
+ }
28
+ function invalidLength(token, percent) {
29
+ const hint = token.includes(" ")
30
+ ? ` (write ${token.replaceAll(" ", "")})`
31
+ : token.endsWith("em")
32
+ ? " (em and rem are not supported: write px or a number)"
33
+ : "";
34
+ const forms = percent
35
+ ? 'a number, "<n>px", or "<n>%"'
36
+ : 'a number or "<n>px"';
37
+ return `invalid length "${token}"${hint}: write ${forms}`;
38
+ }
39
+ /** One token: a number or `<n>px`; `percent` says whether the field takes a percent. */
40
+ function parseSizeToken(token, percent) {
41
+ if (token.endsWith("px")) {
42
+ const value = parseNumber(token.slice(0, -2));
43
+ return value === undefined
44
+ ? refused(invalidLength(token, percent))
45
+ : ok({ unit: "px", value });
46
+ }
47
+ if (!percent &&
48
+ token.endsWith("%") &&
49
+ parseNumber(token.slice(0, -1)) !== undefined) {
50
+ return refused(`percent is not allowed here: "${token}"`);
51
+ }
52
+ const value = parseNumber(token);
53
+ return value === undefined
54
+ ? refused(invalidLength(token, percent))
55
+ : ok({ unit: "fraction", value });
56
+ }
57
+ /** A length that may not be a percent (`LayoutSize`), from its string form. */
58
+ export function parseSize(text) {
59
+ return parseSizeToken(trimSpaces(text), false);
60
+ }
61
+ /** A length that may be a percent (`LayoutLength`), from its string form. */
62
+ export function parseLength(text) {
63
+ const trimmed = trimSpaces(text);
64
+ if (trimmed.endsWith("%")) {
65
+ const value = parseNumber(trimmed.slice(0, -1));
66
+ return value === undefined
67
+ ? refused(invalidLength(text, true))
68
+ : ok({ unit: "percent", value });
69
+ }
70
+ const size = parseSizeToken(trimmed, true);
71
+ return size.ok ? size : refused(invalidLength(text, true));
72
+ }
73
+ /** The four sides of a CSS shorthand of one to four values, top first. */
74
+ function shorthand(values) {
75
+ const [a, b, c, d] = values;
76
+ switch (values.length) {
77
+ case 1:
78
+ return ok([a, a, a, a]);
79
+ case 2:
80
+ return ok([a, b, a, b]);
81
+ case 3:
82
+ return ok([a, b, c, b]);
83
+ case 4:
84
+ return ok([a, b, c, d]);
85
+ default:
86
+ return refused(`expected 1 to 4 lengths, got ${values.length}`);
87
+ }
88
+ }
89
+ /** Padding or margin sides (`Insets`), top first, from the shorthand string. */
90
+ export function parseInsets(text) {
91
+ const sides = [];
92
+ for (const token of tokens(text)) {
93
+ const side = parseSizeToken(token, false);
94
+ if (!side.ok)
95
+ return side;
96
+ sides.push(side.value);
97
+ }
98
+ return shorthand(sides);
99
+ }
100
+ /** A translation (`LayoutOffset`) from the CSS `translate` string: x, then y (0 when missing). */
101
+ export function parseOffset(text) {
102
+ const values = [];
103
+ for (const token of tokens(text)) {
104
+ const value = parseSizeToken(token, false);
105
+ if (!value.ok)
106
+ return value;
107
+ values.push(value.value);
108
+ }
109
+ if (values.length === 1)
110
+ return ok({ x: values[0], y: { unit: "fraction", value: 0 } });
111
+ if (values.length === 2)
112
+ return ok({ x: values[0], y: values[1] });
113
+ return refused(`expected 1 or 2 lengths, got ${values.length}`);
114
+ }
115
+ function unknownTrack(token) {
116
+ const hints = {
117
+ min_content: "min-content",
118
+ max_content: "max-content",
119
+ auto_fill: "auto-fill",
120
+ auto_fit: "auto-fit",
121
+ };
122
+ if (!(token in hints) && token.startsWith("[")) {
123
+ return `named grid lines are not supported: "${token}"`;
124
+ }
125
+ const hint = hints[token] ?? (token.includes(" ") ? token.replaceAll(" ", "") : "");
126
+ return hint
127
+ ? `unknown track "${token}" (write ${hint})`
128
+ : `unknown track "${token}"`;
129
+ }
130
+ function parseBreadth(token, max) {
131
+ if (token === "auto" || token === "min-content" || token === "max-content")
132
+ return ok({ kind: token });
133
+ if (token.endsWith("fr")) {
134
+ const share = parseNumber(token.slice(0, -2));
135
+ if (share !== undefined) {
136
+ return max
137
+ ? ok({ kind: "fr", share })
138
+ : refused(`a minimum size cannot be fr: "${token}"`);
139
+ }
140
+ }
141
+ const length = parseLength(token);
142
+ return length.ok
143
+ ? ok({ kind: "length", length: length.value })
144
+ : refused(unknownTrack(token));
145
+ }
146
+ /** Reads a track list left to right, as `TrackParser` does. */
147
+ class TrackParser {
148
+ text;
149
+ at = 0;
150
+ constructor(text) {
151
+ this.text = text;
152
+ }
153
+ rest() {
154
+ return this.text.slice(this.at);
155
+ }
156
+ /** Skips spaces; whether anything is left. */
157
+ skipSpaces() {
158
+ while (this.rest().startsWith(" "))
159
+ this.at += 1;
160
+ return this.rest().length > 0;
161
+ }
162
+ /** The next token: up to a space, a comma or a parenthesis. */
163
+ token() {
164
+ const rest = this.rest();
165
+ const match = /[ ,()]/.exec(rest);
166
+ const end = match ? match.index : rest.length;
167
+ this.at += end;
168
+ return rest.slice(0, end);
169
+ }
170
+ expect(expected) {
171
+ this.skipSpaces();
172
+ if (this.rest().startsWith(expected)) {
173
+ this.at += 1;
174
+ return ok(null);
175
+ }
176
+ return refused(`expected "${expected}" in "${this.text}"`);
177
+ }
178
+ breadth(max) {
179
+ this.skipSpaces();
180
+ const token = this.token();
181
+ if (token.length === 0)
182
+ return refused(`expected a track size in "${this.text}"`);
183
+ return parseBreadth(token, max);
184
+ }
185
+ track() {
186
+ const start = this.at;
187
+ const token = this.token();
188
+ if ((token === "minmax" || token === "fit-content") &&
189
+ this.rest().startsWith("(")) {
190
+ this.at += 1;
191
+ if (token === "fit-content") {
192
+ const limit = this.breadth(false);
193
+ if (!limit.ok)
194
+ return limit;
195
+ const close = this.expect(")");
196
+ if (!close.ok)
197
+ return close;
198
+ return limit.value.kind === "length"
199
+ ? ok({ kind: "fit-content", limit: limit.value.length })
200
+ : refused(`fit-content takes a length: "${this.text.slice(start, this.at)}"`);
201
+ }
202
+ const min = this.breadth(false);
203
+ if (!min.ok)
204
+ return min;
205
+ const comma = this.expect(",");
206
+ if (!comma.ok)
207
+ return comma;
208
+ const max = this.breadth(true);
209
+ if (!max.ok)
210
+ return max;
211
+ const close = this.expect(")");
212
+ if (!close.ok)
213
+ return close;
214
+ return ok({ kind: "minmax", min: min.value, max: max.value });
215
+ }
216
+ if (token === "")
217
+ return refused(`expected a track in "${this.text}"`);
218
+ if (token === "fit_content" || token === "min_max") {
219
+ const hint = token.replaceAll("_", "-").replace("min-max", "minmax");
220
+ return refused(`unknown track "${token}" (write ${hint})`);
221
+ }
222
+ // A unit standing apart from its number: "1 fr".
223
+ const after = this.at;
224
+ if (parseNumber(token) !== undefined && this.skipSpaces()) {
225
+ const unit = this.token();
226
+ if (unit === "fr" || unit === "px" || unit === "%") {
227
+ return refused(unknownTrack(this.text.slice(start, this.at)));
228
+ }
229
+ }
230
+ this.at = after;
231
+ const breadth = parseBreadth(token, true);
232
+ return breadth.ok
233
+ ? ok({ kind: "breadth", breadth: breadth.value })
234
+ : breadth;
235
+ }
236
+ repeat() {
237
+ this.skipSpaces();
238
+ const token = this.token();
239
+ let count;
240
+ if (token === "auto-fill" || token === "auto-fit")
241
+ count = token;
242
+ else if (token === "auto_fill" || token === "auto_fit") {
243
+ return refused(`unknown repeat count "${token}" (write ${token.replace("_", "-")})`);
244
+ }
245
+ else if (/^\d+$/.test(token) && Number(token) <= 65535) {
246
+ count = Number(token);
247
+ }
248
+ else
249
+ return refused(`unknown repeat count "${token}"`);
250
+ const comma = this.expect(",");
251
+ if (!comma.ok)
252
+ return comma;
253
+ const tracks = [];
254
+ for (;;) {
255
+ if (!this.skipSpaces())
256
+ return refused(`expected ")" in "${this.text}"`);
257
+ if (this.rest().startsWith(")")) {
258
+ this.at += 1;
259
+ break;
260
+ }
261
+ if (this.rest().startsWith("repeat("))
262
+ return refused("repeat() cannot hold repeat()");
263
+ const track = this.track();
264
+ if (!track.ok)
265
+ return track;
266
+ tracks.push(track.value);
267
+ }
268
+ if (tracks.length === 0)
269
+ return refused("repeat() needs at least one track");
270
+ return ok({ kind: "repeat", count, tracks });
271
+ }
272
+ }
273
+ /** A grid track list (`TrackList`), from its CSS string. */
274
+ export function parseTrackList(text) {
275
+ const parser = new TrackParser(text);
276
+ const components = [];
277
+ while (parser.skipSpaces()) {
278
+ if (parser.rest().startsWith("repeat(")) {
279
+ parser.at += "repeat(".length;
280
+ const repeat = parser.repeat();
281
+ if (!repeat.ok)
282
+ return repeat;
283
+ components.push(repeat.value);
284
+ }
285
+ else {
286
+ const track = parser.track();
287
+ if (!track.ok)
288
+ return track;
289
+ components.push({ kind: "single", size: track.value });
290
+ }
291
+ }
292
+ return components.length === 0
293
+ ? refused("expected at least one track")
294
+ : ok(components);
295
+ }
296
+ function invalidLine(text) {
297
+ const trimmed = trimSpaces(text);
298
+ const named = trimmed
299
+ .split(/[ /]/)
300
+ .filter((word) => word.length > 0)
301
+ .some((word) => word !== "span" && word !== "auto" && /^[A-Za-z]/.test(word));
302
+ return named
303
+ ? `named grid lines are not supported: "${trimmed}"`
304
+ : `invalid grid line "${trimmed}": write a line number, "span <n>", or "auto"`;
305
+ }
306
+ /** An i16, as a CSS integer: digits with an optional minus. */
307
+ function gridInteger(word) {
308
+ if (!/^-?\d+$/.test(word))
309
+ return undefined;
310
+ const value = Number(word);
311
+ return value >= -32768 && value <= 32767 ? value : undefined;
312
+ }
313
+ function parseEdge(text) {
314
+ const words = tokens(text);
315
+ if (words.length === 1 && words[0] === "auto")
316
+ return { kind: "auto" };
317
+ if (words.length === 2 && words[0] === "span") {
318
+ const count = gridInteger(words[1]);
319
+ return count !== undefined && count >= 0
320
+ ? { kind: "span", count }
321
+ : undefined;
322
+ }
323
+ if (words.length === 1) {
324
+ const line = gridInteger(words[0]);
325
+ return line === undefined ? undefined : { kind: "line", line };
326
+ }
327
+ return undefined;
328
+ }
329
+ /** Where a grid item lies on one axis (`GridPlacement`), from a line number or its CSS string. */
330
+ export function parsePlacement(value) {
331
+ if (typeof value === "number") {
332
+ return Number.isInteger(value) && value >= -32768 && value <= 32767
333
+ ? ok({ start: { kind: "line", line: value }, end: { kind: "auto" } })
334
+ : refused(invalidLine(String(value)));
335
+ }
336
+ const split = value.indexOf("/");
337
+ const [start, end] = split < 0
338
+ ? [value, undefined]
339
+ : [value.slice(0, split), value.slice(split + 1)];
340
+ if (end?.includes("/"))
341
+ return refused(invalidLine(value));
342
+ const first = parseEdge(start);
343
+ if (first === undefined)
344
+ return refused(invalidLine(start));
345
+ if (end === undefined)
346
+ return ok({ start: first, end: { kind: "auto" } });
347
+ const second = parseEdge(end);
348
+ return second === undefined
349
+ ? refused(invalidLine(end))
350
+ : ok({ start: first, end: second });
351
+ }
352
+ /** The color a CSS hex string names (`#rgb`, `#rgba`, `#rrggbb`, `#rrggbbaa`), as 32-bit floats. */
353
+ export function parseHex(text) {
354
+ const digits = text.startsWith("#") ? text.slice(1) : undefined;
355
+ if (digits === undefined ||
356
+ ![3, 4, 6, 8].includes(digits.length) ||
357
+ !/^[0-9a-fA-F]*$/.test(digits)) {
358
+ return refused(`invalid color "${text}": write #rgb, #rgba, #rrggbb, or #rrggbbaa`);
359
+ }
360
+ const short = digits.length <= 4;
361
+ const channels = Array.from({ length: short ? digits.length : digits.length / 2 }, (_, index) => Math.fround((short
362
+ ? parseInt(digits[index], 16) * 17
363
+ : parseInt(digits.slice(index * 2, index * 2 + 2), 16)) / 255));
364
+ return ok({
365
+ red: channels[0],
366
+ green: channels[1],
367
+ blue: channels[2],
368
+ alpha: channels[3] ?? 1,
369
+ });
370
+ }
@@ -0,0 +1,167 @@
1
+ /**
2
+ * Layout generators for authors: boxes laid out by CSS flexbox or grid around their text and
3
+ * shapes, as a project's `{ "type": "layout" }` generator holds them.
4
+ *
5
+ * {@link measureLayout} answers, in wasm and with the fonts the engine draws with, where every box
6
+ * of a layout lies on a picture and whether anything overflows, before anything is rendered. The
7
+ * builder ({@link box}, {@link text}, {@link shape}, {@link layout}) writes the document from
8
+ * CSS-like props: a value that is not animated becomes a constant, a `[top, right, bottom, left]`
9
+ * tuple the sides object, an `[x, y]` tuple a vector. Lengths are written as the document writes
10
+ * them: a number is a fraction of the picture's shorter side, `"12px"` pixels of the project
11
+ * canvas, `"50%"` a percent of the parent's content box. Text style (`font_family`, `font_size`,
12
+ * `color`, `line_height`, `text_align`, `outline`) may be set on any box and is inherited. Its
13
+ * output is a plain document that `validateProject` accepts; a CSS value string it cannot read
14
+ * throws, with the parser's message.
15
+ */
16
+ import type { PictureSize } from "./geometry.js";
17
+ import type { AlignContent, AlignItems, Animated, Display, FlexDirection, FlexWrap, Generator, GridAutoFlow, JustifyContent, LayoutNode, Overflow, Paint, Position, Rgba, ShapeItem, TextAlign, TextOutline, Ticks, Vec2 } from "./project.js";
18
+ /** The part of `alpha2/wasm`'s `WasmTextMeasurer` {@link measureLayout} uses. */
19
+ export interface LayoutBinding {
20
+ measureLayout(generatorJson: string, width: number, height: number, time: number, canvasWidth?: number, canvasHeight?: number): string;
21
+ }
22
+ /** A rectangle as fractions of the picture, `(0, 0)` top-left to `(1, 1)` bottom-right. */
23
+ export interface LayoutRect {
24
+ readonly left: number;
25
+ readonly top: number;
26
+ readonly right: number;
27
+ readonly bottom: number;
28
+ }
29
+ /** Where one node lies: its layout boxes, before its clip's transform and node visuals. */
30
+ export interface NodeBounds {
31
+ /** Its path from the root, like `root.children[1]`. */
32
+ readonly at: string;
33
+ /** The border box. */
34
+ readonly border: LayoutRect;
35
+ /** The content box. */
36
+ readonly content: LayoutRect;
37
+ /**
38
+ * Whether it overflows: its text is taller than its content box or splits a word, or an
39
+ * in-flow child reaches past its padding box. Rendering draws it anyway.
40
+ */
41
+ readonly overflow: boolean;
42
+ /** A text node's line count; `null` for other nodes. */
43
+ readonly lineCount: number | null;
44
+ }
45
+ /** Where every node of a layout lies, the root first, in document order. */
46
+ export interface LayoutBounds {
47
+ readonly nodes: readonly NodeBounds[];
48
+ }
49
+ /**
50
+ * Where every node of `generator` (a layout generator, or its root) lies on `picture` at picture
51
+ * time `time`, laid out with `binding`'s fonts as a frame lays it out. Measure at the size the
52
+ * picture is drawn at: at another size, lines can break elsewhere. The layout's `"<n>px"` lengths
53
+ * are pixels of `canvas`, the project canvas: `picture` itself by default, so a preview measured
54
+ * at half size passes the project's own size here.
55
+ *
56
+ * @throws An `INVALID_INPUT` error for a layout the model rejects (on that canvas), a picture or
57
+ * canvas outside 1 to 16384 pixels a side, or a time that is not whole ticks; a text error for a
58
+ * measurer without fonts when the layout has text.
59
+ */
60
+ export declare function measureLayout(binding: LayoutBinding, generator: Generator | LayoutNode, picture: PictureSize, time?: Ticks, canvas?: PictureSize): LayoutBounds;
61
+ /** A value, or the document's animated form of it. */
62
+ export type Value<T> = T | Animated<T>;
63
+ /** A length that may not be a percent: a fraction of the picture's shorter side, or `"12px"`. */
64
+ export type Size = number | `${number}px`;
65
+ /** A size or inset: a {@link Size}, or `"50%"` of the parent's content box. */
66
+ export type Length = Size | `${number}%`;
67
+ /**
68
+ * The sides of a box: one size for all, the CSS shorthand (`"8px 16px"`), a
69
+ * `[top, right, bottom, left]` tuple, or the sides object (missing sides 0).
70
+ */
71
+ export type Sides = number | string | readonly [Size, Size, Size, Size] | {
72
+ readonly top?: Size;
73
+ readonly right?: Size;
74
+ readonly bottom?: Size;
75
+ readonly left?: Size;
76
+ };
77
+ /** A color: the components object, or CSS hex (`"#1e2230"`) as `Rgba` allows. */
78
+ export type Color = Rgba;
79
+ /** A paint, or a color painted solid. */
80
+ export type Fill = Paint | Color;
81
+ /** An offset: the CSS `translate` string (`"10px 20px"`), an `[x, y]` tuple, or `{ x, y }`. */
82
+ export type Offset = string | readonly [Size, Size] | {
83
+ readonly x: Size;
84
+ readonly y: Size;
85
+ };
86
+ /** The style a box gives its text and the boxes in it, inherited as CSS inherits it. */
87
+ export interface TextStyleProps {
88
+ readonly font_family?: string;
89
+ readonly font_size?: Value<Size>;
90
+ readonly color?: Color;
91
+ readonly line_height?: number;
92
+ readonly text_align?: TextAlign;
93
+ readonly outline?: TextOutline;
94
+ }
95
+ /** A box's CSS fields, with shorthands. */
96
+ export interface BoxProps extends TextStyleProps {
97
+ readonly display?: Display;
98
+ readonly flex_direction?: FlexDirection;
99
+ readonly flex_wrap?: FlexWrap;
100
+ /** A grid's columns, as CSS writes them: `"1fr 2fr"`, `"repeat(3, minmax(100px, 1fr))"`. */
101
+ readonly grid_template_columns?: string;
102
+ readonly grid_template_rows?: string;
103
+ readonly grid_auto_columns?: string;
104
+ readonly grid_auto_rows?: string;
105
+ readonly grid_auto_flow?: GridAutoFlow;
106
+ readonly gap?: Value<Size>;
107
+ readonly row_gap?: Value<Size>;
108
+ readonly column_gap?: Value<Size>;
109
+ readonly justify_content?: JustifyContent;
110
+ readonly align_items?: AlignItems;
111
+ readonly align_content?: AlignContent;
112
+ readonly justify_items?: AlignItems;
113
+ readonly padding?: Value<Sides>;
114
+ readonly background?: Value<Fill>;
115
+ readonly border?: {
116
+ readonly width: Value<Size>;
117
+ readonly paint: Value<Fill>;
118
+ };
119
+ readonly border_radius?: Value<Size>;
120
+ readonly overflow?: Overflow;
121
+ readonly width?: Value<Length>;
122
+ readonly height?: Value<Length>;
123
+ readonly min_width?: Value<Length>;
124
+ readonly min_height?: Value<Length>;
125
+ readonly max_width?: Value<Length>;
126
+ readonly max_height?: Value<Length>;
127
+ readonly aspect_ratio?: number;
128
+ readonly margin?: Value<Sides>;
129
+ readonly flex_grow?: Value<number>;
130
+ readonly flex_shrink?: Value<number>;
131
+ readonly flex_basis?: Value<Length>;
132
+ readonly align_self?: AlignItems;
133
+ readonly justify_self?: AlignItems;
134
+ /** The box's grid columns, as CSS writes them: `2`, `"1 / 3"`, `"span 2"`. */
135
+ readonly grid_column?: number | string;
136
+ readonly grid_row?: number | string;
137
+ readonly position?: Position;
138
+ readonly inset?: {
139
+ readonly left?: Value<Length>;
140
+ readonly top?: Value<Length>;
141
+ readonly right?: Value<Length>;
142
+ readonly bottom?: Value<Length>;
143
+ };
144
+ readonly opacity?: Value<number>;
145
+ readonly translate?: Value<Offset>;
146
+ /** One number scales both axes. */
147
+ readonly scale?: Value<Vec2> | number | readonly [number, number];
148
+ readonly rotation_degrees?: Value<number>;
149
+ }
150
+ /** A layout generator whose root is `root`: the whole picture. */
151
+ export declare function layout(root: LayoutNode): Generator;
152
+ /** A box: a container holding `children`, or empty without them. */
153
+ export declare function box(props?: BoxProps, ...children: LayoutNode[]): LayoutNode;
154
+ /**
155
+ * A box holding one paragraph of text, wrapped at its content width and drawn in the style it
156
+ * sets or inherits.
157
+ */
158
+ export declare function text(content: Value<string>, props?: Omit<BoxProps, ContainerField>): LayoutNode;
159
+ /**
160
+ * A box holding shapes, drawn on a picture the size of its content box: positions normalized to
161
+ * it, lengths fractions of its shorter side. It has no size of its own: give it `width` and
162
+ * `height`, an `aspect_ratio`, or `flex_grow`.
163
+ */
164
+ export declare function shape(items: readonly ShapeItem[], props?: Omit<BoxProps, ContainerField>): LayoutNode;
165
+ /** The container fields a text or shape node may not take. */
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";
167
+ export {};