@solidtv/solid 1.3.0-0 → 1.3.0

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 (46) 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/config.d.ts +8 -0
  5. package/dist/src/core/config.js +2 -0
  6. package/dist/src/core/config.js.map +1 -1
  7. package/dist/src/core/dom-renderer/domRenderer.d.ts +6 -2
  8. package/dist/src/core/dom-renderer/domRenderer.js +24 -4
  9. package/dist/src/core/dom-renderer/domRenderer.js.map +1 -1
  10. package/dist/src/core/elementNode.js +12 -4
  11. package/dist/src/core/elementNode.js.map +1 -1
  12. package/dist/src/core/flex.js +52 -124
  13. package/dist/src/core/flex.js.map +1 -1
  14. package/dist/src/core/flexLayout.d.ts +2 -0
  15. package/dist/src/core/flexLayout.js +356 -0
  16. package/dist/src/core/flexLayout.js.map +1 -0
  17. package/dist/src/core/focusKeyTypes.d.ts +0 -14
  18. package/dist/src/core/focusManager.d.ts +10 -16
  19. package/dist/src/core/focusManager.js +28 -27
  20. package/dist/src/core/focusManager.js.map +1 -1
  21. package/dist/src/core/utils.d.ts +4 -2
  22. package/dist/src/core/utils.js.map +1 -1
  23. package/dist/src/index.d.ts +2 -1
  24. package/dist/src/index.js +2 -1
  25. package/dist/src/index.js.map +1 -1
  26. package/dist/src/primitives/index.d.ts +1 -0
  27. package/dist/src/primitives/useFocusManager.d.ts +2 -1
  28. package/dist/src/primitives/useFocusManager.js +2 -1
  29. package/dist/src/primitives/useFocusManager.js.map +1 -1
  30. package/dist/src/render.js +1 -1
  31. package/dist/src/render.js.map +1 -1
  32. package/dist/tsconfig.tsbuildinfo +1 -1
  33. package/package.json +2 -2
  34. package/src/core/activeElement.ts +24 -0
  35. package/src/core/config.ts +10 -0
  36. package/src/core/dom-renderer/domRenderer.ts +26 -4
  37. package/src/core/elementNode.ts +13 -4
  38. package/src/core/flex.ts +56 -135
  39. package/src/core/flexLayout.ts +410 -0
  40. package/src/core/focusKeyTypes.ts +0 -14
  41. package/src/core/focusManager.ts +34 -42
  42. package/src/core/utils.ts +4 -2
  43. package/src/index.ts +2 -1
  44. package/src/primitives/index.ts +1 -0
  45. package/src/primitives/useFocusManager.ts +2 -2
  46. 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.0",
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);
@@ -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,
@@ -63,6 +64,14 @@ export interface Config {
63
64
  animationsEnabled: boolean;
64
65
  fontSettings: Partial<TextProps>;
65
66
  rendererOptions?: Partial<RendererMainSettings> | DomRendererMainSettings;
67
+ /**
68
+ * Hook the focus manager calls to publish the active element. Defaults to
69
+ * writing the {@link activeElement} signal directly; a custom focus manager
70
+ * (or the built-in `useFocusManager`) may reassign this — e.g. to run the
71
+ * write inside a captured Solid owner context. This is the seam that keeps
72
+ * the `activeElement` signal decoupled from focus-manager logic.
73
+ */
74
+ setActiveElement: (elm: ElementNode) => void;
66
75
  focusStateKey: DollarString;
67
76
  lockStyles?: boolean;
68
77
  fontWeightAlias?: Record<string, number | string>;
@@ -84,6 +93,7 @@ export const Config: Config = {
84
93
  easing: 'ease-in-out',
85
94
  },
86
95
  convertToShader: defaultConvertToShader,
96
+ setActiveElement: (elm) => setActiveElementSignal(elm),
87
97
  fontSettings: {
88
98
  fontFamily: 'Ubuntu',
89
99
  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,
@@ -50,7 +55,7 @@ import { assertTruthy } from '@solidtv/renderer/utils';
50
55
  import { NodeType, TextNode } from './nodeTypes.js';
51
56
  import {
52
57
  ForwardFocusHandler,
53
- setActiveElement,
58
+ setActiveElementCore,
54
59
  FocusNode,
55
60
  } from './focusManager.js';
56
61
  import { initClickInspector } from './clickInspector.js';
@@ -125,7 +130,7 @@ function runPostMutation() {
125
130
 
126
131
  // Phase 3: focus. setFocus() may have evaluated forwardFocus pre-render
127
132
  // (when no children existed yet); deferredFocusElement re-runs setFocus
128
- // here once the subtree has rendered, then setActiveElement is applied.
133
+ // here once the subtree has rendered, then setActiveElementCore is applied.
129
134
  if (deferredFocusElement !== null) {
130
135
  const el = deferredFocusElement;
131
136
  deferredFocusElement = null;
@@ -133,7 +138,7 @@ function runPostMutation() {
133
138
  } else if (nextActiveElement !== null) {
134
139
  const element = nextActiveElement;
135
140
  nextActiveElement = null;
136
- setActiveElement(element);
141
+ setActiveElementCore(element);
137
142
  }
138
143
  }
139
144
 
@@ -266,6 +271,7 @@ const LightningRendererNonAnimatingProps = [
266
271
  'fontStretch',
267
272
  'fontStyle',
268
273
  'group',
274
+ 'ignoreParentAlpha',
269
275
  'imageType',
270
276
  'letterSpacing',
271
277
  'maxHeight',
@@ -273,6 +279,7 @@ const LightningRendererNonAnimatingProps = [
273
279
  'maxWidth',
274
280
  'offsetY',
275
281
  'overflowSuffix',
282
+ 'placeholderColor',
276
283
  'preventCleanup',
277
284
  'rtt',
278
285
  'scrollable',
@@ -788,6 +795,8 @@ export class ElementNode {
788
795
  shader: undefined,
789
796
  clipping: undefined,
790
797
  text: undefined,
798
+ ignoreParentAlpha: undefined,
799
+ placeholderColor: undefined,
791
800
  };
792
801
  this.children = [];
793
802
 
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