@solidtv/solid 1.3.0-0 → 1.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 (54) hide show
  1. package/dist/src/core/activeElement.d.ts +20 -0
  2. package/dist/src/core/activeElement.js +21 -0
  3. package/dist/src/core/activeElement.js.map +1 -0
  4. package/dist/src/core/clickInspector.js +2 -1
  5. package/dist/src/core/clickInspector.js.map +1 -1
  6. package/dist/src/core/config.d.ts +9 -5
  7. package/dist/src/core/config.js +4 -7
  8. package/dist/src/core/config.js.map +1 -1
  9. package/dist/src/core/dom-renderer/domRenderer.d.ts +6 -2
  10. package/dist/src/core/dom-renderer/domRenderer.js +24 -4
  11. package/dist/src/core/dom-renderer/domRenderer.js.map +1 -1
  12. package/dist/src/core/elementNode.d.ts +3 -3
  13. package/dist/src/core/elementNode.js +14 -5
  14. package/dist/src/core/elementNode.js.map +1 -1
  15. package/dist/src/core/env.d.ts +5 -0
  16. package/dist/src/core/env.js +8 -0
  17. package/dist/src/core/env.js.map +1 -0
  18. package/dist/src/core/flex.js +52 -124
  19. package/dist/src/core/flex.js.map +1 -1
  20. package/dist/src/core/flexLayout.d.ts +2 -0
  21. package/dist/src/core/flexLayout.js +356 -0
  22. package/dist/src/core/flexLayout.js.map +1 -0
  23. package/dist/src/core/focusKeyTypes.d.ts +0 -14
  24. package/dist/src/core/focusManager.d.ts +10 -16
  25. package/dist/src/core/focusManager.js +28 -27
  26. package/dist/src/core/focusManager.js.map +1 -1
  27. package/dist/src/core/utils.d.ts +4 -2
  28. package/dist/src/core/utils.js.map +1 -1
  29. package/dist/src/index.d.ts +2 -1
  30. package/dist/src/index.js +2 -1
  31. package/dist/src/index.js.map +1 -1
  32. package/dist/src/primitives/index.d.ts +1 -0
  33. package/dist/src/primitives/useFocusManager.d.ts +2 -1
  34. package/dist/src/primitives/useFocusManager.js +2 -1
  35. package/dist/src/primitives/useFocusManager.js.map +1 -1
  36. package/dist/src/render.js +1 -1
  37. package/dist/src/render.js.map +1 -1
  38. package/dist/tsconfig.tsbuildinfo +1 -1
  39. package/package.json +2 -2
  40. package/src/core/activeElement.ts +24 -0
  41. package/src/core/clickInspector.ts +2 -1
  42. package/src/core/config.ts +12 -11
  43. package/src/core/dom-renderer/domRenderer.ts +26 -4
  44. package/src/core/elementNode.ts +17 -12
  45. package/src/core/env.ts +11 -0
  46. package/src/core/flex.ts +56 -135
  47. package/src/core/flexLayout.ts +410 -0
  48. package/src/core/focusKeyTypes.ts +0 -14
  49. package/src/core/focusManager.ts +34 -42
  50. package/src/core/utils.ts +4 -2
  51. package/src/index.ts +2 -1
  52. package/src/primitives/index.ts +1 -0
  53. package/src/primitives/useFocusManager.ts +2 -2
  54. package/src/render.ts +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidtv/solid",
3
- "version": "1.3.0-0",
3
+ "version": "1.3.1",
4
4
  "description": "SolidTV",
5
5
  "type": "module",
6
6
  "exports": {
@@ -109,7 +109,7 @@
109
109
  },
110
110
  "peerDependencies": {
111
111
  "@solidjs/router": "^0.16.1",
112
- "@solidtv/renderer": "^1.2.3",
112
+ "@solidtv/renderer": "^1.5.4",
113
113
  "solid-js": "*"
114
114
  },
115
115
  "peerDependenciesMeta": {},
@@ -0,0 +1,24 @@
1
+ import { createSignal } from 'solid-js';
2
+ import type { ElementNode } from './elementNode.js';
3
+
4
+ /**
5
+ * Generic active-element signal — intentionally decoupled from the focus
6
+ * manager so consumers can drive focus from their own focus-management logic.
7
+ *
8
+ * `setActiveElement` is the *raw* signal setter: it only updates the reactive
9
+ * value. It does NOT move focus state, fire `onFocus`/`onBlur`, or touch the
10
+ * focus path — that is the focus manager's job (`setActiveElementCore` in
11
+ * {@link ./focusManager.ts}).
12
+ *
13
+ * The built-in focus manager applies focus via `setActiveElementCore` and
14
+ * publishes the result through `Config.setActiveElement`, which defaults to
15
+ * this setter. A library shipping its own focus manager can read
16
+ * {@link activeElement}, reassign `Config.setActiveElement` (e.g. to inject a
17
+ * Solid owner context), or call `setActiveElement` directly — without depending
18
+ * on `focusManager.ts`. Because it is a terminal signal write (it never calls
19
+ * back into the focus manager), wiring it into `Config.setActiveElement` cannot
20
+ * recurse.
21
+ */
22
+ export const [activeElement, setActiveElement] = createSignal<
23
+ ElementNode | undefined
24
+ >(undefined);
@@ -1,5 +1,6 @@
1
- import { Config, isDev } from './config.js';
1
+ import { Config } from './config.js';
2
2
  import { isElementNode } from './utils.js';
3
+ import { isDev } from './env.js';
3
4
  import type { ElementNode } from './elementNode.js';
4
5
  import { IRendererNode } from './dom-renderer/domRendererTypes.js';
5
6
 
@@ -9,6 +9,7 @@ import {
9
9
  type ElementNode,
10
10
  convertToShader as defaultConvertToShader,
11
11
  } from './elementNode.js';
12
+ import { setActiveElement as setActiveElementSignal } from './activeElement.js';
12
13
  import {
13
14
  DomRendererMainSettings,
14
15
  IRendererShader,
@@ -21,17 +22,8 @@ import {
21
22
  See `vite-env.d.ts` for environment variable type definitions.
22
23
  */
23
24
 
24
- export const isDev = !!(import.meta.env && import.meta.env.DEV);
25
-
26
- /** Whether the DOM renderer is used instead of `@solidtv/renderer` */
27
- export const DOM_RENDERING =
28
- typeof SOLIDTV_DOM_RENDERING !== 'undefined' &&
29
- SOLIDTV_DOM_RENDERING === true;
30
-
31
- /** Whether element shaders are enabled */
32
- export const SHADERS_ENABLED =
33
- typeof SOLIDTV_DISABLE_SHADERS === 'undefined' ||
34
- SOLIDTV_DISABLE_SHADERS !== true;
25
+ export { isDev, DOM_RENDERING, SHADERS_ENABLED } from './env.js';
26
+ import { DOM_RENDERING } from './env.js';
35
27
 
36
28
  /**
37
29
  * True when the DOM renderer is both built in (`DOM_RENDERING`) and turned on
@@ -63,6 +55,14 @@ export interface Config {
63
55
  animationsEnabled: boolean;
64
56
  fontSettings: Partial<TextProps>;
65
57
  rendererOptions?: Partial<RendererMainSettings> | DomRendererMainSettings;
58
+ /**
59
+ * Hook the focus manager calls to publish the active element. Defaults to
60
+ * writing the {@link activeElement} signal directly; a custom focus manager
61
+ * (or the built-in `useFocusManager`) may reassign this — e.g. to run the
62
+ * write inside a captured Solid owner context. This is the seam that keeps
63
+ * the `activeElement` signal decoupled from focus-manager logic.
64
+ */
65
+ setActiveElement: (elm: ElementNode) => void;
66
66
  focusStateKey: DollarString;
67
67
  lockStyles?: boolean;
68
68
  fontWeightAlias?: Record<string, number | string>;
@@ -84,6 +84,7 @@ export const Config: Config = {
84
84
  easing: 'ease-in-out',
85
85
  },
86
86
  convertToShader: defaultConvertToShader,
87
+ setActiveElement: (elm) => setActiveElementSignal(elm),
87
88
  fontSettings: {
88
89
  fontFamily: 'Ubuntu',
89
90
  fontSize: 100,
@@ -519,9 +519,14 @@ function updateNodeStyles(node: DOMNode | DOMText) {
519
519
  }
520
520
  hasDivBgTint = true;
521
521
  }
522
- } else if (gradient) {
523
- // use gradient as a mask when no tint is applied
524
- maskStyle += `mask-image: ${gradient};`;
522
+ } else {
523
+ if (gradient) {
524
+ // use gradient as a mask when no tint is applied
525
+ maskStyle += `mask-image: ${gradient};`;
526
+ }
527
+ if (props.placeholderColor !== 0) {
528
+ bgStyle += `background-color: ${colorToRgba(props.placeholderColor)};`;
529
+ }
525
530
  }
526
531
 
527
532
  const imgStyleParts = [
@@ -1137,7 +1142,6 @@ function updateDOMTextSize(node: DOMText, emitLoaded = true): void {
1137
1142
  w: node.w,
1138
1143
  h: node.h,
1139
1144
  },
1140
- trimmedHeight: node.h,
1141
1145
  };
1142
1146
  node.emit('loaded', payload);
1143
1147
  node.loaded = true;
@@ -1244,6 +1248,7 @@ function resolveNodeDefaults(
1244
1248
  w: props.w ?? 0,
1245
1249
  h: props.h ?? 0,
1246
1250
  alpha: props.alpha ?? 1,
1251
+ ignoreParentAlpha: props.ignoreParentAlpha ?? false,
1247
1252
  autosize: props.autosize ?? false,
1248
1253
  boundsMargin: props.boundsMargin ?? null,
1249
1254
  clipping: props.clipping ?? false,
@@ -1279,6 +1284,7 @@ function resolveNodeDefaults(
1279
1284
  pivotY: props.pivotY ?? props.pivot ?? 0.5,
1280
1285
  rotation: props.rotation ?? 0,
1281
1286
  rtt: props.rtt ?? false,
1287
+ placeholderColor: props.placeholderColor ?? 0,
1282
1288
  data: {},
1283
1289
  imageType: props.imageType,
1284
1290
  };
@@ -1807,6 +1813,22 @@ export class DOMNode extends EventEmitter implements IRendererNode {
1807
1813
  this.markChildrenBoundsDirty();
1808
1814
  }
1809
1815
 
1816
+ get ignoreParentAlpha(): boolean {
1817
+ return this.props.ignoreParentAlpha;
1818
+ }
1819
+ set ignoreParentAlpha(v: boolean) {
1820
+ this.props.ignoreParentAlpha = v;
1821
+ updateNodeStyles(this);
1822
+ }
1823
+
1824
+ get placeholderColor(): number {
1825
+ return this.props.placeholderColor;
1826
+ }
1827
+ set placeholderColor(v: number) {
1828
+ this.props.placeholderColor = v;
1829
+ updateNodeStyles(this);
1830
+ }
1831
+
1810
1832
  get absX(): number {
1811
1833
  const parent = this.props.parent;
1812
1834
  return (
@@ -16,7 +16,12 @@ import {
16
16
  type DollarString,
17
17
  } from './intrinsicTypes.js';
18
18
  import States, { type NodeStates } from './states.js';
19
- import calculateFlex from './flex.js';
19
+ import calculateFlexOld from './flex.js';
20
+ import calculateFlexNew from './flexLayout.js';
21
+
22
+ const calculateFlex = import.meta.env?.VITE_USE_NEW_FLEX
23
+ ? calculateFlexNew
24
+ : calculateFlexOld;
20
25
  import {
21
26
  log,
22
27
  isArray,
@@ -28,12 +33,8 @@ import {
28
33
  isFunction,
29
34
  spliceItem,
30
35
  } from './utils.js';
31
- import {
32
- Config,
33
- isDev,
34
- SHADERS_ENABLED,
35
- isDomRendererActive,
36
- } from './config.js';
36
+ import { isDev, SHADERS_ENABLED } from './env.js';
37
+ import { Config, isDomRendererActive } from './config.js';
37
38
  import type {
38
39
  RendererMain,
39
40
  INode,
@@ -50,7 +51,7 @@ import { assertTruthy } from '@solidtv/renderer/utils';
50
51
  import { NodeType, TextNode } from './nodeTypes.js';
51
52
  import {
52
53
  ForwardFocusHandler,
53
- setActiveElement,
54
+ setActiveElementCore,
54
55
  FocusNode,
55
56
  } from './focusManager.js';
56
57
  import { initClickInspector } from './clickInspector.js';
@@ -125,7 +126,7 @@ function runPostMutation() {
125
126
 
126
127
  // Phase 3: focus. setFocus() may have evaluated forwardFocus pre-render
127
128
  // (when no children existed yet); deferredFocusElement re-runs setFocus
128
- // here once the subtree has rendered, then setActiveElement is applied.
129
+ // here once the subtree has rendered, then setActiveElementCore is applied.
129
130
  if (deferredFocusElement !== null) {
130
131
  const el = deferredFocusElement;
131
132
  deferredFocusElement = null;
@@ -133,7 +134,7 @@ function runPostMutation() {
133
134
  } else if (nextActiveElement !== null) {
134
135
  const element = nextActiveElement;
135
136
  nextActiveElement = null;
136
- setActiveElement(element);
137
+ setActiveElementCore(element);
137
138
  }
138
139
  }
139
140
 
@@ -266,6 +267,7 @@ const LightningRendererNonAnimatingProps = [
266
267
  'fontStretch',
267
268
  'fontStyle',
268
269
  'group',
270
+ 'ignoreParentAlpha',
269
271
  'imageType',
270
272
  'letterSpacing',
271
273
  'maxHeight',
@@ -273,6 +275,7 @@ const LightningRendererNonAnimatingProps = [
273
275
  'maxWidth',
274
276
  'offsetY',
275
277
  'overflowSuffix',
278
+ 'placeholderColor',
276
279
  'preventCleanup',
277
280
  'rtt',
278
281
  'scrollable',
@@ -327,7 +330,7 @@ export interface ElementNode extends RendererNode, FocusNode {
327
330
  _animationQueueSettings?: AnimationSettings;
328
331
  _animationRunning?: boolean;
329
332
  _animationSettings?: AnimationSettings;
330
- _autofocus?: boolean;
333
+ _autofocus?: any;
331
334
  _containsFlexGrow?: boolean | null;
332
335
  _hasRenderedChildren?: boolean;
333
336
  _effects?: Record<string, any>;
@@ -788,6 +791,8 @@ export class ElementNode {
788
791
  shader: undefined,
789
792
  clipping: undefined,
790
793
  text: undefined,
794
+ ignoreParentAlpha: undefined,
795
+ placeholderColor: undefined,
791
796
  };
792
797
  this.children = [];
793
798
 
@@ -1311,7 +1316,7 @@ export class ElementNode {
1311
1316
  * @param val - A value to determine if the element should autofocus.
1312
1317
  * A truthy value enables autofocus, otherwise disables it.
1313
1318
  */
1314
- set autofocus(val: boolean | undefined) {
1319
+ set autofocus(val: any) {
1315
1320
  this._autofocus = val;
1316
1321
  // Defer setFocus so children render first (forwardFocus needs them).
1317
1322
  // The post-mutation focus phase calls setFocus on this element.
@@ -0,0 +1,11 @@
1
+ export const isDev = !!(import.meta.env && import.meta.env.DEV);
2
+
3
+ /** Whether the DOM renderer is used instead of `@solidtv/renderer` */
4
+ export const DOM_RENDERING =
5
+ typeof SOLIDTV_DOM_RENDERING !== 'undefined' &&
6
+ SOLIDTV_DOM_RENDERING === true;
7
+
8
+ /** Whether element shaders are enabled */
9
+ export const SHADERS_ENABLED =
10
+ typeof SOLIDTV_DISABLE_SHADERS === 'undefined' ||
11
+ SOLIDTV_DISABLE_SHADERS !== true;
package/src/core/flex.ts CHANGED
@@ -1,26 +1,6 @@
1
1
  import { type ElementNode } from './elementNode.js';
2
2
  import { isTextNode, isElementText } from './utils.js';
3
3
 
4
- function getArrayValue(
5
- val: number | number[] | undefined,
6
- index: number,
7
- defaultValue: number = 0,
8
- ): number {
9
- if (val === undefined) return defaultValue;
10
- if (typeof val === 'number') return val;
11
-
12
- const len = val.length;
13
- let result;
14
- if (len === 2) {
15
- result = index % 2 === 0 ? val[0] : val[1];
16
- } else if (len === 3) {
17
- result = index === 0 ? val[0] : index === 2 ? val[2] : val[1];
18
- } else {
19
- result = val[index];
20
- }
21
- return result ?? defaultValue;
22
- }
23
-
24
4
  export default function (node: ElementNode): boolean {
25
5
  const direction = node.flexDirection || 'row';
26
6
  const isRow = direction === 'row' || direction === 'row-reverse';
@@ -28,20 +8,10 @@ export default function (node: ElementNode): boolean {
28
8
  direction === 'row-reverse' || direction === 'column-reverse';
29
9
  const dimension = isRow ? 'width' : 'height';
30
10
  const crossDimension = isRow ? 'height' : 'width';
31
-
32
- // padding order: Top, Right, Bottom, Left
33
- const nodePadding = node.padding;
34
- const paddingTop = node.paddingTop ?? getArrayValue(nodePadding, 0);
35
- const paddingRight = node.paddingRight ?? getArrayValue(nodePadding, 1);
36
- const paddingBottom = node.paddingBottom ?? getArrayValue(nodePadding, 2);
37
- const paddingLeft = node.paddingLeft ?? getArrayValue(nodePadding, 3);
38
-
39
- const paddingStart = isRow ? paddingLeft : paddingTop;
40
- const paddingEnd = isRow ? paddingRight : paddingBottom;
41
- const paddingCrossStart = isRow ? paddingTop : paddingLeft;
42
- const paddingCrossEnd = isRow ? paddingBottom : paddingRight;
43
- const nodePaddingTotal = paddingStart + paddingEnd;
44
-
11
+ const marginOne = isRow ? 'marginLeft' : 'marginTop';
12
+ const crossMarginOne = isRow ? 'marginTop' : 'marginLeft';
13
+ const marginTwo = isRow ? 'marginRight' : 'marginBottom';
14
+ const crossMarginTwo = isRow ? 'marginBottom' : 'marginRight';
45
15
  const minDimension = isRow ? 'minWidth' : 'minHeight';
46
16
  const crossMinDimension = isRow ? 'minHeight' : 'minWidth';
47
17
 
@@ -52,17 +22,15 @@ export default function (node: ElementNode): boolean {
52
22
  return false;
53
23
  }
54
24
 
55
- // Optimize arrays caching
56
25
  const processableChildrenIndices: number[] = [];
57
26
  let hasOrder = false;
58
27
  let totalFlexGrow = 0;
59
- let totalFlexShrink = 0;
60
28
 
61
29
  for (let i = 0; i < numChildren; i++) {
62
30
  const c = children[i]!;
63
31
 
64
32
  if (isElementText(c) && c.text && !(c.width || c.height)) {
65
- return false; // specific text layout constraint
33
+ return false;
66
34
  }
67
35
 
68
36
  if (isTextNode(c) || c.flexItem === false) {
@@ -74,15 +42,10 @@ export default function (node: ElementNode): boolean {
74
42
  }
75
43
 
76
44
  const flexGrow = c.flexGrow;
77
- if (flexGrow !== undefined && flexGrow > 0) {
45
+ if (flexGrow !== undefined && flexGrow >= 0) {
78
46
  totalFlexGrow += flexGrow;
79
47
  }
80
48
 
81
- const flexShrink = c.flexShrink;
82
- if (flexShrink !== undefined && flexShrink > 0) {
83
- totalFlexShrink += flexShrink;
84
- }
85
-
86
49
  if (c[minDimension] && (c[dimension] || 0) < c[minDimension]) {
87
50
  c[dimension] = c[minDimension]!;
88
51
  }
@@ -105,14 +68,13 @@ export default function (node: ElementNode): boolean {
105
68
  });
106
69
  }
107
70
 
108
- // Apply reverse layout ordering
109
71
  if (isReverse || node.direction === 'rtl') {
110
72
  processableChildrenIndices.reverse();
111
73
  }
112
74
 
113
75
  const numProcessedChildren = processableChildrenIndices.length;
114
76
  if (numProcessedChildren === 0) {
115
- return false;
77
+ return false; // No layout changes if no processable children
116
78
  }
117
79
 
118
80
  const prop = isRow ? 'x' : 'y';
@@ -130,10 +92,9 @@ export default function (node: ElementNode): boolean {
130
92
  const isWrapReverse = node.flexWrap === 'wrap-reverse';
131
93
  const gap = node.gap || 0;
132
94
  const justify = node.justifyContent || 'flexStart';
133
- const align = node.alignItems || (node.flexWrap ? 'flexStart' : undefined);
95
+ const nodePadding = (node.padding as number) || 0;
134
96
  let containerUpdated = false;
135
97
 
136
- // Resolve sizes matching old processed calculation
137
98
  const childMainSizes = new Float32Array(numProcessedChildren);
138
99
  const childMarginStarts = new Float32Array(numProcessedChildren);
139
100
  const childMarginEnds = new Float32Array(numProcessedChildren);
@@ -146,55 +107,41 @@ export default function (node: ElementNode): boolean {
146
107
 
147
108
  for (let idx = 0; idx < numProcessedChildren; idx++) {
148
109
  const c = children[processableChildrenIndices[idx]!] as ElementNode;
149
- const marginArray = c.margin;
150
- // index mappings for margins: Top: 0, Right: 1, Bottom: 2, Left: 3
151
- // if row: main = left/right (3/1),
152
- const flexBasis = c.flexBasis;
153
- const isBasisAuto = flexBasis === undefined || flexBasis === 'auto';
154
- const computedBasis = isBasisAuto
155
- ? c[dimension] || 0
156
- : (flexBasis as number);
157
- const baseMainSize = isBasisAuto
158
- ? computedBasis
159
- : Math.max(computedBasis, c[minDimension] || 0);
160
-
161
- const marginStart = isRow
162
- ? c.marginLeft || getArrayValue(marginArray, 3)
163
- : c.marginTop || getArrayValue(marginArray, 0);
164
- const marginEnd = isRow
165
- ? c.marginRight || getArrayValue(marginArray, 1)
166
- : c.marginBottom || getArrayValue(marginArray, 2);
167
- const marginCrossStart = isRow
168
- ? c.marginTop || getArrayValue(marginArray, 0)
169
- : c.marginLeft || getArrayValue(marginArray, 3);
170
- const marginCrossEnd = isRow
171
- ? c.marginBottom || getArrayValue(marginArray, 2)
172
- : c.marginRight || getArrayValue(marginArray, 1);
110
+
111
+ const baseMainSize = c[dimension] || 0;
112
+ const marginStart = (c[marginOne] as number) || 0;
113
+ const marginEnd = (c[marginTwo] as number) || 0;
173
114
 
174
115
  childMainSizes[idx] = baseMainSize;
175
116
  childMarginStarts[idx] = marginStart;
176
117
  childMarginEnds[idx] = marginEnd;
177
118
  childTotalMainSizes[idx] = baseMainSize + marginStart + marginEnd;
119
+
178
120
  childCrossSizes[idx] = c[crossDimension] || 0;
179
- childMarginCrossStarts[idx] = marginCrossStart;
180
- childMarginCrossEnds[idx] = marginCrossEnd;
121
+ childMarginCrossStarts[idx] = (c[crossMarginOne] as number) || 0;
122
+ childMarginCrossEnds[idx] = (c[crossMarginTwo] as number) || 0;
181
123
 
182
124
  sumOfFlexBaseSizesWithMargins += childTotalMainSizes[idx]!;
183
125
  }
184
126
 
185
- if ((totalFlexGrow > 0 || totalFlexShrink > 0) && numProcessedChildren > 1) {
127
+ if (totalFlexGrow > 0 && numProcessedChildren > 1) {
128
+ // When flex-grow is used, the container's size is considered fixed for this calculation pass,
129
+ // unless flexBoundary is explicitly set to allow container resizing based on content.
186
130
  node.flexBoundary = node.flexBoundary || 'fixed';
187
131
 
132
+ // Calculate the total space occupied by gaps between items.
188
133
  const totalGapSpace =
189
134
  numProcessedChildren > 0 ? gap * (numProcessedChildren - 1) : 0;
135
+
136
+ // Calculate the available space for flex items to grow into.
190
137
  const availableSpace =
191
138
  containerSize - sumOfFlexBaseSizesWithMargins - totalGapSpace;
192
139
 
193
- if (availableSpace > 0 && totalFlexGrow > 0) {
140
+ if (availableSpace > 0) {
194
141
  for (let idx = 0; idx < numProcessedChildren; idx++) {
195
142
  const c = children[processableChildrenIndices[idx]!] as ElementNode;
196
- const flexGrowValue = c.flexGrow || 0;
197
- if (flexGrowValue > 0) {
143
+ const flexGrowValue = c.flexGrow;
144
+ if (flexGrowValue !== undefined && flexGrowValue > 0) {
198
145
  const shareOfSpace = (flexGrowValue / totalFlexGrow) * availableSpace;
199
146
  const newMainSize = childMainSizes[idx]! + shareOfSpace;
200
147
  c[dimension] = newMainSize;
@@ -203,43 +150,16 @@ export default function (node: ElementNode): boolean {
203
150
  newMainSize + childMarginStarts[idx]! + childMarginEnds[idx]!;
204
151
  }
205
152
  }
206
- node._containsFlexGrow = node._containsFlexGrow ? null : true;
207
- } else if (availableSpace < 0 && totalFlexShrink > 0) {
208
- // Flex Shrink Phase
209
- let totalScaledShrinkFactor = 0;
210
- for (let idx = 0; idx < numProcessedChildren; idx++) {
211
- const c = children[processableChildrenIndices[idx]!] as ElementNode;
212
- const flexShrinkValue = c.flexShrink || 0;
213
- totalScaledShrinkFactor += flexShrinkValue * childMainSizes[idx]!;
214
- }
215
-
216
- if (totalScaledShrinkFactor > 0) {
217
- for (let idx = 0; idx < numProcessedChildren; idx++) {
218
- const c = children[processableChildrenIndices[idx]!] as ElementNode;
219
- const flexShrinkValue = c.flexShrink || 0;
220
- if (flexShrinkValue > 0) {
221
- const shrinkRatio =
222
- (flexShrinkValue * childMainSizes[idx]!) /
223
- totalScaledShrinkFactor;
224
- const sizeReduction = shrinkRatio * Math.abs(availableSpace);
225
- let newMainSize = childMainSizes[idx]! - sizeReduction;
226
-
227
- // Constrain by min width/height
228
- const minBound = c[minDimension] || 0;
229
- if (newMainSize < minBound) {
230
- newMainSize = minBound;
231
- }
232
-
233
- c[dimension] = newMainSize;
234
- childMainSizes[idx] = newMainSize;
235
- childTotalMainSizes[idx] =
236
- newMainSize + childMarginStarts[idx]! + childMarginEnds[idx]!;
237
- }
238
- }
239
- }
153
+ // prevent infinite loops by only doing this once
240
154
  node._containsFlexGrow = node._containsFlexGrow ? null : true;
241
155
  } else if (node._containsFlexGrow) {
242
156
  node._containsFlexGrow = null;
157
+ } else {
158
+ // No positive space available for items to grow, or items overflow.
159
+ // flex-grow has no effect in this case.
160
+ console.warn(
161
+ 'No available space for flex-grow items to expand, or items overflow.',
162
+ );
243
163
  }
244
164
  }
245
165
 
@@ -255,6 +175,7 @@ export default function (node: ElementNode): boolean {
255
175
  }
256
176
  }
257
177
 
178
+ const align = node.alignItems || (node.flexWrap ? 'flexStart' : undefined);
258
179
  const doCrossAlign = containerCrossSize
259
180
  ? (c: ElementNode, idx: number, crossCurrentPos: number = 0) => {
260
181
  const alignSelf = c.alignSelf || align;
@@ -292,23 +213,23 @@ export default function (node: ElementNode): boolean {
292
213
  }
293
214
  }
294
215
 
295
- let currentPos = paddingStart;
216
+ let currentPos = nodePadding;
296
217
  if (justify === 'flexStart') {
297
- if (node.flexWrap === 'wrap') {
218
+ if (node.flexWrap === 'wrap' || isWrapReverse) {
298
219
  const childCrossSizeVar =
299
220
  numProcessedChildren > 0 ? childCrossSizes[0]! : containerCrossSize;
300
221
  let crossCurrentPos = isWrapReverse
301
- ? containerCrossSize - paddingCrossEnd - childCrossSizeVar
302
- : paddingCrossStart;
222
+ ? containerCrossSize - childCrossSizeVar
223
+ : 0;
303
224
  const crossGap = isRow ? (node.columnGap ?? gap) : (node.rowGap ?? gap);
304
225
 
305
226
  for (let idx = 0; idx < numProcessedChildren; idx++) {
306
227
  const c = children[processableChildrenIndices[idx]!] as ElementNode;
307
228
  if (
308
229
  currentPos + childTotalMainSizes[idx]! > containerSize &&
309
- currentPos > paddingStart
230
+ currentPos > nodePadding
310
231
  ) {
311
- currentPos = paddingStart;
232
+ currentPos = nodePadding;
312
233
  crossCurrentPos += isWrapReverse
313
234
  ? -(childCrossSizeVar + crossGap)
314
235
  : childCrossSizeVar + crossGap;
@@ -319,8 +240,8 @@ export default function (node: ElementNode): boolean {
319
240
  }
320
241
 
321
242
  const finalCrossSize = isWrapReverse
322
- ? containerCrossSize - crossCurrentPos + paddingCrossStart
323
- : crossCurrentPos + childCrossSizeVar + paddingCrossEnd;
243
+ ? containerCrossSize - crossCurrentPos
244
+ : crossCurrentPos + childCrossSizeVar;
324
245
 
325
246
  if (node[crossDimension] !== finalCrossSize) {
326
247
  node[`preFlex${crossDimension}`] = node[crossDimension];
@@ -332,77 +253,77 @@ export default function (node: ElementNode): boolean {
332
253
  const c = children[processableChildrenIndices[idx]!] as ElementNode;
333
254
  c[prop] = currentPos + childMarginStarts[idx]!;
334
255
  currentPos += childTotalMainSizes[idx]! + gap;
335
- doCrossAlign(c, idx, paddingCrossStart);
256
+ doCrossAlign(c, idx);
336
257
  }
337
258
  }
338
-
339
259
  // Update container size
340
260
  if (node.flexBoundary !== 'fixed' && node.flexWrap !== 'wrap') {
341
- let calculatedSize = currentPos - gap + paddingEnd;
261
+ let calculatedSize = currentPos - gap + nodePadding;
342
262
  const minSize = node[minDimension] || 0;
343
263
  if (calculatedSize < minSize) {
344
264
  calculatedSize = minSize;
345
265
  }
346
266
  if (calculatedSize !== (node[dimension] || 0)) {
267
+ // store the original size for Row & Column
347
268
  node[`preFlex${dimension}`] = containerSize;
348
269
  node[dimension] = calculatedSize;
349
270
  return true;
350
271
  }
351
272
  }
352
273
  } else if (justify === 'flexEnd') {
353
- currentPos = containerSize - paddingEnd;
274
+ currentPos = containerSize - nodePadding;
354
275
  for (let idx = numProcessedChildren - 1; idx >= 0; idx--) {
355
276
  const c = children[processableChildrenIndices[idx]!] as ElementNode;
356
277
  c[prop] = currentPos - childMainSizes[idx]! - childMarginEnds[idx]!;
357
278
  currentPos -= childTotalMainSizes[idx]! + gap;
358
- doCrossAlign(c, idx, paddingCrossStart);
279
+ doCrossAlign(c, idx);
359
280
  }
360
281
  } else if (justify === 'center') {
361
282
  currentPos =
362
283
  (containerSize - (totalItemSize + gap * (numProcessedChildren - 1))) / 2 +
363
- paddingStart;
284
+ nodePadding;
364
285
  for (let idx = 0; idx < numProcessedChildren; idx++) {
365
286
  const c = children[processableChildrenIndices[idx]!] as ElementNode;
366
287
  c[prop] = currentPos + childMarginStarts[idx]!;
367
288
  currentPos += childTotalMainSizes[idx]! + gap;
368
- doCrossAlign(c, idx, paddingCrossStart);
289
+ doCrossAlign(c, idx);
369
290
  }
370
291
  } else if (justify === 'spaceBetween') {
371
292
  const spaceBetween =
372
293
  numProcessedChildren > 1
373
- ? (containerSize - totalItemSize - nodePaddingTotal) /
294
+ ? (containerSize - totalItemSize - nodePadding * 2) /
374
295
  (numProcessedChildren - 1)
375
296
  : 0;
376
- currentPos = paddingStart;
297
+ currentPos = nodePadding;
377
298
  for (let idx = 0; idx < numProcessedChildren; idx++) {
378
299
  const c = children[processableChildrenIndices[idx]!] as ElementNode;
379
300
  c[prop] = currentPos + childMarginStarts[idx]!;
380
301
  currentPos += childTotalMainSizes[idx]! + spaceBetween;
381
- doCrossAlign(c, idx, paddingCrossStart);
302
+ doCrossAlign(c, idx);
382
303
  }
383
304
  } else if (justify === 'spaceAround') {
384
305
  const spaceAround =
385
306
  numProcessedChildren > 0
386
- ? (containerSize - totalItemSize - nodePaddingTotal) /
307
+ ? (containerSize - totalItemSize - nodePadding * 2) /
387
308
  numProcessedChildren
388
309
  : 0;
389
- currentPos = paddingStart + spaceAround / 2;
310
+ currentPos = nodePadding + spaceAround / 2;
390
311
  for (let idx = 0; idx < numProcessedChildren; idx++) {
391
312
  const c = children[processableChildrenIndices[idx]!] as ElementNode;
392
313
  c[prop] = currentPos + childMarginStarts[idx]!;
393
314
  currentPos += childTotalMainSizes[idx]! + spaceAround;
394
- doCrossAlign(c, idx, paddingCrossStart);
315
+ doCrossAlign(c, idx);
395
316
  }
396
317
  } else if (justify === 'spaceEvenly') {
397
318
  const spaceEvenly =
398
- (containerSize - totalItemSize - nodePaddingTotal) /
319
+ (containerSize - totalItemSize - nodePadding * 2) /
399
320
  (numProcessedChildren + 1);
400
- currentPos = spaceEvenly + paddingStart;
321
+ currentPos = spaceEvenly + nodePadding;
401
322
  for (let idx = 0; idx < numProcessedChildren; idx++) {
402
323
  const c = children[processableChildrenIndices[idx]!] as ElementNode;
403
324
  c[prop] = currentPos + childMarginStarts[idx]!;
404
325
  currentPos += childTotalMainSizes[idx]! + spaceEvenly;
405
- doCrossAlign(c, idx, paddingCrossStart);
326
+ doCrossAlign(c, idx);
406
327
  }
407
328
  }
408
329