@alchemy.run/sigil 0.0.0-alpha.1 → 0.0.0-alpha.2

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 (121) hide show
  1. package/README.md +299 -299
  2. package/dist/ansi.d.ts +223 -0
  3. package/dist/ansi.js +2 -0
  4. package/dist/{devtools-QpCMm9JH.mjs → devtools-BhYGjb7h.js} +1 -1
  5. package/dist/index-DDVME65c.d.ts +919 -0
  6. package/dist/index.d.ts +1657 -0
  7. package/dist/index.js +4643 -0
  8. package/dist/sgr-CMfEpjSk.d.ts +91 -0
  9. package/dist/truncate-CBiyyZzw.js +2156 -0
  10. package/dist/yoga-5jKhYCJC.js +3465 -0
  11. package/dist/yoga.d.ts +2 -0
  12. package/dist/yoga.js +2 -0
  13. package/package.json +37 -17
  14. package/src/ansi/chalk.ts +179 -0
  15. package/src/ansi/cursor.ts +48 -0
  16. package/src/ansi/east-asian-width.ts +215 -0
  17. package/src/ansi/escapes.ts +128 -0
  18. package/src/ansi/index.ts +27 -0
  19. package/src/ansi/sgr.ts +237 -0
  20. package/src/ansi/slice.ts +43 -0
  21. package/src/ansi/string-width.ts +236 -0
  22. package/src/ansi/strip.ts +33 -0
  23. package/src/ansi/supports-color.ts +213 -0
  24. package/src/ansi/tokenize.ts +453 -0
  25. package/src/ansi/truncate.ts +194 -0
  26. package/src/ansi/widest-line.ts +12 -0
  27. package/src/ansi/wrap.ts +766 -0
  28. package/src/ansi-tokenizer.ts +510 -0
  29. package/src/auto-bind.ts +41 -0
  30. package/src/boxes.ts +100 -0
  31. package/src/code-excerpt.ts +39 -0
  32. package/src/colorize.ts +60 -0
  33. package/src/components/AccessibilityContext.ts +5 -0
  34. package/src/components/AnimationContext.ts +24 -0
  35. package/src/components/App.tsx +781 -0
  36. package/src/components/AppContext.ts +111 -0
  37. package/src/components/BackgroundContext.ts +8 -0
  38. package/src/components/Box.tsx +116 -0
  39. package/src/components/CursorContext.ts +19 -0
  40. package/src/components/ErrorBoundary.tsx +38 -0
  41. package/src/components/ErrorOverview.tsx +133 -0
  42. package/src/components/FocusContext.ts +30 -0
  43. package/src/components/Newline.tsx +15 -0
  44. package/src/components/Spacer.tsx +10 -0
  45. package/src/components/Static.tsx +59 -0
  46. package/src/components/StderrContext.ts +26 -0
  47. package/src/components/StdinContext.ts +49 -0
  48. package/src/components/StdoutContext.ts +28 -0
  49. package/src/components/Text.tsx +144 -0
  50. package/src/components/Transform.tsx +37 -0
  51. package/src/cursor-position.ts +103 -0
  52. package/src/devtools-window-polyfill.ts +73 -0
  53. package/src/devtools.ts +43 -0
  54. package/src/dom.ts +292 -0
  55. package/src/get-max-width.ts +11 -0
  56. package/src/global.d.ts +36 -0
  57. package/src/hooks/use-animation.ts +142 -0
  58. package/src/hooks/use-app.ts +8 -0
  59. package/src/hooks/use-box-metrics.ts +134 -0
  60. package/src/hooks/use-cursor.ts +33 -0
  61. package/src/hooks/use-focus-manager.ts +62 -0
  62. package/src/hooks/use-focus.ts +83 -0
  63. package/src/hooks/use-input.ts +267 -0
  64. package/src/hooks/use-is-screen-reader-enabled.ts +12 -0
  65. package/src/hooks/use-paste.ts +78 -0
  66. package/src/hooks/use-stderr.ts +8 -0
  67. package/src/hooks/use-stdin.ts +10 -0
  68. package/src/hooks/use-stdout.ts +8 -0
  69. package/src/hooks/use-window-size.ts +41 -0
  70. package/src/indent-string.ts +16 -0
  71. package/src/index.ts +44 -0
  72. package/src/ink.tsx +1506 -0
  73. package/src/input-parser.ts +283 -0
  74. package/src/instances.ts +9 -0
  75. package/src/is-in-ci.ts +7 -0
  76. package/src/kitty-keyboard.ts +57 -0
  77. package/src/log-update.ts +370 -0
  78. package/src/measure-element.ts +62 -0
  79. package/src/measure-text.ts +31 -0
  80. package/src/output.ts +308 -0
  81. package/src/parse-keypress.ts +516 -0
  82. package/src/parse-stack-line.ts +139 -0
  83. package/src/patch-console.ts +62 -0
  84. package/src/quick-lru.ts +85 -0
  85. package/src/reconciler.ts +451 -0
  86. package/src/render-background.ts +38 -0
  87. package/src/render-border.ts +134 -0
  88. package/src/render-node-to-output.ts +191 -0
  89. package/src/render-to-string.ts +131 -0
  90. package/src/render.ts +276 -0
  91. package/src/renderer.ts +73 -0
  92. package/src/sanitize-ansi.ts +33 -0
  93. package/src/signal-exit.ts +107 -0
  94. package/src/squash-text-nodes.ts +40 -0
  95. package/src/stream.ts +30 -0
  96. package/src/styles.ts +748 -0
  97. package/src/terminal-size.ts +57 -0
  98. package/src/throttle.ts +73 -0
  99. package/src/types.ts +15 -0
  100. package/src/utils.ts +40 -0
  101. package/src/wrap-text.ts +50 -0
  102. package/src/write-synchronized.ts +9 -0
  103. package/src/yoga/config.ts +57 -0
  104. package/src/yoga/core/absoluteLayout.ts +626 -0
  105. package/src/yoga/core/baseline.ts +66 -0
  106. package/src/yoga/core/cache.ts +136 -0
  107. package/src/yoga/core/calculateLayout.ts +2920 -0
  108. package/src/yoga/core/config.ts +104 -0
  109. package/src/yoga/core/flexLine.ts +177 -0
  110. package/src/yoga/core/helpers.ts +293 -0
  111. package/src/yoga/core/layoutResults.ts +167 -0
  112. package/src/yoga/core/node.ts +611 -0
  113. package/src/yoga/core/numeric.ts +44 -0
  114. package/src/yoga/core/pixelGrid.ts +151 -0
  115. package/src/yoga/core/style.ts +887 -0
  116. package/src/yoga/core/types.ts +224 -0
  117. package/src/yoga/generated/YGEnums.ts +263 -0
  118. package/src/yoga/index.ts +19 -0
  119. package/src/yoga/node.ts +1140 -0
  120. package/dist/index.d.mts +0 -2379
  121. package/dist/index.mjs +0 -10072
package/src/styles.ts ADDED
@@ -0,0 +1,748 @@
1
+ import { type ForegroundColorName } from "./ansi/sgr.ts"; // Note: We import directly from `ansi-styles` to avoid a bug in TypeScript.
2
+ import { type Boxes, type BoxStyle } from "./boxes.ts";
3
+ import { type LiteralUnion } from "./types.ts";
4
+ import { Yoga, type Node as YogaNode, type PositionType } from "./yoga/index.ts";
5
+
6
+ export type Styles = {
7
+ /*
8
+ We keep this as a single enum so overflow is one complete choice and invalid combinations like wrap + truncate-middle are unrepresentable. In hindsight, `normal` would have been a clearer default value than `wrap`, since it describes the standard behavior instead of repeating the prop name.
9
+ */
10
+ readonly textWrap?:
11
+ | "wrap"
12
+ | "hard"
13
+ | "truncate-end"
14
+ | "truncate"
15
+ | "truncate-middle"
16
+ | "truncate-start";
17
+
18
+ /**
19
+ Controls how the element is positioned.
20
+
21
+ When `position` is `static`, `top`, `right`, `bottom`, and `left` are ignored.
22
+ */
23
+ readonly position?: "absolute" | "relative" | "static";
24
+
25
+ /**
26
+ Top offset for positioned elements.
27
+ */
28
+ readonly top?: number | string;
29
+
30
+ /**
31
+ Right offset for positioned elements.
32
+ */
33
+ readonly right?: number | string;
34
+
35
+ /**
36
+ Bottom offset for positioned elements.
37
+ */
38
+ readonly bottom?: number | string;
39
+
40
+ /**
41
+ Left offset for positioned elements.
42
+ */
43
+ readonly left?: number | string;
44
+
45
+ /**
46
+ Size of the gap between an element's columns.
47
+ */
48
+ readonly columnGap?: number;
49
+
50
+ /**
51
+ Size of the gap between an element's rows.
52
+ */
53
+ readonly rowGap?: number;
54
+
55
+ /**
56
+ Size of the gap between an element's columns and rows. A shorthand for `columnGap` and `rowGap`.
57
+ */
58
+ readonly gap?: number;
59
+
60
+ /**
61
+ Margin on all sides. Equivalent to setting `marginTop`, `marginBottom`, `marginLeft`, and `marginRight`.
62
+ */
63
+ readonly margin?: number;
64
+
65
+ /**
66
+ Horizontal margin. Equivalent to setting `marginLeft` and `marginRight`.
67
+ */
68
+ readonly marginX?: number;
69
+
70
+ /**
71
+ Vertical margin. Equivalent to setting `marginTop` and `marginBottom`.
72
+ */
73
+ readonly marginY?: number;
74
+
75
+ /**
76
+ Top margin.
77
+ */
78
+ readonly marginTop?: number;
79
+
80
+ /**
81
+ Bottom margin.
82
+ */
83
+ readonly marginBottom?: number;
84
+
85
+ /**
86
+ Left margin.
87
+ */
88
+ readonly marginLeft?: number;
89
+
90
+ /**
91
+ Right margin.
92
+ */
93
+ readonly marginRight?: number;
94
+
95
+ /**
96
+ Padding on all sides. Equivalent to setting `paddingTop`, `paddingBottom`, `paddingLeft`, and `paddingRight`.
97
+ */
98
+ readonly padding?: number;
99
+
100
+ /**
101
+ Horizontal padding. Equivalent to setting `paddingLeft` and `paddingRight`.
102
+ */
103
+ readonly paddingX?: number;
104
+
105
+ /**
106
+ Vertical padding. Equivalent to setting `paddingTop` and `paddingBottom`.
107
+ */
108
+ readonly paddingY?: number;
109
+
110
+ /**
111
+ Top padding.
112
+ */
113
+ readonly paddingTop?: number;
114
+
115
+ /**
116
+ Bottom padding.
117
+ */
118
+ readonly paddingBottom?: number;
119
+
120
+ /**
121
+ Left padding.
122
+ */
123
+ readonly paddingLeft?: number;
124
+
125
+ /**
126
+ Right padding.
127
+ */
128
+ readonly paddingRight?: number;
129
+
130
+ /**
131
+ This property defines the ability for a flex item to grow if necessary.
132
+ See [flex-grow](https://css-tricks.com/almanac/properties/f/flex-grow/).
133
+ */
134
+ readonly flexGrow?: number;
135
+
136
+ /**
137
+ It specifies the “flex shrink factor”, which determines how much the flex item will shrink relative to the rest of the flex items in the flex container when there isn’t enough space on the row.
138
+ See [flex-shrink](https://css-tricks.com/almanac/properties/f/flex-shrink/).
139
+ */
140
+ readonly flexShrink?: number;
141
+
142
+ /**
143
+ It establishes the main-axis, thus defining the direction flex items are placed in the flex container.
144
+ See [flex-direction](https://css-tricks.com/almanac/properties/f/flex-direction/).
145
+ */
146
+ readonly flexDirection?: "row" | "column" | "row-reverse" | "column-reverse";
147
+
148
+ /**
149
+ It specifies the initial size of the flex item, before any available space is distributed according to the flex factors.
150
+ See [flex-basis](https://css-tricks.com/almanac/properties/f/flex-basis/).
151
+ */
152
+ readonly flexBasis?: number | string;
153
+
154
+ /**
155
+ It defines whether the flex items are forced in a single line or can be flowed into multiple lines. If set to multiple lines, it also defines the cross-axis which determines the direction new lines are stacked in.
156
+ See [flex-wrap](https://css-tricks.com/almanac/properties/f/flex-wrap/).
157
+ */
158
+ readonly flexWrap?: "nowrap" | "wrap" | "wrap-reverse";
159
+
160
+ /**
161
+ The align-items property defines the default behavior for how items are laid out along the cross axis (perpendicular to the main axis).
162
+ See [align-items](https://css-tricks.com/almanac/properties/a/align-items/).
163
+ */
164
+ readonly alignItems?: "flex-start" | "center" | "flex-end" | "stretch" | "baseline";
165
+
166
+ /**
167
+ It makes possible to override the align-items value for specific flex items.
168
+ See [align-self](https://css-tricks.com/almanac/properties/a/align-self/).
169
+ */
170
+ readonly alignSelf?: "flex-start" | "center" | "flex-end" | "auto" | "stretch" | "baseline";
171
+
172
+ /**
173
+ It defines the alignment along the cross axis when there are multiple lines of flex items (when using flex-wrap).
174
+ See [align-content](https://css-tricks.com/almanac/properties/a/align-content/).
175
+ */
176
+ readonly alignContent?:
177
+ | "flex-start"
178
+ | "flex-end"
179
+ | "center"
180
+ | "stretch"
181
+ | "space-between"
182
+ | "space-around"
183
+ | "space-evenly";
184
+
185
+ /**
186
+ It defines the alignment along the main axis.
187
+ See [justify-content](https://css-tricks.com/almanac/properties/j/justify-content/).
188
+ */
189
+ readonly justifyContent?:
190
+ | "flex-start"
191
+ | "flex-end"
192
+ | "space-between"
193
+ | "space-around"
194
+ | "space-evenly"
195
+ | "center";
196
+
197
+ /**
198
+ Width of the element in spaces. You can also set it as a percentage, which will calculate the width based on the width of the parent element.
199
+ */
200
+ readonly width?: number | string;
201
+
202
+ /**
203
+ Height of the element in lines (rows). You can also set it as a percentage, which will calculate the height based on the height of the parent element.
204
+ */
205
+ readonly height?: number | string;
206
+
207
+ /**
208
+ Sets a minimum width of the element.
209
+ Percentages aren't supported yet; see https://github.com/facebook/yoga/issues/872.
210
+ */
211
+ readonly minWidth?: number | string;
212
+
213
+ /**
214
+ Sets a minimum height of the element in lines (rows). You can also set it as a percentage, which will calculate the minimum height based on the height of the parent element.
215
+ */
216
+ readonly minHeight?: number | string;
217
+
218
+ /**
219
+ Sets a maximum width of the element.
220
+ Percentages aren't supported yet; see https://github.com/facebook/yoga/issues/872.
221
+ */
222
+ readonly maxWidth?: number | string;
223
+
224
+ /**
225
+ Sets a maximum height of the element in lines (rows). You can also set it as a percentage, which will calculate the maximum height based on the height of the parent element.
226
+ */
227
+ readonly maxHeight?: number | string;
228
+
229
+ /**
230
+ Defines the aspect ratio (width/height) for the element.
231
+
232
+ Use it with at least one size constraint (`width`, `height`, `minHeight`, or `maxHeight`) so Ink can derive the missing dimension.
233
+ */
234
+ readonly aspectRatio?: number;
235
+
236
+ /**
237
+ Set this property to `none` to hide the element.
238
+ */
239
+ readonly display?: "flex" | "none";
240
+
241
+ /**
242
+ Add a border with a specified style. If `borderStyle` is `undefined` (the default), no border will be added.
243
+ */
244
+ readonly borderStyle?: keyof Boxes | BoxStyle;
245
+
246
+ /**
247
+ Determines whether the top border is visible.
248
+
249
+ @default true
250
+ */
251
+ readonly borderTop?: boolean;
252
+
253
+ /**
254
+ Determines whether the bottom border is visible.
255
+
256
+ @default true
257
+ */
258
+ readonly borderBottom?: boolean;
259
+
260
+ /**
261
+ Determines whether the left border is visible.
262
+
263
+ @default true
264
+ */
265
+ readonly borderLeft?: boolean;
266
+
267
+ /**
268
+ Determines whether the right border is visible.
269
+
270
+ @default true
271
+ */
272
+ readonly borderRight?: boolean;
273
+
274
+ /**
275
+ Change border color. A shorthand for setting `borderTopColor`, `borderRightColor`, `borderBottomColor`, and `borderLeftColor`.
276
+ */
277
+ readonly borderColor?: LiteralUnion<ForegroundColorName, string>;
278
+
279
+ /**
280
+ Change the top border color. Accepts the same values as `color` in `Text` component.
281
+ */
282
+ readonly borderTopColor?: LiteralUnion<ForegroundColorName, string>;
283
+
284
+ /**
285
+ Change the bottom border color. Accepts the same values as `color` in `Text` component.
286
+ */
287
+ readonly borderBottomColor?: LiteralUnion<ForegroundColorName, string>;
288
+
289
+ /**
290
+ Change the left border color. Accepts the same values as `color` in `Text` component.
291
+ */
292
+ readonly borderLeftColor?: LiteralUnion<ForegroundColorName, string>;
293
+
294
+ /**
295
+ Change the right border color. Accepts the same values as `color` in `Text` component.
296
+ */
297
+ readonly borderRightColor?: LiteralUnion<ForegroundColorName, string>;
298
+
299
+ /**
300
+ Dim the border color. A shorthand for setting `borderTopDimColor`, `borderBottomDimColor`, `borderLeftDimColor`, and `borderRightDimColor`.
301
+
302
+ @default false
303
+ */
304
+ readonly borderDimColor?: boolean;
305
+
306
+ /**
307
+ Dim the top border color.
308
+
309
+ @default false
310
+ */
311
+ readonly borderTopDimColor?: boolean;
312
+
313
+ /**
314
+ Dim the bottom border color.
315
+
316
+ @default false
317
+ */
318
+ readonly borderBottomDimColor?: boolean;
319
+
320
+ /**
321
+ Dim the left border color.
322
+
323
+ @default false
324
+ */
325
+ readonly borderLeftDimColor?: boolean;
326
+
327
+ /**
328
+ Dim the right border color.
329
+
330
+ @default false
331
+ */
332
+ readonly borderRightDimColor?: boolean;
333
+
334
+ /**
335
+ Change border background color. A shorthand for setting `borderTopBackgroundColor`, `borderRightBackgroundColor`, `borderBottomBackgroundColor`, and `borderLeftBackgroundColor`.
336
+ */
337
+ readonly borderBackgroundColor?: LiteralUnion<ForegroundColorName, string>;
338
+
339
+ /**
340
+ Change top border background color. Accepts the same values as `backgroundColor` in `Text` component.
341
+ */
342
+ readonly borderTopBackgroundColor?: LiteralUnion<ForegroundColorName, string>;
343
+
344
+ /**
345
+ Change bottom border background color. Accepts the same values as `backgroundColor` in `Text` component.
346
+ */
347
+ readonly borderBottomBackgroundColor?: LiteralUnion<ForegroundColorName, string>;
348
+
349
+ /**
350
+ Change left border background color. Accepts the same values as `backgroundColor` in `Text` component.
351
+ */
352
+ readonly borderLeftBackgroundColor?: LiteralUnion<ForegroundColorName, string>;
353
+
354
+ /**
355
+ Change right border background color. Accepts the same values as `backgroundColor` in `Text` component.
356
+ */
357
+ readonly borderRightBackgroundColor?: LiteralUnion<ForegroundColorName, string>;
358
+
359
+ /**
360
+ Behavior for an element's overflow in both directions.
361
+
362
+ @default 'visible'
363
+ */
364
+ readonly overflow?: "visible" | "hidden";
365
+
366
+ /**
367
+ Behavior for an element's overflow in the horizontal direction.
368
+
369
+ @default 'visible'
370
+ */
371
+ readonly overflowX?: "visible" | "hidden";
372
+
373
+ /**
374
+ Behavior for an element's overflow in the vertical direction.
375
+
376
+ @default 'visible'
377
+ */
378
+ readonly overflowY?: "visible" | "hidden";
379
+
380
+ /**
381
+ Background color for the element.
382
+
383
+ Accepts the same values as `color` in the `<Text>` component.
384
+ */
385
+ readonly backgroundColor?: LiteralUnion<ForegroundColorName, string>;
386
+ };
387
+
388
+ const positionEdges = [
389
+ ["top", Yoga.EDGE_TOP],
390
+ ["right", Yoga.EDGE_RIGHT],
391
+ ["bottom", Yoga.EDGE_BOTTOM],
392
+ ["left", Yoga.EDGE_LEFT],
393
+ ] as const;
394
+
395
+ const applyPositionStyles = (node: YogaNode, style: Styles): void => {
396
+ if ("position" in style) {
397
+ let positionType: PositionType = Yoga.POSITION_TYPE_RELATIVE;
398
+
399
+ if (style.position === "absolute") {
400
+ positionType = Yoga.POSITION_TYPE_ABSOLUTE;
401
+ } else if (style.position === "static") {
402
+ positionType = Yoga.POSITION_TYPE_STATIC;
403
+ }
404
+
405
+ node.setPositionType(positionType);
406
+ }
407
+
408
+ for (const [property, edge] of positionEdges) {
409
+ if (!(property in style)) {
410
+ continue;
411
+ }
412
+
413
+ const value = style[property];
414
+
415
+ if (typeof value === "string") {
416
+ node.setPositionPercent(edge, Number.parseFloat(value));
417
+ continue;
418
+ }
419
+
420
+ node.setPosition(edge, value);
421
+ }
422
+ };
423
+
424
+ const applyMarginStyles = (node: YogaNode, style: Styles): void => {
425
+ if ("margin" in style) {
426
+ node.setMargin(Yoga.EDGE_ALL, style.margin ?? 0);
427
+ }
428
+
429
+ if ("marginX" in style) {
430
+ node.setMargin(Yoga.EDGE_HORIZONTAL, style.marginX ?? 0);
431
+ }
432
+
433
+ if ("marginY" in style) {
434
+ node.setMargin(Yoga.EDGE_VERTICAL, style.marginY ?? 0);
435
+ }
436
+
437
+ if ("marginLeft" in style) {
438
+ node.setMargin(Yoga.EDGE_START, style.marginLeft ?? 0);
439
+ }
440
+
441
+ if ("marginRight" in style) {
442
+ node.setMargin(Yoga.EDGE_END, style.marginRight ?? 0);
443
+ }
444
+
445
+ if ("marginTop" in style) {
446
+ node.setMargin(Yoga.EDGE_TOP, style.marginTop ?? 0);
447
+ }
448
+
449
+ if ("marginBottom" in style) {
450
+ node.setMargin(Yoga.EDGE_BOTTOM, style.marginBottom ?? 0);
451
+ }
452
+ };
453
+
454
+ const applyPaddingStyles = (node: YogaNode, style: Styles): void => {
455
+ if ("padding" in style) {
456
+ node.setPadding(Yoga.EDGE_ALL, style.padding ?? 0);
457
+ }
458
+
459
+ if ("paddingX" in style) {
460
+ node.setPadding(Yoga.EDGE_HORIZONTAL, style.paddingX ?? 0);
461
+ }
462
+
463
+ if ("paddingY" in style) {
464
+ node.setPadding(Yoga.EDGE_VERTICAL, style.paddingY ?? 0);
465
+ }
466
+
467
+ if ("paddingLeft" in style) {
468
+ node.setPadding(Yoga.EDGE_LEFT, style.paddingLeft ?? 0);
469
+ }
470
+
471
+ if ("paddingRight" in style) {
472
+ node.setPadding(Yoga.EDGE_RIGHT, style.paddingRight ?? 0);
473
+ }
474
+
475
+ if ("paddingTop" in style) {
476
+ node.setPadding(Yoga.EDGE_TOP, style.paddingTop ?? 0);
477
+ }
478
+
479
+ if ("paddingBottom" in style) {
480
+ node.setPadding(Yoga.EDGE_BOTTOM, style.paddingBottom ?? 0);
481
+ }
482
+ };
483
+
484
+ const applyFlexStyles = (node: YogaNode, style: Styles): void => {
485
+ if ("flexGrow" in style) {
486
+ node.setFlexGrow(style.flexGrow ?? 0);
487
+ }
488
+
489
+ if ("flexShrink" in style) {
490
+ node.setFlexShrink(typeof style.flexShrink === "number" ? style.flexShrink : 1);
491
+ }
492
+
493
+ if ("flexWrap" in style) {
494
+ if (style.flexWrap === "nowrap") {
495
+ node.setFlexWrap(Yoga.WRAP_NO_WRAP);
496
+ }
497
+
498
+ if (style.flexWrap === "wrap") {
499
+ node.setFlexWrap(Yoga.WRAP_WRAP);
500
+ }
501
+
502
+ if (style.flexWrap === "wrap-reverse") {
503
+ node.setFlexWrap(Yoga.WRAP_WRAP_REVERSE);
504
+ }
505
+ }
506
+
507
+ if ("flexDirection" in style) {
508
+ if (style.flexDirection === "row") {
509
+ node.setFlexDirection(Yoga.FLEX_DIRECTION_ROW);
510
+ }
511
+
512
+ if (style.flexDirection === "row-reverse") {
513
+ node.setFlexDirection(Yoga.FLEX_DIRECTION_ROW_REVERSE);
514
+ }
515
+
516
+ if (style.flexDirection === "column") {
517
+ node.setFlexDirection(Yoga.FLEX_DIRECTION_COLUMN);
518
+ }
519
+
520
+ if (style.flexDirection === "column-reverse") {
521
+ node.setFlexDirection(Yoga.FLEX_DIRECTION_COLUMN_REVERSE);
522
+ }
523
+ }
524
+
525
+ if ("flexBasis" in style) {
526
+ if (typeof style.flexBasis === "number") {
527
+ node.setFlexBasis(style.flexBasis);
528
+ } else if (typeof style.flexBasis === "string") {
529
+ node.setFlexBasisPercent(Number.parseInt(style.flexBasis, 10));
530
+ } else {
531
+ node.setFlexBasisAuto();
532
+ }
533
+ }
534
+
535
+ if ("alignItems" in style) {
536
+ if (style.alignItems === "stretch" || !style.alignItems) {
537
+ node.setAlignItems(Yoga.ALIGN_STRETCH);
538
+ }
539
+
540
+ if (style.alignItems === "flex-start") {
541
+ node.setAlignItems(Yoga.ALIGN_FLEX_START);
542
+ }
543
+
544
+ if (style.alignItems === "center") {
545
+ node.setAlignItems(Yoga.ALIGN_CENTER);
546
+ }
547
+
548
+ if (style.alignItems === "flex-end") {
549
+ node.setAlignItems(Yoga.ALIGN_FLEX_END);
550
+ }
551
+
552
+ if (style.alignItems === "baseline") {
553
+ node.setAlignItems(Yoga.ALIGN_BASELINE);
554
+ }
555
+ }
556
+
557
+ if ("alignSelf" in style) {
558
+ if (style.alignSelf === "auto" || !style.alignSelf) {
559
+ node.setAlignSelf(Yoga.ALIGN_AUTO);
560
+ }
561
+
562
+ if (style.alignSelf === "flex-start") {
563
+ node.setAlignSelf(Yoga.ALIGN_FLEX_START);
564
+ }
565
+
566
+ if (style.alignSelf === "center") {
567
+ node.setAlignSelf(Yoga.ALIGN_CENTER);
568
+ }
569
+
570
+ if (style.alignSelf === "flex-end") {
571
+ node.setAlignSelf(Yoga.ALIGN_FLEX_END);
572
+ }
573
+
574
+ if (style.alignSelf === "stretch") {
575
+ node.setAlignSelf(Yoga.ALIGN_STRETCH);
576
+ }
577
+
578
+ if (style.alignSelf === "baseline") {
579
+ node.setAlignSelf(Yoga.ALIGN_BASELINE);
580
+ }
581
+ }
582
+
583
+ if ("alignContent" in style) {
584
+ // Keep wrapped lines top-packed by default; stretch can add surprising empty rows in fixed-height boxes.
585
+ if (style.alignContent === "flex-start" || !style.alignContent) {
586
+ node.setAlignContent(Yoga.ALIGN_FLEX_START);
587
+ }
588
+
589
+ if (style.alignContent === "center") {
590
+ node.setAlignContent(Yoga.ALIGN_CENTER);
591
+ }
592
+
593
+ if (style.alignContent === "flex-end") {
594
+ node.setAlignContent(Yoga.ALIGN_FLEX_END);
595
+ }
596
+
597
+ if (style.alignContent === "space-between") {
598
+ node.setAlignContent(Yoga.ALIGN_SPACE_BETWEEN);
599
+ }
600
+
601
+ if (style.alignContent === "space-around") {
602
+ node.setAlignContent(Yoga.ALIGN_SPACE_AROUND);
603
+ }
604
+
605
+ if (style.alignContent === "space-evenly") {
606
+ node.setAlignContent(Yoga.ALIGN_SPACE_EVENLY);
607
+ }
608
+
609
+ if (style.alignContent === "stretch") {
610
+ node.setAlignContent(Yoga.ALIGN_STRETCH);
611
+ }
612
+ }
613
+
614
+ if ("justifyContent" in style) {
615
+ if (style.justifyContent === "flex-start" || !style.justifyContent) {
616
+ node.setJustifyContent(Yoga.JUSTIFY_FLEX_START);
617
+ }
618
+
619
+ if (style.justifyContent === "center") {
620
+ node.setJustifyContent(Yoga.JUSTIFY_CENTER);
621
+ }
622
+
623
+ if (style.justifyContent === "flex-end") {
624
+ node.setJustifyContent(Yoga.JUSTIFY_FLEX_END);
625
+ }
626
+
627
+ if (style.justifyContent === "space-between") {
628
+ node.setJustifyContent(Yoga.JUSTIFY_SPACE_BETWEEN);
629
+ }
630
+
631
+ if (style.justifyContent === "space-around") {
632
+ node.setJustifyContent(Yoga.JUSTIFY_SPACE_AROUND);
633
+ }
634
+
635
+ if (style.justifyContent === "space-evenly") {
636
+ node.setJustifyContent(Yoga.JUSTIFY_SPACE_EVENLY);
637
+ }
638
+ }
639
+ };
640
+
641
+ const applyDimensionStyles = (node: YogaNode, style: Styles): void => {
642
+ if ("width" in style) {
643
+ if (typeof style.width === "number") {
644
+ node.setWidth(style.width);
645
+ } else if (typeof style.width === "string") {
646
+ node.setWidthPercent(Number.parseInt(style.width, 10));
647
+ } else {
648
+ node.setWidthAuto();
649
+ }
650
+ }
651
+
652
+ if ("height" in style) {
653
+ if (typeof style.height === "number") {
654
+ node.setHeight(style.height);
655
+ } else if (typeof style.height === "string") {
656
+ node.setHeightPercent(Number.parseInt(style.height, 10));
657
+ } else {
658
+ node.setHeightAuto();
659
+ }
660
+ }
661
+
662
+ if ("minWidth" in style) {
663
+ if (typeof style.minWidth === "string") {
664
+ node.setMinWidthPercent(Number.parseInt(style.minWidth, 10));
665
+ } else {
666
+ node.setMinWidth(style.minWidth ?? 0);
667
+ }
668
+ }
669
+
670
+ if ("minHeight" in style) {
671
+ if (typeof style.minHeight === "string") {
672
+ node.setMinHeightPercent(Number.parseInt(style.minHeight, 10));
673
+ } else {
674
+ node.setMinHeight(style.minHeight ?? 0);
675
+ }
676
+ }
677
+
678
+ if ("maxWidth" in style) {
679
+ if (typeof style.maxWidth === "string") {
680
+ node.setMaxWidthPercent(Number.parseInt(style.maxWidth, 10));
681
+ } else {
682
+ node.setMaxWidth(style.maxWidth);
683
+ }
684
+ }
685
+
686
+ if ("maxHeight" in style) {
687
+ if (typeof style.maxHeight === "string") {
688
+ node.setMaxHeightPercent(Number.parseInt(style.maxHeight, 10));
689
+ } else {
690
+ node.setMaxHeight(style.maxHeight);
691
+ }
692
+ }
693
+
694
+ if ("aspectRatio" in style) {
695
+ node.setAspectRatio(style.aspectRatio);
696
+ }
697
+ };
698
+
699
+ const applyDisplayStyles = (node: YogaNode, style: Styles): void => {
700
+ if ("display" in style) {
701
+ node.setDisplay(style.display === "flex" ? Yoga.DISPLAY_FLEX : Yoga.DISPLAY_NONE);
702
+ }
703
+ };
704
+
705
+ const applyBorderStyles = (node: YogaNode, style: Styles, currentStyle: Styles): void => {
706
+ const hasBorderChanges =
707
+ "borderStyle" in style ||
708
+ "borderTop" in style ||
709
+ "borderBottom" in style ||
710
+ "borderLeft" in style ||
711
+ "borderRight" in style;
712
+
713
+ if (!hasBorderChanges) {
714
+ return;
715
+ }
716
+
717
+ const borderWidth = currentStyle.borderStyle ? 1 : 0;
718
+
719
+ node.setBorder(Yoga.EDGE_TOP, currentStyle.borderTop === false ? 0 : borderWidth);
720
+ node.setBorder(Yoga.EDGE_BOTTOM, currentStyle.borderBottom === false ? 0 : borderWidth);
721
+ node.setBorder(Yoga.EDGE_LEFT, currentStyle.borderLeft === false ? 0 : borderWidth);
722
+ node.setBorder(Yoga.EDGE_RIGHT, currentStyle.borderRight === false ? 0 : borderWidth);
723
+ };
724
+
725
+ const applyGapStyles = (node: YogaNode, style: Styles): void => {
726
+ if ("gap" in style) {
727
+ node.setGap(Yoga.GUTTER_ALL, style.gap ?? 0);
728
+ }
729
+
730
+ if ("columnGap" in style) {
731
+ node.setGap(Yoga.GUTTER_COLUMN, style.columnGap ?? 0);
732
+ }
733
+
734
+ if ("rowGap" in style) {
735
+ node.setGap(Yoga.GUTTER_ROW, style.rowGap ?? 0);
736
+ }
737
+ };
738
+
739
+ export const styles = (node: YogaNode, style: Styles = {}, currentStyle: Styles = style): void => {
740
+ applyPositionStyles(node, style);
741
+ applyMarginStyles(node, style);
742
+ applyPaddingStyles(node, style);
743
+ applyFlexStyles(node, style);
744
+ applyDimensionStyles(node, style);
745
+ applyDisplayStyles(node, style);
746
+ applyBorderStyles(node, style, currentStyle);
747
+ applyGapStyles(node, style);
748
+ };