taffy-js 0.2.2 → 0.2.4

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/taffy_js.d.ts CHANGED
@@ -2,818 +2,2039 @@
2
2
  /* eslint-disable */
3
3
 
4
4
  /**
5
- * Multi-line content alignment enum (Align Content)
6
- *
7
- * Controls spacing distribution between lines in a multi-line flex container.
8
- * Corresponds to CSS `align-content` property. Only effective when `flex-wrap: wrap`.
9
- *
10
- * # Variants
11
- * - `SpaceBetween`: Lines evenly distributed, first/last lines flush with edges
12
- * - `SpaceAround`: Equal space on both sides of each line
13
- * - `SpaceEvenly`: All spacing completely equal
5
+ * Available space constraint for layout computation.
6
+ *
7
+ * Specifies how much space is available for a node during layout calculation.
8
+ * This is passed to `computeLayout()` to define the container constraints.
9
+ *
10
+ * @remarks
11
+ * - Use `number` when you have a fixed container size
12
+ * - Use `"minContent"` to shrink-wrap to the minimum content size
13
+ * - Use `"maxContent"` to expand to fit all content without wrapping
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import init, { TaffyTree, Style, type AvailableSpace, type Size } from 'taffy-js';
18
+ *
19
+ * await init();
20
+ * const tree = new TaffyTree();
21
+ * const root: bigint = tree.newLeaf(new Style());
22
+ *
23
+ * // Fixed size container with type annotation
24
+ * const fixedSpace: Size<AvailableSpace> = {
25
+ * width: 800,
26
+ * height: 600
27
+ * };
28
+ * tree.computeLayout(root, fixedSpace);
29
+ *
30
+ * // Flexible width, fixed height
31
+ * const flexibleSpace: Size<AvailableSpace> = {
32
+ * width: "maxContent",
33
+ * height: 400
34
+ * };
35
+ * tree.computeLayout(root, flexibleSpace);
36
+ * ```
37
+ */
38
+ export type AvailableSpace = number | "minContent" | "maxContent";
39
+
40
+ /**
41
+ * Generic size type with width and height.
42
+ *
43
+ * A two-dimensional container for width and height values. The type parameter `T`
44
+ * determines what kind of values are stored.
45
+ *
46
+ * @typeParam T - The type of each dimension (e.g., `number`, `Dimension`, `AvailableSpace`)
47
+ *
48
+ * @property width - The horizontal dimension value
49
+ * @property height - The vertical dimension value
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * import type { Size, Dimension, AvailableSpace } from 'taffy-js';
54
+ *
55
+ * // Size with explicit type parameters
56
+ * const pixelSize: Size<number> = { width: 200, height: 100 };
57
+ *
58
+ * const dimensionSize: Size<Dimension> = {
59
+ * width: { Length: 200 },
60
+ * height: { Percent: 50 }
61
+ * };
62
+ *
63
+ * const availableSize: Size<AvailableSpace> = {
64
+ * width: 800,
65
+ * height: "MaxContent"
66
+ * };
67
+ * ```
68
+ */
69
+ export interface Size<T> {
70
+ /** The horizontal dimension value */
71
+ width: T;
72
+ /** The vertical dimension value */
73
+ height: T;
74
+ }
75
+
76
+ /**
77
+ * Custom measure function for leaf nodes with text or other dynamic content.
78
+ *
79
+ * This callback is invoked during layout computation for leaf nodes that need
80
+ * custom sizing based on their content (e.g., text nodes that need text measurement).
81
+ *
82
+ * @param knownDimensions - Dimensions already determined by constraints. Each dimension
83
+ * is `number` if known, or `null` if needs to be measured.
84
+ * @param availableSpace - The available space constraints for the node. Can be definite
85
+ * pixels, "minContent", or "maxContent".
86
+ * @param node - The node ID (`bigint`) of the node being measured
87
+ * @param context - User-provided context attached to the node via `newLeafWithContext()`
88
+ * @param style - The node's current Style configuration
89
+ *
90
+ * @returns - The measured size of the content in pixels
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * import init, { TaffyTree, Style, type MeasureFunction, type Size } from 'taffy-js';
95
+ *
96
+ * interface TextContext {
97
+ * text: string;
98
+ * fontSize: number;
99
+ * }
100
+ *
101
+ * await init();
102
+ * const tree = new TaffyTree();
103
+ *
104
+ * const style = new Style();
105
+ * const context: TextContext = { text: "Hello, World!", fontSize: 16 };
106
+ * const textNode: bigint = tree.newLeafWithContext(style, context);
107
+ *
108
+ * // Typed measure function
109
+ * const measureText: MeasureFunction = (
110
+ * knownDimensions,
111
+ * availableSpace,
112
+ * node,
113
+ * context,
114
+ * style
115
+ * ): Size<number> => {
116
+ * const ctx = context as TextContext | undefined;
117
+ * if (!ctx?.text) return { width: 0, height: 0 };
118
+ *
119
+ * const width = knownDimensions.width ?? measureTextWidth(ctx.text, ctx.fontSize);
120
+ * const height = knownDimensions.height ?? ctx.fontSize * 1.2;
121
+ *
122
+ * return { width, height };
123
+ * };
124
+ *
125
+ * tree.computeLayoutWithMeasure(
126
+ * textNode,
127
+ * { width: 200, height: "maxContent" },
128
+ * measureText
129
+ * );
130
+ * ```
131
+ */
132
+ export type MeasureFunction = (
133
+ knownDimensions: Size<number | null>,
134
+ availableSpace: Size<AvailableSpace>,
135
+ node: bigint,
136
+ context: any,
137
+ style: Style,
138
+ ) => Size<number>;
139
+
140
+ /**
141
+ * Dimension type supporting length, percentage, or auto values.
142
+ *
143
+ * Used for sizing properties like `width`, `height`, `flexBasis`, etc.
144
+ *
145
+ * @remarks
146
+ * - `number`: Fixed size in pixels
147
+ * - `"{number}%"`: Percentage of parent's size (0-100)
148
+ * - `"auto"`: Size determined by content or layout algorithm
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * import { Style, type Dimension, type Size } from 'taffy-js';
153
+ *
154
+ * const style = new Style();
155
+ *
156
+ * // With explicit type annotations
157
+ * const fixedSize: Size<Dimension> = {
158
+ * width: 200,
159
+ * height: 100
160
+ * };
161
+ *
162
+ * const percentSize: Size<Dimension> = {
163
+ * width: "50%",
164
+ * height: "100%"
165
+ * };
166
+ *
167
+ * const autoSize: Size<Dimension> = {
168
+ * width: "auto",
169
+ * height: "auto"
170
+ * };
171
+ *
172
+ * style.size = fixedSize;
173
+ * ```
174
+ */
175
+ export type Dimension = number | `${number}%` | "auto";
176
+
177
+ /**
178
+ * Length or percentage value (no auto support).
179
+ *
180
+ * Used for properties that require explicit values, such as `padding`, `border`, and `gap`.
181
+ *
182
+ * @remarks
183
+ * - `number`: Fixed size in pixels
184
+ * - `"{number}%"`: Percentage of parent's size (0-100)
185
+ *
186
+ * @example
187
+ * ```typescript
188
+ * import { Style, type LengthPercentage, type Rect, type Size } from 'taffy-js';
189
+ *
190
+ * const style = new Style();
191
+ *
192
+ * const padding: Rect<LengthPercentage> = {
193
+ * left: 10,
194
+ * right: 10,
195
+ * top: 5,
196
+ * bottom: 5
197
+ * };
198
+ *
199
+ * const gap: Size<LengthPercentage> = {
200
+ * width: "5%",
201
+ * height: "5%"
202
+ * };
203
+ *
204
+ * style.padding = padding;
205
+ * style.gap = gap;
206
+ * ```
207
+ */
208
+ export type LengthPercentage = number | `${number}%`;
209
+
210
+ /**
211
+ * Length, percentage, or auto value.
212
+ *
213
+ * Used for properties that support auto values, such as `margin` and `inset`.
214
+ *
215
+ * @remarks
216
+ * - `number`: Fixed size in pixels
217
+ * - `"{number}%"`: Percentage of parent's size (0-100)
218
+ * - `"auto"`: Automatic value (behavior depends on property)
219
+ *
220
+ * @example
221
+ * ```typescript
222
+ * import { Style, type LengthPercentageAuto, type Rect } from 'taffy-js';
223
+ *
224
+ * const style = new Style();
225
+ *
226
+ * // Auto margins for horizontal centering
227
+ * const centerMargin: Rect<LengthPercentageAuto> = {
228
+ * left: "auto",
229
+ * right: "auto",
230
+ * top: 0,
231
+ * bottom: 0
232
+ * };
233
+ *
234
+ * style.margin = centerMargin;
235
+ * ```
236
+ */
237
+ export type LengthPercentageAuto = number | `${number}%` | "auto";
238
+
239
+ /**
240
+ * Point with x and y coordinates/values.
241
+ *
242
+ * Used for properties that have separate horizontal (x) and vertical (y) values,
243
+ * such as `overflow`.
244
+ *
245
+ * @typeParam T - The type of each coordinate
246
+ *
247
+ * @property x - The horizontal value
248
+ * @property y - The vertical value
249
+ *
250
+ * @example
251
+ * ```typescript
252
+ * import { Style, Overflow, type Point } from 'taffy-js';
253
+ *
254
+ * const style = new Style();
255
+ *
256
+ * const overflow: Point<typeof Overflow[keyof typeof Overflow]> = {
257
+ * x: Overflow.Hidden,
258
+ * y: Overflow.Scroll
259
+ * };
260
+ *
261
+ * style.overflow = overflow;
262
+ * ```
263
+ */
264
+ export interface Point<T> {
265
+ /** The horizontal (x-axis) value */
266
+ x: T;
267
+ /** The vertical (y-axis) value */
268
+ y: T;
269
+ }
270
+
271
+ /**
272
+ * Rectangle with left, right, top, and bottom values.
273
+ *
274
+ * Used for box model properties like `margin`, `padding`, `border`, and `inset`.
275
+ *
276
+ * @typeParam T - The type of each side value
277
+ *
278
+ * @property left - The left side value
279
+ * @property right - The right side value
280
+ * @property top - The top side value
281
+ * @property bottom - The bottom side value
282
+ *
283
+ * @example
284
+ * ```typescript
285
+ * import { Style, type Rect, type LengthPercentage, type LengthPercentageAuto } from 'taffy-js';
286
+ *
287
+ * const style = new Style();
288
+ *
289
+ * // Typed padding
290
+ * const padding: Rect<LengthPercentage> = {
291
+ * left: 10,
292
+ * right: 10,
293
+ * top: 10,
294
+ * bottom: 10
295
+ * };
296
+ *
297
+ * // Typed margin with auto
298
+ * const margin: Rect<LengthPercentageAuto> = {
299
+ * left: "auto",
300
+ * right: "auto",
301
+ * top: 10,
302
+ * bottom: 30
303
+ * };
304
+ *
305
+ * style.padding = padding;
306
+ * style.margin = margin;
307
+ * ```
308
+ */
309
+ export interface Rect<T> {
310
+ /** The left side value */
311
+ left: T;
312
+ /** The right side value */
313
+ right: T;
314
+ /** The top side value */
315
+ top: T;
316
+ /** The bottom side value */
317
+ bottom: T;
318
+ }
319
+
320
+ /**
321
+ * Detailed layout information (for grid layouts).
322
+ *
323
+ * Returned by `detailedLayoutInfo()` for nodes using CSS Grid layout.
324
+ * Contains detailed information about grid tracks and item placement.
325
+ *
326
+ * @remarks
327
+ * This is only available when the `detailed_layout_info` feature is enabled.
328
+ *
329
+ * @example
330
+ * ```typescript
331
+ * import type { DetailedLayoutInfo, DetailedGridInfo } from 'taffy-js';
332
+ *
333
+ * const info: DetailedLayoutInfo = tree.detailedLayoutInfo(gridNode);
334
+ *
335
+ * if (info !== "None" && typeof info === 'object' && 'Grid' in info) {
336
+ * const grid: DetailedGridInfo = info.Grid;
337
+ * console.log('Rows:', grid.rows.sizes);
338
+ * console.log('Columns:', grid.columns.sizes);
339
+ * }
340
+ * ```
341
+ */
342
+ export type DetailedLayoutInfo = DetailedGridInfo | null;
343
+
344
+ /**
345
+ * Detailed information about a grid layout.
346
+ *
347
+ * Contains information about grid rows, columns, and item placement.
348
+ *
349
+ * @property rows - Information about row tracks
350
+ * @property columns - Information about column tracks
351
+ * @property items - Array of item placement information
352
+ */
353
+ export interface DetailedGridInfo {
354
+ /** Information about the grid's row tracks */
355
+ rows: DetailedGridTracksInfo;
356
+ /** Information about the grid's column tracks */
357
+ columns: DetailedGridTracksInfo;
358
+ /** Placement information for each grid item */
359
+ items: DetailedGridItemsInfo[];
360
+ }
361
+
362
+ /**
363
+ * Information about grid tracks (rows or columns).
364
+ *
365
+ * Provides detailed sizing and gutter information for a set of grid tracks.
366
+ *
367
+ * @property negative_implicit_tracks - Number of implicit tracks before explicit tracks
368
+ * @property explicit_tracks - Number of explicitly defined tracks
369
+ * @property positive_implicit_tracks - Number of implicit tracks after explicit tracks
370
+ * @property gutters - Array of gutter sizes between tracks (in pixels)
371
+ * @property sizes - Array of track sizes (in pixels)
372
+ */
373
+ export interface DetailedGridTracksInfo {
374
+ /** Number of implicit tracks before explicit tracks (for negative line numbers) */
375
+ negative_implicit_tracks: number;
376
+ /** Number of tracks explicitly defined in grid-template-rows/columns */
377
+ explicit_tracks: number;
378
+ /** Number of implicit tracks created after explicit tracks */
379
+ positive_implicit_tracks: number;
380
+ /** Gap sizes between tracks in pixels */
381
+ gutters: number[];
382
+ /** Computed sizes of each track in pixels */
383
+ sizes: number[];
384
+ }
385
+
386
+ /**
387
+ * Information about a grid item's placement.
388
+ *
389
+ * Specifies which grid lines the item spans on both axes.
390
+ * Line numbers are 1-indexed, with 1 being the first line.
391
+ *
392
+ * @property row_start - Starting row line number (1-indexed)
393
+ * @property row_end - Ending row line number (exclusive)
394
+ * @property column_start - Starting column line number (1-indexed)
395
+ * @property column_end - Ending column line number (exclusive)
396
+ */
397
+ export interface DetailedGridItemsInfo {
398
+ /** Starting row line (1-indexed) */
399
+ row_start: number;
400
+ /** Ending row line (exclusive) */
401
+ row_end: number;
402
+ /** Starting column line (1-indexed) */
403
+ column_start: number;
404
+ /** Ending column line (exclusive) */
405
+ column_end: number;
406
+ }
407
+
408
+ /**
409
+ * Multi-line content alignment enumeration
410
+ *
411
+ * Controls the distribution of space between and around content items along the cross axis
412
+ * in a multi-line flex container. This corresponds to the CSS `align-content` property.
413
+ *
414
+ * **Note**: This property only has effect when `flex-wrap` is set to `Wrap` or `WrapReverse`.
415
+ *
416
+ * @example
417
+ * ```typescript
418
+ * import { AlignContent, FlexWrap } from 'taffy-js';
419
+ *
420
+ * style.flexWrap = FlexWrap.Wrap;
421
+ * style.alignContent = AlignContent.SpaceBetween; // Distribute lines evenly
422
+ * ```
14
423
  */
15
424
  export enum AlignContent {
425
+ /**
426
+ * Lines packed toward the start of the cross axis
427
+ */
16
428
  Start = 0,
429
+ /**
430
+ * Lines packed toward the end of the cross axis
431
+ */
17
432
  End = 1,
433
+ /**
434
+ * Lines packed toward the start of the flex container
435
+ */
18
436
  FlexStart = 2,
437
+ /**
438
+ * Lines packed toward the end of the flex container
439
+ */
19
440
  FlexEnd = 3,
441
+ /**
442
+ * Lines centered within the container
443
+ */
20
444
  Center = 4,
445
+ /**
446
+ * Lines stretched to fill the container
447
+ */
21
448
  Stretch = 5,
449
+ /**
450
+ * Lines evenly distributed with first/last at edges
451
+ */
22
452
  SpaceBetween = 6,
453
+ /**
454
+ * Lines evenly distributed with equal space around each
455
+ */
23
456
  SpaceAround = 7,
457
+ /**
458
+ * Lines evenly distributed with equal space between each
459
+ */
24
460
  SpaceEvenly = 8,
25
461
  }
26
462
 
27
463
  /**
28
- * Cross-axis alignment enum for children (Align Items)
29
- *
30
- * Defines how all children are aligned on the cross axis in a Flex/Grid container.
31
- *
32
- * # Variants
33
- * - `Start/FlexStart`: Align to cross axis start
34
- * - `End/FlexEnd`: Align to cross axis end
35
- * - `Center`: Center alignment
36
- * - `Baseline`: Baseline alignment (text baseline)
37
- * - `Stretch`: Stretch to fill container
464
+ * Cross-axis alignment enumeration for all children
465
+ *
466
+ * Defines the default alignment for all flex/grid items along the cross axis.
467
+ * This corresponds to the CSS `align-items` property.
468
+ *
469
+ * @example
470
+ * ```typescript
471
+ * import { AlignItems } from 'taffy-js';
472
+ *
473
+ * style.alignItems = AlignItems.Center; // Center items on cross axis
474
+ * style.alignItems = AlignItems.Stretch; // Stretch items to fill container
475
+ * ```
38
476
  */
39
477
  export enum AlignItems {
478
+ /**
479
+ * Items aligned to the start of the cross axis
480
+ */
40
481
  Start = 0,
482
+ /**
483
+ * Items aligned to the end of the cross axis
484
+ */
41
485
  End = 1,
486
+ /**
487
+ * Items aligned to the start of the flex container
488
+ */
42
489
  FlexStart = 2,
490
+ /**
491
+ * Items aligned to the end of the flex container
492
+ */
43
493
  FlexEnd = 3,
494
+ /**
495
+ * Items centered along the cross axis
496
+ */
44
497
  Center = 4,
498
+ /**
499
+ * Items aligned to their text baselines
500
+ */
45
501
  Baseline = 5,
502
+ /**
503
+ * Items stretched to fill the container
504
+ */
46
505
  Stretch = 6,
47
506
  }
48
507
 
49
508
  /**
50
- * Cross-axis alignment enum for single element (Align Self)
51
- *
52
- * Overrides parent's `align-items` for a single child element's cross-axis alignment.
53
- *
54
- * # Variants
55
- * - `Auto`: Inherit parent's `align-items` value
56
- * - Other values have same meaning as `AlignItems`
509
+ * Cross-axis alignment enumeration for a single element
510
+ *
511
+ * Overrides the parent's `align-items` value for a specific child element.
512
+ * This corresponds to the CSS `align-self` property.
513
+ *
514
+ * @example
515
+ * ```typescript
516
+ * import { AlignSelf } from 'taffy-js';
517
+ *
518
+ * style.alignSelf = AlignSelf.Auto; // Use parent's align-items
519
+ * style.alignSelf = AlignSelf.Center; // Override to center this item
520
+ * ```
57
521
  */
58
522
  export enum AlignSelf {
523
+ /**
524
+ * Inherits the parent container's `align-items` value
525
+ */
59
526
  Auto = 0,
527
+ /**
528
+ * Item aligned to the start of the cross axis
529
+ */
60
530
  Start = 1,
531
+ /**
532
+ * Item aligned to the end of the cross axis
533
+ */
61
534
  End = 2,
535
+ /**
536
+ * Item aligned to the start of the flex container
537
+ */
62
538
  FlexStart = 3,
539
+ /**
540
+ * Item aligned to the end of the flex container
541
+ */
63
542
  FlexEnd = 4,
543
+ /**
544
+ * Item centered along the cross axis
545
+ */
64
546
  Center = 5,
547
+ /**
548
+ * Item aligned to its text baseline
549
+ */
65
550
  Baseline = 6,
551
+ /**
552
+ * Item stretched to fill the container
553
+ */
66
554
  Stretch = 7,
67
555
  }
68
556
 
69
557
  /**
70
- * Box sizing enum
71
- *
558
+ * Box sizing enumeration
559
+ *
72
560
  * Controls how the total width and height of an element is calculated.
73
- *
74
- * # Variants
75
- * - `BorderBox`: Width and height include content, padding, and border (default)
76
- * - `ContentBox`: Width and height include only the content
561
+ * This corresponds to the CSS `box-sizing` property.
562
+ *
563
+ * @example
564
+ * ```typescript
565
+ * import { BoxSizing } from 'taffy-js';
566
+ *
567
+ * style.boxSizing = BoxSizing.BorderBox; // Size includes padding and border
568
+ * style.boxSizing = BoxSizing.ContentBox; // Size is content only
569
+ * ```
77
570
  */
78
571
  export enum BoxSizing {
572
+ /**
573
+ * The width and height properties include padding and border
574
+ */
79
575
  BorderBox = 0,
576
+ /**
577
+ * The width and height properties include only the content
578
+ */
80
579
  ContentBox = 1,
81
580
  }
82
581
 
83
582
  /**
84
- * Display mode enum
85
- *
86
- * Controls the layout algorithm type for an element. Corresponds to CSS `display` property.
87
- *
88
- * # Variants
89
- * - `Block`: Block-level layout, element takes full width
90
- * - `Flex`: Flexbox layout, one-dimensional layout model
91
- * - `Grid`: CSS Grid layout, two-dimensional layout model
92
- * - `None`: Hidden, element does not participate in layout calculation
583
+ * Display mode enumeration
584
+ *
585
+ * Controls the layout algorithm type for an element. This corresponds to the CSS `display` property
586
+ * and determines how an element and its children are laid out.
587
+ *
588
+ * @example
589
+ * ```typescript
590
+ * import { Display } from 'taffy-js';
591
+ *
592
+ * style.display = Display.Flex; // Enable flexbox layout
593
+ * style.display = Display.Grid; // Enable grid layout
594
+ * style.display = Display.None; // Hide element from layout
595
+ * ```
93
596
  */
94
597
  export enum Display {
598
+ /**
599
+ * Block-level layout where element takes the full available width
600
+ */
95
601
  Block = 0,
602
+ /**
603
+ * Flexbox layout for one-dimensional item arrangement
604
+ */
96
605
  Flex = 1,
606
+ /**
607
+ * CSS Grid layout for two-dimensional item arrangement
608
+ */
97
609
  Grid = 2,
610
+ /**
611
+ * Element is removed from layout calculation entirely
612
+ */
98
613
  None = 3,
99
614
  }
100
615
 
101
616
  /**
102
- * Flex main axis direction enum
103
- *
104
- * Defines the direction children are laid out in a flex container. Corresponds to CSS `flex-direction` property.
105
- *
106
- * # Variants
107
- * - `Row`: Horizontal direction, left to right (LTR mode)
108
- * - `Column`: Vertical direction, top to bottom
109
- * - `RowReverse`: Horizontal reverse, right to left
110
- * - `ColumnReverse`: Vertical reverse, bottom to top
617
+ * Flex direction enumeration
618
+ *
619
+ * Defines the main axis direction for flex item layout. This corresponds to the CSS
620
+ * `flex-direction` property and determines how flex items are placed within the container.
621
+ *
622
+ * @example
623
+ * ```typescript
624
+ * import { FlexDirection } from 'taffy-js';
625
+ *
626
+ * style.flexDirection = FlexDirection.Row; // Horizontal, left to right
627
+ * style.flexDirection = FlexDirection.Column; // Vertical, top to bottom
628
+ * ```
111
629
  */
112
630
  export enum FlexDirection {
631
+ /**
632
+ * Main axis runs horizontally from left to right
633
+ */
113
634
  Row = 0,
635
+ /**
636
+ * Main axis runs vertically from top to bottom
637
+ */
114
638
  Column = 1,
639
+ /**
640
+ * Main axis runs horizontally from right to left
641
+ */
115
642
  RowReverse = 2,
643
+ /**
644
+ * Main axis runs vertically from bottom to top
645
+ */
116
646
  ColumnReverse = 3,
117
647
  }
118
648
 
119
649
  /**
120
- * Flex wrap mode enum
121
- *
122
- * Controls whether flex items wrap onto multiple lines. Corresponds to CSS `flex-wrap` property.
123
- *
124
- * # Variants
125
- * - `NoWrap`: No wrapping, all items compressed into single line/column
126
- * - `Wrap`: Automatic wrapping, items flow to next line when container overflows
127
- * - `WrapReverse`: Reverse wrapping, new lines appear above or to the left
650
+ * Flex wrap mode enumeration
651
+ *
652
+ * Controls whether flex items wrap onto multiple lines when they overflow the container.
653
+ * This corresponds to the CSS `flex-wrap` property.
654
+ *
655
+ * @example
656
+ * ```typescript
657
+ * import { FlexWrap } from 'taffy-js';
658
+ *
659
+ * style.flexWrap = FlexWrap.NoWrap; // All items on single line
660
+ * style.flexWrap = FlexWrap.Wrap; // Items wrap to new lines
661
+ * ```
128
662
  */
129
663
  export enum FlexWrap {
664
+ /**
665
+ * All flex items are placed on a single line
666
+ */
130
667
  NoWrap = 0,
668
+ /**
669
+ * Flex items wrap onto multiple lines from top to bottom
670
+ */
131
671
  Wrap = 1,
672
+ /**
673
+ * Flex items wrap onto multiple lines from bottom to top
674
+ */
132
675
  WrapReverse = 2,
133
676
  }
134
677
 
135
678
  /**
136
- * Main axis alignment enum (Justify Content)
137
- *
138
- * Defines alignment and spacing distribution of children along the main axis.
139
- * Corresponds to CSS `justify-content` property.
140
- *
141
- * # Variants
142
- * - `Start/FlexStart`: Align to main axis start
143
- * - `End/FlexEnd`: Align to main axis end
144
- * - `Center`: Center alignment
145
- * - `SpaceBetween`: First and last items flush with edges, remaining space distributed evenly
146
- * - `SpaceAround`: Equal space on both sides of each item
147
- * - `SpaceEvenly`: All spacing completely equal
679
+ * Main axis alignment enumeration
680
+ *
681
+ * Defines how flex items are aligned and spaced along the main axis.
682
+ * This corresponds to the CSS `justify-content` property.
683
+ *
684
+ * @example
685
+ * ```typescript
686
+ * import { JustifyContent } from 'taffy-js';
687
+ *
688
+ * style.justifyContent = JustifyContent.Center; // Center items
689
+ * style.justifyContent = JustifyContent.SpaceBetween; // Distribute evenly
690
+ * ```
148
691
  */
149
692
  export enum JustifyContent {
693
+ /**
694
+ * Items packed toward the start of the main axis
695
+ */
150
696
  Start = 0,
697
+ /**
698
+ * Items packed toward the end of the main axis
699
+ */
151
700
  End = 1,
701
+ /**
702
+ * Items packed toward the start of the flex container
703
+ */
152
704
  FlexStart = 2,
705
+ /**
706
+ * Items packed toward the end of the flex container
707
+ */
153
708
  FlexEnd = 3,
709
+ /**
710
+ * Items centered along the main axis
711
+ */
154
712
  Center = 4,
713
+ /**
714
+ * Items stretched along the main axis
715
+ */
155
716
  Stretch = 5,
717
+ /**
718
+ * Items evenly distributed with first/last at edges
719
+ */
156
720
  SpaceBetween = 6,
721
+ /**
722
+ * Items evenly distributed with equal space around each
723
+ */
157
724
  SpaceAround = 7,
725
+ /**
726
+ * Items evenly distributed with equal space between each
727
+ */
158
728
  SpaceEvenly = 8,
159
729
  }
160
730
 
161
731
  /**
162
- * Overflow handling enum
163
- *
164
- * Defines how content that overflows container boundaries is handled.
165
- * Corresponds to CSS `overflow` property.
166
- *
167
- * # Variants
168
- * - `Visible`: Content is not clipped
169
- * - `Hidden`: Content is clipped, overflow hidden
170
- * - `Scroll`: Always show scrollbars
171
- * - `Auto`: Show scrollbars when needed (internally mapped to Scroll)
732
+ * Computed layout result containing position, size, and spacing values for a node.
733
+ *
734
+ * This class wraps the native [`taffy::Layout`] and provides read-only access
735
+ * to all computed layout values. All dimensions are in pixels.
736
+ *
737
+ * @example
738
+ * ```typescript
739
+ * const layout = tree.getLayout(node);
740
+ *
741
+ * console.log("Position:", layout.x, layout.y);
742
+ * console.log("Size:", layout.width, layout.height);
743
+ * console.log("Content:", layout.contentWidth, layout.contentHeight);
744
+ * console.log("Padding:", layout.paddingTop, layout.paddingRight, layout.paddingBottom, layout.paddingLeft);
745
+ * console.log("Border:", layout.borderTop, layout.borderRight, layout.borderBottom, layout.borderLeft);
746
+ * console.log("Margin:", layout.marginTop, layout.marginRight, layout.marginBottom, layout.marginLeft);
747
+ * console.log("Scrollbar:", layout.scrollbarWidth, layout.scrollbarHeight);
748
+ * console.log("Order:", layout.order);
749
+ * ```
750
+ */
751
+ export class Layout {
752
+ private constructor();
753
+ free(): void;
754
+ [Symbol.dispose](): void;
755
+ /**
756
+ * Gets the top border width
757
+ *
758
+ * @returns - The computed top border width in pixels
759
+ */
760
+ readonly borderTop: number;
761
+ /**
762
+ * Gets the top margin
763
+ *
764
+ * @returns - The computed top margin in pixels
765
+ */
766
+ readonly marginTop: number;
767
+ /**
768
+ * Gets the left border width
769
+ *
770
+ * @returns - The computed left border width in pixels
771
+ */
772
+ readonly borderLeft: number;
773
+ /**
774
+ * Gets the left margin
775
+ *
776
+ * @returns - The computed left margin in pixels
777
+ */
778
+ readonly marginLeft: number;
779
+ /**
780
+ * Gets the top padding
781
+ *
782
+ * @returns - The computed top padding in pixels
783
+ */
784
+ readonly paddingTop: number;
785
+ /**
786
+ * Gets the right border width
787
+ *
788
+ * @returns - The computed right border width in pixels
789
+ */
790
+ readonly borderRight: number;
791
+ /**
792
+ * Gets the right margin
793
+ *
794
+ * @returns - The computed right margin in pixels
795
+ */
796
+ readonly marginRight: number;
797
+ /**
798
+ * Gets the left padding
799
+ *
800
+ * @returns - The computed left padding in pixels
801
+ */
802
+ readonly paddingLeft: number;
803
+ /**
804
+ * Gets the bottom border width
805
+ *
806
+ * @returns - The computed bottom border width in pixels
807
+ */
808
+ readonly borderBottom: number;
809
+ /**
810
+ * Gets the width of the scrollable content
811
+ *
812
+ * If the node has overflow content, this represents the total
813
+ * width of all content (may exceed `width`).
814
+ *
815
+ * @returns - The content width in pixels
816
+ */
817
+ readonly contentWidth: number;
818
+ /**
819
+ * Gets the bottom margin
820
+ *
821
+ * @returns - The computed bottom margin in pixels
822
+ */
823
+ readonly marginBottom: number;
824
+ /**
825
+ * Gets the right padding
826
+ *
827
+ * @returns - The computed right padding in pixels
828
+ */
829
+ readonly paddingRight: number;
830
+ /**
831
+ * Gets the height of the scrollable content
832
+ *
833
+ * If the node has overflow content, this represents the total
834
+ * height of all content (may exceed `height`).
835
+ *
836
+ * @returns - The content height in pixels
837
+ */
838
+ readonly contentHeight: number;
839
+ /**
840
+ * Gets the bottom padding
841
+ *
842
+ * @returns - The computed bottom padding in pixels
843
+ */
844
+ readonly paddingBottom: number;
845
+ /**
846
+ * Gets the width of the vertical scrollbar
847
+ *
848
+ * When overflow is set to scroll, this indicates the space
849
+ * reserved for the vertical scrollbar.
850
+ *
851
+ * @returns - The scrollbar width in pixels (0 if no scrollbar)
852
+ */
853
+ readonly scrollbarWidth: number;
854
+ /**
855
+ * Gets the height of the horizontal scrollbar
856
+ *
857
+ * When overflow is set to scroll, this indicates the space
858
+ * reserved for the horizontal scrollbar.
859
+ *
860
+ * @returns - The scrollbar height in pixels (0 if no scrollbar)
861
+ */
862
+ readonly scrollbarHeight: number;
863
+ /**
864
+ * Gets the X coordinate of the node's top-left corner
865
+ *
866
+ * This value is relative to the node's parent. For the root node,
867
+ * this is always 0.
868
+ *
869
+ * @returns - The horizontal position in pixels
870
+ */
871
+ readonly x: number;
872
+ /**
873
+ * Gets the Y coordinate of the node's top-left corner
874
+ *
875
+ * This value is relative to the node's parent. For the root node,
876
+ * this is always 0.
877
+ *
878
+ * @returns - The vertical position in pixels
879
+ */
880
+ readonly y: number;
881
+ /**
882
+ * Gets the rendering order of the node
883
+ *
884
+ * This value determines the z-order for overlapping elements.
885
+ * Lower values are rendered first (behind higher values).
886
+ *
887
+ * @returns - The rendering order as an unsigned 32-bit integer
888
+ */
889
+ readonly order: number;
890
+ /**
891
+ * Gets the computed width of the node
892
+ *
893
+ * This is the final width after layout computation, including
894
+ * any constraints from min/max size or flex properties.
895
+ *
896
+ * @returns - The width in pixels
897
+ */
898
+ readonly width: number;
899
+ /**
900
+ * Gets the computed height of the node
901
+ *
902
+ * This is the final height after layout computation, including
903
+ * any constraints from min/max size or flex properties.
904
+ *
905
+ * @returns - The height in pixels
906
+ */
907
+ readonly height: number;
908
+ }
909
+
910
+ /**
911
+ * Overflow handling enumeration
912
+ *
913
+ * Defines how content that exceeds the container boundaries is handled.
914
+ * This corresponds to the CSS `overflow` property.
915
+ *
916
+ * @example
917
+ * ```typescript
918
+ * import { Overflow } from 'taffy-js';
919
+ *
920
+ * style.overflow = { x: Overflow.Hidden, y: Overflow.Scroll };
921
+ * ```
172
922
  */
173
923
  export enum Overflow {
924
+ /**
925
+ * Content is not clipped and may render outside the container
926
+ */
174
927
  Visible = 0,
928
+ /**
929
+ * Content is clipped at the container boundary
930
+ */
175
931
  Hidden = 1,
932
+ /**
933
+ * Always display scrollbars for scrollable content
934
+ */
176
935
  Scroll = 2,
936
+ /**
937
+ * Display scrollbars only when content overflows (internally maps to Scroll)
938
+ */
177
939
  Auto = 3,
178
940
  }
179
941
 
180
942
  /**
181
- * Position mode enum
182
- *
183
- * Controls element positioning method. Corresponds to CSS `position` property.
184
- *
185
- * # Variants
186
- * - `Relative`: Relative positioning, element stays in normal document flow
187
- * - `Absolute`: Absolute positioning, element removed from flow, positioned relative to nearest positioned ancestor
943
+ * Position mode enumeration
944
+ *
945
+ * Controls how an element is positioned within its parent container.
946
+ * This corresponds to the CSS `position` property.
947
+ *
948
+ * @example
949
+ * ```typescript
950
+ * import { Position } from 'taffy-js';
951
+ *
952
+ * style.position = Position.Relative; // Normal document flow
953
+ * style.position = Position.Absolute; // Removed from flow, uses inset values
954
+ * ```
188
955
  */
189
956
  export enum Position {
957
+ /**
958
+ * Element participates in normal document flow
959
+ */
190
960
  Relative = 0,
961
+ /**
962
+ * Element is positioned relative to its nearest positioned ancestor
963
+ */
191
964
  Absolute = 1,
192
965
  }
193
966
 
967
+ /**
968
+ * CSS layout configuration for a node, including flexbox, sizing, spacing, and alignment properties.
969
+ *
970
+ * This class holds all CSS layout properties for a node. Create an instance with
971
+ * `new Style()` and configure properties before passing to `TaffyTree.newLeaf()`.
972
+ *
973
+ * @defaultValue
974
+ * When created, all properties are set to their CSS default values:
975
+ * - `display`: `Display.Block`
976
+ * - `position`: `Position.Relative`
977
+ * - `flexDirection`: `FlexDirection.Row`
978
+ * - `flexWrap`: `FlexWrap.NoWrap`
979
+ * - `flexGrow`: `0`
980
+ * - `flexShrink`: `1`
981
+ * - All alignment properties: `undefined` (use default behavior)
982
+ * - All dimensions: `"Auto"`
983
+ * - All spacing: `{ Length: 0 }`
984
+ *
985
+ */
194
986
  export class Style {
195
987
  free(): void;
196
988
  [Symbol.dispose](): void;
197
989
  /**
198
- * Creates a new Style instance with default values.
199
- *
200
- * All properties are initialized to their CSS default values:
201
- * - display: Block
202
- * - position: Relative
203
- * - flex_direction: Row
204
- * - All dimensions: Auto
205
- * - All spacing (margin, padding, border): 0
206
- *
207
- * # Returns
208
- * A new Style instance with default configuration.
209
- *
210
- * # Example
211
- * ```javascript
990
+ * Creates a new Style instance with default values
991
+ *
992
+ * @returns - A new `Style` object with all properties set to CSS defaults
993
+ *
994
+ * @example
995
+ * ```typescript
212
996
  * const style = new Style();
213
- * style.display = Display.Flex;
997
+ * console.log(style.display); // Display.Block
214
998
  * ```
215
999
  */
216
1000
  constructor();
217
1001
  /**
218
- * Gets the align-self property. Overrides parent's align-items for this element.
219
- * Returns AlignSelf.Auto if not explicitly set.
220
- */
221
- get align_self(): AlignSelf | undefined;
222
- /**
223
- * Sets the align-self property. Use AlignSelf.Auto to inherit from parent.
1002
+ * Gets the align-self property
1003
+ *
1004
+ * Overrides the parent's align-items for this specific element.
1005
+ *
1006
+ * @returns - The current [`AlignSelf`](JsAlignSelf) value (returns `Auto` if not set)
224
1007
  */
225
- set align_self(value: AlignSelf | null | undefined);
1008
+ alignSelf: AlignSelf | undefined;
226
1009
  /**
227
- * Gets the box sizing mode (BorderBox or ContentBox).
1010
+ * Gets the box sizing mode
1011
+ *
1012
+ * Determines whether padding and border are included in dimensions.
1013
+ *
1014
+ * @returns - The current [`BoxSizing`](JsBoxSizing) value
1015
+ *
1016
+ * @defaultValue `BoxSizing.BorderBox`
228
1017
  */
229
- box_sizing: BoxSizing;
1018
+ boxSizing: BoxSizing;
230
1019
  /**
231
- * Gets the flex-basis as a JsDimension (Length, Percent, or Auto).
232
- * Flex-basis defines the initial main size before grow/shrink.
1020
+ * Gets the flex-basis
1021
+ *
1022
+ * The initial size of a flex item before growing/shrinking.
1023
+ *
1024
+ * @returns - A `Dimension` value (`{ Length: n }`, `{ Percent: n }`, or `"Auto"`)
233
1025
  */
234
- flex_basis: any;
1026
+ flexBasis: Dimension;
235
1027
  /**
236
- * Gets the border width as a JsRect<JsLengthPercentage>.
237
- * Border width defines the thickness of element borders.
238
- * Supports Length or Percent for each edge (not Auto).
1028
+ * Gets the border width
1029
+ *
1030
+ * Width of the element's border on each side.
1031
+ *
1032
+ * @returns - A `Rect<LengthPercentage>` with left, right, top, bottom border widths
239
1033
  */
240
- border: any;
1034
+ border: Rect<LengthPercentage>;
241
1035
  /**
242
- * Gets the margin as a JsRect<JsLengthPercentageAuto>.
243
- * Margin is the outer spacing around the element's border.
244
- * Supports Length, Percent, or Auto for each edge.
1036
+ * Gets the margin
1037
+ *
1038
+ * Outer spacing around the element.
1039
+ *
1040
+ * @returns - A `Rect<LengthPercentageAuto>` with left, right, top, bottom margins
245
1041
  */
246
- margin: any;
1042
+ margin: Rect<LengthPercentageAuto>;
247
1043
  /**
248
- * Gets the align-items property. Controls cross-axis alignment of children.
1044
+ * Gets the align-items property
1045
+ *
1046
+ * Defines the default alignment for all children on the cross axis.
1047
+ *
1048
+ * @returns - The current [`AlignItems`](JsAlignItems) value, or `undefined` if not set
249
1049
  */
250
- get align_items(): AlignItems | undefined;
1050
+ alignItems: AlignItems | undefined;
251
1051
  /**
252
- * Sets the align-items property. Affects all children's cross-axis alignment.
1052
+ * Gets the flex shrink factor
1053
+ *
1054
+ * Determines how much the item shrinks relative to siblings when
1055
+ * there is insufficient space.
1056
+ *
1057
+ * @returns - The flex shrink factor (default: 1)
253
1058
  */
254
- set align_items(value: AlignItems | null | undefined);
1059
+ flexShrink: number;
255
1060
  /**
256
- * Gets the flex shrink factor. Determines how much the item shrinks relative to siblings.
257
- */
258
- flex_shrink: number;
259
- /**
260
- * Gets the display mode (Block, Flex, Grid, or None).
1061
+ * Gets the display mode
1062
+ *
1063
+ * Determines the layout algorithm used for this element and its children.
1064
+ *
1065
+ * @returns - The current [`Display`](JsDisplay) value
1066
+ *
1067
+ * @defaultValue - `Display.Block`
261
1068
  */
262
1069
  display: Display;
263
1070
  /**
264
- * Gets the padding as a JsRect<JsLengthPercentage>.
265
- * Padding is the inner spacing between the border and content.
266
- * Supports Length or Percent for each edge (not Auto).
1071
+ * Gets the padding
1072
+ *
1073
+ * Inner spacing between the element's border and content.
1074
+ *
1075
+ * @returns - A `Rect<LengthPercentage>` with left, right, top, bottom padding
267
1076
  */
268
- padding: any;
1077
+ padding: Rect<LengthPercentage>;
269
1078
  /**
270
- * Gets the aspect ratio (width / height). Returns None if not set.
1079
+ * Gets the aspect ratio
1080
+ *
1081
+ * The ratio of width to height. Used to maintain proportions.
1082
+ *
1083
+ * @returns - The aspect ratio value, or `undefined` if not set
271
1084
  */
272
- get aspect_ratio(): number | undefined;
1085
+ aspectRatio: number | undefined;
273
1086
  /**
274
- * Sets the aspect ratio. For example, 16/9 = 1.777... for widescreen.
275
- * Set to None to remove the constraint.
1087
+ * Gets the maximum size constraints
1088
+ *
1089
+ * @returns - A `Size<Dimension>` object with maximum width and height
276
1090
  */
277
- set aspect_ratio(value: number | null | undefined);
1091
+ maxSize: Size<Dimension>;
278
1092
  /**
279
- * Gets the maximum size constraints as a JsSize<JsDimension>.
280
- * Prevents the element from growing beyond these values.
1093
+ * Gets the minimum size constraints
1094
+ *
1095
+ * @returns - A `Size<Dimension>` object with minimum width and height
281
1096
  */
282
- max_size: any;
1097
+ minSize: Size<Dimension>;
283
1098
  /**
284
- * Gets the minimum size constraints as a JsSize<JsDimension>.
285
- * Prevents the element from shrinking below these values.
1099
+ * Gets the overflow behavior
1100
+ *
1101
+ * Controls how content that exceeds the container is handled.
1102
+ *
1103
+ * @returns - A `Point<Overflow>` with `x` and `y` overflow settings
286
1104
  */
287
- min_size: any;
1105
+ overflow: Point<Overflow>;
288
1106
  /**
289
- * Gets the overflow behavior as a JS object with {x, y} properties.
290
- */
291
- overflow: any;
292
- /**
293
- * Gets the position mode (Relative or Absolute).
1107
+ * Gets the position mode
1108
+ *
1109
+ * Determines how the element is positioned within its parent.
1110
+ *
1111
+ * @returns - The current [`Position`](JsPosition) value
1112
+ *
1113
+ * @defaultValue - `Position.Relative`
294
1114
  */
295
1115
  position: Position;
296
1116
  /**
297
- * Gets the align-content property. Controls spacing between lines in multi-line flex.
1117
+ * Gets the align-content property
1118
+ *
1119
+ * Controls distribution of space between lines in a multi-line flex container.
1120
+ *
1121
+ * @returns - The current [`AlignContent`](JsAlignContent) value, or `undefined` if not set
298
1122
  */
299
- get align_content(): AlignContent | undefined;
1123
+ alignContent: AlignContent | undefined;
300
1124
  /**
301
- * Sets the align-content property. Only effective when flex-wrap is enabled.
1125
+ * Gets the flex grow factor
1126
+ *
1127
+ * Determines how much the item grows relative to siblings when
1128
+ * there is extra space available.
1129
+ *
1130
+ * @returns - The flex grow factor (default: 0)
302
1131
  */
303
- set align_content(value: AlignContent | null | undefined);
1132
+ flexGrow: number;
304
1133
  /**
305
- * Gets the flex grow factor. Determines how much the item grows relative to siblings.
1134
+ * Gets the flex wrap mode
1135
+ *
1136
+ * Controls whether flex items wrap to new lines.
1137
+ *
1138
+ * @returns - The current [`FlexWrap`](JsFlexWrap) value
1139
+ *
1140
+ * @defaultValue - `FlexWrap.NoWrap`
306
1141
  */
307
- flex_grow: number;
1142
+ flexWrap: FlexWrap;
308
1143
  /**
309
- * Gets the flex wrap mode (NoWrap, Wrap, WrapReverse).
1144
+ * Gets the flex direction
1145
+ *
1146
+ * Defines the main axis direction for flex items.
1147
+ *
1148
+ * @returns - The current [`FlexDirection`](JsFlexDirection) value
1149
+ *
1150
+ * @defaultValue - `FlexDirection.Row`
310
1151
  */
311
- flex_wrap: FlexWrap;
1152
+ flexDirection: FlexDirection;
312
1153
  /**
313
- * Gets the flex direction (Row, Column, RowReverse, ColumnReverse).
1154
+ * Gets the justify-content property
1155
+ *
1156
+ * Defines alignment and spacing of items along the main axis.
1157
+ *
1158
+ * @returns - The current [`JustifyContent`](JsJustifyContent) value, or `undefined` if not set
314
1159
  */
315
- flex_direction: FlexDirection;
1160
+ justifyContent: JustifyContent | undefined;
316
1161
  /**
317
- * Gets the justify-content property. Controls main-axis alignment and spacing.
1162
+ * Gets the gap
1163
+ *
1164
+ * Spacing between flex/grid items.
1165
+ *
1166
+ * @returns - A `Size<LengthPercentage>` with column (width) and row (height) gaps
318
1167
  */
319
- get justify_content(): JustifyContent | undefined;
1168
+ gap: Size<LengthPercentage>;
320
1169
  /**
321
- * Sets the justify-content property. Distributes space along the main axis.
1170
+ * Gets the size (width and height)
1171
+ *
1172
+ * @returns - A `Size<Dimension>` object with `width` and `height` properties
322
1173
  */
323
- set justify_content(value: JustifyContent | null | undefined);
1174
+ size: Size<Dimension>;
324
1175
  /**
325
- * Gets the gap between children as a JsSize<JsLengthPercentage>.
326
- * Used in Flex and Grid layouts to add spacing between items.
327
- * - width: column gap (horizontal spacing)
328
- * - height: row gap (vertical spacing)
1176
+ * Gets the inset
1177
+ *
1178
+ * Positioning offsets for absolutely positioned elements.
1179
+ *
1180
+ * @returns - A `Rect<LengthPercentageAuto>` with left, right, top, bottom offsets
329
1181
  */
330
- gap: any;
331
- /**
332
- * Gets the size (width, height) as a JsSize<JsDimension>.
333
- * Each dimension can be Length, Percent, or Auto.
334
- */
335
- size: any;
1182
+ inset: Rect<LengthPercentageAuto>;
1183
+ }
1184
+
1185
+ /**
1186
+ * Error class thrown when a Taffy operation fails, containing a human-readable error message.
1187
+ *
1188
+ * This class wraps the native [`taffy::TaffyError`] type and exposes it to JavaScript
1189
+ * with a readable error message. It is thrown as a JavaScript exception on failure.
1190
+ *
1191
+ * @example
1192
+ * ```typescript
1193
+ * try {
1194
+ * tree.remove(node);
1195
+ * } catch (e) {
1196
+ * if (e instanceof TaffyError) {
1197
+ * console.error(e.message);
1198
+ * }
1199
+ * }
1200
+ * ```
1201
+ *
1202
+ * @remarks
1203
+ * The underlying Taffy errors include:
1204
+ * - `InvalidInputNode`: Node ID doesn't exist in the tree
1205
+ * - `InvalidParentNode`: Specified parent node doesn't exist
1206
+ * - `ChildIndexOutOfBounds`: Child index exceeds available children
1207
+ */
1208
+ export class TaffyError {
1209
+ private constructor();
1210
+ free(): void;
1211
+ [Symbol.dispose](): void;
336
1212
  /**
337
- * Gets the inset (absolute positioning offsets) as a JsRect<JsLengthPercentageAuto>.
338
- * Only effective when position is Absolute.
339
- * Defines the distance from each edge of the containing block.
1213
+ * Gets the human-readable error message
1214
+ *
1215
+ * @returns - A string describing what went wrong.
1216
+ *
1217
+ * @remarks
1218
+ * Examples:
1219
+ * - "Node with id 1234 is not present in the Taffy tree"
1220
+ * - "Index 5 is out of bounds for node with 3 children"
340
1221
  */
341
- inset: any;
1222
+ readonly message: string;
342
1223
  }
343
1224
 
1225
+ /**
1226
+ * The main layout tree class for creating nodes, computing layouts, and managing a tree of styled elements.
1227
+ *
1228
+ * TaffyTree is the entry point for the Taffy layout engine. It manages
1229
+ * a tree of nodes and computes their layouts using CSS Flexbox and Grid algorithms.
1230
+ *
1231
+ */
344
1232
  export class TaffyTree {
345
1233
  free(): void;
346
1234
  [Symbol.dispose](): void;
347
1235
  /**
348
- * Marks a node as dirty, requiring re-layout.
349
- *
350
- * Call this when a node's content changes (e.g., text content)
351
- * but its style hasn't. Style changes automatically mark nodes dirty.
352
- *
353
- * # Arguments
354
- * * `node` - The node ID to mark dirty.
1236
+ * Marks a node as dirty (requiring re-layout)
1237
+ *
1238
+ * Use this when a node's content has changed but its style hasn't.
1239
+ * For example, when text content changes and needs remeasuring.
1240
+ *
1241
+ * @param node - The node ID to mark dirty
1242
+ *
1243
+ * @throws `TaffyError` if the node does not exist
1244
+ *
1245
+ * @example
1246
+ * ```typescript
1247
+ * // After updating text content
1248
+ * tree.setNodeContext(nodeId, { text: "Updated text" });
1249
+ * tree.markDirty(nodeId);
1250
+ * tree.computeLayout(rootId, availableSpace);
1251
+ * ```
355
1252
  */
356
1253
  markDirty(node: bigint): void;
357
1254
  /**
358
- * Prints the tree structure to the console (for debugging).
359
- *
360
- * # Arguments
361
- * * `node` - The root node ID to start printing from.
1255
+ * Prints the tree structure to the console (for debugging)
1256
+ *
1257
+ * Outputs a text representation of the tree structure starting from
1258
+ * the given node. Useful for debugging layout issues.
1259
+ *
1260
+ * @param node - The root node ID to print from
1261
+ *
1262
+ * @example
1263
+ * ```typescript
1264
+ * tree.printTree(rootId);
1265
+ * // Output appears in browser console
1266
+ * ```
362
1267
  */
363
1268
  printTree(node: bigint): void;
364
1269
  /**
365
- * Gets the number of children of a node.
366
- *
367
- * # Arguments
368
- * * `parent` - The parent node ID.
369
- *
370
- * # Returns
371
- * The number of children.
1270
+ * Gets the number of children of a node
1271
+ *
1272
+ * @param parent - The parent node ID
1273
+ *
1274
+ * @returns - The number of direct children
1275
+ *
1276
+ * @throws `TaffyError` if the node does not exist
1277
+ *
1278
+ * @example
1279
+ * ```typescript
1280
+ * const count: number = tree.childCount(parentId);
1281
+ * ```
372
1282
  */
373
1283
  childCount(parent: bigint): number;
374
1284
  /**
375
- * Removes a specific child from a parent.
376
- *
377
- * # Arguments
378
- * * `parent` - The parent node ID.
379
- * * `child` - The child node ID to remove.
380
- *
381
- * # Returns
382
- * * `Ok(u64)` - The ID of the removed child.
383
- * * `Err(JsValue)` - Error if parent or child doesn't exist.
1285
+ * Removes a specific child from a parent
1286
+ *
1287
+ * @param parent - The parent node ID
1288
+ * @param child - The child node ID to remove
1289
+ *
1290
+ * @returns - The removed child ID (`bigint`)
1291
+ *
1292
+ * @throws `TaffyError` if the parent or child node does not exist
1293
+ *
1294
+ * @example
1295
+ * ```typescript
1296
+ * tree.removeChild(parentId, childId);
1297
+ * ```
384
1298
  */
385
1299
  removeChild(parent: bigint, child: bigint): bigint;
386
1300
  /**
387
- * Replaces all children of a node.
388
- *
389
- * Previous children are detached but not removed from the tree.
390
- *
391
- * # Arguments
392
- * * `parent` - The parent node ID.
393
- * * `children` - Array of new child node IDs.
1301
+ * Replaces all children of a node
1302
+ *
1303
+ * Any existing children are removed and replaced with the new array.
1304
+ *
1305
+ * @param parent - The parent node ID
1306
+ * @param children - Array of new child node IDs
1307
+ *
1308
+ * @throws `TaffyError` if the parent node does not exist
1309
+ *
1310
+ * @example
1311
+ * ```typescript
1312
+ * const children = BigUint64Array.from([child1, child2, child3]);
1313
+ * tree.setChildren(parentId, children);
1314
+ * ```
394
1315
  */
395
1316
  setChildren(parent: bigint, children: BigUint64Array): void;
396
1317
  /**
397
- * Creates a new TaffyTree with pre-allocated capacity.
398
- *
399
- * Use this when you know approximately how many nodes you'll create
400
- * to avoid reallocation overhead.
401
- *
402
- * # Arguments
403
- * * `capacity` - The number of nodes to pre-allocate space for.
404
- *
405
- * # Returns
406
- * A new TaffyTree instance with pre-allocated capacity.
1318
+ * Creates a new TaffyTree with pre-allocated capacity
1319
+ *
1320
+ * Use this when you know approximately how many nodes will be in the tree.
1321
+ * This can improve performance by reducing memory reallocations.
1322
+ *
1323
+ * @param capacity - The number of nodes to pre-allocate space for
1324
+ *
1325
+ * @example
1326
+ * ```typescript
1327
+ * const tree: TaffyTree = TaffyTree.withCapacity(1000);
1328
+ * ```
407
1329
  */
408
1330
  static withCapacity(capacity: number): TaffyTree;
409
1331
  /**
410
- * Gets a child at a specific index.
411
- *
412
- * # Arguments
413
- * * `parent` - The parent node ID.
414
- * * `index` - The zero-based index.
415
- *
416
- * # Returns
417
- * * `Ok(u64)` - The child node ID at the given index.
418
- * * `Err(JsValue)` - Error if index is out of bounds.
1332
+ * Computes the layout for a subtree
1333
+ *
1334
+ * This is the main layout computation method. Call this on the root node
1335
+ * to compute layouts for all nodes in the tree.
1336
+ *
1337
+ * @param node - The root node ID to compute layout for
1338
+ * @param available_space - The available space constraints
1339
+ *
1340
+ * @example
1341
+ * ```typescript
1342
+ * // Fixed size container
1343
+ * { width: { Definite: 800 }, height: { Definite: 600 } }
1344
+ *
1345
+ * // Flexible width, fixed height
1346
+ * { width: "MaxContent", height: { Definite: 600 } }
1347
+ *
1348
+ * // Minimum content size
1349
+ * { width: "MinContent", height: "MinContent" }
1350
+ * ```
1351
+ *
1352
+ * @throws `TaffyError` if the node does not exist or available space is invalid
1353
+ *
1354
+ * @example
1355
+ * ```typescript
1356
+ * tree.computeLayout(rootId, { width: { Definite: 800 }, height: { Definite: 600 } });
1357
+ * ```
419
1358
  */
420
- getChildAtIndex(parent: bigint, index: number): bigint;
1359
+ computeLayout(node: bigint, available_space: Size<AvailableSpace>): void;
421
1360
  /**
422
- * Computes the layout for a subtree.
423
- *
424
- * Runs the layout algorithm (Flexbox/Grid/Block) on the given node
425
- * and all its descendants. Results are cached and can be retrieved
426
- * with `getLayout()`.
427
- *
428
- * # Arguments
429
- * * `node` - The root node ID for layout computation.
430
- * * `available_space` - The available space constraint, e.g.:
431
- * `{ width: { Definite: 800 }, height: { Definite: 600 } }`
432
- *
433
- * Available space options per dimension:
434
- * - `{ Definite: number }` - A specific size in pixels
435
- * - `"MinContent"` - Use minimum content size
436
- * - `"MaxContent"` - Use maximum content size
437
- */
438
- computeLayout(node: bigint, available_space: any): void;
439
- /**
440
- * Enables rounding of layout values to whole pixels.
441
- *
442
- * When enabled, all computed layout values (x, y, width, height) are
443
- * rounded to the nearest integer. This is the default behavior.
1361
+ * Enables rounding of layout values to whole pixels
1362
+ *
1363
+ * When enabled (default), computed layout values like position and size
1364
+ * are rounded to the nearest integer. This prevents sub-pixel rendering
1365
+ * issues in most rendering contexts.
1366
+ *
1367
+ * @example
1368
+ * ```typescript
1369
+ * tree.enableRounding();
1370
+ * ```
444
1371
  */
445
1372
  enableRounding(): void;
446
1373
  /**
447
- * Disables rounding of layout values.
448
- *
449
- * When disabled, layout values may have fractional pixel values.
450
- * Use `unroundedLayout()` to get the pre-rounding values.
1374
+ * Disables rounding of layout values
1375
+ *
1376
+ * When disabled, computed layout values retain their fractional precision.
1377
+ * Use this when you need sub-pixel accuracy or when performing custom
1378
+ * rounding.
1379
+ *
1380
+ * @example
1381
+ * ```typescript
1382
+ * tree.disableRounding();
1383
+ * const layout = tree.getLayout(node);
1384
+ * console.log(layout.x);
1385
+ * ```
451
1386
  */
452
1387
  disableRounding(): void;
453
1388
  /**
454
- * Gets the context value for a node.
455
- *
456
- * # Arguments
457
- * * `node` - The node ID.
458
- *
459
- * # Returns
460
- * The context value, or `undefined` if not set.
1389
+ * Gets the context value for a node
1390
+ *
1391
+ * @param node - The node ID
1392
+ *
1393
+ * @returns - The attached context value, or `undefined` if none is set
1394
+ *
1395
+ * @example
1396
+ * ```typescript
1397
+ * interface Context { text: string };
1398
+ * const context = tree.getNodeContext(nodeId) as Context | undefined;
1399
+ * if (context) {
1400
+ * console.log(context.text);
1401
+ * }
1402
+ * ```
461
1403
  */
462
1404
  getNodeContext(node: bigint): any;
463
1405
  /**
464
- * Sets a context value for a node.
465
- *
466
- * Context values are passed to the measure function during layout.
467
- * Use this to attach data like text content or custom metadata.
468
- *
469
- * # Arguments
470
- * * `node` - The node ID.
471
- * * `context` - Any JavaScript value.
1406
+ * Sets a context value for a node
1407
+ *
1408
+ * The context can be any JavaScript value and is passed to the measure
1409
+ * function during layout computation.
1410
+ *
1411
+ * @param node - The node ID
1412
+ * @param context - Any JavaScript value to attach
1413
+ *
1414
+ * @throws `TaffyError` if the node does not exist
1415
+ *
1416
+ * @example
1417
+ * ```typescript
1418
+ * interface Context { text: string };
1419
+ * tree.setNodeContext(nodeId, { text: "Updated text" } as Context);
1420
+ * ```
472
1421
  */
473
1422
  setNodeContext(node: bigint, context: any): void;
474
1423
  /**
475
- * Gets the total number of nodes in the tree.
476
- *
477
- * # Returns
478
- * The count of all nodes (including removed nodes that haven't been reclaimed).
1424
+ * Gets the total number of nodes in the tree
1425
+ *
1426
+ * @returns - The total count of all nodes
1427
+ *
1428
+ * @example
1429
+ * ```typescript
1430
+ * const count: number = tree.totalNodeCount();
1431
+ * ```
479
1432
  */
480
1433
  totalNodeCount(): number;
481
1434
  /**
482
- * Gets the unrounded (fractional) layout for a node.
483
- *
1435
+ * Gets the unrounded (fractional) layout for a node
1436
+ *
1437
+ * Returns the raw computed values before any rounding is applied.
484
1438
  * Useful when you need sub-pixel precision.
485
- *
486
- * # Arguments
487
- * * `node` - The node ID to query.
488
- *
489
- * # Returns
490
- * A layout object with potentially fractional values.
491
- */
492
- unroundedLayout(node: bigint): any;
493
- /**
494
- * Creates a new node with the given children.
495
- *
496
- * # Arguments
497
- * * `style` - The Style object to apply to this node.
498
- * * `children` - Array of child node IDs.
499
- *
500
- * # Returns
501
- * * `Ok(u64)` - The node ID of the newly created node.
502
- * * `Err(JsValue)` - Error message if creation fails.
1439
+ *
1440
+ * @param node - The node ID
1441
+ *
1442
+ * @returns - The unrounded `Layout`
1443
+ *
1444
+ * @example
1445
+ * ```typescript
1446
+ * const layout: Layout = tree.unroundedLayout(nodeId);
1447
+ * console.log(`Exact width: ${layout.width}`);
1448
+ * ```
1449
+ */
1450
+ unroundedLayout(node: bigint): Layout;
1451
+ /**
1452
+ * Creates a new node with the given children
1453
+ *
1454
+ * Use this to create container nodes that have child elements.
1455
+ * The children must already exist in the tree.
1456
+ *
1457
+ * @param style - The style configuration for the node
1458
+ * @param children - Array of child node IDs (as BigUint64Array)
1459
+ *
1460
+ * @returns - The node ID (`bigint`)
1461
+ *
1462
+ * @throws `TaffyError` if the node cannot be created
1463
+ *
1464
+ * @example
1465
+ * ```typescript
1466
+ * const containerStyle = new Style();
1467
+ * containerStyle.display = Display.Flex;
1468
+ *
1469
+ * const child1: bigint = tree.newLeaf(new Style());
1470
+ * const child2: bigint = tree.newLeaf(new Style());
1471
+ *
1472
+ * const container: bigint = tree.newWithChildren(
1473
+ * containerStyle,
1474
+ * BigUint64Array.from([child1, child2])
1475
+ * );
1476
+ * ```
503
1477
  */
504
1478
  newWithChildren(style: Style, children: BigUint64Array): bigint;
505
1479
  /**
506
- * Gets a mutable reference to the context value for a node.
507
- *
508
- * Note: In WASM, this returns a clone since we can't return mutable references.
509
- *
510
- * # Arguments
511
- * * `node` - The node ID.
512
- *
513
- * # Returns
514
- * The context value, or `undefined` if not set.
1480
+ * Gets the child at a specific index
1481
+ *
1482
+ * @param parent - The parent node ID
1483
+ * @param index - The index of the child (0-based)
1484
+ *
1485
+ * @returns - The child node ID (`bigint`)
1486
+ *
1487
+ * @throws `TaffyError` if the parent node does not exist or index is out of bounds
1488
+ *
1489
+ * @example
1490
+ * ```typescript
1491
+ * const firstChild: bigint = tree.getChildAtIndex(parentId, 0);
1492
+ * ```
1493
+ */
1494
+ getChildAtIndex(parent: bigint, index: number): bigint;
1495
+ /**
1496
+ * Gets a mutable reference to the context value for a node
1497
+ *
1498
+ * In JavaScript, this behaves the same as `getNodeContext()` since
1499
+ * JavaScript objects are always passed by reference.
1500
+ *
1501
+ * @param node - The node ID
1502
+ *
1503
+ * @returns - The attached context value, or `undefined` if none is set
515
1504
  */
516
1505
  getNodeContextMut(node: bigint): any;
517
1506
  /**
518
- * Inserts a child at a specific index.
519
- *
520
- * Existing children at and after the index are shifted right.
521
- *
522
- * # Arguments
523
- * * `parent` - The parent node ID.
524
- * * `index` - The zero-based index at which to insert.
525
- * * `child` - The child node ID to insert.
1507
+ * Inserts a child at a specific index
1508
+ *
1509
+ * @param parent - The parent node ID
1510
+ * @param index - The position to insert at (0-based)
1511
+ * @param child - The child node ID to insert
1512
+ *
1513
+ * @throws `TaffyError` if the parent or child node does not exist, or index is out of bounds
1514
+ *
1515
+ * @example
1516
+ * ```typescript
1517
+ * tree.insertChildAtIndex(parentId, 0, childId);
1518
+ * ```
526
1519
  */
527
1520
  insertChildAtIndex(parent: bigint, index: number, child: bigint): void;
528
1521
  /**
529
- * Creates a new leaf node with an attached context value.
530
- *
531
- * The context can be any JavaScript value and is useful for associating
532
- * custom data (like text content) with a node for use in measure functions.
533
- *
534
- * # Arguments
535
- * * `style` - The Style object to apply to this node.
536
- * * `context` - Any JavaScript value to attach to this node.
537
- *
538
- * # Returns
539
- * * `Ok(u64)` - The node ID of the newly created node.
540
- * * `Err(JsValue)` - Error message if creation fails.
1522
+ * Creates a new leaf node with an attached context value
1523
+ *
1524
+ * The context can be any JavaScript value and is passed to the measure
1525
+ * function during layout computation. This is useful for storing
1526
+ * references to text content or other dynamic data.
1527
+ *
1528
+ * @param style - The style configuration for the node
1529
+ * @param context - Any JavaScript value to attach to the node
1530
+ * @returns - The node ID (`bigint`)
1531
+ * @throws `TaffyError` if the node cannot be created
1532
+ *
1533
+ * @example
1534
+ * ```typescript
1535
+ * interface TextContext { text: string; isBold: boolean; }
1536
+ *
1537
+ * const style = new Style();
1538
+ * const context: TextContext = { text: "Hello, World!", isBold: true };
1539
+ * const nodeId: bigint = tree.newLeafWithContext(style, context);
1540
+ * ```
541
1541
  */
542
1542
  newLeafWithContext(style: Style, context: any): bigint;
543
1543
  /**
544
- * Removes a child at a specific index.
545
- *
546
- * # Arguments
547
- * * `parent` - The parent node ID.
548
- * * `index` - The zero-based index of the child to remove.
549
- *
550
- * # Returns
551
- * * `Ok(u64)` - The ID of the removed child.
552
- * * `Err(JsValue)` - Error if index is out of bounds.
1544
+ * Removes a child at a specific index
1545
+ *
1546
+ * @param parent - The parent node ID
1547
+ * @param index - The index of the child to remove (0-based)
1548
+ *
1549
+ * @returns - The removed child ID (`bigint`)
1550
+ *
1551
+ * @throws `TaffyError` if the parent node does not exist or index is out of bounds
1552
+ *
1553
+ * @example
1554
+ * ```typescript
1555
+ * const removedId: bigint = tree.removeChildAtIndex(parentId, 0);
1556
+ * ```
553
1557
  */
554
1558
  removeChildAtIndex(parent: bigint, index: number): bigint;
555
1559
  /**
556
- * Removes a range of children from a parent.
557
- *
558
- * # Arguments
559
- * * `parent` - The parent node ID.
560
- * * `start` - The start index (inclusive).
561
- * * `end` - The end index (exclusive).
562
- */
563
- removeChildrenRange(parent: bigint, start: number, end: number): void;
564
- /**
565
- * Replaces a child at a specific index with a new child.
566
- *
567
- * # Arguments
568
- * * `parent` - The parent node ID.
569
- * * `index` - The zero-based index of the child to replace.
570
- * * `child` - The new child node ID.
571
- *
572
- * # Returns
573
- * * `Ok(u64)` - The ID of the replaced (old) child.
574
- * * `Err(JsValue)` - Error if index is out of bounds.
575
- */
576
- replaceChildAtIndex(parent: bigint, index: number, child: bigint): bigint;
577
- /**
578
- * Computes layout with a custom measure function for leaf nodes.
579
- *
580
- * The measure function is called for leaf nodes to determine their
581
- * intrinsic size (e.g., for text measurement).
582
- *
583
- * # Arguments
584
- * * `node` - The root node ID for layout computation.
585
- * * `available_space` - The available space constraint.
586
- * * `measure_func` - A JavaScript function with signature:
587
- * `(knownDimensions, availableSpace, context) => { width, height }`
588
- *
589
- * The measure function receives:
590
- * - `knownDimensions`: `{ width: number | null, height: number | null }`
591
- * - `availableSpace`: `{ width: AvailableSpace, height: AvailableSpace }`
592
- * - `context`: The context value attached to the node (or undefined)
593
- *
594
- * And should return: `{ width: number, height: number }`
595
- */
596
- computeLayoutWithMeasure(node: bigint, available_space: any, measure_func: Function): void;
597
- /**
598
- * Gets context values for multiple nodes at once.
599
- *
600
- * Useful for batch operations.
601
- *
602
- * # Arguments
603
- * * `children` - Array of node IDs to query.
604
- *
605
- * # Returns
606
- * Array of context values in the same order as input.
1560
+ * Removes a range of children
1561
+ *
1562
+ * Removes children from `start_index` (inclusive) to `end_index` (exclusive).
1563
+ *
1564
+ * @param parent - The parent node ID
1565
+ * @param start_index - Start of range (inclusive)
1566
+ * @param end_index - End of range (exclusive)
1567
+ *
1568
+ * @throws `TaffyError` if the parent node does not exist or range is invalid
1569
+ *
1570
+ * @example
1571
+ * ```typescript
1572
+ * tree.removeChildrenRange(parentId, 1, 3);
1573
+ * ```
1574
+ */
1575
+ removeChildrenRange(
1576
+ parent: bigint,
1577
+ start_index: number,
1578
+ end_index: number,
1579
+ ): void;
1580
+ /**
1581
+ * Replaces a child at a specific index
1582
+ *
1583
+ * @param parent - The parent node ID
1584
+ * @param index - The index of the child to replace (0-based)
1585
+ * @param new_child - The new child node ID
1586
+ *
1587
+ * @returns - The replaced (old) child ID (`bigint`)
1588
+ *
1589
+ * @throws `TaffyError` if the parent node does not exist or index is out of bounds
1590
+ *
1591
+ * @example
1592
+ * ```typescript
1593
+ * const oldChildId: bigint = tree.replaceChildAtIndex(parentId, 1, newChildId);
1594
+ * ```
1595
+ */
1596
+ replaceChildAtIndex(parent: bigint, index: number, new_child: bigint): bigint;
1597
+ /**
1598
+ * Computes layout with a custom measure function for leaf nodes
1599
+ *
1600
+ * Use this when you have leaf nodes with dynamic content (like text)
1601
+ * that needs to be measured during layout. The measure function is
1602
+ * called for each leaf node that needs measurement.
1603
+ *
1604
+ * @param node - The root node ID to compute layout for
1605
+ * @param available_space - The available space constraints
1606
+ * @param measure_func - A function that measures leaf node content
1607
+ *
1608
+ * @throws `TaffyError` if the node does not exist or available space is invalid
1609
+ *
1610
+ * @example
1611
+ * ```typescript
1612
+ * tree.computeLayoutWithMeasure(
1613
+ * rootId,
1614
+ * { width: { Definite: 800 }, height: "MaxContent" },
1615
+ * (known, available, node, context, style) => {
1616
+ * if (context?.text) {
1617
+ * const measured = measureText(context.text, available.width);
1618
+ * return { width: measured.width, height: measured.height };
1619
+ * }
1620
+ * return { width: 0, height: 0 };
1621
+ * }
1622
+ * );
1623
+ * ```
1624
+ */
1625
+ computeLayoutWithMeasure(
1626
+ node: bigint,
1627
+ available_space: Size<AvailableSpace>,
1628
+ measure_func: MeasureFunction,
1629
+ ): void;
1630
+ /**
1631
+ * Gets context values for multiple nodes at once
1632
+ *
1633
+ * This is more efficient than calling `getNodeContext()` multiple times
1634
+ * when you need to access contexts for many nodes.
1635
+ *
1636
+ * @param children - Array of node IDs
1637
+ *
1638
+ * @returns - Array of context values (undefined for nodes without context)
1639
+ *
1640
+ * @example
1641
+ * ```typescript
1642
+ * const nodes = BigUint64Array.from([id1, id2]);
1643
+ * const contexts = tree.getDisjointNodeContextMut(nodes);
1644
+ * ```
607
1645
  */
608
1646
  getDisjointNodeContextMut(children: BigUint64Array): any[];
609
1647
  /**
610
- * Creates a new empty TaffyTree.
611
- *
612
- * This is the primary constructor. Initializes panic hook in debug builds
613
- * to provide better error messages in the browser console.
614
- *
615
- * # Returns
616
- * A new TaffyTree instance with no nodes.
1648
+ * Creates a new empty TaffyTree
1649
+ *
1650
+ * The tree starts with no nodes. Use `newLeaf()` or `newWithChildren()`
1651
+ * to add nodes.
1652
+ *
1653
+ * @example
1654
+ * ```typescript
1655
+ * const tree: TaffyTree = new TaffyTree();
1656
+ * ```
617
1657
  */
618
1658
  constructor();
619
1659
  /**
620
- * Removes all nodes from the tree.
621
- *
622
- * After calling this, the tree is empty and all previous node IDs are invalid.
1660
+ * Removes all nodes from the tree
1661
+ *
1662
+ * This clears the entire tree, removing all nodes and their relationships.
1663
+ * Use this to reset the tree for reuse.
1664
+ *
1665
+ * @example
1666
+ * ```typescript
1667
+ * tree.clear();
1668
+ * console.log(tree.totalNodeCount());
1669
+ * ```
623
1670
  */
624
1671
  clear(): void;
625
1672
  /**
626
- * Checks if a node is dirty (needs re-layout).
627
- *
628
- * # Arguments
629
- * * `node` - The node ID to check.
630
- *
631
- * # Returns
632
- * * `Ok(true)` - The node needs re-layout.
633
- * * `Ok(false)` - The node's layout is up-to-date.
634
- * * `Err(JsValue)` - Error if the node doesn't exist.
1673
+ * Checks if a node is dirty (needs re-layout)
1674
+ *
1675
+ * A node is dirty if its style or content has changed since the last
1676
+ * layout computation.
1677
+ *
1678
+ * @param node - The node ID to check
1679
+ *
1680
+ * @returns - true if dirty, false otherwise
1681
+ *
1682
+ * @throws `TaffyError` if the node does not exist
1683
+ *
1684
+ * @example
1685
+ * ```typescript
1686
+ * if (tree.dirty(nodeId)) {
1687
+ * tree.computeLayout(rootId, availableSpace);
1688
+ * }
1689
+ * ```
635
1690
  */
636
1691
  dirty(node: bigint): boolean;
637
1692
  /**
638
- * Gets the style for a node.
639
- *
640
- * # Arguments
641
- * * `node` - The node ID to query.
642
- *
643
- * # Returns
644
- * * `Ok(Style)` - A copy of the node's style.
645
- * * `Err(JsValue)` - Error if the node doesn't exist.
1693
+ * Gets the style for a node
1694
+ *
1695
+ * @param node - The node ID
1696
+ *
1697
+ * @returns - The node's `Style`
1698
+ *
1699
+ * @throws `TaffyError` if the node does not exist
1700
+ *
1701
+ * @example
1702
+ * ```typescript
1703
+ * const style: Style = tree.getStyle(nodeId);
1704
+ * console.log('Flex grow:', style.flexGrow);
1705
+ * ```
646
1706
  */
647
1707
  getStyle(node: bigint): Style;
648
1708
  /**
649
- * Gets the computed layout for a node.
650
- *
651
- * Must be called after `computeLayout()`.
652
- *
653
- * # Arguments
654
- * * `node` - The node ID to query.
655
- *
656
- * # Returns
657
- * A layout object: `{ order, size: {width, height}, location: {x, y}, ... }`
658
- */
659
- getLayout(node: bigint): any;
660
- /**
661
- * Gets the parent of a node.
662
- *
663
- * # Arguments
664
- * * `child` - The child node ID.
665
- *
666
- * # Returns
667
- * * `Some(u64)` - The parent node ID.
668
- * * `None` - If the node has no parent (is a root).
1709
+ * Gets the computed layout for a node
1710
+ *
1711
+ * Call this after `computeLayout()` to retrieve the computed position
1712
+ * and size for a node.
1713
+ *
1714
+ * @param node - The node ID
1715
+ *
1716
+ * @returns - The computed `Layout`
1717
+ *
1718
+ * @throws `TaffyError` if the node does not exist
1719
+ *
1720
+ * @example
1721
+ * ```typescript
1722
+ * tree.computeLayout(rootId, { width: { Definite: 800 }, height: { Definite: 600 } });
1723
+ * const layout: Layout = tree.getLayout(nodeId);
1724
+ * console.log(`Position: (${layout.x}, ${layout.y}), Size: ${layout.width}x${layout.height}`);
1725
+ * ```
1726
+ */
1727
+ getLayout(node: bigint): Layout;
1728
+ /**
1729
+ * Gets the parent of a node
1730
+ *
1731
+ * @param child - The child node ID
1732
+ *
1733
+ * @returns - The parent node ID, or `undefined` if the node has no parent
1734
+ *
1735
+ * @example
1736
+ * ```typescript
1737
+ * const parentId: bigint | undefined = tree.parent(childId);
1738
+ * ```
669
1739
  */
670
1740
  parent(child: bigint): bigint | undefined;
671
1741
  /**
672
- * Removes a node from the tree.
673
- *
674
- * The node is detached from its parent (if any) and removed from the tree.
675
- * Child nodes are NOT automatically removed.
676
- *
677
- * # Arguments
678
- * * `node` - The node ID to remove.
679
- *
680
- * # Returns
681
- * * `Ok(u64)` - The ID of the removed node.
682
- * * `Err(JsValue)` - Error if the node doesn't exist.
1742
+ * Removes a node from the tree
1743
+ *
1744
+ * The node and all its descendants are removed. If the node has a parent,
1745
+ * it is automatically removed from the parent's children.
1746
+ *
1747
+ * @param node - The node ID to remove
1748
+ *
1749
+ * @returns - The removed node ID (`bigint`)
1750
+ *
1751
+ * @throws `TaffyError` if the node does not exist
1752
+ *
1753
+ * @example
1754
+ * ```typescript
1755
+ * try {
1756
+ * const removedId: bigint = tree.remove(nodeId);
1757
+ * } catch (e) {
1758
+ * console.error("Node doesn't exist");
1759
+ * }
1760
+ * ```
683
1761
  */
684
1762
  remove(node: bigint): bigint;
685
1763
  /**
686
- * Gets all children of a node.
687
- *
688
- * # Arguments
689
- * * `parent` - The parent node ID.
690
- *
691
- * # Returns
692
- * * `Ok(Box<[u64]>)` - Array of child node IDs.
693
- * * `Err(JsValue)` - Error if the node doesn't exist.
1764
+ * Gets all children of a node
1765
+ *
1766
+ * @param parent - The parent node ID
1767
+ *
1768
+ * @returns - Array of child node IDs (`BigUint64Array`)
1769
+ *
1770
+ * @throws `TaffyError` if the parent node does not exist
1771
+ *
1772
+ * @example
1773
+ * ```typescript
1774
+ * const children: BigUint64Array = tree.children(parentId);
1775
+ * ```
694
1776
  */
695
1777
  children(parent: bigint): BigUint64Array;
696
1778
  /**
697
- * Creates a new leaf node (no children) with the given style.
698
- *
699
- * # Arguments
700
- * * `style` - The Style object to apply to this node.
701
- *
702
- * # Returns
703
- * * `Ok(u64)` - The node ID of the newly created node.
704
- * * `Err(JsValue)` - Error message if creation fails.
1779
+ * Creates a new leaf node with the given style
1780
+ *
1781
+ * A leaf node has no children. Use this for elements that contain
1782
+ * content (like text) rather than other elements.
1783
+ *
1784
+ * @param style - The style configuration for the node
1785
+ * @returns - The node ID (`bigint`)
1786
+ * @throws `TaffyError` if the node cannot be created
1787
+ *
1788
+ * @example
1789
+ * ```typescript
1790
+ * const style = new Style();
1791
+ * style.size = { width: { Length: 100 }, height: { Length: 50 } };
1792
+ * const nodeId: bigint = tree.newLeaf(style);
1793
+ * ```
705
1794
  */
706
1795
  newLeaf(style: Style): bigint;
707
1796
  /**
708
- * Appends a child node to a parent.
709
- *
710
- * The child is added at the end of the parent's children list.
711
- *
712
- * # Arguments
713
- * * `parent` - The parent node ID.
714
- * * `child` - The child node ID to add.
1797
+ * Appends a child node to a parent
1798
+ *
1799
+ * The child is added as the last child of the parent.
1800
+ *
1801
+ * @param parent - The parent node ID
1802
+ * @param child - The child node ID to add
1803
+ *
1804
+ * @throws `TaffyError` if the parent or child node does not exist
1805
+ *
1806
+ * @example
1807
+ * ```typescript
1808
+ * tree.addChild(parentId, childId);
1809
+ * ```
715
1810
  */
716
1811
  addChild(parent: bigint, child: bigint): void;
717
1812
  /**
718
- * Sets the style for an existing node.
719
- *
720
- * This will mark the node and its ancestors as dirty, triggering
721
- * a re-layout on the next `computeLayout()` call.
722
- *
723
- * # Arguments
724
- * * `node` - The node ID to update.
725
- * * `style` - The new Style to apply.
1813
+ * Sets the style for an existing node
1814
+ *
1815
+ * This replaces the node's current style with the provided one.
1816
+ * The node will be marked as dirty and require re-layout.
1817
+ *
1818
+ * @param node - The node ID
1819
+ * @param style - The new style configuration
1820
+ *
1821
+ * @throws `TaffyError` if the node does not exist
1822
+ *
1823
+ * @example
1824
+ * ```typescript
1825
+ * const newStyle = new Style();
1826
+ * newStyle.flexGrow = 2;
1827
+ * tree.setStyle(nodeId, newStyle);
1828
+ * ```
726
1829
  */
727
1830
  setStyle(node: bigint, style: Style): void;
728
1831
  }
729
1832
 
730
- export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
1833
+ export type InitInput =
1834
+ | RequestInfo
1835
+ | URL
1836
+ | Response
1837
+ | BufferSource
1838
+ | WebAssembly.Module;
731
1839
 
732
1840
  export interface InitOutput {
733
1841
  readonly memory: WebAssembly.Memory;
1842
+ readonly __wbg_layout_free: (a: number, b: number) => void;
734
1843
  readonly __wbg_style_free: (a: number, b: number) => void;
1844
+ readonly __wbg_taffyerror_free: (a: number, b: number) => void;
735
1845
  readonly __wbg_taffytree_free: (a: number, b: number) => void;
736
- readonly style_align_content: (a: number) => number;
737
- readonly style_align_items: (a: number) => number;
738
- readonly style_align_self: (a: number) => number;
739
- readonly style_aspect_ratio: (a: number) => number;
1846
+ readonly layout_borderBottom: (a: number) => number;
1847
+ readonly layout_borderLeft: (a: number) => number;
1848
+ readonly layout_borderRight: (a: number) => number;
1849
+ readonly layout_borderTop: (a: number) => number;
1850
+ readonly layout_contentHeight: (a: number) => number;
1851
+ readonly layout_contentWidth: (a: number) => number;
1852
+ readonly layout_height: (a: number) => number;
1853
+ readonly layout_marginBottom: (a: number) => number;
1854
+ readonly layout_marginLeft: (a: number) => number;
1855
+ readonly layout_marginRight: (a: number) => number;
1856
+ readonly layout_marginTop: (a: number) => number;
1857
+ readonly layout_order: (a: number) => number;
1858
+ readonly layout_paddingBottom: (a: number) => number;
1859
+ readonly layout_paddingLeft: (a: number) => number;
1860
+ readonly layout_paddingRight: (a: number) => number;
1861
+ readonly layout_paddingTop: (a: number) => number;
1862
+ readonly layout_scrollbarHeight: (a: number) => number;
1863
+ readonly layout_scrollbarWidth: (a: number) => number;
1864
+ readonly layout_width: (a: number) => number;
1865
+ readonly layout_x: (a: number) => number;
1866
+ readonly layout_y: (a: number) => number;
1867
+ readonly style_alignContent: (a: number) => number;
1868
+ readonly style_alignItems: (a: number) => number;
1869
+ readonly style_alignSelf: (a: number) => number;
1870
+ readonly style_aspectRatio: (a: number) => number;
740
1871
  readonly style_border: (a: number) => any;
741
- readonly style_box_sizing: (a: number) => number;
1872
+ readonly style_boxSizing: (a: number) => number;
742
1873
  readonly style_display: (a: number) => number;
743
- readonly style_flex_basis: (a: number) => any;
744
- readonly style_flex_direction: (a: number) => number;
745
- readonly style_flex_grow: (a: number) => number;
746
- readonly style_flex_shrink: (a: number) => number;
747
- readonly style_flex_wrap: (a: number) => number;
1874
+ readonly style_flexBasis: (a: number) => any;
1875
+ readonly style_flexDirection: (a: number) => number;
1876
+ readonly style_flexGrow: (a: number) => number;
1877
+ readonly style_flexShrink: (a: number) => number;
1878
+ readonly style_flexWrap: (a: number) => number;
748
1879
  readonly style_gap: (a: number) => any;
749
1880
  readonly style_inset: (a: number) => any;
750
- readonly style_justify_content: (a: number) => number;
1881
+ readonly style_justifyContent: (a: number) => number;
751
1882
  readonly style_margin: (a: number) => any;
752
- readonly style_max_size: (a: number) => any;
753
- readonly style_min_size: (a: number) => any;
1883
+ readonly style_maxSize: (a: number) => any;
1884
+ readonly style_minSize: (a: number) => any;
754
1885
  readonly style_new: () => number;
755
1886
  readonly style_overflow: (a: number) => any;
756
1887
  readonly style_padding: (a: number) => any;
757
1888
  readonly style_position: (a: number) => number;
758
- readonly style_set_align_content: (a: number, b: number) => void;
759
- readonly style_set_align_items: (a: number, b: number) => void;
760
- readonly style_set_align_self: (a: number, b: number) => void;
761
- readonly style_set_aspect_ratio: (a: number, b: number) => void;
1889
+ readonly style_set_alignContent: (a: number, b: any) => void;
1890
+ readonly style_set_alignItems: (a: number, b: any) => void;
1891
+ readonly style_set_alignSelf: (a: number, b: any) => void;
1892
+ readonly style_set_aspectRatio: (a: number, b: any) => void;
762
1893
  readonly style_set_border: (a: number, b: any) => void;
763
- readonly style_set_box_sizing: (a: number, b: number) => void;
1894
+ readonly style_set_boxSizing: (a: number, b: number) => void;
764
1895
  readonly style_set_display: (a: number, b: number) => void;
765
- readonly style_set_flex_basis: (a: number, b: any) => void;
766
- readonly style_set_flex_direction: (a: number, b: number) => void;
767
- readonly style_set_flex_grow: (a: number, b: number) => void;
768
- readonly style_set_flex_shrink: (a: number, b: number) => void;
769
- readonly style_set_flex_wrap: (a: number, b: number) => void;
1896
+ readonly style_set_flexBasis: (a: number, b: any) => void;
1897
+ readonly style_set_flexDirection: (a: number, b: number) => void;
1898
+ readonly style_set_flexGrow: (a: number, b: number) => void;
1899
+ readonly style_set_flexShrink: (a: number, b: number) => void;
1900
+ readonly style_set_flexWrap: (a: number, b: number) => void;
770
1901
  readonly style_set_gap: (a: number, b: any) => void;
771
1902
  readonly style_set_inset: (a: number, b: any) => void;
772
- readonly style_set_justify_content: (a: number, b: number) => void;
1903
+ readonly style_set_justifyContent: (a: number, b: any) => void;
773
1904
  readonly style_set_margin: (a: number, b: any) => void;
774
- readonly style_set_max_size: (a: number, b: any) => void;
775
- readonly style_set_min_size: (a: number, b: any) => void;
1905
+ readonly style_set_maxSize: (a: number, b: any) => void;
1906
+ readonly style_set_minSize: (a: number, b: any) => void;
776
1907
  readonly style_set_overflow: (a: number, b: any) => void;
777
1908
  readonly style_set_padding: (a: number, b: any) => void;
778
1909
  readonly style_set_position: (a: number, b: number) => void;
779
1910
  readonly style_set_size: (a: number, b: any) => void;
780
1911
  readonly style_size: (a: number) => any;
781
- readonly taffytree_addChild: (a: number, b: bigint, c: bigint) => [number, number];
1912
+ readonly taffyerror_message: (a: number) => [number, number];
1913
+ readonly taffytree_addChild: (
1914
+ a: number,
1915
+ b: bigint,
1916
+ c: bigint,
1917
+ ) => [number, number];
782
1918
  readonly taffytree_childCount: (a: number, b: bigint) => number;
783
- readonly taffytree_children: (a: number, b: bigint) => [number, number, number, number];
1919
+ readonly taffytree_children: (
1920
+ a: number,
1921
+ b: bigint,
1922
+ ) => [number, number, number, number];
784
1923
  readonly taffytree_clear: (a: number) => void;
785
- readonly taffytree_computeLayout: (a: number, b: bigint, c: any) => [number, number];
786
- readonly taffytree_computeLayoutWithMeasure: (a: number, b: bigint, c: any, d: any) => [number, number];
1924
+ readonly taffytree_computeLayout: (
1925
+ a: number,
1926
+ b: bigint,
1927
+ c: any,
1928
+ ) => [number, number];
1929
+ readonly taffytree_computeLayoutWithMeasure: (
1930
+ a: number,
1931
+ b: bigint,
1932
+ c: any,
1933
+ d: any,
1934
+ ) => [number, number];
787
1935
  readonly taffytree_dirty: (a: number, b: bigint) => [number, number, number];
788
1936
  readonly taffytree_disableRounding: (a: number) => void;
789
1937
  readonly taffytree_enableRounding: (a: number) => void;
790
- readonly taffytree_getChildAtIndex: (a: number, b: bigint, c: number) => [bigint, number, number];
791
- readonly taffytree_getDisjointNodeContextMut: (a: number, b: number, c: number) => [number, number, number, number];
792
- readonly taffytree_getLayout: (a: number, b: bigint) => [number, number, number];
793
- readonly taffytree_getNodeContext: (a: number, b: bigint) => [number, number, number];
794
- readonly taffytree_getNodeContextMut: (a: number, b: bigint) => [number, number, number];
795
- readonly taffytree_getStyle: (a: number, b: bigint) => [number, number, number];
796
- readonly taffytree_insertChildAtIndex: (a: number, b: bigint, c: number, d: bigint) => [number, number];
1938
+ readonly taffytree_getChildAtIndex: (
1939
+ a: number,
1940
+ b: bigint,
1941
+ c: number,
1942
+ ) => [bigint, number, number];
1943
+ readonly taffytree_getDisjointNodeContextMut: (
1944
+ a: number,
1945
+ b: number,
1946
+ c: number,
1947
+ ) => [number, number, number, number];
1948
+ readonly taffytree_getLayout: (
1949
+ a: number,
1950
+ b: bigint,
1951
+ ) => [number, number, number];
1952
+ readonly taffytree_getNodeContext: (
1953
+ a: number,
1954
+ b: bigint,
1955
+ ) => [number, number, number];
1956
+ readonly taffytree_getNodeContextMut: (
1957
+ a: number,
1958
+ b: bigint,
1959
+ ) => [number, number, number];
1960
+ readonly taffytree_getStyle: (
1961
+ a: number,
1962
+ b: bigint,
1963
+ ) => [number, number, number];
1964
+ readonly taffytree_insertChildAtIndex: (
1965
+ a: number,
1966
+ b: bigint,
1967
+ c: number,
1968
+ d: bigint,
1969
+ ) => [number, number];
797
1970
  readonly taffytree_markDirty: (a: number, b: bigint) => [number, number];
798
1971
  readonly taffytree_new: () => number;
799
- readonly taffytree_newLeaf: (a: number, b: number) => [bigint, number, number];
800
- readonly taffytree_newLeafWithContext: (a: number, b: number, c: any) => [bigint, number, number];
801
- readonly taffytree_newWithChildren: (a: number, b: number, c: number, d: number) => [bigint, number, number];
1972
+ readonly taffytree_newLeaf: (
1973
+ a: number,
1974
+ b: number,
1975
+ ) => [bigint, number, number];
1976
+ readonly taffytree_newLeafWithContext: (
1977
+ a: number,
1978
+ b: number,
1979
+ c: any,
1980
+ ) => [bigint, number, number];
1981
+ readonly taffytree_newWithChildren: (
1982
+ a: number,
1983
+ b: number,
1984
+ c: number,
1985
+ d: number,
1986
+ ) => [bigint, number, number];
802
1987
  readonly taffytree_parent: (a: number, b: bigint) => [number, bigint];
803
1988
  readonly taffytree_printTree: (a: number, b: bigint) => void;
804
1989
  readonly taffytree_remove: (a: number, b: bigint) => [bigint, number, number];
805
- readonly taffytree_removeChild: (a: number, b: bigint, c: bigint) => [bigint, number, number];
806
- readonly taffytree_removeChildAtIndex: (a: number, b: bigint, c: number) => [bigint, number, number];
807
- readonly taffytree_removeChildrenRange: (a: number, b: bigint, c: number, d: number) => [number, number];
808
- readonly taffytree_replaceChildAtIndex: (a: number, b: bigint, c: number, d: bigint) => [bigint, number, number];
809
- readonly taffytree_setChildren: (a: number, b: bigint, c: number, d: number) => [number, number];
810
- readonly taffytree_setNodeContext: (a: number, b: bigint, c: any) => [number, number];
811
- readonly taffytree_setStyle: (a: number, b: bigint, c: number) => [number, number];
1990
+ readonly taffytree_removeChild: (
1991
+ a: number,
1992
+ b: bigint,
1993
+ c: bigint,
1994
+ ) => [bigint, number, number];
1995
+ readonly taffytree_removeChildAtIndex: (
1996
+ a: number,
1997
+ b: bigint,
1998
+ c: number,
1999
+ ) => [bigint, number, number];
2000
+ readonly taffytree_removeChildrenRange: (
2001
+ a: number,
2002
+ b: bigint,
2003
+ c: number,
2004
+ d: number,
2005
+ ) => [number, number];
2006
+ readonly taffytree_replaceChildAtIndex: (
2007
+ a: number,
2008
+ b: bigint,
2009
+ c: number,
2010
+ d: bigint,
2011
+ ) => [bigint, number, number];
2012
+ readonly taffytree_setChildren: (
2013
+ a: number,
2014
+ b: bigint,
2015
+ c: number,
2016
+ d: number,
2017
+ ) => [number, number];
2018
+ readonly taffytree_setNodeContext: (
2019
+ a: number,
2020
+ b: bigint,
2021
+ c: any,
2022
+ ) => [number, number];
2023
+ readonly taffytree_setStyle: (
2024
+ a: number,
2025
+ b: bigint,
2026
+ c: number,
2027
+ ) => [number, number];
812
2028
  readonly taffytree_totalNodeCount: (a: number) => number;
813
- readonly taffytree_unroundedLayout: (a: number, b: bigint) => [number, number, number];
2029
+ readonly taffytree_unroundedLayout: (a: number, b: bigint) => number;
814
2030
  readonly taffytree_withCapacity: (a: number) => number;
815
2031
  readonly __wbindgen_malloc: (a: number, b: number) => number;
816
- readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
2032
+ readonly __wbindgen_realloc: (
2033
+ a: number,
2034
+ b: number,
2035
+ c: number,
2036
+ d: number,
2037
+ ) => number;
817
2038
  readonly __wbindgen_exn_store: (a: number) => void;
818
2039
  readonly __externref_table_alloc: () => number;
819
2040
  readonly __wbindgen_externrefs: WebAssembly.Table;
@@ -826,21 +2047,28 @@ export interface InitOutput {
826
2047
  export type SyncInitInput = BufferSource | WebAssembly.Module;
827
2048
 
828
2049
  /**
829
- * Instantiates the given `module`, which can either be bytes or
830
- * a precompiled `WebAssembly.Module`.
831
- *
832
- * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
833
- *
834
- * @returns {InitOutput}
835
- */
836
- export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
2050
+ * Instantiates the given `module`, which can either be bytes or
2051
+ * a precompiled `WebAssembly.Module`.
2052
+ *
2053
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
2054
+ *
2055
+ * @returns {InitOutput}
2056
+ */
2057
+ export function initSync(
2058
+ module: { module: SyncInitInput } | SyncInitInput,
2059
+ ): InitOutput;
837
2060
 
838
2061
  /**
839
- * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
840
- * for everything else, calls `WebAssembly.instantiate` directly.
841
- *
842
- * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
843
- *
844
- * @returns {Promise<InitOutput>}
845
- */
846
- export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
2062
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
2063
+ * for everything else, calls `WebAssembly.instantiate` directly.
2064
+ *
2065
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
2066
+ *
2067
+ * @returns {Promise<InitOutput>}
2068
+ */
2069
+ export default function __wbg_init(
2070
+ module_or_path?:
2071
+ | { module_or_path: InitInput | Promise<InitInput> }
2072
+ | InitInput
2073
+ | Promise<InitInput>,
2074
+ ): Promise<InitOutput>;