@lightningtv/solid 3.0.0-2 → 3.0.0-21
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 +1 -1
- package/README.md +6 -0
- package/dist/src/activeElement.d.ts +1 -1
- package/dist/src/core/animation.d.ts +35 -0
- package/dist/src/core/animation.js +120 -0
- package/dist/src/core/animation.js.map +1 -0
- package/dist/src/core/config.d.ts +47 -0
- package/dist/src/core/config.js +23 -0
- package/dist/src/core/config.js.map +1 -0
- package/dist/src/core/domRenderer.d.ts +117 -0
- package/dist/src/core/domRenderer.js +1160 -0
- package/dist/src/core/domRenderer.js.map +1 -0
- package/dist/src/core/elementNode.d.ts +209 -0
- package/dist/src/core/elementNode.js +829 -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 +243 -0
- package/dist/src/core/flex.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 +269 -0
- package/dist/src/core/focusManager.js.map +1 -0
- package/dist/src/core/index.d.ts +12 -0
- package/dist/src/core/index.js +12 -0
- package/dist/src/core/index.js.map +1 -0
- package/dist/src/core/intrinsicTypes.d.ts +90 -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 +89 -0
- package/dist/src/core/lightningInit.js +26 -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 +51 -0
- package/dist/src/core/shaders.js +446 -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/timings.d.ts +36 -0
- package/dist/src/core/timings.js +199 -0
- package/dist/src/core/timings.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 +1 -1
- package/dist/src/devtools/index.js +1 -1
- package/dist/src/devtools/index.js.map +1 -1
- package/dist/src/index.d.ts +3 -3
- package/dist/src/index.js +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/jsx-runtime.d.ts +1 -3
- package/dist/src/primitives/Column.jsx +9 -10
- package/dist/src/primitives/Column.jsx.map +1 -1
- package/dist/src/primitives/FPSCounter.jsx +14 -1
- package/dist/src/primitives/FPSCounter.jsx.map +1 -1
- package/dist/src/primitives/Grid.d.ts +15 -6
- package/dist/src/primitives/Grid.jsx +35 -22
- package/dist/src/primitives/Grid.jsx.map +1 -1
- package/dist/src/primitives/Image.d.ts +8 -0
- package/dist/src/primitives/Image.jsx +24 -0
- package/dist/src/primitives/Image.jsx.map +1 -0
- package/dist/src/primitives/KeepAlive.d.ts +30 -0
- package/dist/src/primitives/KeepAlive.jsx +77 -0
- package/dist/src/primitives/KeepAlive.jsx.map +1 -0
- package/dist/src/primitives/Lazy.d.ts +8 -7
- package/dist/src/primitives/Lazy.jsx +52 -23
- package/dist/src/primitives/Lazy.jsx.map +1 -1
- 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.jsx +9 -10
- package/dist/src/primitives/Row.jsx.map +1 -1
- 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 +434 -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/VirtualList.d.ts +11 -0
- package/dist/src/primitives/VirtualList.jsx +96 -0
- package/dist/src/primitives/VirtualList.jsx.map +1 -0
- package/dist/src/primitives/VirtualRow.d.ts +13 -0
- package/dist/src/primitives/VirtualRow.jsx +97 -0
- package/dist/src/primitives/VirtualRow.jsx.map +1 -0
- package/dist/src/primitives/Visible.d.ts +0 -1
- package/dist/src/primitives/Visible.jsx +1 -1
- package/dist/src/primitives/Visible.jsx.map +1 -1
- package/dist/src/primitives/announcer/announcer.d.ts +2 -0
- package/dist/src/primitives/announcer/announcer.js +7 -5
- package/dist/src/primitives/announcer/announcer.js.map +1 -1
- package/dist/src/primitives/announcer/index.d.ts +5 -1
- package/dist/src/primitives/announcer/index.js +8 -2
- package/dist/src/primitives/announcer/index.js.map +1 -1
- package/dist/src/primitives/announcer/speech.d.ts +2 -2
- package/dist/src/primitives/announcer/speech.js +157 -28
- package/dist/src/primitives/announcer/speech.js.map +1 -1
- package/dist/src/primitives/createFocusStack.d.ts +4 -4
- package/dist/src/primitives/createFocusStack.jsx +15 -6
- package/dist/src/primitives/createFocusStack.jsx.map +1 -1
- 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 +14 -4
- package/dist/src/primitives/index.js +13 -3
- package/dist/src/primitives/index.js.map +1 -1
- package/dist/src/primitives/types.d.ts +5 -2
- package/dist/src/primitives/useFocusManager.d.ts +2 -2
- package/dist/src/primitives/useFocusManager.js +2 -2
- package/dist/src/primitives/useFocusManager.js.map +1 -1
- 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 -2
- package/dist/src/primitives/useMouse.js +171 -47
- package/dist/src/primitives/useMouse.js.map +1 -1
- package/dist/src/primitives/utils/chainFunctions.d.ts +30 -4
- package/dist/src/primitives/utils/chainFunctions.js +14 -3
- package/dist/src/primitives/utils/chainFunctions.js.map +1 -1
- 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 +2 -2
- package/dist/src/primitives/utils/createSpriteMap.js +1 -1
- package/dist/src/primitives/utils/createSpriteMap.js.map +1 -1
- package/dist/src/primitives/utils/handleNavigation.d.ts +79 -5
- package/dist/src/primitives/utils/handleNavigation.js +242 -69
- package/dist/src/primitives/utils/handleNavigation.js.map +1 -1
- package/dist/src/primitives/utils/withScrolling.d.ts +14 -2
- package/dist/src/primitives/utils/withScrolling.js +66 -7
- package/dist/src/primitives/utils/withScrolling.js.map +1 -1
- package/dist/src/render.d.ts +8 -7
- package/dist/src/render.js +5 -1
- package/dist/src/render.js.map +1 -1
- package/dist/src/solidOpts.d.ts +1 -7
- package/dist/src/solidOpts.js +32 -16
- package/dist/src/solidOpts.js.map +1 -1
- package/dist/src/types.d.ts +1 -13
- package/dist/src/universal.d.ts +25 -0
- package/dist/src/universal.js +232 -0
- package/dist/src/universal.js.map +1 -0
- package/dist/src/utils.d.ts +3 -1
- package/dist/src/utils.js +9 -1
- package/dist/src/utils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/jsx-runtime.d.ts +2 -4
- package/package.json +17 -15
- package/src/activeElement.ts +1 -1
- package/src/core/animation.ts +183 -0
- package/src/core/config.ts +77 -0
- package/src/core/domRenderer.ts +1308 -0
- package/src/core/elementNode.ts +1198 -0
- package/src/core/flex.ts +284 -0
- package/src/core/focusKeyTypes.ts +87 -0
- package/src/core/focusManager.ts +359 -0
- package/src/core/index.ts +13 -0
- package/src/core/intrinsicTypes.ts +199 -0
- package/src/core/lightningInit.ts +147 -0
- package/src/core/nodeTypes.ts +6 -0
- package/src/core/shaders.ts +567 -0
- package/src/core/states.ts +91 -0
- package/src/core/timings.ts +261 -0
- package/src/core/utils.ts +222 -0
- package/src/devtools/index.ts +1 -1
- package/src/index.ts +3 -3
- package/src/primitives/Column.tsx +10 -12
- package/src/primitives/FPSCounter.tsx +15 -1
- package/src/primitives/Grid.tsx +57 -33
- package/src/primitives/Image.tsx +36 -0
- package/src/primitives/KeepAlive.tsx +124 -0
- package/src/primitives/Lazy.tsx +66 -37
- package/src/primitives/Marquee.tsx +149 -0
- package/src/primitives/Preserve.tsx +18 -0
- package/src/primitives/Row.tsx +13 -14
- package/src/primitives/Suspense.tsx +39 -0
- package/src/primitives/Virtual.tsx +478 -0
- package/src/primitives/VirtualGrid.tsx +220 -0
- package/src/primitives/Visible.tsx +1 -2
- package/src/primitives/announcer/announcer.ts +16 -10
- package/src/primitives/announcer/index.ts +12 -2
- package/src/primitives/announcer/speech.ts +188 -27
- package/src/primitives/createFocusStack.tsx +18 -7
- package/src/primitives/createTag.tsx +31 -0
- package/src/primitives/index.ts +18 -4
- package/src/primitives/types.ts +12 -2
- package/src/primitives/useFocusManager.ts +3 -3
- package/src/primitives/useHold.ts +69 -0
- package/src/primitives/useMouse.ts +306 -67
- package/src/primitives/utils/chainFunctions.ts +40 -9
- package/src/primitives/utils/createBlurredImage.ts +366 -0
- package/src/primitives/utils/createSpriteMap.ts +6 -4
- package/src/primitives/utils/handleNavigation.ts +300 -84
- package/src/primitives/utils/withScrolling.ts +91 -18
- package/src/render.ts +10 -8
- package/src/solidOpts.ts +31 -24
- package/src/types.ts +1 -15
- package/src/utils.ts +11 -1
package/src/core/flex.ts
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import { type ElementNode } from './elementNode.js';
|
|
2
|
+
import { isTextNode, isElementText } from './utils.js';
|
|
3
|
+
|
|
4
|
+
interface ProcessedChild {
|
|
5
|
+
node: ElementNode;
|
|
6
|
+
mainSize: number;
|
|
7
|
+
marginStart: number;
|
|
8
|
+
marginEnd: number;
|
|
9
|
+
totalMainSizeOnAxis: number;
|
|
10
|
+
isGrowItem: boolean;
|
|
11
|
+
flexGrowValue: number;
|
|
12
|
+
flexOrder: number;
|
|
13
|
+
crossSize: number;
|
|
14
|
+
crossMarginStart: number;
|
|
15
|
+
crossMarginEnd: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default function (node: ElementNode): boolean {
|
|
19
|
+
const direction = node.flexDirection || 'row';
|
|
20
|
+
const isRow = direction === 'row';
|
|
21
|
+
const dimension = isRow ? 'width' : 'height';
|
|
22
|
+
const crossDimension = isRow ? 'height' : 'width';
|
|
23
|
+
const marginOne = isRow ? 'marginLeft' : 'marginTop';
|
|
24
|
+
const crossMarginOne = isRow ? 'marginTop' : 'marginLeft';
|
|
25
|
+
const marginTwo = isRow ? 'marginRight' : 'marginBottom';
|
|
26
|
+
const crossMarginTwo = isRow ? 'marginBottom' : 'marginRight';
|
|
27
|
+
|
|
28
|
+
const processedChildren: ProcessedChild[] = [];
|
|
29
|
+
let hasOrder = false;
|
|
30
|
+
let totalFlexGrow = 0;
|
|
31
|
+
|
|
32
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
33
|
+
const c = node.children[i]!;
|
|
34
|
+
|
|
35
|
+
if (isElementText(c) && c.text && !(c.width || c.height)) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (isTextNode(c) || c.flexItem === false) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const flexOrder = c.flexOrder;
|
|
44
|
+
if (flexOrder !== undefined) {
|
|
45
|
+
hasOrder = true;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const flexGrow = c.flexGrow;
|
|
49
|
+
const isGrowItem = flexGrow !== undefined && flexGrow >= 0;
|
|
50
|
+
if (isGrowItem) {
|
|
51
|
+
totalFlexGrow += flexGrow!;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const mainSize = c[dimension] || 0;
|
|
55
|
+
const currentMarginStart = c[marginOne] || 0;
|
|
56
|
+
const currentMarginEnd = c[marginTwo] || 0;
|
|
57
|
+
|
|
58
|
+
processedChildren.push({
|
|
59
|
+
node: c as ElementNode,
|
|
60
|
+
mainSize: mainSize,
|
|
61
|
+
marginStart: currentMarginStart,
|
|
62
|
+
marginEnd: currentMarginEnd,
|
|
63
|
+
totalMainSizeOnAxis: mainSize + currentMarginStart + currentMarginEnd,
|
|
64
|
+
isGrowItem: isGrowItem,
|
|
65
|
+
flexGrowValue: isGrowItem ? flexGrow! : 0,
|
|
66
|
+
flexOrder: flexOrder || 0,
|
|
67
|
+
crossSize: c[crossDimension] || 0,
|
|
68
|
+
crossMarginStart: c[crossMarginOne] || 0,
|
|
69
|
+
crossMarginEnd: c[crossMarginTwo] || 0,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (hasOrder) {
|
|
74
|
+
processedChildren.sort((a, b) => a.flexOrder - b.flexOrder);
|
|
75
|
+
} else if (node.direction === 'rtl') {
|
|
76
|
+
processedChildren.reverse();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const numProcessedChildren = processedChildren.length;
|
|
80
|
+
if (numProcessedChildren === 0) {
|
|
81
|
+
return false; // No layout changes if no processable children
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const prop = isRow ? 'x' : 'y';
|
|
85
|
+
const crossProp = isRow ? 'y' : 'x';
|
|
86
|
+
const containerSize = node[dimension] || 0;
|
|
87
|
+
let containerCrossSize = node[crossDimension] || 0;
|
|
88
|
+
const gap = node.gap || 0;
|
|
89
|
+
const justify = node.justifyContent || 'flexStart';
|
|
90
|
+
let containerUpdated = false;
|
|
91
|
+
|
|
92
|
+
if (totalFlexGrow > 0 && numProcessedChildren > 1) {
|
|
93
|
+
// When flex-grow is used, the container's size is considered fixed for this calculation pass,
|
|
94
|
+
// unless flexBoundary is explicitly set to allow container resizing based on content.
|
|
95
|
+
node.flexBoundary = node.flexBoundary || 'fixed';
|
|
96
|
+
|
|
97
|
+
// Determine the sum of the flex base sizes of all items.
|
|
98
|
+
// The flex base size is the item's mainSize before flex-grow is applied.
|
|
99
|
+
let sumOfFlexBaseSizesWithMargins = 0;
|
|
100
|
+
for (const pc of processedChildren) {
|
|
101
|
+
sumOfFlexBaseSizesWithMargins +=
|
|
102
|
+
pc.mainSize + pc.marginStart + pc.marginEnd;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Calculate the total space occupied by gaps between items.
|
|
106
|
+
const totalGapSpace =
|
|
107
|
+
numProcessedChildren > 0 ? gap * (numProcessedChildren - 1) : 0;
|
|
108
|
+
|
|
109
|
+
// Calculate the available space for flex items to grow into.
|
|
110
|
+
const availableSpace =
|
|
111
|
+
containerSize - sumOfFlexBaseSizesWithMargins - totalGapSpace;
|
|
112
|
+
|
|
113
|
+
if (availableSpace > 0) {
|
|
114
|
+
for (const pc of processedChildren) {
|
|
115
|
+
if (pc.isGrowItem && pc.flexGrowValue > 0) {
|
|
116
|
+
const shareOfSpace =
|
|
117
|
+
(pc.flexGrowValue / totalFlexGrow) * availableSpace;
|
|
118
|
+
const newMainSize = pc.mainSize + shareOfSpace;
|
|
119
|
+
pc.node[dimension] = newMainSize;
|
|
120
|
+
pc.mainSize = newMainSize;
|
|
121
|
+
pc.totalMainSizeOnAxis = newMainSize + pc.marginStart + pc.marginEnd;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// prevent infinite loops by only doing this once
|
|
125
|
+
node._containsFlexGrow = node._containsFlexGrow ? null : true;
|
|
126
|
+
} else if (node._containsFlexGrow) {
|
|
127
|
+
node._containsFlexGrow = null;
|
|
128
|
+
} else {
|
|
129
|
+
// No positive space available for items to grow, or items overflow.
|
|
130
|
+
// flex-grow has no effect in this case.
|
|
131
|
+
console.warn(
|
|
132
|
+
'No available space for flex-grow items to expand, or items overflow.',
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
let totalItemSize = 0;
|
|
138
|
+
if (
|
|
139
|
+
justify === 'center' ||
|
|
140
|
+
justify === 'spaceBetween' ||
|
|
141
|
+
justify === 'spaceEvenly' ||
|
|
142
|
+
justify === 'spaceAround'
|
|
143
|
+
) {
|
|
144
|
+
for (const pc of processedChildren) {
|
|
145
|
+
totalItemSize += pc.totalMainSizeOnAxis;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const align = node.alignItems || (node.flexWrap ? 'flexStart' : undefined);
|
|
150
|
+
const doCrossAlign = containerCrossSize
|
|
151
|
+
? (pc: ProcessedChild, crossCurrentPos: number = 0) => {
|
|
152
|
+
const alignSelf = pc.node.alignSelf || align;
|
|
153
|
+
if (!alignSelf) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (alignSelf === 'flexStart') {
|
|
157
|
+
pc.node[crossProp] = crossCurrentPos + pc.crossMarginStart;
|
|
158
|
+
} else if (alignSelf === 'center') {
|
|
159
|
+
pc.node[crossProp] =
|
|
160
|
+
crossCurrentPos +
|
|
161
|
+
(containerCrossSize - pc.crossSize) / 2 +
|
|
162
|
+
pc.crossMarginStart;
|
|
163
|
+
} else if (alignSelf === 'flexEnd') {
|
|
164
|
+
pc.node[crossProp] =
|
|
165
|
+
crossCurrentPos +
|
|
166
|
+
containerCrossSize -
|
|
167
|
+
pc.crossSize -
|
|
168
|
+
pc.crossMarginEnd;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
: (_pc: ProcessedChild, _crossCurrentPos: number = 0) => {
|
|
172
|
+
/* no-op */
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
if (isRow && node._calcHeight && !node.flexCrossBoundary) {
|
|
176
|
+
const maxHeight = processedChildren.reduce(
|
|
177
|
+
(max, pc) => Math.max(max, pc.crossSize),
|
|
178
|
+
0,
|
|
179
|
+
);
|
|
180
|
+
const newHeight = maxHeight || node.height;
|
|
181
|
+
if (newHeight !== node.height) {
|
|
182
|
+
containerUpdated = true;
|
|
183
|
+
node.height = containerCrossSize = newHeight;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
let currentPos = node.padding || 0;
|
|
188
|
+
if (justify === 'flexStart') {
|
|
189
|
+
if (node.flexWrap === 'wrap') {
|
|
190
|
+
let crossCurrentPos = 0;
|
|
191
|
+
// use the child size to do wrap, not the container
|
|
192
|
+
const childCrossSize =
|
|
193
|
+
processedChildren[0]?.crossSize || containerCrossSize;
|
|
194
|
+
const crossGap = isRow ? (node.columnGap ?? gap) : (node.rowGap ?? gap);
|
|
195
|
+
for (const pc of processedChildren) {
|
|
196
|
+
if (
|
|
197
|
+
currentPos + pc.totalMainSizeOnAxis > containerSize &&
|
|
198
|
+
currentPos > (node.padding || 0)
|
|
199
|
+
) {
|
|
200
|
+
currentPos = node.padding || 0;
|
|
201
|
+
crossCurrentPos += childCrossSize + crossGap;
|
|
202
|
+
}
|
|
203
|
+
pc.node[prop] = currentPos + pc.marginStart;
|
|
204
|
+
currentPos += pc.totalMainSizeOnAxis + gap;
|
|
205
|
+
doCrossAlign(pc, crossCurrentPos);
|
|
206
|
+
}
|
|
207
|
+
const finalCrossSize = crossCurrentPos + childCrossSize;
|
|
208
|
+
if (node[crossDimension] !== finalCrossSize) {
|
|
209
|
+
node[`preFlex${crossDimension}`] = node[crossDimension];
|
|
210
|
+
node[crossDimension] = finalCrossSize;
|
|
211
|
+
containerUpdated = true;
|
|
212
|
+
}
|
|
213
|
+
} else {
|
|
214
|
+
for (const pc of processedChildren) {
|
|
215
|
+
pc.node[prop] = currentPos + pc.marginStart;
|
|
216
|
+
currentPos += pc.totalMainSizeOnAxis + gap;
|
|
217
|
+
doCrossAlign(pc);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
// Update container size
|
|
221
|
+
if (node.flexBoundary !== 'fixed' && node.flexWrap !== 'wrap') {
|
|
222
|
+
const calculatedSize = currentPos - gap + (node.padding || 0);
|
|
223
|
+
if (calculatedSize !== containerSize) {
|
|
224
|
+
// store the original size for Row & Column
|
|
225
|
+
node[`preFlex${dimension}`] = containerSize;
|
|
226
|
+
node[dimension] = calculatedSize;
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
} else if (justify === 'flexEnd') {
|
|
231
|
+
currentPos = containerSize - (node.padding || 0);
|
|
232
|
+
for (let i = numProcessedChildren - 1; i >= 0; i--) {
|
|
233
|
+
const pc = processedChildren[i]!;
|
|
234
|
+
pc.node[prop] = currentPos - pc.mainSize - pc.marginEnd;
|
|
235
|
+
currentPos -= pc.totalMainSizeOnAxis + gap;
|
|
236
|
+
doCrossAlign(pc);
|
|
237
|
+
}
|
|
238
|
+
} else if (justify === 'center') {
|
|
239
|
+
currentPos =
|
|
240
|
+
(containerSize - (totalItemSize + gap * (numProcessedChildren - 1))) / 2 +
|
|
241
|
+
(node.padding || 0);
|
|
242
|
+
for (const pc of processedChildren) {
|
|
243
|
+
pc.node[prop] = currentPos + pc.marginStart;
|
|
244
|
+
currentPos += pc.totalMainSizeOnAxis + gap;
|
|
245
|
+
doCrossAlign(pc);
|
|
246
|
+
}
|
|
247
|
+
} else if (justify === 'spaceBetween') {
|
|
248
|
+
const spaceBetween =
|
|
249
|
+
numProcessedChildren > 1
|
|
250
|
+
? (containerSize - totalItemSize - (node.padding || 0) * 2) /
|
|
251
|
+
(numProcessedChildren - 1)
|
|
252
|
+
: 0;
|
|
253
|
+
currentPos = node.padding || 0;
|
|
254
|
+
for (const pc of processedChildren) {
|
|
255
|
+
pc.node[prop] = currentPos + pc.marginStart;
|
|
256
|
+
currentPos += pc.totalMainSizeOnAxis + spaceBetween;
|
|
257
|
+
doCrossAlign(pc);
|
|
258
|
+
}
|
|
259
|
+
} else if (justify === 'spaceAround') {
|
|
260
|
+
const spaceAround =
|
|
261
|
+
numProcessedChildren > 0
|
|
262
|
+
? (containerSize - totalItemSize - (node.padding || 0) * 2) /
|
|
263
|
+
numProcessedChildren
|
|
264
|
+
: 0;
|
|
265
|
+
currentPos = (node.padding || 0) + spaceAround / 2;
|
|
266
|
+
for (const pc of processedChildren) {
|
|
267
|
+
pc.node[prop] = currentPos + pc.marginStart;
|
|
268
|
+
currentPos += pc.totalMainSizeOnAxis + spaceAround;
|
|
269
|
+
doCrossAlign(pc);
|
|
270
|
+
}
|
|
271
|
+
} else if (justify === 'spaceEvenly') {
|
|
272
|
+
const spaceEvenly =
|
|
273
|
+
(containerSize - totalItemSize - (node.padding || 0) * 2) /
|
|
274
|
+
(numProcessedChildren + 1);
|
|
275
|
+
currentPos = spaceEvenly + (node.padding || 0);
|
|
276
|
+
for (const pc of processedChildren) {
|
|
277
|
+
pc.node[prop] = currentPos + pc.marginStart;
|
|
278
|
+
currentPos += pc.totalMainSizeOnAxis + spaceEvenly;
|
|
279
|
+
doCrossAlign(pc);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return containerUpdated;
|
|
284
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { ElementNode } from './elementNode.js';
|
|
2
|
+
|
|
3
|
+
// Focus + KeyHandling Types
|
|
4
|
+
export interface FocusNode {
|
|
5
|
+
onFocus?: (
|
|
6
|
+
this: ElementNode,
|
|
7
|
+
currentFocusedElm: ElementNode,
|
|
8
|
+
prevFocusedElm: ElementNode | undefined,
|
|
9
|
+
) => void;
|
|
10
|
+
onFocusChanged?: (
|
|
11
|
+
this: ElementNode,
|
|
12
|
+
hasFocus: boolean,
|
|
13
|
+
currentFocusedElm: ElementNode,
|
|
14
|
+
prevFocusedElm: ElementNode | undefined,
|
|
15
|
+
) => void;
|
|
16
|
+
onBlur?: (
|
|
17
|
+
this: ElementNode,
|
|
18
|
+
currentFocusedElm: ElementNode,
|
|
19
|
+
prevFocusedElm: ElementNode,
|
|
20
|
+
) => void;
|
|
21
|
+
onKeyPress?: (
|
|
22
|
+
this: ElementNode,
|
|
23
|
+
e: KeyboardEvent,
|
|
24
|
+
mappedKeyEvent: string | undefined,
|
|
25
|
+
handlerElm: ElementNode,
|
|
26
|
+
currentFocusedElm: ElementNode,
|
|
27
|
+
) => KeyHandlerReturn;
|
|
28
|
+
onKeyHold?: (
|
|
29
|
+
this: ElementNode,
|
|
30
|
+
e: KeyboardEvent,
|
|
31
|
+
mappedKeyEvent: string | undefined,
|
|
32
|
+
handlerElm: ElementNode,
|
|
33
|
+
currentFocusedElm: ElementNode,
|
|
34
|
+
) => KeyHandlerReturn;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type KeyNameOrKeyCode = string | number;
|
|
38
|
+
|
|
39
|
+
export interface DefaultKeyMap {
|
|
40
|
+
Left: KeyNameOrKeyCode | KeyNameOrKeyCode[];
|
|
41
|
+
Right: KeyNameOrKeyCode | KeyNameOrKeyCode[];
|
|
42
|
+
Up: KeyNameOrKeyCode | KeyNameOrKeyCode[];
|
|
43
|
+
Down: KeyNameOrKeyCode | KeyNameOrKeyCode[];
|
|
44
|
+
Enter: KeyNameOrKeyCode | KeyNameOrKeyCode[];
|
|
45
|
+
Last: KeyNameOrKeyCode | KeyNameOrKeyCode[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface KeyMap extends DefaultKeyMap {
|
|
49
|
+
[key: string]: KeyNameOrKeyCode | KeyNameOrKeyCode[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface DefaultKeyHoldMap {
|
|
53
|
+
EnterHold: KeyNameOrKeyCode | KeyNameOrKeyCode[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type EventHandlers<Map> = {
|
|
57
|
+
[K in keyof Map as `on${Capitalize<string & K>}`]?: KeyHandler;
|
|
58
|
+
} & {
|
|
59
|
+
[K in keyof Map as `on${Capitalize<string & K>}Release`]?: KeyHandler;
|
|
60
|
+
} & {
|
|
61
|
+
[K in keyof Map as `onCapture${Capitalize<string & K>}`]?: KeyHandler;
|
|
62
|
+
} & {
|
|
63
|
+
onCaptureKey?: KeyHandler;
|
|
64
|
+
onCaptureKeyRelease?: KeyHandler;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export interface KeyHoldMap extends DefaultKeyHoldMap {}
|
|
68
|
+
|
|
69
|
+
export type KeyHandlerReturn = boolean | void;
|
|
70
|
+
|
|
71
|
+
export type KeyHandler = (
|
|
72
|
+
this: ElementNode,
|
|
73
|
+
e: KeyboardEvent,
|
|
74
|
+
target: ElementNode,
|
|
75
|
+
handlerElm: ElementNode,
|
|
76
|
+
mappedEvent?: string,
|
|
77
|
+
) => KeyHandlerReturn;
|
|
78
|
+
|
|
79
|
+
export type ForwardFocusHandler = (
|
|
80
|
+
this: ElementNode,
|
|
81
|
+
elm: ElementNode,
|
|
82
|
+
) => boolean | void;
|
|
83
|
+
|
|
84
|
+
export type KeyHoldOptions = {
|
|
85
|
+
userKeyHoldMap: Partial<KeyHoldMap>;
|
|
86
|
+
holdThreshold?: number;
|
|
87
|
+
};
|