taffy-js 0.2.11 → 0.2.12

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.
@@ -9,8 +9,8 @@
9
9
  *
10
10
  * @remarks
11
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
12
+ * - Use `"min-content"` to shrink-wrap to the minimum content size
13
+ * - Use `"max-content"` to expand to fit all content without wrapping
14
14
  *
15
15
  * @example
16
16
  * ```typescript
@@ -29,13 +29,13 @@
29
29
  *
30
30
  * // Flexible width, fixed height
31
31
  * const flexibleSpace: Size<AvailableSpace> = {
32
- * width: "maxContent",
32
+ * width: "max-content",
33
33
  * height: 400
34
34
  * };
35
35
  * tree.computeLayout(root, flexibleSpace);
36
36
  * ```
37
37
  */
38
- export type AvailableSpace = number | "minContent" | "maxContent";
38
+ export type AvailableSpace = number | "min-content" | "max-content";
39
39
 
40
40
  /**
41
41
  * Generic size type with width and height.
@@ -62,16 +62,16 @@ export type AvailableSpace = number | "minContent" | "maxContent";
62
62
  *
63
63
  * const availableSize: Size<AvailableSpace> = {
64
64
  * width: 800,
65
- * height: "maxContent"
65
+ * height: "max-content"
66
66
  * };
67
67
  * ```
68
68
  */
69
- export interface Size<T> {
69
+ export type Size<T> = {
70
70
  /** The horizontal dimension value */
71
71
  width: T;
72
72
  /** The vertical dimension value */
73
73
  height: T;
74
- }
74
+ };
75
75
 
76
76
  /**
77
77
  * Custom measure function for leaf nodes with text or other dynamic content.
@@ -82,7 +82,7 @@ export interface Size<T> {
82
82
  * @param knownDimensions - Dimensions already determined by constraints. Each dimension
83
83
  * is `number` if known, or `undefined` if needs to be measured.
84
84
  * @param availableSpace - The available space constraints for the node. Can be definite
85
- * pixels, "minContent", or "maxContent".
85
+ * pixels, "min-content", or "max-content".
86
86
  * @param node - The node ID (`bigint`) of the node being measured
87
87
  * @param context - User-provided context attached to the node via `newLeafWithContext()`
88
88
  * @param style - The node's current Style configuration
@@ -105,6 +105,9 @@ export interface Size<T> {
105
105
  * const context: TextContext = { text: "Hello, World!", fontSize: 16 };
106
106
  * const textNode: bigint = tree.newLeafWithContext(style, context);
107
107
  *
108
+ * // Helper function to measure text width
109
+ * const measureTextWidth = (text: string, fontSize: number) => text.length * fontSize * 0.6;
110
+ *
108
111
  * // Typed measure function
109
112
  * const measureText: MeasureFunction = (
110
113
  * knownDimensions,
@@ -124,7 +127,7 @@ export interface Size<T> {
124
127
  *
125
128
  * tree.computeLayoutWithMeasure(
126
129
  * textNode,
127
- * { width: 200, height: "maxContent" },
130
+ * { width: 200, height: "max-content" },
128
131
  * measureText
129
132
  * );
130
133
  * ```
@@ -261,12 +264,12 @@ export type LengthPercentageAuto = number | `${number}%` | "auto";
261
264
  * style.overflow = overflow;
262
265
  * ```
263
266
  */
264
- export interface Point<T> {
267
+ export type Point<T> = {
265
268
  /** The horizontal (x-axis) value */
266
269
  x: T;
267
270
  /** The vertical (y-axis) value */
268
271
  y: T;
269
- }
272
+ };
270
273
 
271
274
  /**
272
275
  * Rectangle with left, right, top, and bottom values.
@@ -306,7 +309,7 @@ export interface Point<T> {
306
309
  * style.margin = margin;
307
310
  * ```
308
311
  */
309
- export interface Rect<T> {
312
+ export type Rect<T> = {
310
313
  /** The left side value */
311
314
  left: T;
312
315
  /** The right side value */
@@ -315,7 +318,7 @@ export interface Rect<T> {
315
318
  top: T;
316
319
  /** The bottom side value */
317
320
  bottom: T;
318
- }
321
+ };
319
322
 
320
323
  /**
321
324
  * Detailed layout information (for grid layouts).
@@ -328,18 +331,24 @@ export interface Rect<T> {
328
331
  *
329
332
  * @example
330
333
  * ```typescript
331
- * import type { DetailedLayoutInfo, DetailedGridInfo } from 'taffy-js';
334
+ * import { TaffyTree, Style, Display, type DetailedLayoutInfo, type DetailedGridInfo } from 'taffy-js';
335
+ *
336
+ * const tree = new TaffyTree();
337
+ * const style = new Style();
338
+ * style.display = Display.Grid;
339
+ * const gridNode = tree.newLeaf(style);
340
+ * tree.computeLayout(gridNode, { width: 100, height: 100 });
332
341
  *
333
342
  * const info: DetailedLayoutInfo = tree.detailedLayoutInfo(gridNode);
334
343
  *
335
- * if (info !== "None" && typeof info === 'object' && 'Grid' in info) {
336
- * const grid: DetailedGridInfo = info.Grid;
344
+ * if (info && typeof info === 'object' && 'Grid' in info) {
345
+ * const grid = info.Grid as DetailedGridInfo;
337
346
  * console.log('Rows:', grid.rows.sizes);
338
347
  * console.log('Columns:', grid.columns.sizes);
339
348
  * }
340
349
  * ```
341
350
  */
342
- export type DetailedLayoutInfo = DetailedGridInfo | null;
351
+ export type DetailedLayoutInfo = DetailedGridInfo | undefined;
343
352
 
344
353
  /**
345
354
  * Detailed information about a grid layout.
@@ -350,38 +359,38 @@ export type DetailedLayoutInfo = DetailedGridInfo | null;
350
359
  * @property columns - Information about column tracks
351
360
  * @property items - Array of item placement information
352
361
  */
353
- export interface DetailedGridInfo {
362
+ export type DetailedGridInfo = {
354
363
  /** Information about the grid's row tracks */
355
364
  rows: DetailedGridTracksInfo;
356
365
  /** Information about the grid's column tracks */
357
366
  columns: DetailedGridTracksInfo;
358
367
  /** Placement information for each grid item */
359
368
  items: DetailedGridItemsInfo[];
360
- }
369
+ };
361
370
 
362
371
  /**
363
372
  * Information about grid tracks (rows or columns).
364
373
  *
365
374
  * Provides detailed sizing and gutter information for a set of grid tracks.
366
375
  *
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
376
+ * @property negativeImplicitTracks - Number of implicit tracks before explicit tracks
377
+ * @property explicitTracks - Number of explicitly defined tracks
378
+ * @property positiveImplicitTracks - Number of implicit tracks after explicit tracks
370
379
  * @property gutters - Array of gutter sizes between tracks (in pixels)
371
380
  * @property sizes - Array of track sizes (in pixels)
372
381
  */
373
- export interface DetailedGridTracksInfo {
382
+ export type DetailedGridTracksInfo = {
374
383
  /** Number of implicit tracks before explicit tracks (for negative line numbers) */
375
- negative_implicit_tracks: number;
384
+ negativeImplicitTracks: number;
376
385
  /** Number of tracks explicitly defined in grid-template-rows/columns */
377
- explicit_tracks: number;
386
+ explicitTracks: number;
378
387
  /** Number of implicit tracks created after explicit tracks */
379
- positive_implicit_tracks: number;
388
+ positiveImplicitTracks: number;
380
389
  /** Gap sizes between tracks in pixels */
381
390
  gutters: number[];
382
391
  /** Computed sizes of each track in pixels */
383
392
  sizes: number[];
384
- }
393
+ };
385
394
 
386
395
  /**
387
396
  * Information about a grid item's placement.
@@ -389,21 +398,21 @@ export interface DetailedGridTracksInfo {
389
398
  * Specifies which grid lines the item spans on both axes.
390
399
  * Line numbers are 1-indexed, with 1 being the first line.
391
400
  *
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)
401
+ * @property rowStart - Starting row line number (1-indexed)
402
+ * @property rowEnd - Ending row line number (exclusive)
403
+ * @property columnStart - Starting column line number (1-indexed)
404
+ * @property columnEnd - Ending column line number (exclusive)
396
405
  */
397
- export interface DetailedGridItemsInfo {
406
+ export type DetailedGridItemsInfo = {
398
407
  /** Starting row line (1-indexed) */
399
- row_start: number;
408
+ rowStart: number;
400
409
  /** Ending row line (exclusive) */
401
- row_end: number;
410
+ rowEnd: number;
402
411
  /** Starting column line (1-indexed) */
403
- column_start: number;
412
+ columnStart: number;
404
413
  /** Ending column line (exclusive) */
405
- column_end: number;
406
- }
414
+ columnEnd: number;
415
+ };
407
416
 
408
417
  /**
409
418
  * Grid placement type for positioning grid items.
@@ -428,9 +437,15 @@ export interface DetailedGridItemsInfo {
428
437
  *
429
438
  * // Span (CSS: grid-row-start: span 3)
430
439
  * const span: GridPlacement = { span: 3 };
440
+ *
441
+ * // Named line (CSS: grid-row-start: header 2)
442
+ * const named: GridPlacement = { line: 2, ident: "header" };
443
+ *
444
+ * // Named span (CSS: grid-row-start: span 2 header)
445
+ * const namedSpan: GridPlacement = { span: 2, ident: "header" };
431
446
  * ```
432
447
  */
433
- export type GridPlacement = "auto" | number | { span: number };
448
+ export type GridPlacement = "auto" | number | {line: number; ident: string} | {span: number; ident?: string};
434
449
 
435
450
  /**
436
451
  * Line type representing start and end positions.
@@ -460,12 +475,78 @@ export type GridPlacement = "auto" | number | { span: number };
460
475
  * style.gridRow = { start: "auto", end: "auto" };
461
476
  * ```
462
477
  */
463
- export interface Line<T> {
478
+ export type Line<T> = {
464
479
  /** The starting position (CSS: *-start) */
465
480
  start: T;
466
481
  /** The ending position (CSS: *-end) */
467
482
  end: T;
468
483
  }
484
+ /**
485
+ * Grid track repetition parameter.
486
+ *
487
+ * Defines how many times a track pattern should repeat.
488
+ *
489
+ * @remarks
490
+ * - `number`: Exact number of repetitions (e.g. `repeat(3, ...)`).
491
+ * - `"autoFill"`: Fills the container with as many tracks as possible.
492
+ * - `"autoFit"`: Fills the container, collapsing empty tracks.
493
+ */
494
+ export type RepetitionCount = number | "auto-fill" | "auto-fit";
495
+
496
+ /**
497
+ * Minumum track sizing function.
498
+ *
499
+ * Defines the minimum size of a grid track.
500
+ */
501
+ export type MinTrackSizingFunction = number | `${number}%` | "auto" | "min-content" | "max-content";
502
+
503
+ /**
504
+ * Maximum track sizing function.
505
+ *
506
+ * Defines the maximum size of a grid track.
507
+ */
508
+ export type MaxTrackSizingFunction = number | `${number}%` | `${number}fr` | "auto" | "min-content" | "max-content" | "fit-content";
509
+
510
+ /**
511
+ * Track sizing function (min/max pair).
512
+ *
513
+ * Defines the size range for a single grid track.
514
+ */
515
+ export type TrackSizingFunction = {min: MinTrackSizingFunction; max: MaxTrackSizingFunction};
516
+
517
+ /**
518
+ * Grid track repetition definition.
519
+ */
520
+ export type GridTemplateRepetition = {
521
+ count: RepetitionCount;
522
+ tracks: TrackSizingFunction[];
523
+ lineNames?: string[][];
524
+ };
525
+
526
+ /**
527
+ * Grid track sizing definition.
528
+ *
529
+ * Can be a single track sizing function or a repetition of tracks.
530
+ */
531
+ export type GridTemplateComponent = TrackSizingFunction | GridTemplateRepetition;
532
+
533
+ /**
534
+ * Named grid area definition.
535
+ *
536
+ * Defines a named area within the grid and its boundaries.
537
+ */
538
+ export type GridTemplateArea = {
539
+ /** The name of the grid area */
540
+ name: string;
541
+ /** Start row line */
542
+ rowStart: number;
543
+ /** End row line */
544
+ rowEnd: number;
545
+ /** Start column line */
546
+ columnStart: number;
547
+ /** End column line */
548
+ columnEnd: number;
549
+ };
469
550
 
470
551
 
471
552
 
@@ -479,8 +560,9 @@ export interface Line<T> {
479
560
  *
480
561
  * @example
481
562
  * ```typescript
482
- * import { AlignContent, FlexWrap } from 'taffy-js';
563
+ * import { Style, AlignContent, FlexWrap } from 'taffy-js';
483
564
  *
565
+ * const style = new Style();
484
566
  * style.flexWrap = FlexWrap.Wrap;
485
567
  * style.alignContent = AlignContent.SpaceBetween; // Distribute lines evenly
486
568
  * ```
@@ -532,8 +614,9 @@ export enum AlignContent {
532
614
  *
533
615
  * @example
534
616
  * ```typescript
535
- * import { AlignItems } from 'taffy-js';
617
+ * import { Style, AlignItems } from 'taffy-js';
536
618
  *
619
+ * const style = new Style();
537
620
  * style.alignItems = AlignItems.Center; // Center items on cross axis
538
621
  * style.alignItems = AlignItems.Stretch; // Stretch items to fill container
539
622
  * ```
@@ -577,8 +660,9 @@ export enum AlignItems {
577
660
  *
578
661
  * @example
579
662
  * ```typescript
580
- * import { AlignSelf } from 'taffy-js';
663
+ * import { Style, AlignSelf } from 'taffy-js';
581
664
  *
665
+ * const style = new Style();
582
666
  * style.alignSelf = AlignSelf.Auto; // Use parent's align-items
583
667
  * style.alignSelf = AlignSelf.Center; // Override to center this item
584
668
  * ```
@@ -626,8 +710,9 @@ export enum AlignSelf {
626
710
  *
627
711
  * @example
628
712
  * ```typescript
629
- * import { BoxSizing } from 'taffy-js';
713
+ * import { Style, BoxSizing } from 'taffy-js';
630
714
  *
715
+ * const style = new Style();
631
716
  * style.boxSizing = BoxSizing.BorderBox; // Size includes padding and border
632
717
  * style.boxSizing = BoxSizing.ContentBox; // Size is content only
633
718
  * ```
@@ -651,8 +736,9 @@ export enum BoxSizing {
651
736
  *
652
737
  * @example
653
738
  * ```typescript
654
- * import { Display } from 'taffy-js';
739
+ * import { Style, Display } from 'taffy-js';
655
740
  *
741
+ * const style = new Style();
656
742
  * style.display = Display.Flex; // Enable flexbox layout
657
743
  * style.display = Display.Grid; // Enable grid layout
658
744
  * style.display = Display.None; // Hide element from layout
@@ -685,8 +771,9 @@ export enum Display {
685
771
  *
686
772
  * @example
687
773
  * ```typescript
688
- * import { FlexDirection } from 'taffy-js';
774
+ * import { Style, FlexDirection } from 'taffy-js';
689
775
  *
776
+ * const style = new Style();
690
777
  * style.flexDirection = FlexDirection.Row; // Horizontal, left to right
691
778
  * style.flexDirection = FlexDirection.Column; // Vertical, top to bottom
692
779
  * ```
@@ -718,8 +805,9 @@ export enum FlexDirection {
718
805
  *
719
806
  * @example
720
807
  * ```typescript
721
- * import { FlexWrap } from 'taffy-js';
808
+ * import { Style, FlexWrap } from 'taffy-js';
722
809
  *
810
+ * const style = new Style();
723
811
  * style.flexWrap = FlexWrap.NoWrap; // All items on single line
724
812
  * style.flexWrap = FlexWrap.Wrap; // Items wrap to new lines
725
813
  * ```
@@ -747,8 +835,9 @@ export enum FlexWrap {
747
835
  *
748
836
  * @example
749
837
  * ```typescript
750
- * import { GridAutoFlow } from 'taffy-js';
838
+ * import { Style, GridAutoFlow } from 'taffy-js';
751
839
  *
840
+ * const style = new Style();
752
841
  * style.gridAutoFlow = GridAutoFlow.Row; // Fill rows first
753
842
  * style.gridAutoFlow = GridAutoFlow.Column; // Fill columns first
754
843
  * style.gridAutoFlow = GridAutoFlow.RowDense; // Fill rows, pack densely
@@ -781,8 +870,9 @@ export enum GridAutoFlow {
781
870
  *
782
871
  * @example
783
872
  * ```typescript
784
- * import { JustifyContent } from 'taffy-js';
873
+ * import { Style, JustifyContent } from 'taffy-js';
785
874
  *
875
+ * const style = new Style();
786
876
  * style.justifyContent = JustifyContent.Center; // Center items
787
877
  * style.justifyContent = JustifyContent.SpaceBetween; // Distribute evenly
788
878
  * ```
@@ -834,6 +924,11 @@ export enum JustifyContent {
834
924
  *
835
925
  * @example
836
926
  * ```typescript
927
+ * const tree = new TaffyTree();
928
+ * const rootId = tree.newLeaf(new Style());
929
+ * const node = rootId;
930
+ *
931
+ * tree.computeLayout(rootId, { width: 800, height: 600 });
837
932
  * const layout = tree.getLayout(node);
838
933
  *
839
934
  * console.log("Position:", layout.x, layout.y);
@@ -1013,8 +1108,9 @@ export class Layout {
1013
1108
  *
1014
1109
  * @example
1015
1110
  * ```typescript
1016
- * import { Overflow } from 'taffy-js';
1111
+ * import { Style, Overflow } from 'taffy-js';
1017
1112
  *
1113
+ * const style = new Style();
1018
1114
  * style.overflow = { x: Overflow.Hidden, y: Overflow.Scroll };
1019
1115
  * ```
1020
1116
  */
@@ -1045,8 +1141,9 @@ export enum Overflow {
1045
1141
  *
1046
1142
  * @example
1047
1143
  * ```typescript
1048
- * import { Position } from 'taffy-js';
1144
+ * import { Style, Position } from 'taffy-js';
1049
1145
  *
1146
+ * const style = new Style();
1050
1147
  * style.position = Position.Relative; // Normal document flow
1051
1148
  * style.position = Position.Absolute; // Removed from flow, uses inset values
1052
1149
  * ```
@@ -1320,7 +1417,7 @@ export class Style {
1320
1417
  *
1321
1418
  * @returns - An array of track sizing functions
1322
1419
  */
1323
- gridAutoRows: any;
1420
+ gridAutoRows: TrackSizingFunction[];
1324
1421
  /**
1325
1422
  * Gets the justify-content property
1326
1423
  *
@@ -1356,16 +1453,15 @@ export class Style {
1356
1453
  *
1357
1454
  * @returns - An array of track sizing functions
1358
1455
  */
1359
- gridAutoColumns: any;
1456
+ gridAutoColumns: TrackSizingFunction[];
1360
1457
  /**
1361
1458
  * Gets the grid-template-rows property
1362
1459
  *
1363
1460
  * Defines the track sizing functions (heights) of the grid rows.
1364
- * Returns Taffy's native serialization format.
1365
1461
  *
1366
1462
  * @returns - An array of `GridTrack` values
1367
1463
  */
1368
- gridTemplateRows: GridTrack[];
1464
+ gridTemplateRows: GridTemplateComponent[];
1369
1465
  /**
1370
1466
  * Gets the grid-template-areas property
1371
1467
  *
@@ -1373,7 +1469,7 @@ export class Style {
1373
1469
  *
1374
1470
  * @returns - An array of `GridArea` values
1375
1471
  */
1376
- gridTemplateAreas: GridArea[];
1472
+ gridTemplateAreas: GridTemplateArea[];
1377
1473
  /**
1378
1474
  * Gets the grid-template-columns property
1379
1475
  *
@@ -1381,7 +1477,7 @@ export class Style {
1381
1477
  *
1382
1478
  * @returns - An array of `GridTrack` values
1383
1479
  */
1384
- gridTemplateColumns: GridTrack[];
1480
+ gridTemplateColumns: GridTemplateComponent[];
1385
1481
  /**
1386
1482
  * Gets the grid-template-row-names property
1387
1483
  *
@@ -1431,6 +1527,8 @@ export class Style {
1431
1527
  * @example
1432
1528
  * ```typescript
1433
1529
  * try {
1530
+ * const tree = new TaffyTree();
1531
+ * const node = tree.newLeaf(new Style());
1434
1532
  * tree.remove(node);
1435
1533
  * } catch (e) {
1436
1534
  * if (e instanceof TaffyError) {
@@ -1484,6 +1582,11 @@ export class TaffyTree {
1484
1582
  *
1485
1583
  * @example
1486
1584
  * ```typescript
1585
+ * const tree = new TaffyTree();
1586
+ * const rootId = tree.newLeaf(new Style());
1587
+ * const nodeId = rootId;
1588
+ * const availableSpace = { width: 100, height: 100 };
1589
+ *
1487
1590
  * // After updating text content
1488
1591
  * tree.setNodeContext(nodeId, { text: "Updated text" });
1489
1592
  * tree.markDirty(nodeId);
@@ -1501,6 +1604,8 @@ export class TaffyTree {
1501
1604
  *
1502
1605
  * @example
1503
1606
  * ```typescript
1607
+ * const tree = new TaffyTree();
1608
+ * const rootId = tree.newLeaf(new Style());
1504
1609
  * tree.printTree(rootId);
1505
1610
  * // Output appears in browser console
1506
1611
  * ```
@@ -1517,6 +1622,8 @@ export class TaffyTree {
1517
1622
  *
1518
1623
  * @example
1519
1624
  * ```typescript
1625
+ * const tree = new TaffyTree();
1626
+ * const parentId = tree.newLeaf(new Style());
1520
1627
  * const count: number = tree.childCount(parentId);
1521
1628
  * ```
1522
1629
  */
@@ -1533,6 +1640,10 @@ export class TaffyTree {
1533
1640
  *
1534
1641
  * @example
1535
1642
  * ```typescript
1643
+ * const tree = new TaffyTree();
1644
+ * const parentId = tree.newLeaf(new Style());
1645
+ * const childId = tree.newLeaf(new Style());
1646
+ * tree.addChild(parentId, childId);
1536
1647
  * tree.removeChild(parentId, childId);
1537
1648
  * ```
1538
1649
  */
@@ -1549,6 +1660,11 @@ export class TaffyTree {
1549
1660
  *
1550
1661
  * @example
1551
1662
  * ```typescript
1663
+ * const tree = new TaffyTree();
1664
+ * const parentId = tree.newLeaf(new Style());
1665
+ * const child1 = tree.newLeaf(new Style());
1666
+ * const child2 = tree.newLeaf(new Style());
1667
+ * const child3 = tree.newLeaf(new Style());
1552
1668
  * const children = BigUint64Array.from([child1, child2, child3]);
1553
1669
  * tree.setChildren(parentId, children);
1554
1670
  * ```
@@ -1575,28 +1691,33 @@ export class TaffyTree {
1575
1691
  * to compute layouts for all nodes in the tree.
1576
1692
  *
1577
1693
  * @param node - The root node ID to compute layout for
1578
- * @param available_space - The available space constraints
1694
+ * @param availableSpace - The available space constraints
1579
1695
  *
1580
1696
  * @example
1581
1697
  * ```typescript
1698
+ * const tree = new TaffyTree();
1699
+ * const rootId = tree.newLeaf(new Style());
1700
+ *
1582
1701
  * // Fixed size container
1583
- * { width: 800, height: 600 }
1702
+ * tree.computeLayout(rootId, { width: 800, height: 600 });
1584
1703
  *
1585
1704
  * // Flexible width, fixed height
1586
- * { width: "maxContent", height: 600 }
1705
+ * tree.computeLayout(rootId, { width: "max-content", height: 600 });
1587
1706
  *
1588
1707
  * // Minimum content size
1589
- * { width: "minContent", height: "minContent" }
1708
+ * tree.computeLayout(rootId, { width: "min-content", height: "min-content" });
1590
1709
  * ```
1591
1710
  *
1592
1711
  * @throws `TaffyError` if the node does not exist or available space is invalid
1593
1712
  *
1594
1713
  * @example
1595
1714
  * ```typescript
1715
+ * const tree = new TaffyTree();
1716
+ * const rootId = tree.newLeaf(new Style());
1596
1717
  * tree.computeLayout(rootId, { width: 800, height: 600 });
1597
1718
  * ```
1598
1719
  */
1599
- computeLayout(node: bigint, available_space: Size<AvailableSpace>): void;
1720
+ computeLayout(node: bigint, availableSpace: Size<AvailableSpace>): void;
1600
1721
  /**
1601
1722
  * Enables rounding of layout values to whole pixels
1602
1723
  *
@@ -1606,6 +1727,7 @@ export class TaffyTree {
1606
1727
  *
1607
1728
  * @example
1608
1729
  * ```typescript
1730
+ * const tree = new TaffyTree();
1609
1731
  * tree.enableRounding();
1610
1732
  * ```
1611
1733
  */
@@ -1619,6 +1741,8 @@ export class TaffyTree {
1619
1741
  *
1620
1742
  * @example
1621
1743
  * ```typescript
1744
+ * const tree = new TaffyTree();
1745
+ * const node = tree.newLeaf(new Style());
1622
1746
  * tree.disableRounding();
1623
1747
  * const layout = tree.getLayout(node);
1624
1748
  * console.log(layout.x);
@@ -1634,6 +1758,8 @@ export class TaffyTree {
1634
1758
  *
1635
1759
  * @example
1636
1760
  * ```typescript
1761
+ * const tree = new TaffyTree();
1762
+ * const nodeId = tree.newLeaf(new Style());
1637
1763
  * interface Context { text: string };
1638
1764
  * const context = tree.getNodeContext(nodeId) as Context | undefined;
1639
1765
  * if (context) {
@@ -1655,6 +1781,8 @@ export class TaffyTree {
1655
1781
  *
1656
1782
  * @example
1657
1783
  * ```typescript
1784
+ * const tree = new TaffyTree();
1785
+ * const nodeId = tree.newLeaf(new Style());
1658
1786
  * interface Context { text: string };
1659
1787
  * tree.setNodeContext(nodeId, { text: "Updated text" } as Context);
1660
1788
  * ```
@@ -1667,6 +1795,7 @@ export class TaffyTree {
1667
1795
  *
1668
1796
  * @example
1669
1797
  * ```typescript
1798
+ * const tree = new TaffyTree();
1670
1799
  * const count: number = tree.totalNodeCount();
1671
1800
  * ```
1672
1801
  */
@@ -1683,6 +1812,8 @@ export class TaffyTree {
1683
1812
  *
1684
1813
  * @example
1685
1814
  * ```typescript
1815
+ * const tree = new TaffyTree();
1816
+ * const nodeId = tree.newLeaf(new Style());
1686
1817
  * const layout: Layout = tree.unroundedLayout(nodeId);
1687
1818
  * console.log(`Exact width: ${layout.width}`);
1688
1819
  * ```
@@ -1703,6 +1834,7 @@ export class TaffyTree {
1703
1834
  *
1704
1835
  * @example
1705
1836
  * ```typescript
1837
+ * const tree = new TaffyTree();
1706
1838
  * const containerStyle = new Style();
1707
1839
  * containerStyle.display = Display.Flex;
1708
1840
  *
@@ -1728,10 +1860,28 @@ export class TaffyTree {
1728
1860
  *
1729
1861
  * @example
1730
1862
  * ```typescript
1863
+ * const tree = new TaffyTree();
1864
+ * const parentId = tree.newLeaf(new Style());
1865
+ * const childId = tree.newLeaf(new Style());
1866
+ * tree.addChild(parentId, childId);
1731
1867
  * const firstChild: bigint = tree.getChildAtIndex(parentId, 0);
1732
1868
  * ```
1733
1869
  */
1734
1870
  getChildAtIndex(parent: bigint, index: number): bigint;
1871
+ /**
1872
+ * Gets detailed layout information for grid layouts
1873
+ *
1874
+ * @note
1875
+ * This method is only available when the `detailed_layout_info`
1876
+ * feature is enabled.
1877
+ *
1878
+ * @param node - The node ID
1879
+ *
1880
+ * @returns - Detailed grid info or "None" for non-grid nodes
1881
+ *
1882
+ * @throws `TaffyError` if the node does not exist
1883
+ */
1884
+ detailedLayoutInfo(node: bigint): any;
1735
1885
  /**
1736
1886
  * Gets a mutable reference to the context value for a node
1737
1887
  *
@@ -1754,6 +1904,9 @@ export class TaffyTree {
1754
1904
  *
1755
1905
  * @example
1756
1906
  * ```typescript
1907
+ * const tree = new TaffyTree();
1908
+ * const parentId = tree.newLeaf(new Style());
1909
+ * const childId = tree.newLeaf(new Style());
1757
1910
  * tree.insertChildAtIndex(parentId, 0, childId);
1758
1911
  * ```
1759
1912
  */
@@ -1774,6 +1927,7 @@ export class TaffyTree {
1774
1927
  * ```typescript
1775
1928
  * interface TextContext { text: string; isBold: boolean; }
1776
1929
  *
1930
+ * const tree = new TaffyTree();
1777
1931
  * const style = new Style();
1778
1932
  * const context: TextContext = { text: "Hello, World!", isBold: true };
1779
1933
  * const nodeId: bigint = tree.newLeafWithContext(style, context);
@@ -1792,6 +1946,10 @@ export class TaffyTree {
1792
1946
  *
1793
1947
  * @example
1794
1948
  * ```typescript
1949
+ * const tree = new TaffyTree();
1950
+ * const parentId = tree.newLeaf(new Style());
1951
+ * const childId = tree.newLeaf(new Style());
1952
+ * tree.addChild(parentId, childId);
1795
1953
  * const removedId: bigint = tree.removeChildAtIndex(parentId, 0);
1796
1954
  * ```
1797
1955
  */
@@ -1802,23 +1960,30 @@ export class TaffyTree {
1802
1960
  * Removes children from `start_index` (inclusive) to `end_index` (exclusive).
1803
1961
  *
1804
1962
  * @param parent - The parent node ID
1805
- * @param start_index - Start of range (inclusive)
1806
- * @param end_index - End of range (exclusive)
1963
+ * @param startIndex - Start of range (inclusive)
1964
+ * @param endIndex - End of range (exclusive)
1807
1965
  *
1808
1966
  * @throws `TaffyError` if the parent node does not exist or range is invalid
1809
1967
  *
1810
1968
  * @example
1811
1969
  * ```typescript
1970
+ * const tree = new TaffyTree();
1971
+ * const parentId = tree.newLeaf(new Style());
1972
+ * const child1 = tree.newLeaf(new Style());
1973
+ * const child2 = tree.newLeaf(new Style());
1974
+ * const child3 = tree.newLeaf(new Style());
1975
+ * tree.setChildren(parentId, BigUint64Array.from([child1, child2, child3]));
1976
+ *
1812
1977
  * tree.removeChildrenRange(parentId, 1, 3);
1813
1978
  * ```
1814
1979
  */
1815
- removeChildrenRange(parent: bigint, start_index: number, end_index: number): void;
1980
+ removeChildrenRange(parent: bigint, startIndex: number, endIndex: number): void;
1816
1981
  /**
1817
1982
  * Replaces a child at a specific index
1818
1983
  *
1819
1984
  * @param parent - The parent node ID
1820
1985
  * @param index - The index of the child to replace (0-based)
1821
- * @param new_child - The new child node ID
1986
+ * @param newChild - The new child node ID
1822
1987
  *
1823
1988
  * @returns - The replaced (old) child ID (`bigint`)
1824
1989
  *
@@ -1826,10 +1991,18 @@ export class TaffyTree {
1826
1991
  *
1827
1992
  * @example
1828
1993
  * ```typescript
1994
+ * const tree = new TaffyTree();
1995
+ * const parentId = tree.newLeaf(new Style());
1996
+ * const oldChild = tree.newLeaf(new Style());
1997
+ * const newChildId = tree.newLeaf(new Style());
1998
+ * tree.addChild(parentId, oldChild);
1999
+ * const child = tree.newLeaf(new Style()); // filler child at index 0 if needed, but index 1 implies 2 children
2000
+ * tree.insertChildAtIndex(parentId, 0, child);
2001
+ *
1829
2002
  * const oldChildId: bigint = tree.replaceChildAtIndex(parentId, 1, newChildId);
1830
2003
  * ```
1831
2004
  */
1832
- replaceChildAtIndex(parent: bigint, index: number, new_child: bigint): bigint;
2005
+ replaceChildAtIndex(parent: bigint, index: number, newChild: bigint): bigint;
1833
2006
  /**
1834
2007
  * Computes layout with a custom measure function for leaf nodes
1835
2008
  *
@@ -1838,19 +2011,24 @@ export class TaffyTree {
1838
2011
  * called for each leaf node that needs measurement.
1839
2012
  *
1840
2013
  * @param node - The root node ID to compute layout for
1841
- * @param available_space - The available space constraints
1842
- * @param measure_func - A function that measures leaf node content
2014
+ * @param availableSpace - The available space constraints
2015
+ * @param measureFunc - A function that measures leaf node content
1843
2016
  *
1844
2017
  * @throws `TaffyError` if the node does not exist or available space is invalid
1845
2018
  *
1846
2019
  * @example
1847
2020
  * ```typescript
2021
+ * const tree = new TaffyTree();
2022
+ * const rootId = tree.newLeaf(new Style());
2023
+ *
2024
+ * const measureText = (text: string, width: number) => ({ width: 0, height: 0 });
2025
+ *
1848
2026
  * tree.computeLayoutWithMeasure(
1849
2027
  * rootId,
1850
- * { width: 800, height: "maxContent" },
2028
+ * { width: 800, height: "max-content" },
1851
2029
  * (known, available, node, context, style) => {
1852
2030
  * if (context?.text) {
1853
- * const measured = measureText(context.text, available.width);
2031
+ * const measured = measureText(context.text, available.width as number);
1854
2032
  * return { width: measured.width, height: measured.height };
1855
2033
  * }
1856
2034
  * return { width: 0, height: 0 };
@@ -1858,7 +2036,7 @@ export class TaffyTree {
1858
2036
  * );
1859
2037
  * ```
1860
2038
  */
1861
- computeLayoutWithMeasure(node: bigint, available_space: Size<AvailableSpace>, measure_func: MeasureFunction): void;
2039
+ computeLayoutWithMeasure(node: bigint, availableSpace: Size<AvailableSpace>, measureFunc: MeasureFunction): void;
1862
2040
  /**
1863
2041
  * Gets context values for multiple nodes at once
1864
2042
  *
@@ -1871,6 +2049,9 @@ export class TaffyTree {
1871
2049
  *
1872
2050
  * @example
1873
2051
  * ```typescript
2052
+ * const tree = new TaffyTree();
2053
+ * const id1 = tree.newLeaf(new Style());
2054
+ * const id2 = tree.newLeaf(new Style());
1874
2055
  * const nodes = BigUint64Array.from([id1, id2]);
1875
2056
  * const contexts = tree.getDisjointNodeContextMut(nodes);
1876
2057
  * ```
@@ -1896,6 +2077,7 @@ export class TaffyTree {
1896
2077
  *
1897
2078
  * @example
1898
2079
  * ```typescript
2080
+ * const tree = new TaffyTree();
1899
2081
  * tree.clear();
1900
2082
  * console.log(tree.totalNodeCount());
1901
2083
  * ```
@@ -1915,6 +2097,11 @@ export class TaffyTree {
1915
2097
  *
1916
2098
  * @example
1917
2099
  * ```typescript
2100
+ * const tree = new TaffyTree();
2101
+ * const rootId = tree.newLeaf(new Style());
2102
+ * const nodeId = rootId;
2103
+ * const availableSpace = { width: 100, height: 100 };
2104
+ *
1918
2105
  * if (tree.dirty(nodeId)) {
1919
2106
  * tree.computeLayout(rootId, availableSpace);
1920
2107
  * }
@@ -1932,6 +2119,8 @@ export class TaffyTree {
1932
2119
  *
1933
2120
  * @example
1934
2121
  * ```typescript
2122
+ * const tree = new TaffyTree();
2123
+ * const nodeId = tree.newLeaf(new Style());
1935
2124
  * const style: Style = tree.getStyle(nodeId);
1936
2125
  * console.log('Flex grow:', style.flexGrow);
1937
2126
  * ```
@@ -1951,6 +2140,12 @@ export class TaffyTree {
1951
2140
  *
1952
2141
  * @example
1953
2142
  * ```typescript
2143
+ * const tree = new TaffyTree();
2144
+ * const style = new Style();
2145
+ * style.size = { width: 100, height: 100 };
2146
+ * const rootId = tree.newLeaf(style);
2147
+ * const nodeId = rootId;
2148
+ *
1954
2149
  * tree.computeLayout(rootId, { width: 800, height: 600 });
1955
2150
  * const layout: Layout = tree.getLayout(nodeId);
1956
2151
  * console.log(`Position: (${layout.x}, ${layout.y}), Size: ${layout.width}x${layout.height}`);
@@ -1966,7 +2161,11 @@ export class TaffyTree {
1966
2161
  *
1967
2162
  * @example
1968
2163
  * ```typescript
1969
- * const parentId: bigint | undefined = tree.parent(childId);
2164
+ * const tree = new TaffyTree();
2165
+ * const parentId = tree.newLeaf(new Style());
2166
+ * const childId = tree.newLeaf(new Style());
2167
+ * tree.addChild(parentId, childId);
2168
+ * const parent: bigint | undefined = tree.parent(childId);
1970
2169
  * ```
1971
2170
  */
1972
2171
  parent(child: bigint): bigint | undefined;
@@ -1984,6 +2183,8 @@ export class TaffyTree {
1984
2183
  *
1985
2184
  * @example
1986
2185
  * ```typescript
2186
+ * const tree = new TaffyTree();
2187
+ * const nodeId = tree.newLeaf(new Style());
1987
2188
  * try {
1988
2189
  * const removedId: bigint = tree.remove(nodeId);
1989
2190
  * } catch (e) {
@@ -2003,6 +2204,8 @@ export class TaffyTree {
2003
2204
  *
2004
2205
  * @example
2005
2206
  * ```typescript
2207
+ * const tree = new TaffyTree();
2208
+ * const parentId = tree.newLeaf(new Style());
2006
2209
  * const children: BigUint64Array = tree.children(parentId);
2007
2210
  * ```
2008
2211
  */
@@ -2019,6 +2222,7 @@ export class TaffyTree {
2019
2222
  *
2020
2223
  * @example
2021
2224
  * ```typescript
2225
+ * const tree = new TaffyTree();
2022
2226
  * const style = new Style();
2023
2227
  * style.size = { width: 100, height: 50 };
2024
2228
  * const nodeId: bigint = tree.newLeaf(style);
@@ -2037,6 +2241,9 @@ export class TaffyTree {
2037
2241
  *
2038
2242
  * @example
2039
2243
  * ```typescript
2244
+ * const tree = new TaffyTree();
2245
+ * const parentId = tree.newLeaf(new Style());
2246
+ * const childId = tree.newLeaf(new Style());
2040
2247
  * tree.addChild(parentId, childId);
2041
2248
  * ```
2042
2249
  */
@@ -2054,6 +2261,8 @@ export class TaffyTree {
2054
2261
  *
2055
2262
  * @example
2056
2263
  * ```typescript
2264
+ * const tree = new TaffyTree();
2265
+ * const nodeId = tree.newLeaf(new Style());
2057
2266
  * const newStyle = new Style();
2058
2267
  * newStyle.flexGrow = 2;
2059
2268
  * tree.setStyle(nodeId, newStyle);
@@ -2070,8 +2279,9 @@ export class TaffyTree {
2070
2279
  *
2071
2280
  * @example
2072
2281
  * ```typescript
2073
- * import { TextAlign } from 'taffy-js';
2282
+ * import { Style, TextAlign } from 'taffy-js';
2074
2283
  *
2284
+ * const style = new Style();
2075
2285
  * style.textAlign = TextAlign.LegacyCenter; // Center block children
2076
2286
  * ```
2077
2287
  */
@@ -2207,6 +2417,7 @@ export interface InitOutput {
2207
2417
  readonly taffytree_clear: (a: number) => void;
2208
2418
  readonly taffytree_computeLayout: (a: number, b: bigint, c: any) => [number, number];
2209
2419
  readonly taffytree_computeLayoutWithMeasure: (a: number, b: bigint, c: any, d: any) => [number, number];
2420
+ readonly taffytree_detailedLayoutInfo: (a: number, b: bigint) => [number, number, number];
2210
2421
  readonly taffytree_dirty: (a: number, b: bigint) => [number, number, number];
2211
2422
  readonly taffytree_disableRounding: (a: number) => void;
2212
2423
  readonly taffytree_enableRounding: (a: number) => void;