@solidtv/solid 1.0.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.
- package/LICENSE +202 -0
- package/NOTICE +7 -0
- package/README.md +95 -0
- package/dist/jsx-runtime.d.ts +14 -0
- package/dist/src/activeElement.d.ts +2 -0
- package/dist/src/activeElement.js +3 -0
- package/dist/src/activeElement.js.map +1 -0
- package/dist/src/core/config.d.ts +51 -0
- package/dist/src/core/config.js +37 -0
- package/dist/src/core/config.js.map +1 -0
- package/dist/src/core/dom-renderer/domRenderer.d.ts +138 -0
- package/dist/src/core/dom-renderer/domRenderer.js +1844 -0
- package/dist/src/core/dom-renderer/domRenderer.js.map +1 -0
- package/dist/src/core/dom-renderer/domRendererTypes.d.ts +110 -0
- package/dist/src/core/dom-renderer/domRendererTypes.js +2 -0
- package/dist/src/core/dom-renderer/domRendererTypes.js.map +1 -0
- package/dist/src/core/dom-renderer/domRendererUtils.d.ts +23 -0
- package/dist/src/core/dom-renderer/domRendererUtils.js +232 -0
- package/dist/src/core/dom-renderer/domRendererUtils.js.map +1 -0
- package/dist/src/core/elementNode.d.ts +508 -0
- package/dist/src/core/elementNode.js +928 -0
- package/dist/src/core/elementNode.js.map +1 -0
- package/dist/src/core/flex.d.ts +2 -0
- package/dist/src/core/flex.js +284 -0
- package/dist/src/core/flex.js.map +1 -0
- package/dist/src/core/flexLayout.d.ts +2 -0
- package/dist/src/core/flexLayout.js +360 -0
- package/dist/src/core/flexLayout.js.map +1 -0
- package/dist/src/core/focusKeyTypes.d.ts +42 -0
- package/dist/src/core/focusKeyTypes.js +2 -0
- package/dist/src/core/focusKeyTypes.js.map +1 -0
- package/dist/src/core/focusManager.d.ts +13 -0
- package/dist/src/core/focusManager.js +270 -0
- package/dist/src/core/focusManager.js.map +1 -0
- package/dist/src/core/index.d.ts +14 -0
- package/dist/src/core/index.js +11 -0
- package/dist/src/core/index.js.map +1 -0
- package/dist/src/core/intrinsicTypes.d.ts +106 -0
- package/dist/src/core/intrinsicTypes.js +2 -0
- package/dist/src/core/intrinsicTypes.js.map +1 -0
- package/dist/src/core/lightningInit.d.ts +9 -0
- package/dist/src/core/lightningInit.js +34 -0
- package/dist/src/core/lightningInit.js.map +1 -0
- package/dist/src/core/nodeTypes.d.ts +6 -0
- package/dist/src/core/nodeTypes.js +6 -0
- package/dist/src/core/nodeTypes.js.map +1 -0
- package/dist/src/core/shaders.d.ts +52 -0
- package/dist/src/core/shaders.js +86 -0
- package/dist/src/core/shaders.js.map +1 -0
- package/dist/src/core/states.d.ts +12 -0
- package/dist/src/core/states.js +84 -0
- package/dist/src/core/states.js.map +1 -0
- package/dist/src/core/utils.d.ts +39 -0
- package/dist/src/core/utils.js +164 -0
- package/dist/src/core/utils.js.map +1 -0
- package/dist/src/devtools/index.d.ts +6 -0
- package/dist/src/devtools/index.js +65 -0
- package/dist/src/devtools/index.js.map +1 -0
- package/dist/src/index.d.ts +9 -0
- package/dist/src/index.js +7 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/primitives/Column.d.ts +3 -0
- package/dist/src/primitives/Column.jsx +25 -0
- package/dist/src/primitives/Column.jsx.map +1 -0
- package/dist/src/primitives/FPSCounter.d.ts +4 -0
- package/dist/src/primitives/FPSCounter.jsx +188 -0
- package/dist/src/primitives/FPSCounter.jsx.map +1 -0
- package/dist/src/primitives/FadeInOut.d.ts +18 -0
- package/dist/src/primitives/FadeInOut.jsx +39 -0
- package/dist/src/primitives/FadeInOut.jsx.map +1 -0
- package/dist/src/primitives/Grid.d.ts +23 -0
- package/dist/src/primitives/Grid.jsx +100 -0
- package/dist/src/primitives/Grid.jsx.map +1 -0
- package/dist/src/primitives/Image.d.ts +8 -0
- package/dist/src/primitives/Image.jsx +42 -0
- package/dist/src/primitives/Image.jsx.map +1 -0
- package/dist/src/primitives/KeepAlive.d.ts +42 -0
- package/dist/src/primitives/KeepAlive.jsx +160 -0
- package/dist/src/primitives/KeepAlive.jsx.map +1 -0
- package/dist/src/primitives/Lazy.d.ts +15 -0
- package/dist/src/primitives/Lazy.jsx +95 -0
- package/dist/src/primitives/Lazy.jsx.map +1 -0
- package/dist/src/primitives/LazyImport.d.ts +8 -0
- package/dist/src/primitives/LazyImport.js +40 -0
- package/dist/src/primitives/LazyImport.js.map +1 -0
- package/dist/src/primitives/Marquee.d.ts +64 -0
- package/dist/src/primitives/Marquee.jsx +86 -0
- package/dist/src/primitives/Marquee.jsx.map +1 -0
- package/dist/src/primitives/Preserve.d.ts +4 -0
- package/dist/src/primitives/Preserve.jsx +11 -0
- package/dist/src/primitives/Preserve.jsx.map +1 -0
- package/dist/src/primitives/Row.d.ts +3 -0
- package/dist/src/primitives/Row.jsx +24 -0
- package/dist/src/primitives/Row.jsx.map +1 -0
- package/dist/src/primitives/Suspense.d.ts +22 -0
- package/dist/src/primitives/Suspense.jsx +33 -0
- package/dist/src/primitives/Suspense.jsx.map +1 -0
- package/dist/src/primitives/Virtual.d.ts +18 -0
- package/dist/src/primitives/Virtual.jsx +495 -0
- package/dist/src/primitives/Virtual.jsx.map +1 -0
- package/dist/src/primitives/VirtualGrid.d.ts +13 -0
- package/dist/src/primitives/VirtualGrid.jsx +160 -0
- package/dist/src/primitives/VirtualGrid.jsx.map +1 -0
- package/dist/src/primitives/Visible.d.ts +6 -0
- package/dist/src/primitives/Visible.jsx +37 -0
- package/dist/src/primitives/Visible.jsx.map +1 -0
- package/dist/src/primitives/announcer/announcer.d.ts +40 -0
- package/dist/src/primitives/announcer/announcer.js +125 -0
- package/dist/src/primitives/announcer/announcer.js.map +1 -0
- package/dist/src/primitives/announcer/index.d.ts +6 -0
- package/dist/src/primitives/announcer/index.js +15 -0
- package/dist/src/primitives/announcer/index.js.map +1 -0
- package/dist/src/primitives/announcer/speech.d.ts +10 -0
- package/dist/src/primitives/announcer/speech.js +281 -0
- package/dist/src/primitives/announcer/speech.js.map +1 -0
- package/dist/src/primitives/borderBox.d.ts +8 -0
- package/dist/src/primitives/borderBox.jsx +47 -0
- package/dist/src/primitives/borderBox.jsx.map +1 -0
- package/dist/src/primitives/createFocusStack.d.ts +31 -0
- package/dist/src/primitives/createFocusStack.jsx +62 -0
- package/dist/src/primitives/createFocusStack.jsx.map +1 -0
- package/dist/src/primitives/createInfiniteItems.d.ts +27 -0
- package/dist/src/primitives/createInfiniteItems.js +46 -0
- package/dist/src/primitives/createInfiniteItems.js.map +1 -0
- package/dist/src/primitives/createTag.d.ts +8 -0
- package/dist/src/primitives/createTag.jsx +20 -0
- package/dist/src/primitives/createTag.jsx.map +1 -0
- package/dist/src/primitives/index.d.ts +32 -0
- package/dist/src/primitives/index.js +31 -0
- package/dist/src/primitives/index.js.map +1 -0
- package/dist/src/primitives/portal.d.ts +5 -0
- package/dist/src/primitives/portal.jsx +21 -0
- package/dist/src/primitives/portal.jsx.map +1 -0
- package/dist/src/primitives/router.d.ts +20 -0
- package/dist/src/primitives/router.js +90 -0
- package/dist/src/primitives/router.js.map +1 -0
- package/dist/src/primitives/types.d.ts +79 -0
- package/dist/src/primitives/types.js +2 -0
- package/dist/src/primitives/types.js.map +1 -0
- package/dist/src/primitives/useFocusManager.d.ts +5 -0
- package/dist/src/primitives/useFocusManager.js +21 -0
- package/dist/src/primitives/useFocusManager.js.map +1 -0
- package/dist/src/primitives/useHold.d.ts +27 -0
- package/dist/src/primitives/useHold.js +54 -0
- package/dist/src/primitives/useHold.js.map +1 -0
- package/dist/src/primitives/useMouse.d.ts +18 -0
- package/dist/src/primitives/useMouse.js +240 -0
- package/dist/src/primitives/useMouse.js.map +1 -0
- package/dist/src/primitives/utils/chainFunctions.d.ts +30 -0
- package/dist/src/primitives/utils/chainFunctions.js +32 -0
- package/dist/src/primitives/utils/chainFunctions.js.map +1 -0
- package/dist/src/primitives/utils/createBlurredImage.d.ts +56 -0
- package/dist/src/primitives/utils/createBlurredImage.js +223 -0
- package/dist/src/primitives/utils/createBlurredImage.js.map +1 -0
- package/dist/src/primitives/utils/createSpriteMap.d.ts +9 -0
- package/dist/src/primitives/utils/createSpriteMap.js +18 -0
- package/dist/src/primitives/utils/createSpriteMap.js.map +1 -0
- package/dist/src/primitives/utils/handleNavigation.d.ts +103 -0
- package/dist/src/primitives/utils/handleNavigation.js +300 -0
- package/dist/src/primitives/utils/handleNavigation.js.map +1 -0
- package/dist/src/primitives/utils/withScrolling.d.ts +22 -0
- package/dist/src/primitives/utils/withScrolling.js +186 -0
- package/dist/src/primitives/utils/withScrolling.js.map +1 -0
- package/dist/src/render.d.ts +28 -0
- package/dist/src/render.js +107 -0
- package/dist/src/render.js.map +1 -0
- package/dist/src/solidOpts.d.ts +15 -0
- package/dist/src/solidOpts.js +93 -0
- package/dist/src/solidOpts.js.map +1 -0
- package/dist/src/types.d.ts +11 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils.d.ts +19 -0
- package/dist/src/utils.js +94 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/docs/AI_CODING_GUIDELINES.md +108 -0
- package/docs/README.md +35 -0
- package/jsx-runtime.d.ts +14 -0
- package/package.json +125 -0
- package/src/activeElement.ts +5 -0
- package/src/core/config.ts +101 -0
- package/src/core/dom-renderer/domRenderer.ts +2066 -0
- package/src/core/dom-renderer/domRendererTypes.ts +148 -0
- package/src/core/dom-renderer/domRendererUtils.ts +292 -0
- package/src/core/elementNode.ts +1623 -0
- package/src/core/flex.ts +331 -0
- package/src/core/flexLayout.ts +414 -0
- package/src/core/focusKeyTypes.ts +90 -0
- package/src/core/focusManager.ts +374 -0
- package/src/core/index.ts +15 -0
- package/src/core/intrinsicTypes.ts +216 -0
- package/src/core/lightningInit.ts +45 -0
- package/src/core/nodeTypes.ts +6 -0
- package/src/core/shaders.ts +187 -0
- package/src/core/states.ts +91 -0
- package/src/core/utils.ts +222 -0
- package/src/devtools/index.ts +77 -0
- package/src/index.ts +18 -0
- package/src/primitives/Column.tsx +59 -0
- package/src/primitives/FPSCounter.tsx +209 -0
- package/src/primitives/FadeInOut.tsx +58 -0
- package/src/primitives/Grid.tsx +151 -0
- package/src/primitives/Image.tsx +56 -0
- package/src/primitives/KeepAlive.tsx +268 -0
- package/src/primitives/Lazy.tsx +128 -0
- package/src/primitives/LazyImport.ts +53 -0
- package/src/primitives/Marquee.tsx +149 -0
- package/src/primitives/Preserve.tsx +18 -0
- package/src/primitives/Row.tsx +58 -0
- package/src/primitives/Suspense.tsx +39 -0
- package/src/primitives/Virtual.tsx +602 -0
- package/src/primitives/VirtualGrid.tsx +220 -0
- package/src/primitives/Visible.tsx +59 -0
- package/src/primitives/announcer/announcer.ts +198 -0
- package/src/primitives/announcer/index.ts +20 -0
- package/src/primitives/announcer/speech.ts +334 -0
- package/src/primitives/borderBox.tsx +69 -0
- package/src/primitives/createFocusStack.tsx +79 -0
- package/src/primitives/createInfiniteItems.ts +66 -0
- package/src/primitives/createTag.tsx +33 -0
- package/src/primitives/index.ts +37 -0
- package/src/primitives/portal.tsx +25 -0
- package/src/primitives/router.ts +147 -0
- package/src/primitives/types.ts +109 -0
- package/src/primitives/useFocusManager.ts +47 -0
- package/src/primitives/useHold.ts +69 -0
- package/src/primitives/useMouse.ts +417 -0
- package/src/primitives/utils/chainFunctions.ts +60 -0
- package/src/primitives/utils/createBlurredImage.ts +366 -0
- package/src/primitives/utils/createSpriteMap.ts +32 -0
- package/src/primitives/utils/handleNavigation.ts +373 -0
- package/src/primitives/utils/withScrolling.ts +238 -0
- package/src/render.ts +164 -0
- package/src/solidOpts.ts +107 -0
- package/src/types.ts +22 -0
- package/src/utils.ts +129 -0
package/src/core/flex.ts
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import { type ElementNode } from './elementNode.js';
|
|
2
|
+
import { isTextNode, isElementText } from './utils.js';
|
|
3
|
+
|
|
4
|
+
export default function (node: ElementNode): boolean {
|
|
5
|
+
const direction = node.flexDirection || 'row';
|
|
6
|
+
const isRow = direction === 'row' || direction === 'row-reverse';
|
|
7
|
+
const isReverse =
|
|
8
|
+
direction === 'row-reverse' || direction === 'column-reverse';
|
|
9
|
+
const dimension = isRow ? 'width' : 'height';
|
|
10
|
+
const crossDimension = isRow ? 'height' : 'width';
|
|
11
|
+
const marginOne = isRow ? 'marginLeft' : 'marginTop';
|
|
12
|
+
const crossMarginOne = isRow ? 'marginTop' : 'marginLeft';
|
|
13
|
+
const marginTwo = isRow ? 'marginRight' : 'marginBottom';
|
|
14
|
+
const crossMarginTwo = isRow ? 'marginBottom' : 'marginRight';
|
|
15
|
+
const minDimension = isRow ? 'minWidth' : 'minHeight';
|
|
16
|
+
const crossMinDimension = isRow ? 'minHeight' : 'minWidth';
|
|
17
|
+
|
|
18
|
+
const children = node.children;
|
|
19
|
+
const numChildren = children.length;
|
|
20
|
+
|
|
21
|
+
if (numChildren === 0) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let processableChildrenIndices: number[] = [];
|
|
26
|
+
let hasOrder = false;
|
|
27
|
+
let totalFlexGrow = 0;
|
|
28
|
+
|
|
29
|
+
for (let i = 0; i < numChildren; i++) {
|
|
30
|
+
const c = children[i]!;
|
|
31
|
+
|
|
32
|
+
if (isElementText(c) && c.text && !(c.width || c.height)) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (isTextNode(c) || c.flexItem === false) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (c.flexOrder !== undefined) {
|
|
41
|
+
hasOrder = true;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const flexGrow = c.flexGrow;
|
|
45
|
+
if (flexGrow !== undefined && flexGrow >= 0) {
|
|
46
|
+
totalFlexGrow += flexGrow;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (c[minDimension] && (c[dimension] || 0) < c[minDimension]!) {
|
|
50
|
+
c[dimension] = c[minDimension]!;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (
|
|
54
|
+
c[crossMinDimension] &&
|
|
55
|
+
(c[crossDimension] || 0) < c[crossMinDimension]!
|
|
56
|
+
) {
|
|
57
|
+
c[crossDimension] = c[crossMinDimension]!;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
processableChildrenIndices.push(i);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (hasOrder) {
|
|
64
|
+
processableChildrenIndices.sort((aIdx, bIdx) => {
|
|
65
|
+
const a = children[aIdx] as ElementNode;
|
|
66
|
+
const b = children[bIdx] as ElementNode;
|
|
67
|
+
return (a.flexOrder || 0) - (b.flexOrder || 0);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (isReverse || node.direction === 'rtl') {
|
|
72
|
+
processableChildrenIndices.reverse();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const numProcessedChildren = processableChildrenIndices.length;
|
|
76
|
+
if (numProcessedChildren === 0) {
|
|
77
|
+
return false; // No layout changes if no processable children
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const prop = isRow ? 'x' : 'y';
|
|
81
|
+
const crossProp = isRow ? 'y' : 'x';
|
|
82
|
+
const containerSize = Math.max(
|
|
83
|
+
node[dimension] || 0,
|
|
84
|
+
node[minDimension] || 0,
|
|
85
|
+
0,
|
|
86
|
+
);
|
|
87
|
+
let containerCrossSize = Math.max(
|
|
88
|
+
node[crossDimension] || 0,
|
|
89
|
+
node[crossMinDimension] || 0,
|
|
90
|
+
0,
|
|
91
|
+
);
|
|
92
|
+
const isWrapReverse = node.flexWrap === 'wrap-reverse';
|
|
93
|
+
const gap = node.gap || 0;
|
|
94
|
+
const justify = node.justifyContent || 'flexStart';
|
|
95
|
+
const nodePadding = (node.padding as number) || 0;
|
|
96
|
+
let containerUpdated = false;
|
|
97
|
+
|
|
98
|
+
const childMainSizes = new Float32Array(numProcessedChildren);
|
|
99
|
+
const childMarginStarts = new Float32Array(numProcessedChildren);
|
|
100
|
+
const childMarginEnds = new Float32Array(numProcessedChildren);
|
|
101
|
+
const childTotalMainSizes = new Float32Array(numProcessedChildren);
|
|
102
|
+
const childCrossSizes = new Float32Array(numProcessedChildren);
|
|
103
|
+
const childMarginCrossStarts = new Float32Array(numProcessedChildren);
|
|
104
|
+
const childMarginCrossEnds = new Float32Array(numProcessedChildren);
|
|
105
|
+
|
|
106
|
+
let sumOfFlexBaseSizesWithMargins = 0;
|
|
107
|
+
|
|
108
|
+
for (let idx = 0; idx < numProcessedChildren; idx++) {
|
|
109
|
+
const c = children[processableChildrenIndices[idx]!] as ElementNode;
|
|
110
|
+
|
|
111
|
+
const baseMainSize = c[dimension] || 0;
|
|
112
|
+
const marginStart = (c[marginOne] as number) || 0;
|
|
113
|
+
const marginEnd = (c[marginTwo] as number) || 0;
|
|
114
|
+
|
|
115
|
+
childMainSizes[idx] = baseMainSize;
|
|
116
|
+
childMarginStarts[idx] = marginStart;
|
|
117
|
+
childMarginEnds[idx] = marginEnd;
|
|
118
|
+
childTotalMainSizes[idx] = baseMainSize + marginStart + marginEnd;
|
|
119
|
+
|
|
120
|
+
childCrossSizes[idx] = c[crossDimension] || 0;
|
|
121
|
+
childMarginCrossStarts[idx] = (c[crossMarginOne] as number) || 0;
|
|
122
|
+
childMarginCrossEnds[idx] = (c[crossMarginTwo] as number) || 0;
|
|
123
|
+
|
|
124
|
+
sumOfFlexBaseSizesWithMargins += childTotalMainSizes[idx]!;
|
|
125
|
+
}
|
|
126
|
+
|
|
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.
|
|
130
|
+
node.flexBoundary = node.flexBoundary || 'fixed';
|
|
131
|
+
|
|
132
|
+
// Calculate the total space occupied by gaps between items.
|
|
133
|
+
const totalGapSpace =
|
|
134
|
+
numProcessedChildren > 0 ? gap * (numProcessedChildren - 1) : 0;
|
|
135
|
+
|
|
136
|
+
// Calculate the available space for flex items to grow into.
|
|
137
|
+
const availableSpace =
|
|
138
|
+
containerSize - sumOfFlexBaseSizesWithMargins - totalGapSpace;
|
|
139
|
+
|
|
140
|
+
if (availableSpace > 0) {
|
|
141
|
+
for (let idx = 0; idx < numProcessedChildren; idx++) {
|
|
142
|
+
const c = children[processableChildrenIndices[idx]!] as ElementNode;
|
|
143
|
+
const flexGrowValue = c.flexGrow;
|
|
144
|
+
if (flexGrowValue !== undefined && flexGrowValue > 0) {
|
|
145
|
+
const shareOfSpace = (flexGrowValue / totalFlexGrow) * availableSpace;
|
|
146
|
+
const newMainSize = childMainSizes[idx]! + shareOfSpace;
|
|
147
|
+
c[dimension] = newMainSize;
|
|
148
|
+
childMainSizes[idx] = newMainSize;
|
|
149
|
+
childTotalMainSizes[idx] =
|
|
150
|
+
newMainSize + childMarginStarts[idx]! + childMarginEnds[idx]!;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// prevent infinite loops by only doing this once
|
|
154
|
+
node._containsFlexGrow = node._containsFlexGrow ? null : true;
|
|
155
|
+
} else if (node._containsFlexGrow) {
|
|
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
|
+
);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
let totalItemSize = 0;
|
|
167
|
+
if (
|
|
168
|
+
justify === 'center' ||
|
|
169
|
+
justify === 'spaceBetween' ||
|
|
170
|
+
justify === 'spaceEvenly' ||
|
|
171
|
+
justify === 'spaceAround'
|
|
172
|
+
) {
|
|
173
|
+
for (let idx = 0; idx < numProcessedChildren; idx++) {
|
|
174
|
+
totalItemSize += childTotalMainSizes[idx]!;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const align = node.alignItems || (node.flexWrap ? 'flexStart' : undefined);
|
|
179
|
+
const doCrossAlign = containerCrossSize
|
|
180
|
+
? (c: ElementNode, idx: number, crossCurrentPos: number = 0) => {
|
|
181
|
+
const alignSelf = c.alignSelf || align;
|
|
182
|
+
if (!alignSelf) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (alignSelf === 'flexStart') {
|
|
186
|
+
c[crossProp] = crossCurrentPos + childMarginCrossStarts[idx]!;
|
|
187
|
+
} else if (alignSelf === 'center') {
|
|
188
|
+
c[crossProp] =
|
|
189
|
+
crossCurrentPos +
|
|
190
|
+
(containerCrossSize - childCrossSizes[idx]!) / 2 +
|
|
191
|
+
childMarginCrossStarts[idx]!;
|
|
192
|
+
} else if (alignSelf === 'flexEnd') {
|
|
193
|
+
c[crossProp] =
|
|
194
|
+
crossCurrentPos +
|
|
195
|
+
containerCrossSize -
|
|
196
|
+
childCrossSizes[idx]! -
|
|
197
|
+
childMarginCrossEnds[idx]!;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
: (_c: ElementNode, _idx: number, _crossCurrentPos: number = 0) => {
|
|
201
|
+
/* no-op */
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
if (isRow && node._calcHeight && !node.flexCrossBoundary) {
|
|
205
|
+
let maxHeight = 0;
|
|
206
|
+
for (let idx = 0; idx < numProcessedChildren; idx++) {
|
|
207
|
+
if (childCrossSizes[idx]! > maxHeight) maxHeight = childCrossSizes[idx]!;
|
|
208
|
+
}
|
|
209
|
+
const newHeight = maxHeight || node.height;
|
|
210
|
+
if (newHeight !== node.height) {
|
|
211
|
+
containerUpdated = true;
|
|
212
|
+
node.height = containerCrossSize = newHeight;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
let currentPos = nodePadding;
|
|
217
|
+
if (justify === 'flexStart') {
|
|
218
|
+
if (node.flexWrap === 'wrap' || isWrapReverse) {
|
|
219
|
+
const childCrossSizeVar =
|
|
220
|
+
numProcessedChildren > 0 ? childCrossSizes[0]! : containerCrossSize;
|
|
221
|
+
let crossCurrentPos = isWrapReverse
|
|
222
|
+
? containerCrossSize - childCrossSizeVar
|
|
223
|
+
: 0;
|
|
224
|
+
const crossGap = isRow ? (node.columnGap ?? gap) : (node.rowGap ?? gap);
|
|
225
|
+
|
|
226
|
+
for (let idx = 0; idx < numProcessedChildren; idx++) {
|
|
227
|
+
const c = children[processableChildrenIndices[idx]!] as ElementNode;
|
|
228
|
+
if (
|
|
229
|
+
currentPos + childTotalMainSizes[idx]! > containerSize &&
|
|
230
|
+
currentPos > nodePadding
|
|
231
|
+
) {
|
|
232
|
+
currentPos = nodePadding;
|
|
233
|
+
crossCurrentPos += isWrapReverse
|
|
234
|
+
? -(childCrossSizeVar + crossGap)
|
|
235
|
+
: childCrossSizeVar + crossGap;
|
|
236
|
+
}
|
|
237
|
+
c[prop] = currentPos + childMarginStarts[idx]!;
|
|
238
|
+
currentPos += childTotalMainSizes[idx]! + gap;
|
|
239
|
+
doCrossAlign(c, idx, crossCurrentPos);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const finalCrossSize = isWrapReverse
|
|
243
|
+
? containerCrossSize - crossCurrentPos
|
|
244
|
+
: crossCurrentPos + childCrossSizeVar;
|
|
245
|
+
|
|
246
|
+
if (node[crossDimension] !== finalCrossSize) {
|
|
247
|
+
node[`preFlex${crossDimension}`] = node[crossDimension];
|
|
248
|
+
node[crossDimension] = finalCrossSize;
|
|
249
|
+
containerUpdated = true;
|
|
250
|
+
}
|
|
251
|
+
} else {
|
|
252
|
+
for (let idx = 0; idx < numProcessedChildren; idx++) {
|
|
253
|
+
const c = children[processableChildrenIndices[idx]!] as ElementNode;
|
|
254
|
+
c[prop] = currentPos + childMarginStarts[idx]!;
|
|
255
|
+
currentPos += childTotalMainSizes[idx]! + gap;
|
|
256
|
+
doCrossAlign(c, idx);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
// Update container size
|
|
260
|
+
if (node.flexBoundary !== 'fixed' && node.flexWrap !== 'wrap') {
|
|
261
|
+
let calculatedSize = currentPos - gap + nodePadding;
|
|
262
|
+
const minSize = node[minDimension] || 0;
|
|
263
|
+
if (calculatedSize < minSize) {
|
|
264
|
+
calculatedSize = minSize;
|
|
265
|
+
}
|
|
266
|
+
if (calculatedSize !== (node[dimension] || 0)) {
|
|
267
|
+
// store the original size for Row & Column
|
|
268
|
+
node[`preFlex${dimension}`] = containerSize;
|
|
269
|
+
node[dimension] = calculatedSize;
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
} else if (justify === 'flexEnd') {
|
|
274
|
+
currentPos = containerSize - nodePadding;
|
|
275
|
+
for (let idx = numProcessedChildren - 1; idx >= 0; idx--) {
|
|
276
|
+
const c = children[processableChildrenIndices[idx]!] as ElementNode;
|
|
277
|
+
c[prop] = currentPos - childMainSizes[idx]! - childMarginEnds[idx]!;
|
|
278
|
+
currentPos -= childTotalMainSizes[idx]! + gap;
|
|
279
|
+
doCrossAlign(c, idx);
|
|
280
|
+
}
|
|
281
|
+
} else if (justify === 'center') {
|
|
282
|
+
currentPos =
|
|
283
|
+
(containerSize - (totalItemSize + gap * (numProcessedChildren - 1))) / 2 +
|
|
284
|
+
nodePadding;
|
|
285
|
+
for (let idx = 0; idx < numProcessedChildren; idx++) {
|
|
286
|
+
const c = children[processableChildrenIndices[idx]!] as ElementNode;
|
|
287
|
+
c[prop] = currentPos + childMarginStarts[idx]!;
|
|
288
|
+
currentPos += childTotalMainSizes[idx]! + gap;
|
|
289
|
+
doCrossAlign(c, idx);
|
|
290
|
+
}
|
|
291
|
+
} else if (justify === 'spaceBetween') {
|
|
292
|
+
const spaceBetween =
|
|
293
|
+
numProcessedChildren > 1
|
|
294
|
+
? (containerSize - totalItemSize - nodePadding * 2) /
|
|
295
|
+
(numProcessedChildren - 1)
|
|
296
|
+
: 0;
|
|
297
|
+
currentPos = nodePadding;
|
|
298
|
+
for (let idx = 0; idx < numProcessedChildren; idx++) {
|
|
299
|
+
const c = children[processableChildrenIndices[idx]!] as ElementNode;
|
|
300
|
+
c[prop] = currentPos + childMarginStarts[idx]!;
|
|
301
|
+
currentPos += childTotalMainSizes[idx]! + spaceBetween;
|
|
302
|
+
doCrossAlign(c, idx);
|
|
303
|
+
}
|
|
304
|
+
} else if (justify === 'spaceAround') {
|
|
305
|
+
const spaceAround =
|
|
306
|
+
numProcessedChildren > 0
|
|
307
|
+
? (containerSize - totalItemSize - nodePadding * 2) /
|
|
308
|
+
numProcessedChildren
|
|
309
|
+
: 0;
|
|
310
|
+
currentPos = nodePadding + spaceAround / 2;
|
|
311
|
+
for (let idx = 0; idx < numProcessedChildren; idx++) {
|
|
312
|
+
const c = children[processableChildrenIndices[idx]!] as ElementNode;
|
|
313
|
+
c[prop] = currentPos + childMarginStarts[idx]!;
|
|
314
|
+
currentPos += childTotalMainSizes[idx]! + spaceAround;
|
|
315
|
+
doCrossAlign(c, idx);
|
|
316
|
+
}
|
|
317
|
+
} else if (justify === 'spaceEvenly') {
|
|
318
|
+
const spaceEvenly =
|
|
319
|
+
(containerSize - totalItemSize - nodePadding * 2) /
|
|
320
|
+
(numProcessedChildren + 1);
|
|
321
|
+
currentPos = spaceEvenly + nodePadding;
|
|
322
|
+
for (let idx = 0; idx < numProcessedChildren; idx++) {
|
|
323
|
+
const c = children[processableChildrenIndices[idx]!] as ElementNode;
|
|
324
|
+
c[prop] = currentPos + childMarginStarts[idx]!;
|
|
325
|
+
currentPos += childTotalMainSizes[idx]! + spaceEvenly;
|
|
326
|
+
doCrossAlign(c, idx);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return containerUpdated;
|
|
331
|
+
}
|