@rezi-ui/core 0.1.0-alpha.60 → 0.1.0-alpha.63

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 (345) hide show
  1. package/dist/app/createApp/breadcrumbs.d.ts +38 -0
  2. package/dist/app/createApp/breadcrumbs.d.ts.map +1 -0
  3. package/dist/app/createApp/breadcrumbs.js +65 -0
  4. package/dist/app/createApp/breadcrumbs.js.map +1 -0
  5. package/dist/app/createApp/config.d.ts +25 -0
  6. package/dist/app/createApp/config.d.ts.map +1 -0
  7. package/dist/app/createApp/config.js +130 -0
  8. package/dist/app/createApp/config.js.map +1 -0
  9. package/dist/app/createApp/eventLoop.d.ts +95 -0
  10. package/dist/app/createApp/eventLoop.d.ts.map +1 -0
  11. package/dist/app/createApp/eventLoop.js +384 -0
  12. package/dist/app/createApp/eventLoop.js.map +1 -0
  13. package/dist/app/createApp/guards.d.ts +21 -0
  14. package/dist/app/createApp/guards.d.ts.map +1 -0
  15. package/dist/app/createApp/guards.js +54 -0
  16. package/dist/app/createApp/guards.js.map +1 -0
  17. package/dist/app/createApp/keybindings.d.ts +28 -0
  18. package/dist/app/createApp/keybindings.d.ts.map +1 -0
  19. package/dist/app/createApp/keybindings.js +113 -0
  20. package/dist/app/createApp/keybindings.js.map +1 -0
  21. package/dist/app/createApp/renderLoop.d.ts +64 -0
  22. package/dist/app/createApp/renderLoop.d.ts.map +1 -0
  23. package/dist/app/createApp/renderLoop.js +305 -0
  24. package/dist/app/createApp/renderLoop.js.map +1 -0
  25. package/dist/app/createApp.d.ts +3 -39
  26. package/dist/app/createApp.d.ts.map +1 -1
  27. package/dist/app/createApp.js +403 -1205
  28. package/dist/app/createApp.js.map +1 -1
  29. package/dist/app/widgetRenderer/constraintState.d.ts +98 -0
  30. package/dist/app/widgetRenderer/constraintState.d.ts.map +1 -0
  31. package/dist/app/widgetRenderer/constraintState.js +563 -0
  32. package/dist/app/widgetRenderer/constraintState.js.map +1 -0
  33. package/dist/app/widgetRenderer/fileNodeCache.d.ts +2 -0
  34. package/dist/app/widgetRenderer/fileNodeCache.d.ts.map +1 -1
  35. package/dist/app/widgetRenderer/fileNodeCache.js +31 -0
  36. package/dist/app/widgetRenderer/fileNodeCache.js.map +1 -1
  37. package/dist/app/widgetRenderer/filePickerRouting.d.ts +12 -1
  38. package/dist/app/widgetRenderer/filePickerRouting.d.ts.map +1 -1
  39. package/dist/app/widgetRenderer/filePickerRouting.js +63 -14
  40. package/dist/app/widgetRenderer/filePickerRouting.js.map +1 -1
  41. package/dist/app/widgetRenderer/focusState.d.ts +46 -0
  42. package/dist/app/widgetRenderer/focusState.d.ts.map +1 -0
  43. package/dist/app/widgetRenderer/focusState.js +122 -0
  44. package/dist/app/widgetRenderer/focusState.js.map +1 -0
  45. package/dist/app/widgetRenderer/keyboardRouting.d.ts.map +1 -1
  46. package/dist/app/widgetRenderer/keyboardRouting.js.map +1 -1
  47. package/dist/app/widgetRenderer/mouseRouting.d.ts +5 -0
  48. package/dist/app/widgetRenderer/mouseRouting.d.ts.map +1 -1
  49. package/dist/app/widgetRenderer/mouseRouting.js +78 -8
  50. package/dist/app/widgetRenderer/mouseRouting.js.map +1 -1
  51. package/dist/app/widgetRenderer/overlayShortcuts.d.ts.map +1 -1
  52. package/dist/app/widgetRenderer/overlayShortcuts.js +14 -4
  53. package/dist/app/widgetRenderer/overlayShortcuts.js.map +1 -1
  54. package/dist/app/widgetRenderer/overlayState.d.ts +198 -0
  55. package/dist/app/widgetRenderer/overlayState.d.ts.map +1 -0
  56. package/dist/app/widgetRenderer/overlayState.js +590 -0
  57. package/dist/app/widgetRenderer/overlayState.js.map +1 -0
  58. package/dist/app/widgetRenderer/routeEngineEvent.d.ts +189 -0
  59. package/dist/app/widgetRenderer/routeEngineEvent.d.ts.map +1 -0
  60. package/dist/app/widgetRenderer/routeEngineEvent.js +527 -0
  61. package/dist/app/widgetRenderer/routeEngineEvent.js.map +1 -0
  62. package/dist/app/widgetRenderer.d.ts +2 -1
  63. package/dist/app/widgetRenderer.d.ts.map +1 -1
  64. package/dist/app/widgetRenderer.js +334 -1707
  65. package/dist/app/widgetRenderer.js.map +1 -1
  66. package/dist/forms/internal/arrayState.d.ts +35 -0
  67. package/dist/forms/internal/arrayState.d.ts.map +1 -0
  68. package/dist/forms/internal/arrayState.js +238 -0
  69. package/dist/forms/internal/arrayState.js.map +1 -0
  70. package/dist/forms/internal/bindings.d.ts +46 -0
  71. package/dist/forms/internal/bindings.d.ts.map +1 -0
  72. package/dist/forms/internal/bindings.js +161 -0
  73. package/dist/forms/internal/bindings.js.map +1 -0
  74. package/dist/forms/internal/dev.d.ts +4 -0
  75. package/dist/forms/internal/dev.d.ts.map +1 -0
  76. package/dist/forms/internal/dev.js +21 -0
  77. package/dist/forms/internal/dev.js.map +1 -0
  78. package/dist/forms/internal/state.d.ts +52 -0
  79. package/dist/forms/internal/state.d.ts.map +1 -0
  80. package/dist/forms/internal/state.js +240 -0
  81. package/dist/forms/internal/state.js.map +1 -0
  82. package/dist/forms/internal/submit.d.ts +43 -0
  83. package/dist/forms/internal/submit.d.ts.map +1 -0
  84. package/dist/forms/internal/submit.js +165 -0
  85. package/dist/forms/internal/submit.js.map +1 -0
  86. package/dist/forms/internal/wizard.d.ts +53 -0
  87. package/dist/forms/internal/wizard.d.ts.map +1 -0
  88. package/dist/forms/internal/wizard.js +311 -0
  89. package/dist/forms/internal/wizard.js.map +1 -0
  90. package/dist/forms/useForm.d.ts.map +1 -1
  91. package/dist/forms/useForm.js +90 -1117
  92. package/dist/forms/useForm.js.map +1 -1
  93. package/dist/index.d.ts +1 -1
  94. package/dist/index.d.ts.map +1 -1
  95. package/dist/index.js +1 -1
  96. package/dist/index.js.map +1 -1
  97. package/dist/keybindings/manager.d.ts.map +1 -1
  98. package/dist/keybindings/manager.js.map +1 -1
  99. package/dist/keybindings/parser.d.ts.map +1 -1
  100. package/dist/keybindings/parser.js +10 -5
  101. package/dist/keybindings/parser.js.map +1 -1
  102. package/dist/layout/dropdownGeometry.d.ts +8 -0
  103. package/dist/layout/dropdownGeometry.d.ts.map +1 -1
  104. package/dist/layout/dropdownGeometry.js +40 -0
  105. package/dist/layout/dropdownGeometry.js.map +1 -1
  106. package/dist/layout/engine/layoutEngine.js +1 -1
  107. package/dist/layout/engine/layoutEngine.js.map +1 -1
  108. package/dist/layout/kinds/overlays.d.ts.map +1 -1
  109. package/dist/layout/kinds/stack.d.ts +1 -3
  110. package/dist/layout/kinds/stack.d.ts.map +1 -1
  111. package/dist/layout/kinds/stack.js +11 -1523
  112. package/dist/layout/kinds/stack.js.map +1 -1
  113. package/dist/layout/kinds/stackParts/axis.d.ts +32 -0
  114. package/dist/layout/kinds/stackParts/axis.d.ts.map +1 -0
  115. package/dist/layout/kinds/stackParts/axis.js +61 -0
  116. package/dist/layout/kinds/stackParts/axis.js.map +1 -0
  117. package/dist/layout/kinds/stackParts/constraintPlan.d.ts +18 -0
  118. package/dist/layout/kinds/stackParts/constraintPlan.d.ts.map +1 -0
  119. package/dist/layout/kinds/stackParts/constraintPlan.js +434 -0
  120. package/dist/layout/kinds/stackParts/constraintPlan.js.map +1 -0
  121. package/dist/layout/kinds/stackParts/layout.d.ts +6 -0
  122. package/dist/layout/kinds/stackParts/layout.d.ts.map +1 -0
  123. package/dist/layout/kinds/stackParts/layout.js +376 -0
  124. package/dist/layout/kinds/stackParts/layout.js.map +1 -0
  125. package/dist/layout/kinds/stackParts/measure.d.ts +6 -0
  126. package/dist/layout/kinds/stackParts/measure.d.ts.map +1 -0
  127. package/dist/layout/kinds/stackParts/measure.js +212 -0
  128. package/dist/layout/kinds/stackParts/measure.js.map +1 -0
  129. package/dist/layout/kinds/stackParts/shared.d.ts +31 -0
  130. package/dist/layout/kinds/stackParts/shared.d.ts.map +1 -0
  131. package/dist/layout/kinds/stackParts/shared.js +94 -0
  132. package/dist/layout/kinds/stackParts/shared.js.map +1 -0
  133. package/dist/layout/kinds/stackParts/wrap.d.ts +26 -0
  134. package/dist/layout/kinds/stackParts/wrap.d.ts.map +1 -0
  135. package/dist/layout/kinds/stackParts/wrap.js +374 -0
  136. package/dist/layout/kinds/stackParts/wrap.js.map +1 -0
  137. package/dist/layout/validate/interactive.d.ts +106 -0
  138. package/dist/layout/validate/interactive.d.ts.map +1 -0
  139. package/dist/layout/validate/interactive.js +430 -0
  140. package/dist/layout/validate/interactive.js.map +1 -0
  141. package/dist/layout/validate/layoutConstraints.d.ts +51 -0
  142. package/dist/layout/validate/layoutConstraints.d.ts.map +1 -0
  143. package/dist/layout/validate/layoutConstraints.js +100 -0
  144. package/dist/layout/validate/layoutConstraints.js.map +1 -0
  145. package/dist/layout/validate/primitives.d.ts +31 -0
  146. package/dist/layout/validate/primitives.d.ts.map +1 -0
  147. package/dist/layout/validate/primitives.js +299 -0
  148. package/dist/layout/validate/primitives.js.map +1 -0
  149. package/dist/layout/validate/shared.d.ts +23 -0
  150. package/dist/layout/validate/shared.d.ts.map +1 -0
  151. package/dist/layout/validate/shared.js +32 -0
  152. package/dist/layout/validate/shared.js.map +1 -0
  153. package/dist/layout/validate/spacing.d.ts +21 -0
  154. package/dist/layout/validate/spacing.d.ts.map +1 -0
  155. package/dist/layout/validate/spacing.js +33 -0
  156. package/dist/layout/validate/spacing.js.map +1 -0
  157. package/dist/layout/validateProps.d.ts +5 -159
  158. package/dist/layout/validateProps.d.ts.map +1 -1
  159. package/dist/layout/validateProps.js +1 -832
  160. package/dist/layout/validateProps.js.map +1 -1
  161. package/dist/pipeline.js +1 -1
  162. package/dist/pipeline.js.map +1 -1
  163. package/dist/renderer/renderToDrawlist/renderTree.d.ts +1 -1
  164. package/dist/renderer/renderToDrawlist/renderTree.d.ts.map +1 -1
  165. package/dist/renderer/renderToDrawlist/renderTree.js +3 -3
  166. package/dist/renderer/renderToDrawlist/renderTree.js.map +1 -1
  167. package/dist/renderer/renderToDrawlist/types.d.ts +2 -0
  168. package/dist/renderer/renderToDrawlist/types.d.ts.map +1 -1
  169. package/dist/renderer/renderToDrawlist/widgets/containers.d.ts.map +1 -1
  170. package/dist/renderer/renderToDrawlist/widgets/containers.js +1 -1
  171. package/dist/renderer/renderToDrawlist/widgets/containers.js.map +1 -1
  172. package/dist/renderer/renderToDrawlist/widgets/files.d.ts +2 -1
  173. package/dist/renderer/renderToDrawlist/widgets/files.d.ts.map +1 -1
  174. package/dist/renderer/renderToDrawlist/widgets/files.js +30 -3
  175. package/dist/renderer/renderToDrawlist/widgets/files.js.map +1 -1
  176. package/dist/renderer/renderToDrawlist/widgets/overlays.d.ts +1 -1
  177. package/dist/renderer/renderToDrawlist/widgets/overlays.d.ts.map +1 -1
  178. package/dist/renderer/renderToDrawlist/widgets/overlays.js +26 -6
  179. package/dist/renderer/renderToDrawlist/widgets/overlays.js.map +1 -1
  180. package/dist/renderer/renderToDrawlist/widgets/renderFormWidgets.d.ts.map +1 -1
  181. package/dist/renderer/renderToDrawlist/widgets/renderFormWidgets.js +52 -18
  182. package/dist/renderer/renderToDrawlist/widgets/renderFormWidgets.js.map +1 -1
  183. package/dist/renderer/renderToDrawlist.d.ts +0 -8
  184. package/dist/renderer/renderToDrawlist.d.ts.map +1 -1
  185. package/dist/renderer/renderToDrawlist.js +1 -9
  186. package/dist/renderer/renderToDrawlist.js.map +1 -1
  187. package/dist/runtime/commit/composite.d.ts +11 -0
  188. package/dist/runtime/commit/composite.d.ts.map +1 -0
  189. package/dist/runtime/commit/composite.js +238 -0
  190. package/dist/runtime/commit/composite.js.map +1 -0
  191. package/dist/runtime/commit/container.d.ts +7 -0
  192. package/dist/runtime/commit/container.d.ts.map +1 -0
  193. package/dist/runtime/commit/container.js +350 -0
  194. package/dist/runtime/commit/container.js.map +1 -0
  195. package/dist/runtime/commit/equality.d.ts +20 -0
  196. package/dist/runtime/commit/equality.d.ts.map +1 -0
  197. package/dist/runtime/commit/equality.js +436 -0
  198. package/dist/runtime/commit/equality.js.map +1 -0
  199. package/dist/runtime/commit/errorBoundary.d.ts +7 -0
  200. package/dist/runtime/commit/errorBoundary.d.ts.map +1 -0
  201. package/dist/runtime/commit/errorBoundary.js +53 -0
  202. package/dist/runtime/commit/errorBoundary.js.map +1 -0
  203. package/dist/runtime/commit/shared.d.ts +138 -0
  204. package/dist/runtime/commit/shared.d.ts.map +1 -0
  205. package/dist/runtime/commit/shared.js +11 -0
  206. package/dist/runtime/commit/shared.js.map +1 -0
  207. package/dist/runtime/commit/transitions.d.ts +9 -0
  208. package/dist/runtime/commit/transitions.d.ts.map +1 -0
  209. package/dist/runtime/commit/transitions.js +93 -0
  210. package/dist/runtime/commit/transitions.js.map +1 -0
  211. package/dist/runtime/commit/validation.d.ts +16 -0
  212. package/dist/runtime/commit/validation.d.ts.map +1 -0
  213. package/dist/runtime/commit/validation.js +157 -0
  214. package/dist/runtime/commit/validation.js.map +1 -0
  215. package/dist/runtime/commit.d.ts +7 -117
  216. package/dist/runtime/commit.d.ts.map +1 -1
  217. package/dist/runtime/commit.js +13 -1394
  218. package/dist/runtime/commit.js.map +1 -1
  219. package/dist/runtime/localState.d.ts +4 -0
  220. package/dist/runtime/localState.d.ts.map +1 -1
  221. package/dist/runtime/localState.js.map +1 -1
  222. package/dist/runtime/widgetMeta/collector.d.ts +77 -0
  223. package/dist/runtime/widgetMeta/collector.d.ts.map +1 -0
  224. package/dist/runtime/widgetMeta/collector.js +293 -0
  225. package/dist/runtime/widgetMeta/collector.js.map +1 -0
  226. package/dist/runtime/widgetMeta/focusContainers.d.ts +44 -0
  227. package/dist/runtime/widgetMeta/focusContainers.d.ts.map +1 -0
  228. package/dist/runtime/widgetMeta/focusContainers.js +190 -0
  229. package/dist/runtime/widgetMeta/focusContainers.js.map +1 -0
  230. package/dist/runtime/widgetMeta/focusInfo.d.ts +19 -0
  231. package/dist/runtime/widgetMeta/focusInfo.d.ts.map +1 -0
  232. package/dist/runtime/widgetMeta/focusInfo.js +172 -0
  233. package/dist/runtime/widgetMeta/focusInfo.js.map +1 -0
  234. package/dist/runtime/widgetMeta/helpers.d.ts +47 -0
  235. package/dist/runtime/widgetMeta/helpers.d.ts.map +1 -0
  236. package/dist/runtime/widgetMeta/helpers.js +182 -0
  237. package/dist/runtime/widgetMeta/helpers.js.map +1 -0
  238. package/dist/runtime/widgetMeta.d.ts +12 -175
  239. package/dist/runtime/widgetMeta.d.ts.map +1 -1
  240. package/dist/runtime/widgetMeta.js +6 -847
  241. package/dist/runtime/widgetMeta.js.map +1 -1
  242. package/dist/ui/capabilities.d.ts.map +1 -1
  243. package/dist/ui/designTokens.d.ts.map +1 -1
  244. package/dist/widgets/accordion.d.ts.map +1 -1
  245. package/dist/widgets/accordion.js +8 -13
  246. package/dist/widgets/accordion.js.map +1 -1
  247. package/dist/widgets/factories/advanced.d.ts +20 -0
  248. package/dist/widgets/factories/advanced.d.ts.map +1 -0
  249. package/dist/widgets/factories/advanced.js +75 -0
  250. package/dist/widgets/factories/advanced.js.map +1 -0
  251. package/dist/widgets/factories/basic.d.ts +14 -0
  252. package/dist/widgets/factories/basic.d.ts.map +1 -0
  253. package/dist/widgets/factories/basic.js +44 -0
  254. package/dist/widgets/factories/basic.js.map +1 -0
  255. package/dist/widgets/factories/feedback.d.ts +20 -0
  256. package/dist/widgets/factories/feedback.d.ts.map +1 -0
  257. package/dist/widgets/factories/feedback.js +102 -0
  258. package/dist/widgets/factories/feedback.js.map +1 -0
  259. package/dist/widgets/factories/helpers.d.ts +41 -0
  260. package/dist/widgets/factories/helpers.d.ts.map +1 -0
  261. package/dist/widgets/factories/helpers.js +72 -0
  262. package/dist/widgets/factories/helpers.js.map +1 -0
  263. package/dist/widgets/factories/interactive.d.ts +15 -0
  264. package/dist/widgets/factories/interactive.d.ts.map +1 -0
  265. package/dist/widgets/factories/interactive.js +46 -0
  266. package/dist/widgets/factories/interactive.js.map +1 -0
  267. package/dist/widgets/factories/layoutShell.d.ts +22 -0
  268. package/dist/widgets/factories/layoutShell.d.ts.map +1 -0
  269. package/dist/widgets/factories/layoutShell.js +190 -0
  270. package/dist/widgets/factories/layoutShell.js.map +1 -0
  271. package/dist/widgets/factories/media.d.ts +14 -0
  272. package/dist/widgets/factories/media.d.ts.map +1 -0
  273. package/dist/widgets/factories/media.js +25 -0
  274. package/dist/widgets/factories/media.js.map +1 -0
  275. package/dist/widgets/factories/navigation.d.ts +10 -0
  276. package/dist/widgets/factories/navigation.d.ts.map +1 -0
  277. package/dist/widgets/factories/navigation.js +24 -0
  278. package/dist/widgets/factories/navigation.js.map +1 -0
  279. package/dist/widgets/field.d.ts +6 -1
  280. package/dist/widgets/field.d.ts.map +1 -1
  281. package/dist/widgets/field.js +8 -2
  282. package/dist/widgets/field.js.map +1 -1
  283. package/dist/widgets/filePicker.d.ts +5 -0
  284. package/dist/widgets/filePicker.d.ts.map +1 -0
  285. package/dist/widgets/filePicker.js +136 -0
  286. package/dist/widgets/filePicker.js.map +1 -0
  287. package/dist/widgets/protocol.d.ts +0 -6
  288. package/dist/widgets/protocol.d.ts.map +1 -1
  289. package/dist/widgets/protocol.js +0 -6
  290. package/dist/widgets/protocol.js.map +1 -1
  291. package/dist/widgets/select.js +1 -1
  292. package/dist/widgets/select.js.map +1 -1
  293. package/dist/widgets/splitPane.d.ts.map +1 -1
  294. package/dist/widgets/splitPane.js.map +1 -1
  295. package/dist/widgets/table.d.ts.map +1 -1
  296. package/dist/widgets/table.js +43 -1
  297. package/dist/widgets/table.js.map +1 -1
  298. package/dist/widgets/tree.d.ts.map +1 -1
  299. package/dist/widgets/types/advanced.d.ts +611 -0
  300. package/dist/widgets/types/advanced.d.ts.map +1 -0
  301. package/dist/widgets/types/advanced.js +2 -0
  302. package/dist/widgets/types/advanced.js.map +1 -0
  303. package/dist/widgets/types/base.d.ts +933 -0
  304. package/dist/widgets/types/base.d.ts.map +1 -0
  305. package/dist/widgets/types/base.js +2 -0
  306. package/dist/widgets/types/base.js.map +1 -0
  307. package/dist/widgets/types/forms.d.ts +136 -0
  308. package/dist/widgets/types/forms.d.ts.map +1 -0
  309. package/dist/widgets/types/forms.js +2 -0
  310. package/dist/widgets/types/forms.js.map +1 -0
  311. package/dist/widgets/types/navigation.d.ts +83 -0
  312. package/dist/widgets/types/navigation.d.ts.map +1 -0
  313. package/dist/widgets/types/navigation.js +2 -0
  314. package/dist/widgets/types/navigation.js.map +1 -0
  315. package/dist/widgets/types/overlaysShell.d.ts +223 -0
  316. package/dist/widgets/types/overlaysShell.d.ts.map +1 -0
  317. package/dist/widgets/types/overlaysShell.js +2 -0
  318. package/dist/widgets/types/overlaysShell.js.map +1 -0
  319. package/dist/widgets/types/table.d.ts +104 -0
  320. package/dist/widgets/types/table.d.ts.map +1 -0
  321. package/dist/widgets/types/table.js +2 -0
  322. package/dist/widgets/types/table.js.map +1 -0
  323. package/dist/widgets/types/tree.d.ts +64 -0
  324. package/dist/widgets/types/tree.d.ts.map +1 -0
  325. package/dist/widgets/types/tree.js +2 -0
  326. package/dist/widgets/types/tree.js.map +1 -0
  327. package/dist/widgets/types.d.ts +14 -2123
  328. package/dist/widgets/types.d.ts.map +1 -1
  329. package/dist/widgets/ui.d.ts +37 -843
  330. package/dist/widgets/ui.d.ts.map +1 -1
  331. package/dist/widgets/ui.js +37 -1262
  332. package/dist/widgets/ui.js.map +1 -1
  333. package/package.json +2 -2
  334. package/dist/constraints/aggregation.d.ts +0 -17
  335. package/dist/constraints/aggregation.d.ts.map +0 -1
  336. package/dist/constraints/aggregation.js +0 -59
  337. package/dist/constraints/aggregation.js.map +0 -1
  338. package/dist/renderer/renderToDrawlist/overflowCulling.d.ts +0 -3
  339. package/dist/renderer/renderToDrawlist/overflowCulling.d.ts.map +0 -1
  340. package/dist/renderer/renderToDrawlist/overflowCulling.js +0 -81
  341. package/dist/renderer/renderToDrawlist/overflowCulling.js.map +0 -1
  342. package/dist/widgets/tests/protocol.test.d.ts +0 -2
  343. package/dist/widgets/tests/protocol.test.d.ts.map +0 -1
  344. package/dist/widgets/tests/protocol.test.js +0 -120
  345. package/dist/widgets/tests/protocol.test.js.map +0 -1
@@ -1,1545 +1,33 @@
1
- import { measureContentBounds, resolveAbsolutePosition, resolveLayoutConstraints, resolveOverflow, } from "../constraints.js";
2
- import { clampNonNegative, clampWithin, isPercentString, toFiniteMax } from "../engine/bounds.js";
3
- import { getActiveDirtySet } from "../engine/dirtySet.js";
4
- import { distributeInteger } from "../engine/distributeInteger.js";
5
- import { computeJustifyExtraGap, computeJustifyStartOffset, distributeFlex, shrinkFlex, } from "../engine/flex.js";
6
- import { childHasAbsolutePosition, childHasFlexInMainAxis, getConstraintProps, } from "../engine/guards.js";
7
- import { measureMaxContent, measureMinContent } from "../engine/intrinsic.js";
8
- import { acquireArray, releaseArray } from "../engine/pool.js";
9
- import { ok } from "../engine/result.js";
10
- import { resolveResponsiveValue } from "../responsive.js";
11
- import { resolveMargin as resolveMarginProps, resolveSpacing as resolveSpacingProps, } from "../spacing.js";
12
- import { validateSpacerProps, validateStackProps } from "../validateProps.js";
13
- const ROW_AXIS = Object.freeze({
14
- axis: "row",
15
- crossAxis: "column",
16
- mainSize: "w",
17
- crossSize: "h",
18
- mainPos: "x",
19
- crossPos: "y",
20
- mainProp: "width",
21
- crossProp: "height",
22
- minMainProp: "minWidth",
23
- maxMainProp: "maxWidth",
24
- minCrossProp: "minHeight",
25
- maxCrossProp: "maxHeight",
26
- });
27
- const COL_AXIS = Object.freeze({
28
- axis: "column",
29
- crossAxis: "row",
30
- mainSize: "h",
31
- crossSize: "w",
32
- mainPos: "y",
33
- crossPos: "x",
34
- mainProp: "height",
35
- crossProp: "width",
36
- minMainProp: "minHeight",
37
- maxMainProp: "maxHeight",
38
- minCrossProp: "minWidth",
39
- maxCrossProp: "maxWidth",
40
- });
41
- function resolveEffectiveAlign(child, align) {
42
- const childAlignSelfRaw = getConstraintProps(child)
43
- ?.alignSelf;
44
- if (childAlignSelfRaw === "start" ||
45
- childAlignSelfRaw === "center" ||
46
- childAlignSelfRaw === "end" ||
47
- childAlignSelfRaw === "stretch") {
48
- return childAlignSelfRaw;
49
- }
50
- return align;
51
- }
52
- function childHasAdvancedFlexProps(vnode) {
53
- const props = getConstraintProps(vnode);
54
- if (!props)
55
- return false;
56
- const rawShrink = props.flexShrink;
57
- if (typeof rawShrink === "number" && Number.isFinite(rawShrink) && rawShrink > 0) {
58
- return true;
59
- }
60
- return props.flexBasis !== undefined;
61
- }
62
- function getAxisConfig(kind) {
63
- switch (kind) {
64
- case "row":
65
- return ROW_AXIS;
66
- case "column":
67
- return COL_AXIS;
68
- default:
69
- return null;
70
- }
71
- }
72
- function isStackVNode(vnode) {
73
- return vnode.kind === "row" || vnode.kind === "column";
74
- }
75
- function mainFromWH(axis, w, h) {
76
- return axis.mainSize === "w" ? w : h;
77
- }
78
- function crossFromWH(axis, w, h) {
79
- return axis.crossSize === "w" ? w : h;
80
- }
81
- function mainFromSize(axis, size) {
82
- return axis.mainSize === "w" ? size.w : size.h;
83
- }
84
- function crossFromSize(axis, size) {
85
- return axis.crossSize === "w" ? size.w : size.h;
86
- }
87
- function toWH(axis, main, cross) {
88
- if (axis.mainSize === "w")
89
- return { w: main, h: cross };
90
- return { w: cross, h: main };
91
- }
92
- function toXY(axis, main, cross) {
93
- if (axis.mainPos === "x")
94
- return { x: main, y: cross };
95
- return { x: cross, y: main };
96
- }
97
- function measureNodeOnAxis(axis, child, maxMain, maxCross, measureNode) {
98
- const { w, h } = toWH(axis, maxMain, maxCross);
99
- return measureNode(child, w, h, axis.axis);
100
- }
101
- function layoutNodeOnAxis(axis, child, main, cross, maxMain, maxCross, layoutNode, forcedMain, forcedCross, precomputedSize) {
102
- const { x, y } = toXY(axis, main, cross);
103
- const { w, h } = toWH(axis, maxMain, maxCross);
104
- const forcedW = axis.mainProp === "width" ? forcedMain : forcedCross;
105
- const forcedH = axis.mainProp === "width" ? forcedCross : forcedMain;
106
- return layoutNode(child, x, y, w, h, axis.axis, forcedW, forcedH, precomputedSize);
107
- }
108
- function countNonEmptyChildren(children) {
109
- let count = 0;
110
- for (const child of children) {
111
- if (!child || childHasAbsolutePosition(child))
112
- continue;
113
- count++;
114
- }
115
- return count;
116
- }
117
- function shiftLayoutTree(node, dx, dy) {
118
- if (dx === 0 && dy === 0)
119
- return node;
120
- const shiftedChildren = node.children.length === 0
121
- ? node.children
122
- : Object.freeze(node.children.map((child) => shiftLayoutTree(child, dx, dy)));
1
+ import { getAxisConfig } from "./stackParts/axis.js";
2
+ import { layoutStack } from "./stackParts/layout.js";
3
+ import { measureStack } from "./stackParts/measure.js";
4
+ import { isStackVNode } from "./stackParts/shared.js";
5
+ function invalid(detail) {
123
6
  return {
124
- vnode: node.vnode,
125
- rect: { x: node.rect.x + dx, y: node.rect.y + dy, w: node.rect.w, h: node.rect.h },
126
- ...(node.meta === undefined ? {} : { meta: node.meta }),
127
- children: shiftedChildren,
7
+ ok: false,
8
+ fatal: { code: "ZRUI_INVALID_PROPS", detail },
128
9
  };
129
10
  }
130
- function shiftLayoutChildren(children, dx, dy) {
131
- if (dx === 0 && dy === 0)
132
- return children;
133
- return children.map((child) => shiftLayoutTree(child, dx, dy));
134
- }
135
- const previousChildSizeCache = new WeakMap();
136
- function recordChildLayoutSize(child, layout) {
137
- previousChildSizeCache.set(child, { w: layout.rect.w, h: layout.rect.h });
138
- }
139
- function maybePruneRemainingDirtySiblings(children, index, child, laidOut) {
140
- const dirtySet = getActiveDirtySet();
141
- if (dirtySet === null || !dirtySet.has(child)) {
142
- recordChildLayoutSize(child, laidOut);
143
- return;
144
- }
145
- const prev = previousChildSizeCache.get(child);
146
- recordChildLayoutSize(child, laidOut);
147
- if (!prev)
148
- return;
149
- if (prev.w !== laidOut.rect.w || prev.h !== laidOut.rect.h)
150
- return;
151
- for (let i = index + 1; i < children.length; i++) {
152
- const sibling = children[i];
153
- if (!sibling)
154
- continue;
155
- dirtySet.delete(sibling);
156
- }
157
- }
158
- function isWrapEnabled(props) {
159
- if (typeof props !== "object" || props === null)
160
- return false;
161
- return props.wrap === true;
162
- }
163
- const FEEDBACK_COMPLEX_LEAF_KINDS = new Set([
164
- "table",
165
- "virtualList",
166
- "codeEditor",
167
- "diffViewer",
168
- "logsConsole",
169
- ]);
170
- const crossFeedbackPotentialCache = new WeakMap();
171
- function childMayNeedCrossAxisFeedback(vnode) {
172
- const hit = crossFeedbackPotentialCache.get(vnode);
173
- if (hit !== undefined)
174
- return hit;
175
- let out = false;
176
- if (vnode.kind === "text") {
177
- out = vnode.props.wrap === true;
178
- }
179
- else if (FEEDBACK_COMPLEX_LEAF_KINDS.has(vnode.kind)) {
180
- out = true;
181
- }
182
- else if ("children" in vnode) {
183
- const children = vnode.children;
184
- for (let i = 0; i < children.length; i++) {
185
- const child = children[i];
186
- if (!child)
187
- continue;
188
- if (childMayNeedCrossAxisFeedback(child)) {
189
- out = true;
190
- break;
191
- }
192
- }
193
- }
194
- crossFeedbackPotentialCache.set(vnode, out);
195
- return out;
196
- }
197
- function parseMainPercentWeight(value) {
198
- if (!isPercentString(value))
199
- return null;
200
- const raw = Number.parseFloat(value.slice(0, -1));
201
- if (!Number.isFinite(raw))
202
- return null;
203
- return raw;
204
- }
205
- function maybeRebalanceNearFullPercentChildren(axis, children, mainSizes, measureMaxMain, availableForChildren, parentRect) {
206
- if (availableForChildren <= 0)
207
- return;
208
- const indices = [];
209
- const percentWeights = [];
210
- const flexWeights = [];
211
- let percentSum = 0;
212
- let hasFlexChildren = false;
213
- let hasNonFlexChildren = false;
214
- for (let i = 0; i < children.length; i++) {
215
- const child = children[i];
216
- if (!child || childHasAbsolutePosition(child))
217
- continue;
218
- if (child.kind === "spacer")
219
- return;
220
- const childProps = getConstraintProps(child) ?? {};
221
- const rawMain = childProps[axis.mainProp];
222
- const percent = parseMainPercentWeight(rawMain);
223
- if (percent === null)
224
- return;
225
- const resolved = resolveLayoutConstraints(childProps, parentRect, axis.axis);
226
- if (resolved.flex > 0) {
227
- hasFlexChildren = true;
228
- flexWeights.push(resolved.flex);
229
- }
230
- else {
231
- hasNonFlexChildren = true;
232
- flexWeights.push(0);
233
- }
234
- if (resolved[axis.minMainProp] > 0)
235
- return;
236
- const maxMain = toFiniteMax(resolved[axis.maxMainProp], availableForChildren);
237
- if (maxMain < availableForChildren)
238
- return;
239
- indices.push(i);
240
- percentWeights.push(percent);
241
- percentSum += percent;
242
- }
243
- if (indices.length <= 1)
244
- return;
245
- if (hasFlexChildren && !hasNonFlexChildren) {
246
- // For flex rows where all children also declare percent widths (for example 100%+100%),
247
- // legacy fixed-size planning can collapse later siblings to zero. Rebalance only when
248
- // collapse happened so normal flex-percentage cases keep their existing sizing behavior.
249
- let hasCollapsedSibling = false;
250
- for (let i = 0; i < indices.length; i++) {
251
- const slot = indices[i];
252
- if (slot === undefined)
253
- continue;
254
- if ((mainSizes[slot] ?? 0) <= 0) {
255
- hasCollapsedSibling = true;
256
- break;
257
- }
258
- }
259
- if (!hasCollapsedSibling)
260
- return;
261
- const flexAlloc = distributeInteger(availableForChildren, flexWeights);
262
- for (let i = 0; i < indices.length; i++) {
263
- const slot = indices[i];
264
- if (slot === undefined)
265
- continue;
266
- const next = flexAlloc[i] ?? 0;
267
- mainSizes[slot] = next;
268
- measureMaxMain[slot] = Math.max(measureMaxMain[slot] ?? 0, next);
269
- }
270
- return;
271
- }
272
- if (hasFlexChildren)
273
- return;
274
- // Only normalize near-full percentage groups (e.g. 33/33/33).
275
- if (percentSum < 99 || percentSum > 101)
276
- return;
277
- const alloc = distributeInteger(availableForChildren, percentWeights);
278
- for (let i = 0; i < indices.length; i++) {
279
- const slot = indices[i];
280
- if (slot === undefined)
281
- continue;
282
- const next = alloc[i] ?? 0;
283
- mainSizes[slot] = next;
284
- measureMaxMain[slot] = Math.max(measureMaxMain[slot] ?? 0, next);
285
- }
286
- }
287
- function probeWrapChildMain(axis, child, cw, ch, parentRect, measureNode) {
288
- const mainLimit = mainFromWH(axis, cw, ch);
289
- const crossLimit = crossFromWH(axis, cw, ch);
290
- if (child.kind === "spacer") {
291
- const sp = validateSpacerProps(child.props);
292
- if (!sp.ok)
293
- return sp;
294
- return ok(Math.min(sp.value.size, mainLimit));
295
- }
296
- const childProps = getConstraintProps(child) ?? {};
297
- const resolved = resolveLayoutConstraints(childProps, parentRect, axis.axis);
298
- const fixedMain = resolved[axis.mainProp];
299
- const minMain = Math.min(resolved[axis.minMainProp], mainLimit);
300
- const maxMain = Math.min(toFiniteMax(resolved[axis.maxMainProp], mainLimit), mainLimit);
301
- const flex = resolved.flex;
302
- if (fixedMain !== null)
303
- return ok(clampWithin(fixedMain, minMain, maxMain));
304
- if (flex > 0)
305
- return ok(Math.min(minMain, maxMain));
306
- const childRes = measureNodeOnAxis(axis, child, mainLimit, crossLimit, measureNode);
307
- if (!childRes.ok)
308
- return childRes;
309
- return ok(Math.min(mainFromSize(axis, childRes.value), maxMain));
310
- }
311
- function computeWrapConstraintLine(axis, lineChildren, cw, ch, gap, parentRect, measureNode, includeChildren) {
312
- const lineChildCount = lineChildren.length;
313
- if (lineChildCount === 0) {
314
- if (includeChildren)
315
- return ok({ children: Object.freeze([]), main: 0, cross: 0 });
316
- return ok({ main: 0, cross: 0 });
317
- }
318
- const mainLimit = mainFromWH(axis, cw, ch);
319
- const crossLimit = crossFromWH(axis, cw, ch);
320
- const gapTotal = lineChildCount <= 1 ? 0 : gap * (lineChildCount - 1);
321
- const availableForChildren = clampNonNegative(mainLimit - gapTotal);
322
- const mainSizes = acquireArray(lineChildCount);
323
- const measureMaxMain = acquireArray(lineChildCount);
324
- const crossSizes = includeChildren ? acquireArray(lineChildCount) : null;
325
- const crossPass1 = acquireArray(lineChildCount);
326
- try {
327
- const flexItems = [];
328
- let remaining = availableForChildren;
329
- for (let i = 0; i < lineChildCount; i++) {
330
- const child = lineChildren[i];
331
- if (!child || childHasAbsolutePosition(child))
332
- continue;
333
- if (child.kind === "spacer") {
334
- const sp = validateSpacerProps(child.props);
335
- if (!sp.ok)
336
- return sp;
337
- const maxMain = availableForChildren;
338
- if (remaining === 0) {
339
- mainSizes[i] = 0;
340
- measureMaxMain[i] = 0;
341
- continue;
342
- }
343
- if (sp.value.flex > 0) {
344
- flexItems.push({
345
- index: i,
346
- flex: sp.value.flex,
347
- shrink: 0,
348
- basis: 0,
349
- min: sp.value.size,
350
- max: maxMain,
351
- });
352
- continue;
353
- }
354
- const size = Math.min(sp.value.size, remaining);
355
- mainSizes[i] = size;
356
- measureMaxMain[i] = size;
357
- remaining = clampNonNegative(remaining - size);
358
- continue;
359
- }
360
- const childProps = getConstraintProps(child) ?? {};
361
- const resolved = resolveLayoutConstraints(childProps, parentRect, axis.axis);
362
- const fixedMain = resolved[axis.mainProp];
363
- const minMain = resolved[axis.minMainProp];
364
- const maxMain = Math.min(toFiniteMax(resolved[axis.maxMainProp], availableForChildren), availableForChildren);
365
- const flex = resolved.flex;
366
- const rawMain = childProps[axis.mainProp];
367
- const mainIsPercent = isPercentString(rawMain);
368
- if (remaining === 0) {
369
- mainSizes[i] = 0;
370
- measureMaxMain[i] = 0;
371
- continue;
372
- }
373
- if (fixedMain !== null) {
374
- const desired = clampWithin(fixedMain, minMain, maxMain);
375
- const size = Math.min(desired, remaining);
376
- mainSizes[i] = size;
377
- measureMaxMain[i] = mainIsPercent ? mainLimit : size;
378
- remaining = clampNonNegative(remaining - size);
379
- continue;
380
- }
381
- if (flex > 0) {
382
- flexItems.push({
383
- index: i,
384
- flex,
385
- shrink: 0,
386
- basis: 0,
387
- min: minMain,
388
- max: maxMain,
389
- });
390
- continue;
391
- }
392
- const childRes = measureNodeOnAxis(axis, child, remaining, crossLimit, measureNode);
393
- if (!childRes.ok)
394
- return childRes;
395
- const childMain = mainFromSize(axis, childRes.value);
396
- mainSizes[i] = childMain;
397
- measureMaxMain[i] = childMain;
398
- remaining = clampNonNegative(remaining - childMain);
399
- }
400
- if (flexItems.length > 0 && remaining > 0) {
401
- const alloc = distributeFlex(remaining, flexItems);
402
- for (let j = 0; j < flexItems.length; j++) {
403
- const it = flexItems[j];
404
- if (!it)
405
- continue;
406
- const size = alloc[j] ?? 0;
407
- mainSizes[it.index] = size;
408
- const child = lineChildren[it.index];
409
- if (child?.kind === "spacer") {
410
- measureMaxMain[it.index] = size;
411
- continue;
412
- }
413
- const childProps = getConstraintProps(child) ?? {};
414
- const rawMain = childProps[axis.mainProp];
415
- measureMaxMain[it.index] = isPercentString(rawMain) ? mainLimit : size;
416
- }
417
- releaseArray(alloc);
418
- }
419
- maybeRebalanceNearFullPercentChildren(axis, lineChildren, mainSizes, measureMaxMain, availableForChildren, parentRect);
420
- let lineMain = 0;
421
- for (let i = 0; i < lineChildCount; i++) {
422
- lineMain += mainSizes[i] ?? 0;
423
- }
424
- lineMain += lineChildCount <= 1 ? 0 : gap * (lineChildCount - 1);
425
- let lineCross = 0;
426
- const sizeCache = new Array(lineChildCount).fill(null);
427
- const mayFeedback = new Array(lineChildCount).fill(false);
428
- let feedbackCandidate = false;
429
- for (let i = 0; i < lineChildCount; i++) {
430
- const child = lineChildren[i];
431
- if (!child || childHasAbsolutePosition(child))
432
- continue;
433
- const main = mainSizes[i] ?? 0;
434
- const mm = measureMaxMain[i] ?? 0;
435
- const childSizeRes = main === 0
436
- ? measureNodeOnAxis(axis, child, 0, 0, measureNode)
437
- : measureNodeOnAxis(axis, child, mm, crossLimit, measureNode);
438
- if (!childSizeRes.ok)
439
- return childSizeRes;
440
- const childCross = crossFromSize(axis, childSizeRes.value);
441
- if (crossSizes)
442
- crossSizes[i] = childCross;
443
- sizeCache[i] = childSizeRes.value;
444
- const childProps = getConstraintProps(child) ?? {};
445
- const rawMain = childProps[axis.mainProp];
446
- const needsFeedback = main > 0 &&
447
- mm !== main &&
448
- !isPercentString(rawMain) &&
449
- childMayNeedCrossAxisFeedback(child);
450
- mayFeedback[i] = needsFeedback;
451
- crossPass1[i] = childCross;
452
- if (needsFeedback)
453
- feedbackCandidate = true;
454
- if (childCross > lineCross)
455
- lineCross = childCross;
456
- }
457
- if (feedbackCandidate) {
458
- lineCross = 0;
459
- for (let i = 0; i < lineChildCount; i++) {
460
- const child = lineChildren[i];
461
- if (!child || childHasAbsolutePosition(child))
462
- continue;
463
- const needsFeedback = mayFeedback[i] === true;
464
- let size = sizeCache[i] ?? null;
465
- if (needsFeedback) {
466
- const main = mainSizes[i] ?? 0;
467
- const nextSizeRes = main === 0
468
- ? measureNodeOnAxis(axis, child, 0, 0, measureNode)
469
- : measureNodeOnAxis(axis, child, main, crossLimit, measureNode);
470
- if (!nextSizeRes.ok)
471
- return nextSizeRes;
472
- const nextCross = crossFromSize(axis, nextSizeRes.value);
473
- if (nextCross !== (crossPass1[i] ?? 0)) {
474
- size = nextSizeRes.value;
475
- sizeCache[i] = size;
476
- if (crossSizes)
477
- crossSizes[i] = nextCross;
478
- crossPass1[i] = nextCross;
479
- }
480
- }
481
- const cross = crossSizes?.[i] ?? crossPass1[i] ?? (size === null ? 0 : crossFromSize(axis, size));
482
- if (cross > lineCross)
483
- lineCross = cross;
484
- }
485
- }
486
- if (!includeChildren)
487
- return ok({ main: lineMain, cross: lineCross });
488
- const plannedChildren = [];
489
- for (let i = 0; i < lineChildCount; i++) {
490
- const child = lineChildren[i];
491
- if (!child || childHasAbsolutePosition(child))
492
- continue;
493
- plannedChildren.push({
494
- child,
495
- main: mainSizes[i] ?? 0,
496
- measureMaxMain: measureMaxMain[i] ?? 0,
497
- cross: crossSizes?.[i] ?? 0,
498
- });
499
- }
500
- return ok({
501
- children: Object.freeze(plannedChildren),
502
- main: lineMain,
503
- cross: lineCross,
504
- });
505
- }
506
- finally {
507
- releaseArray(mainSizes);
508
- releaseArray(measureMaxMain);
509
- if (crossSizes)
510
- releaseArray(crossSizes);
511
- releaseArray(crossPass1);
512
- }
513
- }
514
- function measureWrapConstraintLine(axis, lineChildren, cw, ch, gap, parentRect, measureNode) {
515
- const lineRes = computeWrapConstraintLine(axis, lineChildren, cw, ch, gap, parentRect, measureNode, false);
516
- if (!lineRes.ok)
517
- return lineRes;
518
- return ok(lineRes.value);
519
- }
520
- function planWrapConstraintLine(axis, lineChildren, cw, ch, gap, parentRect, measureNode) {
521
- const lineRes = computeWrapConstraintLine(axis, lineChildren, cw, ch, gap, parentRect, measureNode, true);
522
- if (!lineRes.ok)
523
- return lineRes;
524
- return ok(lineRes.value);
525
- }
526
- function planConstraintMainSizes(axis, children, availableForChildren, mainLimit, crossLimit, parentRect, measureNode, collectPrecomputed) {
527
- const mainSizes = new Array(children.length).fill(0);
528
- const measureMaxMain = new Array(children.length).fill(0);
529
- const precomputedSizes = new Array(children.length).fill(null);
530
- let hasAdvancedFlex = false;
531
- for (let i = 0; i < children.length; i++) {
532
- const child = children[i];
533
- if (!child || child.kind === "spacer")
534
- continue;
535
- const props = getConstraintProps(child);
536
- if (!props)
537
- continue;
538
- const rawShrink = props.flexShrink;
539
- const rawBasis = props.flexBasis;
540
- if ((typeof rawShrink === "number" && Number.isFinite(rawShrink) && rawShrink > 0) ||
541
- rawBasis !== undefined) {
542
- hasAdvancedFlex = true;
543
- break;
544
- }
545
- }
546
- // Preserve legacy planning semantics when advanced flex-shrink/basis is not used.
547
- if (!hasAdvancedFlex) {
548
- const flexItems = [];
549
- const reservedMainByIndex = new Array(children.length + 1).fill(0);
550
- for (let i = children.length - 1; i >= 0; i--) {
551
- const child = children[i];
552
- const downstreamReserved = reservedMainByIndex[i + 1] ?? 0;
553
- if (!child || childHasAbsolutePosition(child)) {
554
- reservedMainByIndex[i] = downstreamReserved;
555
- continue;
556
- }
557
- if (child.kind === "spacer") {
558
- const sp = validateSpacerProps(child.props);
559
- if (!sp.ok)
560
- return sp;
561
- reservedMainByIndex[i] = downstreamReserved + Math.max(0, sp.value.size);
562
- continue;
563
- }
564
- const childProps = getConstraintProps(child) ?? {};
565
- const resolved = resolveLayoutConstraints(childProps, parentRect, axis.axis);
566
- const fixedMain = resolved[axis.mainProp];
567
- const minMain = resolved[axis.minMainProp];
568
- const maxMain = Math.min(toFiniteMax(resolved[axis.maxMainProp], availableForChildren), availableForChildren);
569
- const required = fixedMain !== null || resolved.flex > 0 ? clampWithin(minMain, 0, maxMain) : 0;
570
- reservedMainByIndex[i] = downstreamReserved + required;
571
- }
572
- let remaining = availableForChildren;
573
- for (let i = 0; i < children.length; i++) {
574
- const child = children[i];
575
- if (!child || childHasAbsolutePosition(child))
576
- continue;
577
- const reserveForLater = reservedMainByIndex[i + 1] ?? 0;
578
- const budgetAfterReserve = reserveForLater <= remaining ? clampNonNegative(remaining - reserveForLater) : remaining;
579
- if (child.kind === "spacer") {
580
- const sp = validateSpacerProps(child.props);
581
- if (!sp.ok)
582
- return sp;
583
- const maxMain = availableForChildren;
584
- if (remaining === 0) {
585
- mainSizes[i] = 0;
586
- measureMaxMain[i] = 0;
587
- continue;
588
- }
589
- if (sp.value.flex > 0) {
590
- flexItems.push({
591
- index: i,
592
- flex: sp.value.flex,
593
- shrink: 0,
594
- basis: 0,
595
- min: sp.value.size,
596
- max: maxMain,
597
- });
598
- continue;
599
- }
600
- const size = Math.min(sp.value.size, budgetAfterReserve);
601
- mainSizes[i] = size;
602
- measureMaxMain[i] = size;
603
- remaining = clampNonNegative(remaining - size);
604
- continue;
605
- }
606
- const childProps = getConstraintProps(child) ?? {};
607
- const resolved = resolveLayoutConstraints(childProps, parentRect, axis.axis);
608
- const fixedMain = resolved[axis.mainProp];
609
- const minMain = resolved[axis.minMainProp];
610
- const maxMain = Math.min(toFiniteMax(resolved[axis.maxMainProp], availableForChildren), availableForChildren);
611
- const flex = resolved.flex;
612
- const rawMain = childProps[axis.mainProp];
613
- const mainIsPercent = isPercentString(rawMain);
614
- if (remaining === 0) {
615
- mainSizes[i] = 0;
616
- measureMaxMain[i] = 0;
617
- continue;
618
- }
619
- if (fixedMain !== null) {
620
- const desired = clampWithin(fixedMain, minMain, maxMain);
621
- const size = Math.min(desired, budgetAfterReserve);
622
- mainSizes[i] = size;
623
- measureMaxMain[i] = mainIsPercent ? mainLimit : size;
624
- remaining = clampNonNegative(remaining - size);
625
- continue;
626
- }
627
- if (flex > 0) {
628
- flexItems.push({
629
- index: i,
630
- flex,
631
- shrink: 0,
632
- basis: 0,
633
- min: minMain,
634
- max: maxMain,
635
- });
636
- continue;
637
- }
638
- const childRes = measureNodeOnAxis(axis, child, remaining, crossLimit, measureNode);
639
- if (!childRes.ok)
640
- return childRes;
641
- const childMain = mainFromSize(axis, childRes.value);
642
- mainSizes[i] = childMain;
643
- measureMaxMain[i] = childMain;
644
- if (collectPrecomputed)
645
- precomputedSizes[i] = childRes.value;
646
- remaining = clampNonNegative(remaining - childMain);
647
- }
648
- if (flexItems.length > 0 && remaining > 0) {
649
- const alloc = distributeFlex(remaining, flexItems);
650
- for (let j = 0; j < flexItems.length; j++) {
651
- const it = flexItems[j];
652
- if (!it)
653
- continue;
654
- const size = alloc[j] ?? 0;
655
- mainSizes[it.index] = size;
656
- const child = children[it.index];
657
- if (child?.kind === "spacer") {
658
- measureMaxMain[it.index] = size;
659
- }
660
- else if (child) {
661
- const childProps = getConstraintProps(child) ?? {};
662
- const rawMain = childProps[axis.mainProp];
663
- measureMaxMain[it.index] = isPercentString(rawMain) ? mainLimit : size;
664
- }
665
- if (collectPrecomputed)
666
- precomputedSizes[it.index] = null;
667
- }
668
- releaseArray(alloc);
669
- }
670
- maybeRebalanceNearFullPercentChildren(axis, children, mainSizes, measureMaxMain, availableForChildren, parentRect);
671
- return ok({
672
- mainSizes,
673
- measureMaxMain,
674
- precomputedSizes,
675
- });
676
- }
677
- // Advanced path: supports flexShrink/flexBasis while keeping legacy defaults.
678
- const minMains = acquireArray(children.length);
679
- const maxMains = acquireArray(children.length);
680
- maxMains.fill(availableForChildren, 0, children.length);
681
- const shrinkFactors = acquireArray(children.length);
682
- const reservedMainByIndex = new Array(children.length + 1).fill(0);
683
- try {
684
- for (let i = children.length - 1; i >= 0; i--) {
685
- const child = children[i];
686
- const downstreamReserved = reservedMainByIndex[i + 1] ?? 0;
687
- if (!child || childHasAbsolutePosition(child)) {
688
- reservedMainByIndex[i] = downstreamReserved;
689
- continue;
690
- }
691
- if (child.kind === "spacer") {
692
- const sp = validateSpacerProps(child.props);
693
- if (!sp.ok)
694
- return sp;
695
- reservedMainByIndex[i] = downstreamReserved + Math.max(0, sp.value.size);
696
- continue;
697
- }
698
- const childProps = (getConstraintProps(child) ?? {});
699
- const resolved = resolveLayoutConstraints(childProps, parentRect, axis.axis);
700
- const fixedMain = resolved[axis.mainProp];
701
- const minMain = resolved[axis.minMainProp];
702
- const maxMain = Math.min(toFiniteMax(resolved[axis.maxMainProp], availableForChildren), availableForChildren);
703
- const required = fixedMain !== null || resolved.flex > 0 ? clampWithin(minMain, 0, maxMain) : 0;
704
- reservedMainByIndex[i] = downstreamReserved + required;
705
- }
706
- const growItems = [];
707
- let totalMain = 0;
708
- for (let i = 0; i < children.length; i++) {
709
- const child = children[i];
710
- if (!child || childHasAbsolutePosition(child))
711
- continue;
712
- const reserveForLater = reservedMainByIndex[i + 1] ?? 0;
713
- const remainingBudget = clampNonNegative(availableForChildren - totalMain);
714
- const budgetAfterReserve = reserveForLater <= remainingBudget
715
- ? clampNonNegative(remainingBudget - reserveForLater)
716
- : remainingBudget;
717
- if (child.kind === "spacer") {
718
- const sp = validateSpacerProps(child.props);
719
- if (!sp.ok)
720
- return sp;
721
- const basis = sp.value.flex > 0 ? 0 : Math.min(sp.value.size, budgetAfterReserve);
722
- mainSizes[i] = basis;
723
- measureMaxMain[i] = basis;
724
- minMains[i] = 0;
725
- maxMains[i] = availableForChildren;
726
- shrinkFactors[i] = 0;
727
- totalMain += basis;
728
- if (sp.value.flex > 0) {
729
- growItems.push({
730
- index: i,
731
- flex: sp.value.flex,
732
- shrink: 0,
733
- basis: 0,
734
- min: sp.value.size,
735
- max: availableForChildren,
736
- });
737
- }
738
- continue;
739
- }
740
- const childProps = (getConstraintProps(child) ?? {});
741
- const resolved = resolveLayoutConstraints(childProps, parentRect, axis.axis);
742
- const fixedMain = resolved[axis.mainProp];
743
- const maxMain = Math.min(toFiniteMax(resolved[axis.maxMainProp], availableForChildren), availableForChildren);
744
- let minMain = Math.min(resolved[axis.minMainProp], availableForChildren);
745
- const rawMain = childProps[axis.mainProp];
746
- const rawMinMain = childProps[axis.minMainProp];
747
- const rawFlexBasis = childProps.flexBasis;
748
- const mainPercent = isPercentString(rawMain);
749
- const flexBasisIsAuto = resolveResponsiveValue(rawFlexBasis) === "auto";
750
- if (rawMinMain === undefined && resolved.flexShrink > 0) {
751
- const intrinsicMinRes = measureMinContent(child, axis.axis, measureNode);
752
- if (!intrinsicMinRes.ok)
753
- return intrinsicMinRes;
754
- const intrinsicMain = mainFromSize(axis, intrinsicMinRes.value);
755
- minMain = Math.max(minMain, Math.min(intrinsicMain, availableForChildren));
756
- }
757
- const normalizedMinMain = Math.min(minMain, maxMain);
758
- minMains[i] = normalizedMinMain;
759
- maxMains[i] = maxMain;
760
- shrinkFactors[i] = resolved.flexShrink;
761
- let measuredSize = null;
762
- let basis;
763
- if (fixedMain !== null) {
764
- basis = clampWithin(fixedMain, normalizedMinMain, maxMain);
765
- }
766
- else if (resolved.flexBasis !== null) {
767
- basis = clampWithin(resolved.flexBasis, normalizedMinMain, maxMain);
768
- }
769
- else if (flexBasisIsAuto) {
770
- const intrinsicMaxRes = measureMaxContent(child, axis.axis, measureNode);
771
- if (!intrinsicMaxRes.ok)
772
- return intrinsicMaxRes;
773
- const intrinsicMain = mainFromSize(axis, intrinsicMaxRes.value);
774
- basis = clampWithin(intrinsicMain, normalizedMinMain, maxMain);
775
- }
776
- else if (resolved.flex > 0) {
777
- basis = 0;
778
- }
779
- else {
780
- const childRes = measureNodeOnAxis(axis, child, availableForChildren, crossLimit, measureNode);
781
- if (!childRes.ok)
782
- return childRes;
783
- measuredSize = childRes.value;
784
- basis = clampWithin(mainFromSize(axis, childRes.value), normalizedMinMain, maxMain);
785
- }
786
- const reserveForLaterMins = fixedMain !== null &&
787
- resolved.flex === 0 &&
788
- resolved.flexShrink <= 0 &&
789
- resolved.flexBasis === null;
790
- if (reserveForLaterMins) {
791
- basis = Math.min(basis, budgetAfterReserve);
792
- }
793
- mainSizes[i] = basis;
794
- measureMaxMain[i] = mainPercent ? mainLimit : basis;
795
- if (collectPrecomputed && measuredSize !== null)
796
- precomputedSizes[i] = measuredSize;
797
- totalMain += basis;
798
- if (fixedMain === null && resolved.flex > 0) {
799
- const growMin = Math.max(0, normalizedMinMain - basis);
800
- const growCap = Math.max(0, maxMain - basis);
801
- growItems.push({
802
- index: i,
803
- flex: resolved.flex,
804
- shrink: 0,
805
- basis: 0,
806
- min: growMin,
807
- max: growCap,
808
- });
809
- }
810
- }
811
- let didResize = false;
812
- const growRemaining = availableForChildren - totalMain;
813
- if (growItems.length > 0 && growRemaining > 0) {
814
- const alloc = distributeFlex(growRemaining, growItems);
815
- for (let i = 0; i < growItems.length; i++) {
816
- const item = growItems[i];
817
- if (!item)
818
- continue;
819
- const add = alloc[i] ?? 0;
820
- if (add <= 0)
821
- continue;
822
- const current = mainSizes[item.index] ?? 0;
823
- const next = Math.min(maxMains[item.index] ?? availableForChildren, current + add);
824
- if (next !== current)
825
- didResize = true;
826
- mainSizes[item.index] = next;
827
- }
828
- releaseArray(alloc);
829
- }
830
- totalMain = 0;
831
- for (let i = 0; i < mainSizes.length; i++) {
832
- totalMain += mainSizes[i] ?? 0;
833
- }
834
- if (totalMain > availableForChildren) {
835
- const shrinkItems = [];
836
- for (let i = 0; i < children.length; i++) {
837
- const child = children[i];
838
- if (!child || childHasAbsolutePosition(child))
839
- continue;
840
- shrinkItems.push({
841
- index: i,
842
- flex: 0,
843
- shrink: shrinkFactors[i] ?? 0,
844
- basis: mainSizes[i] ?? 0,
845
- min: minMains[i] ?? 0,
846
- max: maxMains[i] ?? availableForChildren,
847
- });
848
- }
849
- if (shrinkItems.length > 0) {
850
- const shrunk = shrinkFlex(availableForChildren, shrinkItems);
851
- for (let i = 0; i < shrinkItems.length; i++) {
852
- const item = shrinkItems[i];
853
- if (!item)
854
- continue;
855
- const current = mainSizes[item.index] ?? 0;
856
- const next = clampWithin(shrunk[i] ?? 0, item.min, item.max);
857
- if (next !== current)
858
- didResize = true;
859
- mainSizes[item.index] = next;
860
- }
861
- releaseArray(shrunk);
862
- }
863
- }
864
- for (let i = 0; i < children.length; i++) {
865
- if (!children[i])
866
- continue;
867
- if (didResize && collectPrecomputed)
868
- precomputedSizes[i] = null;
869
- }
870
- maybeRebalanceNearFullPercentChildren(axis, children, mainSizes, measureMaxMain, availableForChildren, parentRect);
871
- return ok({
872
- mainSizes,
873
- measureMaxMain,
874
- precomputedSizes,
875
- });
876
- }
877
- finally {
878
- releaseArray(minMains);
879
- releaseArray(maxMains);
880
- releaseArray(shrinkFactors);
881
- }
882
- }
883
- function planConstraintCrossSizes(axis, children, mainSizes, measureMaxMain, crossLimit, align, measureNode, seedSizes) {
884
- const sizes = (seedSizes ?? []).slice();
885
- if (sizes.length < children.length) {
886
- sizes.length = children.length;
887
- }
888
- const crossSizes = new Array(children.length).fill(0);
889
- const feedbackCandidates = new Array(children.length).fill(false);
890
- let hasFeedbackCandidate = false;
891
- for (let i = 0; i < children.length; i++) {
892
- const child = children[i];
893
- if (!child || childHasAbsolutePosition(child))
894
- continue;
895
- const main = mainSizes[i] ?? 0;
896
- const mm = measureMaxMain[i] ?? 0;
897
- let size = sizes[i] ?? null;
898
- if (size === null) {
899
- const firstRes = main === 0
900
- ? measureNodeOnAxis(axis, child, 0, 0, measureNode)
901
- : measureNodeOnAxis(axis, child, mm, crossLimit, measureNode);
902
- if (!firstRes.ok)
903
- return firstRes;
904
- size = firstRes.value;
905
- sizes[i] = size;
906
- }
907
- crossSizes[i] = crossFromSize(axis, size);
908
- const childProps = getConstraintProps(child) ?? {};
909
- const rawMain = childProps[axis.mainProp];
910
- const candidate = main > 0 && mm !== main && !isPercentString(rawMain) && childMayNeedCrossAxisFeedback(child);
911
- feedbackCandidates[i] = candidate;
912
- if (candidate)
913
- hasFeedbackCandidate = true;
914
- }
915
- if (hasFeedbackCandidate) {
916
- for (let i = 0; i < children.length; i++) {
917
- if (feedbackCandidates[i] !== true)
918
- continue;
919
- const child = children[i];
920
- if (!child || childHasAbsolutePosition(child))
921
- continue;
922
- const main = mainSizes[i] ?? 0;
923
- const secondRes = main === 0
924
- ? measureNodeOnAxis(axis, child, 0, 0, measureNode)
925
- : measureNodeOnAxis(axis, child, main, crossLimit, measureNode);
926
- if (!secondRes.ok)
927
- return secondRes;
928
- const nextCross = crossFromSize(axis, secondRes.value);
929
- if (nextCross !== (crossSizes[i] ?? 0)) {
930
- sizes[i] = secondRes.value;
931
- crossSizes[i] = nextCross;
932
- }
933
- }
934
- }
935
- let maxCross = 0;
936
- for (let i = 0; i < children.length; i++) {
937
- const child = children[i];
938
- if (!child || childHasAbsolutePosition(child))
939
- continue;
940
- const effectiveAlign = resolveEffectiveAlign(child, align);
941
- const cross = effectiveAlign === "stretch" ? crossLimit : (crossSizes[i] ?? 0);
942
- if (cross > maxCross)
943
- maxCross = cross;
944
- }
945
- return ok({ sizes, crossSizes, maxCross });
946
- }
947
- function measureStack(axis, vnode, maxW, maxH, measureNode) {
948
- const propsRes = validateStackProps(axis.axis, vnode.props);
949
- if (!propsRes.ok)
950
- return propsRes;
951
- const { gap, align } = propsRes.value;
952
- const spacing = resolveSpacingProps(propsRes.value);
953
- const margin = resolveMarginProps(propsRes.value);
954
- const padX = spacing.left + spacing.right;
955
- const padY = spacing.top + spacing.bottom;
956
- const marginX = margin.left + margin.right;
957
- const marginY = margin.top + margin.bottom;
958
- const innerMaxW = clampNonNegative(maxW - marginX);
959
- const innerMaxH = clampNonNegative(maxH - marginY);
960
- const self = resolveLayoutConstraints(propsRes.value, {
961
- x: 0,
962
- y: 0,
963
- w: innerMaxW,
964
- h: innerMaxH,
965
- }, axis.axis);
966
- const maxWCap = clampNonNegative(Math.min(innerMaxW, toFiniteMax(self.maxWidth, innerMaxW)));
967
- const maxHCap = clampNonNegative(Math.min(innerMaxH, toFiniteMax(self.maxHeight, innerMaxH)));
968
- const minW = Math.min(self.minWidth, maxWCap);
969
- const minH = Math.min(self.minHeight, maxHCap);
970
- const forcedW = self.width === null ? null : clampWithin(self.width, minW, maxWCap);
971
- const forcedH = self.height === null ? null : clampWithin(self.height, minH, maxHCap);
972
- const forcedMain = axis.axis === "row" ? forcedW : forcedH;
973
- const forcedCross = axis.axis === "row" ? forcedH : forcedW;
974
- const minMain = axis.axis === "row" ? minW : minH;
975
- const minCross = axis.axis === "row" ? minH : minW;
976
- const maxMainCap = axis.axis === "row" ? maxWCap : maxHCap;
977
- const maxCrossCap = axis.axis === "row" ? maxHCap : maxWCap;
978
- const padMain = axis.axis === "row" ? padX : padY;
979
- const padCross = axis.axis === "row" ? padY : padX;
980
- const hasFlexInMainAxis = vnode.children.some((c) => !childHasAbsolutePosition(c) && childHasFlexInMainAxis(c, axis.axis));
981
- const hasAdvancedFlexProps = vnode.children.some((c) => !childHasAbsolutePosition(c) && childHasAdvancedFlexProps(c));
982
- const needsConstraintPass = hasFlexInMainAxis || hasAdvancedFlexProps;
983
- const childCount = countNonEmptyChildren(vnode.children);
984
- const outerWLimit = forcedW ?? maxWCap;
985
- const outerHLimit = forcedH ?? maxHCap;
986
- const cw = clampNonNegative(outerWLimit - padX);
987
- const ch = clampNonNegative(outerHLimit - padY);
988
- const mainLimit = mainFromWH(axis, cw, ch);
989
- const crossLimit = crossFromWH(axis, cw, ch);
990
- const finalizeSize = (contentMain, contentCross) => {
991
- const chosenMain = forcedMain ?? Math.min(maxMainCap, padMain + contentMain);
992
- const chosenCross = forcedCross ?? Math.min(maxCrossCap, padCross + contentCross);
993
- const innerMain = clampWithin(chosenMain, minMain, maxMainCap);
994
- const innerCross = clampWithin(chosenCross, minCross, maxCrossCap);
995
- const { w: innerW, h: innerH } = toWH(axis, innerMain, innerCross);
996
- return ok({
997
- w: clampNonNegative(Math.min(maxW, innerW + marginX)),
998
- h: clampNonNegative(Math.min(maxH, innerH + marginY)),
999
- });
1000
- };
1001
- const wrap = isWrapEnabled(vnode.props);
1002
- if (wrap) {
1003
- let maxLineMain = 0;
1004
- let totalCross = 0;
1005
- let lineCount = 0;
1006
- if (needsConstraintPass) {
1007
- const parentRect = { x: 0, y: 0, w: cw, h: ch };
1008
- const lineChildren = [];
1009
- let lineProbeMain = 0;
1010
- for (let i = 0; i < vnode.children.length; i++) {
1011
- const child = vnode.children[i];
1012
- if (!child || childHasAbsolutePosition(child))
1013
- continue;
1014
- const probeMainRes = probeWrapChildMain(axis, child, cw, ch, parentRect, measureNode);
1015
- if (!probeMainRes.ok)
1016
- return probeMainRes;
1017
- const probeMain = probeMainRes.value;
1018
- const wouldOverflow = lineChildren.length > 0 && lineProbeMain + gap + probeMain > mainLimit;
1019
- if (wouldOverflow) {
1020
- const lineRes = measureWrapConstraintLine(axis, lineChildren, cw, ch, gap, parentRect, measureNode);
1021
- if (!lineRes.ok)
1022
- return lineRes;
1023
- if (lineCount > 0)
1024
- totalCross += gap;
1025
- totalCross += lineRes.value.cross;
1026
- if (lineRes.value.main > maxLineMain)
1027
- maxLineMain = lineRes.value.main;
1028
- lineCount++;
1029
- lineChildren.length = 0;
1030
- lineProbeMain = 0;
1031
- }
1032
- if (lineChildren.length === 0)
1033
- lineProbeMain = probeMain;
1034
- else
1035
- lineProbeMain += gap + probeMain;
1036
- lineChildren.push(child);
1037
- }
1038
- if (lineChildren.length > 0) {
1039
- const lineRes = measureWrapConstraintLine(axis, lineChildren, cw, ch, gap, parentRect, measureNode);
1040
- if (!lineRes.ok)
1041
- return lineRes;
1042
- if (lineCount > 0)
1043
- totalCross += gap;
1044
- totalCross += lineRes.value.cross;
1045
- if (lineRes.value.main > maxLineMain)
1046
- maxLineMain = lineRes.value.main;
1047
- }
1048
- }
1049
- else {
1050
- let lineMain = 0;
1051
- let lineCross = 0;
1052
- let lineItems = 0;
1053
- for (let i = 0; i < vnode.children.length; i++) {
1054
- const child = vnode.children[i];
1055
- if (!child || childHasAbsolutePosition(child))
1056
- continue;
1057
- const childSizeRes = measureNode(child, cw, ch, axis.axis);
1058
- if (!childSizeRes.ok)
1059
- return childSizeRes;
1060
- const childMain = mainFromSize(axis, childSizeRes.value);
1061
- const childCross = crossFromSize(axis, childSizeRes.value);
1062
- const wouldOverflow = lineItems > 0 && lineMain + gap + childMain > mainLimit;
1063
- if (wouldOverflow) {
1064
- if (lineCount > 0)
1065
- totalCross += gap;
1066
- totalCross += lineCross;
1067
- if (lineMain > maxLineMain)
1068
- maxLineMain = lineMain;
1069
- lineCount++;
1070
- lineMain = 0;
1071
- lineCross = 0;
1072
- lineItems = 0;
1073
- }
1074
- if (lineItems === 0)
1075
- lineMain = childMain;
1076
- else
1077
- lineMain += gap + childMain;
1078
- if (childCross > lineCross)
1079
- lineCross = childCross;
1080
- lineItems++;
1081
- }
1082
- if (lineItems > 0) {
1083
- if (lineCount > 0)
1084
- totalCross += gap;
1085
- totalCross += lineCross;
1086
- if (lineMain > maxLineMain)
1087
- maxLineMain = lineMain;
1088
- }
1089
- }
1090
- return finalizeSize(maxLineMain, totalCross);
1091
- }
1092
- let maxChildCross = 0;
1093
- let usedMainInConstraintPass = 0;
1094
- if (needsConstraintPass) {
1095
- const parentRect = { x: 0, y: 0, w: cw, h: ch };
1096
- const gapTotal = childCount <= 1 ? 0 : gap * (childCount - 1);
1097
- const availableForChildren = clampNonNegative(mainLimit - gapTotal);
1098
- const planRes = planConstraintMainSizes(axis, vnode.children, availableForChildren, mainLimit, crossLimit, parentRect, measureNode, false);
1099
- if (!planRes.ok)
1100
- return planRes;
1101
- const { mainSizes, measureMaxMain } = planRes.value;
1102
- const crossPlanRes = planConstraintCrossSizes(axis, vnode.children, mainSizes, measureMaxMain, crossLimit, align, measureNode);
1103
- if (!crossPlanRes.ok)
1104
- return crossPlanRes;
1105
- maxChildCross = crossPlanRes.value.maxCross;
1106
- for (let i = 0; i < mainSizes.length; i++) {
1107
- usedMainInConstraintPass += mainSizes[i] ?? 0;
1108
- }
1109
- usedMainInConstraintPass += childCount <= 1 ? 0 : gap * (childCount - 1);
1110
- }
1111
- else {
1112
- let remainingMain = mainLimit;
1113
- let cursorMain = 0;
1114
- let laidOutCount = 0;
1115
- for (const child of vnode.children) {
1116
- if (!child || childHasAbsolutePosition(child))
1117
- continue;
1118
- if (remainingMain === 0) {
1119
- // Still validate subtree deterministically, even if it gets assigned {w:0,h:0}.
1120
- const zeroRes = measureNodeOnAxis(axis, child, 0, 0, measureNode);
1121
- if (!zeroRes.ok)
1122
- return zeroRes;
1123
- const zeroCross = crossFromSize(axis, zeroRes.value);
1124
- if (zeroCross > 0)
1125
- laidOutCount++;
1126
- if (zeroCross > maxChildCross)
1127
- maxChildCross = zeroCross;
1128
- continue;
1129
- }
1130
- const childSizeRes = measureNodeOnAxis(axis, child, remainingMain, crossLimit, measureNode);
1131
- if (!childSizeRes.ok)
1132
- return childSizeRes;
1133
- const childMain = mainFromSize(axis, childSizeRes.value);
1134
- const effectiveAlign = resolveEffectiveAlign(child, align);
1135
- const childCross = effectiveAlign === "stretch" ? crossLimit : crossFromSize(axis, childSizeRes.value);
1136
- cursorMain = cursorMain + childMain + gap;
1137
- remainingMain = clampNonNegative(remainingMain - childMain - gap);
1138
- if (childMain > 0 || childCross > 0)
1139
- laidOutCount++;
1140
- if (childCross > maxChildCross)
1141
- maxChildCross = childCross;
1142
- }
1143
- const usedMainExcludingTrailingGap = laidOutCount === 0 ? 0 : clampNonNegative(cursorMain - gap);
1144
- return finalizeSize(Math.min(mainLimit, usedMainExcludingTrailingGap), maxChildCross);
1145
- }
1146
- return finalizeSize(Math.min(mainLimit, usedMainInConstraintPass), maxChildCross);
1147
- }
1148
11
  export function measureStackKinds(vnode, maxW, maxH, axis, measureNode) {
1149
12
  void axis;
1150
13
  if (!isStackVNode(vnode)) {
1151
- return {
1152
- ok: false,
1153
- fatal: { code: "ZRUI_INVALID_PROPS", detail: "measureStackKinds: unexpected vnode kind" },
1154
- };
14
+ return invalid("measureStackKinds: unexpected vnode kind");
1155
15
  }
1156
16
  const stackAxis = getAxisConfig(vnode.kind);
1157
17
  if (stackAxis === null) {
1158
- return {
1159
- ok: false,
1160
- fatal: { code: "ZRUI_INVALID_PROPS", detail: "measureStackKinds: unexpected vnode kind" },
1161
- };
18
+ return invalid("measureStackKinds: unexpected vnode kind");
1162
19
  }
1163
20
  return measureStack(stackAxis, vnode, maxW, maxH, measureNode);
1164
21
  }
1165
22
  export function layoutStackKinds(vnode, x, y, rectW, rectH, axis, measureNode, layoutNode) {
1166
23
  void axis;
1167
24
  if (!isStackVNode(vnode)) {
1168
- return {
1169
- ok: false,
1170
- fatal: { code: "ZRUI_INVALID_PROPS", detail: "layoutStackKinds: unexpected vnode kind" },
1171
- };
25
+ return invalid("layoutStackKinds: unexpected vnode kind");
1172
26
  }
1173
27
  const stackAxis = getAxisConfig(vnode.kind);
1174
28
  if (stackAxis === null) {
1175
- return {
1176
- ok: false,
1177
- fatal: { code: "ZRUI_INVALID_PROPS", detail: "layoutStackKinds: unexpected vnode kind" },
1178
- };
29
+ return invalid("layoutStackKinds: unexpected vnode kind");
1179
30
  }
1180
31
  return layoutStack(stackAxis, vnode, x, y, rectW, rectH, measureNode, layoutNode);
1181
32
  }
1182
- function layoutStack(axis, vnode, x, y, rectW, rectH, measureNode, layoutNode) {
1183
- const propsRes = validateStackProps(axis.axis, vnode.props);
1184
- if (!propsRes.ok)
1185
- return propsRes;
1186
- const { gap, align } = propsRes.value;
1187
- const justify = propsRes.value.justify;
1188
- const spacing = resolveSpacingProps(propsRes.value);
1189
- const margin = resolveMarginProps(propsRes.value);
1190
- const stackX = x + margin.left;
1191
- const stackY = y + margin.top;
1192
- const stackW = clampNonNegative(rectW - margin.left - margin.right);
1193
- const stackH = clampNonNegative(rectH - margin.top - margin.bottom);
1194
- const cx = stackX + spacing.left;
1195
- const cy = stackY + spacing.top;
1196
- const cw = clampNonNegative(stackW - spacing.left - spacing.right);
1197
- const ch = clampNonNegative(stackH - spacing.top - spacing.bottom);
1198
- const mainOrigin = mainFromWH(axis, cx, cy);
1199
- const crossOrigin = crossFromWH(axis, cx, cy);
1200
- const mainLimit = mainFromWH(axis, cw, ch);
1201
- const crossLimit = crossFromWH(axis, cw, ch);
1202
- const count = vnode.children.length;
1203
- const childCount = countNonEmptyChildren(vnode.children);
1204
- const children = [];
1205
- const needsConstraintPass = vnode.children.some((c) => !childHasAbsolutePosition(c) &&
1206
- (childHasFlexInMainAxis(c, axis.axis) || childHasAdvancedFlexProps(c)));
1207
- const wrap = isWrapEnabled(vnode.props);
1208
- if (wrap) {
1209
- const lines = [];
1210
- if (needsConstraintPass) {
1211
- const parentRect = { x: 0, y: 0, w: cw, h: ch };
1212
- const lineChildren = [];
1213
- let lineProbeMain = 0;
1214
- for (let i = 0; i < count; i++) {
1215
- const child = vnode.children[i];
1216
- if (!child || childHasAbsolutePosition(child))
1217
- continue;
1218
- const probeMainRes = probeWrapChildMain(axis, child, cw, ch, parentRect, measureNode);
1219
- if (!probeMainRes.ok)
1220
- return probeMainRes;
1221
- const probeMain = probeMainRes.value;
1222
- const wouldOverflow = lineChildren.length > 0 && lineProbeMain + gap + probeMain > mainLimit;
1223
- if (wouldOverflow) {
1224
- const linePlanRes = planWrapConstraintLine(axis, lineChildren, cw, ch, gap, parentRect, measureNode);
1225
- if (!linePlanRes.ok)
1226
- return linePlanRes;
1227
- lines.push(linePlanRes.value);
1228
- lineChildren.length = 0;
1229
- lineProbeMain = 0;
1230
- }
1231
- if (lineChildren.length === 0)
1232
- lineProbeMain = probeMain;
1233
- else
1234
- lineProbeMain += gap + probeMain;
1235
- lineChildren.push(child);
1236
- }
1237
- if (lineChildren.length > 0) {
1238
- const linePlanRes = planWrapConstraintLine(axis, lineChildren, cw, ch, gap, parentRect, measureNode);
1239
- if (!linePlanRes.ok)
1240
- return linePlanRes;
1241
- lines.push(linePlanRes.value);
1242
- }
1243
- }
1244
- else {
1245
- let lineMain = 0;
1246
- let lineCross = 0;
1247
- let lineChildren = [];
1248
- for (let i = 0; i < count; i++) {
1249
- const child = vnode.children[i];
1250
- if (!child || childHasAbsolutePosition(child))
1251
- continue;
1252
- const childSizeRes = measureNode(child, cw, ch, axis.axis);
1253
- if (!childSizeRes.ok)
1254
- return childSizeRes;
1255
- const childMain = mainFromSize(axis, childSizeRes.value);
1256
- const childCross = crossFromSize(axis, childSizeRes.value);
1257
- const wouldOverflow = lineChildren.length > 0 && lineMain + gap + childMain > mainLimit;
1258
- if (wouldOverflow) {
1259
- lines.push({
1260
- children: Object.freeze(lineChildren),
1261
- main: lineMain,
1262
- cross: lineCross,
1263
- });
1264
- lineMain = 0;
1265
- lineCross = 0;
1266
- lineChildren = [];
1267
- }
1268
- if (lineChildren.length === 0)
1269
- lineMain = childMain;
1270
- else
1271
- lineMain += gap + childMain;
1272
- if (childCross > lineCross)
1273
- lineCross = childCross;
1274
- lineChildren.push({
1275
- child,
1276
- main: childMain,
1277
- measureMaxMain: childMain,
1278
- cross: childCross,
1279
- });
1280
- }
1281
- if (lineChildren.length > 0) {
1282
- lines.push({
1283
- children: Object.freeze(lineChildren),
1284
- main: lineMain,
1285
- cross: lineCross,
1286
- });
1287
- }
1288
- }
1289
- let lineCrossPos = crossOrigin;
1290
- for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
1291
- const line = lines[lineIndex];
1292
- if (!line)
1293
- continue;
1294
- const lineChildCount = line.children.length;
1295
- const extra = clampNonNegative(mainLimit - line.main);
1296
- const startOffset = computeJustifyStartOffset(justify, extra, lineChildCount);
1297
- let cursorMain = mainOrigin + startOffset;
1298
- let remainingMain = clampNonNegative(mainLimit - startOffset);
1299
- for (let childOrdinal = 0; childOrdinal < lineChildCount; childOrdinal++) {
1300
- const planned = line.children[childOrdinal];
1301
- if (!planned)
1302
- continue;
1303
- const child = planned.child;
1304
- if (remainingMain === 0) {
1305
- const childRes = layoutNodeOnAxis(axis, child, cursorMain, lineCrossPos, 0, 0, layoutNode);
1306
- if (!childRes.ok)
1307
- return childRes;
1308
- children.push(childRes.value);
1309
- }
1310
- else {
1311
- const childCross = planned.cross;
1312
- let childCrossPos = lineCrossPos;
1313
- let forceCross = null;
1314
- const effectiveAlign = resolveEffectiveAlign(child, align);
1315
- if (effectiveAlign === "center") {
1316
- childCrossPos = lineCrossPos + Math.floor((line.cross - childCross) / 2);
1317
- }
1318
- else if (effectiveAlign === "end") {
1319
- childCrossPos = lineCrossPos + (line.cross - childCross);
1320
- }
1321
- else if (effectiveAlign === "stretch") {
1322
- forceCross = line.cross;
1323
- }
1324
- const childRes = needsConstraintPass
1325
- ? layoutNodeOnAxis(axis, child, cursorMain, childCrossPos, Math.max(planned.measureMaxMain, planned.main), crossLimit, layoutNode, planned.main, forceCross)
1326
- : layoutNodeOnAxis(axis, child, cursorMain, childCrossPos, remainingMain, crossLimit, layoutNode, null, forceCross);
1327
- if (!childRes.ok)
1328
- return childRes;
1329
- children.push(childRes.value);
1330
- }
1331
- const hasNextChild = childOrdinal < lineChildCount - 1;
1332
- const extraGap = hasNextChild
1333
- ? computeJustifyExtraGap(justify, extra, lineChildCount, childOrdinal)
1334
- : 0;
1335
- const step = planned.main + (hasNextChild ? gap + extraGap : 0);
1336
- cursorMain = cursorMain + step;
1337
- remainingMain = clampNonNegative(remainingMain - step);
1338
- }
1339
- if (lineIndex < lines.length - 1) {
1340
- lineCrossPos = lineCrossPos + line.cross + gap;
1341
- }
1342
- }
1343
- }
1344
- else if (!needsConstraintPass) {
1345
- const mainSizes = acquireArray(count);
1346
- const crossSizes = acquireArray(count);
1347
- try {
1348
- let rem = mainLimit;
1349
- for (let i = 0; i < count; i++) {
1350
- const child = vnode.children[i];
1351
- if (!child || childHasAbsolutePosition(child))
1352
- continue;
1353
- if (rem === 0)
1354
- continue;
1355
- const childSizeRes = measureNodeOnAxis(axis, child, rem, crossLimit, measureNode);
1356
- if (!childSizeRes.ok)
1357
- return childSizeRes;
1358
- mainSizes[i] = mainFromSize(axis, childSizeRes.value);
1359
- crossSizes[i] = crossFromSize(axis, childSizeRes.value);
1360
- rem = clampNonNegative(rem - (mainSizes[i] ?? 0) - gap);
1361
- }
1362
- let usedMain = 0;
1363
- for (let i = 0; i < count; i++) {
1364
- usedMain += mainSizes[i] ?? 0;
1365
- }
1366
- usedMain += childCount <= 1 ? 0 : gap * (childCount - 1);
1367
- const extra = clampNonNegative(mainLimit - usedMain);
1368
- const startOffset = computeJustifyStartOffset(justify, extra, childCount);
1369
- let cursorMain = mainOrigin + startOffset;
1370
- let remainingMain = clampNonNegative(mainLimit - startOffset);
1371
- let childOrdinal = 0;
1372
- for (let i = 0; i < count; i++) {
1373
- const child = vnode.children[i];
1374
- if (!child || childHasAbsolutePosition(child))
1375
- continue;
1376
- if (remainingMain === 0) {
1377
- const childRes = layoutNodeOnAxis(axis, child, cursorMain, crossOrigin, 0, 0, layoutNode);
1378
- if (!childRes.ok)
1379
- return childRes;
1380
- children.push(childRes.value);
1381
- childOrdinal++;
1382
- continue;
1383
- }
1384
- const childMain = mainSizes[i] ?? 0;
1385
- const childCross = crossSizes[i] ?? 0;
1386
- let childCrossPos = crossOrigin;
1387
- let forceCross = null;
1388
- const effectiveAlign = resolveEffectiveAlign(child, align);
1389
- if (effectiveAlign === "center") {
1390
- childCrossPos = crossOrigin + Math.floor((crossLimit - childCross) / 2);
1391
- }
1392
- else if (effectiveAlign === "end") {
1393
- childCrossPos = crossOrigin + (crossLimit - childCross);
1394
- }
1395
- else if (effectiveAlign === "stretch") {
1396
- forceCross = crossLimit;
1397
- }
1398
- const childRes = layoutNodeOnAxis(axis, child, cursorMain, childCrossPos, remainingMain, crossLimit, layoutNode, null, forceCross);
1399
- if (!childRes.ok)
1400
- return childRes;
1401
- children.push(childRes.value);
1402
- const hasNextChild = childOrdinal < childCount - 1;
1403
- const extraGap = hasNextChild
1404
- ? computeJustifyExtraGap(justify, extra, childCount, childOrdinal)
1405
- : 0;
1406
- const step = childMain + (hasNextChild ? gap + extraGap : 0);
1407
- cursorMain = cursorMain + step;
1408
- remainingMain = clampNonNegative(remainingMain - step);
1409
- childOrdinal++;
1410
- }
1411
- }
1412
- finally {
1413
- releaseArray(mainSizes);
1414
- releaseArray(crossSizes);
1415
- }
1416
- }
1417
- else {
1418
- const parentRect = { x: 0, y: 0, w: cw, h: ch };
1419
- const gapTotal = childCount <= 1 ? 0 : gap * (childCount - 1);
1420
- const availableForChildren = clampNonNegative(mainLimit - gapTotal);
1421
- const planRes = planConstraintMainSizes(axis, vnode.children, availableForChildren, mainLimit, crossLimit, parentRect, measureNode, true);
1422
- if (!planRes.ok)
1423
- return planRes;
1424
- const { mainSizes, measureMaxMain, precomputedSizes } = planRes.value;
1425
- const crossPlanRes = planConstraintCrossSizes(axis, vnode.children, mainSizes, measureMaxMain, crossLimit, align, measureNode, precomputedSizes);
1426
- if (!crossPlanRes.ok)
1427
- return crossPlanRes;
1428
- const plannedSizes = crossPlanRes.value.sizes;
1429
- const plannedCrossSizes = crossPlanRes.value.crossSizes;
1430
- let usedMain = 0;
1431
- for (let i = 0; i < mainSizes.length; i++) {
1432
- usedMain += mainSizes[i] ?? 0;
1433
- }
1434
- usedMain += childCount <= 1 ? 0 : gap * (childCount - 1);
1435
- const extra = clampNonNegative(mainLimit - usedMain);
1436
- const startOffset = computeJustifyStartOffset(justify, extra, childCount);
1437
- let cursorMain = mainOrigin + startOffset;
1438
- let remainingMain = clampNonNegative(mainLimit - startOffset);
1439
- let childOrdinal = 0;
1440
- for (let i = 0; i < count; i++) {
1441
- const child = vnode.children[i];
1442
- if (!child || childHasAbsolutePosition(child))
1443
- continue;
1444
- if (remainingMain === 0) {
1445
- let precomputed = plannedSizes[i];
1446
- if (precomputed == null) {
1447
- const zeroSizeRes = measureNodeOnAxis(axis, child, 0, 0, measureNode);
1448
- if (!zeroSizeRes.ok)
1449
- return zeroSizeRes;
1450
- precomputed = zeroSizeRes.value;
1451
- plannedSizes[i] = precomputed;
1452
- }
1453
- const childRes = layoutNodeOnAxis(axis, child, cursorMain, crossOrigin, 0, 0, layoutNode, null, null, precomputed);
1454
- if (!childRes.ok)
1455
- return childRes;
1456
- children.push(childRes.value);
1457
- maybePruneRemainingDirtySiblings(vnode.children, i, child, childRes.value);
1458
- childOrdinal++;
1459
- continue;
1460
- }
1461
- const main = mainSizes[i] ?? 0;
1462
- const mm = measureMaxMain[i] ?? 0;
1463
- let childSize = plannedSizes[i];
1464
- if (childSize == null) {
1465
- const childSizeRes = measureNodeOnAxis(axis, child, mm, crossLimit, measureNode);
1466
- if (!childSizeRes.ok)
1467
- return childSizeRes;
1468
- childSize = childSizeRes.value;
1469
- plannedSizes[i] = childSize;
1470
- }
1471
- const childCross = plannedCrossSizes[i] ?? crossFromSize(axis, childSize);
1472
- let childCrossPos = crossOrigin;
1473
- let forceCross = null;
1474
- const effectiveAlign = resolveEffectiveAlign(child, align);
1475
- if (effectiveAlign === "center") {
1476
- childCrossPos = crossOrigin + Math.floor((crossLimit - childCross) / 2);
1477
- }
1478
- else if (effectiveAlign === "end") {
1479
- childCrossPos = crossOrigin + (crossLimit - childCross);
1480
- }
1481
- else if (effectiveAlign === "stretch") {
1482
- forceCross = crossLimit;
1483
- }
1484
- const childRes = layoutNodeOnAxis(axis, child, cursorMain, childCrossPos, Math.max(mm, main), crossLimit, layoutNode, main, forceCross, childSize);
1485
- if (!childRes.ok)
1486
- return childRes;
1487
- children.push(childRes.value);
1488
- maybePruneRemainingDirtySiblings(vnode.children, i, child, childRes.value);
1489
- const hasNextChild = childOrdinal < childCount - 1;
1490
- const extraGap = hasNextChild
1491
- ? computeJustifyExtraGap(justify, extra, childCount, childOrdinal)
1492
- : 0;
1493
- const step = main + (hasNextChild ? gap + extraGap : 0);
1494
- cursorMain = cursorMain + step;
1495
- remainingMain = clampNonNegative(remainingMain - step);
1496
- childOrdinal++;
1497
- }
1498
- }
1499
- const contentRect = { x: cx, y: cy, w: cw, h: ch };
1500
- for (let i = 0; i < count; i++) {
1501
- const child = vnode.children[i];
1502
- if (!child || !childHasAbsolutePosition(child))
1503
- continue;
1504
- const naturalRes = measureNode(child, cw, ch, axis.axis);
1505
- if (!naturalRes.ok)
1506
- return naturalRes;
1507
- const absProps = (child.props ?? {});
1508
- const absRect = resolveAbsolutePosition(absProps, contentRect, naturalRes.value);
1509
- const childRes = layoutNode(child, absRect.x, absRect.y, absRect.w, absRect.h, axis.axis, absRect.w, absRect.h, naturalRes.value);
1510
- if (!childRes.ok)
1511
- return childRes;
1512
- children.push(childRes.value);
1513
- }
1514
- const flowChildren = children.slice(0, childCount);
1515
- const absChildren = children.slice(childCount);
1516
- const orderedChildren = [];
1517
- let flowIndex = 0;
1518
- let absIndex = 0;
1519
- for (let i = 0; i < count; i++) {
1520
- const child = vnode.children[i];
1521
- if (!child)
1522
- continue;
1523
- if (childHasAbsolutePosition(child)) {
1524
- const absChild = absChildren[absIndex];
1525
- absIndex++;
1526
- if (absChild)
1527
- orderedChildren.push(absChild);
1528
- continue;
1529
- }
1530
- const flowChild = flowChildren[flowIndex];
1531
- flowIndex++;
1532
- if (flowChild)
1533
- orderedChildren.push(flowChild);
1534
- }
1535
- const { contentWidth, contentHeight } = measureContentBounds(orderedChildren, cx, cy);
1536
- const overflow = resolveOverflow(propsRes.value, cw, ch, contentWidth, contentHeight);
1537
- const shiftedChildren = shiftLayoutChildren(orderedChildren, -overflow.metadata.scrollX, -overflow.metadata.scrollY);
1538
- return ok({
1539
- vnode,
1540
- rect: { x: stackX, y: stackY, w: stackW, h: stackH },
1541
- children: Object.freeze(shiftedChildren),
1542
- meta: overflow.metadata,
1543
- });
1544
- }
1545
33
  //# sourceMappingURL=stack.js.map