taffy-js 0.2.1 → 0.2.3

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 CHANGED
@@ -229,6 +229,7 @@ const style = new Style();
229
229
  | `min_size` | `{ width, height }` | Minimum size constraints |
230
230
  | `max_size` | `{ width, height }` | Maximum size constraints |
231
231
  | `aspect_ratio` | `number?` | Width-to-height ratio |
232
+ | `box_sizing` | `BoxSizing` | Size calculation mode |
232
233
 
233
234
  #### Spacing
234
235
 
@@ -416,6 +417,13 @@ Overflow.Scroll; // Always show scrollbars
416
417
  Overflow.Auto; // Show scrollbars when needed
417
418
  ```
418
419
 
420
+ #### BoxSizing
421
+
422
+ ```typescript
423
+ BoxSizing.BorderBox; // Include padding/border in size (default)
424
+ BoxSizing.ContentBox; // Size is content only
425
+ ```
426
+
419
427
  ---
420
428
 
421
429
  ## 📏 Custom Measurement
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "ByteLandTechnology <github@byteland.app>"
6
6
  ],
7
7
  "description": "WebAssembly bindings for Taffy layout library",
8
- "version": "0.2.1",
8
+ "version": "0.2.3",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",
package/taffy_js.d.ts CHANGED
@@ -66,6 +66,20 @@ export enum AlignSelf {
66
66
  Stretch = 7,
67
67
  }
68
68
 
69
+ /**
70
+ * Box sizing enum
71
+ *
72
+ * 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
77
+ */
78
+ export enum BoxSizing {
79
+ BorderBox = 0,
80
+ ContentBox = 1,
81
+ }
82
+
69
83
  /**
70
84
  * Display mode enum
71
85
  *
@@ -144,6 +158,96 @@ export enum JustifyContent {
144
158
  SpaceEvenly = 8,
145
159
  }
146
160
 
161
+ export class Layout {
162
+ private constructor();
163
+ free(): void;
164
+ [Symbol.dispose](): void;
165
+ /**
166
+ * Gets the top border width.
167
+ */
168
+ readonly borderTop: number;
169
+ /**
170
+ * Gets the top margin.
171
+ */
172
+ readonly marginTop: number;
173
+ /**
174
+ * Gets the left border width.
175
+ */
176
+ readonly borderLeft: number;
177
+ /**
178
+ * Gets the left margin.
179
+ */
180
+ readonly marginLeft: number;
181
+ /**
182
+ * Gets the top padding.
183
+ */
184
+ readonly paddingTop: number;
185
+ /**
186
+ * Gets the right border width.
187
+ */
188
+ readonly borderRight: number;
189
+ /**
190
+ * Gets the right margin.
191
+ */
192
+ readonly marginRight: number;
193
+ /**
194
+ * Gets the left padding.
195
+ */
196
+ readonly paddingLeft: number;
197
+ /**
198
+ * Gets the bottom border width.
199
+ */
200
+ readonly borderBottom: number;
201
+ /**
202
+ * Gets the width of the scrollable content.
203
+ */
204
+ readonly contentWidth: number;
205
+ /**
206
+ * Gets the bottom margin.
207
+ */
208
+ readonly marginBottom: number;
209
+ /**
210
+ * Gets the right padding.
211
+ */
212
+ readonly paddingRight: number;
213
+ /**
214
+ * Gets the height of the scrollable content.
215
+ */
216
+ readonly contentHeight: number;
217
+ /**
218
+ * Gets the bottom padding.
219
+ */
220
+ readonly paddingBottom: number;
221
+ /**
222
+ * Gets the width of the vertical scrollbar.
223
+ */
224
+ readonly scrollbarWidth: number;
225
+ /**
226
+ * Gets the height of the horizontal scrollbar.
227
+ */
228
+ readonly scrollbarHeight: number;
229
+ /**
230
+ * Gets the x coordinate of the node's top-left corner.
231
+ */
232
+ readonly x: number;
233
+ /**
234
+ * Gets the y coordinate of the node's top-left corner.
235
+ */
236
+ readonly y: number;
237
+ /**
238
+ * Gets the rendering order of the node.
239
+ */
240
+ readonly order: number;
241
+ /**
242
+ * Gets the computed width of the node.
243
+ */
244
+ readonly width: number;
245
+ /**
246
+ * Gets the computed height of the node.
247
+ */
248
+ readonly height: number;
249
+ }
250
+
147
251
  /**
148
252
  * Overflow handling enum
149
253
  *
@@ -209,6 +313,10 @@ export class Style {
209
313
  * Sets the align-self property. Use AlignSelf.Auto to inherit from parent.
210
314
  */
211
315
  set align_self(value: AlignSelf | null | undefined);
316
+ /**
317
+ * Gets the box sizing mode (BorderBox or ContentBox).
318
+ */
319
+ box_sizing: BoxSizing;
212
320
  /**
213
321
  * Gets the flex-basis as a JsDimension (Length, Percent, or Auto).
214
322
  * Flex-basis defines the initial main size before grow/shrink.
@@ -469,9 +577,9 @@ export class TaffyTree {
469
577
  * * `node` - The node ID to query.
470
578
  *
471
579
  * # Returns
472
- * A layout object with potentially fractional values.
580
+ * A `Layout` object with potentially fractional pixel values.
473
581
  */
474
- unroundedLayout(node: bigint): any;
582
+ unroundedLayout(node: bigint): Layout;
475
583
  /**
476
584
  * Creates a new node with the given children.
477
585
  *
@@ -636,9 +744,9 @@ export class TaffyTree {
636
744
  * * `node` - The node ID to query.
637
745
  *
638
746
  * # Returns
639
- * A layout object: `{ order, size: {width, height}, location: {x, y}, ... }`
747
+ * A `Layout` object with computed position, size, and spacing values.
640
748
  */
641
- getLayout(node: bigint): any;
749
+ getLayout(node: bigint): Layout;
642
750
  /**
643
751
  * Gets the parent of a node.
644
752
  *
@@ -713,13 +821,36 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
713
821
 
714
822
  export interface InitOutput {
715
823
  readonly memory: WebAssembly.Memory;
824
+ readonly __wbg_layout_free: (a: number, b: number) => void;
716
825
  readonly __wbg_style_free: (a: number, b: number) => void;
717
826
  readonly __wbg_taffytree_free: (a: number, b: number) => void;
827
+ readonly layout_borderBottom: (a: number) => number;
828
+ readonly layout_borderLeft: (a: number) => number;
829
+ readonly layout_borderRight: (a: number) => number;
830
+ readonly layout_borderTop: (a: number) => number;
831
+ readonly layout_contentHeight: (a: number) => number;
832
+ readonly layout_contentWidth: (a: number) => number;
833
+ readonly layout_height: (a: number) => number;
834
+ readonly layout_marginBottom: (a: number) => number;
835
+ readonly layout_marginLeft: (a: number) => number;
836
+ readonly layout_marginRight: (a: number) => number;
837
+ readonly layout_marginTop: (a: number) => number;
838
+ readonly layout_order: (a: number) => number;
839
+ readonly layout_paddingBottom: (a: number) => number;
840
+ readonly layout_paddingLeft: (a: number) => number;
841
+ readonly layout_paddingRight: (a: number) => number;
842
+ readonly layout_paddingTop: (a: number) => number;
843
+ readonly layout_scrollbarHeight: (a: number) => number;
844
+ readonly layout_scrollbarWidth: (a: number) => number;
845
+ readonly layout_width: (a: number) => number;
846
+ readonly layout_x: (a: number) => number;
847
+ readonly layout_y: (a: number) => number;
718
848
  readonly style_align_content: (a: number) => number;
719
849
  readonly style_align_items: (a: number) => number;
720
850
  readonly style_align_self: (a: number) => number;
721
851
  readonly style_aspect_ratio: (a: number) => number;
722
852
  readonly style_border: (a: number) => any;
853
+ readonly style_box_sizing: (a: number) => number;
723
854
  readonly style_display: (a: number) => number;
724
855
  readonly style_flex_basis: (a: number) => any;
725
856
  readonly style_flex_direction: (a: number) => number;
@@ -741,6 +872,7 @@ export interface InitOutput {
741
872
  readonly style_set_align_self: (a: number, b: number) => void;
742
873
  readonly style_set_aspect_ratio: (a: number, b: number) => void;
743
874
  readonly style_set_border: (a: number, b: any) => void;
875
+ readonly style_set_box_sizing: (a: number, b: number) => void;
744
876
  readonly style_set_display: (a: number, b: number) => void;
745
877
  readonly style_set_flex_basis: (a: number, b: any) => void;
746
878
  readonly style_set_flex_direction: (a: number, b: number) => void;
package/taffy_js.js CHANGED
@@ -219,6 +219,10 @@ if (!('encodeInto' in cachedTextEncoder)) {
219
219
 
220
220
  let WASM_VECTOR_LEN = 0;
221
221
 
222
+ const LayoutFinalization = (typeof FinalizationRegistry === 'undefined')
223
+ ? { register: () => {}, unregister: () => {} }
224
+ : new FinalizationRegistry(ptr => wasm.__wbg_layout_free(ptr >>> 0, 1));
225
+
222
226
  const StyleFinalization = (typeof FinalizationRegistry === 'undefined')
223
227
  ? { register: () => {}, unregister: () => {} }
224
228
  : new FinalizationRegistry(ptr => wasm.__wbg_style_free(ptr >>> 0, 1));
@@ -295,6 +299,21 @@ export const AlignSelf = Object.freeze({
295
299
  Stretch: 7, "7": "Stretch",
296
300
  });
297
301
 
302
+ /**
303
+ * Box sizing enum
304
+ *
305
+ * Controls how the total width and height of an element is calculated.
306
+ *
307
+ * # Variants
308
+ * - `BorderBox`: Width and height include content, padding, and border (default)
309
+ * - `ContentBox`: Width and height include only the content
310
+ * @enum {0 | 1}
311
+ */
312
+ export const BoxSizing = Object.freeze({
313
+ BorderBox: 0, "0": "BorderBox",
314
+ ContentBox: 1, "1": "ContentBox",
315
+ });
316
+
298
317
  /**
299
318
  * Display mode enum
300
319
  *
@@ -377,6 +396,212 @@ export const JustifyContent = Object.freeze({
377
396
  SpaceEvenly: 8, "8": "SpaceEvenly",
378
397
  });
379
398
 
399
+ /**
400
+ * Layout result struct
401
+ *
402
+ * A wrapper around `taffy::Layout` that provides WASM bindings.
403
+ * Contains the computed layout values for a node after calling `computeLayout()`.
404
+ * All values are in pixels.
405
+ *
406
+ * # Properties
407
+ * - `order`: Rendering order (higher = on top)
408
+ * - `x`, `y`: Position of top-left corner relative to parent
409
+ * - `width`, `height`: Computed dimensions
410
+ * - `contentWidth`, `contentHeight`: Size of scrollable content
411
+ * - `scrollbarWidth`, `scrollbarHeight`: Size allocated for scrollbars
412
+ * - `borderLeft`, `borderRight`, `borderTop`, `borderBottom`: Border widths
413
+ * - `paddingLeft`, `paddingRight`, `paddingTop`, `paddingBottom`: Padding sizes
414
+ * - `marginLeft`, `marginRight`, `marginTop`, `marginBottom`: Margin sizes
415
+ */
416
+ export class Layout {
417
+ static __wrap(ptr) {
418
+ ptr = ptr >>> 0;
419
+ const obj = Object.create(Layout.prototype);
420
+ obj.__wbg_ptr = ptr;
421
+ LayoutFinalization.register(obj, obj.__wbg_ptr, obj);
422
+ return obj;
423
+ }
424
+ __destroy_into_raw() {
425
+ const ptr = this.__wbg_ptr;
426
+ this.__wbg_ptr = 0;
427
+ LayoutFinalization.unregister(this);
428
+ return ptr;
429
+ }
430
+ free() {
431
+ const ptr = this.__destroy_into_raw();
432
+ wasm.__wbg_layout_free(ptr, 0);
433
+ }
434
+ /**
435
+ * Gets the top border width.
436
+ * @returns {number}
437
+ */
438
+ get borderTop() {
439
+ const ret = wasm.layout_borderTop(this.__wbg_ptr);
440
+ return ret;
441
+ }
442
+ /**
443
+ * Gets the top margin.
444
+ * @returns {number}
445
+ */
446
+ get marginTop() {
447
+ const ret = wasm.layout_marginTop(this.__wbg_ptr);
448
+ return ret;
449
+ }
450
+ /**
451
+ * Gets the left border width.
452
+ * @returns {number}
453
+ */
454
+ get borderLeft() {
455
+ const ret = wasm.layout_borderLeft(this.__wbg_ptr);
456
+ return ret;
457
+ }
458
+ /**
459
+ * Gets the left margin.
460
+ * @returns {number}
461
+ */
462
+ get marginLeft() {
463
+ const ret = wasm.layout_marginLeft(this.__wbg_ptr);
464
+ return ret;
465
+ }
466
+ /**
467
+ * Gets the top padding.
468
+ * @returns {number}
469
+ */
470
+ get paddingTop() {
471
+ const ret = wasm.layout_paddingTop(this.__wbg_ptr);
472
+ return ret;
473
+ }
474
+ /**
475
+ * Gets the right border width.
476
+ * @returns {number}
477
+ */
478
+ get borderRight() {
479
+ const ret = wasm.layout_borderRight(this.__wbg_ptr);
480
+ return ret;
481
+ }
482
+ /**
483
+ * Gets the right margin.
484
+ * @returns {number}
485
+ */
486
+ get marginRight() {
487
+ const ret = wasm.layout_marginRight(this.__wbg_ptr);
488
+ return ret;
489
+ }
490
+ /**
491
+ * Gets the left padding.
492
+ * @returns {number}
493
+ */
494
+ get paddingLeft() {
495
+ const ret = wasm.layout_paddingLeft(this.__wbg_ptr);
496
+ return ret;
497
+ }
498
+ /**
499
+ * Gets the bottom border width.
500
+ * @returns {number}
501
+ */
502
+ get borderBottom() {
503
+ const ret = wasm.layout_borderBottom(this.__wbg_ptr);
504
+ return ret;
505
+ }
506
+ /**
507
+ * Gets the width of the scrollable content.
508
+ * @returns {number}
509
+ */
510
+ get contentWidth() {
511
+ const ret = wasm.layout_contentWidth(this.__wbg_ptr);
512
+ return ret;
513
+ }
514
+ /**
515
+ * Gets the bottom margin.
516
+ * @returns {number}
517
+ */
518
+ get marginBottom() {
519
+ const ret = wasm.layout_marginBottom(this.__wbg_ptr);
520
+ return ret;
521
+ }
522
+ /**
523
+ * Gets the right padding.
524
+ * @returns {number}
525
+ */
526
+ get paddingRight() {
527
+ const ret = wasm.layout_paddingRight(this.__wbg_ptr);
528
+ return ret;
529
+ }
530
+ /**
531
+ * Gets the height of the scrollable content.
532
+ * @returns {number}
533
+ */
534
+ get contentHeight() {
535
+ const ret = wasm.layout_contentHeight(this.__wbg_ptr);
536
+ return ret;
537
+ }
538
+ /**
539
+ * Gets the bottom padding.
540
+ * @returns {number}
541
+ */
542
+ get paddingBottom() {
543
+ const ret = wasm.layout_paddingBottom(this.__wbg_ptr);
544
+ return ret;
545
+ }
546
+ /**
547
+ * Gets the width of the vertical scrollbar.
548
+ * @returns {number}
549
+ */
550
+ get scrollbarWidth() {
551
+ const ret = wasm.layout_scrollbarWidth(this.__wbg_ptr);
552
+ return ret;
553
+ }
554
+ /**
555
+ * Gets the height of the horizontal scrollbar.
556
+ * @returns {number}
557
+ */
558
+ get scrollbarHeight() {
559
+ const ret = wasm.layout_scrollbarHeight(this.__wbg_ptr);
560
+ return ret;
561
+ }
562
+ /**
563
+ * Gets the x coordinate of the node's top-left corner.
564
+ * @returns {number}
565
+ */
566
+ get x() {
567
+ const ret = wasm.layout_x(this.__wbg_ptr);
568
+ return ret;
569
+ }
570
+ /**
571
+ * Gets the y coordinate of the node's top-left corner.
572
+ * @returns {number}
573
+ */
574
+ get y() {
575
+ const ret = wasm.layout_y(this.__wbg_ptr);
576
+ return ret;
577
+ }
578
+ /**
579
+ * Gets the rendering order of the node.
580
+ * @returns {number}
581
+ */
582
+ get order() {
583
+ const ret = wasm.layout_order(this.__wbg_ptr);
584
+ return ret >>> 0;
585
+ }
586
+ /**
587
+ * Gets the computed width of the node.
588
+ * @returns {number}
589
+ */
590
+ get width() {
591
+ const ret = wasm.layout_width(this.__wbg_ptr);
592
+ return ret;
593
+ }
594
+ /**
595
+ * Gets the computed height of the node.
596
+ * @returns {number}
597
+ */
598
+ get height() {
599
+ const ret = wasm.layout_height(this.__wbg_ptr);
600
+ return ret;
601
+ }
602
+ }
603
+ if (Symbol.dispose) Layout.prototype[Symbol.dispose] = Layout.prototype.free;
604
+
380
605
  /**
381
606
  * Overflow handling enum
382
607
  *
@@ -471,6 +696,14 @@ export class Style {
471
696
  const ret = wasm.style_align_self(this.__wbg_ptr);
472
697
  return ret === 8 ? undefined : ret;
473
698
  }
699
+ /**
700
+ * Gets the box sizing mode (BorderBox or ContentBox).
701
+ * @returns {BoxSizing}
702
+ */
703
+ get box_sizing() {
704
+ const ret = wasm.style_box_sizing(this.__wbg_ptr);
705
+ return ret;
706
+ }
474
707
  /**
475
708
  * Gets the flex-basis as a JsDimension (Length, Percent, or Auto).
476
709
  * Flex-basis defines the initial main size before grow/shrink.
@@ -607,6 +840,15 @@ export class Style {
607
840
  set align_self(val) {
608
841
  wasm.style_set_align_self(this.__wbg_ptr, isLikeNone(val) ? 8 : val);
609
842
  }
843
+ /**
844
+ * Sets the box sizing mode.
845
+ * - `BoxSizing.BorderBox`: Width and height include content, padding, and border (default)
846
+ * - `BoxSizing.ContentBox`: Width and height include only the content
847
+ * @param {BoxSizing} val
848
+ */
849
+ set box_sizing(val) {
850
+ wasm.style_set_box_sizing(this.__wbg_ptr, val);
851
+ }
610
852
  /**
611
853
  * Sets the flex-basis. Accepts { Length: number } | { Percent: number } | "Auto".
612
854
  * @param {any} val
@@ -1097,16 +1339,16 @@ export class TaffyTree {
1097
1339
  * * `node` - The node ID to query.
1098
1340
  *
1099
1341
  * # Returns
1100
- * A layout object with potentially fractional values.
1342
+ * A `Layout` object with potentially fractional pixel values.
1101
1343
  * @param {bigint} node
1102
- * @returns {any}
1344
+ * @returns {Layout}
1103
1345
  */
1104
1346
  unroundedLayout(node) {
1105
1347
  const ret = wasm.taffytree_unroundedLayout(this.__wbg_ptr, node);
1106
1348
  if (ret[2]) {
1107
1349
  throw takeFromExternrefTable0(ret[1]);
1108
1350
  }
1109
- return takeFromExternrefTable0(ret[0]);
1351
+ return Layout.__wrap(ret[0]);
1110
1352
  }
1111
1353
  /**
1112
1354
  * Creates a new node with the given children.
@@ -1380,16 +1622,16 @@ export class TaffyTree {
1380
1622
  * * `node` - The node ID to query.
1381
1623
  *
1382
1624
  * # Returns
1383
- * A layout object: `{ order, size: {width, height}, location: {x, y}, ... }`
1625
+ * A `Layout` object with computed position, size, and spacing values.
1384
1626
  * @param {bigint} node
1385
- * @returns {any}
1627
+ * @returns {Layout}
1386
1628
  */
1387
1629
  getLayout(node) {
1388
1630
  const ret = wasm.taffytree_getLayout(this.__wbg_ptr, node);
1389
1631
  if (ret[2]) {
1390
1632
  throw takeFromExternrefTable0(ret[1]);
1391
1633
  }
1392
- return takeFromExternrefTable0(ret[0]);
1634
+ return Layout.__wrap(ret[0]);
1393
1635
  }
1394
1636
  /**
1395
1637
  * Gets the parent of a node.
@@ -1664,7 +1906,7 @@ function __wbg_get_imports() {
1664
1906
  const ret = arg0.length;
1665
1907
  return ret;
1666
1908
  };
1667
- imports.wbg.__wbg_log_730ba2e365bddb50 = function(arg0, arg1) {
1909
+ imports.wbg.__wbg_log_b0b3f53073d3e573 = function(arg0, arg1) {
1668
1910
  console.log(getStringFromWasm0(arg0, arg1));
1669
1911
  };
1670
1912
  imports.wbg.__wbg_new_1ba21ce319a06297 = function() {
package/taffy_js_bg.wasm CHANGED
Binary file