@solidtv/solid 1.1.3 → 1.3.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 (70) hide show
  1. package/README.md +2 -2
  2. package/dist/src/core/config.d.ts +13 -1
  3. package/dist/src/core/config.js +13 -1
  4. package/dist/src/core/config.js.map +1 -1
  5. package/dist/src/core/dom-renderer/domRenderer.js +1 -0
  6. package/dist/src/core/dom-renderer/domRenderer.js.map +1 -1
  7. package/dist/src/core/dom-renderer/domRendererUtils.js +2 -2
  8. package/dist/src/core/dom-renderer/domRendererUtils.js.map +1 -1
  9. package/dist/src/core/elementNode.d.ts +10 -4
  10. package/dist/src/core/elementNode.js +60 -49
  11. package/dist/src/core/elementNode.js.map +1 -1
  12. package/dist/src/core/flex.js +124 -52
  13. package/dist/src/core/flex.js.map +1 -1
  14. package/dist/src/core/focusKeyTypes.d.ts +14 -0
  15. package/dist/src/core/focusManager.d.ts +19 -9
  16. package/dist/src/core/focusManager.js +125 -101
  17. package/dist/src/core/focusManager.js.map +1 -1
  18. package/dist/src/core/lightningInit.js +3 -0
  19. package/dist/src/core/lightningInit.js.map +1 -1
  20. package/dist/src/core/shaders.js +10 -10
  21. package/dist/src/core/shaders.js.map +1 -1
  22. package/dist/src/core/utils.d.ts +0 -1
  23. package/dist/src/core/utils.js +0 -1
  24. package/dist/src/core/utils.js.map +1 -1
  25. package/dist/src/index.d.ts +1 -1
  26. package/dist/src/index.js +1 -1
  27. package/dist/src/index.js.map +1 -1
  28. package/dist/src/primitives/FadeInOut.jsx +1 -2
  29. package/dist/src/primitives/FadeInOut.jsx.map +1 -1
  30. package/dist/src/primitives/useFocusManager.d.ts +1 -5
  31. package/dist/src/primitives/useFocusManager.js +1 -20
  32. package/dist/src/primitives/useFocusManager.js.map +1 -1
  33. package/dist/src/primitives/useHold.d.ts +1 -1
  34. package/dist/src/primitives/useHold.js +1 -1
  35. package/dist/src/primitives/useMouse.js +4 -4
  36. package/dist/src/primitives/useMouse.js.map +1 -1
  37. package/dist/src/render.d.ts +6 -0
  38. package/dist/src/render.js +7 -3
  39. package/dist/src/render.js.map +1 -1
  40. package/dist/src/solidOpts.d.ts +1 -1
  41. package/dist/src/solidOpts.js +4 -23
  42. package/dist/src/solidOpts.js.map +1 -1
  43. package/dist/tsconfig.tsbuildinfo +1 -1
  44. package/docs/AI_CODING_GUIDELINES.md +7 -7
  45. package/package.json +2 -2
  46. package/src/core/config.ts +15 -2
  47. package/src/core/dom-renderer/domRenderer.ts +1 -0
  48. package/src/core/dom-renderer/domRendererUtils.ts +2 -2
  49. package/src/core/elementNode.ts +66 -46
  50. package/src/core/flex.ts +135 -56
  51. package/src/core/focusKeyTypes.ts +14 -0
  52. package/src/core/focusManager.ts +183 -139
  53. package/src/core/lightningInit.ts +3 -0
  54. package/src/core/shaders.ts +10 -10
  55. package/src/core/utils.ts +0 -3
  56. package/src/index.ts +1 -1
  57. package/src/primitives/FadeInOut.tsx +2 -2
  58. package/src/primitives/useFocusManager.ts +5 -44
  59. package/src/primitives/useHold.ts +1 -1
  60. package/src/primitives/useMouse.ts +4 -4
  61. package/src/render.ts +7 -3
  62. package/src/solidOpts.ts +4 -25
  63. package/dist/src/activeElement.d.ts +0 -2
  64. package/dist/src/activeElement.js +0 -3
  65. package/dist/src/activeElement.js.map +0 -1
  66. package/dist/src/core/flexLayout.d.ts +0 -2
  67. package/dist/src/core/flexLayout.js +0 -356
  68. package/dist/src/core/flexLayout.js.map +0 -1
  69. package/src/activeElement.ts +0 -5
  70. package/src/core/flexLayout.ts +0 -410
@@ -1,410 +0,0 @@
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 ?? 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
-
45
- const minDimension = isRow ? 'minWidth' : 'minHeight';
46
- const crossMinDimension = isRow ? 'minHeight' : 'minWidth';
47
-
48
- const children = node.children;
49
- const numChildren = children.length;
50
-
51
- if (numChildren === 0) {
52
- return false;
53
- }
54
-
55
- // Optimize arrays caching
56
- const processableChildrenIndices: number[] = [];
57
- let hasOrder = false;
58
- let totalFlexGrow = 0;
59
- let totalFlexShrink = 0;
60
-
61
- for (let i = 0; i < numChildren; i++) {
62
- const c = children[i]!;
63
-
64
- if (isElementText(c) && c.text && !(c.width || c.height)) {
65
- return false; // specific text layout constraint
66
- }
67
-
68
- if (isTextNode(c) || c.flexItem === false) {
69
- continue;
70
- }
71
-
72
- if (c.flexOrder !== undefined) {
73
- hasOrder = true;
74
- }
75
-
76
- const flexGrow = c.flexGrow;
77
- if (flexGrow !== undefined && flexGrow > 0) {
78
- totalFlexGrow += flexGrow;
79
- }
80
-
81
- const flexShrink = c.flexShrink;
82
- if (flexShrink !== undefined && flexShrink > 0) {
83
- totalFlexShrink += flexShrink;
84
- }
85
-
86
- if (c[minDimension] && (c[dimension] || 0) < c[minDimension]) {
87
- c[dimension] = c[minDimension]!;
88
- }
89
-
90
- if (
91
- c[crossMinDimension] &&
92
- (c[crossDimension] || 0) < c[crossMinDimension]
93
- ) {
94
- c[crossDimension] = c[crossMinDimension]!;
95
- }
96
-
97
- processableChildrenIndices.push(i);
98
- }
99
-
100
- if (hasOrder) {
101
- processableChildrenIndices.sort((aIdx, bIdx) => {
102
- const a = children[aIdx] as ElementNode;
103
- const b = children[bIdx] as ElementNode;
104
- return (a.flexOrder || 0) - (b.flexOrder || 0);
105
- });
106
- }
107
-
108
- // Apply reverse layout ordering
109
- if (isReverse || node.direction === 'rtl') {
110
- processableChildrenIndices.reverse();
111
- }
112
-
113
- const numProcessedChildren = processableChildrenIndices.length;
114
- if (numProcessedChildren === 0) {
115
- return false;
116
- }
117
-
118
- const prop = isRow ? 'x' : 'y';
119
- const crossProp = isRow ? 'y' : 'x';
120
- const containerSize = Math.max(
121
- node[dimension] || 0,
122
- node[minDimension] || 0,
123
- 0,
124
- );
125
- let containerCrossSize = Math.max(
126
- node[crossDimension] || 0,
127
- node[crossMinDimension] || 0,
128
- 0,
129
- );
130
- const isWrapReverse = node.flexWrap === 'wrap-reverse';
131
- const gap = node.gap || 0;
132
- const justify = node.justifyContent || 'flexStart';
133
- const align = node.alignItems || (node.flexWrap ? 'flexStart' : undefined);
134
- let containerUpdated = false;
135
-
136
- // Resolve sizes matching old processed calculation
137
- const childMainSizes = new Float32Array(numProcessedChildren);
138
- const childMarginStarts = new Float32Array(numProcessedChildren);
139
- const childMarginEnds = new Float32Array(numProcessedChildren);
140
- const childTotalMainSizes = new Float32Array(numProcessedChildren);
141
- const childCrossSizes = new Float32Array(numProcessedChildren);
142
- const childMarginCrossStarts = new Float32Array(numProcessedChildren);
143
- const childMarginCrossEnds = new Float32Array(numProcessedChildren);
144
-
145
- let sumOfFlexBaseSizesWithMargins = 0;
146
-
147
- for (let idx = 0; idx < numProcessedChildren; idx++) {
148
- 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);
173
-
174
- childMainSizes[idx] = baseMainSize;
175
- childMarginStarts[idx] = marginStart;
176
- childMarginEnds[idx] = marginEnd;
177
- childTotalMainSizes[idx] = baseMainSize + marginStart + marginEnd;
178
- childCrossSizes[idx] = c[crossDimension] || 0;
179
- childMarginCrossStarts[idx] = marginCrossStart;
180
- childMarginCrossEnds[idx] = marginCrossEnd;
181
-
182
- sumOfFlexBaseSizesWithMargins += childTotalMainSizes[idx]!;
183
- }
184
-
185
- if ((totalFlexGrow > 0 || totalFlexShrink > 0) && numProcessedChildren > 1) {
186
- node.flexBoundary = node.flexBoundary || 'fixed';
187
-
188
- const totalGapSpace =
189
- numProcessedChildren > 0 ? gap * (numProcessedChildren - 1) : 0;
190
- const availableSpace =
191
- containerSize - sumOfFlexBaseSizesWithMargins - totalGapSpace;
192
-
193
- if (availableSpace > 0 && totalFlexGrow > 0) {
194
- for (let idx = 0; idx < numProcessedChildren; idx++) {
195
- const c = children[processableChildrenIndices[idx]!] as ElementNode;
196
- const flexGrowValue = c.flexGrow || 0;
197
- if (flexGrowValue > 0) {
198
- const shareOfSpace = (flexGrowValue / totalFlexGrow) * availableSpace;
199
- const newMainSize = childMainSizes[idx]! + shareOfSpace;
200
- c[dimension] = newMainSize;
201
- childMainSizes[idx] = newMainSize;
202
- childTotalMainSizes[idx] =
203
- newMainSize + childMarginStarts[idx]! + childMarginEnds[idx]!;
204
- }
205
- }
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
- }
240
- node._containsFlexGrow = node._containsFlexGrow ? null : true;
241
- } else if (node._containsFlexGrow) {
242
- node._containsFlexGrow = null;
243
- }
244
- }
245
-
246
- let totalItemSize = 0;
247
- if (
248
- justify === 'center' ||
249
- justify === 'spaceBetween' ||
250
- justify === 'spaceEvenly' ||
251
- justify === 'spaceAround'
252
- ) {
253
- for (let idx = 0; idx < numProcessedChildren; idx++) {
254
- totalItemSize += childTotalMainSizes[idx]!;
255
- }
256
- }
257
-
258
- const doCrossAlign = containerCrossSize
259
- ? (c: ElementNode, idx: number, crossCurrentPos: number = 0) => {
260
- const alignSelf = c.alignSelf || align;
261
- if (!alignSelf) {
262
- return;
263
- }
264
- if (alignSelf === 'flexStart') {
265
- c[crossProp] = crossCurrentPos + childMarginCrossStarts[idx]!;
266
- } else if (alignSelf === 'center') {
267
- c[crossProp] =
268
- crossCurrentPos +
269
- (containerCrossSize - childCrossSizes[idx]!) / 2 +
270
- childMarginCrossStarts[idx]!;
271
- } else if (alignSelf === 'flexEnd') {
272
- c[crossProp] =
273
- crossCurrentPos +
274
- containerCrossSize -
275
- childCrossSizes[idx]! -
276
- childMarginCrossEnds[idx]!;
277
- }
278
- }
279
- : (_c: ElementNode, _idx: number, _crossCurrentPos: number = 0) => {
280
- /* no-op */
281
- };
282
-
283
- if (isRow && node._calcHeight && !node.flexCrossBoundary) {
284
- let maxHeight = 0;
285
- for (let idx = 0; idx < numProcessedChildren; idx++) {
286
- if (childCrossSizes[idx]! > maxHeight) maxHeight = childCrossSizes[idx]!;
287
- }
288
- const newHeight = maxHeight || node.height;
289
- if (newHeight !== node.height) {
290
- containerUpdated = true;
291
- node.height = containerCrossSize = newHeight;
292
- }
293
- }
294
-
295
- let currentPos = paddingStart;
296
- if (justify === 'flexStart') {
297
- if (node.flexWrap === 'wrap') {
298
- const childCrossSizeVar =
299
- numProcessedChildren > 0 ? childCrossSizes[0]! : containerCrossSize;
300
- let crossCurrentPos = isWrapReverse
301
- ? containerCrossSize - paddingCrossEnd - childCrossSizeVar
302
- : paddingCrossStart;
303
- const crossGap = isRow ? (node.columnGap ?? gap) : (node.rowGap ?? gap);
304
-
305
- for (let idx = 0; idx < numProcessedChildren; idx++) {
306
- const c = children[processableChildrenIndices[idx]!] as ElementNode;
307
- if (
308
- currentPos + childTotalMainSizes[idx]! > containerSize &&
309
- currentPos > paddingStart
310
- ) {
311
- currentPos = paddingStart;
312
- crossCurrentPos += isWrapReverse
313
- ? -(childCrossSizeVar + crossGap)
314
- : childCrossSizeVar + crossGap;
315
- }
316
- c[prop] = currentPos + childMarginStarts[idx]!;
317
- currentPos += childTotalMainSizes[idx]! + gap;
318
- doCrossAlign(c, idx, crossCurrentPos);
319
- }
320
-
321
- const finalCrossSize = isWrapReverse
322
- ? containerCrossSize - crossCurrentPos + paddingCrossStart
323
- : crossCurrentPos + childCrossSizeVar + paddingCrossEnd;
324
-
325
- if (node[crossDimension] !== finalCrossSize) {
326
- node[`preFlex${crossDimension}`] = node[crossDimension];
327
- node[crossDimension] = finalCrossSize;
328
- containerUpdated = true;
329
- }
330
- } else {
331
- for (let idx = 0; idx < numProcessedChildren; idx++) {
332
- const c = children[processableChildrenIndices[idx]!] as ElementNode;
333
- c[prop] = currentPos + childMarginStarts[idx]!;
334
- currentPos += childTotalMainSizes[idx]! + gap;
335
- doCrossAlign(c, idx, paddingCrossStart);
336
- }
337
- }
338
-
339
- // Update container size
340
- if (node.flexBoundary !== 'fixed' && node.flexWrap !== 'wrap') {
341
- let calculatedSize = currentPos - gap + paddingEnd;
342
- const minSize = node[minDimension] || 0;
343
- if (calculatedSize < minSize) {
344
- calculatedSize = minSize;
345
- }
346
- if (calculatedSize !== (node[dimension] || 0)) {
347
- node[`preFlex${dimension}`] = containerSize;
348
- node[dimension] = calculatedSize;
349
- return true;
350
- }
351
- }
352
- } else if (justify === 'flexEnd') {
353
- currentPos = containerSize - paddingEnd;
354
- for (let idx = numProcessedChildren - 1; idx >= 0; idx--) {
355
- const c = children[processableChildrenIndices[idx]!] as ElementNode;
356
- c[prop] = currentPos - childMainSizes[idx]! - childMarginEnds[idx]!;
357
- currentPos -= childTotalMainSizes[idx]! + gap;
358
- doCrossAlign(c, idx, paddingCrossStart);
359
- }
360
- } else if (justify === 'center') {
361
- currentPos =
362
- (containerSize - (totalItemSize + gap * (numProcessedChildren - 1))) / 2 +
363
- paddingStart;
364
- for (let idx = 0; idx < numProcessedChildren; idx++) {
365
- const c = children[processableChildrenIndices[idx]!] as ElementNode;
366
- c[prop] = currentPos + childMarginStarts[idx]!;
367
- currentPos += childTotalMainSizes[idx]! + gap;
368
- doCrossAlign(c, idx, paddingCrossStart);
369
- }
370
- } else if (justify === 'spaceBetween') {
371
- const spaceBetween =
372
- numProcessedChildren > 1
373
- ? (containerSize - totalItemSize - nodePaddingTotal) /
374
- (numProcessedChildren - 1)
375
- : 0;
376
- currentPos = paddingStart;
377
- for (let idx = 0; idx < numProcessedChildren; idx++) {
378
- const c = children[processableChildrenIndices[idx]!] as ElementNode;
379
- c[prop] = currentPos + childMarginStarts[idx]!;
380
- currentPos += childTotalMainSizes[idx]! + spaceBetween;
381
- doCrossAlign(c, idx, paddingCrossStart);
382
- }
383
- } else if (justify === 'spaceAround') {
384
- const spaceAround =
385
- numProcessedChildren > 0
386
- ? (containerSize - totalItemSize - nodePaddingTotal) /
387
- numProcessedChildren
388
- : 0;
389
- currentPos = paddingStart + spaceAround / 2;
390
- for (let idx = 0; idx < numProcessedChildren; idx++) {
391
- const c = children[processableChildrenIndices[idx]!] as ElementNode;
392
- c[prop] = currentPos + childMarginStarts[idx]!;
393
- currentPos += childTotalMainSizes[idx]! + spaceAround;
394
- doCrossAlign(c, idx, paddingCrossStart);
395
- }
396
- } else if (justify === 'spaceEvenly') {
397
- const spaceEvenly =
398
- (containerSize - totalItemSize - nodePaddingTotal) /
399
- (numProcessedChildren + 1);
400
- currentPos = spaceEvenly + paddingStart;
401
- for (let idx = 0; idx < numProcessedChildren; idx++) {
402
- const c = children[processableChildrenIndices[idx]!] as ElementNode;
403
- c[prop] = currentPos + childMarginStarts[idx]!;
404
- currentPos += childTotalMainSizes[idx]! + spaceEvenly;
405
- doCrossAlign(c, idx, paddingCrossStart);
406
- }
407
- }
408
-
409
- return containerUpdated;
410
- }