@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.
Files changed (237) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +7 -0
  3. package/README.md +95 -0
  4. package/dist/jsx-runtime.d.ts +14 -0
  5. package/dist/src/activeElement.d.ts +2 -0
  6. package/dist/src/activeElement.js +3 -0
  7. package/dist/src/activeElement.js.map +1 -0
  8. package/dist/src/core/config.d.ts +51 -0
  9. package/dist/src/core/config.js +37 -0
  10. package/dist/src/core/config.js.map +1 -0
  11. package/dist/src/core/dom-renderer/domRenderer.d.ts +138 -0
  12. package/dist/src/core/dom-renderer/domRenderer.js +1844 -0
  13. package/dist/src/core/dom-renderer/domRenderer.js.map +1 -0
  14. package/dist/src/core/dom-renderer/domRendererTypes.d.ts +110 -0
  15. package/dist/src/core/dom-renderer/domRendererTypes.js +2 -0
  16. package/dist/src/core/dom-renderer/domRendererTypes.js.map +1 -0
  17. package/dist/src/core/dom-renderer/domRendererUtils.d.ts +23 -0
  18. package/dist/src/core/dom-renderer/domRendererUtils.js +232 -0
  19. package/dist/src/core/dom-renderer/domRendererUtils.js.map +1 -0
  20. package/dist/src/core/elementNode.d.ts +508 -0
  21. package/dist/src/core/elementNode.js +928 -0
  22. package/dist/src/core/elementNode.js.map +1 -0
  23. package/dist/src/core/flex.d.ts +2 -0
  24. package/dist/src/core/flex.js +284 -0
  25. package/dist/src/core/flex.js.map +1 -0
  26. package/dist/src/core/flexLayout.d.ts +2 -0
  27. package/dist/src/core/flexLayout.js +360 -0
  28. package/dist/src/core/flexLayout.js.map +1 -0
  29. package/dist/src/core/focusKeyTypes.d.ts +42 -0
  30. package/dist/src/core/focusKeyTypes.js +2 -0
  31. package/dist/src/core/focusKeyTypes.js.map +1 -0
  32. package/dist/src/core/focusManager.d.ts +13 -0
  33. package/dist/src/core/focusManager.js +270 -0
  34. package/dist/src/core/focusManager.js.map +1 -0
  35. package/dist/src/core/index.d.ts +14 -0
  36. package/dist/src/core/index.js +11 -0
  37. package/dist/src/core/index.js.map +1 -0
  38. package/dist/src/core/intrinsicTypes.d.ts +106 -0
  39. package/dist/src/core/intrinsicTypes.js +2 -0
  40. package/dist/src/core/intrinsicTypes.js.map +1 -0
  41. package/dist/src/core/lightningInit.d.ts +9 -0
  42. package/dist/src/core/lightningInit.js +34 -0
  43. package/dist/src/core/lightningInit.js.map +1 -0
  44. package/dist/src/core/nodeTypes.d.ts +6 -0
  45. package/dist/src/core/nodeTypes.js +6 -0
  46. package/dist/src/core/nodeTypes.js.map +1 -0
  47. package/dist/src/core/shaders.d.ts +52 -0
  48. package/dist/src/core/shaders.js +86 -0
  49. package/dist/src/core/shaders.js.map +1 -0
  50. package/dist/src/core/states.d.ts +12 -0
  51. package/dist/src/core/states.js +84 -0
  52. package/dist/src/core/states.js.map +1 -0
  53. package/dist/src/core/utils.d.ts +39 -0
  54. package/dist/src/core/utils.js +164 -0
  55. package/dist/src/core/utils.js.map +1 -0
  56. package/dist/src/devtools/index.d.ts +6 -0
  57. package/dist/src/devtools/index.js +65 -0
  58. package/dist/src/devtools/index.js.map +1 -0
  59. package/dist/src/index.d.ts +9 -0
  60. package/dist/src/index.js +7 -0
  61. package/dist/src/index.js.map +1 -0
  62. package/dist/src/primitives/Column.d.ts +3 -0
  63. package/dist/src/primitives/Column.jsx +25 -0
  64. package/dist/src/primitives/Column.jsx.map +1 -0
  65. package/dist/src/primitives/FPSCounter.d.ts +4 -0
  66. package/dist/src/primitives/FPSCounter.jsx +188 -0
  67. package/dist/src/primitives/FPSCounter.jsx.map +1 -0
  68. package/dist/src/primitives/FadeInOut.d.ts +18 -0
  69. package/dist/src/primitives/FadeInOut.jsx +39 -0
  70. package/dist/src/primitives/FadeInOut.jsx.map +1 -0
  71. package/dist/src/primitives/Grid.d.ts +23 -0
  72. package/dist/src/primitives/Grid.jsx +100 -0
  73. package/dist/src/primitives/Grid.jsx.map +1 -0
  74. package/dist/src/primitives/Image.d.ts +8 -0
  75. package/dist/src/primitives/Image.jsx +42 -0
  76. package/dist/src/primitives/Image.jsx.map +1 -0
  77. package/dist/src/primitives/KeepAlive.d.ts +42 -0
  78. package/dist/src/primitives/KeepAlive.jsx +160 -0
  79. package/dist/src/primitives/KeepAlive.jsx.map +1 -0
  80. package/dist/src/primitives/Lazy.d.ts +15 -0
  81. package/dist/src/primitives/Lazy.jsx +95 -0
  82. package/dist/src/primitives/Lazy.jsx.map +1 -0
  83. package/dist/src/primitives/LazyImport.d.ts +8 -0
  84. package/dist/src/primitives/LazyImport.js +40 -0
  85. package/dist/src/primitives/LazyImport.js.map +1 -0
  86. package/dist/src/primitives/Marquee.d.ts +64 -0
  87. package/dist/src/primitives/Marquee.jsx +86 -0
  88. package/dist/src/primitives/Marquee.jsx.map +1 -0
  89. package/dist/src/primitives/Preserve.d.ts +4 -0
  90. package/dist/src/primitives/Preserve.jsx +11 -0
  91. package/dist/src/primitives/Preserve.jsx.map +1 -0
  92. package/dist/src/primitives/Row.d.ts +3 -0
  93. package/dist/src/primitives/Row.jsx +24 -0
  94. package/dist/src/primitives/Row.jsx.map +1 -0
  95. package/dist/src/primitives/Suspense.d.ts +22 -0
  96. package/dist/src/primitives/Suspense.jsx +33 -0
  97. package/dist/src/primitives/Suspense.jsx.map +1 -0
  98. package/dist/src/primitives/Virtual.d.ts +18 -0
  99. package/dist/src/primitives/Virtual.jsx +495 -0
  100. package/dist/src/primitives/Virtual.jsx.map +1 -0
  101. package/dist/src/primitives/VirtualGrid.d.ts +13 -0
  102. package/dist/src/primitives/VirtualGrid.jsx +160 -0
  103. package/dist/src/primitives/VirtualGrid.jsx.map +1 -0
  104. package/dist/src/primitives/Visible.d.ts +6 -0
  105. package/dist/src/primitives/Visible.jsx +37 -0
  106. package/dist/src/primitives/Visible.jsx.map +1 -0
  107. package/dist/src/primitives/announcer/announcer.d.ts +40 -0
  108. package/dist/src/primitives/announcer/announcer.js +125 -0
  109. package/dist/src/primitives/announcer/announcer.js.map +1 -0
  110. package/dist/src/primitives/announcer/index.d.ts +6 -0
  111. package/dist/src/primitives/announcer/index.js +15 -0
  112. package/dist/src/primitives/announcer/index.js.map +1 -0
  113. package/dist/src/primitives/announcer/speech.d.ts +10 -0
  114. package/dist/src/primitives/announcer/speech.js +281 -0
  115. package/dist/src/primitives/announcer/speech.js.map +1 -0
  116. package/dist/src/primitives/borderBox.d.ts +8 -0
  117. package/dist/src/primitives/borderBox.jsx +47 -0
  118. package/dist/src/primitives/borderBox.jsx.map +1 -0
  119. package/dist/src/primitives/createFocusStack.d.ts +31 -0
  120. package/dist/src/primitives/createFocusStack.jsx +62 -0
  121. package/dist/src/primitives/createFocusStack.jsx.map +1 -0
  122. package/dist/src/primitives/createInfiniteItems.d.ts +27 -0
  123. package/dist/src/primitives/createInfiniteItems.js +46 -0
  124. package/dist/src/primitives/createInfiniteItems.js.map +1 -0
  125. package/dist/src/primitives/createTag.d.ts +8 -0
  126. package/dist/src/primitives/createTag.jsx +20 -0
  127. package/dist/src/primitives/createTag.jsx.map +1 -0
  128. package/dist/src/primitives/index.d.ts +32 -0
  129. package/dist/src/primitives/index.js +31 -0
  130. package/dist/src/primitives/index.js.map +1 -0
  131. package/dist/src/primitives/portal.d.ts +5 -0
  132. package/dist/src/primitives/portal.jsx +21 -0
  133. package/dist/src/primitives/portal.jsx.map +1 -0
  134. package/dist/src/primitives/router.d.ts +20 -0
  135. package/dist/src/primitives/router.js +90 -0
  136. package/dist/src/primitives/router.js.map +1 -0
  137. package/dist/src/primitives/types.d.ts +79 -0
  138. package/dist/src/primitives/types.js +2 -0
  139. package/dist/src/primitives/types.js.map +1 -0
  140. package/dist/src/primitives/useFocusManager.d.ts +5 -0
  141. package/dist/src/primitives/useFocusManager.js +21 -0
  142. package/dist/src/primitives/useFocusManager.js.map +1 -0
  143. package/dist/src/primitives/useHold.d.ts +27 -0
  144. package/dist/src/primitives/useHold.js +54 -0
  145. package/dist/src/primitives/useHold.js.map +1 -0
  146. package/dist/src/primitives/useMouse.d.ts +18 -0
  147. package/dist/src/primitives/useMouse.js +240 -0
  148. package/dist/src/primitives/useMouse.js.map +1 -0
  149. package/dist/src/primitives/utils/chainFunctions.d.ts +30 -0
  150. package/dist/src/primitives/utils/chainFunctions.js +32 -0
  151. package/dist/src/primitives/utils/chainFunctions.js.map +1 -0
  152. package/dist/src/primitives/utils/createBlurredImage.d.ts +56 -0
  153. package/dist/src/primitives/utils/createBlurredImage.js +223 -0
  154. package/dist/src/primitives/utils/createBlurredImage.js.map +1 -0
  155. package/dist/src/primitives/utils/createSpriteMap.d.ts +9 -0
  156. package/dist/src/primitives/utils/createSpriteMap.js +18 -0
  157. package/dist/src/primitives/utils/createSpriteMap.js.map +1 -0
  158. package/dist/src/primitives/utils/handleNavigation.d.ts +103 -0
  159. package/dist/src/primitives/utils/handleNavigation.js +300 -0
  160. package/dist/src/primitives/utils/handleNavigation.js.map +1 -0
  161. package/dist/src/primitives/utils/withScrolling.d.ts +22 -0
  162. package/dist/src/primitives/utils/withScrolling.js +186 -0
  163. package/dist/src/primitives/utils/withScrolling.js.map +1 -0
  164. package/dist/src/render.d.ts +28 -0
  165. package/dist/src/render.js +107 -0
  166. package/dist/src/render.js.map +1 -0
  167. package/dist/src/solidOpts.d.ts +15 -0
  168. package/dist/src/solidOpts.js +93 -0
  169. package/dist/src/solidOpts.js.map +1 -0
  170. package/dist/src/types.d.ts +11 -0
  171. package/dist/src/types.js +2 -0
  172. package/dist/src/types.js.map +1 -0
  173. package/dist/src/utils.d.ts +19 -0
  174. package/dist/src/utils.js +94 -0
  175. package/dist/src/utils.js.map +1 -0
  176. package/dist/tsconfig.tsbuildinfo +1 -0
  177. package/docs/AI_CODING_GUIDELINES.md +108 -0
  178. package/docs/README.md +35 -0
  179. package/jsx-runtime.d.ts +14 -0
  180. package/package.json +125 -0
  181. package/src/activeElement.ts +5 -0
  182. package/src/core/config.ts +101 -0
  183. package/src/core/dom-renderer/domRenderer.ts +2066 -0
  184. package/src/core/dom-renderer/domRendererTypes.ts +148 -0
  185. package/src/core/dom-renderer/domRendererUtils.ts +292 -0
  186. package/src/core/elementNode.ts +1623 -0
  187. package/src/core/flex.ts +331 -0
  188. package/src/core/flexLayout.ts +414 -0
  189. package/src/core/focusKeyTypes.ts +90 -0
  190. package/src/core/focusManager.ts +374 -0
  191. package/src/core/index.ts +15 -0
  192. package/src/core/intrinsicTypes.ts +216 -0
  193. package/src/core/lightningInit.ts +45 -0
  194. package/src/core/nodeTypes.ts +6 -0
  195. package/src/core/shaders.ts +187 -0
  196. package/src/core/states.ts +91 -0
  197. package/src/core/utils.ts +222 -0
  198. package/src/devtools/index.ts +77 -0
  199. package/src/index.ts +18 -0
  200. package/src/primitives/Column.tsx +59 -0
  201. package/src/primitives/FPSCounter.tsx +209 -0
  202. package/src/primitives/FadeInOut.tsx +58 -0
  203. package/src/primitives/Grid.tsx +151 -0
  204. package/src/primitives/Image.tsx +56 -0
  205. package/src/primitives/KeepAlive.tsx +268 -0
  206. package/src/primitives/Lazy.tsx +128 -0
  207. package/src/primitives/LazyImport.ts +53 -0
  208. package/src/primitives/Marquee.tsx +149 -0
  209. package/src/primitives/Preserve.tsx +18 -0
  210. package/src/primitives/Row.tsx +58 -0
  211. package/src/primitives/Suspense.tsx +39 -0
  212. package/src/primitives/Virtual.tsx +602 -0
  213. package/src/primitives/VirtualGrid.tsx +220 -0
  214. package/src/primitives/Visible.tsx +59 -0
  215. package/src/primitives/announcer/announcer.ts +198 -0
  216. package/src/primitives/announcer/index.ts +20 -0
  217. package/src/primitives/announcer/speech.ts +334 -0
  218. package/src/primitives/borderBox.tsx +69 -0
  219. package/src/primitives/createFocusStack.tsx +79 -0
  220. package/src/primitives/createInfiniteItems.ts +66 -0
  221. package/src/primitives/createTag.tsx +33 -0
  222. package/src/primitives/index.ts +37 -0
  223. package/src/primitives/portal.tsx +25 -0
  224. package/src/primitives/router.ts +147 -0
  225. package/src/primitives/types.ts +109 -0
  226. package/src/primitives/useFocusManager.ts +47 -0
  227. package/src/primitives/useHold.ts +69 -0
  228. package/src/primitives/useMouse.ts +417 -0
  229. package/src/primitives/utils/chainFunctions.ts +60 -0
  230. package/src/primitives/utils/createBlurredImage.ts +366 -0
  231. package/src/primitives/utils/createSpriteMap.ts +32 -0
  232. package/src/primitives/utils/handleNavigation.ts +373 -0
  233. package/src/primitives/utils/withScrolling.ts +238 -0
  234. package/src/render.ts +164 -0
  235. package/src/solidOpts.ts +107 -0
  236. package/src/types.ts +22 -0
  237. package/src/utils.ts +129 -0
@@ -0,0 +1,414 @@
1
+ import { type ElementNode } from './elementNode.js';
2
+ import { isTextNode, isElementText } from './utils.js';
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
+ export default function (node: ElementNode): boolean {
25
+ const direction = node.flexDirection || 'row';
26
+ const isRow = direction === 'row' || direction === 'row-reverse';
27
+ const isReverse =
28
+ direction === 'row-reverse' || direction === 'column-reverse';
29
+ const dimension = isRow ? 'width' : 'height';
30
+ const crossDimension = isRow ? 'height' : 'width';
31
+
32
+ // padding order: Top, Right, Bottom, Left
33
+ const nodePadding = node.padding;
34
+ const paddingTop = (node.paddingTop ??
35
+ getArrayValue(nodePadding, 0)) as number;
36
+ const paddingRight = (node.paddingRight ??
37
+ getArrayValue(nodePadding, 1)) as number;
38
+ const paddingBottom = (node.paddingBottom ??
39
+ getArrayValue(nodePadding, 2)) as number;
40
+ const paddingLeft = (node.paddingLeft ??
41
+ getArrayValue(nodePadding, 3)) as number;
42
+
43
+ const paddingStart = isRow ? paddingLeft : paddingTop;
44
+ const paddingEnd = isRow ? paddingRight : paddingBottom;
45
+ const paddingCrossStart = isRow ? paddingTop : paddingLeft;
46
+ const paddingCrossEnd = isRow ? paddingBottom : paddingRight;
47
+ const nodePaddingTotal = paddingStart + paddingEnd;
48
+
49
+ const minDimension = isRow ? 'minWidth' : 'minHeight';
50
+ const crossMinDimension = isRow ? 'minHeight' : 'minWidth';
51
+
52
+ const children = node.children;
53
+ const numChildren = children.length;
54
+
55
+ if (numChildren === 0) {
56
+ return false;
57
+ }
58
+
59
+ // Optimize arrays caching
60
+ let processableChildrenIndices: number[] = [];
61
+ let hasOrder = false;
62
+ let totalFlexGrow = 0;
63
+ let totalFlexShrink = 0;
64
+
65
+ for (let i = 0; i < numChildren; i++) {
66
+ const c = children[i]!;
67
+
68
+ if (isElementText(c) && c.text && !(c.width || c.height)) {
69
+ return false; // specific text layout constraint
70
+ }
71
+
72
+ if (isTextNode(c) || c.flexItem === false) {
73
+ continue;
74
+ }
75
+
76
+ if (c.flexOrder !== undefined) {
77
+ hasOrder = true;
78
+ }
79
+
80
+ const flexGrow = c.flexGrow;
81
+ if (flexGrow !== undefined && flexGrow > 0) {
82
+ totalFlexGrow += flexGrow;
83
+ }
84
+
85
+ const flexShrink = c.flexShrink;
86
+ if (flexShrink !== undefined && flexShrink > 0) {
87
+ totalFlexShrink += flexShrink;
88
+ }
89
+
90
+ if (c[minDimension] && (c[dimension] || 0) < c[minDimension]!) {
91
+ c[dimension] = c[minDimension]!;
92
+ }
93
+
94
+ if (
95
+ c[crossMinDimension] &&
96
+ (c[crossDimension] || 0) < c[crossMinDimension]!
97
+ ) {
98
+ c[crossDimension] = c[crossMinDimension]!;
99
+ }
100
+
101
+ processableChildrenIndices.push(i);
102
+ }
103
+
104
+ if (hasOrder) {
105
+ processableChildrenIndices.sort((aIdx, bIdx) => {
106
+ const a = children[aIdx] as ElementNode;
107
+ const b = children[bIdx] as ElementNode;
108
+ return (a.flexOrder || 0) - (b.flexOrder || 0);
109
+ });
110
+ }
111
+
112
+ // Apply reverse layout ordering
113
+ if (isReverse || node.direction === 'rtl') {
114
+ processableChildrenIndices.reverse();
115
+ }
116
+
117
+ const numProcessedChildren = processableChildrenIndices.length;
118
+ if (numProcessedChildren === 0) {
119
+ return false;
120
+ }
121
+
122
+ const prop = isRow ? 'x' : 'y';
123
+ const crossProp = isRow ? 'y' : 'x';
124
+ const containerSize = Math.max(
125
+ node[dimension] || 0,
126
+ node[minDimension] || 0,
127
+ 0,
128
+ );
129
+ let containerCrossSize = Math.max(
130
+ node[crossDimension] || 0,
131
+ node[crossMinDimension] || 0,
132
+ 0,
133
+ );
134
+ const isWrapReverse = node.flexWrap === 'wrap-reverse';
135
+ const gap = node.gap || 0;
136
+ const justify = node.justifyContent || 'flexStart';
137
+ const align = node.alignItems || (node.flexWrap ? 'flexStart' : undefined);
138
+ let containerUpdated = false;
139
+
140
+ // Resolve sizes matching old processed calculation
141
+ const childMainSizes = new Float32Array(numProcessedChildren);
142
+ const childMarginStarts = new Float32Array(numProcessedChildren);
143
+ const childMarginEnds = new Float32Array(numProcessedChildren);
144
+ const childTotalMainSizes = new Float32Array(numProcessedChildren);
145
+ const childCrossSizes = new Float32Array(numProcessedChildren);
146
+ const childMarginCrossStarts = new Float32Array(numProcessedChildren);
147
+ const childMarginCrossEnds = new Float32Array(numProcessedChildren);
148
+
149
+ let sumOfFlexBaseSizesWithMargins = 0;
150
+
151
+ for (let idx = 0; idx < numProcessedChildren; idx++) {
152
+ const c = children[processableChildrenIndices[idx]!] as ElementNode;
153
+ const marginArray = c.margin;
154
+ // index mappings for margins: Top: 0, Right: 1, Bottom: 2, Left: 3
155
+ // if row: main = left/right (3/1),
156
+ const flexBasis = c.flexBasis;
157
+ const isBasisAuto = flexBasis === undefined || flexBasis === 'auto';
158
+ const computedBasis = isBasisAuto
159
+ ? c[dimension] || 0
160
+ : (flexBasis as number);
161
+ const baseMainSize = isBasisAuto
162
+ ? computedBasis
163
+ : Math.max(computedBasis, c[minDimension] || 0);
164
+
165
+ const marginStart = isRow
166
+ ? c.marginLeft || getArrayValue(marginArray, 3)
167
+ : c.marginTop || getArrayValue(marginArray, 0);
168
+ const marginEnd = isRow
169
+ ? c.marginRight || getArrayValue(marginArray, 1)
170
+ : c.marginBottom || getArrayValue(marginArray, 2);
171
+ const marginCrossStart = isRow
172
+ ? c.marginTop || getArrayValue(marginArray, 0)
173
+ : c.marginLeft || getArrayValue(marginArray, 3);
174
+ const marginCrossEnd = isRow
175
+ ? c.marginBottom || getArrayValue(marginArray, 2)
176
+ : c.marginRight || getArrayValue(marginArray, 1);
177
+
178
+ childMainSizes[idx] = baseMainSize;
179
+ childMarginStarts[idx] = marginStart;
180
+ childMarginEnds[idx] = marginEnd;
181
+ childTotalMainSizes[idx] = baseMainSize + marginStart + marginEnd;
182
+ childCrossSizes[idx] = c[crossDimension] || 0;
183
+ childMarginCrossStarts[idx] = marginCrossStart;
184
+ childMarginCrossEnds[idx] = marginCrossEnd;
185
+
186
+ sumOfFlexBaseSizesWithMargins += childTotalMainSizes[idx]!;
187
+ }
188
+
189
+ if ((totalFlexGrow > 0 || totalFlexShrink > 0) && numProcessedChildren > 1) {
190
+ node.flexBoundary = node.flexBoundary || 'fixed';
191
+
192
+ const totalGapSpace =
193
+ numProcessedChildren > 0 ? gap * (numProcessedChildren - 1) : 0;
194
+ const availableSpace =
195
+ containerSize - sumOfFlexBaseSizesWithMargins - totalGapSpace;
196
+
197
+ if (availableSpace > 0 && totalFlexGrow > 0) {
198
+ for (let idx = 0; idx < numProcessedChildren; idx++) {
199
+ const c = children[processableChildrenIndices[idx]!] as ElementNode;
200
+ const flexGrowValue = c.flexGrow || 0;
201
+ if (flexGrowValue > 0) {
202
+ const shareOfSpace = (flexGrowValue / totalFlexGrow) * availableSpace;
203
+ const newMainSize = childMainSizes[idx]! + shareOfSpace;
204
+ c[dimension] = newMainSize;
205
+ childMainSizes[idx] = newMainSize;
206
+ childTotalMainSizes[idx] =
207
+ newMainSize + childMarginStarts[idx]! + childMarginEnds[idx]!;
208
+ }
209
+ }
210
+ node._containsFlexGrow = node._containsFlexGrow ? null : true;
211
+ } else if (availableSpace < 0 && totalFlexShrink > 0) {
212
+ // Flex Shrink Phase
213
+ let totalScaledShrinkFactor = 0;
214
+ for (let idx = 0; idx < numProcessedChildren; idx++) {
215
+ const c = children[processableChildrenIndices[idx]!] as ElementNode;
216
+ const flexShrinkValue = c.flexShrink || 0;
217
+ totalScaledShrinkFactor += flexShrinkValue * childMainSizes[idx]!;
218
+ }
219
+
220
+ if (totalScaledShrinkFactor > 0) {
221
+ for (let idx = 0; idx < numProcessedChildren; idx++) {
222
+ const c = children[processableChildrenIndices[idx]!] as ElementNode;
223
+ const flexShrinkValue = c.flexShrink || 0;
224
+ if (flexShrinkValue > 0) {
225
+ const shrinkRatio =
226
+ (flexShrinkValue * childMainSizes[idx]!) /
227
+ totalScaledShrinkFactor;
228
+ const sizeReduction = shrinkRatio * Math.abs(availableSpace);
229
+ let newMainSize = childMainSizes[idx]! - sizeReduction;
230
+
231
+ // Constrain by min width/height
232
+ const minBound = c[minDimension] || 0;
233
+ if (newMainSize < minBound) {
234
+ newMainSize = minBound;
235
+ }
236
+
237
+ c[dimension] = newMainSize;
238
+ childMainSizes[idx] = newMainSize;
239
+ childTotalMainSizes[idx] =
240
+ newMainSize + childMarginStarts[idx]! + childMarginEnds[idx]!;
241
+ }
242
+ }
243
+ }
244
+ node._containsFlexGrow = node._containsFlexGrow ? null : true;
245
+ } else if (node._containsFlexGrow) {
246
+ node._containsFlexGrow = null;
247
+ }
248
+ }
249
+
250
+ let totalItemSize = 0;
251
+ if (
252
+ justify === 'center' ||
253
+ justify === 'spaceBetween' ||
254
+ justify === 'spaceEvenly' ||
255
+ justify === 'spaceAround'
256
+ ) {
257
+ for (let idx = 0; idx < numProcessedChildren; idx++) {
258
+ totalItemSize += childTotalMainSizes[idx]!;
259
+ }
260
+ }
261
+
262
+ const doCrossAlign = containerCrossSize
263
+ ? (c: ElementNode, idx: number, crossCurrentPos: number = 0) => {
264
+ const alignSelf = c.alignSelf || align;
265
+ if (!alignSelf) {
266
+ return;
267
+ }
268
+ if (alignSelf === 'flexStart') {
269
+ c[crossProp] = crossCurrentPos + childMarginCrossStarts[idx]!;
270
+ } else if (alignSelf === 'center') {
271
+ c[crossProp] =
272
+ crossCurrentPos +
273
+ (containerCrossSize - childCrossSizes[idx]!) / 2 +
274
+ childMarginCrossStarts[idx]!;
275
+ } else if (alignSelf === 'flexEnd') {
276
+ c[crossProp] =
277
+ crossCurrentPos +
278
+ containerCrossSize -
279
+ childCrossSizes[idx]! -
280
+ childMarginCrossEnds[idx]!;
281
+ }
282
+ }
283
+ : (_c: ElementNode, _idx: number, _crossCurrentPos: number = 0) => {
284
+ /* no-op */
285
+ };
286
+
287
+ if (isRow && node._calcHeight && !node.flexCrossBoundary) {
288
+ let maxHeight = 0;
289
+ for (let idx = 0; idx < numProcessedChildren; idx++) {
290
+ if (childCrossSizes[idx]! > maxHeight) maxHeight = childCrossSizes[idx]!;
291
+ }
292
+ const newHeight = maxHeight || node.height;
293
+ if (newHeight !== node.height) {
294
+ containerUpdated = true;
295
+ node.height = containerCrossSize = newHeight;
296
+ }
297
+ }
298
+
299
+ let currentPos = paddingStart;
300
+ if (justify === 'flexStart') {
301
+ if (node.flexWrap === 'wrap') {
302
+ const childCrossSizeVar =
303
+ numProcessedChildren > 0 ? childCrossSizes[0]! : containerCrossSize;
304
+ let crossCurrentPos = isWrapReverse
305
+ ? containerCrossSize - paddingCrossEnd - childCrossSizeVar
306
+ : paddingCrossStart;
307
+ const crossGap = isRow ? (node.columnGap ?? gap) : (node.rowGap ?? gap);
308
+
309
+ for (let idx = 0; idx < numProcessedChildren; idx++) {
310
+ const c = children[processableChildrenIndices[idx]!] as ElementNode;
311
+ if (
312
+ currentPos + childTotalMainSizes[idx]! > containerSize &&
313
+ currentPos > paddingStart
314
+ ) {
315
+ currentPos = paddingStart;
316
+ crossCurrentPos += isWrapReverse
317
+ ? -(childCrossSizeVar + crossGap)
318
+ : childCrossSizeVar + crossGap;
319
+ }
320
+ c[prop] = currentPos + childMarginStarts[idx]!;
321
+ currentPos += childTotalMainSizes[idx]! + gap;
322
+ doCrossAlign(c, idx, crossCurrentPos);
323
+ }
324
+
325
+ const finalCrossSize = isWrapReverse
326
+ ? containerCrossSize - crossCurrentPos + paddingCrossStart
327
+ : crossCurrentPos + childCrossSizeVar + paddingCrossEnd;
328
+
329
+ if (node[crossDimension] !== finalCrossSize) {
330
+ node[`preFlex${crossDimension}`] = node[crossDimension];
331
+ node[crossDimension] = finalCrossSize;
332
+ containerUpdated = true;
333
+ }
334
+ } else {
335
+ for (let idx = 0; idx < numProcessedChildren; idx++) {
336
+ const c = children[processableChildrenIndices[idx]!] as ElementNode;
337
+ c[prop] = currentPos + childMarginStarts[idx]!;
338
+ currentPos += childTotalMainSizes[idx]! + gap;
339
+ doCrossAlign(c, idx, paddingCrossStart);
340
+ }
341
+ }
342
+
343
+ // Update container size
344
+ if (node.flexBoundary !== 'fixed' && node.flexWrap !== 'wrap') {
345
+ let calculatedSize = currentPos - gap + paddingEnd;
346
+ const minSize = node[minDimension] || 0;
347
+ if (calculatedSize < minSize) {
348
+ calculatedSize = minSize;
349
+ }
350
+ if (calculatedSize !== (node[dimension] || 0)) {
351
+ node[`preFlex${dimension}`] = containerSize;
352
+ node[dimension] = calculatedSize;
353
+ return true;
354
+ }
355
+ }
356
+ } else if (justify === 'flexEnd') {
357
+ currentPos = containerSize - paddingEnd;
358
+ for (let idx = numProcessedChildren - 1; idx >= 0; idx--) {
359
+ const c = children[processableChildrenIndices[idx]!] as ElementNode;
360
+ c[prop] = currentPos - childMainSizes[idx]! - childMarginEnds[idx]!;
361
+ currentPos -= childTotalMainSizes[idx]! + gap;
362
+ doCrossAlign(c, idx, paddingCrossStart);
363
+ }
364
+ } else if (justify === 'center') {
365
+ currentPos =
366
+ (containerSize - (totalItemSize + gap * (numProcessedChildren - 1))) / 2 +
367
+ paddingStart;
368
+ for (let idx = 0; idx < numProcessedChildren; idx++) {
369
+ const c = children[processableChildrenIndices[idx]!] as ElementNode;
370
+ c[prop] = currentPos + childMarginStarts[idx]!;
371
+ currentPos += childTotalMainSizes[idx]! + gap;
372
+ doCrossAlign(c, idx, paddingCrossStart);
373
+ }
374
+ } else if (justify === 'spaceBetween') {
375
+ const spaceBetween =
376
+ numProcessedChildren > 1
377
+ ? (containerSize - totalItemSize - nodePaddingTotal) /
378
+ (numProcessedChildren - 1)
379
+ : 0;
380
+ currentPos = paddingStart;
381
+ for (let idx = 0; idx < numProcessedChildren; idx++) {
382
+ const c = children[processableChildrenIndices[idx]!] as ElementNode;
383
+ c[prop] = currentPos + childMarginStarts[idx]!;
384
+ currentPos += childTotalMainSizes[idx]! + spaceBetween;
385
+ doCrossAlign(c, idx, paddingCrossStart);
386
+ }
387
+ } else if (justify === 'spaceAround') {
388
+ const spaceAround =
389
+ numProcessedChildren > 0
390
+ ? (containerSize - totalItemSize - nodePaddingTotal) /
391
+ numProcessedChildren
392
+ : 0;
393
+ currentPos = paddingStart + spaceAround / 2;
394
+ for (let idx = 0; idx < numProcessedChildren; idx++) {
395
+ const c = children[processableChildrenIndices[idx]!] as ElementNode;
396
+ c[prop] = currentPos + childMarginStarts[idx]!;
397
+ currentPos += childTotalMainSizes[idx]! + spaceAround;
398
+ doCrossAlign(c, idx, paddingCrossStart);
399
+ }
400
+ } else if (justify === 'spaceEvenly') {
401
+ const spaceEvenly =
402
+ (containerSize - totalItemSize - nodePaddingTotal) /
403
+ (numProcessedChildren + 1);
404
+ currentPos = spaceEvenly + paddingStart;
405
+ for (let idx = 0; idx < numProcessedChildren; idx++) {
406
+ const c = children[processableChildrenIndices[idx]!] as ElementNode;
407
+ c[prop] = currentPos + childMarginStarts[idx]!;
408
+ currentPos += childTotalMainSizes[idx]! + spaceEvenly;
409
+ doCrossAlign(c, idx, paddingCrossStart);
410
+ }
411
+ }
412
+
413
+ return containerUpdated;
414
+ }
@@ -0,0 +1,90 @@
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
+ nodeWithCallback: ElementNode,
10
+ ) => void;
11
+ onFocusChanged?: (
12
+ this: ElementNode,
13
+ hasFocus: boolean,
14
+ currentFocusedElm: ElementNode,
15
+ prevFocusedElm: ElementNode | undefined,
16
+ nodeWithCallback: ElementNode,
17
+ ) => void;
18
+ onBlur?: (
19
+ this: ElementNode,
20
+ currentFocusedElm: ElementNode,
21
+ prevFocusedElm: ElementNode,
22
+ nodeWithCallback: ElementNode,
23
+ ) => void;
24
+ onKeyPress?: (
25
+ this: ElementNode,
26
+ e: KeyboardEvent,
27
+ mappedKeyEvent: string | undefined,
28
+ handlerElm: ElementNode,
29
+ currentFocusedElm: ElementNode,
30
+ ) => KeyHandlerReturn;
31
+ onKeyHold?: (
32
+ this: ElementNode,
33
+ e: KeyboardEvent,
34
+ mappedKeyEvent: string | undefined,
35
+ handlerElm: ElementNode,
36
+ currentFocusedElm: ElementNode,
37
+ ) => KeyHandlerReturn;
38
+ }
39
+
40
+ export type KeyNameOrKeyCode = string | number;
41
+
42
+ export interface DefaultKeyMap {
43
+ Left: KeyNameOrKeyCode | KeyNameOrKeyCode[];
44
+ Right: KeyNameOrKeyCode | KeyNameOrKeyCode[];
45
+ Up: KeyNameOrKeyCode | KeyNameOrKeyCode[];
46
+ Down: KeyNameOrKeyCode | KeyNameOrKeyCode[];
47
+ Enter: KeyNameOrKeyCode | KeyNameOrKeyCode[];
48
+ Last: KeyNameOrKeyCode | KeyNameOrKeyCode[];
49
+ }
50
+
51
+ export interface KeyMap extends DefaultKeyMap {
52
+ [key: string]: KeyNameOrKeyCode | KeyNameOrKeyCode[];
53
+ }
54
+
55
+ export interface DefaultKeyHoldMap {
56
+ EnterHold: KeyNameOrKeyCode | KeyNameOrKeyCode[];
57
+ }
58
+
59
+ export type EventHandlers<Map> = {
60
+ [K in keyof Map as `on${Capitalize<string & K>}`]?: KeyHandler;
61
+ } & {
62
+ [K in keyof Map as `on${Capitalize<string & K>}Release`]?: KeyHandler;
63
+ } & {
64
+ [K in keyof Map as `onCapture${Capitalize<string & K>}`]?: KeyHandler;
65
+ } & {
66
+ onCaptureKey?: KeyHandler;
67
+ onCaptureKeyRelease?: KeyHandler;
68
+ };
69
+
70
+ export interface KeyHoldMap extends DefaultKeyHoldMap {}
71
+
72
+ export type KeyHandlerReturn = boolean | void;
73
+
74
+ export type KeyHandler = (
75
+ this: ElementNode,
76
+ e: KeyboardEvent,
77
+ target: ElementNode,
78
+ handlerElm: ElementNode,
79
+ mappedEvent?: string,
80
+ ) => KeyHandlerReturn;
81
+
82
+ export type ForwardFocusHandler = (
83
+ this: ElementNode,
84
+ elm: ElementNode,
85
+ ) => boolean | void;
86
+
87
+ export type KeyHoldOptions = {
88
+ userKeyHoldMap: Partial<KeyHoldMap>;
89
+ holdThreshold?: number;
90
+ };