flexily 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/README.md +2 -0
  2. package/package.json +16 -24
  3. package/src/classic/layout.ts +2 -2
  4. package/src/layout-helpers.ts +2 -2
  5. package/dist/classic/layout.d.ts +0 -57
  6. package/dist/classic/layout.d.ts.map +0 -1
  7. package/dist/classic/layout.js +0 -1567
  8. package/dist/classic/layout.js.map +0 -1
  9. package/dist/classic/node.d.ts +0 -648
  10. package/dist/classic/node.d.ts.map +0 -1
  11. package/dist/classic/node.js +0 -1002
  12. package/dist/classic/node.js.map +0 -1
  13. package/dist/constants.d.ts +0 -59
  14. package/dist/constants.d.ts.map +0 -1
  15. package/dist/constants.js +0 -71
  16. package/dist/constants.js.map +0 -1
  17. package/dist/index-classic.d.ts +0 -30
  18. package/dist/index-classic.d.ts.map +0 -1
  19. package/dist/index-classic.js +0 -57
  20. package/dist/index-classic.js.map +0 -1
  21. package/dist/index.d.ts +0 -30
  22. package/dist/index.d.ts.map +0 -1
  23. package/dist/index.js +0 -57
  24. package/dist/index.js.map +0 -1
  25. package/dist/layout-flex-lines.d.ts +0 -77
  26. package/dist/layout-flex-lines.d.ts.map +0 -1
  27. package/dist/layout-flex-lines.js +0 -317
  28. package/dist/layout-flex-lines.js.map +0 -1
  29. package/dist/layout-helpers.d.ts +0 -45
  30. package/dist/layout-helpers.d.ts.map +0 -1
  31. package/dist/layout-helpers.js +0 -103
  32. package/dist/layout-helpers.js.map +0 -1
  33. package/dist/layout-measure.d.ts +0 -25
  34. package/dist/layout-measure.d.ts.map +0 -1
  35. package/dist/layout-measure.js +0 -231
  36. package/dist/layout-measure.js.map +0 -1
  37. package/dist/layout-stats.d.ts +0 -19
  38. package/dist/layout-stats.d.ts.map +0 -1
  39. package/dist/layout-stats.js +0 -37
  40. package/dist/layout-stats.js.map +0 -1
  41. package/dist/layout-traversal.d.ts +0 -28
  42. package/dist/layout-traversal.d.ts.map +0 -1
  43. package/dist/layout-traversal.js +0 -65
  44. package/dist/layout-traversal.js.map +0 -1
  45. package/dist/layout-zero.d.ts +0 -26
  46. package/dist/layout-zero.d.ts.map +0 -1
  47. package/dist/layout-zero.js +0 -1757
  48. package/dist/layout-zero.js.map +0 -1
  49. package/dist/logger.d.ts +0 -14
  50. package/dist/logger.d.ts.map +0 -1
  51. package/dist/logger.js +0 -61
  52. package/dist/logger.js.map +0 -1
  53. package/dist/node-zero.d.ts +0 -702
  54. package/dist/node-zero.d.ts.map +0 -1
  55. package/dist/node-zero.js +0 -1268
  56. package/dist/node-zero.js.map +0 -1
  57. package/dist/testing.d.ts +0 -69
  58. package/dist/testing.d.ts.map +0 -1
  59. package/dist/testing.js +0 -179
  60. package/dist/testing.js.map +0 -1
  61. package/dist/trace.d.ts +0 -74
  62. package/dist/trace.d.ts.map +0 -1
  63. package/dist/trace.js +0 -191
  64. package/dist/trace.js.map +0 -1
  65. package/dist/types.d.ts +0 -170
  66. package/dist/types.d.ts.map +0 -1
  67. package/dist/types.js +0 -43
  68. package/dist/types.js.map +0 -1
  69. package/dist/utils.d.ts +0 -49
  70. package/dist/utils.d.ts.map +0 -1
  71. package/dist/utils.js +0 -222
  72. package/dist/utils.js.map +0 -1
  73. package/src/beorn-logger.d.ts +0 -10
@@ -1,1002 +0,0 @@
1
- /**
2
- * Flexily Node
3
- *
4
- * Yoga-compatible Node class for flexbox layout.
5
- */
6
- import * as C from "../constants.js";
7
- import { computeLayout, countNodes, markSubtreeLayoutSeen } from "./layout.js";
8
- import { createDefaultStyle, } from "../types.js";
9
- import { setEdgeValue, setEdgeBorder, getEdgeValue, getEdgeBorderValue } from "../utils.js";
10
- import { log } from "../logger.js";
11
- /**
12
- * A layout node in the flexbox tree.
13
- */
14
- export class Node {
15
- // Tree structure
16
- _parent = null;
17
- _children = [];
18
- // Style
19
- _style = createDefaultStyle();
20
- // Measure function for intrinsic sizing
21
- _measureFunc = null;
22
- // Baseline function for baseline alignment
23
- _baselineFunc = null;
24
- // Computed layout
25
- _layout = { left: 0, top: 0, width: 0, height: 0 };
26
- // Dirty flags
27
- _isDirty = true;
28
- _hasNewLayout = false;
29
- // ============================================================================
30
- // Static Factory
31
- // ============================================================================
32
- /**
33
- * Create a new layout node.
34
- *
35
- * @returns A new Node instance
36
- * @example
37
- * ```typescript
38
- * const root = Node.create();
39
- * root.setWidth(100);
40
- * root.setHeight(200);
41
- * ```
42
- */
43
- static create() {
44
- return new Node();
45
- }
46
- // ============================================================================
47
- // Tree Operations
48
- // ============================================================================
49
- /**
50
- * Get the number of child nodes.
51
- *
52
- * @returns The number of children
53
- */
54
- getChildCount() {
55
- return this._children.length;
56
- }
57
- /**
58
- * Get a child node by index.
59
- *
60
- * @param index - Zero-based child index
61
- * @returns The child node at the given index, or undefined if index is out of bounds
62
- */
63
- getChild(index) {
64
- return this._children[index];
65
- }
66
- /**
67
- * Get the parent node.
68
- *
69
- * @returns The parent node, or null if this is a root node
70
- */
71
- getParent() {
72
- return this._parent;
73
- }
74
- /**
75
- * Insert a child node at the specified index.
76
- * If the child already has a parent, it will be removed from that parent first.
77
- * Marks the node as dirty to trigger layout recalculation.
78
- *
79
- * @param child - The child node to insert
80
- * @param index - The index at which to insert the child
81
- * @example
82
- * ```typescript
83
- * const parent = Node.create();
84
- * const child1 = Node.create();
85
- * const child2 = Node.create();
86
- * parent.insertChild(child1, 0);
87
- * parent.insertChild(child2, 1);
88
- * ```
89
- */
90
- insertChild(child, index) {
91
- if (child._parent !== null) {
92
- child._parent.removeChild(child);
93
- }
94
- child._parent = this;
95
- this._children.splice(index, 0, child);
96
- this.markDirty();
97
- }
98
- /**
99
- * Remove a child node from this node.
100
- * The child's parent reference will be cleared.
101
- * Marks the node as dirty to trigger layout recalculation.
102
- *
103
- * @param child - The child node to remove
104
- */
105
- removeChild(child) {
106
- const index = this._children.indexOf(child);
107
- if (index !== -1) {
108
- this._children.splice(index, 1);
109
- child._parent = null;
110
- this.markDirty();
111
- }
112
- }
113
- /**
114
- * Free this node and clean up all references.
115
- * Removes the node from its parent, clears all children, and removes the measure function.
116
- * This does not recursively free child nodes.
117
- */
118
- free() {
119
- // Remove from parent
120
- if (this._parent !== null) {
121
- this._parent.removeChild(this);
122
- }
123
- // Clear children
124
- for (const child of this._children) {
125
- child._parent = null;
126
- }
127
- this._children = [];
128
- this._measureFunc = null;
129
- this._baselineFunc = null;
130
- }
131
- /**
132
- * Dispose the node (calls free)
133
- */
134
- [Symbol.dispose]() {
135
- this.free();
136
- }
137
- // ============================================================================
138
- // Measure Function
139
- // ============================================================================
140
- /**
141
- * Set a measure function for intrinsic sizing.
142
- * The measure function is called during layout to determine the node's natural size.
143
- * Typically used for text nodes or other content that has an intrinsic size.
144
- * Marks the node as dirty to trigger layout recalculation.
145
- *
146
- * @param measureFunc - Function that returns width and height given available space and constraints
147
- * @example
148
- * ```typescript
149
- * const textNode = Node.create();
150
- * textNode.setMeasureFunc((width, widthMode, height, heightMode) => {
151
- * // Measure text and return dimensions
152
- * return { width: 50, height: 20 };
153
- * });
154
- * ```
155
- */
156
- setMeasureFunc(measureFunc) {
157
- this._measureFunc = measureFunc;
158
- this.markDirty();
159
- }
160
- /**
161
- * Remove the measure function from this node.
162
- * Marks the node as dirty to trigger layout recalculation.
163
- */
164
- unsetMeasureFunc() {
165
- this._measureFunc = null;
166
- this.markDirty();
167
- }
168
- /**
169
- * Check if this node has a measure function.
170
- *
171
- * @returns True if a measure function is set
172
- */
173
- hasMeasureFunc() {
174
- return this._measureFunc !== null;
175
- }
176
- // ============================================================================
177
- // Baseline Function
178
- // ============================================================================
179
- /**
180
- * Set a baseline function to determine where this node's text baseline is.
181
- * Used for ALIGN_BASELINE to align text across siblings with different heights.
182
- *
183
- * @param baselineFunc - Function that returns baseline offset from top given width and height
184
- * @example
185
- * ```typescript
186
- * textNode.setBaselineFunc((width, height) => {
187
- * // For a text node, baseline might be at 80% of height
188
- * return height * 0.8;
189
- * });
190
- * ```
191
- */
192
- setBaselineFunc(baselineFunc) {
193
- this._baselineFunc = baselineFunc;
194
- this.markDirty();
195
- }
196
- /**
197
- * Remove the baseline function from this node.
198
- * Marks the node as dirty to trigger layout recalculation.
199
- */
200
- unsetBaselineFunc() {
201
- this._baselineFunc = null;
202
- this.markDirty();
203
- }
204
- /**
205
- * Check if this node has a baseline function.
206
- *
207
- * @returns True if a baseline function is set
208
- */
209
- hasBaselineFunc() {
210
- return this._baselineFunc !== null;
211
- }
212
- // ============================================================================
213
- // Dirty Tracking
214
- // ============================================================================
215
- /**
216
- * Check if this node needs layout recalculation.
217
- *
218
- * @returns True if the node is dirty and needs layout
219
- */
220
- isDirty() {
221
- return this._isDirty;
222
- }
223
- /**
224
- * Mark this node and all ancestors as dirty.
225
- * A dirty node needs layout recalculation.
226
- * This is automatically called by all style setters and tree operations.
227
- */
228
- markDirty() {
229
- this._isDirty = true;
230
- if (this._parent !== null) {
231
- this._parent.markDirty();
232
- }
233
- }
234
- /**
235
- * Check if this node has new layout results since the last check.
236
- *
237
- * @returns True if layout was recalculated since the last call to markLayoutSeen
238
- */
239
- hasNewLayout() {
240
- return this._hasNewLayout;
241
- }
242
- /**
243
- * Mark that the current layout has been seen/processed.
244
- * Clears the hasNewLayout flag.
245
- */
246
- markLayoutSeen() {
247
- this._hasNewLayout = false;
248
- }
249
- // ============================================================================
250
- // Layout Calculation
251
- // ============================================================================
252
- /**
253
- * Calculate layout for this node and all descendants.
254
- * This runs the flexbox layout algorithm to compute positions and sizes.
255
- * Only recalculates if the node is marked as dirty.
256
- *
257
- * @param width - Available width for layout
258
- * @param height - Available height for layout
259
- * @param _direction - Text direction (LTR or RTL), defaults to LTR
260
- * @example
261
- * ```typescript
262
- * const root = Node.create();
263
- * root.setFlexDirection(FLEX_DIRECTION_ROW);
264
- * root.setWidth(100);
265
- * root.setHeight(50);
266
- *
267
- * const child = Node.create();
268
- * child.setFlexGrow(1);
269
- * root.insertChild(child, 0);
270
- *
271
- * root.calculateLayout(100, 50, DIRECTION_LTR);
272
- *
273
- * // Now you can read computed layout
274
- * console.log(child.getComputedWidth());
275
- * ```
276
- */
277
- calculateLayout(width, height, _direction = C.DIRECTION_LTR) {
278
- if (!this._isDirty) {
279
- log.debug?.("layout skip (not dirty)");
280
- return;
281
- }
282
- const start = Date.now();
283
- const nodeCount = countNodes(this);
284
- // Treat undefined as unconstrained (NaN signals content-based sizing)
285
- const availableWidth = width ?? NaN;
286
- const availableHeight = height ?? NaN;
287
- // Run the layout algorithm
288
- computeLayout(this, availableWidth, availableHeight, _direction);
289
- // Mark layout computed
290
- this._isDirty = false;
291
- this._hasNewLayout = true;
292
- markSubtreeLayoutSeen(this);
293
- log.debug?.("layout: %dx%d, %d nodes in %dms", width, height, nodeCount, Date.now() - start);
294
- }
295
- // ============================================================================
296
- // Layout Results
297
- // ============================================================================
298
- /**
299
- * Get the computed left position after layout.
300
- *
301
- * @returns The left position in points
302
- */
303
- getComputedLeft() {
304
- return this._layout.left;
305
- }
306
- /**
307
- * Get the computed top position after layout.
308
- *
309
- * @returns The top position in points
310
- */
311
- getComputedTop() {
312
- return this._layout.top;
313
- }
314
- /**
315
- * Get the computed width after layout.
316
- *
317
- * @returns The width in points
318
- */
319
- getComputedWidth() {
320
- return this._layout.width;
321
- }
322
- /**
323
- * Get the computed height after layout.
324
- *
325
- * @returns The height in points
326
- */
327
- getComputedHeight() {
328
- return this._layout.height;
329
- }
330
- // ============================================================================
331
- // Internal Accessors (for layout algorithm)
332
- // ============================================================================
333
- get children() {
334
- return this._children;
335
- }
336
- get style() {
337
- return this._style;
338
- }
339
- get layout() {
340
- return this._layout;
341
- }
342
- get measureFunc() {
343
- return this._measureFunc;
344
- }
345
- get baselineFunc() {
346
- return this._baselineFunc;
347
- }
348
- // ============================================================================
349
- // Width Setters
350
- // ============================================================================
351
- /**
352
- * Set the width to a fixed value in points.
353
- *
354
- * @param value - Width in points
355
- */
356
- setWidth(value) {
357
- // NaN means "auto" in Yoga API
358
- if (Number.isNaN(value)) {
359
- this._style.width = { value: 0, unit: C.UNIT_AUTO };
360
- }
361
- else {
362
- this._style.width = { value, unit: C.UNIT_POINT };
363
- }
364
- this.markDirty();
365
- }
366
- /**
367
- * Set the width as a percentage of the parent's width.
368
- *
369
- * @param value - Width as a percentage (0-100)
370
- */
371
- setWidthPercent(value) {
372
- this._style.width = { value, unit: C.UNIT_PERCENT };
373
- this.markDirty();
374
- }
375
- /**
376
- * Set the width to auto (determined by layout algorithm).
377
- */
378
- setWidthAuto() {
379
- this._style.width = { value: 0, unit: C.UNIT_AUTO };
380
- this.markDirty();
381
- }
382
- // ============================================================================
383
- // Height Setters
384
- // ============================================================================
385
- /**
386
- * Set the height to a fixed value in points.
387
- *
388
- * @param value - Height in points
389
- */
390
- setHeight(value) {
391
- // NaN means "auto" in Yoga API
392
- if (Number.isNaN(value)) {
393
- this._style.height = { value: 0, unit: C.UNIT_AUTO };
394
- }
395
- else {
396
- this._style.height = { value, unit: C.UNIT_POINT };
397
- }
398
- this.markDirty();
399
- }
400
- /**
401
- * Set the height as a percentage of the parent's height.
402
- *
403
- * @param value - Height as a percentage (0-100)
404
- */
405
- setHeightPercent(value) {
406
- this._style.height = { value, unit: C.UNIT_PERCENT };
407
- this.markDirty();
408
- }
409
- /**
410
- * Set the height to auto (determined by layout algorithm).
411
- */
412
- setHeightAuto() {
413
- this._style.height = { value: 0, unit: C.UNIT_AUTO };
414
- this.markDirty();
415
- }
416
- // ============================================================================
417
- // Min/Max Size Setters
418
- // ============================================================================
419
- /**
420
- * Set the minimum width in points.
421
- *
422
- * @param value - Minimum width in points
423
- */
424
- setMinWidth(value) {
425
- this._style.minWidth = { value, unit: C.UNIT_POINT };
426
- this.markDirty();
427
- }
428
- /**
429
- * Set the minimum width as a percentage of the parent's width.
430
- *
431
- * @param value - Minimum width as a percentage (0-100)
432
- */
433
- setMinWidthPercent(value) {
434
- this._style.minWidth = { value, unit: C.UNIT_PERCENT };
435
- this.markDirty();
436
- }
437
- /**
438
- * Set the minimum height in points.
439
- *
440
- * @param value - Minimum height in points
441
- */
442
- setMinHeight(value) {
443
- this._style.minHeight = { value, unit: C.UNIT_POINT };
444
- this.markDirty();
445
- }
446
- /**
447
- * Set the minimum height as a percentage of the parent's height.
448
- *
449
- * @param value - Minimum height as a percentage (0-100)
450
- */
451
- setMinHeightPercent(value) {
452
- this._style.minHeight = { value, unit: C.UNIT_PERCENT };
453
- this.markDirty();
454
- }
455
- /**
456
- * Set the maximum width in points.
457
- *
458
- * @param value - Maximum width in points
459
- */
460
- setMaxWidth(value) {
461
- this._style.maxWidth = { value, unit: C.UNIT_POINT };
462
- this.markDirty();
463
- }
464
- /**
465
- * Set the maximum width as a percentage of the parent's width.
466
- *
467
- * @param value - Maximum width as a percentage (0-100)
468
- */
469
- setMaxWidthPercent(value) {
470
- this._style.maxWidth = { value, unit: C.UNIT_PERCENT };
471
- this.markDirty();
472
- }
473
- /**
474
- * Set the maximum height in points.
475
- *
476
- * @param value - Maximum height in points
477
- */
478
- setMaxHeight(value) {
479
- this._style.maxHeight = { value, unit: C.UNIT_POINT };
480
- this.markDirty();
481
- }
482
- /**
483
- * Set the maximum height as a percentage of the parent's height.
484
- *
485
- * @param value - Maximum height as a percentage (0-100)
486
- */
487
- setMaxHeightPercent(value) {
488
- this._style.maxHeight = { value, unit: C.UNIT_PERCENT };
489
- this.markDirty();
490
- }
491
- /**
492
- * Set the aspect ratio of the node.
493
- * When set, the node's width/height relationship is constrained.
494
- * If width is defined, height = width / aspectRatio.
495
- * If height is defined, width = height * aspectRatio.
496
- *
497
- * @param value - Aspect ratio (width/height). Use NaN to unset.
498
- */
499
- setAspectRatio(value) {
500
- this._style.aspectRatio = value;
501
- this.markDirty();
502
- }
503
- // ============================================================================
504
- // Flex Setters
505
- // ============================================================================
506
- /**
507
- * Set the flex grow factor.
508
- * Determines how much the node will grow relative to siblings when there is extra space.
509
- *
510
- * @param value - Flex grow factor (typically 0 or 1+)
511
- * @example
512
- * ```typescript
513
- * const child = Node.create();
514
- * child.setFlexGrow(1); // Will grow to fill available space
515
- * ```
516
- */
517
- setFlexGrow(value) {
518
- this._style.flexGrow = value;
519
- this.markDirty();
520
- }
521
- /**
522
- * Set the flex shrink factor.
523
- * Determines how much the node will shrink relative to siblings when there is insufficient space.
524
- *
525
- * @param value - Flex shrink factor (default is 1)
526
- */
527
- setFlexShrink(value) {
528
- this._style.flexShrink = value;
529
- this.markDirty();
530
- }
531
- /**
532
- * Set the flex basis to a fixed value in points.
533
- * The initial size of the node before flex grow/shrink is applied.
534
- *
535
- * @param value - Flex basis in points
536
- */
537
- setFlexBasis(value) {
538
- this._style.flexBasis = { value, unit: C.UNIT_POINT };
539
- this.markDirty();
540
- }
541
- /**
542
- * Set the flex basis as a percentage of the parent's size.
543
- *
544
- * @param value - Flex basis as a percentage (0-100)
545
- */
546
- setFlexBasisPercent(value) {
547
- this._style.flexBasis = { value, unit: C.UNIT_PERCENT };
548
- this.markDirty();
549
- }
550
- /**
551
- * Set the flex basis to auto (based on the node's width/height).
552
- */
553
- setFlexBasisAuto() {
554
- this._style.flexBasis = { value: 0, unit: C.UNIT_AUTO };
555
- this.markDirty();
556
- }
557
- /**
558
- * Set the flex direction (main axis direction).
559
- *
560
- * @param direction - FLEX_DIRECTION_ROW, FLEX_DIRECTION_COLUMN, FLEX_DIRECTION_ROW_REVERSE, or FLEX_DIRECTION_COLUMN_REVERSE
561
- * @example
562
- * ```typescript
563
- * const container = Node.create();
564
- * container.setFlexDirection(FLEX_DIRECTION_ROW); // Lay out children horizontally
565
- * ```
566
- */
567
- setFlexDirection(direction) {
568
- this._style.flexDirection = direction;
569
- this.markDirty();
570
- }
571
- /**
572
- * Set the flex wrap behavior.
573
- *
574
- * @param wrap - WRAP_NO_WRAP, WRAP_WRAP, or WRAP_WRAP_REVERSE
575
- */
576
- setFlexWrap(wrap) {
577
- this._style.flexWrap = wrap;
578
- this.markDirty();
579
- }
580
- // ============================================================================
581
- // Alignment Setters
582
- // ============================================================================
583
- /**
584
- * Set how children are aligned along the cross axis.
585
- *
586
- * @param align - ALIGN_FLEX_START, ALIGN_CENTER, ALIGN_FLEX_END, ALIGN_STRETCH, or ALIGN_BASELINE
587
- * @example
588
- * ```typescript
589
- * const container = Node.create();
590
- * container.setFlexDirection(FLEX_DIRECTION_ROW);
591
- * container.setAlignItems(ALIGN_CENTER); // Center children vertically
592
- * ```
593
- */
594
- setAlignItems(align) {
595
- this._style.alignItems = align;
596
- this.markDirty();
597
- }
598
- /**
599
- * Set how this node is aligned along the parent's cross axis.
600
- * Overrides the parent's alignItems for this specific child.
601
- *
602
- * @param align - ALIGN_AUTO, ALIGN_FLEX_START, ALIGN_CENTER, ALIGN_FLEX_END, ALIGN_STRETCH, or ALIGN_BASELINE
603
- */
604
- setAlignSelf(align) {
605
- this._style.alignSelf = align;
606
- this.markDirty();
607
- }
608
- /**
609
- * Set how lines are aligned in a multi-line flex container.
610
- * Only affects containers with wrap enabled and multiple lines.
611
- *
612
- * @param align - ALIGN_FLEX_START, ALIGN_CENTER, ALIGN_FLEX_END, ALIGN_STRETCH, ALIGN_SPACE_BETWEEN, or ALIGN_SPACE_AROUND
613
- */
614
- setAlignContent(align) {
615
- this._style.alignContent = align;
616
- this.markDirty();
617
- }
618
- /**
619
- * Set how children are distributed along the main axis.
620
- *
621
- * @param justify - JUSTIFY_FLEX_START, JUSTIFY_CENTER, JUSTIFY_FLEX_END, JUSTIFY_SPACE_BETWEEN, JUSTIFY_SPACE_AROUND, or JUSTIFY_SPACE_EVENLY
622
- * @example
623
- * ```typescript
624
- * const container = Node.create();
625
- * container.setJustifyContent(JUSTIFY_SPACE_BETWEEN); // Space children evenly with edges at start/end
626
- * ```
627
- */
628
- setJustifyContent(justify) {
629
- this._style.justifyContent = justify;
630
- this.markDirty();
631
- }
632
- // ============================================================================
633
- // Spacing Setters
634
- // ============================================================================
635
- /**
636
- * Set padding for one or more edges.
637
- *
638
- * @param edge - EDGE_LEFT, EDGE_TOP, EDGE_RIGHT, EDGE_BOTTOM, EDGE_HORIZONTAL, EDGE_VERTICAL, or EDGE_ALL
639
- * @param value - Padding in points
640
- * @example
641
- * ```typescript
642
- * node.setPadding(EDGE_ALL, 10); // Set 10pt padding on all edges
643
- * node.setPadding(EDGE_HORIZONTAL, 5); // Set 5pt padding on left and right
644
- * ```
645
- */
646
- setPadding(edge, value) {
647
- setEdgeValue(this._style.padding, edge, value, C.UNIT_POINT);
648
- this.markDirty();
649
- }
650
- /**
651
- * Set padding as a percentage of the parent's width.
652
- * Per CSS spec, percentage padding always resolves against the containing block's width.
653
- *
654
- * @param edge - EDGE_LEFT, EDGE_TOP, EDGE_RIGHT, EDGE_BOTTOM, EDGE_HORIZONTAL, EDGE_VERTICAL, or EDGE_ALL
655
- * @param value - Padding as a percentage (0-100)
656
- */
657
- setPaddingPercent(edge, value) {
658
- setEdgeValue(this._style.padding, edge, value, C.UNIT_PERCENT);
659
- this.markDirty();
660
- }
661
- /**
662
- * Set margin for one or more edges.
663
- *
664
- * @param edge - EDGE_LEFT, EDGE_TOP, EDGE_RIGHT, EDGE_BOTTOM, EDGE_HORIZONTAL, EDGE_VERTICAL, or EDGE_ALL
665
- * @param value - Margin in points
666
- * @example
667
- * ```typescript
668
- * node.setMargin(EDGE_ALL, 5); // Set 5pt margin on all edges
669
- * node.setMargin(EDGE_TOP, 10); // Set 10pt margin on top only
670
- * ```
671
- */
672
- setMargin(edge, value) {
673
- setEdgeValue(this._style.margin, edge, value, C.UNIT_POINT);
674
- this.markDirty();
675
- }
676
- /**
677
- * Set margin as a percentage of the parent's size.
678
- *
679
- * @param edge - EDGE_LEFT, EDGE_TOP, EDGE_RIGHT, EDGE_BOTTOM, EDGE_HORIZONTAL, EDGE_VERTICAL, or EDGE_ALL
680
- * @param value - Margin as a percentage (0-100)
681
- */
682
- setMarginPercent(edge, value) {
683
- setEdgeValue(this._style.margin, edge, value, C.UNIT_PERCENT);
684
- this.markDirty();
685
- }
686
- /**
687
- * Set margin to auto (for centering items with margin: auto).
688
- *
689
- * @param edge - EDGE_LEFT, EDGE_TOP, EDGE_RIGHT, EDGE_BOTTOM, EDGE_HORIZONTAL, EDGE_VERTICAL, or EDGE_ALL
690
- */
691
- setMarginAuto(edge) {
692
- setEdgeValue(this._style.margin, edge, 0, C.UNIT_AUTO);
693
- this.markDirty();
694
- }
695
- /**
696
- * Set border width for one or more edges.
697
- *
698
- * @param edge - EDGE_LEFT, EDGE_TOP, EDGE_RIGHT, EDGE_BOTTOM, EDGE_HORIZONTAL, EDGE_VERTICAL, or EDGE_ALL
699
- * @param value - Border width in points
700
- */
701
- setBorder(edge, value) {
702
- setEdgeBorder(this._style.border, edge, value);
703
- this.markDirty();
704
- }
705
- /**
706
- * Set gap between flex items.
707
- *
708
- * @param gutter - GUTTER_COLUMN (horizontal gap), GUTTER_ROW (vertical gap), or GUTTER_ALL (both)
709
- * @param value - Gap size in points
710
- * @example
711
- * ```typescript
712
- * container.setGap(GUTTER_ALL, 8); // Set 8pt gap between all items
713
- * container.setGap(GUTTER_COLUMN, 10); // Set 10pt horizontal gap only
714
- * ```
715
- */
716
- setGap(gutter, value) {
717
- if (gutter === C.GUTTER_COLUMN) {
718
- this._style.gap[0] = value;
719
- }
720
- else if (gutter === C.GUTTER_ROW) {
721
- this._style.gap[1] = value;
722
- }
723
- else if (gutter === C.GUTTER_ALL) {
724
- this._style.gap[0] = value;
725
- this._style.gap[1] = value;
726
- }
727
- this.markDirty();
728
- }
729
- // ============================================================================
730
- // Position Setters
731
- // ============================================================================
732
- /**
733
- * Set the position type.
734
- *
735
- * @param positionType - POSITION_TYPE_STATIC, POSITION_TYPE_RELATIVE, or POSITION_TYPE_ABSOLUTE
736
- * @example
737
- * ```typescript
738
- * node.setPositionType(POSITION_TYPE_ABSOLUTE);
739
- * node.setPosition(EDGE_LEFT, 10);
740
- * node.setPosition(EDGE_TOP, 20);
741
- * ```
742
- */
743
- setPositionType(positionType) {
744
- this._style.positionType = positionType;
745
- this.markDirty();
746
- }
747
- /**
748
- * Set position offset for one or more edges.
749
- * Only applies when position type is ABSOLUTE or RELATIVE.
750
- *
751
- * @param edge - EDGE_LEFT, EDGE_TOP, EDGE_RIGHT, EDGE_BOTTOM, EDGE_HORIZONTAL, EDGE_VERTICAL, or EDGE_ALL
752
- * @param value - Position offset in points
753
- */
754
- setPosition(edge, value) {
755
- // NaN means "auto" (unset) in Yoga API
756
- if (Number.isNaN(value)) {
757
- setEdgeValue(this._style.position, edge, 0, C.UNIT_UNDEFINED);
758
- }
759
- else {
760
- setEdgeValue(this._style.position, edge, value, C.UNIT_POINT);
761
- }
762
- this.markDirty();
763
- }
764
- /**
765
- * Set position offset as a percentage.
766
- *
767
- * @param edge - EDGE_LEFT, EDGE_TOP, EDGE_RIGHT, EDGE_BOTTOM, EDGE_HORIZONTAL, EDGE_VERTICAL, or EDGE_ALL
768
- * @param value - Position offset as a percentage of parent's corresponding dimension
769
- */
770
- setPositionPercent(edge, value) {
771
- setEdgeValue(this._style.position, edge, value, C.UNIT_PERCENT);
772
- this.markDirty();
773
- }
774
- // ============================================================================
775
- // Other Setters
776
- // ============================================================================
777
- /**
778
- * Set the display type.
779
- *
780
- * @param display - DISPLAY_FLEX or DISPLAY_NONE
781
- */
782
- setDisplay(display) {
783
- this._style.display = display;
784
- this.markDirty();
785
- }
786
- /**
787
- * Set the overflow behavior.
788
- *
789
- * @param overflow - OVERFLOW_VISIBLE, OVERFLOW_HIDDEN, or OVERFLOW_SCROLL
790
- */
791
- setOverflow(overflow) {
792
- this._style.overflow = overflow;
793
- this.markDirty();
794
- }
795
- // ============================================================================
796
- // Style Getters
797
- // ============================================================================
798
- /**
799
- * Get the width style value.
800
- *
801
- * @returns Width value with unit (points, percent, or auto)
802
- */
803
- getWidth() {
804
- return this._style.width;
805
- }
806
- /**
807
- * Get the height style value.
808
- *
809
- * @returns Height value with unit (points, percent, or auto)
810
- */
811
- getHeight() {
812
- return this._style.height;
813
- }
814
- /**
815
- * Get the minimum width style value.
816
- *
817
- * @returns Minimum width value with unit
818
- */
819
- getMinWidth() {
820
- return this._style.minWidth;
821
- }
822
- /**
823
- * Get the minimum height style value.
824
- *
825
- * @returns Minimum height value with unit
826
- */
827
- getMinHeight() {
828
- return this._style.minHeight;
829
- }
830
- /**
831
- * Get the maximum width style value.
832
- *
833
- * @returns Maximum width value with unit
834
- */
835
- getMaxWidth() {
836
- return this._style.maxWidth;
837
- }
838
- /**
839
- * Get the maximum height style value.
840
- *
841
- * @returns Maximum height value with unit
842
- */
843
- getMaxHeight() {
844
- return this._style.maxHeight;
845
- }
846
- /**
847
- * Get the aspect ratio.
848
- *
849
- * @returns Aspect ratio value (NaN if not set)
850
- */
851
- getAspectRatio() {
852
- return this._style.aspectRatio;
853
- }
854
- /**
855
- * Get the flex grow factor.
856
- *
857
- * @returns Flex grow value
858
- */
859
- getFlexGrow() {
860
- return this._style.flexGrow;
861
- }
862
- /**
863
- * Get the flex shrink factor.
864
- *
865
- * @returns Flex shrink value
866
- */
867
- getFlexShrink() {
868
- return this._style.flexShrink;
869
- }
870
- /**
871
- * Get the flex basis style value.
872
- *
873
- * @returns Flex basis value with unit
874
- */
875
- getFlexBasis() {
876
- return this._style.flexBasis;
877
- }
878
- /**
879
- * Get the flex direction.
880
- *
881
- * @returns Flex direction constant
882
- */
883
- getFlexDirection() {
884
- return this._style.flexDirection;
885
- }
886
- /**
887
- * Get the flex wrap setting.
888
- *
889
- * @returns Flex wrap constant
890
- */
891
- getFlexWrap() {
892
- return this._style.flexWrap;
893
- }
894
- /**
895
- * Get the align items setting.
896
- *
897
- * @returns Align items constant
898
- */
899
- getAlignItems() {
900
- return this._style.alignItems;
901
- }
902
- /**
903
- * Get the align self setting.
904
- *
905
- * @returns Align self constant
906
- */
907
- getAlignSelf() {
908
- return this._style.alignSelf;
909
- }
910
- /**
911
- * Get the align content setting.
912
- *
913
- * @returns Align content constant
914
- */
915
- getAlignContent() {
916
- return this._style.alignContent;
917
- }
918
- /**
919
- * Get the justify content setting.
920
- *
921
- * @returns Justify content constant
922
- */
923
- getJustifyContent() {
924
- return this._style.justifyContent;
925
- }
926
- /**
927
- * Get the padding for a specific edge.
928
- *
929
- * @param edge - EDGE_LEFT, EDGE_TOP, EDGE_RIGHT, or EDGE_BOTTOM
930
- * @returns Padding value with unit
931
- */
932
- getPadding(edge) {
933
- return getEdgeValue(this._style.padding, edge);
934
- }
935
- /**
936
- * Get the margin for a specific edge.
937
- *
938
- * @param edge - EDGE_LEFT, EDGE_TOP, EDGE_RIGHT, or EDGE_BOTTOM
939
- * @returns Margin value with unit
940
- */
941
- getMargin(edge) {
942
- return getEdgeValue(this._style.margin, edge);
943
- }
944
- /**
945
- * Get the border width for a specific edge.
946
- *
947
- * @param edge - EDGE_LEFT, EDGE_TOP, EDGE_RIGHT, or EDGE_BOTTOM
948
- * @returns Border width in points
949
- */
950
- getBorder(edge) {
951
- return getEdgeBorderValue(this._style.border, edge);
952
- }
953
- /**
954
- * Get the position offset for a specific edge.
955
- *
956
- * @param edge - EDGE_LEFT, EDGE_TOP, EDGE_RIGHT, or EDGE_BOTTOM
957
- * @returns Position value with unit
958
- */
959
- getPosition(edge) {
960
- return getEdgeValue(this._style.position, edge);
961
- }
962
- /**
963
- * Get the position type.
964
- *
965
- * @returns Position type constant
966
- */
967
- getPositionType() {
968
- return this._style.positionType;
969
- }
970
- /**
971
- * Get the display type.
972
- *
973
- * @returns Display constant
974
- */
975
- getDisplay() {
976
- return this._style.display;
977
- }
978
- /**
979
- * Get the overflow setting.
980
- *
981
- * @returns Overflow constant
982
- */
983
- getOverflow() {
984
- return this._style.overflow;
985
- }
986
- /**
987
- * Get the gap for column or row.
988
- *
989
- * @param gutter - GUTTER_COLUMN or GUTTER_ROW
990
- * @returns Gap size in points
991
- */
992
- getGap(gutter) {
993
- if (gutter === C.GUTTER_COLUMN) {
994
- return this._style.gap[0];
995
- }
996
- else if (gutter === C.GUTTER_ROW) {
997
- return this._style.gap[1];
998
- }
999
- return this._style.gap[0]; // Default to column gap
1000
- }
1001
- }
1002
- //# sourceMappingURL=node.js.map