taffy-js 0.2.10 → 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.
- package/README.md +110 -288
- package/package.json +4 -3
- package/pkg/README.md +110 -288
- package/pkg/package.json +1 -1
- package/pkg/taffy_wasm.d.ts +575 -62
- package/pkg/taffy_wasm.js +726 -37
- package/pkg/taffy_wasm_bg.wasm +0 -0
- package/pkg/taffy_wasm_bg.wasm.d.ts +33 -0
package/pkg/taffy_wasm.d.ts
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @remarks
|
|
11
11
|
* - Use `number` when you have a fixed container size
|
|
12
|
-
* - Use `"
|
|
13
|
-
* - Use `"
|
|
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: "
|
|
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 | "
|
|
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: "
|
|
65
|
+
* height: "max-content"
|
|
66
66
|
* };
|
|
67
67
|
* ```
|
|
68
68
|
*/
|
|
69
|
-
export
|
|
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, "
|
|
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: "
|
|
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
|
|
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
|
|
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
|
|
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
|
|
336
|
-
* const 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 |
|
|
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
|
|
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
|
|
368
|
-
* @property
|
|
369
|
-
* @property
|
|
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
|
|
382
|
+
export type DetailedGridTracksInfo = {
|
|
374
383
|
/** Number of implicit tracks before explicit tracks (for negative line numbers) */
|
|
375
|
-
|
|
384
|
+
negativeImplicitTracks: number;
|
|
376
385
|
/** Number of tracks explicitly defined in grid-template-rows/columns */
|
|
377
|
-
|
|
386
|
+
explicitTracks: number;
|
|
378
387
|
/** Number of implicit tracks created after explicit tracks */
|
|
379
|
-
|
|
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,155 @@ 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
|
|
393
|
-
* @property
|
|
394
|
-
* @property
|
|
395
|
-
* @property
|
|
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
|
|
406
|
+
export type DetailedGridItemsInfo = {
|
|
398
407
|
/** Starting row line (1-indexed) */
|
|
399
|
-
|
|
408
|
+
rowStart: number;
|
|
400
409
|
/** Ending row line (exclusive) */
|
|
401
|
-
|
|
410
|
+
rowEnd: number;
|
|
402
411
|
/** Starting column line (1-indexed) */
|
|
403
|
-
|
|
412
|
+
columnStart: number;
|
|
404
413
|
/** Ending column line (exclusive) */
|
|
405
|
-
|
|
414
|
+
columnEnd: number;
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Grid placement type for positioning grid items.
|
|
419
|
+
*
|
|
420
|
+
* Specifies how an item is placed on a grid track (row or column).
|
|
421
|
+
* Follows CSS `grid-row-start` / `grid-column-start` specification.
|
|
422
|
+
*
|
|
423
|
+
* @remarks
|
|
424
|
+
* - `"auto"`: Auto-placement using the grid's flow algorithm
|
|
425
|
+
* - `number`: Place at a specific line index (1-indexed, can be negative)
|
|
426
|
+
* - `{ span: number }`: Span a specified number of tracks
|
|
427
|
+
*
|
|
428
|
+
* @example
|
|
429
|
+
* ```typescript
|
|
430
|
+
* import type { GridPlacement, Line } from 'taffy-js';
|
|
431
|
+
*
|
|
432
|
+
* // Line index (CSS: grid-row-start: 2)
|
|
433
|
+
* const lineIndex: GridPlacement = 2;
|
|
434
|
+
*
|
|
435
|
+
* // Auto placement (CSS: grid-row-start: auto)
|
|
436
|
+
* const auto: GridPlacement = "auto";
|
|
437
|
+
*
|
|
438
|
+
* // Span (CSS: grid-row-start: span 3)
|
|
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" };
|
|
446
|
+
* ```
|
|
447
|
+
*/
|
|
448
|
+
export type GridPlacement = "auto" | number | {line: number; ident: string} | {span: number; ident?: string};
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* Line type representing start and end positions.
|
|
452
|
+
*
|
|
453
|
+
* A container for start and end values, used for CSS grid-row and grid-column
|
|
454
|
+
* shorthand properties.
|
|
455
|
+
*
|
|
456
|
+
* @typeParam T - The type of start and end values
|
|
457
|
+
*
|
|
458
|
+
* @property start - The starting line/position
|
|
459
|
+
* @property end - The ending line/position
|
|
460
|
+
*
|
|
461
|
+
* @example
|
|
462
|
+
* ```typescript
|
|
463
|
+
* import { Style, Display, type Line, type GridPlacement } from 'taffy-js';
|
|
464
|
+
*
|
|
465
|
+
* const style = new Style();
|
|
466
|
+
* style.display = Display.Grid;
|
|
467
|
+
*
|
|
468
|
+
* // CSS: grid-row: 1 / 3
|
|
469
|
+
* style.gridRow = { start: 1, end: 3 };
|
|
470
|
+
*
|
|
471
|
+
* // CSS: grid-column: 1 / span 2
|
|
472
|
+
* style.gridColumn = { start: 1, end: { span: 2 } };
|
|
473
|
+
*
|
|
474
|
+
* // CSS: grid-row: auto / auto
|
|
475
|
+
* style.gridRow = { start: "auto", end: "auto" };
|
|
476
|
+
* ```
|
|
477
|
+
*/
|
|
478
|
+
export type Line<T> = {
|
|
479
|
+
/** The starting position (CSS: *-start) */
|
|
480
|
+
start: T;
|
|
481
|
+
/** The ending position (CSS: *-end) */
|
|
482
|
+
end: T;
|
|
406
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
|
+
};
|
|
407
550
|
|
|
408
551
|
|
|
409
552
|
|
|
@@ -417,8 +560,9 @@ export interface DetailedGridItemsInfo {
|
|
|
417
560
|
*
|
|
418
561
|
* @example
|
|
419
562
|
* ```typescript
|
|
420
|
-
* import { AlignContent, FlexWrap } from 'taffy-js';
|
|
563
|
+
* import { Style, AlignContent, FlexWrap } from 'taffy-js';
|
|
421
564
|
*
|
|
565
|
+
* const style = new Style();
|
|
422
566
|
* style.flexWrap = FlexWrap.Wrap;
|
|
423
567
|
* style.alignContent = AlignContent.SpaceBetween; // Distribute lines evenly
|
|
424
568
|
* ```
|
|
@@ -470,8 +614,9 @@ export enum AlignContent {
|
|
|
470
614
|
*
|
|
471
615
|
* @example
|
|
472
616
|
* ```typescript
|
|
473
|
-
* import { AlignItems } from 'taffy-js';
|
|
617
|
+
* import { Style, AlignItems } from 'taffy-js';
|
|
474
618
|
*
|
|
619
|
+
* const style = new Style();
|
|
475
620
|
* style.alignItems = AlignItems.Center; // Center items on cross axis
|
|
476
621
|
* style.alignItems = AlignItems.Stretch; // Stretch items to fill container
|
|
477
622
|
* ```
|
|
@@ -515,8 +660,9 @@ export enum AlignItems {
|
|
|
515
660
|
*
|
|
516
661
|
* @example
|
|
517
662
|
* ```typescript
|
|
518
|
-
* import { AlignSelf } from 'taffy-js';
|
|
663
|
+
* import { Style, AlignSelf } from 'taffy-js';
|
|
519
664
|
*
|
|
665
|
+
* const style = new Style();
|
|
520
666
|
* style.alignSelf = AlignSelf.Auto; // Use parent's align-items
|
|
521
667
|
* style.alignSelf = AlignSelf.Center; // Override to center this item
|
|
522
668
|
* ```
|
|
@@ -564,8 +710,9 @@ export enum AlignSelf {
|
|
|
564
710
|
*
|
|
565
711
|
* @example
|
|
566
712
|
* ```typescript
|
|
567
|
-
* import { BoxSizing } from 'taffy-js';
|
|
713
|
+
* import { Style, BoxSizing } from 'taffy-js';
|
|
568
714
|
*
|
|
715
|
+
* const style = new Style();
|
|
569
716
|
* style.boxSizing = BoxSizing.BorderBox; // Size includes padding and border
|
|
570
717
|
* style.boxSizing = BoxSizing.ContentBox; // Size is content only
|
|
571
718
|
* ```
|
|
@@ -589,8 +736,9 @@ export enum BoxSizing {
|
|
|
589
736
|
*
|
|
590
737
|
* @example
|
|
591
738
|
* ```typescript
|
|
592
|
-
* import { Display } from 'taffy-js';
|
|
739
|
+
* import { Style, Display } from 'taffy-js';
|
|
593
740
|
*
|
|
741
|
+
* const style = new Style();
|
|
594
742
|
* style.display = Display.Flex; // Enable flexbox layout
|
|
595
743
|
* style.display = Display.Grid; // Enable grid layout
|
|
596
744
|
* style.display = Display.None; // Hide element from layout
|
|
@@ -623,8 +771,9 @@ export enum Display {
|
|
|
623
771
|
*
|
|
624
772
|
* @example
|
|
625
773
|
* ```typescript
|
|
626
|
-
* import { FlexDirection } from 'taffy-js';
|
|
774
|
+
* import { Style, FlexDirection } from 'taffy-js';
|
|
627
775
|
*
|
|
776
|
+
* const style = new Style();
|
|
628
777
|
* style.flexDirection = FlexDirection.Row; // Horizontal, left to right
|
|
629
778
|
* style.flexDirection = FlexDirection.Column; // Vertical, top to bottom
|
|
630
779
|
* ```
|
|
@@ -656,8 +805,9 @@ export enum FlexDirection {
|
|
|
656
805
|
*
|
|
657
806
|
* @example
|
|
658
807
|
* ```typescript
|
|
659
|
-
* import { FlexWrap } from 'taffy-js';
|
|
808
|
+
* import { Style, FlexWrap } from 'taffy-js';
|
|
660
809
|
*
|
|
810
|
+
* const style = new Style();
|
|
661
811
|
* style.flexWrap = FlexWrap.NoWrap; // All items on single line
|
|
662
812
|
* style.flexWrap = FlexWrap.Wrap; // Items wrap to new lines
|
|
663
813
|
* ```
|
|
@@ -677,6 +827,41 @@ export enum FlexWrap {
|
|
|
677
827
|
WrapReverse = 2,
|
|
678
828
|
}
|
|
679
829
|
|
|
830
|
+
/**
|
|
831
|
+
* Grid auto flow enumeration
|
|
832
|
+
*
|
|
833
|
+
* Controls whether grid items are placed row-wise or column-wise, and whether
|
|
834
|
+
* the sparse or dense packing algorithm is used.
|
|
835
|
+
*
|
|
836
|
+
* @example
|
|
837
|
+
* ```typescript
|
|
838
|
+
* import { Style, GridAutoFlow } from 'taffy-js';
|
|
839
|
+
*
|
|
840
|
+
* const style = new Style();
|
|
841
|
+
* style.gridAutoFlow = GridAutoFlow.Row; // Fill rows first
|
|
842
|
+
* style.gridAutoFlow = GridAutoFlow.Column; // Fill columns first
|
|
843
|
+
* style.gridAutoFlow = GridAutoFlow.RowDense; // Fill rows, pack densely
|
|
844
|
+
* ```
|
|
845
|
+
*/
|
|
846
|
+
export enum GridAutoFlow {
|
|
847
|
+
/**
|
|
848
|
+
* Items are placed by filling each row in turn, adding new rows as necessary
|
|
849
|
+
*/
|
|
850
|
+
Row = 0,
|
|
851
|
+
/**
|
|
852
|
+
* Items are placed by filling each column in turn, adding new columns as necessary
|
|
853
|
+
*/
|
|
854
|
+
Column = 1,
|
|
855
|
+
/**
|
|
856
|
+
* Combines `Row` with the dense packing algorithm
|
|
857
|
+
*/
|
|
858
|
+
RowDense = 2,
|
|
859
|
+
/**
|
|
860
|
+
* Combines `Column` with the dense packing algorithm
|
|
861
|
+
*/
|
|
862
|
+
ColumnDense = 3,
|
|
863
|
+
}
|
|
864
|
+
|
|
680
865
|
/**
|
|
681
866
|
* Main axis alignment enumeration
|
|
682
867
|
*
|
|
@@ -685,8 +870,9 @@ export enum FlexWrap {
|
|
|
685
870
|
*
|
|
686
871
|
* @example
|
|
687
872
|
* ```typescript
|
|
688
|
-
* import { JustifyContent } from 'taffy-js';
|
|
873
|
+
* import { Style, JustifyContent } from 'taffy-js';
|
|
689
874
|
*
|
|
875
|
+
* const style = new Style();
|
|
690
876
|
* style.justifyContent = JustifyContent.Center; // Center items
|
|
691
877
|
* style.justifyContent = JustifyContent.SpaceBetween; // Distribute evenly
|
|
692
878
|
* ```
|
|
@@ -738,6 +924,11 @@ export enum JustifyContent {
|
|
|
738
924
|
*
|
|
739
925
|
* @example
|
|
740
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 });
|
|
741
932
|
* const layout = tree.getLayout(node);
|
|
742
933
|
*
|
|
743
934
|
* console.log("Position:", layout.x, layout.y);
|
|
@@ -917,8 +1108,9 @@ export class Layout {
|
|
|
917
1108
|
*
|
|
918
1109
|
* @example
|
|
919
1110
|
* ```typescript
|
|
920
|
-
* import { Overflow } from 'taffy-js';
|
|
1111
|
+
* import { Style, Overflow } from 'taffy-js';
|
|
921
1112
|
*
|
|
1113
|
+
* const style = new Style();
|
|
922
1114
|
* style.overflow = { x: Overflow.Hidden, y: Overflow.Scroll };
|
|
923
1115
|
* ```
|
|
924
1116
|
*/
|
|
@@ -949,8 +1141,9 @@ export enum Overflow {
|
|
|
949
1141
|
*
|
|
950
1142
|
* @example
|
|
951
1143
|
* ```typescript
|
|
952
|
-
* import { Position } from 'taffy-js';
|
|
1144
|
+
* import { Style, Position } from 'taffy-js';
|
|
953
1145
|
*
|
|
1146
|
+
* const style = new Style();
|
|
954
1147
|
* style.position = Position.Relative; // Normal document flow
|
|
955
1148
|
* style.position = Position.Absolute; // Removed from flow, uses inset values
|
|
956
1149
|
* ```
|
|
@@ -1042,6 +1235,16 @@ export class Style {
|
|
|
1042
1235
|
* @returns - A `Rect<LengthPercentageAuto>` with left, right, top, bottom margins
|
|
1043
1236
|
*/
|
|
1044
1237
|
margin: Rect<LengthPercentageAuto>;
|
|
1238
|
+
/**
|
|
1239
|
+
* Gets the text-align property
|
|
1240
|
+
*
|
|
1241
|
+
* Used by block layout to implement legacy text alignment behavior.
|
|
1242
|
+
*
|
|
1243
|
+
* @returns - The current [`TextAlign`](JsTextAlign) value
|
|
1244
|
+
*
|
|
1245
|
+
* @defaultValue - `TextAlign.Auto`
|
|
1246
|
+
*/
|
|
1247
|
+
textAlign: TextAlign;
|
|
1045
1248
|
/**
|
|
1046
1249
|
* Gets the align-items property
|
|
1047
1250
|
*
|
|
@@ -1059,6 +1262,15 @@ export class Style {
|
|
|
1059
1262
|
* @returns - The flex shrink factor (default: 1)
|
|
1060
1263
|
*/
|
|
1061
1264
|
flexShrink: number;
|
|
1265
|
+
/**
|
|
1266
|
+
* Gets the grid-column property
|
|
1267
|
+
*
|
|
1268
|
+
* Defines which column in the grid the item should start and end at.
|
|
1269
|
+
* Corresponds to CSS `grid-column` shorthand.
|
|
1270
|
+
*
|
|
1271
|
+
* @returns - A `Line<GridPlacement>` with start and end placements
|
|
1272
|
+
*/
|
|
1273
|
+
gridColumn: Line<GridPlacement>;
|
|
1062
1274
|
/**
|
|
1063
1275
|
* Gets the display mode
|
|
1064
1276
|
*
|
|
@@ -1085,6 +1297,23 @@ export class Style {
|
|
|
1085
1297
|
* @returns - The aspect ratio value, or `undefined` if not set
|
|
1086
1298
|
*/
|
|
1087
1299
|
aspectRatio: number | undefined;
|
|
1300
|
+
/**
|
|
1301
|
+
* Gets the justify-self property
|
|
1302
|
+
*
|
|
1303
|
+
* Overrides the parent's justify-items for this specific element in the inline axis.
|
|
1304
|
+
*
|
|
1305
|
+
* @returns - The current [`AlignSelf`](JsAlignSelf) value (returns `Auto` if not set)
|
|
1306
|
+
*/
|
|
1307
|
+
justifySelf: AlignSelf | undefined;
|
|
1308
|
+
/**
|
|
1309
|
+
* Gets the grid-row property
|
|
1310
|
+
*
|
|
1311
|
+
* Defines which row in the grid the item should start and end at.
|
|
1312
|
+
* Corresponds to CSS `grid-row` shorthand.
|
|
1313
|
+
*
|
|
1314
|
+
* @returns - A `Line<GridPlacement>` with start and end placements
|
|
1315
|
+
*/
|
|
1316
|
+
gridRow: Line<GridPlacement>;
|
|
1088
1317
|
/**
|
|
1089
1318
|
* Gets the maximum size constraints
|
|
1090
1319
|
*
|
|
@@ -1123,6 +1352,25 @@ export class Style {
|
|
|
1123
1352
|
* @returns - The current [`AlignContent`](JsAlignContent) value, or `undefined` if not set
|
|
1124
1353
|
*/
|
|
1125
1354
|
alignContent: AlignContent | undefined;
|
|
1355
|
+
/**
|
|
1356
|
+
* Gets whether this item is a table
|
|
1357
|
+
*
|
|
1358
|
+
* Table children are handled specially in block layout.
|
|
1359
|
+
*
|
|
1360
|
+
* @returns - Whether the item is treated as a table
|
|
1361
|
+
*
|
|
1362
|
+
* @defaultValue - `false`
|
|
1363
|
+
*/
|
|
1364
|
+
itemIsTable: boolean;
|
|
1365
|
+
/**
|
|
1366
|
+
* Gets the justify-items property
|
|
1367
|
+
*
|
|
1368
|
+
* Defines the default justify-self for all children in the inline axis.
|
|
1369
|
+
* This is primarily used for CSS Grid layout.
|
|
1370
|
+
*
|
|
1371
|
+
* @returns - The current [`AlignItems`](JsAlignItems) value, or `undefined` if not set
|
|
1372
|
+
*/
|
|
1373
|
+
justifyItems: AlignItems | undefined;
|
|
1126
1374
|
/**
|
|
1127
1375
|
* Gets the flex grow factor
|
|
1128
1376
|
*
|
|
@@ -1152,6 +1400,24 @@ export class Style {
|
|
|
1152
1400
|
* @defaultValue - `FlexDirection.Row`
|
|
1153
1401
|
*/
|
|
1154
1402
|
flexDirection: FlexDirection;
|
|
1403
|
+
/**
|
|
1404
|
+
* Gets the grid-auto-flow property
|
|
1405
|
+
*
|
|
1406
|
+
* Controls how auto-placed items are inserted into the grid.
|
|
1407
|
+
*
|
|
1408
|
+
* @returns - The current [`GridAutoFlow`](JsGridAutoFlow) value
|
|
1409
|
+
*
|
|
1410
|
+
* @defaultValue - `GridAutoFlow.Row`
|
|
1411
|
+
*/
|
|
1412
|
+
gridAutoFlow: GridAutoFlow;
|
|
1413
|
+
/**
|
|
1414
|
+
* Gets the grid-auto-rows property
|
|
1415
|
+
*
|
|
1416
|
+
* Defines the size of implicitly created rows.
|
|
1417
|
+
*
|
|
1418
|
+
* @returns - An array of track sizing functions
|
|
1419
|
+
*/
|
|
1420
|
+
gridAutoRows: TrackSizingFunction[];
|
|
1155
1421
|
/**
|
|
1156
1422
|
* Gets the justify-content property
|
|
1157
1423
|
*
|
|
@@ -1160,6 +1426,74 @@ export class Style {
|
|
|
1160
1426
|
* @returns - The current [`JustifyContent`](JsJustifyContent) value, or `undefined` if not set
|
|
1161
1427
|
*/
|
|
1162
1428
|
justifyContent: JustifyContent | undefined;
|
|
1429
|
+
/**
|
|
1430
|
+
* Gets the scrollbar width
|
|
1431
|
+
*
|
|
1432
|
+
* The width of the scrollbar gutter when `overflow` is set to `Scroll`.
|
|
1433
|
+
*
|
|
1434
|
+
* @returns - The scrollbar width in pixels
|
|
1435
|
+
*
|
|
1436
|
+
* @defaultValue - `0`
|
|
1437
|
+
*/
|
|
1438
|
+
scrollbarWidth: number;
|
|
1439
|
+
/**
|
|
1440
|
+
* Gets whether this item is a replaced element
|
|
1441
|
+
*
|
|
1442
|
+
* Replaced elements have special sizing behavior (e.g., `<img>`, `<video>`).
|
|
1443
|
+
*
|
|
1444
|
+
* @returns - Whether the item is a replaced element
|
|
1445
|
+
*
|
|
1446
|
+
* @defaultValue - `false`
|
|
1447
|
+
*/
|
|
1448
|
+
itemIsReplaced: boolean;
|
|
1449
|
+
/**
|
|
1450
|
+
* Gets the grid-auto-columns property
|
|
1451
|
+
*
|
|
1452
|
+
* Defines the size of implicitly created columns.
|
|
1453
|
+
*
|
|
1454
|
+
* @returns - An array of track sizing functions
|
|
1455
|
+
*/
|
|
1456
|
+
gridAutoColumns: TrackSizingFunction[];
|
|
1457
|
+
/**
|
|
1458
|
+
* Gets the grid-template-rows property
|
|
1459
|
+
*
|
|
1460
|
+
* Defines the track sizing functions (heights) of the grid rows.
|
|
1461
|
+
*
|
|
1462
|
+
* @returns - An array of `GridTrack` values
|
|
1463
|
+
*/
|
|
1464
|
+
gridTemplateRows: GridTemplateComponent[];
|
|
1465
|
+
/**
|
|
1466
|
+
* Gets the grid-template-areas property
|
|
1467
|
+
*
|
|
1468
|
+
* Defines named grid areas that can be referenced by grid items.
|
|
1469
|
+
*
|
|
1470
|
+
* @returns - An array of `GridArea` values
|
|
1471
|
+
*/
|
|
1472
|
+
gridTemplateAreas: GridTemplateArea[];
|
|
1473
|
+
/**
|
|
1474
|
+
* Gets the grid-template-columns property
|
|
1475
|
+
*
|
|
1476
|
+
* Defines the track sizing functions (widths) of the grid columns.
|
|
1477
|
+
*
|
|
1478
|
+
* @returns - An array of `GridTrack` values
|
|
1479
|
+
*/
|
|
1480
|
+
gridTemplateColumns: GridTemplateComponent[];
|
|
1481
|
+
/**
|
|
1482
|
+
* Gets the grid-template-row-names property
|
|
1483
|
+
*
|
|
1484
|
+
* Defines the named lines between the rows.
|
|
1485
|
+
*
|
|
1486
|
+
* @returns - An array of arrays of line names
|
|
1487
|
+
*/
|
|
1488
|
+
gridTemplateRowNames: string[][];
|
|
1489
|
+
/**
|
|
1490
|
+
* Gets the grid-template-column-names property
|
|
1491
|
+
*
|
|
1492
|
+
* Defines the named lines between the columns.
|
|
1493
|
+
*
|
|
1494
|
+
* @returns - An array of arrays of line names
|
|
1495
|
+
*/
|
|
1496
|
+
gridTemplateColumnNames: string[][];
|
|
1163
1497
|
/**
|
|
1164
1498
|
* Gets the gap
|
|
1165
1499
|
*
|
|
@@ -1193,6 +1527,8 @@ export class Style {
|
|
|
1193
1527
|
* @example
|
|
1194
1528
|
* ```typescript
|
|
1195
1529
|
* try {
|
|
1530
|
+
* const tree = new TaffyTree();
|
|
1531
|
+
* const node = tree.newLeaf(new Style());
|
|
1196
1532
|
* tree.remove(node);
|
|
1197
1533
|
* } catch (e) {
|
|
1198
1534
|
* if (e instanceof TaffyError) {
|
|
@@ -1246,6 +1582,11 @@ export class TaffyTree {
|
|
|
1246
1582
|
*
|
|
1247
1583
|
* @example
|
|
1248
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
|
+
*
|
|
1249
1590
|
* // After updating text content
|
|
1250
1591
|
* tree.setNodeContext(nodeId, { text: "Updated text" });
|
|
1251
1592
|
* tree.markDirty(nodeId);
|
|
@@ -1263,6 +1604,8 @@ export class TaffyTree {
|
|
|
1263
1604
|
*
|
|
1264
1605
|
* @example
|
|
1265
1606
|
* ```typescript
|
|
1607
|
+
* const tree = new TaffyTree();
|
|
1608
|
+
* const rootId = tree.newLeaf(new Style());
|
|
1266
1609
|
* tree.printTree(rootId);
|
|
1267
1610
|
* // Output appears in browser console
|
|
1268
1611
|
* ```
|
|
@@ -1279,6 +1622,8 @@ export class TaffyTree {
|
|
|
1279
1622
|
*
|
|
1280
1623
|
* @example
|
|
1281
1624
|
* ```typescript
|
|
1625
|
+
* const tree = new TaffyTree();
|
|
1626
|
+
* const parentId = tree.newLeaf(new Style());
|
|
1282
1627
|
* const count: number = tree.childCount(parentId);
|
|
1283
1628
|
* ```
|
|
1284
1629
|
*/
|
|
@@ -1295,6 +1640,10 @@ export class TaffyTree {
|
|
|
1295
1640
|
*
|
|
1296
1641
|
* @example
|
|
1297
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);
|
|
1298
1647
|
* tree.removeChild(parentId, childId);
|
|
1299
1648
|
* ```
|
|
1300
1649
|
*/
|
|
@@ -1311,6 +1660,11 @@ export class TaffyTree {
|
|
|
1311
1660
|
*
|
|
1312
1661
|
* @example
|
|
1313
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());
|
|
1314
1668
|
* const children = BigUint64Array.from([child1, child2, child3]);
|
|
1315
1669
|
* tree.setChildren(parentId, children);
|
|
1316
1670
|
* ```
|
|
@@ -1337,28 +1691,33 @@ export class TaffyTree {
|
|
|
1337
1691
|
* to compute layouts for all nodes in the tree.
|
|
1338
1692
|
*
|
|
1339
1693
|
* @param node - The root node ID to compute layout for
|
|
1340
|
-
* @param
|
|
1694
|
+
* @param availableSpace - The available space constraints
|
|
1341
1695
|
*
|
|
1342
1696
|
* @example
|
|
1343
1697
|
* ```typescript
|
|
1698
|
+
* const tree = new TaffyTree();
|
|
1699
|
+
* const rootId = tree.newLeaf(new Style());
|
|
1700
|
+
*
|
|
1344
1701
|
* // Fixed size container
|
|
1345
|
-
* { width: 800, height: 600 }
|
|
1702
|
+
* tree.computeLayout(rootId, { width: 800, height: 600 });
|
|
1346
1703
|
*
|
|
1347
1704
|
* // Flexible width, fixed height
|
|
1348
|
-
* { width: "
|
|
1705
|
+
* tree.computeLayout(rootId, { width: "max-content", height: 600 });
|
|
1349
1706
|
*
|
|
1350
1707
|
* // Minimum content size
|
|
1351
|
-
* { width: "
|
|
1708
|
+
* tree.computeLayout(rootId, { width: "min-content", height: "min-content" });
|
|
1352
1709
|
* ```
|
|
1353
1710
|
*
|
|
1354
1711
|
* @throws `TaffyError` if the node does not exist or available space is invalid
|
|
1355
1712
|
*
|
|
1356
1713
|
* @example
|
|
1357
1714
|
* ```typescript
|
|
1715
|
+
* const tree = new TaffyTree();
|
|
1716
|
+
* const rootId = tree.newLeaf(new Style());
|
|
1358
1717
|
* tree.computeLayout(rootId, { width: 800, height: 600 });
|
|
1359
1718
|
* ```
|
|
1360
1719
|
*/
|
|
1361
|
-
computeLayout(node: bigint,
|
|
1720
|
+
computeLayout(node: bigint, availableSpace: Size<AvailableSpace>): void;
|
|
1362
1721
|
/**
|
|
1363
1722
|
* Enables rounding of layout values to whole pixels
|
|
1364
1723
|
*
|
|
@@ -1368,6 +1727,7 @@ export class TaffyTree {
|
|
|
1368
1727
|
*
|
|
1369
1728
|
* @example
|
|
1370
1729
|
* ```typescript
|
|
1730
|
+
* const tree = new TaffyTree();
|
|
1371
1731
|
* tree.enableRounding();
|
|
1372
1732
|
* ```
|
|
1373
1733
|
*/
|
|
@@ -1381,6 +1741,8 @@ export class TaffyTree {
|
|
|
1381
1741
|
*
|
|
1382
1742
|
* @example
|
|
1383
1743
|
* ```typescript
|
|
1744
|
+
* const tree = new TaffyTree();
|
|
1745
|
+
* const node = tree.newLeaf(new Style());
|
|
1384
1746
|
* tree.disableRounding();
|
|
1385
1747
|
* const layout = tree.getLayout(node);
|
|
1386
1748
|
* console.log(layout.x);
|
|
@@ -1396,6 +1758,8 @@ export class TaffyTree {
|
|
|
1396
1758
|
*
|
|
1397
1759
|
* @example
|
|
1398
1760
|
* ```typescript
|
|
1761
|
+
* const tree = new TaffyTree();
|
|
1762
|
+
* const nodeId = tree.newLeaf(new Style());
|
|
1399
1763
|
* interface Context { text: string };
|
|
1400
1764
|
* const context = tree.getNodeContext(nodeId) as Context | undefined;
|
|
1401
1765
|
* if (context) {
|
|
@@ -1417,6 +1781,8 @@ export class TaffyTree {
|
|
|
1417
1781
|
*
|
|
1418
1782
|
* @example
|
|
1419
1783
|
* ```typescript
|
|
1784
|
+
* const tree = new TaffyTree();
|
|
1785
|
+
* const nodeId = tree.newLeaf(new Style());
|
|
1420
1786
|
* interface Context { text: string };
|
|
1421
1787
|
* tree.setNodeContext(nodeId, { text: "Updated text" } as Context);
|
|
1422
1788
|
* ```
|
|
@@ -1429,6 +1795,7 @@ export class TaffyTree {
|
|
|
1429
1795
|
*
|
|
1430
1796
|
* @example
|
|
1431
1797
|
* ```typescript
|
|
1798
|
+
* const tree = new TaffyTree();
|
|
1432
1799
|
* const count: number = tree.totalNodeCount();
|
|
1433
1800
|
* ```
|
|
1434
1801
|
*/
|
|
@@ -1445,6 +1812,8 @@ export class TaffyTree {
|
|
|
1445
1812
|
*
|
|
1446
1813
|
* @example
|
|
1447
1814
|
* ```typescript
|
|
1815
|
+
* const tree = new TaffyTree();
|
|
1816
|
+
* const nodeId = tree.newLeaf(new Style());
|
|
1448
1817
|
* const layout: Layout = tree.unroundedLayout(nodeId);
|
|
1449
1818
|
* console.log(`Exact width: ${layout.width}`);
|
|
1450
1819
|
* ```
|
|
@@ -1465,6 +1834,7 @@ export class TaffyTree {
|
|
|
1465
1834
|
*
|
|
1466
1835
|
* @example
|
|
1467
1836
|
* ```typescript
|
|
1837
|
+
* const tree = new TaffyTree();
|
|
1468
1838
|
* const containerStyle = new Style();
|
|
1469
1839
|
* containerStyle.display = Display.Flex;
|
|
1470
1840
|
*
|
|
@@ -1490,10 +1860,28 @@ export class TaffyTree {
|
|
|
1490
1860
|
*
|
|
1491
1861
|
* @example
|
|
1492
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);
|
|
1493
1867
|
* const firstChild: bigint = tree.getChildAtIndex(parentId, 0);
|
|
1494
1868
|
* ```
|
|
1495
1869
|
*/
|
|
1496
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;
|
|
1497
1885
|
/**
|
|
1498
1886
|
* Gets a mutable reference to the context value for a node
|
|
1499
1887
|
*
|
|
@@ -1516,6 +1904,9 @@ export class TaffyTree {
|
|
|
1516
1904
|
*
|
|
1517
1905
|
* @example
|
|
1518
1906
|
* ```typescript
|
|
1907
|
+
* const tree = new TaffyTree();
|
|
1908
|
+
* const parentId = tree.newLeaf(new Style());
|
|
1909
|
+
* const childId = tree.newLeaf(new Style());
|
|
1519
1910
|
* tree.insertChildAtIndex(parentId, 0, childId);
|
|
1520
1911
|
* ```
|
|
1521
1912
|
*/
|
|
@@ -1536,6 +1927,7 @@ export class TaffyTree {
|
|
|
1536
1927
|
* ```typescript
|
|
1537
1928
|
* interface TextContext { text: string; isBold: boolean; }
|
|
1538
1929
|
*
|
|
1930
|
+
* const tree = new TaffyTree();
|
|
1539
1931
|
* const style = new Style();
|
|
1540
1932
|
* const context: TextContext = { text: "Hello, World!", isBold: true };
|
|
1541
1933
|
* const nodeId: bigint = tree.newLeafWithContext(style, context);
|
|
@@ -1554,6 +1946,10 @@ export class TaffyTree {
|
|
|
1554
1946
|
*
|
|
1555
1947
|
* @example
|
|
1556
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);
|
|
1557
1953
|
* const removedId: bigint = tree.removeChildAtIndex(parentId, 0);
|
|
1558
1954
|
* ```
|
|
1559
1955
|
*/
|
|
@@ -1564,23 +1960,30 @@ export class TaffyTree {
|
|
|
1564
1960
|
* Removes children from `start_index` (inclusive) to `end_index` (exclusive).
|
|
1565
1961
|
*
|
|
1566
1962
|
* @param parent - The parent node ID
|
|
1567
|
-
* @param
|
|
1568
|
-
* @param
|
|
1963
|
+
* @param startIndex - Start of range (inclusive)
|
|
1964
|
+
* @param endIndex - End of range (exclusive)
|
|
1569
1965
|
*
|
|
1570
1966
|
* @throws `TaffyError` if the parent node does not exist or range is invalid
|
|
1571
1967
|
*
|
|
1572
1968
|
* @example
|
|
1573
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
|
+
*
|
|
1574
1977
|
* tree.removeChildrenRange(parentId, 1, 3);
|
|
1575
1978
|
* ```
|
|
1576
1979
|
*/
|
|
1577
|
-
removeChildrenRange(parent: bigint,
|
|
1980
|
+
removeChildrenRange(parent: bigint, startIndex: number, endIndex: number): void;
|
|
1578
1981
|
/**
|
|
1579
1982
|
* Replaces a child at a specific index
|
|
1580
1983
|
*
|
|
1581
1984
|
* @param parent - The parent node ID
|
|
1582
1985
|
* @param index - The index of the child to replace (0-based)
|
|
1583
|
-
* @param
|
|
1986
|
+
* @param newChild - The new child node ID
|
|
1584
1987
|
*
|
|
1585
1988
|
* @returns - The replaced (old) child ID (`bigint`)
|
|
1586
1989
|
*
|
|
@@ -1588,10 +1991,18 @@ export class TaffyTree {
|
|
|
1588
1991
|
*
|
|
1589
1992
|
* @example
|
|
1590
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
|
+
*
|
|
1591
2002
|
* const oldChildId: bigint = tree.replaceChildAtIndex(parentId, 1, newChildId);
|
|
1592
2003
|
* ```
|
|
1593
2004
|
*/
|
|
1594
|
-
replaceChildAtIndex(parent: bigint, index: number,
|
|
2005
|
+
replaceChildAtIndex(parent: bigint, index: number, newChild: bigint): bigint;
|
|
1595
2006
|
/**
|
|
1596
2007
|
* Computes layout with a custom measure function for leaf nodes
|
|
1597
2008
|
*
|
|
@@ -1600,19 +2011,24 @@ export class TaffyTree {
|
|
|
1600
2011
|
* called for each leaf node that needs measurement.
|
|
1601
2012
|
*
|
|
1602
2013
|
* @param node - The root node ID to compute layout for
|
|
1603
|
-
* @param
|
|
1604
|
-
* @param
|
|
2014
|
+
* @param availableSpace - The available space constraints
|
|
2015
|
+
* @param measureFunc - A function that measures leaf node content
|
|
1605
2016
|
*
|
|
1606
2017
|
* @throws `TaffyError` if the node does not exist or available space is invalid
|
|
1607
2018
|
*
|
|
1608
2019
|
* @example
|
|
1609
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
|
+
*
|
|
1610
2026
|
* tree.computeLayoutWithMeasure(
|
|
1611
2027
|
* rootId,
|
|
1612
|
-
* { width: 800, height: "
|
|
2028
|
+
* { width: 800, height: "max-content" },
|
|
1613
2029
|
* (known, available, node, context, style) => {
|
|
1614
2030
|
* if (context?.text) {
|
|
1615
|
-
* const measured = measureText(context.text, available.width);
|
|
2031
|
+
* const measured = measureText(context.text, available.width as number);
|
|
1616
2032
|
* return { width: measured.width, height: measured.height };
|
|
1617
2033
|
* }
|
|
1618
2034
|
* return { width: 0, height: 0 };
|
|
@@ -1620,7 +2036,7 @@ export class TaffyTree {
|
|
|
1620
2036
|
* );
|
|
1621
2037
|
* ```
|
|
1622
2038
|
*/
|
|
1623
|
-
computeLayoutWithMeasure(node: bigint,
|
|
2039
|
+
computeLayoutWithMeasure(node: bigint, availableSpace: Size<AvailableSpace>, measureFunc: MeasureFunction): void;
|
|
1624
2040
|
/**
|
|
1625
2041
|
* Gets context values for multiple nodes at once
|
|
1626
2042
|
*
|
|
@@ -1633,6 +2049,9 @@ export class TaffyTree {
|
|
|
1633
2049
|
*
|
|
1634
2050
|
* @example
|
|
1635
2051
|
* ```typescript
|
|
2052
|
+
* const tree = new TaffyTree();
|
|
2053
|
+
* const id1 = tree.newLeaf(new Style());
|
|
2054
|
+
* const id2 = tree.newLeaf(new Style());
|
|
1636
2055
|
* const nodes = BigUint64Array.from([id1, id2]);
|
|
1637
2056
|
* const contexts = tree.getDisjointNodeContextMut(nodes);
|
|
1638
2057
|
* ```
|
|
@@ -1658,6 +2077,7 @@ export class TaffyTree {
|
|
|
1658
2077
|
*
|
|
1659
2078
|
* @example
|
|
1660
2079
|
* ```typescript
|
|
2080
|
+
* const tree = new TaffyTree();
|
|
1661
2081
|
* tree.clear();
|
|
1662
2082
|
* console.log(tree.totalNodeCount());
|
|
1663
2083
|
* ```
|
|
@@ -1677,6 +2097,11 @@ export class TaffyTree {
|
|
|
1677
2097
|
*
|
|
1678
2098
|
* @example
|
|
1679
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
|
+
*
|
|
1680
2105
|
* if (tree.dirty(nodeId)) {
|
|
1681
2106
|
* tree.computeLayout(rootId, availableSpace);
|
|
1682
2107
|
* }
|
|
@@ -1694,6 +2119,8 @@ export class TaffyTree {
|
|
|
1694
2119
|
*
|
|
1695
2120
|
* @example
|
|
1696
2121
|
* ```typescript
|
|
2122
|
+
* const tree = new TaffyTree();
|
|
2123
|
+
* const nodeId = tree.newLeaf(new Style());
|
|
1697
2124
|
* const style: Style = tree.getStyle(nodeId);
|
|
1698
2125
|
* console.log('Flex grow:', style.flexGrow);
|
|
1699
2126
|
* ```
|
|
@@ -1713,6 +2140,12 @@ export class TaffyTree {
|
|
|
1713
2140
|
*
|
|
1714
2141
|
* @example
|
|
1715
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
|
+
*
|
|
1716
2149
|
* tree.computeLayout(rootId, { width: 800, height: 600 });
|
|
1717
2150
|
* const layout: Layout = tree.getLayout(nodeId);
|
|
1718
2151
|
* console.log(`Position: (${layout.x}, ${layout.y}), Size: ${layout.width}x${layout.height}`);
|
|
@@ -1728,7 +2161,11 @@ export class TaffyTree {
|
|
|
1728
2161
|
*
|
|
1729
2162
|
* @example
|
|
1730
2163
|
* ```typescript
|
|
1731
|
-
* const
|
|
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);
|
|
1732
2169
|
* ```
|
|
1733
2170
|
*/
|
|
1734
2171
|
parent(child: bigint): bigint | undefined;
|
|
@@ -1746,6 +2183,8 @@ export class TaffyTree {
|
|
|
1746
2183
|
*
|
|
1747
2184
|
* @example
|
|
1748
2185
|
* ```typescript
|
|
2186
|
+
* const tree = new TaffyTree();
|
|
2187
|
+
* const nodeId = tree.newLeaf(new Style());
|
|
1749
2188
|
* try {
|
|
1750
2189
|
* const removedId: bigint = tree.remove(nodeId);
|
|
1751
2190
|
* } catch (e) {
|
|
@@ -1765,6 +2204,8 @@ export class TaffyTree {
|
|
|
1765
2204
|
*
|
|
1766
2205
|
* @example
|
|
1767
2206
|
* ```typescript
|
|
2207
|
+
* const tree = new TaffyTree();
|
|
2208
|
+
* const parentId = tree.newLeaf(new Style());
|
|
1768
2209
|
* const children: BigUint64Array = tree.children(parentId);
|
|
1769
2210
|
* ```
|
|
1770
2211
|
*/
|
|
@@ -1781,6 +2222,7 @@ export class TaffyTree {
|
|
|
1781
2222
|
*
|
|
1782
2223
|
* @example
|
|
1783
2224
|
* ```typescript
|
|
2225
|
+
* const tree = new TaffyTree();
|
|
1784
2226
|
* const style = new Style();
|
|
1785
2227
|
* style.size = { width: 100, height: 50 };
|
|
1786
2228
|
* const nodeId: bigint = tree.newLeaf(style);
|
|
@@ -1799,6 +2241,9 @@ export class TaffyTree {
|
|
|
1799
2241
|
*
|
|
1800
2242
|
* @example
|
|
1801
2243
|
* ```typescript
|
|
2244
|
+
* const tree = new TaffyTree();
|
|
2245
|
+
* const parentId = tree.newLeaf(new Style());
|
|
2246
|
+
* const childId = tree.newLeaf(new Style());
|
|
1802
2247
|
* tree.addChild(parentId, childId);
|
|
1803
2248
|
* ```
|
|
1804
2249
|
*/
|
|
@@ -1816,6 +2261,8 @@ export class TaffyTree {
|
|
|
1816
2261
|
*
|
|
1817
2262
|
* @example
|
|
1818
2263
|
* ```typescript
|
|
2264
|
+
* const tree = new TaffyTree();
|
|
2265
|
+
* const nodeId = tree.newLeaf(new Style());
|
|
1819
2266
|
* const newStyle = new Style();
|
|
1820
2267
|
* newStyle.flexGrow = 2;
|
|
1821
2268
|
* tree.setStyle(nodeId, newStyle);
|
|
@@ -1824,6 +2271,39 @@ export class TaffyTree {
|
|
|
1824
2271
|
setStyle(node: bigint, style: Style): void;
|
|
1825
2272
|
}
|
|
1826
2273
|
|
|
2274
|
+
/**
|
|
2275
|
+
* Text alignment enumeration (for block layout)
|
|
2276
|
+
*
|
|
2277
|
+
* Used by block layout to implement the legacy behaviour of `<center>` and
|
|
2278
|
+
* `<div align="left | right | center">`.
|
|
2279
|
+
*
|
|
2280
|
+
* @example
|
|
2281
|
+
* ```typescript
|
|
2282
|
+
* import { Style, TextAlign } from 'taffy-js';
|
|
2283
|
+
*
|
|
2284
|
+
* const style = new Style();
|
|
2285
|
+
* style.textAlign = TextAlign.LegacyCenter; // Center block children
|
|
2286
|
+
* ```
|
|
2287
|
+
*/
|
|
2288
|
+
export enum TextAlign {
|
|
2289
|
+
/**
|
|
2290
|
+
* No special legacy text align behaviour
|
|
2291
|
+
*/
|
|
2292
|
+
Auto = 0,
|
|
2293
|
+
/**
|
|
2294
|
+
* Corresponds to `-webkit-left` or `-moz-left` in browsers
|
|
2295
|
+
*/
|
|
2296
|
+
LegacyLeft = 1,
|
|
2297
|
+
/**
|
|
2298
|
+
* Corresponds to `-webkit-right` or `-moz-right` in browsers
|
|
2299
|
+
*/
|
|
2300
|
+
LegacyRight = 2,
|
|
2301
|
+
/**
|
|
2302
|
+
* Corresponds to `-webkit-center` or `-moz-center` in browsers
|
|
2303
|
+
*/
|
|
2304
|
+
LegacyCenter = 3,
|
|
2305
|
+
}
|
|
2306
|
+
|
|
1827
2307
|
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
1828
2308
|
|
|
1829
2309
|
export interface InitOutput {
|
|
@@ -1866,8 +2346,22 @@ export interface InitOutput {
|
|
|
1866
2346
|
readonly style_flexShrink: (a: number) => number;
|
|
1867
2347
|
readonly style_flexWrap: (a: number) => number;
|
|
1868
2348
|
readonly style_gap: (a: number) => any;
|
|
2349
|
+
readonly style_gridAutoColumns: (a: number) => any;
|
|
2350
|
+
readonly style_gridAutoFlow: (a: number) => number;
|
|
2351
|
+
readonly style_gridAutoRows: (a: number) => any;
|
|
2352
|
+
readonly style_gridColumn: (a: number) => any;
|
|
2353
|
+
readonly style_gridRow: (a: number) => any;
|
|
2354
|
+
readonly style_gridTemplateAreas: (a: number) => any;
|
|
2355
|
+
readonly style_gridTemplateColumnNames: (a: number) => any;
|
|
2356
|
+
readonly style_gridTemplateColumns: (a: number) => any;
|
|
2357
|
+
readonly style_gridTemplateRowNames: (a: number) => any;
|
|
2358
|
+
readonly style_gridTemplateRows: (a: number) => any;
|
|
1869
2359
|
readonly style_inset: (a: number) => any;
|
|
2360
|
+
readonly style_itemIsReplaced: (a: number) => number;
|
|
2361
|
+
readonly style_itemIsTable: (a: number) => number;
|
|
1870
2362
|
readonly style_justifyContent: (a: number) => number;
|
|
2363
|
+
readonly style_justifyItems: (a: number) => number;
|
|
2364
|
+
readonly style_justifySelf: (a: number) => number;
|
|
1871
2365
|
readonly style_margin: (a: number) => any;
|
|
1872
2366
|
readonly style_maxSize: (a: number) => any;
|
|
1873
2367
|
readonly style_minSize: (a: number) => any;
|
|
@@ -1875,6 +2369,7 @@ export interface InitOutput {
|
|
|
1875
2369
|
readonly style_overflow: (a: number) => any;
|
|
1876
2370
|
readonly style_padding: (a: number) => any;
|
|
1877
2371
|
readonly style_position: (a: number) => number;
|
|
2372
|
+
readonly style_scrollbarWidth: (a: number) => number;
|
|
1878
2373
|
readonly style_set_alignContent: (a: number, b: any) => void;
|
|
1879
2374
|
readonly style_set_alignItems: (a: number, b: any) => void;
|
|
1880
2375
|
readonly style_set_alignSelf: (a: number, b: any) => void;
|
|
@@ -1888,16 +2383,33 @@ export interface InitOutput {
|
|
|
1888
2383
|
readonly style_set_flexShrink: (a: number, b: number) => void;
|
|
1889
2384
|
readonly style_set_flexWrap: (a: number, b: number) => void;
|
|
1890
2385
|
readonly style_set_gap: (a: number, b: any) => void;
|
|
2386
|
+
readonly style_set_gridAutoColumns: (a: number, b: any) => void;
|
|
2387
|
+
readonly style_set_gridAutoFlow: (a: number, b: number) => void;
|
|
2388
|
+
readonly style_set_gridAutoRows: (a: number, b: any) => void;
|
|
2389
|
+
readonly style_set_gridColumn: (a: number, b: any) => void;
|
|
2390
|
+
readonly style_set_gridRow: (a: number, b: any) => void;
|
|
2391
|
+
readonly style_set_gridTemplateAreas: (a: number, b: any) => void;
|
|
2392
|
+
readonly style_set_gridTemplateColumnNames: (a: number, b: any) => void;
|
|
2393
|
+
readonly style_set_gridTemplateColumns: (a: number, b: any) => void;
|
|
2394
|
+
readonly style_set_gridTemplateRowNames: (a: number, b: any) => void;
|
|
2395
|
+
readonly style_set_gridTemplateRows: (a: number, b: any) => void;
|
|
1891
2396
|
readonly style_set_inset: (a: number, b: any) => void;
|
|
2397
|
+
readonly style_set_itemIsReplaced: (a: number, b: number) => void;
|
|
2398
|
+
readonly style_set_itemIsTable: (a: number, b: number) => void;
|
|
1892
2399
|
readonly style_set_justifyContent: (a: number, b: any) => void;
|
|
2400
|
+
readonly style_set_justifyItems: (a: number, b: any) => void;
|
|
2401
|
+
readonly style_set_justifySelf: (a: number, b: any) => void;
|
|
1893
2402
|
readonly style_set_margin: (a: number, b: any) => void;
|
|
1894
2403
|
readonly style_set_maxSize: (a: number, b: any) => void;
|
|
1895
2404
|
readonly style_set_minSize: (a: number, b: any) => void;
|
|
1896
2405
|
readonly style_set_overflow: (a: number, b: any) => void;
|
|
1897
2406
|
readonly style_set_padding: (a: number, b: any) => void;
|
|
1898
2407
|
readonly style_set_position: (a: number, b: number) => void;
|
|
2408
|
+
readonly style_set_scrollbarWidth: (a: number, b: number) => void;
|
|
1899
2409
|
readonly style_set_size: (a: number, b: any) => void;
|
|
2410
|
+
readonly style_set_textAlign: (a: number, b: number) => void;
|
|
1900
2411
|
readonly style_size: (a: number) => any;
|
|
2412
|
+
readonly style_textAlign: (a: number) => number;
|
|
1901
2413
|
readonly taffyerror_message: (a: number) => [number, number];
|
|
1902
2414
|
readonly taffytree_addChild: (a: number, b: bigint, c: bigint) => [number, number];
|
|
1903
2415
|
readonly taffytree_childCount: (a: number, b: bigint) => number;
|
|
@@ -1905,6 +2417,7 @@ export interface InitOutput {
|
|
|
1905
2417
|
readonly taffytree_clear: (a: number) => void;
|
|
1906
2418
|
readonly taffytree_computeLayout: (a: number, b: bigint, c: any) => [number, number];
|
|
1907
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];
|
|
1908
2421
|
readonly taffytree_dirty: (a: number, b: bigint) => [number, number, number];
|
|
1909
2422
|
readonly taffytree_disableRounding: (a: number) => void;
|
|
1910
2423
|
readonly taffytree_enableRounding: (a: number) => void;
|