@pibbl/core 0.0.2 → 0.0.3-alpha.109.1

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 (549) hide show
  1. package/THIRD_PARTY_NOTICES.txt +81 -0
  2. package/dist/features/physics/2d-testing.d.ts +1 -1
  3. package/dist/features/physics/2d-testing.js +2 -2
  4. package/dist/features/physics/2d-testing.js.map +2 -2
  5. package/dist/features/physics/lib/2d/canvas/components.js +25 -21
  6. package/dist/features/physics/lib/2d/canvas/components.js.map +2 -2
  7. package/dist/features/physics/lib/2d/canvas/presentation.js +1 -2
  8. package/dist/features/physics/lib/2d/canvas/presentation.js.map +2 -2
  9. package/dist/features/physics/lib/2d/collision/casts.js +4 -2
  10. package/dist/features/physics/lib/2d/collision/casts.js.map +2 -2
  11. package/dist/features/physics/lib/2d/runtime/controller.js +1 -1
  12. package/dist/features/physics/lib/2d/runtime/controller.js.map +2 -2
  13. package/dist/features/physics/lib/2d/runtime/obstacles.js +9 -11
  14. package/dist/features/physics/lib/2d/runtime/obstacles.js.map +2 -2
  15. package/dist/features/physics/lib/2d/shapes.js +8 -9
  16. package/dist/features/physics/lib/2d/shapes.js.map +2 -2
  17. package/dist/features/physics/lib/2d/world/rapier.js +22 -26
  18. package/dist/features/physics/lib/2d/world/rapier.js.map +2 -2
  19. package/dist/features/sprites/loader.js +6 -3
  20. package/dist/features/sprites/loader.js.map +2 -2
  21. package/dist/features/textures/index.d.ts +12 -2
  22. package/dist/features/textures/index.js +33 -1
  23. package/dist/features/textures/index.js.map +2 -2
  24. package/dist/features/textures/lib/chemical-field.d.ts +56 -0
  25. package/dist/features/textures/lib/chemical-field.js +154 -0
  26. package/dist/features/textures/lib/chemical-field.js.map +7 -0
  27. package/dist/features/textures/lib/chemical-recipes.d.ts +119 -0
  28. package/dist/features/textures/lib/chemical-recipes.js +275 -0
  29. package/dist/features/textures/lib/chemical-recipes.js.map +7 -0
  30. package/dist/features/textures/lib/definitions.d.ts +3 -18
  31. package/dist/features/textures/lib/definitions.js +17 -24
  32. package/dist/features/textures/lib/definitions.js.map +2 -2
  33. package/dist/features/textures/lib/geometric-patterns.d.ts +149 -0
  34. package/dist/features/textures/lib/geometric-patterns.js +305 -0
  35. package/dist/features/textures/lib/geometric-patterns.js.map +7 -0
  36. package/dist/features/textures/lib/gray-scott.d.ts +55 -0
  37. package/dist/features/textures/lib/gray-scott.js +37 -0
  38. package/dist/features/textures/lib/gray-scott.js.map +7 -0
  39. package/dist/features/textures/lib/palette.js +1 -3
  40. package/dist/features/textures/lib/palette.js.map +2 -2
  41. package/dist/features/textures/lib/patterns.d.ts +123 -0
  42. package/dist/features/textures/lib/patterns.js +344 -0
  43. package/dist/features/textures/lib/patterns.js.map +7 -0
  44. package/dist/features/textures/lib/rain-drops.js +2 -1
  45. package/dist/features/textures/lib/rain-drops.js.map +2 -2
  46. package/dist/features/textures/lib/reaction-diffusion.d.ts +3 -2
  47. package/dist/features/textures/lib/reaction-diffusion.js +9 -20
  48. package/dist/features/textures/lib/reaction-diffusion.js.map +2 -2
  49. package/dist/features/textures/lib/simulation.d.ts +10 -4
  50. package/dist/features/textures/lib/simulation.js +23 -13
  51. package/dist/features/textures/lib/simulation.js.map +2 -2
  52. package/dist/features/textures/lib/wasm/electric.js +8 -1
  53. package/dist/features/textures/lib/wasm/electric.js.map +2 -2
  54. package/dist/features/textures/lib/water-surface.js +1 -3
  55. package/dist/features/textures/lib/water-surface.js.map +2 -2
  56. package/dist/features/viz/index.d.ts +68 -6
  57. package/dist/features/viz/index.js +164 -2
  58. package/dist/features/viz/index.js.map +2 -2
  59. package/dist/features/viz/inspection/bar.d.ts +79 -0
  60. package/dist/features/viz/inspection/bar.js +49 -0
  61. package/dist/features/viz/inspection/bar.js.map +7 -0
  62. package/dist/features/viz/inspection/candle.d.ts +156 -0
  63. package/dist/features/viz/inspection/candle.js +120 -0
  64. package/dist/features/viz/inspection/candle.js.map +7 -0
  65. package/dist/features/viz/inspection/capture-types.d.ts +65 -0
  66. package/dist/features/viz/inspection/capture.d.ts +16 -0
  67. package/dist/features/viz/inspection/capture.js +49 -0
  68. package/dist/features/viz/inspection/capture.js.map +7 -0
  69. package/dist/features/viz/inspection/handler.d.ts +36 -0
  70. package/dist/features/viz/inspection/handler.js +91 -0
  71. package/dist/features/viz/inspection/handler.js.map +7 -0
  72. package/dist/features/viz/inspection/ohlc-bar.d.ts +132 -0
  73. package/dist/features/viz/inspection/ohlc-bar.js +118 -0
  74. package/dist/features/viz/inspection/ohlc-bar.js.map +7 -0
  75. package/dist/features/viz/inspection/owned-ref.d.ts +16 -0
  76. package/dist/features/viz/inspection/owned-ref.js +99 -0
  77. package/dist/features/viz/inspection/owned-ref.js.map +7 -0
  78. package/dist/features/viz/inspection/painted-point.d.ts +22 -0
  79. package/dist/features/viz/inspection/painted-point.js +29 -0
  80. package/dist/features/viz/inspection/painted-point.js.map +7 -0
  81. package/dist/features/viz/inspection/queries.d.ts +100 -0
  82. package/dist/features/viz/inspection/queries.js +192 -0
  83. package/dist/features/viz/inspection/queries.js.map +7 -0
  84. package/dist/features/viz/inspection/query-types.d.ts +177 -0
  85. package/dist/features/viz/inspection/volume.d.ts +104 -0
  86. package/dist/features/viz/inspection/volume.js +95 -0
  87. package/dist/features/viz/inspection/volume.js.map +7 -0
  88. package/dist/features/viz/inspection.d.ts +19 -0
  89. package/dist/features/viz/inspection.js +54 -0
  90. package/dist/features/viz/inspection.js.map +7 -0
  91. package/dist/features/viz/inspection.mjs +1 -0
  92. package/dist/features/viz/lib/area-series.d.ts +62 -0
  93. package/dist/features/viz/lib/area-series.js +120 -0
  94. package/dist/features/viz/lib/area-series.js.map +7 -0
  95. package/dist/features/viz/lib/axis-title.js +2 -1
  96. package/dist/features/viz/lib/axis-title.js.map +2 -2
  97. package/dist/features/viz/lib/axis.js +1 -1
  98. package/dist/features/viz/lib/axis.js.map +2 -2
  99. package/dist/features/viz/lib/bar-series.d.ts +3 -1
  100. package/dist/features/viz/lib/bar-series.js +16 -1
  101. package/dist/features/viz/lib/bar-series.js.map +2 -2
  102. package/dist/features/viz/lib/baseline-series.d.ts +55 -0
  103. package/dist/features/viz/lib/baseline-series.js +136 -0
  104. package/dist/features/viz/lib/baseline-series.js.map +7 -0
  105. package/dist/features/viz/lib/candlestick-series.d.ts +62 -0
  106. package/dist/features/viz/lib/candlestick-series.js +150 -0
  107. package/dist/features/viz/lib/candlestick-series.js.map +7 -0
  108. package/dist/features/viz/lib/censored-point-series.d.ts +71 -0
  109. package/dist/features/viz/lib/censored-point-series.js +129 -0
  110. package/dist/features/viz/lib/censored-point-series.js.map +7 -0
  111. package/dist/features/viz/lib/color-context.d.ts +4 -0
  112. package/dist/features/viz/lib/color-context.js +41 -0
  113. package/dist/features/viz/lib/color-context.js.map +7 -0
  114. package/dist/features/viz/lib/color-math.d.ts +4 -0
  115. package/dist/features/viz/lib/color-math.js +31 -0
  116. package/dist/features/viz/lib/color-math.js.map +7 -0
  117. package/dist/features/viz/lib/color-types.d.ts +53 -0
  118. package/dist/features/viz/lib/curve-definition.d.ts +49 -0
  119. package/dist/features/viz/lib/curve-definition.js +142 -0
  120. package/dist/features/viz/lib/curve-definition.js.map +7 -0
  121. package/dist/features/viz/lib/diverging-color-scale.d.ts +11 -0
  122. package/dist/features/viz/lib/diverging-color-scale.js +51 -0
  123. package/dist/features/viz/lib/diverging-color-scale.js.map +7 -0
  124. package/dist/features/viz/lib/domain-navigation.d.ts +40 -0
  125. package/dist/features/viz/lib/domain-navigation.js +77 -0
  126. package/dist/features/viz/lib/domain-navigation.js.map +7 -0
  127. package/dist/features/viz/lib/editable-chart-elements.d.ts +178 -0
  128. package/dist/features/viz/lib/editable-chart-elements.js +733 -0
  129. package/dist/features/viz/lib/editable-chart-elements.js.map +7 -0
  130. package/dist/features/viz/lib/financial-aggregation.d.ts +127 -0
  131. package/dist/features/viz/lib/financial-aggregation.js +116 -0
  132. package/dist/features/viz/lib/financial-aggregation.js.map +7 -0
  133. package/dist/features/viz/lib/financial-autoscale.d.ts +64 -0
  134. package/dist/features/viz/lib/financial-autoscale.js +61 -0
  135. package/dist/features/viz/lib/financial-autoscale.js.map +7 -0
  136. package/dist/features/viz/lib/financial-comparison.d.ts +62 -0
  137. package/dist/features/viz/lib/financial-comparison.js +98 -0
  138. package/dist/features/viz/lib/financial-comparison.js.map +7 -0
  139. package/dist/features/viz/lib/financial-geometry.d.ts +77 -0
  140. package/dist/features/viz/lib/financial-geometry.js +67 -0
  141. package/dist/features/viz/lib/financial-geometry.js.map +7 -0
  142. package/dist/features/viz/lib/financial-indicators.d.ts +114 -0
  143. package/dist/features/viz/lib/financial-indicators.js +135 -0
  144. package/dist/features/viz/lib/financial-indicators.js.map +7 -0
  145. package/dist/features/viz/lib/financial-oscillators.d.ts +171 -0
  146. package/dist/features/viz/lib/financial-oscillators.js +265 -0
  147. package/dist/features/viz/lib/financial-oscillators.js.map +7 -0
  148. package/dist/features/viz/lib/graph/bipartite.d.ts +14 -0
  149. package/dist/features/viz/lib/graph/bipartite.js +250 -0
  150. package/dist/features/viz/lib/graph/bipartite.js.map +7 -0
  151. package/dist/features/viz/lib/graph/chord.d.ts +44 -0
  152. package/dist/features/viz/lib/graph/chord.js +348 -0
  153. package/dist/features/viz/lib/graph/chord.js.map +7 -0
  154. package/dist/features/viz/lib/graph/dependency.d.ts +26 -0
  155. package/dist/features/viz/lib/graph/dependency.js +140 -0
  156. package/dist/features/viz/lib/graph/dependency.js.map +7 -0
  157. package/dist/features/viz/lib/graph/force.d.ts +28 -0
  158. package/dist/features/viz/lib/graph/force.js +580 -0
  159. package/dist/features/viz/lib/graph/force.js.map +7 -0
  160. package/dist/features/viz/lib/graph/hierarchy.d.ts +21 -0
  161. package/dist/features/viz/lib/graph/hierarchy.js +112 -0
  162. package/dist/features/viz/lib/graph/hierarchy.js.map +7 -0
  163. package/dist/features/viz/lib/graph/icicle.d.ts +16 -0
  164. package/dist/features/viz/lib/graph/icicle.js +153 -0
  165. package/dist/features/viz/lib/graph/icicle.js.map +7 -0
  166. package/dist/features/viz/lib/graph/matrix.d.ts +30 -0
  167. package/dist/features/viz/lib/graph/matrix.js +243 -0
  168. package/dist/features/viz/lib/graph/matrix.js.map +7 -0
  169. package/dist/features/viz/lib/graph/neighborhood.d.ts +11 -0
  170. package/dist/features/viz/lib/graph/neighborhood.js +281 -0
  171. package/dist/features/viz/lib/graph/neighborhood.js.map +7 -0
  172. package/dist/features/viz/lib/graph/routes.d.ts +35 -0
  173. package/dist/features/viz/lib/graph/routes.js +101 -0
  174. package/dist/features/viz/lib/graph/routes.js.map +7 -0
  175. package/dist/features/viz/lib/graph/sankey.d.ts +44 -0
  176. package/dist/features/viz/lib/graph/sankey.js +341 -0
  177. package/dist/features/viz/lib/graph/sankey.js.map +7 -0
  178. package/dist/features/viz/lib/graph/shared.d.ts +59 -0
  179. package/dist/features/viz/lib/graph/shared.js +301 -0
  180. package/dist/features/viz/lib/graph/shared.js.map +7 -0
  181. package/dist/features/viz/lib/graph/tree.d.ts +11 -0
  182. package/dist/features/viz/lib/graph/tree.js +232 -0
  183. package/dist/features/viz/lib/graph/tree.js.map +7 -0
  184. package/dist/features/viz/lib/graph/treemap.d.ts +20 -0
  185. package/dist/features/viz/lib/graph/treemap.js +227 -0
  186. package/dist/features/viz/lib/graph/treemap.js.map +7 -0
  187. package/dist/features/viz/lib/graph/types.d.ts +1097 -0
  188. package/dist/features/viz/lib/hover-card.js +8 -9
  189. package/dist/features/viz/lib/hover-card.js.map +2 -2
  190. package/dist/features/viz/lib/hover-data.d.ts +1 -1
  191. package/dist/features/viz/lib/hover-data.js +5 -2
  192. package/dist/features/viz/lib/hover-data.js.map +2 -2
  193. package/dist/features/viz/lib/interval-band-series.d.ts +49 -0
  194. package/dist/features/viz/lib/interval-band-series.js +136 -0
  195. package/dist/features/viz/lib/interval-band-series.js.map +7 -0
  196. package/dist/features/viz/lib/interval-diamond-series.d.ts +43 -0
  197. package/dist/features/viz/lib/interval-diamond-series.js +122 -0
  198. package/dist/features/viz/lib/interval-diamond-series.js.map +7 -0
  199. package/dist/features/viz/lib/interval-series.d.ts +79 -0
  200. package/dist/features/viz/lib/interval-series.js +158 -0
  201. package/dist/features/viz/lib/interval-series.js.map +7 -0
  202. package/dist/features/viz/lib/layout-pie.js +9 -13
  203. package/dist/features/viz/lib/layout-pie.js.map +2 -2
  204. package/dist/features/viz/lib/line-series.d.ts +1 -1
  205. package/dist/features/viz/lib/line-series.js +47 -28
  206. package/dist/features/viz/lib/line-series.js.map +2 -2
  207. package/dist/features/viz/lib/linear-scale.js +1 -1
  208. package/dist/features/viz/lib/linear-scale.js.map +2 -2
  209. package/dist/features/viz/lib/monotone-curve.d.ts +11 -0
  210. package/dist/features/viz/lib/monotone-curve.js +63 -0
  211. package/dist/features/viz/lib/monotone-curve.js.map +7 -0
  212. package/dist/features/viz/lib/numeric-range-interpolation.d.ts +15 -0
  213. package/dist/features/viz/lib/numeric-range-interpolation.js +36 -0
  214. package/dist/features/viz/lib/numeric-range-interpolation.js.map +7 -0
  215. package/dist/features/viz/lib/ohlc-bar-series.d.ts +55 -0
  216. package/dist/features/viz/lib/ohlc-bar-series.js +168 -0
  217. package/dist/features/viz/lib/ohlc-bar-series.js.map +7 -0
  218. package/dist/features/viz/lib/paired-series.d.ts +44 -0
  219. package/dist/features/viz/lib/paired-series.js +93 -0
  220. package/dist/features/viz/lib/paired-series.js.map +7 -0
  221. package/dist/features/viz/lib/pie-layout.js +2 -1
  222. package/dist/features/viz/lib/pie-layout.js.map +2 -2
  223. package/dist/features/viz/lib/plot-series.js +11 -6
  224. package/dist/features/viz/lib/plot-series.js.map +2 -2
  225. package/dist/features/viz/lib/plot-types.d.ts +4 -3
  226. package/dist/features/viz/lib/point-series.d.ts +1 -1
  227. package/dist/features/viz/lib/point-series.js +36 -9
  228. package/dist/features/viz/lib/point-series.js.map +2 -2
  229. package/dist/features/viz/lib/point-types.d.ts +5 -2
  230. package/dist/features/viz/lib/reference-band.js +4 -1
  231. package/dist/features/viz/lib/reference-band.js.map +2 -2
  232. package/dist/features/viz/lib/scale-context.d.ts +1 -1
  233. package/dist/features/viz/lib/scale-ticks.js +21 -6
  234. package/dist/features/viz/lib/scale-ticks.js.map +2 -2
  235. package/dist/features/viz/lib/sequential-color-scale.d.ts +11 -0
  236. package/dist/features/viz/lib/sequential-color-scale.js +49 -0
  237. package/dist/features/viz/lib/sequential-color-scale.js.map +7 -0
  238. package/dist/features/viz/lib/series-position.d.ts +12 -0
  239. package/dist/features/viz/lib/series-position.js +44 -0
  240. package/dist/features/viz/lib/series-position.js.map +7 -0
  241. package/dist/features/viz/lib/step-curves.d.ts +19 -0
  242. package/dist/features/viz/lib/step-curves.js +53 -0
  243. package/dist/features/viz/lib/step-curves.js.map +7 -0
  244. package/dist/features/viz/lib/threshold-color-scale.d.ts +43 -0
  245. package/dist/features/viz/lib/threshold-color-scale.js +59 -0
  246. package/dist/features/viz/lib/threshold-color-scale.js.map +7 -0
  247. package/dist/features/viz/lib/trading-time-mapping.d.ts +32 -0
  248. package/dist/features/viz/lib/trading-time-mapping.js +89 -0
  249. package/dist/features/viz/lib/trading-time-mapping.js.map +7 -0
  250. package/dist/features/viz/lib/trading-time-scale.d.ts +83 -0
  251. package/dist/features/viz/lib/trading-time-scale.js +96 -0
  252. package/dist/features/viz/lib/trading-time-scale.js.map +7 -0
  253. package/dist/features/viz/lib/trajectory-series.d.ts +71 -0
  254. package/dist/features/viz/lib/trajectory-series.js +111 -0
  255. package/dist/features/viz/lib/trajectory-series.js.map +7 -0
  256. package/dist/features/viz/lib/types.d.ts +20 -4
  257. package/dist/features/viz/lib/use-continuous-scale.js +6 -1
  258. package/dist/features/viz/lib/use-continuous-scale.js.map +2 -2
  259. package/dist/features/viz/lib/utc-scale.js +11 -10
  260. package/dist/features/viz/lib/utc-scale.js.map +2 -2
  261. package/dist/features/viz/lib/volume-series.d.ts +59 -0
  262. package/dist/features/viz/lib/volume-series.js +117 -0
  263. package/dist/features/viz/lib/volume-series.js.map +7 -0
  264. package/dist/features/viz/lib/weighted-point-series.d.ts +71 -0
  265. package/dist/features/viz/lib/weighted-point-series.js +169 -0
  266. package/dist/features/viz/lib/weighted-point-series.js.map +7 -0
  267. package/dist/filters/backdrop-contrast-gpu.d.ts +5 -0
  268. package/dist/filters/backdrop-contrast-gpu.js +33 -0
  269. package/dist/filters/backdrop-contrast-gpu.js.map +7 -0
  270. package/dist/filters/backdrop-contrast.d.ts +21 -0
  271. package/dist/filters/backdrop-contrast.js +61 -0
  272. package/dist/filters/backdrop-contrast.js.map +7 -0
  273. package/dist/filters/displacement.js +1 -1
  274. package/dist/filters/displacement.js.map +2 -2
  275. package/dist/filters/emboss-gpu.d.ts +4 -0
  276. package/dist/filters/emboss-gpu.js +39 -0
  277. package/dist/filters/emboss-gpu.js.map +7 -0
  278. package/dist/filters/emboss.d.ts +32 -0
  279. package/dist/filters/emboss.js +104 -0
  280. package/dist/filters/emboss.js.map +7 -0
  281. package/dist/filters/filter-executor.d.ts +11 -4
  282. package/dist/filters/filter-executor.js +104 -49
  283. package/dist/filters/filter-executor.js.map +2 -2
  284. package/dist/filters/reflected-light.js +1 -1
  285. package/dist/filters/reflected-light.js.map +2 -2
  286. package/dist/filters/reflection-gpu.d.ts +3 -1
  287. package/dist/filters/reflection-gpu.js +5 -2
  288. package/dist/filters/reflection-gpu.js.map +2 -2
  289. package/dist/filters/render-backdrop-contrast-boundary.d.ts +31 -0
  290. package/dist/filters/render-backdrop-contrast-boundary.js +116 -0
  291. package/dist/filters/render-backdrop-contrast-boundary.js.map +7 -0
  292. package/dist/filters/render-emboss-boundary.d.ts +13 -0
  293. package/dist/filters/render-emboss-boundary.js +131 -0
  294. package/dist/filters/render-emboss-boundary.js.map +7 -0
  295. package/dist/filters.d.ts +9 -5
  296. package/dist/filters.js +4 -0
  297. package/dist/filters.js.map +2 -2
  298. package/dist/index.d.ts +9 -5
  299. package/dist/index.js +18 -2
  300. package/dist/index.js.map +2 -2
  301. package/dist/internal.d.ts +4 -0
  302. package/dist/internal.js +6 -0
  303. package/dist/internal.js.map +2 -2
  304. package/dist/layout-kernel.d.ts +12 -0
  305. package/dist/layout-kernel.js +11 -0
  306. package/dist/layout-kernel.js.map +7 -0
  307. package/dist/layout-kernel.mjs +1 -0
  308. package/dist/lib/backend/types.d.ts +13 -1
  309. package/dist/lib/backend/types.js.map +2 -2
  310. package/dist/lib/components/arc-geometry.js +2 -1
  311. package/dist/lib/components/arc-geometry.js.map +2 -2
  312. package/dist/lib/components/g.js +2 -0
  313. package/dist/lib/components/g.js.map +2 -2
  314. package/dist/lib/components/html-box.js +2 -1
  315. package/dist/lib/components/html-box.js.map +2 -2
  316. package/dist/lib/components/img.js +3 -3
  317. package/dist/lib/components/img.js.map +2 -2
  318. package/dist/lib/components/layer.js +98 -16
  319. package/dist/lib/components/layer.js.map +3 -3
  320. package/dist/lib/components/text.d.ts +16 -0
  321. package/dist/lib/components/text.js +131 -24
  322. package/dist/lib/components/text.js.map +2 -2
  323. package/dist/lib/define-primitive.d.ts +4 -2
  324. package/dist/lib/define-primitive.js +3 -1
  325. package/dist/lib/define-primitive.js.map +2 -2
  326. package/dist/lib/element/metadata.d.ts +9 -0
  327. package/dist/lib/element/metadata.js +19 -0
  328. package/dist/lib/element/metadata.js.map +2 -2
  329. package/dist/lib/element/resolve-primitive-inputs.d.ts +2 -0
  330. package/dist/lib/element/resolve-primitive-inputs.js +17 -4
  331. package/dist/lib/element/resolve-primitive-inputs.js.map +2 -2
  332. package/dist/lib/events/event-facade.d.ts +18 -0
  333. package/dist/lib/events/event-facade.js +28 -2
  334. package/dist/lib/events/event-facade.js.map +2 -2
  335. package/dist/lib/events/hit-test.js +2 -1
  336. package/dist/lib/events/hit-test.js.map +2 -2
  337. package/dist/lib/events/propagation.d.ts +2 -1
  338. package/dist/lib/events/propagation.js +22 -16
  339. package/dist/lib/events/propagation.js.map +2 -2
  340. package/dist/lib/events/registrations.d.ts +10 -0
  341. package/dist/lib/events/registrations.js +160 -5
  342. package/dist/lib/events/registrations.js.map +2 -2
  343. package/dist/lib/execute-render.js +25 -1
  344. package/dist/lib/execute-render.js.map +2 -2
  345. package/dist/lib/filter/filter-region.js +3 -10
  346. package/dist/lib/filter/filter-region.js.map +2 -2
  347. package/dist/lib/focus/focus-manager.d.ts +8 -1
  348. package/dist/lib/focus/focus-manager.js +87 -43
  349. package/dist/lib/focus/focus-manager.js.map +2 -2
  350. package/dist/lib/focus/geometry.d.ts +2 -0
  351. package/dist/lib/focus/geometry.js +6 -0
  352. package/dist/lib/focus/geometry.js.map +2 -2
  353. package/dist/lib/geometry/path-bend-guide.js +1 -1
  354. package/dist/lib/geometry/path-bend-guide.js.map +2 -2
  355. package/dist/lib/geometry/path-geometry.js +12 -11
  356. package/dist/lib/geometry/path-geometry.js.map +2 -2
  357. package/dist/lib/geometry/path-transforms.js +17 -21
  358. package/dist/lib/geometry/path-transforms.js.map +2 -2
  359. package/dist/lib/geometry/path-warp-bezier.js +3 -1
  360. package/dist/lib/geometry/path-warp-bezier.js.map +2 -2
  361. package/dist/lib/geometry/path-warp.js +1 -1
  362. package/dist/lib/geometry/path-warp.js.map +2 -2
  363. package/dist/lib/global-state.js +2 -0
  364. package/dist/lib/global-state.js.map +2 -2
  365. package/dist/lib/html/html-events.d.ts +32 -0
  366. package/dist/lib/html/html-events.js +179 -0
  367. package/dist/lib/html/html-events.js.map +7 -0
  368. package/dist/lib/html/html-service.d.ts +8 -2
  369. package/dist/lib/html/html-service.js +198 -65
  370. package/dist/lib/html/html-service.js.map +2 -2
  371. package/dist/lib/html/overlay-config.js +7 -6
  372. package/dist/lib/html/overlay-config.js.map +2 -2
  373. package/dist/lib/html/types.d.ts +29 -2
  374. package/dist/lib/layout/absolute.d.ts +11 -5
  375. package/dist/lib/layout/absolute.js +329 -55
  376. package/dist/lib/layout/absolute.js.map +3 -3
  377. package/dist/lib/layout/allocation-checkpoint-owner.d.ts +11 -0
  378. package/dist/lib/layout/allocation-checkpoint-owner.js +86 -0
  379. package/dist/lib/layout/allocation-checkpoint-owner.js.map +7 -0
  380. package/dist/lib/layout/allocation-checkpoint.d.ts +53 -0
  381. package/dist/lib/layout/allocation-checkpoint.js +463 -0
  382. package/dist/lib/layout/allocation-checkpoint.js.map +7 -0
  383. package/dist/lib/layout/allocation-dependencies.d.ts +30 -0
  384. package/dist/lib/layout/allocation-dependencies.js +90 -0
  385. package/dist/lib/layout/allocation-dependencies.js.map +7 -0
  386. package/dist/lib/layout/allocation-revision.d.ts +13 -0
  387. package/dist/lib/layout/allocation-revision.js +67 -0
  388. package/dist/lib/layout/allocation-revision.js.map +7 -0
  389. package/dist/lib/layout/box-insets.d.ts +17 -0
  390. package/dist/lib/layout/box-insets.js +138 -0
  391. package/dist/lib/layout/box-insets.js.map +7 -0
  392. package/dist/lib/layout/box-sizing.d.ts +16 -0
  393. package/dist/lib/layout/box-sizing.js +77 -0
  394. package/dist/lib/layout/box-sizing.js.map +7 -0
  395. package/dist/lib/layout/box.js +42 -12
  396. package/dist/lib/layout/box.js.map +2 -2
  397. package/dist/lib/layout/canvas-measurement.d.ts +13 -0
  398. package/dist/lib/layout/canvas-measurement.js +57 -0
  399. package/dist/lib/layout/canvas-measurement.js.map +7 -0
  400. package/dist/lib/layout/context.d.ts +35 -6
  401. package/dist/lib/layout/context.js +72 -3
  402. package/dist/lib/layout/context.js.map +2 -2
  403. package/dist/lib/layout/define-layout-component.d.ts +23 -0
  404. package/dist/lib/layout/define-layout-component.js +84 -0
  405. package/dist/lib/layout/define-layout-component.js.map +7 -0
  406. package/dist/lib/layout/flex-allocation-cache.d.ts +42 -0
  407. package/dist/lib/layout/flex-baseline-mode.d.ts +2 -0
  408. package/dist/lib/layout/flex-baseline-mode.js +7 -0
  409. package/dist/lib/layout/flex-baseline-mode.js.map +7 -0
  410. package/dist/lib/layout/flex.d.ts +50 -15
  411. package/dist/lib/layout/flex.js +2124 -195
  412. package/dist/lib/layout/flex.js.map +3 -3
  413. package/dist/lib/layout/flow.js +225 -49
  414. package/dist/lib/layout/flow.js.map +2 -2
  415. package/dist/lib/layout/geometry-publication.d.ts +53 -0
  416. package/dist/lib/layout/geometry-publication.js +244 -0
  417. package/dist/lib/layout/geometry-publication.js.map +7 -0
  418. package/dist/lib/layout/grid-kernel.d.ts +63 -0
  419. package/dist/lib/layout/grid-kernel.js +168 -0
  420. package/dist/lib/layout/grid-kernel.js.map +7 -0
  421. package/dist/lib/layout/grid.d.ts +63 -4
  422. package/dist/lib/layout/grid.js +767 -171
  423. package/dist/lib/layout/grid.js.map +3 -3
  424. package/dist/lib/layout/measure.d.ts +55 -3
  425. package/dist/lib/layout/measure.js +448 -15
  426. package/dist/lib/layout/measure.js.map +2 -2
  427. package/dist/lib/layout/overlay.js +81 -23
  428. package/dist/lib/layout/overlay.js.map +2 -2
  429. package/dist/lib/layout/participation.d.ts +27 -0
  430. package/dist/lib/layout/participation.js +188 -0
  431. package/dist/lib/layout/participation.js.map +7 -0
  432. package/dist/lib/layout/place-child.js +1 -1
  433. package/dist/lib/layout/place-child.js.map +2 -2
  434. package/dist/lib/layout/positioning-diagnostics.d.ts +1 -1
  435. package/dist/lib/layout/positioning-diagnostics.js +13 -2
  436. package/dist/lib/layout/positioning-diagnostics.js.map +2 -2
  437. package/dist/lib/layout/prepared-root.d.ts +121 -0
  438. package/dist/lib/layout/prepared-root.js +360 -0
  439. package/dist/lib/layout/prepared-root.js.map +7 -0
  440. package/dist/lib/layout/standalone-kernel.d.ts +60 -0
  441. package/dist/lib/layout/standalone-kernel.js +722 -0
  442. package/dist/lib/layout/standalone-kernel.js.map +7 -0
  443. package/dist/lib/layout/topology.d.ts +21 -0
  444. package/dist/lib/layout/topology.js +113 -0
  445. package/dist/lib/layout/topology.js.map +7 -0
  446. package/dist/lib/layout/types.d.ts +5 -0
  447. package/dist/lib/layout/wasm/artifact.d.ts +1 -0
  448. package/dist/lib/layout/wasm/artifact.js +5 -0
  449. package/dist/lib/layout/wasm/artifact.js.map +7 -0
  450. package/dist/lib/layout/wasm/bytes.d.ts +1 -0
  451. package/dist/lib/layout/wasm/bytes.js +5 -0
  452. package/dist/lib/layout/wasm/bytes.js.map +7 -0
  453. package/dist/lib/layout/wasm/embedded.d.ts +2 -0
  454. package/dist/lib/layout/wasm/embedded.js +12 -0
  455. package/dist/lib/layout/wasm/embedded.js.map +7 -0
  456. package/dist/lib/layout/wasm/layout.wasm +0 -0
  457. package/dist/lib/layout/wasm/module.d.ts +8 -0
  458. package/dist/lib/layout/wasm/module.js +70 -0
  459. package/dist/lib/layout/wasm/module.js.map +7 -0
  460. package/dist/lib/layout/wasm/region.d.ts +267 -0
  461. package/dist/lib/layout/wasm/region.js +1018 -0
  462. package/dist/lib/layout/wasm/region.js.map +7 -0
  463. package/dist/lib/manipulation/controller.js +4 -7
  464. package/dist/lib/manipulation/controller.js.map +2 -2
  465. package/dist/lib/manipulation/frame.js +1 -1
  466. package/dist/lib/manipulation/frame.js.map +2 -2
  467. package/dist/lib/manipulation/handles.js +32 -33
  468. package/dist/lib/manipulation/handles.js.map +2 -2
  469. package/dist/lib/manipulation/solve.js +12 -10
  470. package/dist/lib/manipulation/solve.js.map +2 -2
  471. package/dist/lib/mount-pibbl.js +1 -0
  472. package/dist/lib/mount-pibbl.js.map +2 -2
  473. package/dist/lib/mount-prepared-pibbl.d.ts +5 -0
  474. package/dist/lib/mount-prepared-pibbl.js +29 -0
  475. package/dist/lib/mount-prepared-pibbl.js.map +7 -0
  476. package/dist/lib/mount-request.d.ts +8 -0
  477. package/dist/lib/mount-request.js +41 -0
  478. package/dist/lib/mount-request.js.map +7 -0
  479. package/dist/lib/pibbl.d.ts +21 -13
  480. package/dist/lib/pibbl.js +18 -16
  481. package/dist/lib/pibbl.js.map +2 -2
  482. package/dist/lib/recording/recording.d.ts +43 -0
  483. package/dist/lib/recording/recording.js +555 -0
  484. package/dist/lib/recording/recording.js.map +7 -0
  485. package/dist/lib/recording/types.d.ts +118 -0
  486. package/dist/lib/recording/wasm-bytes.d.ts +1 -0
  487. package/dist/lib/recording/wasm-bytes.js +5 -0
  488. package/dist/lib/recording/wasm-bytes.js.map +7 -0
  489. package/dist/lib/recording/worker-source.d.ts +1 -0
  490. package/dist/lib/recording/worker-source.js +5 -0
  491. package/dist/lib/recording/worker-source.js.map +7 -0
  492. package/dist/lib/render-layer/controller.d.ts +9 -3
  493. package/dist/lib/render-layer/controller.js +259 -110
  494. package/dist/lib/render-layer/controller.js.map +2 -2
  495. package/dist/lib/render-transaction.d.ts +12 -2
  496. package/dist/lib/render-transaction.js +69 -1
  497. package/dist/lib/render-transaction.js.map +2 -2
  498. package/dist/lib/render.js +32 -8
  499. package/dist/lib/render.js.map +2 -2
  500. package/dist/lib/scheduler/realm-scheduler.d.ts +2 -0
  501. package/dist/lib/scheduler/realm-scheduler.js +55 -26
  502. package/dist/lib/scheduler/realm-scheduler.js.map +2 -2
  503. package/dist/lib/scheduler/renderer-participant.js +1 -0
  504. package/dist/lib/scheduler/renderer-participant.js.map +2 -2
  505. package/dist/lib/series-inspection-frame.d.ts +18 -0
  506. package/dist/lib/series-inspection-frame.js +70 -0
  507. package/dist/lib/series-inspection-frame.js.map +7 -0
  508. package/dist/lib/signals/edge.d.ts +7 -4
  509. package/dist/lib/signals/edge.js +25 -3
  510. package/dist/lib/signals/edge.js.map +2 -2
  511. package/dist/lib/signals/graph.d.ts +16 -2
  512. package/dist/lib/signals/graph.js +54 -12
  513. package/dist/lib/signals/graph.js.map +2 -2
  514. package/dist/lib/signals/input-provision.d.ts +15 -0
  515. package/dist/lib/signals/input-provision.js +53 -3
  516. package/dist/lib/signals/input-provision.js.map +2 -2
  517. package/dist/lib/signals/render-consumer.d.ts +3 -0
  518. package/dist/lib/signals/render-consumer.js +22 -14
  519. package/dist/lib/signals/render-consumer.js.map +2 -2
  520. package/dist/lib/style/positioning.d.ts +50 -2
  521. package/dist/lib/style/positioning.js +28 -4
  522. package/dist/lib/style/positioning.js.map +2 -2
  523. package/dist/lib/style/resolve-built-in.d.ts +4 -3
  524. package/dist/lib/style/resolve-built-in.js +17 -3
  525. package/dist/lib/style/resolve-built-in.js.map +2 -2
  526. package/dist/lib/style/resolve-dispatch.d.ts +3 -0
  527. package/dist/lib/style/resolve-dispatch.js +77 -4
  528. package/dist/lib/style/resolve-dispatch.js.map +2 -2
  529. package/dist/lib/style/resolve-length.d.ts +2 -0
  530. package/dist/lib/style/resolve-length.js +13 -9
  531. package/dist/lib/style/resolve-length.js.map +2 -2
  532. package/dist/lib/style/sizing-length.d.ts +51 -0
  533. package/dist/lib/style/sizing-length.js +77 -0
  534. package/dist/lib/style/sizing-length.js.map +7 -0
  535. package/dist/lib/style/types.d.ts +63 -25
  536. package/dist/lib/surface/root-surface.js +10 -6
  537. package/dist/lib/surface/root-surface.js.map +2 -2
  538. package/dist/lib/textures/texture.js +10 -8
  539. package/dist/lib/textures/texture.js.map +2 -2
  540. package/dist/lib/transitions/capture.js +4 -1
  541. package/dist/lib/transitions/capture.js.map +2 -2
  542. package/dist/lib/transitions/embers-physics.js +17 -10
  543. package/dist/lib/transitions/embers-physics.js.map +2 -2
  544. package/dist/lib/types.d.ts +110 -1
  545. package/dist/sync.d.ts +16 -0
  546. package/dist/sync.js +13 -0
  547. package/dist/sync.js.map +7 -0
  548. package/dist/sync.mjs +1 -0
  549. package/package.json +26 -3
@@ -1,30 +1,67 @@
1
- import { preparedStyleValue, preparedStyleQuery } from "../style/responsive.js";
1
+ import { allocationCheckpointPhaseOwner, retainAllocationCheckpointPhases } from "./allocation-checkpoint-owner.js";
2
+ import { withAllocationCheckpoint, recordAllocationStyle, allocationMeasurement, declineUnrecordedAllocationMeasurement } from "./allocation-checkpoint.js";
3
+ import { contentBoxStyle } from "./box-sizing.js";
4
+ import { canvasMeasurementService, isCurrentCanvasMeasurementService, isGenericCanvasFont } from "./canvas-measurement.js";
5
+ import { Grid } from "./grid.js";
6
+ import { Flow } from "./flow.js";
7
+ import { currentPreparedReceiverSlot, isKnownLayoutType, registerKnownLayoutPreflight, stagePreparedChildStyle, claimPreparedFlexPlan, peekPreparedLayoutPlan, peekPreparedFlexPlan, stagePreparedLayoutPlan, preflightKnownLayout, attachPreparedLayoutSlot, stagePreparedIntrinsicMain, peekPreparedIntrinsicMain, takePreparedIntrinsicMain } from "./prepared-root.js";
8
+ import { isLayoutComponent, prepareLayoutComponent } from "./define-layout-component.js";
9
+ import { allocationInputRevision, allocationStructuralRevision } from "./allocation-revision.js";
10
+ import { FLEX_BASELINE_GROUP, FLEX_LAST_BASELINE } from "./flex-baseline-mode.js";
11
+ import { nativeLayout, LayoutRegion, mountedLayoutRegion, solveTransientFlexMain, prepareTransientIntrinsicMainQueries, resolveTransientIntrinsicMain, resolveTransientKnownOwnerMain, recordWasmMeasurement, recordWasmAllocationPass, recordWasmAllocationItem, recordWasmAllocationCacheHit } from "./wasm/region.js";
12
+ import { Rectangle } from "../components/rect.js";
13
+ import { Text, prepareLayoutTextContent as readLayoutTextContent, measureLayoutTextMinimumWidth, measureLayoutTextNaturalRun } from "../components/text.js";
14
+ const unsupportedProperties = ["order"];
15
+ import { ResponsiveStylePreparation, UnsupportedResponsiveMeasurement, withStyleMeasurement, preparedStyleValue, preparedStyleQuery } from "../style/responsive.js";
2
16
  import { definePrimitive } from "../define-primitive.js";
3
17
  import { clonePibblElement } from "../element/create-element.js";
4
- import { getChildPrimitiveReceiverToken } from "../element/metadata.js";
18
+ import { getChildPrimitiveReceiverToken, getPrimitiveReceiverToken, getPrimitiveDefinition, getPrimitiveProgramProps, getElementMetadata, setElementMetadata } from "../element/metadata.js";
5
19
  import { GLOBAL_STATE } from "../global-state.js";
6
- import { layoutDiagnostic } from "../style/diagnostics.js";
20
+ import { LayoutDiagnostic, layoutDiagnostic } from "../style/diagnostics.js";
7
21
  import {
8
22
  wireStructuralEvents
9
23
  } from "../components/structural-events.js";
10
- import { normalizeEdges } from "../style/normalize.js";
11
- import { resolveLength } from "../style/resolve-length.js";
12
- import { setPreNormalizedStyle } from "../style/resolve-dispatch.js";
24
+ import { normalizeBoxInsets, hasPercentageBoxPadding, resolveAllocatedInsets } from "./box-insets.js";
25
+ import { resolveScalarSizingLength } from "../style/sizing-length.js";
26
+ import { parsePercentage } from "../style/resolve-length.js";
27
+ import { isIntrinsicSizingValue, normalizeSizingLength } from "../style/sizing-length.js";
28
+ import { setPreNormalizedStyle, peekPreNormalizedStyle } from "../style/resolve-dispatch.js";
13
29
  import {
14
30
  childWithUsedSize,
15
31
  prepareDirectChildStyle,
16
32
  materializeLayoutChildren,
17
33
  placeDirectChildren,
18
34
  prepareLayoutChildren,
19
- resolveContainerBox
35
+ resolveContainerBox,
36
+ resolveDirectChildBox
20
37
  } from "./absolute.js";
21
- import { pushLayoutBox } from "./context.js";
38
+ import { getLayoutDirection, getLogicalContainingBox, pushLayoutBox } from "./context.js";
22
39
  import { recordLayoutEvaluation } from "./diagnostics.js";
23
40
  import { assertSupportedChildPosition } from "./positioning-diagnostics.js";
24
- import { measureElement } from "./measure.js";
41
+ import { markDerivedAbsoluteAxes } from "../style/positioning.js";
42
+ import { measureElement, measureConstrainedLayoutChild, measureIntrinsicElement, measureConstrainedIntrinsicElement, measurePreparedLayoutElement, measureBaselineElement, setPreparedBaselineOwner, withIsolatedRenderState } from "./measure.js";
43
+ import { isSignal, withSignalWriteForbidden } from "../signals/graph.js";
44
+ const FLEX_ABSOLUTE_BOX_STYLE = /* @__PURE__ */ Symbol("pibbl.flex-absolute-box-style");
45
+ const FLEX_INHERITED_CONTAINING_BOX = /* @__PURE__ */ Symbol("pibbl.flex-inherited-containing-box");
46
+ const deferredStaticPlans = /* @__PURE__ */ new WeakMap();
47
+ function deferredStaticPlacementSentinel() {
48
+ const fail = () => {
49
+ throw new Error("Deferred static Flex absolute placement was read before finalization.");
50
+ };
51
+ return { get box() {
52
+ return fail();
53
+ }, get layoutY() {
54
+ return fail();
55
+ }, get usedWidth() {
56
+ return fail();
57
+ }, get usedHeight() {
58
+ return fail();
59
+ }, get element() {
60
+ return fail();
61
+ } };
62
+ }
25
63
  function renderFlex(props, style, ctx) {
26
64
  wireStructuralEvents(props);
27
- const children = prepareLayoutChildren(props.children, "Flex");
28
65
  recordLayoutEvaluation();
29
66
  const content = style.box.contentBox;
30
67
  ctx.translate(content.x, content.y);
@@ -34,28 +71,19 @@ function renderFlex(props, style, ctx) {
34
71
  width: content.width,
35
72
  height: content.height
36
73
  });
37
- const releaseLayout = pushLayoutBox(localContent);
74
+ const specified = style[FLEX_ABSOLUTE_BOX_STYLE];
75
+ const releaseLayout = pushLayoutBox(localContent, {
76
+ layoutDirection: style.layoutDirection,
77
+ logicalOffset: content,
78
+ containingBlock: nativeLayout && specified?.position !== "static" ? resolveFlexAbsolutePaddingBox(specified ?? {}, localContent) : void 0
79
+ });
38
80
  GLOBAL_STATE.componentRefs.onAfterRender = releaseLayout;
39
- const service = {
40
- measureText(value, font) {
41
- ctx.save();
42
- try {
43
- ctx.font = font;
44
- return ctx.measureText(value);
45
- } finally {
46
- ctx.restore();
47
- }
48
- }
49
- };
50
- const placements = resolveFlexPlacements(
51
- localContent,
52
- children,
53
- style,
54
- {
55
- service,
56
- measureElement: (element, constraints) => measureElement(element, constraints, service)
57
- }
58
- );
81
+ const service = flexMeasurementService(ctx);
82
+ const prepared = nativeLayout ? claimPreparedFlexPlan(GLOBAL_STATE.componentRefs.element, localContent) : void 0;
83
+ const region = nativeLayout ? mountedLayoutRegion() : void 0;
84
+ const plan = prepared ?? prepareFlexAllocation(props, style, localContent, service, region);
85
+ if (nativeLayout && !prepared) prepareFlexDescendants(plan, style);
86
+ const { children, placements } = plan;
59
87
  let index = 0;
60
88
  return placeDirectChildren(
61
89
  children,
@@ -64,39 +92,395 @@ function renderFlex(props, style, ctx) {
64
92
  style.overflow
65
93
  );
66
94
  }
95
+ function flexMeasurementService(ctx) {
96
+ return canvasMeasurementService(ctx);
97
+ }
98
+ function prepareFlexAllocation(props, style, localContent, service, region, parentSlot, deferStaticAbsolute) {
99
+ const revision = allocationInputRevision();
100
+ const children = prepareLayoutChildren(props.children, "Flex");
101
+ const axis = isRowDirection(style.flexDirection) ? "row" : "column";
102
+ const staged = takePreparedIntrinsicMain(
103
+ GLOBAL_STATE.primitiveReceiverToken,
104
+ children,
105
+ axis,
106
+ axis === "row" ? localContent.width : localContent.height,
107
+ revision
108
+ );
109
+ const placements = withAllocationCheckpoint(region, {
110
+ children,
111
+ content: localContent,
112
+ settings: { style, deferred: !!deferStaticAbsolute },
113
+ flexMargins: true,
114
+ continuation: staged && { axis: staged.axis, contentMain: staged.contentMain, items: staged.items, autoMarginFreeMain: staged.autoMarginFreeMain },
115
+ pending: deferStaticAbsolute && {
116
+ read: (index) => {
117
+ const entry = deferStaticAbsolute[index];
118
+ return entry && { style: entry.style, data: { measured: !!entry.measurement, token: entry.measurementToken } };
119
+ },
120
+ replay: (index, normalized, receiverToken, query, data) => {
121
+ const { measured, token } = data;
122
+ deferStaticAbsolute[index] = {
123
+ sourceIndex: index,
124
+ child: children[index],
125
+ style: normalized,
126
+ receiverToken,
127
+ query,
128
+ measurement: measured ? { service, measureElement: (element, constraints) => measureElement(element, constraints, service) } : void 0,
129
+ measurementToken: token
130
+ };
131
+ return deferredStaticPlacementSentinel();
132
+ }
133
+ },
134
+ onHit: recordWasmAllocationCacheHit,
135
+ calculate: () => resolveFlexPlacements(localContent, children, style, {
136
+ service,
137
+ measureElement: (element, constraints) => measureElement(element, constraints, service)
138
+ }, region, staged, parentSlot, deferStaticAbsolute)
139
+ });
140
+ for (let index = 0; index < placements.length; index++) {
141
+ if (deferStaticAbsolute?.[index]) continue;
142
+ const placement = placements[index];
143
+ attachPreparedLayoutSlot(placement.element, currentPreparedReceiverSlot(getPrimitiveReceiverToken(placement.element)));
144
+ }
145
+ if (region) retainAllocationCheckpointPhases(region, deferStaticAbsolute?.flatMap((entry, index) => entry ? [index] : []) ?? []);
146
+ return { children, placements, revision, content: localContent, cached: false };
147
+ }
67
148
  const Flex = definePrimitive(renderFlex, {
68
149
  childInput: "structural",
69
- resolveStyle: (style, context) => ({
70
- box: resolveContainerBox(style, context, "Flex", "flex"),
71
- overflow: style.overflow ?? "visible",
72
- ...normalizeFlexOptions(style, context.allocation)
73
- }),
74
- measure: (input) => measureFlex(input)
150
+ resolveStyle: (style, context) => {
151
+ const box = resolveContainerBox(style, context, "Flex", "flex");
152
+ return {
153
+ box,
154
+ [FLEX_ABSOLUTE_BOX_STYLE]: style,
155
+ [FLEX_INHERITED_CONTAINING_BOX]: nativeLayout ? getElementMetadata(GLOBAL_STATE.componentRefs.element)?.absoluteContainingBlock : void 0,
156
+ overflow: style.overflow ?? "visible",
157
+ ...normalizeFlexOptions(style, box.contentBox)
158
+ };
159
+ },
160
+ measure: (input) => measureFlex(input),
161
+ measureIntrinsic: (input) => measureFlexIntrinsic(input)
162
+ });
163
+ let allocatedIntrinsicMain;
164
+ let requestedIntrinsicContribution;
165
+ if (nativeLayout) registerKnownLayoutPreflight(Flex, (element, style, content, receiver, slot, parentMainAxis, preflightOptions) => {
166
+ const options = normalizeFlexOptions(style, content);
167
+ const releaseLayout = pushLayoutBox(content, options);
168
+ const previous = GLOBAL_STATE.primitiveReceiverToken;
169
+ GLOBAL_STATE.primitiveReceiverToken = receiver;
170
+ try {
171
+ const children = prepareLayoutChildren(element.props.children, "Flex");
172
+ const axis = isRowDirection(options.flexDirection) ? "row" : "column";
173
+ const main = axis === "row" ? content.width : content.height;
174
+ const contribution = parentMainAxis === axis ? peekPreparedIntrinsicMain(
175
+ receiver,
176
+ children,
177
+ axis,
178
+ main,
179
+ allocationInputRevision()
180
+ ) : void 0;
181
+ if (contribution && !contribution.normalOwner) {
182
+ const ctx2 = GLOBAL_STATE.renderContext;
183
+ if (!ctx2) throw new Error("Known layout preparation requires a Canvas measurement context.");
184
+ const measuredRoot = clonePibblElement(element);
185
+ setPreNormalizedStyle(measuredRoot, contribution.style, element, receiver);
186
+ const previousPhase = allocatedIntrinsicMain;
187
+ allocatedIntrinsicMain = { receiver, main, rootMin: contribution.rootMin, rootMax: contribution.rootMax };
188
+ try {
189
+ const result = measureConstrainedIntrinsicElement(measuredRoot, {
190
+ minWidth: 0,
191
+ maxWidth: content.width,
192
+ minHeight: 0,
193
+ maxHeight: content.height
194
+ }, flexMeasurementService(ctx2));
195
+ if (result.status !== "measured") throw new Error(`Known Flex allocated-owner measurement is unsupported: ${result.reason}`);
196
+ } finally {
197
+ allocatedIntrinsicMain = previousPhase;
198
+ }
199
+ }
200
+ for (let index = 0; index < children.length; index++) {
201
+ const child = children[index];
202
+ const token = getChildPrimitiveReceiverToken(GLOBAL_STATE.renderTransaction, receiver, index);
203
+ let prepared = prepareDirectChildStyle(child, token, content, true);
204
+ const specified = preparedStyleValue(prepared);
205
+ const normalized = resolveAllocatedInsets(specified, { width: content.width, layoutDirection: options.layoutDirection, context: childContext(child, content) });
206
+ if (normalized !== specified) {
207
+ if (prepared instanceof ResponsiveStylePreparation) prepared.style = normalized;
208
+ else prepared = normalized;
209
+ }
210
+ assertSupportedChildPosition("Flex", child, normalized, true);
211
+ rejectUnsupportedItemFields(child, normalized, content);
212
+ nonnegativeFactor(normalized.flexGrow ?? 0, "flexGrow", child, content);
213
+ nonnegativeFactor(normalized.flexShrink ?? 1, "flexShrink", child, content);
214
+ stagePreparedChildStyle(child, token, content, prepared);
215
+ }
216
+ const ctx = GLOBAL_STATE.renderContext;
217
+ if (!ctx) throw new Error("Known layout preparation requires a Canvas measurement context.");
218
+ const region = slot.acquire();
219
+ const resolved = {
220
+ box: { contentBox: content },
221
+ [FLEX_ABSOLUTE_BOX_STYLE]: style,
222
+ [FLEX_INHERITED_CONTAINING_BOX]: getElementMetadata(element)?.absoluteContainingBlock,
223
+ overflow: style.overflow ?? "visible",
224
+ ...normalizeFlexOptions(style, content)
225
+ };
226
+ const deferred = preflightOptions?.deferStaticContainingDescendants ? [] : void 0;
227
+ const plan = prepareFlexAllocation(element.props, resolved, content, flexMeasurementService(ctx), region, slot, deferred);
228
+ const staged = { ...plan, region };
229
+ if (deferred) {
230
+ staged.pending = { kind: "static-flex-containing-origin", count: 1 };
231
+ deferredStaticPlans.set(staged, { slots: deferred, style: resolved });
232
+ prepareFlexDescendants(staged, resolved, slot, true);
233
+ } else prepareFlexDescendants(staged, resolved, slot);
234
+ stagePreparedLayoutPlan(slot, staged);
235
+ } finally {
236
+ GLOBAL_STATE.primitiveReceiverToken = previous;
237
+ releaseLayout();
238
+ }
75
239
  });
240
+ function deferredStaticState(plan) {
241
+ return deferredStaticPlans.get(plan);
242
+ }
243
+ function finalizeDeferredStaticAbsolutePlacements(plan, style) {
244
+ const state = deferredStaticState(plan);
245
+ if (!state) return;
246
+ let paddingBox;
247
+ for (let sourceIndex = 0; sourceIndex < state.slots.length; sourceIndex++) {
248
+ const entry = state.slots[sourceIndex];
249
+ if (!entry) continue;
250
+ if (entry.sourceIndex !== sourceIndex || sourceIndex >= plan.placements.length) throw new Error("Deferred static absolute placement lost source ordering.");
251
+ const containing = paddingBox ??= resolveFlexContainingBox(style, plan.content);
252
+ const owner = plan.region && allocationCheckpointPhaseOwner(plan.region, sourceIndex);
253
+ plan.placements[sourceIndex] = withAllocationCheckpoint(owner, {
254
+ children: [entry.child],
255
+ receiverTokens: [entry.receiverToken],
256
+ content: plan.content,
257
+ settings: { style, containing },
258
+ flexMargins: true,
259
+ onHit: recordWasmAllocationCacheHit,
260
+ calculate: () => {
261
+ if (plan.region) {
262
+ recordWasmAllocationPass();
263
+ recordWasmAllocationItem();
264
+ }
265
+ recordAllocationStyle(entry.receiverToken, entry.query ? new ResponsiveStylePreparation(entry.style, entry.query) : entry.style);
266
+ return [resolveAbsoluteFlexPlacement(
267
+ containing,
268
+ entry.child,
269
+ entry.style,
270
+ entry.receiverToken,
271
+ entry.query,
272
+ plan.content,
273
+ style,
274
+ entry.measurement,
275
+ plan.region,
276
+ entry.measurementToken
277
+ )];
278
+ }
279
+ })[0];
280
+ state.slots[sourceIndex] = void 0;
281
+ }
282
+ }
283
+ function prepareFlexDescendants(plan, style, parentSlot, unresolvedStaticOrigin = false) {
284
+ if (!unresolvedStaticOrigin) finalizeDeferredStaticAbsolutePlacements(plan, style);
285
+ let containingBox;
286
+ let flexOccurrence = 0;
287
+ let descriptionOccurrences;
288
+ for (let index = 0; index < plan.children.length; index++) {
289
+ const child = plan.children[index];
290
+ if (!isKnownLayoutType(child.type) && !isLayoutComponent(child.type)) continue;
291
+ let occurrence = 0;
292
+ if (child.key === void 0) {
293
+ if (child.type === Flex) occurrence = flexOccurrence++;
294
+ else {
295
+ descriptionOccurrences ??= /* @__PURE__ */ new Map();
296
+ occurrence = descriptionOccurrences.get(child.type) ?? 0;
297
+ descriptionOccurrences.set(child.type, occurrence + 1);
298
+ }
299
+ }
300
+ if (deferredStaticState(plan)?.slots[index]) continue;
301
+ const placement = plan.placements[index];
302
+ const prepared = peekPreNormalizedStyle(placement.element);
303
+ if (!prepared) throw new Error("Known layout preparation requires settled receiver inputs.");
304
+ const receiver = getPrimitiveReceiverToken(placement.element);
305
+ if (!receiver) throw new Error("Known layout preparation requires the current child receiver.");
306
+ const preparedRoot = isLayoutComponent(child.type) ? prepareLayoutComponent(child, { receiverToken: receiver }) : child;
307
+ const staticFlexRoot = preparedRoot.type === Flex && prepared.style.position === "static";
308
+ let preparationChild = child;
309
+ const unresolvedStaticChild = unresolvedStaticOrigin && staticFlexRoot;
310
+ if (staticFlexRoot && !unresolvedStaticChild) {
311
+ containingBox ??= resolveFlexContainingBox(style, plan.content);
312
+ const insets = normalizeBoxInsets(prepared.style, childContext(child, plan.content));
313
+ const x = finiteRelativePlacement(containingBox.x - placement.box.x - insets.left, "left", child, plan.content);
314
+ const y = finiteRelativePlacement(containingBox.y - placement.box.y - insets.top, "top", child, plan.content);
315
+ setElementMetadata(placement.element, {
316
+ ...getElementMetadata(placement.element),
317
+ layoutDescriptionSource: getElementMetadata(child)?.layoutDescriptionSource ?? child,
318
+ absoluteContainingBlock: Object.freeze({ x, y, width: containingBox.width, height: containingBox.height })
319
+ });
320
+ preparationChild = placement.element;
321
+ }
322
+ const content = { x: 0, y: 0, width: placement.usedWidth, height: placement.usedHeight };
323
+ const staged = getElementMetadata(placement.element)?.preparedLayoutSlot;
324
+ const current = staged && peekPreparedLayoutPlan(staged, content, prepared.style.layoutDirection ?? style.layoutDirection);
325
+ if (current) {
326
+ if (preparedRoot.type === Flex) {
327
+ const stagedFlex = current;
328
+ const state = deferredStaticState(stagedFlex);
329
+ if (state && !unresolvedStaticOrigin) {
330
+ const inherited = getElementMetadata(placement.element)?.absoluteContainingBlock;
331
+ if (!inherited) throw new Error("Static structural descendants require the settled containing box before finalization.");
332
+ const nestedStyle = { ...state.style, [FLEX_INHERITED_CONTAINING_BOX]: inherited };
333
+ finalizeDeferredStaticAbsolutePlacements(stagedFlex, nestedStyle);
334
+ prepareFlexDescendants(stagedFlex, nestedStyle, staged);
335
+ stagedFlex.pending.count = 0;
336
+ deferredStaticPlans.delete(stagedFlex);
337
+ }
338
+ }
339
+ continue;
340
+ }
341
+ const nested = preflightKnownLayout(
342
+ preparationChild,
343
+ prepared.style,
344
+ content,
345
+ receiver,
346
+ occurrence,
347
+ parentSlot,
348
+ isRowDirection(style.flexDirection) ? "row" : "column",
349
+ unresolvedStaticChild ? { deferStaticContainingDescendants: true } : void 0
350
+ );
351
+ attachPreparedLayoutSlot(placement.element, nested);
352
+ }
353
+ }
354
+ function measureFlexIntrinsic(input) {
355
+ const width = input.constraints.width.kind === "bounded" ? input.constraints.width.max : Number.POSITIVE_INFINITY;
356
+ const height = input.constraints.height.kind === "bounded" ? input.constraints.height.max : Number.POSITIVE_INFINITY;
357
+ const owner = { x: 0, y: 0, width: Number.isFinite(width) ? width : 0, height: Number.isFinite(height) ? height : 0 };
358
+ const row = isRowDirection(input.style.flexDirection);
359
+ const wrap = (input.style.flexWrap ?? "nowrap") !== "nowrap";
360
+ if (isPercentage(input.style.gap) || isPercentage(input.style.columnGap) || isPercentage(input.style.rowGap)) return { status: "unsupported", reason: "Flex intrinsic percentage gaps require a definite owning axis" };
361
+ const options = normalizeFlexOptions(input.style, owner);
362
+ const children = materializeLayoutChildren(input.props.children, "Flex");
363
+ let minMain = 0, maxMain = 0, minCross = 0, maxCross = 0, count = 0;
364
+ for (let index = 0; index < children.length; index++) {
365
+ const child = children[index];
366
+ const receiver = getChildPrimitiveReceiverToken(GLOBAL_STATE.renderTransaction, GLOBAL_STATE.primitiveReceiverToken, index);
367
+ const prepared = prepareDirectChildStyle(child, receiver, owner, true);
368
+ let style = preparedStyleValue(prepared);
369
+ if (style.position === "absolute") continue;
370
+ if (style.boxSizing !== void 0) style = contentBoxStyle(style, { width: owner.width, height: owner.height, mainAxis: row ? "width" : "height", context: childContext(child, owner) });
371
+ if (hasPercentageBoxPadding(style) || isPercentage(style.width) || isPercentage(style.height) || isPercentage(style.flexBasis) || hasPercentageBounds(style)) return { status: "unsupported", reason: "Flex intrinsic percentage child sizes require a definite owning axis" };
372
+ const measuredChild = clonePibblElement(child);
373
+ setPreNormalizedStyle(measuredChild, style, child, receiver, preparedStyleQuery(prepared));
374
+ const measured = typeof style.width === "number" && typeof style.height === "number" ? {
375
+ status: "measured",
376
+ minContent: { width: style.width, height: style.height },
377
+ maxContent: { width: style.width, height: style.height }
378
+ } : measureIntrinsicElement(measuredChild, { minWidth: 0, maxWidth: width, minHeight: 0, maxHeight: height }, input.service);
379
+ if (measured.status !== "measured") return measured;
380
+ const padding = normalizeBoxInsets(style, childContext(child, owner));
381
+ const horizontal = padding.left + padding.right, vertical = padding.top + padding.bottom;
382
+ const marginLeft = style.marginLeft ?? style.margin, marginRight = style.marginRight ?? style.margin;
383
+ const marginTop = style.marginTop ?? style.margin, marginBottom = style.marginBottom ?? style.margin;
384
+ const marginsX = allocatedMargin(marginLeft === "auto" ? 0 : marginLeft, "marginLeft", child, owner) + allocatedMargin(marginRight === "auto" ? 0 : marginRight, "marginRight", child, owner);
385
+ const marginsY = allocatedMargin(marginTop === "auto" ? 0 : marginTop, "marginTop", child, owner) + allocatedMargin(marginBottom === "auto" ? 0 : marginBottom, "marginBottom", child, owner);
386
+ const lowerWidth = intrinsicOptionalNumber(style.minWidth, 0, "minWidth");
387
+ const upperWidth = intrinsicOptionalNumber(style.maxWidth, Number.POSITIVE_INFINITY, "maxWidth");
388
+ const lowerHeight = intrinsicOptionalNumber(style.minHeight, 0, "minHeight");
389
+ const upperHeight = intrinsicOptionalNumber(style.maxHeight, Number.POSITIVE_INFINITY, "maxHeight");
390
+ if (lowerWidth > upperWidth) throw childDiagnostic(child, "minWidth", lowerWidth, owner, "minimum must not exceed maximum");
391
+ if (lowerHeight > upperHeight) throw childDiagnostic(child, "minHeight", lowerHeight, owner, "minimum must not exceed maximum");
392
+ const minimumWidth = clamp(typeof style.width === "number" ? style.width : measured.minContent.width, lowerWidth, upperWidth) + horizontal + marginsX;
393
+ const maximumWidth = clamp(typeof style.width === "number" ? style.width : measured.maxContent.width, lowerWidth, upperWidth) + horizontal + marginsX;
394
+ const minimumHeight = clamp(typeof style.height === "number" ? style.height : measured.minContent.height, lowerHeight, upperHeight) + vertical + marginsY;
395
+ const maximumHeight = clamp(typeof style.height === "number" ? style.height : measured.maxContent.height, lowerHeight, upperHeight) + vertical + marginsY;
396
+ const childMinMain = row ? minimumWidth : minimumHeight, childMaxMain = row ? maximumWidth : maximumHeight;
397
+ const childMinCross = row ? minimumHeight : minimumWidth, childMaxCross = row ? maximumHeight : maximumWidth;
398
+ minMain = wrap ? Math.max(minMain, childMinMain) : minMain + childMinMain;
399
+ maxMain += childMaxMain;
400
+ minCross = wrap ? minCross + childMinCross : Math.max(minCross, childMinCross);
401
+ maxCross = Math.max(maxCross, childMaxCross);
402
+ count++;
403
+ }
404
+ const mainGaps = Math.max(0, count - 1) * (row ? options.columnGap : options.rowGap);
405
+ const crossGaps = Math.max(0, count - 1) * (row ? options.rowGap : options.columnGap);
406
+ if (!wrap) minMain += mainGaps;
407
+ else minCross += crossGaps;
408
+ maxMain += mainGaps;
409
+ return { status: "measured", minContent: { width: Math.max(0, row ? minMain : minCross), height: Math.max(0, row ? minCross : minMain) }, maxContent: { width: Math.max(0, row ? maxMain : maxCross), height: Math.max(0, row ? maxCross : maxMain) } };
410
+ }
411
+ function measureAllocatedFlex(input, children, measuredWidth) {
412
+ const width = resolveMeasuredContainerLength(measuredWidth, input.constraints.maxWidth, "width", input.constraints);
413
+ const height = Number.isFinite(input.constraints.maxHeight) ? input.constraints.maxHeight : 0;
414
+ const region = new LayoutRegion();
415
+ let placements;
416
+ try {
417
+ placements = resolveFlexPlacements({ x: 0, y: 0, width, height }, children, {
418
+ ...input.style,
419
+ alignContent: "flex-start",
420
+ alignItems: input.style.alignItems === void 0 || input.style.alignItems === "stretch" ? "flex-start" : input.style.alignItems
421
+ }, input, region);
422
+ } catch (error) {
423
+ if (error instanceof LayoutDiagnostic && error.message.includes("measurement is required but unsupported:")) return { status: "unsupported", reason: error.message };
424
+ throw error;
425
+ } finally {
426
+ region.dispose();
427
+ }
428
+ let first = Number.POSITIVE_INFINITY, last = Number.NEGATIVE_INFINITY;
429
+ const owner = { x: 0, y: 0, width, height };
430
+ for (let index = 0; index < placements.length; index++) {
431
+ const placement = placements[index];
432
+ const style = peekPreNormalizedStyle(placement.element)?.style;
433
+ if (style.position === "absolute") continue;
434
+ const top = style.marginTop ?? style.margin, bottom = style.marginBottom ?? style.margin;
435
+ const before = top === "auto" ? 0 : allocatedMargin(top, "marginTop", placement.element, owner);
436
+ const after = bottom === "auto" ? 0 : allocatedMargin(bottom, "marginBottom", placement.element, owner);
437
+ first = Math.min(first, placement.layoutY - before);
438
+ last = Math.max(last, placement.layoutY + placement.box.height + after);
439
+ }
440
+ return { status: "measured", size: { width, height: Number.isFinite(first) ? Math.max(0, last - first) : 0 } };
441
+ }
76
442
  function measureFlex(input) {
77
443
  const children = prepareLayoutChildren(input.props.children, "Flex");
78
- const widthDefinite = input.style.width !== void 0 && input.style.width !== "auto";
79
- const heightDefinite = input.style.height !== void 0 && input.style.height !== "auto";
444
+ const phase = allocatedIntrinsicMain;
445
+ if (phase && phase.receiver === GLOBAL_STATE.primitiveReceiverToken) {
446
+ allocatedIntrinsicMain = void 0;
447
+ try {
448
+ const diagnosticBox2 = { x: 0, y: 0, width: input.constraints.maxWidth, height: input.constraints.maxHeight };
449
+ const result = measureStagedNonexactMain(input, children, normalizeFlexOptions(input.style, diagnosticBox2), diagnosticBox2, phase);
450
+ if (result) return result;
451
+ return unsupportedIntrinsic("allocated known-owner continuation no longer matches its measured profile");
452
+ } finally {
453
+ allocatedIntrinsicMain = phase;
454
+ }
455
+ }
456
+ const automaticWidth = input.style.width === void 0 || input.style.width === "auto";
457
+ const exactRowWidth = nativeLayout && automaticWidth && (input.style.flexDirection ?? "row") === "row" && (input.style.flexWrap ?? "nowrap") === "nowrap" && (input.style.layoutDirection ?? getLayoutDirection()) === "ltr" && input.constraints.minWidth === input.constraints.maxWidth && Number.isFinite(input.constraints.maxWidth) && input.constraints.maxWidth >= 0 ? input.constraints.maxWidth : void 0;
458
+ const automaticHeight = input.style.height === void 0 || input.style.height === "auto";
459
+ const exactColumnHeight = nativeLayout && automaticHeight && input.style.flexDirection === "column" && (input.style.flexWrap ?? "nowrap") === "nowrap" && (input.style.layoutDirection ?? getLayoutDirection()) === "ltr" && input.constraints.minHeight === input.constraints.maxHeight && Number.isFinite(input.constraints.maxHeight) && input.constraints.maxHeight >= 0 ? input.constraints.maxHeight : void 0;
460
+ const measuredHeight = exactColumnHeight ?? input.style.height;
461
+ const measuredWidth = exactRowWidth ?? input.style.width;
462
+ const widthDefinite = measuredWidth !== void 0 && measuredWidth !== "auto";
463
+ const heightDefinite = measuredHeight !== void 0 && measuredHeight !== "auto";
80
464
  if (widthDefinite && heightDefinite) {
81
465
  return { status: "measured", size: {
82
466
  width: resolveMeasuredContainerLength(
83
- input.style.width,
467
+ measuredWidth,
84
468
  input.constraints.maxWidth,
85
469
  "width",
86
470
  input.constraints
87
471
  ),
88
472
  height: resolveMeasuredContainerLength(
89
- input.style.height,
473
+ measuredHeight,
90
474
  input.constraints.maxHeight,
91
475
  "height",
92
476
  input.constraints
93
477
  )
94
478
  } };
95
479
  }
96
- if ((input.style.flexWrap ?? "nowrap") !== "nowrap") {
97
- return unsupportedIntrinsic("requires nowrap because wrapped intrinsic sizing is deferred");
98
- }
99
- const row = (input.style.flexDirection ?? "row") === "row";
480
+ const wrappedIntrinsic = (input.style.flexWrap ?? "nowrap") !== "nowrap";
481
+ if (wrappedIntrinsic && !nativeLayout) return unsupportedIntrinsic("requires nowrap because wrapped intrinsic sizing is deferred");
482
+ if (isPercentage(input.style.gap) || isPercentage(input.style.rowGap) || isPercentage(input.style.columnGap)) return unsupportedIntrinsic("does not support percentage gaps without an actual finite content allocation");
483
+ const row = isRowDirection(input.style.flexDirection);
100
484
  const diagnosticBox = {
101
485
  x: 0,
102
486
  y: 0,
@@ -104,19 +488,115 @@ function measureFlex(input) {
104
488
  height: Number.isFinite(input.constraints.maxHeight) ? input.constraints.maxHeight : 0
105
489
  };
106
490
  const options = normalizeFlexOptions(input.style, diagnosticBox);
491
+ const stagedNonexact = measureStagedNonexactMain(input, children, options, diagnosticBox);
492
+ if (stagedNonexact) return stagedNonexact;
493
+ if (wrappedIntrinsic && !(nativeLayout && options.flexDirection === "row" && options.flexWrap === "wrap" && options.layoutDirection === "ltr" && typeof input.style.width === "number" && !heightDefinite)) {
494
+ if (nativeLayout && row && widthDefinite && !heightDefinite) return measureAllocatedFlex(input, children, measuredWidth);
495
+ return unsupportedIntrinsic("wrapped intrinsic height requires a finite main allocation");
496
+ }
497
+ const wrapWidth = wrappedIntrinsic ? resolveMeasuredContainerLength(measuredWidth, input.constraints.maxWidth, "width", input.constraints) : 0;
107
498
  const mainGap = row ? options.columnGap : options.rowGap;
499
+ const measuredRowWidth = nativeLayout && options.flexDirection === "row" && options.flexWrap === "nowrap" && options.layoutDirection === "ltr" && !heightDefinite && typeof measuredWidth === "number" ? resolveMeasuredContainerLength(measuredWidth, input.constraints.maxWidth, "width", input.constraints) : void 0;
500
+ let rowItems;
501
+ if (measuredRowWidth !== void 0) for (let index = 0; index < children.length; index++) {
502
+ const candidate = children[index];
503
+ const root = isLayoutComponent(candidate.type) ? prepareLayoutComponent(candidate, { receiverToken: getChildPrimitiveReceiverToken(
504
+ GLOBAL_STATE.renderTransaction,
505
+ GLOBAL_STATE.primitiveReceiverToken,
506
+ index
507
+ ) }) : candidate;
508
+ const definition = getPrimitiveDefinition(root.type);
509
+ if (root.type !== Text && definition?.measureIntrinsic && definition.measure) {
510
+ rowItems = [];
511
+ break;
512
+ }
513
+ }
514
+ let requiresSolvedCross = false;
515
+ let lineMain = 0, lineCross = 0, lineItems = 0, wrappedHeight = 0;
108
516
  let intrinsicMain = 0;
109
517
  let intrinsicCross = 0;
110
518
  let count = 0;
111
- for (const child of children) {
519
+ for (let sourceIndex = 0; sourceIndex < children.length; sourceIndex++) {
520
+ const child = children[sourceIndex];
112
521
  const receiverToken = getChildPrimitiveReceiverToken(
113
522
  GLOBAL_STATE.renderTransaction,
114
523
  GLOBAL_STATE.primitiveReceiverToken,
115
- count
524
+ sourceIndex
116
525
  );
117
- const prepared = prepareDirectChildStyle(child, receiverToken, diagnosticBox);
118
- const style = preparedStyleValue(prepared);
526
+ const prepared = prepareDirectChildStyle(child, receiverToken, diagnosticBox, true);
527
+ let style = preparedStyleValue(prepared);
528
+ if (nativeLayout) {
529
+ validateIntrinsicBound(style.minWidth, "minWidth", child, diagnosticBox);
530
+ validateIntrinsicBound(style.maxWidth, "maxWidth", child, diagnosticBox);
531
+ validateIntrinsicBound(style.minHeight, "minHeight", child, diagnosticBox);
532
+ validateIntrinsicBound(style.maxHeight, "maxHeight", child, diagnosticBox);
533
+ }
534
+ if (hasPercentageBoxPadding(style, options.layoutDirection)) return unsupportedIntrinsic("does not support percentage padding without an actual finite Flex allocation");
535
+ if (style.position === "absolute") {
536
+ if (nativeLayout && wrappedIntrinsic && row && widthDefinite && !heightDefinite) return measureAllocatedFlex(input, children, measuredWidth);
537
+ return unsupportedIntrinsic("does not support absolute children during intrinsic Flex measurement");
538
+ }
539
+ if (nativeLayout && (style.paddingStart !== void 0 || style.paddingEnd !== void 0 || style.borderStartWidth !== void 0 || style.borderEndWidth !== void 0)) style = resolveAllocatedInsets(style, { width: diagnosticBox.width, layoutDirection: options.layoutDirection, context: childContext(child, diagnosticBox) });
540
+ const layoutChild = isLayoutComponent(child.type) ? prepareLayoutComponent(child, { receiverToken }) : child;
541
+ const layoutReceiverToken = getPrimitiveReceiverToken(layoutChild) ?? receiverToken;
542
+ const settledColumnChild = nativeLayout && !row && typeof input.style.width === "number" && !heightDefinite && (child.type === Text || layoutChild.type === Flow || layoutChild.type === Grid || layoutChild.type === Flex && isColumnDirection(style.flexDirection) && (style.flexWrap ?? "nowrap") === "nowrap");
543
+ if (settledColumnChild && (isPercentage(style.width) || isPercentage(style.minWidth) || isPercentage(style.maxWidth))) {
544
+ if (isPercentage(style.height) || isPercentage(style.flexBasis) || isPercentage(style.minHeight) || isPercentage(style.maxHeight)) return unsupportedIntrinsic("does not support percentage child main sizes or bounds");
545
+ const reference = resolveMeasuredContainerLength(measuredWidth, input.constraints.maxWidth, "width", input.constraints);
546
+ const context = childContext(child, diagnosticBox);
547
+ style = {
548
+ ...style,
549
+ width: isPercentage(style.width) ? resolveScalarSizingLength(style.width, reference, "width", context) : style.width,
550
+ minWidth: isPercentage(style.minWidth) ? resolveScalarSizingLength(style.minWidth, reference, "minWidth", context) : style.minWidth,
551
+ maxWidth: isPercentage(style.maxWidth) ? resolveScalarSizingLength(style.maxWidth, reference, "maxWidth", context) : style.maxWidth
552
+ };
553
+ }
554
+ if (nativeLayout && automaticWidth && options.flexDirection === "row" && options.flexWrap === "nowrap" && options.layoutDirection === "ltr" && (isPercentage(style.minWidth) || isPercentage(style.maxWidth))) {
555
+ if (exactRowWidth === void 0) return unsupportedIntrinsic("requires an exact finite row width to resolve percentage main bounds");
556
+ const context = childContext(child, diagnosticBox);
557
+ style = {
558
+ ...style,
559
+ minWidth: isPercentage(style.minWidth) ? resolveScalarSizingLength(style.minWidth, exactRowWidth, "minWidth", context) : style.minWidth,
560
+ maxWidth: isPercentage(style.maxWidth) ? resolveScalarSizingLength(style.maxWidth, exactRowWidth, "maxWidth", context) : style.maxWidth
561
+ };
562
+ if (typeof style.minWidth === "number" && typeof style.maxWidth === "number" && style.minWidth > style.maxWidth) {
563
+ throw childDiagnostic(child, "minWidth", style.minWidth, diagnosticBox, "minimum must not exceed maximum");
564
+ }
565
+ }
566
+ if (nativeLayout && automaticHeight && options.flexDirection === "column" && options.flexWrap === "nowrap" && options.layoutDirection === "ltr" && (isPercentage(style.minHeight) || isPercentage(style.maxHeight))) {
567
+ if (exactColumnHeight === void 0) return unsupportedIntrinsic("requires an exact finite column height to resolve percentage main bounds");
568
+ const context = childContext(child, diagnosticBox);
569
+ style = {
570
+ ...style,
571
+ minHeight: isPercentage(style.minHeight) ? resolveScalarSizingLength(style.minHeight, exactColumnHeight, "minHeight", context) : style.minHeight,
572
+ maxHeight: isPercentage(style.maxHeight) ? resolveScalarSizingLength(style.maxHeight, exactColumnHeight, "maxHeight", context) : style.maxHeight
573
+ };
574
+ if (typeof style.minHeight === "number" && typeof style.maxHeight === "number" && style.minHeight > style.maxHeight) {
575
+ throw childDiagnostic(child, "minHeight", style.minHeight, diagnosticBox, "minimum must not exceed maximum");
576
+ }
577
+ }
578
+ if (style.boxSizing !== void 0) style = contentBoxStyle(style, { width: diagnosticBox.width, height: diagnosticBox.height, mainAxis: row ? "width" : "height", context: childContext(child, diagnosticBox) });
119
579
  rejectUnsupportedItemFields(child, style, diagnosticBox);
580
+ if (style.aspectRatio !== void 0) return unsupportedIntrinsic("does not support aspectRatio during intrinsic measurement");
581
+ const marginDirection = layoutChild.type === Flex ? style.layoutDirection ?? options.layoutDirection : options.layoutDirection;
582
+ const logicalLeft = marginDirection === "rtl" ? style.marginEnd : style.marginStart;
583
+ const logicalRight = marginDirection === "rtl" ? style.marginStart : style.marginEnd;
584
+ const leftValue = logicalLeft !== void 0 ? logicalLeft : style.marginLeft === void 0 ? style.margin : style.marginLeft;
585
+ const rightValue = logicalRight !== void 0 ? logicalRight : style.marginRight === void 0 ? style.margin : style.marginRight;
586
+ const topValue = style.marginTop === void 0 ? style.margin : style.marginTop;
587
+ const bottomValue = style.marginBottom === void 0 ? style.margin : style.marginBottom;
588
+ const hasLogicalMargin = style.marginStart !== void 0 || style.marginEnd !== void 0;
589
+ if (!hasLogicalMargin && isPercentage(style.margin) || isPercentage(topValue) || isPercentage(rightValue) || isPercentage(bottomValue) || isPercentage(leftValue)) return unsupportedIntrinsic("does not support percentage margins without an actual finite Flex allocation");
590
+ const autoTop = topValue === "auto", autoRight = rightValue === "auto";
591
+ const autoBottom = bottomValue === "auto", autoLeft = leftValue === "auto";
592
+ if (!nativeLayout && (autoTop || autoRight || autoBottom || autoLeft)) return unsupportedIntrinsic("automatic margins require the experimental layout engine");
593
+ if (!hasLogicalMargin) numericMargin(nativeLayout && style.margin === "auto" ? 0 : style.margin, "margin", child, diagnosticBox);
594
+ const marginTop = numericMargin(autoTop ? 0 : topValue, "marginTop", child, diagnosticBox);
595
+ const marginRight = numericMargin(autoRight ? 0 : rightValue, logicalRight !== void 0 ? marginDirection === "rtl" ? "marginStart" : "marginEnd" : "marginRight", child, diagnosticBox);
596
+ const marginBottom = numericMargin(autoBottom ? 0 : bottomValue, "marginBottom", child, diagnosticBox);
597
+ const marginLeft = numericMargin(autoLeft ? 0 : leftValue, logicalLeft !== void 0 ? marginDirection === "rtl" ? "marginEnd" : "marginStart" : "marginLeft", child, diagnosticBox);
598
+ const marginMain = row ? marginLeft + marginRight : marginTop + marginBottom;
599
+ const marginCross = row ? marginTop + marginBottom : marginLeft + marginRight;
120
600
  const grow = nonnegativeFactor(
121
601
  style.flexGrow ?? 0,
122
602
  "flexGrow",
@@ -124,6 +604,7 @@ function measureFlex(input) {
124
604
  diagnosticBox
125
605
  );
126
606
  if (grow !== 0) {
607
+ if (nativeLayout && wrappedIntrinsic && row && widthDefinite && !heightDefinite) return measureAllocatedFlex(input, children, measuredWidth);
127
608
  return unsupportedIntrinsic("does not support flexGrow during intrinsic measurement");
128
609
  }
129
610
  const shrink = nonnegativeFactor(
@@ -133,10 +614,12 @@ function measureFlex(input) {
133
614
  diagnosticBox
134
615
  );
135
616
  const basis = style.flexBasis ?? "auto";
617
+ if (wrappedIntrinsic && (!hasEmptyRectangleMinimum(child, style, preparedStyleQuery(prepared)) || shrink !== 0 || basis !== "auto")) return measureAllocatedFlex(input, children, measuredWidth);
136
618
  const mainProperty = row ? "width" : "height";
137
619
  const crossProperty = row ? "height" : "width";
138
620
  const minimumProperty = row ? "minWidth" : "minHeight";
139
- if ((shrink > 0 || basis === "auto") && style[minimumProperty] === void 0) {
621
+ if ((shrink > 0 || basis === "auto") && style[minimumProperty] === void 0 && !hasEmptyRectangleMinimum(child, style, preparedStyleQuery(prepared))) {
622
+ if (nativeLayout && row && widthDefinite && !heightDefinite && getPrimitiveDefinition(layoutChild.type)?.measureIntrinsic) return measureAllocatedFlex(input, children, measuredWidth);
140
623
  throw childDiagnostic(
141
624
  child,
142
625
  minimumProperty,
@@ -150,14 +633,63 @@ function measureFlex(input) {
150
633
  if (isPercentage(mainValue) || isPercentage(crossValue) || hasPercentageBounds(style)) {
151
634
  return unsupportedIntrinsic("does not support percentage child sizes or bounds");
152
635
  }
153
- if (mainValue === void 0 || mainValue === "auto") {
154
- return unsupportedIntrinsic("requires a definite child basis; measured auto basis is deferred");
155
- }
156
- if (crossValue === void 0 || crossValue === "auto") {
157
- return unsupportedIntrinsic("requires a definite child cross size");
636
+ let baseMain;
637
+ let baseCross;
638
+ const provider = rowItems && layoutChild.type !== Text ? getPrimitiveDefinition(layoutChild.type) : void 0;
639
+ const measureCross = !!rowItems && !!provider?.measureIntrinsic && !!provider.measure && (crossValue === void 0 || crossValue === "auto");
640
+ if (rowItems && preparedStyleQuery(prepared)) return unsupportedIntrinsic("does not support responsive child queries during solved row measurement");
641
+ if (nativeLayout && layoutChild.type === Flex && (style.flexDirection ?? "row") === options.flexDirection && options.flexWrap === "nowrap" && (style.flexWrap ?? "nowrap") === "nowrap" && options.layoutDirection === "ltr" && (style.layoutDirection ?? "ltr") === "ltr" && (mainValue === void 0 || mainValue === "auto") && typeof crossValue === "number" && Number.isFinite(crossValue) && crossValue >= 0 && grow === 0 && shrink === 0) {
642
+ const measuredChild = clonePibblElement(layoutChild);
643
+ setPreNormalizedStyle(measuredChild, style, layoutChild, layoutReceiverToken, preparedStyleQuery(prepared));
644
+ const previousContribution = requestedIntrinsicContribution;
645
+ requestedIntrinsicContribution = { receiver: layoutReceiverToken, axis: row ? "row" : "column" };
646
+ let result;
647
+ try {
648
+ result = input.measureElement(measuredChild, row ? {
649
+ minWidth: 0,
650
+ maxWidth: input.constraints.maxWidth,
651
+ minHeight: crossValue,
652
+ maxHeight: crossValue
653
+ } : {
654
+ minWidth: crossValue,
655
+ maxWidth: crossValue,
656
+ minHeight: 0,
657
+ maxHeight: input.constraints.maxHeight
658
+ });
659
+ } finally {
660
+ requestedIntrinsicContribution = previousContribution;
661
+ }
662
+ if (result.status !== "measured") return result;
663
+ baseMain = row ? result.size.width : result.size.height;
664
+ baseCross = crossValue;
665
+ } else if (nativeLayout && !row && widthDefinite && !heightDefinite && (child.type === Text || layoutChild.type === Flow || layoutChild.type === Grid || layoutChild.type === Flex && isColumnDirection(style.flexDirection) && (style.flexWrap ?? "nowrap") === "nowrap") && (mainValue === void 0 || mainValue === "auto" || crossValue === void 0 || crossValue === "auto")) {
666
+ const padding2 = normalizeBoxInsets(style, childContext(child, diagnosticBox));
667
+ const automaticWidth2 = crossValue === void 0 || crossValue === "auto";
668
+ if (automaticWidth2 && effectiveAlignment(normalizeItemAlignment(style.alignSelf, child, diagnosticBox), options.alignItems) !== "stretch") {
669
+ return unsupportedIntrinsic("requires stretch or a definite child width in an auto-height column");
670
+ }
671
+ const availableWidth = resolveMeasuredContainerLength(measuredWidth, input.constraints.maxWidth, "width", input.constraints);
672
+ const minWidth = intrinsicOptionalNumber(style.minWidth, 0, "minWidth");
673
+ const maxWidth = intrinsicOptionalNumber(style.maxWidth, Number.POSITIVE_INFINITY, "maxWidth");
674
+ if (minWidth > maxWidth) throw childDiagnostic(child, "minWidth", minWidth, diagnosticBox, "minimum must not exceed maximum");
675
+ const usedWidth = clamp(automaticWidth2 ? Math.max(0, availableWidth - padding2.left - padding2.right - marginCross) : intrinsicNumber(crossValue, "width"), minWidth, maxWidth);
676
+ const measuredChild = clonePibblElement(layoutChild);
677
+ const measuredStyle = { ...style, width: usedWidth };
678
+ setPreNormalizedStyle(measuredChild, measuredStyle, layoutChild, getPrimitiveReceiverToken(layoutChild) ?? receiverToken, preparedStyleQuery(prepared));
679
+ const result = input.measureElement(measuredChild, { minWidth: 0, maxWidth: usedWidth, minHeight: 0, maxHeight: input.constraints.maxHeight });
680
+ if (result.status !== "measured") return result;
681
+ baseMain = mainValue === void 0 || mainValue === "auto" ? result.size.height : intrinsicNumber(mainValue, "flexBasis");
682
+ baseCross = usedWidth;
683
+ } else {
684
+ if (mainValue === void 0 || mainValue === "auto") {
685
+ return unsupportedIntrinsic("requires a definite child basis; measured auto basis is deferred");
686
+ }
687
+ if ((crossValue === void 0 || crossValue === "auto") && !measureCross) {
688
+ return unsupportedIntrinsic("requires a definite child cross size");
689
+ }
690
+ baseMain = intrinsicNumber(mainValue, "flexBasis");
691
+ baseCross = measureCross ? 0 : intrinsicNumber(crossValue, crossProperty);
158
692
  }
159
- const baseMain = intrinsicNumber(mainValue, "flexBasis");
160
- const baseCross = intrinsicNumber(crossValue, crossProperty);
161
693
  const minMain = intrinsicOptionalNumber(style[minimumProperty], 0, minimumProperty);
162
694
  const maxMainProperty = row ? "maxWidth" : "maxHeight";
163
695
  const maxMain = intrinsicOptionalNumber(
@@ -173,38 +705,233 @@ function measureFlex(input) {
173
705
  Number.POSITIVE_INFINITY,
174
706
  maxCrossProperty
175
707
  );
176
- const padding = normalizeEdges(
177
- style.padding,
178
- "padding",
179
- childContext(child, diagnosticBox)
180
- );
708
+ const padding = normalizeBoxInsets(style, childContext(child, diagnosticBox));
181
709
  const paddingMain = row ? padding.left + padding.right : padding.top + padding.bottom;
182
710
  const paddingCross = row ? padding.top + padding.bottom : padding.left + padding.right;
183
- intrinsicMain += clamp(baseMain, minMain, maxMain) + paddingMain;
184
- intrinsicCross = Math.max(
185
- intrinsicCross,
186
- clamp(baseCross, minCross, maxCross) + paddingCross
187
- );
711
+ if (wrappedIntrinsic) {
712
+ const outerMain = clamp(baseMain, minMain, maxMain) + paddingMain + marginLeft + marginRight;
713
+ const crossExtent = clamp(baseCross, minCross, maxCross) + paddingCross + marginTop + marginBottom;
714
+ const nextMain = lineMain + (lineItems > 0 ? mainGap : 0) + outerMain;
715
+ if (!Number.isFinite(outerMain) || !Number.isFinite(crossExtent)) throw childDiagnostic(child, "intrinsicLine", nextMain, diagnosticBox, "wrapped intrinsic outer extents and line widths must remain finite");
716
+ const outerCross = Math.max(0, crossExtent);
717
+ if (lineItems > 0 && nextMain > wrapWidth) {
718
+ wrappedHeight += lineCross + options.rowGap;
719
+ if (!Number.isFinite(wrappedHeight)) throw childDiagnostic(child, "intrinsicLine", wrappedHeight, diagnosticBox, "wrapped intrinsic accumulated height must remain finite");
720
+ lineCross = 0;
721
+ lineItems = 0;
722
+ }
723
+ lineMain = lineItems > 0 ? nextMain : outerMain;
724
+ if (!Number.isFinite(lineMain)) throw childDiagnostic(child, "intrinsicLine", lineMain, diagnosticBox, "wrapped intrinsic accumulated line width must remain finite");
725
+ lineCross = Math.max(lineCross, outerCross);
726
+ lineItems++;
727
+ }
728
+ if (rowItems) {
729
+ rowItems.push({
730
+ sourceIndex,
731
+ child,
732
+ measuredChild: layoutChild,
733
+ style,
734
+ receiverToken: layoutReceiverToken,
735
+ measureCross,
736
+ baseMain,
737
+ minMain,
738
+ maxMain,
739
+ paddingMain,
740
+ grow,
741
+ shrink,
742
+ marginMainBefore: marginLeft,
743
+ marginMainAfter: marginRight,
744
+ baseCross,
745
+ minCross,
746
+ maxCross,
747
+ paddingCross,
748
+ marginCross
749
+ });
750
+ if (measureCross) requiresSolvedCross = true;
751
+ } else {
752
+ intrinsicMain += clamp(baseMain, minMain, maxMain) + paddingMain + marginMain;
753
+ intrinsicCross = Math.max(
754
+ intrinsicCross,
755
+ clamp(baseCross, minCross, maxCross) + paddingCross + marginCross
756
+ );
757
+ }
188
758
  count++;
189
759
  }
190
- intrinsicMain += Math.max(0, count - 1) * mainGap;
760
+ if (rowItems) {
761
+ const targets = requiresSolvedCross ? solveTransientFlexMain(rowItems, measuredRowWidth, mainGap) : void 0;
762
+ for (let index = 0; index < rowItems.length; index++) {
763
+ const item = rowItems[index];
764
+ const main = targets ? targets[index] : clamp(item.baseMain, item.minMain, item.maxMain);
765
+ let cross = item.baseCross;
766
+ if (item.measureCross) {
767
+ const measuredChild = clonePibblElement(item.measuredChild);
768
+ const measuredStyle = { ...item.style, width: main };
769
+ setPreNormalizedStyle(measuredChild, measuredStyle, item.child, item.receiverToken);
770
+ const result = measureConstrainedLayoutChild(measuredChild, {
771
+ minWidth: main,
772
+ maxWidth: main,
773
+ minHeight: 0,
774
+ maxHeight: Number.POSITIVE_INFINITY
775
+ }, item.sourceIndex);
776
+ if (result.status !== "measured") return result;
777
+ cross = result.size.height;
778
+ }
779
+ intrinsicMain += main + item.paddingMain + item.marginMainBefore + item.marginMainAfter;
780
+ intrinsicCross = Math.max(
781
+ intrinsicCross,
782
+ clamp(cross, item.minCross, item.maxCross) + item.paddingCross + item.marginCross
783
+ );
784
+ }
785
+ }
786
+ intrinsicMain = Math.max(0, intrinsicMain + Math.max(0, count - 1) * mainGap);
191
787
  return { status: "measured", size: {
192
788
  width: widthDefinite ? resolveMeasuredContainerLength(
193
- input.style.width,
789
+ measuredWidth,
194
790
  input.constraints.maxWidth,
195
791
  "width",
196
792
  input.constraints
197
793
  ) : row ? intrinsicMain : intrinsicCross,
198
794
  height: heightDefinite ? resolveMeasuredContainerLength(
199
- input.style.height,
795
+ measuredHeight,
200
796
  input.constraints.maxHeight,
201
797
  "height",
202
798
  input.constraints
203
- ) : row ? intrinsicCross : intrinsicMain
799
+ ) : row ? wrappedIntrinsic ? wrappedHeight + lineCross : intrinsicCross : intrinsicMain
204
800
  } };
205
801
  }
802
+ function intrinsicMainLength(value, property, child, box) {
803
+ if (value === void 0) return { unit: "none" };
804
+ if (typeof value === "number" && Number.isFinite(value) && value >= 0) return { value, unit: "point" };
805
+ if (isPercentage(value)) return { value: parsePercentage(value, property, childContext(child, box)), unit: "percent" };
806
+ return void 0;
807
+ }
808
+ function measureStagedNonexactMain(input, children, options, diagnosticBox, allocated) {
809
+ if (!nativeLayout || options.flexWrap !== "nowrap" || options.layoutDirection !== "ltr") return;
810
+ if (options.flexDirection !== "row" && options.flexDirection !== "column") return;
811
+ const row = options.flexDirection === "row";
812
+ const automaticMain = row ? input.style.width === void 0 || input.style.width === "auto" : input.style.height === void 0 || input.style.height === "auto";
813
+ const cross = row ? input.style.height : input.style.width;
814
+ const available = row ? input.constraints.maxWidth : input.constraints.maxHeight;
815
+ const ownerReference = Number.isFinite(available) ? available : void 0;
816
+ const rootMin = allocated ? allocated.rootMin : intrinsicOwnerBound(
817
+ row ? input.style.minWidth : input.style.minHeight,
818
+ ownerReference,
819
+ row ? "minWidth" : "minHeight",
820
+ input.constraints
821
+ );
822
+ const rootMax = allocated ? allocated.rootMax : intrinsicOwnerBound(
823
+ row ? input.style.maxWidth : input.style.maxHeight,
824
+ ownerReference,
825
+ row ? "maxWidth" : "maxHeight",
826
+ input.constraints
827
+ );
828
+ if (input.style.padding !== void 0 || input.style.paddingStart !== void 0 || input.style.paddingEnd !== void 0 || input.style.borderWidth !== void 0 || input.style.borderStartWidth !== void 0 || input.style.borderEndWidth !== void 0 || input.style.boxSizing !== void 0 || input.style.aspectRatio !== void 0 || (row ? input.style.minHeight !== void 0 && input.style.minHeight !== 0 || input.style.maxHeight !== void 0 : input.style.minWidth !== void 0 && input.style.minWidth !== 0 || input.style.maxWidth !== void 0)) return;
829
+ if (!automaticMain || typeof cross !== "number" || !Number.isFinite(cross) || cross < 0 || rootMin !== void 0 && (typeof rootMin !== "number" || !Number.isFinite(rootMin) || rootMin < 0) || rootMax !== void 0 && (typeof rootMax !== "number" || !Number.isFinite(rootMax) || rootMax < 0) || typeof input.style.gap === "number" && input.style.gap !== 0 || input.style.rowGap !== void 0 || input.style.columnGap !== void 0) return;
830
+ if (typeof rootMin === "number" && typeof rootMax === "number" && rootMin > rootMax) {
831
+ throw layoutDiagnostic({ component: "Flex", property: row ? "minWidth" : "minHeight", value: rootMin, algorithm: "measurement", constraints: input.constraints, reason: "minimum must not exceed maximum" });
832
+ }
833
+ const externalOwner = allocated?.main ?? ownerReference;
834
+ const initialAvailable = allocated?.main ?? (typeof rootMax === "number" ? rootMax : externalOwner);
835
+ const mode = allocated !== void 0 ? "exact" : initialAvailable === void 0 ? "max-content" : "fit-content";
836
+ let hasPercentageBound = false;
837
+ const items = [];
838
+ const measuredLeaves = [];
839
+ for (let sourceIndex = 0; sourceIndex < children.length; sourceIndex++) {
840
+ const child = children[sourceIndex];
841
+ const definition = getPrimitiveDefinition(child.type);
842
+ const pairedMeasuredLeaf = child.type !== Rectangle && child.type !== Text && !isKnownLayoutType(child.type) && !Object.hasOwn(child.props, "children") && !!definition?.measureIntrinsic && !!definition.measure;
843
+ if (!pairedMeasuredLeaf && (child.type !== Rectangle || Object.hasOwn(child.props, "children")) || !child.props.style || typeof child.props.style !== "object" || isSignal(child.props.style)) return;
844
+ const receiver2 = getChildPrimitiveReceiverToken(GLOBAL_STATE.renderTransaction, GLOBAL_STATE.primitiveReceiverToken, sourceIndex);
845
+ const prepared = prepareDirectChildStyle(child, receiver2, diagnosticBox, true);
846
+ const style = preparedStyleValue(prepared);
847
+ validateIntrinsicBound(style.minWidth, "minWidth", child, diagnosticBox);
848
+ validateIntrinsicBound(style.maxWidth, "maxWidth", child, diagnosticBox);
849
+ validateIntrinsicBound(style.minHeight, "minHeight", child, diagnosticBox);
850
+ validateIntrinsicBound(style.maxHeight, "maxHeight", child, diagnosticBox);
851
+ const main = row ? style.width : style.height;
852
+ const basis = style.flexBasis ?? "auto";
853
+ const childCross = row ? style.height : style.width;
854
+ const min = row ? style.minWidth : style.minHeight;
855
+ const max = row ? style.maxWidth : style.maxHeight;
856
+ const automaticMeasuredMain = main === void 0 || main === "auto";
857
+ if (preparedStyleQuery(prepared) || style.position !== void 0 || style.aspectRatio !== void 0 || pairedMeasuredLeaf && (row ? style.minHeight !== void 0 && style.minHeight !== 0 || style.maxHeight !== void 0 : style.minWidth !== void 0 && style.minWidth !== 0 || style.maxWidth !== void 0) || typeof childCross !== "number" || !Number.isFinite(childCross) || childCross < 0 || (style.flexGrow ?? 0) !== 0 || (style.flexShrink ?? 1) !== 0 || !zeroIntrinsicMargin(style.margin) || !zeroIntrinsicMargin(style.marginTop) || !zeroIntrinsicMargin(style.marginRight) || !zeroIntrinsicMargin(style.marginBottom) || !zeroIntrinsicMargin(style.marginLeft) || !zeroIntrinsicMargin(style.marginStart) || !zeroIntrinsicMargin(style.marginEnd) || style.padding !== void 0 || style.paddingStart !== void 0 || style.paddingEnd !== void 0 || style.borderWidth !== void 0 || style.borderStartWidth !== void 0 || style.borderEndWidth !== void 0 || (pairedMeasuredLeaf ? !automaticMeasuredMain || basis !== "auto" : typeof main !== "number" || !Number.isFinite(main) || main < 0 || typeof basis !== "number" || !Number.isFinite(basis) || basis < 0 || main !== basis)) return;
858
+ const intrinsicMin = intrinsicMainLength(min, row ? "minWidth" : "minHeight", child, diagnosticBox);
859
+ const intrinsicMax = intrinsicMainLength(max, row ? "maxWidth" : "maxHeight", child, diagnosticBox);
860
+ if (!intrinsicMin || !intrinsicMax) return;
861
+ if (intrinsicMin.unit === "percent" || intrinsicMax.unit === "percent") hasPercentageBound = true;
862
+ items.push({ base: pairedMeasuredLeaf ? 0 : basis, min: intrinsicMin, max: intrinsicMax, measured: pairedMeasuredLeaf || void 0 });
863
+ if (pairedMeasuredLeaf) measuredLeaves.push({ sourceIndex, child, normalized: style, receiver: receiver2, query: preparedStyleQuery(prepared) });
864
+ }
865
+ if (!items.length || !hasPercentageBound) return;
866
+ const intrinsicQuery = {
867
+ externalOwner,
868
+ initialAvailable,
869
+ rootMin,
870
+ rootMax,
871
+ mode,
872
+ gap: 0
873
+ };
874
+ if (measuredLeaves.length) {
875
+ const preparedQueries = prepareTransientIntrinsicMainQueries(items, intrinsicQuery);
876
+ for (let index = 0; index < measuredLeaves.length; index++) {
877
+ const leaf = measuredLeaves[index];
878
+ const queryMaximum = preparedQueries.maximums[leaf.sourceIndex];
879
+ const measurementChild = clonePibblElement(leaf.child);
880
+ setPreNormalizedStyle(measurementChild, leaf.normalized, leaf.child, leaf.receiver, leaf.query);
881
+ const leafCross = row ? leaf.normalized.height : leaf.normalized.width;
882
+ const constraints = row ? { minWidth: 0, maxWidth: queryMaximum, minHeight: leafCross, maxHeight: leafCross } : { minWidth: leafCross, maxWidth: leafCross, minHeight: 0, maxHeight: queryMaximum };
883
+ const result = measureConstrainedLayoutChild(measurementChild, constraints);
884
+ if (result.status === "unsupported") return result;
885
+ const natural = row ? result.size.width : result.size.height;
886
+ if (!Number.isFinite(natural) || natural < 0) throw new Error("Experimental staged intrinsic Flex provider returned an invalid main size.");
887
+ items[leaf.sourceIndex] = { ...items[leaf.sourceIndex], base: natural, measured: true, queryMaximum };
888
+ }
889
+ }
890
+ const receiver = GLOBAL_STATE.primitiveReceiverToken;
891
+ const axis = row ? "row" : "column";
892
+ const contribution = allocated === void 0 && requestedIntrinsicContribution !== void 0 && requestedIntrinsicContribution.receiver === receiver && requestedIntrinsicContribution.axis === axis;
893
+ const normalOwner = contribution && requestedIntrinsicContribution?.normalOwner === true && !measuredLeaves.length && externalOwner !== void 0 && Number.isFinite(externalOwner) && initialAvailable !== void 0 && Number.isFinite(initialAvailable);
894
+ const resolved = normalOwner ? resolveTransientKnownOwnerMain(items, intrinsicQuery) : resolveTransientIntrinsicMain(items, intrinsicQuery);
895
+ const stagedMain = allocated?.main ?? (contribution ? resolved.contributionMain : resolved.main);
896
+ stagePreparedIntrinsicMain(receiver, {
897
+ elements: children,
898
+ axis,
899
+ style: input.style,
900
+ rootMin,
901
+ rootMax,
902
+ contentMain: stagedMain,
903
+ normalOwner,
904
+ autoMarginFreeMain: resolved.autoMarginFreeMain,
905
+ revision: allocationInputRevision(),
906
+ items: resolved.targets.map((target, sourceIndex) => ({
907
+ sourceIndex,
908
+ target,
909
+ min: resolved.effectiveMins[sourceIndex],
910
+ max: resolved.effectiveMaxes[sourceIndex],
911
+ measured: items[sourceIndex].measured
912
+ }))
913
+ });
914
+ const reportedMain = contribution ? resolved.contributionMain : resolved.main;
915
+ return { status: "measured", size: row ? { width: reportedMain, height: cross } : { width: cross, height: reportedMain } };
916
+ }
917
+ function zeroIntrinsicMargin(value) {
918
+ return value === void 0 || value === 0 || value === "auto";
919
+ }
920
+ function intrinsicOwnerBound(value, reference, property, constraints) {
921
+ if (value === void 0) return;
922
+ if (typeof value === "number") {
923
+ if (Number.isFinite(value) && value >= 0) return value;
924
+ throw layoutDiagnostic({ component: "Flex", property, value, algorithm: "measurement", constraints, reason: "must be finite and nonnegative" });
925
+ }
926
+ const percentage = parsePercentage(value, property, { component: "Flex", algorithm: "measurement", constraints });
927
+ if (percentage < 0) throw layoutDiagnostic({ component: "Flex", property, value, algorithm: "measurement", constraints, reason: "must be nonnegative" });
928
+ if (reference === void 0) return;
929
+ const resolved = percentage / 100 * reference;
930
+ if (!Number.isFinite(resolved)) throw layoutDiagnostic({ component: "Flex", property, value, algorithm: "measurement", constraints, reason: "resolved percentage arithmetic must remain finite" });
931
+ return resolved;
932
+ }
206
933
  function resolveMeasuredContainerLength(value, reference, property, constraints) {
207
- const resolved = resolveLength(value, reference, property, {
934
+ const resolved = resolveScalarSizingLength(value, reference, property, {
208
935
  component: "Flex",
209
936
  algorithm: "measurement",
210
937
  constraints
@@ -233,6 +960,15 @@ function intrinsicNumber(value, property) {
233
960
  }
234
961
  return value;
235
962
  }
963
+ function validateIntrinsicBound(value, property, child, container) {
964
+ if (value === void 0) return;
965
+ if (typeof value === "number") {
966
+ if (!Number.isFinite(value) || value < 0) throw childDiagnostic(child, property, value, container, "must be finite and nonnegative");
967
+ return;
968
+ }
969
+ const percentage = parsePercentage(value, property, childContext(child, container));
970
+ if (percentage < 0) throw childDiagnostic(child, property, value, container, "must be nonnegative");
971
+ }
236
972
  function intrinsicOptionalNumber(value, fallback, property) {
237
973
  return value === void 0 ? fallback : intrinsicNumber(value, property);
238
974
  }
@@ -240,12 +976,7 @@ function isPercentage(value) {
240
976
  return typeof value === "string" && value.endsWith("%");
241
977
  }
242
978
  function hasPercentageBounds(style) {
243
- return [
244
- style.minWidth,
245
- style.maxWidth,
246
- style.minHeight,
247
- style.maxHeight
248
- ].some(isPercentage);
979
+ return isPercentage(style.minWidth) || isPercentage(style.maxWidth) || isPercentage(style.minHeight) || isPercentage(style.maxHeight);
249
980
  }
250
981
  function unsupportedIntrinsic(reason) {
251
982
  return {
@@ -255,27 +986,180 @@ function unsupportedIntrinsic(reason) {
255
986
  }
256
987
  function layoutFlex(container, children, style, measurement) {
257
988
  const prepared = materializeLayoutChildren(children, "Flex");
258
- return resolveFlexPlacements(container, prepared, style, measurement).map((placement) => placement.box);
989
+ const region = nativeLayout ? new LayoutRegion() : void 0;
990
+ try {
991
+ return resolveFlexPlacements(
992
+ container,
993
+ prepared,
994
+ style,
995
+ measurement,
996
+ region
997
+ ).map((placement) => placement.box);
998
+ } finally {
999
+ region?.dispose();
1000
+ }
259
1001
  }
260
- function resolveFlexPlacements(container, children, style, measurement) {
1002
+ function resolveFlexPlacements(container, children, style, measurement, region, stagedIntrinsic, parentSlot, deferStaticAbsolute) {
1003
+ if (region) recordWasmAllocationPass();
261
1004
  assertFiniteBox(container);
262
1005
  const options = normalizeFlexOptions(style, container);
263
- const row = options.flexDirection === "row";
1006
+ const row = isRowDirection(options.flexDirection);
1007
+ const authoredReverse = options.flexDirection === "row-reverse" || options.flexDirection === "column-reverse";
1008
+ const reverse = authoredReverse !== (row && options.layoutDirection === "rtl");
1009
+ const authoredWrapReverse = options.flexWrap === "wrap-reverse";
1010
+ const wrapReverse = authoredWrapReverse !== (!row && options.layoutDirection === "rtl");
264
1011
  const mainSize = row ? container.width : container.height;
265
1012
  const crossSize = row ? container.height : container.width;
266
1013
  const mainGap = row ? options.columnGap : options.rowGap;
267
1014
  const crossGap = row ? options.rowGap : options.columnGap;
268
1015
  const items = [];
269
- for (const child of children) {
1016
+ const placementsBySource = new Array(children.length);
1017
+ let hasAspectRatio = false;
1018
+ let hasAutoMainMargins = false;
1019
+ let absolutePaddingBox;
1020
+ let absoluteMeasurementTokens;
1021
+ const occurrences = /* @__PURE__ */ new Map();
1022
+ for (let sourceIndex = 0; sourceIndex < children.length; sourceIndex++) {
1023
+ const child = children[sourceIndex];
1024
+ if (region) recordWasmAllocationItem();
270
1025
  const receiverToken = getChildPrimitiveReceiverToken(
271
1026
  GLOBAL_STATE.renderTransaction,
272
1027
  GLOBAL_STATE.primitiveReceiverToken,
273
- items.length
1028
+ sourceIndex
274
1029
  );
275
- const prepared = prepareDirectChildStyle(child, receiverToken, container);
276
- const normalized = preparedStyleValue(prepared);
277
- assertSupportedChildPosition("Flex", child, normalized);
1030
+ const occurrence = occurrences.get(child.type) ?? 0;
1031
+ if (child.key === void 0) occurrences.set(child.type, occurrence + 1);
1032
+ const prepared = prepareDirectChildStyle(child, receiverToken, container, true);
1033
+ const declared = preparedStyleValue(prepared);
1034
+ let normalized = declared;
1035
+ if (nativeLayout) normalized = resolveAllocatedInsets(normalized, { width: container.width, layoutDirection: options.layoutDirection, context: childContext(child, container) });
1036
+ if (normalized.boxSizing !== void 0) normalized = contentBoxStyle(normalized, { width: container.width, height: container.height, mainAxis: row ? "width" : "height", context: childContext(child, container) });
1037
+ const stagedItem = stagedIntrinsic?.items[sourceIndex];
1038
+ if (stagedItem && stagedItem.sourceIndex !== sourceIndex) throw new Error("Staged intrinsic Flex children are out of source order.");
1039
+ const stagedMeasured = stagedItem?.measured === true;
1040
+ const aspectRatio = normalized.aspectRatio;
1041
+ if (aspectRatio !== void 0 && (typeof aspectRatio !== "number" || !Number.isFinite(aspectRatio) || aspectRatio <= 0)) {
1042
+ throw childDiagnostic(child, "aspectRatio", aspectRatio, container, "must be a positive finite outer width/height ratio");
1043
+ }
1044
+ if (nativeLayout && aspectRatio !== void 0 && normalized.position !== "absolute" && (normalized.flexBasis === void 0 || normalized.flexBasis === "auto")) {
1045
+ const main = normalized[row ? "width" : "height"], cross = normalized[row ? "height" : "width"];
1046
+ if ((main === void 0 || main === "auto") && typeof cross === "number") {
1047
+ const insets = normalizeBoxInsets(normalized, childContext(child, container));
1048
+ const crossInsets = row ? insets.top + insets.bottom : insets.left + insets.right;
1049
+ const mainInsets = row ? insets.left + insets.right : insets.top + insets.bottom;
1050
+ const outer = row ? (cross + crossInsets) * aspectRatio : (cross + crossInsets) / aspectRatio;
1051
+ normalized = { ...normalized, [row ? "width" : "height"]: Math.max(0, outer - mainInsets) };
1052
+ }
1053
+ }
1054
+ assertSupportedChildPosition("Flex", child, normalized, true);
278
1055
  rejectUnsupportedItemFields(child, normalized, container);
1056
+ if (options[FLEX_BASELINE_GROUP] && normalized.position === "absolute") {
1057
+ throw childDiagnostic(child, "position", "absolute", container, "PIBBL_LAYOUT_UNSUPPORTED_BASELINE: absolute children are outside first-baseline composition");
1058
+ }
1059
+ if (normalized.position === "absolute") {
1060
+ const definition = getPrimitiveDefinition(child.type);
1061
+ const hasPairedMeasurement = child.type !== Text && !!definition?.measureIntrinsic && !!definition.measure;
1062
+ const measurableText = child.type === Text && (normalized.wrap === void 0 || typeof normalized.wrap === "boolean") && (normalized.fit === void 0 || normalized.fit === "visible") && (normalized.overflow === void 0 || normalized.overflow === "visible" || normalized.overflow === "clip") && genericTextFont(normalized);
1063
+ const unwrappedText = measurableText && normalized.wrap !== true;
1064
+ const automaticWidth = normalized.width === void 0 || normalized.width === "auto";
1065
+ const automaticHeight = normalized.height === void 0 || normalized.height === "auto";
1066
+ const naturalBoth = unwrappedText && automaticWidth && automaticHeight && normalized.aspectRatio === void 0 && (absoluteLeftInset(normalized, options.layoutDirection) === void 0 || absoluteRightInset(normalized, options.layoutDirection) === void 0) && (normalized.top === void 0 || normalized.bottom === void 0);
1067
+ const naturalWidth = naturalBoth || automaticWidth && isAbsoluteSizeInput(normalized.height) && normalized.aspectRatio === void 0 && (absoluteLeftInset(normalized, options.layoutDirection) === void 0 || absoluteRightInset(normalized, options.layoutDirection) === void 0) && (hasPairedMeasurement || unwrappedText);
1068
+ const naturalHeight = naturalBoth || automaticHeight && isAbsoluteSizeInput(normalized.width) && normalized.aspectRatio === void 0 && (normalized.top === void 0 || normalized.bottom === void 0) && (hasPairedMeasurement || measurableText);
1069
+ assertSupportedAbsoluteFlexPosition(child, normalized, container, options.layoutDirection, preparedStyleQuery(prepared), naturalWidth, naturalHeight);
1070
+ const measurementToken = naturalWidth || naturalHeight ? region?.absoluteMeasurementIdentity(
1071
+ child.type,
1072
+ child.key === void 0 ? `occurrence:${occurrence}` : `key:${typeof child.key}:${child.key}`
1073
+ ) : void 0;
1074
+ if (measurementToken) (absoluteMeasurementTokens ??= /* @__PURE__ */ new Set()).add(measurementToken);
1075
+ const absoluteMeasurement = naturalWidth || naturalHeight ? measurement : void 0;
1076
+ if (deferStaticAbsolute) {
1077
+ deferStaticAbsolute[sourceIndex] = {
1078
+ sourceIndex,
1079
+ child,
1080
+ style: normalized,
1081
+ receiverToken,
1082
+ query: preparedStyleQuery(prepared),
1083
+ measurement: absoluteMeasurement,
1084
+ measurementToken
1085
+ };
1086
+ placementsBySource[sourceIndex] = deferredStaticPlacementSentinel();
1087
+ } else placementsBySource[sourceIndex] = resolveAbsoluteFlexPlacement(
1088
+ absolutePaddingBox ??= resolveFlexContainingBox(style, container),
1089
+ child,
1090
+ normalized,
1091
+ receiverToken,
1092
+ preparedStyleQuery(prepared),
1093
+ container,
1094
+ options,
1095
+ absoluteMeasurement,
1096
+ region,
1097
+ measurementToken
1098
+ );
1099
+ continue;
1100
+ }
1101
+ if (aspectRatio !== void 0) hasAspectRatio = true;
1102
+ const layoutChild = isLayoutComponent(child.type) ? prepareLayoutComponent(child, { receiverToken }) : child;
1103
+ const pairedLayoutDefinition = getPrimitiveDefinition(layoutChild.type);
1104
+ const knownIntrinsicLayout = child.type === Flex || layoutChild.type === Flow || layoutChild.type === Grid || layoutChild.type === Flex && isColumnDirection(normalized.flexDirection) && (normalized.flexWrap ?? "nowrap") === "nowrap";
1105
+ const layoutToken = region?.identity(child.type, child.key === void 0 ? `occurrence:${occurrence}` : `key:${typeof child.key}:${child.key}`);
1106
+ let relativeX = 0;
1107
+ let relativeY = 0;
1108
+ const position = normalized.position;
1109
+ if (position !== void 0) {
1110
+ assertSupportedRelativeFlexPosition(child, normalized, options, container);
1111
+ const left = resolveFlexInset(normalized.left, "left", child, container);
1112
+ const right = resolveFlexInset(normalized.right, "right", child, container);
1113
+ const top = resolveFlexInset(normalized.top, "top", child, container);
1114
+ const bottom = resolveFlexInset(normalized.bottom, "bottom", child, container);
1115
+ if (position === "relative") {
1116
+ if (options.layoutDirection === "rtl") relativeX = right === void 0 ? left ?? 0 : -right;
1117
+ else relativeX = left === void 0 ? right === void 0 ? 0 : -right : left;
1118
+ relativeY = top === void 0 ? bottom === void 0 ? 0 : -bottom : top;
1119
+ }
1120
+ }
1121
+ const allMargin = normalized.margin === "auto" ? "auto" : allocatedMargin(normalized.margin, "margin", child, container);
1122
+ const marginDirection = layoutChild.type === Flex ? normalized.layoutDirection ?? options.layoutDirection : options.layoutDirection;
1123
+ const logicalLeft = marginDirection === "rtl" ? normalized.marginEnd : normalized.marginStart;
1124
+ const logicalRight = marginDirection === "rtl" ? normalized.marginStart : normalized.marginEnd;
1125
+ const marginLeftProperty = logicalLeft !== void 0 ? marginDirection === "rtl" ? "marginEnd" : "marginStart" : "marginLeft";
1126
+ const marginRightProperty = logicalRight !== void 0 ? marginDirection === "rtl" ? "marginStart" : "marginEnd" : "marginRight";
1127
+ const marginTopValue = normalized.marginTop === void 0 ? allMargin : normalized.marginTop;
1128
+ const marginBottomValue = normalized.marginBottom === void 0 ? allMargin : normalized.marginBottom;
1129
+ const marginRightValue = logicalRight !== void 0 ? logicalRight : normalized.marginRight === void 0 ? allMargin : normalized.marginRight;
1130
+ const marginLeftValue = logicalLeft !== void 0 ? logicalLeft : normalized.marginLeft === void 0 ? allMargin : normalized.marginLeft;
1131
+ const autoTop = marginTopValue === "auto", autoRight = marginRightValue === "auto";
1132
+ const autoBottom = marginBottomValue === "auto", autoLeft = marginLeftValue === "auto";
1133
+ const declaredCrossSize = row ? normalized.height : normalized.width;
1134
+ const hasAutoCrossMargin = row ? autoTop || autoBottom : autoLeft || autoRight;
1135
+ const measuredCrossContext = hasAutoCrossMargin && nativeLayout && row && (declaredCrossSize === void 0 || declaredCrossSize === "auto") && !preparedStyleQuery(prepared) && aspectRatio === void 0;
1136
+ const columnNaturalWrappedTextCross = nativeLayout && !row && options.flexWrap === "nowrap" && child.type === Text && (declaredCrossSize === void 0 || declaredCrossSize === "auto") && typeof declared.height === "number" && typeof normalized.height === "number" && Number.isFinite(normalized.height) && normalized.height >= 0 && (normalized.flexBasis === void 0 || normalized.flexBasis === "auto") && (normalized.flexGrow ?? 0) === 0 && normalized.flexShrink === 0 && normalized.minHeight === 0 && normalized.maxHeight === void 0 && (normalized.minWidth === void 0 || normalized.minWidth === 0) && normalized.maxWidth === void 0 && normalized.wrap === true && (normalized.fit === void 0 || normalized.fit === "visible") && (normalized.overflow === void 0 || normalized.overflow === "visible" || normalized.overflow === "clip") && !preparedStyleQuery(prepared) && aspectRatio === void 0 && genericTextFont(normalized);
1137
+ const measuredColumnTextCross = hasAutoCrossMargin && nativeLayout && !row && options.flexWrap === "nowrap" && child.type === Text && (declaredCrossSize === void 0 || declaredCrossSize === "auto") && (normalized.height === void 0 || normalized.height === "auto" || typeof normalized.height === "number" && Number.isFinite(normalized.height) && normalized.height >= 0) && (normalized.flexBasis === void 0 || normalized.flexBasis === "auto" || typeof normalized.flexBasis === "number" && Number.isFinite(normalized.flexBasis) && normalized.flexBasis >= 0) && (normalized.flexGrow ?? 0) === 0 && normalized.flexShrink === 0 && normalized.minHeight === 0 && normalized.maxHeight === void 0 && normalized.minWidth === void 0 && normalized.maxWidth === void 0 && (normalized.wrap === void 0 || normalized.wrap === false) && !preparedStyleQuery(prepared) && aspectRatio === void 0;
1138
+ const measuredColumnProviderCrossDefinition = hasAutoCrossMargin && nativeLayout && !row && options.flexWrap === "nowrap" && (declaredCrossSize === void 0 || declaredCrossSize === "auto") && typeof declared.height === "number" && typeof normalized.height === "number" && Number.isFinite(normalized.height) && normalized.height >= 0 && (normalized.flexBasis === void 0 || normalized.flexBasis === "auto") && (normalized.flexGrow ?? 0) === 0 && normalized.flexShrink === 0 && normalized.minHeight === 0 && normalized.maxHeight === void 0 && normalized.minWidth === void 0 && normalized.maxWidth === void 0 && !preparedStyleQuery(prepared) && aspectRatio === void 0 && child.type !== Text ? getPrimitiveDefinition(child.type) : void 0;
1139
+ const measuredColumnProviderCross = !!measuredColumnProviderCrossDefinition?.measureIntrinsic && !!measuredColumnProviderCrossDefinition.measure;
1140
+ const measuredColumnKnownCrossAuto = hasAutoCrossMargin && nativeLayout && !row && options.flexWrap === "nowrap" && isKnownLayoutType(layoutChild.type) && (declaredCrossSize === void 0 || declaredCrossSize === "auto") && typeof declared.height === "number" && typeof normalized.height === "number" && Number.isFinite(normalized.height) && normalized.height >= 0 && (normalized.flexBasis === void 0 || normalized.flexBasis === "auto") && (normalized.flexGrow ?? 0) === 0 && normalized.flexShrink === 0 && normalized.minHeight === 0 && normalized.maxHeight === void 0 && (normalized.minWidth === void 0 || normalized.minWidth === 0) && normalized.maxWidth === void 0 && !preparedStyleQuery(prepared) && aspectRatio === void 0;
1141
+ const deferredColumnAutoCross = hasAutoCrossMargin && nativeLayout && !row && options.flexWrap === "nowrap" && (declaredCrossSize === void 0 || declaredCrossSize === "auto") && !preparedStyleQuery(prepared) && aspectRatio === void 0 && (child.type === Text && (normalized.wrap === void 0 || normalized.wrap === false) || layoutChild.type !== Text && !!pairedLayoutDefinition?.measureIntrinsic && !!pairedLayoutDefinition.measure || layoutChild.type === Flex || layoutChild.type === Flow || layoutChild.type === Grid);
1142
+ const measuredTextCrossAuto = hasAutoCrossMargin && nativeLayout && row && child.type === Text && (declaredCrossSize === void 0 || declaredCrossSize === "auto") && !preparedStyleQuery(prepared) && aspectRatio === void 0;
1143
+ const autoCrossDefinition = measuredCrossContext && !measuredTextCrossAuto ? pairedLayoutDefinition : void 0;
1144
+ const measuredPrimitiveCrossAuto = !!autoCrossDefinition?.measureIntrinsic && !!autoCrossDefinition.measure;
1145
+ const measuredKnownCrossAuto = measuredCrossContext && (layoutChild.type === Flex || layoutChild.type === Flow || layoutChild.type === Grid);
1146
+ const ordinaryCrossAuto = hasAutoCrossMargin && nativeLayout && (row || options.flexWrap === "nowrap") && (declaredCrossSize === void 0 || declaredCrossSize === "auto") && !preparedStyleQuery(prepared) && aspectRatio === void 0 && !!pairedLayoutDefinition?.measure;
1147
+ if (hasAutoCrossMargin && !measuredTextCrossAuto && !measuredColumnTextCross && !columnNaturalWrappedTextCross && !measuredColumnProviderCross && !measuredColumnKnownCrossAuto && !deferredColumnAutoCross && !measuredPrimitiveCrossAuto && !measuredKnownCrossAuto && !ordinaryCrossAuto && aspectRatio === void 0 && (declaredCrossSize === void 0 || declaredCrossSize === "auto")) {
1148
+ throw childDiagnostic(child, row ? autoTop ? "marginTop" : "marginBottom" : autoLeft ? marginLeftProperty : marginRightProperty, "auto", container, "auto cross-axis margins require a finite numeric child cross size or supported measurement");
1149
+ }
1150
+ const autoCrossBefore = row ? wrapReverse ? autoBottom : autoTop : wrapReverse ? autoRight : autoLeft;
1151
+ const autoCrossAfter = row ? wrapReverse ? autoTop : autoBottom : wrapReverse ? autoLeft : autoRight;
1152
+ const autoMainBefore = row ? reverse ? autoRight : autoLeft : reverse ? autoBottom : autoTop;
1153
+ const autoMainAfter = row ? reverse ? autoLeft : autoRight : reverse ? autoTop : autoBottom;
1154
+ if (autoMainBefore || autoMainAfter) hasAutoMainMargins = true;
1155
+ const marginTop = allocatedMargin(autoTop ? 0 : marginTopValue, "marginTop", child, container);
1156
+ const marginRight = allocatedMargin(autoRight ? 0 : marginRightValue, marginRightProperty, child, container);
1157
+ const marginBottom = allocatedMargin(autoBottom ? 0 : marginBottomValue, "marginBottom", child, container);
1158
+ const marginLeft = allocatedMargin(autoLeft ? 0 : marginLeftValue, marginLeftProperty, child, container);
1159
+ const marginMainBefore = row ? reverse ? marginRight : marginLeft : reverse ? marginBottom : marginTop;
1160
+ const marginMainAfter = row ? reverse ? marginLeft : marginRight : reverse ? marginTop : marginBottom;
1161
+ const marginCrossBefore = row ? wrapReverse ? marginBottom : marginTop : wrapReverse ? marginRight : marginLeft;
1162
+ const marginCrossAfter = row ? wrapReverse ? marginTop : marginBottom : wrapReverse ? marginLeft : marginRight;
279
1163
  const grow = nonnegativeFactor(normalized.flexGrow ?? 0, "flexGrow", child, container);
280
1164
  const shrink = nonnegativeFactor(
281
1165
  normalized.flexShrink ?? 1,
@@ -284,8 +1168,93 @@ function resolveFlexPlacements(container, children, style, measurement) {
284
1168
  container
285
1169
  );
286
1170
  const basisValue = normalized.flexBasis ?? "auto";
1171
+ const alignment = normalizeItemAlignment(normalized.alignSelf, child, container, authoredWrapReverse);
1172
+ const padding = normalizeBoxInsets(normalized, childContext(child, container));
1173
+ const paddingMain = row ? padding.left + padding.right : padding.top + padding.bottom;
1174
+ const paddingCross = row ? padding.top + padding.bottom : padding.left + padding.right;
287
1175
  const minimumProperty = row ? "minWidth" : "minHeight";
288
- if ((shrink > 0 || basisValue === "auto") && normalized[minimumProperty] === void 0) {
1176
+ const intrinsicTextSizing = nativeLayout && row && child.type === Text && (normalized.fit === void 0 || normalized.fit === "visible") && (normalized.overflow === void 0 || normalized.overflow === "visible" || normalized.overflow === "clip") && !preparedStyleQuery(prepared) && aspectRatio === void 0 && (normalized.width === void 0 || normalized.width === "auto" || typeof normalized.width === "number") && (normalized.maxWidth === void 0 || typeof normalized.maxWidth === "number");
1177
+ const automaticTextBasis = intrinsicTextSizing && basisValue === "auto" && (normalized.width === void 0 || normalized.width === "auto") && (normalized.minWidth === void 0 || typeof normalized.minWidth === "number");
1178
+ const automaticTextMinimum = intrinsicTextSizing && normalized[minimumProperty] === void 0 && shrink > 0 && (typeof basisValue === "number" || basisValue === "auto" && (typeof normalized.width === "number" || automaticTextBasis));
1179
+ const aspectMain = basisValue === "auto" ? normalized[row ? "width" : "height"] : basisValue;
1180
+ const aspectCross = normalized[row ? "height" : "width"];
1181
+ const automaticAspectRectangleMinimum = nativeLayout && aspectRatio !== void 0 && child.type === Rectangle && !Object.hasOwn(child.props, "children") && !preparedStyleQuery(prepared) && typeof aspectMain === "number" && Number.isFinite(aspectMain) && aspectMain >= 0 && (aspectCross === void 0 || aspectCross === "auto" || typeof aspectCross === "number" && Number.isFinite(aspectCross) && aspectCross >= 0);
1182
+ const automaticRectangleMinimum = automaticAspectRectangleMinimum || hasEmptyRectangleMinimum(child, normalized, preparedStyleQuery(prepared), true);
1183
+ const intrinsicMainValue = basisValue === void 0 || basisValue === "auto" ? normalized[row ? "width" : "height"] : basisValue;
1184
+ const intrinsicMainBounds = isIntrinsicSizingValue(normalized[row ? "minWidth" : "minHeight"]) || isIntrinsicSizingValue(normalized[row ? "maxWidth" : "maxHeight"]);
1185
+ const intrinsicMainRequested = isIntrinsicSizingValue(intrinsicMainValue);
1186
+ const directIntrinsicTextMain = (intrinsicMainRequested || intrinsicMainBounds) && !stagedMeasured && nativeLayout && row && child.type === Text && !preparedStyleQuery(prepared);
1187
+ const directIntrinsicMain = (intrinsicMainRequested || intrinsicMainBounds) && !stagedMeasured && nativeLayout && row && !preparedStyleQuery(prepared) && child.type !== Text && !isLayoutComponent(child.type) && !!pairedLayoutDefinition?.measureIntrinsic && !!pairedLayoutDefinition.measure;
1188
+ const customIntrinsic = child.type !== Text && (!isKnownLayoutType(layoutChild.type) || directIntrinsicMain) && !stagedMeasured && nativeLayout && row && !preparedStyleQuery(prepared) && !!pairedLayoutDefinition?.measureIntrinsic && (!isLayoutComponent(child.type) || aspectRatio === void 0 && !!pairedLayoutDefinition.measure) && (directIntrinsicMain || basisValue === "auto" && (normalized.width === void 0 || normalized.width === "auto") || shrink > 0 && normalized.minWidth === void 0);
1189
+ let intrinsicMainRequest;
1190
+ if (intrinsicMainRequested && (directIntrinsicMain || directIntrinsicTextMain)) {
1191
+ intrinsicMainRequest = normalizeSizingLength(intrinsicMainValue, {
1192
+ reference: mainSize,
1193
+ property: basisValue === void 0 || basisValue === "auto" ? "width" : "flexBasis",
1194
+ context: childContext(child, container),
1195
+ allowAuto: false,
1196
+ allowIntrinsic: true
1197
+ });
1198
+ }
1199
+ let intrinsicTextMinimum;
1200
+ let intrinsicTextBasis;
1201
+ let intrinsicTextMaximum;
1202
+ if (directIntrinsicTextMain) {
1203
+ const intrinsic = measureTextIntrinsicWidths(child, normalized, receiverToken, measurement, region);
1204
+ const maximum = intrinsic.maximum;
1205
+ if (!Number.isFinite(maximum) || maximum < 0) {
1206
+ throw childDiagnostic(child, "width", intrinsicMainValue, container, "Text intrinsic run width must be finite and nonnegative");
1207
+ }
1208
+ intrinsicTextMinimum = intrinsic.minimum;
1209
+ intrinsicTextMaximum = maximum;
1210
+ if (intrinsicMainRequest) {
1211
+ intrinsicTextBasis = resolveIntrinsicMainBasis(intrinsicMainRequest, intrinsicTextMinimum, maximum, child, container);
1212
+ } else if (basisValue === "auto" && (normalized.width === void 0 || normalized.width === "auto")) {
1213
+ intrinsicTextBasis = maximum;
1214
+ }
1215
+ }
1216
+ let intrinsicSizes;
1217
+ if (customIntrinsic) {
1218
+ const measurementChild = clonePibblElement(child);
1219
+ setPreNormalizedStyle(measurementChild, normalized, child, receiverToken);
1220
+ const result = measureIntrinsicElement(measurementChild, { minWidth: 0, maxWidth: container.width, minHeight: 0, maxHeight: container.height }, measurement.service, region ? { cache: region, token: layoutToken ?? receiverToken, recordMeasurement: recordWasmMeasurement, key: JSON.stringify([allocationStructuralRevision(), measurementStyle(normalized), container.width, container.height]) } : void 0);
1221
+ if (result.status === "unsupported") throw childDiagnostic(child, "measureIntrinsic", "unsupported", container, `intrinsic measurement is required but unsupported: ${result.reason}; supply a definite basis and explicit minWidth: 0 to avoid the query`);
1222
+ intrinsicSizes = result;
1223
+ }
1224
+ const columnExactWidth = !row && typeof normalized.width === "number" ? normalized.width : !row && (normalized.width === void 0 || normalized.width === "auto" || normalized.width === "stretch") && !hasAutoCrossMargin && effectiveAlignment(alignment, options.alignItems) === "stretch" ? clamp(
1225
+ Math.max(0, crossSize - paddingCross - marginCrossBefore - marginCrossAfter),
1226
+ resolveOptionalBound(normalized.minWidth, crossSize, "minWidth", 0, child, container),
1227
+ resolveOptionalBound(normalized.maxWidth, crossSize, "maxWidth", Number.POSITIVE_INFINITY, child, container)
1228
+ ) : void 0;
1229
+ const columnMinimumDefinition = nativeLayout && !row && (intrinsicMainRequested || intrinsicMainBounds || shrink > 0 && normalized.minHeight === void 0) && (normalized.height === void 0 || normalized.height === "auto" || typeof normalized.height === "number" || isIntrinsicSizingValue(normalized.height)) && columnExactWidth !== void 0 && Number.isFinite(columnExactWidth) && columnExactWidth >= 0 && aspectRatio === void 0 && !preparedStyleQuery(prepared) ? getPrimitiveDefinition(layoutChild.type) : void 0;
1230
+ let columnMinimumSize;
1231
+ if (columnMinimumDefinition?.measure && (columnMinimumDefinition.measureIntrinsic || child.type === Text || knownIntrinsicLayout)) {
1232
+ const measurementChild = clonePibblElement(child);
1233
+ const measurementStyle2 = { ...normalized, width: columnExactWidth };
1234
+ setPreNormalizedStyle(measurementChild, measurementStyle2, child, receiverToken);
1235
+ const result = measureFlexChild(measurementChild, {
1236
+ minWidth: columnExactWidth,
1237
+ maxWidth: columnExactWidth,
1238
+ minHeight: 0,
1239
+ maxHeight: Number.POSITIVE_INFINITY
1240
+ }, measurementStyle2, layoutToken ?? receiverToken, measurement, region, void 0, true);
1241
+ if (result.status === "unsupported") throw childDiagnostic(
1242
+ child,
1243
+ "minHeight",
1244
+ "auto",
1245
+ container,
1246
+ `exact-width automatic minimum measurement is required but unsupported: ${result.reason}`
1247
+ );
1248
+ columnMinimumSize = result.size;
1249
+ if (intrinsicMainRequested) intrinsicMainRequest = normalizeSizingLength(intrinsicMainValue, {
1250
+ reference: mainSize,
1251
+ property: "height",
1252
+ context: childContext(child, container),
1253
+ allowAuto: false,
1254
+ allowIntrinsic: true
1255
+ });
1256
+ }
1257
+ if (!stagedMeasured && (shrink > 0 || basisValue === "auto") && normalized[minimumProperty] === void 0 && !automaticTextMinimum && !automaticTextBasis && !automaticRectangleMinimum && !intrinsicSizes && intrinsicTextMinimum === void 0 && !columnMinimumSize) {
289
1258
  throw childDiagnostic(
290
1259
  child,
291
1260
  minimumProperty,
@@ -298,19 +1267,36 @@ function resolveFlexPlacements(container, children, style, measurement) {
298
1267
  const crossProperty = row ? "height" : "width";
299
1268
  const mainReference = mainSize;
300
1269
  const crossReference = crossSize;
301
- let measured;
1270
+ let measured = columnMinimumSize;
302
1271
  const specifiedMain = normalized[mainProperty];
303
1272
  const specifiedCross = normalized[crossProperty];
304
- const needsMeasuredMain = basisValue === "auto" && (specifiedMain === void 0 || specifiedMain === "auto");
1273
+ const needsMeasuredMain = !stagedMeasured && basisValue === "auto" && (specifiedMain === void 0 || specifiedMain === "auto");
1274
+ if (aspectRatio !== void 0 && needsMeasuredMain && !intrinsicSizes && !automaticTextBasis) throw childDiagnostic(child, "aspectRatio", aspectRatio, container, "requires a definite main dimension or flexBasis; intrinsic aspect sizing is unsupported");
305
1275
  const crossAuto = specifiedCross === void 0 || specifiedCross === "auto";
306
- const alignment = normalizeItemAlignment(normalized.alignSelf, child, container);
307
- const needsMeasuredCross = crossAuto && alignment !== "stretch" && options.alignItems !== "stretch";
308
- if (needsMeasuredMain || needsMeasuredCross || crossAuto) {
1276
+ const measuredColumnWrapText = nativeLayout && !row && options.flexWrap !== "nowrap" && needsMeasuredMain && child.type === Text && aspectRatio === void 0 && typeof declared.width === "number" && typeof normalized.width === "number" && Number.isFinite(normalized.width) && normalized.width >= 0 && declared.minHeight === 0 && grow === 0 && shrink === 0 && normalized.wrap === true && (normalized.fit === void 0 || normalized.fit === "visible") && (normalized.overflow === void 0 || normalized.overflow === "visible" || normalized.overflow === "clip") && (normalized.minWidth === void 0 || normalized.minWidth === 0) && normalized.maxWidth === void 0 && normalized.maxHeight === void 0 && !preparedStyleQuery(prepared) && genericTextFont(normalized);
1277
+ const measuredColumnProviderDefinition = nativeLayout && !row && options.flexDirection === "column" && options.flexWrap === "nowrap" && options.layoutDirection === "ltr" && needsMeasuredMain && aspectRatio === void 0 && typeof declared.width === "number" && typeof normalized.width === "number" && Number.isFinite(normalized.width) && normalized.width >= 0 && declared.minHeight === 0 && grow === 0 && shrink === 0 && (normalized.minWidth === void 0 || normalized.minWidth === 0) && normalized.maxWidth === void 0 && !preparedStyleQuery(prepared) ? getPrimitiveDefinition(child.type) : void 0;
1278
+ const measuredColumnProvider = child.type !== Text && !isKnownLayoutType(layoutChild.type) && !!measuredColumnProviderDefinition?.measureIntrinsic && !!measuredColumnProviderDefinition.measure;
1279
+ const naturalColumnWrappedTextCross = columnNaturalWrappedTextCross && (hasAutoCrossMargin || effectiveAlignment(alignment, options.alignItems) !== "stretch");
1280
+ if (nativeLayout && !row && options.flexWrap !== "nowrap" && (needsMeasuredMain && !measuredColumnWrapText || aspectRatio === void 0 && crossAuto && effectiveAlignment(alignment, options.alignItems) !== "stretch")) {
1281
+ throw childDiagnostic(
1282
+ child,
1283
+ needsMeasuredMain ? mainProperty : crossProperty,
1284
+ "auto",
1285
+ container,
1286
+ "Experimental WASM column wrap requires a declared height or flexBasis and a declared width or stretched automatic width; intrinsic item sizes are unsupported."
1287
+ );
1288
+ }
1289
+ const needsMeasuredCross = aspectRatio === void 0 && crossAuto && alignment !== "stretch" && options.alignItems !== "stretch";
1290
+ const deferredIntrinsicColumn = aspectRatio === void 0 && nativeLayout && !row && knownIntrinsicLayout && needsMeasuredMain && crossAuto && effectiveAlignment(alignment, options.alignItems) === "stretch";
1291
+ if (intrinsicSizes) measured = intrinsicSizes.maxContent;
1292
+ if (!columnMinimumSize && !directIntrinsicTextMain && !intrinsicSizes && !deferredIntrinsicColumn && !naturalColumnWrappedTextCross && (!deferredColumnAutoCross || needsMeasuredMain) && (needsMeasuredMain || aspectRatio === void 0 && (needsMeasuredCross || crossAuto))) {
1293
+ const naturalColumnCross = measuredColumnTextCross || measuredColumnProviderCross || measuredColumnKnownCrossAuto || deferredColumnAutoCross;
1294
+ const exactColumnHeight = naturalColumnCross && typeof normalized.height === "number" ? normalized.height : void 0;
309
1295
  const constraints = {
310
- minWidth: 0,
311
- maxWidth: container.width,
312
- minHeight: 0,
313
- maxHeight: container.height
1296
+ minWidth: naturalColumnCross ? 0 : measuredColumnWrapText || measuredColumnProvider ? normalized.width : 0,
1297
+ maxWidth: naturalColumnCross ? Number.POSITIVE_INFINITY : measuredColumnWrapText || measuredColumnProvider ? normalized.width : container.width,
1298
+ minHeight: exactColumnHeight ?? 0,
1299
+ maxHeight: exactColumnHeight ?? (measuredColumnWrapText || measuredColumnProvider ? Number.POSITIVE_INFINITY : container.height)
314
1300
  };
315
1301
  const measurementChild = clonePibblElement(child);
316
1302
  setPreNormalizedStyle(
@@ -320,10 +1306,21 @@ function resolveFlexPlacements(container, children, style, measurement) {
320
1306
  receiverToken,
321
1307
  preparedStyleQuery(prepared)
322
1308
  );
323
- const result = measurement.measureElement(measurementChild, constraints);
1309
+ const result = measureFlexChild(
1310
+ measurementChild,
1311
+ constraints,
1312
+ normalized,
1313
+ layoutToken ?? receiverToken,
1314
+ measurement,
1315
+ region,
1316
+ preparedStyleQuery(prepared),
1317
+ nativeLayout && row && options.flexWrap === "nowrap" || measuredPrimitiveCrossAuto || measuredColumnProvider || measuredColumnProviderCross,
1318
+ needsMeasuredMain ? row ? "row" : "column" : void 0,
1319
+ ordinaryCrossAuto || !!pairedLayoutDefinition?.measure && !pairedLayoutDefinition.measureIntrinsic && layoutChild.type !== Text && !isKnownLayoutType(layoutChild.type)
1320
+ );
324
1321
  if (result.status === "measured") {
325
1322
  measured = result.size;
326
- } else if (needsMeasuredMain || crossAuto && effectiveAlignment(
1323
+ } else if (measuredTextCrossAuto || measuredColumnTextCross || measuredKnownCrossAuto || measuredColumnProviderCross || measuredColumnKnownCrossAuto || deferredColumnAutoCross || ordinaryCrossAuto || needsMeasuredMain || crossAuto && effectiveAlignment(
327
1324
  alignment,
328
1325
  options.alignItems
329
1326
  ) !== "stretch") {
@@ -336,26 +1333,9 @@ function resolveFlexPlacements(container, children, style, measurement) {
336
1333
  );
337
1334
  }
338
1335
  }
339
- const baseMain = resolveBasis(
340
- basisValue,
341
- specifiedMain,
342
- measured?.[mainProperty],
343
- mainReference,
344
- mainProperty,
345
- child,
346
- container
347
- );
348
- const preferredCross = crossAuto ? measured?.[crossProperty] ?? 0 : resolveItemLength(
349
- specifiedCross,
350
- crossReference,
351
- crossProperty,
352
- child,
353
- container
354
- );
355
- const padding = normalizeEdges(normalized.padding, "padding", childContext(child, container));
356
- const paddingMain = row ? padding.left + padding.right : padding.top + padding.bottom;
357
- const paddingCross = row ? padding.top + padding.bottom : padding.left + padding.right;
358
- const minMain = resolveOptionalBound(
1336
+ const intrinsicMinimum = row ? intrinsicSizes?.minContent.width ?? intrinsicTextMinimum : columnMinimumSize?.height;
1337
+ const intrinsicMaximum = row ? intrinsicSizes?.maxContent.width ?? intrinsicTextMaximum : columnMinimumSize?.height;
1338
+ let minMain = stagedItem ? stagedItem.min : isIntrinsicSizingValue(normalized[minimumProperty]) ? resolveIntrinsicMainBound(normalized[minimumProperty], intrinsicMinimum, intrinsicMaximum, minimumProperty, mainReference, child, container) : resolveOptionalBound(
359
1339
  normalized[minimumProperty],
360
1340
  mainReference,
361
1341
  minimumProperty,
@@ -364,7 +1344,7 @@ function resolveFlexPlacements(container, children, style, measurement) {
364
1344
  container
365
1345
  );
366
1346
  const maximumProperty = row ? "maxWidth" : "maxHeight";
367
- const maxMain = resolveOptionalBound(
1347
+ const maxMain = stagedItem ? stagedItem.max : isIntrinsicSizingValue(normalized[maximumProperty]) ? resolveIntrinsicMainBound(normalized[maximumProperty], intrinsicMinimum, intrinsicMaximum, maximumProperty, mainReference, child, container) : resolveOptionalBound(
368
1348
  normalized[maximumProperty],
369
1349
  mainReference,
370
1350
  maximumProperty,
@@ -372,6 +1352,32 @@ function resolveFlexPlacements(container, children, style, measurement) {
372
1352
  child,
373
1353
  container
374
1354
  );
1355
+ if (intrinsicSizes && normalized.minWidth === void 0 && shrink > 0) {
1356
+ minMain = Math.min(
1357
+ intrinsicSizes.minContent.width,
1358
+ maxMain,
1359
+ typeof specifiedMain === "number" ? specifiedMain : Number.POSITIVE_INFINITY
1360
+ );
1361
+ }
1362
+ if (columnMinimumSize) {
1363
+ minMain = Math.min(
1364
+ columnMinimumSize.height,
1365
+ maxMain,
1366
+ typeof specifiedMain === "number" ? specifiedMain : Number.POSITIVE_INFINITY
1367
+ );
1368
+ }
1369
+ if (intrinsicTextMinimum !== void 0 && normalized.minWidth === void 0 && shrink > 0) {
1370
+ minMain = Math.min(intrinsicTextMinimum, maxMain);
1371
+ }
1372
+ const intrinsicMainBasis = intrinsicTextBasis ?? (intrinsicMainRequest && intrinsicMinimum !== void 0 && intrinsicMaximum !== void 0 ? resolveIntrinsicMainBasis(intrinsicMainRequest, intrinsicMinimum, intrinsicMaximum, child, container) : void 0);
1373
+ if (automaticTextMinimum) {
1374
+ const contentMinimum = measureTextContentMinimum(child, normalized, receiverToken, measurement, region);
1375
+ minMain = Math.min(
1376
+ contentMinimum,
1377
+ maxMain,
1378
+ typeof specifiedMain === "number" ? specifiedMain : Number.POSITIVE_INFINITY
1379
+ );
1380
+ }
375
1381
  const minCrossProperty = row ? "minHeight" : "minWidth";
376
1382
  const maxCrossProperty = row ? "maxHeight" : "maxWidth";
377
1383
  const minCross = resolveOptionalBound(
@@ -390,6 +1396,30 @@ function resolveFlexPlacements(container, children, style, measurement) {
390
1396
  child,
391
1397
  container
392
1398
  );
1399
+ if (naturalColumnWrappedTextCross) {
1400
+ const token = layoutToken ?? receiverToken;
1401
+ const naturalWidth = measureTextNaturalWidth(child, normalized, receiverToken, token, measurement, region);
1402
+ const chosenWidth = Math.min(naturalWidth, Math.max(0, crossSize - paddingCross - marginCrossBefore - marginCrossAfter));
1403
+ const measuredStyle = { ...normalized, width: chosenWidth };
1404
+ const measurementChild = clonePibblElement(child);
1405
+ setPreNormalizedStyle(measurementChild, measuredStyle, child, receiverToken, preparedStyleQuery(prepared));
1406
+ const result = measureFlexChild(measurementChild, {
1407
+ minWidth: chosenWidth,
1408
+ maxWidth: chosenWidth,
1409
+ minHeight: normalized.height,
1410
+ maxHeight: normalized.height
1411
+ }, measuredStyle, token, measurement, region, preparedStyleQuery(prepared));
1412
+ if (result.status !== "measured") {
1413
+ throw childDiagnostic(
1414
+ child,
1415
+ "width",
1416
+ "auto",
1417
+ container,
1418
+ `measurement is required but unsupported: ${result.reason}`
1419
+ );
1420
+ }
1421
+ measured = result.size;
1422
+ }
393
1423
  if (minMain > maxMain) {
394
1424
  throw childDiagnostic(
395
1425
  child,
@@ -408,94 +1438,665 @@ function resolveFlexPlacements(container, children, style, measurement) {
408
1438
  "minimum must not exceed maximum"
409
1439
  );
410
1440
  }
1441
+ if (!row && options.flexWrap === "nowrap" && (child.type === Text || nativeLayout && knownIntrinsicLayout) && needsMeasuredMain) {
1442
+ const preferredWidth = crossAuto ? effectiveAlignment(alignment, options.alignItems) === "stretch" && !hasAutoCrossMargin ? Math.max(0, crossSize - paddingCross - marginCrossBefore - marginCrossAfter) : measured?.width ?? 0 : resolveItemLength(specifiedCross, crossReference, crossProperty, child, container);
1443
+ const usedWidth = clamp(preferredWidth, minCross, maxCross);
1444
+ if (child.type === Text || usedWidth !== measured?.width) {
1445
+ const measuredStyle = { ...normalized, width: usedWidth };
1446
+ const measurementChild = clonePibblElement(layoutChild);
1447
+ setPreNormalizedStyle(measurementChild, measuredStyle, layoutChild, getPrimitiveReceiverToken(layoutChild) ?? receiverToken, preparedStyleQuery(prepared));
1448
+ const result = measureFlexChild(measurementChild, {
1449
+ minWidth: 0,
1450
+ maxWidth: usedWidth,
1451
+ minHeight: 0,
1452
+ maxHeight: container.height
1453
+ }, measuredStyle, layoutToken ?? receiverToken, measurement, region, preparedStyleQuery(prepared));
1454
+ if (result.status === "measured") measured = result.size;
1455
+ else throw childDiagnostic(
1456
+ child,
1457
+ mainProperty,
1458
+ "auto",
1459
+ container,
1460
+ `measurement is required but unsupported: ${result.reason}`
1461
+ );
1462
+ }
1463
+ }
1464
+ let naturalTextMain;
1465
+ if (automaticTextBasis) {
1466
+ naturalTextMain = measureTextNaturalWidth(child, normalized, receiverToken, layoutToken ?? receiverToken, measurement, region);
1467
+ }
1468
+ const stretchMain = (declared.flexBasis === void 0 || declared.flexBasis === "auto" ? declared[mainProperty] : declared.flexBasis) === "stretch";
1469
+ const baseMain = stagedMeasured ? stagedItem.target : stretchMain ? Math.max(0, mainReference - marginMainBefore - marginMainAfter - paddingMain) : intrinsicMainBasis ?? naturalTextMain ?? resolveBasis(
1470
+ basisValue,
1471
+ specifiedMain,
1472
+ measured?.[mainProperty],
1473
+ mainReference,
1474
+ mainProperty,
1475
+ child,
1476
+ container
1477
+ );
1478
+ const preferredCross = declared[crossProperty] === "stretch" ? Math.max(0, crossReference - marginCrossBefore - marginCrossAfter - paddingCross) : aspectRatio !== void 0 ? 0 : crossAuto ? measured?.[crossProperty] ?? 0 : resolveItemLength(
1479
+ specifiedCross,
1480
+ crossReference,
1481
+ crossProperty,
1482
+ child,
1483
+ container
1484
+ );
411
1485
  items.push({
412
1486
  child,
413
1487
  normalized,
414
1488
  baseMain,
415
1489
  targetMain: baseMain,
416
1490
  paddingMain,
1491
+ marginMainBefore,
1492
+ marginMainAfter,
1493
+ autoMainBefore,
1494
+ autoMainAfter,
1495
+ marginCrossBefore,
1496
+ marginCrossAfter,
1497
+ autoCrossBefore,
1498
+ autoCrossAfter,
417
1499
  preferredCross: clamp(preferredCross, minCross, maxCross) + paddingCross,
418
1500
  paddingCross,
1501
+ paddingCrossBefore: row ? padding.top : padding.left,
419
1502
  minMain,
420
1503
  maxMain,
421
1504
  minCross,
422
1505
  maxCross,
423
1506
  grow,
424
1507
  shrink,
425
- crossAuto,
1508
+ crossAuto: aspectRatio === void 0 && crossAuto,
1509
+ aspectRatio,
426
1510
  alignSelf: alignment,
427
1511
  receiverToken,
428
- query: preparedStyleQuery(prepared)
1512
+ layoutToken,
1513
+ query: preparedStyleQuery(prepared),
1514
+ relativeX,
1515
+ relativeY,
1516
+ deferredColumnAutoCross,
1517
+ ordinaryColumnAutoCross: !row && ordinaryCrossAuto && !deferredColumnAutoCross && !naturalColumnWrappedTextCross,
1518
+ sourceIndex,
1519
+ layoutOccurrence: occurrence
429
1520
  });
430
1521
  }
431
- const lines = collectLines(items, mainSize, mainGap, options.flexWrap);
432
- for (const line of lines) resolveFlexibleLengths(line, mainSize, mainGap);
433
- resolveLineCrossSizes(
434
- lines,
435
- crossSize,
436
- crossGap,
437
- options.alignContent,
438
- options.flexWrap === "wrap"
439
- );
440
- const placements = [];
1522
+ const wrappedRegion = region && options.flexWrap !== "nowrap";
1523
+ const lines = region ? items.length ? [{ items, crossSize: 0, crossOffset: 0 }] : [] : collectLines(items, mainSize, mainGap, options.flexWrap);
1524
+ if (lines.length === 0) region?.solve([], mainSize, mainGap, !!wrappedRegion);
1525
+ for (const line of lines) {
1526
+ if (region) region.solve(line.items, mainSize, mainGap, !!wrappedRegion);
1527
+ else resolveFlexibleLengths(line, mainSize, mainGap);
1528
+ if (hasAspectRatio) for (const item of line.items) {
1529
+ if (item.aspectRatio === void 0) continue;
1530
+ const outerMain = item.targetMain + item.paddingMain;
1531
+ const outerCross = row ? outerMain / item.aspectRatio : outerMain * item.aspectRatio;
1532
+ if (!Number.isFinite(outerCross)) throw childDiagnostic(item.child, "aspectRatio", item.aspectRatio, container, "derived cross size must be finite");
1533
+ item.preferredCross = clamp(Math.max(0, outerCross - item.paddingCross), item.minCross, item.maxCross) + item.paddingCross;
1534
+ }
1535
+ if (row) for (const item of line.items) {
1536
+ let measuredRoot = item.child;
1537
+ if (item.crossAuto && nativeLayout && (options.flexWrap === "nowrap" && options.flexDirection === "row" && options.layoutDirection === "ltr" || item.autoCrossBefore || item.autoCrossAfter || options[FLEX_BASELINE_GROUP]) && !item.query && item.aspectRatio === void 0 && isLayoutComponent(item.child.type)) {
1538
+ measuredRoot = prepareLayoutComponent(item.child, { receiverToken: item.receiverToken });
1539
+ }
1540
+ const definition = nativeLayout && (options.flexWrap === "nowrap" || item.autoCrossBefore || item.autoCrossAfter || options[FLEX_BASELINE_GROUP]) && !item.query && item.aspectRatio === void 0 ? getPrimitiveDefinition(measuredRoot.type) : void 0;
1541
+ const constrainedProvider = measuredRoot.type !== Text && !isKnownLayoutType(measuredRoot.type) && !!definition?.measureIntrinsic && !!definition.measure;
1542
+ const ordinaryProvider = !!definition?.measure && (item.autoCrossBefore || item.autoCrossAfter || options[FLEX_BASELINE_GROUP]);
1543
+ const requiredKnownCross = nativeLayout && (item.autoCrossBefore || item.autoCrossAfter) && (measuredRoot.type === Flex || measuredRoot.type === Flow || measuredRoot.type === Grid);
1544
+ if (!item.crossAuto || item.child.type !== Text && !(nativeLayout && item.child.type === Flex) && !constrainedProvider && !ordinaryProvider && !requiredKnownCross) continue;
1545
+ if (item.child.type === Flex && item.normalized.width === item.targetMain) continue;
1546
+ const measuredStyle = { ...item.normalized, width: item.targetMain };
1547
+ const child = clonePibblElement(item.child);
1548
+ setPreNormalizedStyle(child, measuredStyle, item.child, item.receiverToken, item.query);
1549
+ const result = measureFlexChild(child, {
1550
+ minWidth: constrainedProvider || ordinaryProvider ? item.targetMain : 0,
1551
+ maxWidth: item.targetMain,
1552
+ minHeight: 0,
1553
+ maxHeight: container.height
1554
+ }, measuredStyle, item.layoutToken ?? item.receiverToken, measurement, region, item.query, constrainedProvider, void 0, ordinaryProvider);
1555
+ if (result.status === "measured") {
1556
+ item.preferredCross = clamp(result.size.height, item.minCross, item.maxCross) + item.paddingCross;
1557
+ if (options[FLEX_BASELINE_GROUP] && (item.alignSelf !== "stretch" || item.autoCrossBefore || item.autoCrossAfter)) item.crossAuto = false;
1558
+ } else if (constrainedProvider || ordinaryProvider || requiredKnownCross || options[FLEX_BASELINE_GROUP] || nativeLayout && item.child.type === Text && (item.autoCrossBefore || item.autoCrossAfter)) throw childDiagnostic(item.child, "height", "auto", container, `final-width measurement is required but unsupported: ${result.reason}`);
1559
+ }
1560
+ }
1561
+ if (!row) for (const item of items) {
1562
+ if (!item.deferredColumnAutoCross && !item.ordinaryColumnAutoCross || !item.crossAuto) continue;
1563
+ let measuredRoot = item.child;
1564
+ if (isLayoutComponent(item.child.type)) {
1565
+ measuredRoot = prepareLayoutComponent(item.child, { receiverToken: item.receiverToken });
1566
+ }
1567
+ const definition = getPrimitiveDefinition(measuredRoot.type);
1568
+ const constrainedProvider = measuredRoot.type !== Text && !!definition?.measureIntrinsic && !!definition.measure;
1569
+ const ordinaryWidth = Math.max(0, item.preferredCross - item.paddingCross);
1570
+ const measuredStyle = item.ordinaryColumnAutoCross ? { ...item.normalized, width: ordinaryWidth, height: item.targetMain } : { ...item.normalized, height: item.targetMain };
1571
+ const measurementChild = clonePibblElement(item.child);
1572
+ setPreNormalizedStyle(measurementChild, measuredStyle, item.child, item.receiverToken, item.query);
1573
+ const result = measureFlexChild(measurementChild, {
1574
+ minWidth: 0,
1575
+ maxWidth: item.ordinaryColumnAutoCross ? ordinaryWidth : Number.POSITIVE_INFINITY,
1576
+ minHeight: item.targetMain,
1577
+ maxHeight: item.targetMain
1578
+ }, measuredStyle, item.layoutToken ?? item.receiverToken, measurement, region, item.query, constrainedProvider, void 0, item.ordinaryColumnAutoCross);
1579
+ if (result.status === "unsupported") {
1580
+ throw childDiagnostic(
1581
+ item.child,
1582
+ "width",
1583
+ "auto",
1584
+ container,
1585
+ `final-height measurement is required but unsupported: ${result.reason}`
1586
+ );
1587
+ }
1588
+ item.preferredCross = clamp(result.size.width, item.minCross, item.maxCross) + item.paddingCross;
1589
+ }
1590
+ if (options[FLEX_BASELINE_GROUP]) {
1591
+ assertSupportedBaselineFlex(options, items, container, region !== void 0);
1592
+ for (const item of items) {
1593
+ if (item.alignSelf !== "auto" || item.autoCrossBefore || item.autoCrossAfter) {
1594
+ item.firstBaseline = 0;
1595
+ continue;
1596
+ }
1597
+ const structural = prepareKnownStructuralBaseline(item, container, measurement, parentSlot, options[FLEX_LAST_BASELINE]);
1598
+ if (structural !== void 0) {
1599
+ item.structuralBaselineSlot = structural.slot;
1600
+ item.firstBaseline = item.paddingCrossBefore + structural.offset;
1601
+ continue;
1602
+ }
1603
+ const allocation = { x: 0, y: 0, width: item.targetMain, height: Math.max(0, item.preferredCross - item.paddingCross) };
1604
+ const baselineRoot = item.baselineRoot ?? item.child;
1605
+ const definition = getPrimitiveDefinition(baselineRoot.type);
1606
+ if (!definition?.measureBaselines) {
1607
+ item.firstBaseline = item.paddingCrossBefore + allocation.height;
1608
+ continue;
1609
+ }
1610
+ const measurementChild = clonePibblElement(baselineRoot);
1611
+ const measuredStyle = { ...item.normalized, width: allocation.width, height: allocation.height };
1612
+ setPreNormalizedStyle(measurementChild, measuredStyle, baselineRoot, getPrimitiveReceiverToken(baselineRoot) ?? item.receiverToken, item.query);
1613
+ if (item.query) setPreparedBaselineOwner(measurementChild, container);
1614
+ const cacheOptions = region && !item.query && (baselineRoot.type !== Text || genericTextFont(item.normalized)) ? {
1615
+ cache: region,
1616
+ token: item.layoutToken ?? item.receiverToken,
1617
+ key: `${allocationStructuralRevision()}:${allocation.width}:${allocation.height}:${JSON.stringify(measurementStyle(item.normalized))}`,
1618
+ recordMeasurement: recordWasmMeasurement
1619
+ } : void 0;
1620
+ if (cacheOptions && item.baselineRoot) cacheOptions.source = item.child;
1621
+ const result = measureBaselineElement(measurementChild, allocation, measurement.service, cacheOptions);
1622
+ if (result.status === "unsupported") {
1623
+ throw childDiagnostic(item.child, "measureBaselines", "unsupported", container, `first-baseline alignment requires a baseline result: ${result.reason}`);
1624
+ }
1625
+ item.firstBaseline = item.paddingCrossBefore + (options[FLEX_LAST_BASELINE] ? result.last : result.first);
1626
+ }
1627
+ }
1628
+ if (region) {
1629
+ for (const line of lines) {
1630
+ line.crossSize = crossSize;
1631
+ line.crossOffset = 0;
1632
+ }
1633
+ } else {
1634
+ resolveLineCrossSizes(lines, crossSize, crossGap, options.alignContent, options.flexWrap === "wrap");
1635
+ }
1636
+ const crossPlacements = region?.placeCross(items, crossSize, options.alignItems, {
1637
+ reverse: wrapReverse,
1638
+ wrap: wrappedRegion ? { gap: crossGap, alignContent: options.alignContent } : void 0,
1639
+ baseline: options[FLEX_BASELINE_GROUP],
1640
+ lastBaseline: options[FLEX_LAST_BASELINE]
1641
+ });
1642
+ const mainPlacements = region?.placeMain(mainSize, mainGap, options.justifyContent, reverse, hasAutoMainMargins ? items : void 0, stagedIntrinsic?.autoMarginFreeMain);
1643
+ let mainIndex = 0;
1644
+ let crossIndex = 0;
441
1645
  for (const line of lines) {
442
- const occupied = line.items.reduce(
1646
+ const occupied = mainPlacements ? 0 : line.items.reduce(
443
1647
  (total, item) => total + item.targetMain + item.paddingMain,
444
1648
  Math.max(0, line.items.length - 1) * mainGap
445
1649
  );
446
- const distribution = distributeAlignment(
1650
+ const distribution = mainPlacements ? { start: 0, between: 0 } : distributeAlignment(
447
1651
  options.justifyContent,
448
1652
  mainSize - occupied,
449
1653
  line.items.length
450
1654
  );
451
1655
  let mainCursor = distribution.start;
452
1656
  for (const item of line.items) {
453
- const alignment = effectiveAlignment(item.alignSelf, options.alignItems);
454
- let outerCross = item.preferredCross;
455
- if (alignment === "stretch" && item.crossAuto) {
456
- outerCross = clamp(
457
- Math.max(0, line.crossSize - item.paddingCross),
458
- item.minCross,
459
- item.maxCross
460
- ) + item.paddingCross;
461
- }
462
- const crossOffset = alignmentOffset(
463
- alignment,
464
- line.crossSize,
465
- outerCross
466
- );
1657
+ if (mainPlacements) mainCursor = mainPlacements[mainIndex++];
1658
+ let outerCross;
1659
+ let crossOffset;
1660
+ if (crossPlacements) {
1661
+ const placement = crossPlacements[crossIndex++];
1662
+ outerCross = placement.outerCross;
1663
+ crossOffset = placement.offset;
1664
+ } else {
1665
+ const alignment = effectiveAlignment(item.alignSelf, options.alignItems);
1666
+ outerCross = item.preferredCross;
1667
+ if (alignment === "stretch" && item.crossAuto) {
1668
+ outerCross = clamp(Math.max(0, line.crossSize - item.paddingCross), item.minCross, item.maxCross) + item.paddingCross;
1669
+ }
1670
+ crossOffset = alignmentOffset(alignment, line.crossSize, outerCross);
1671
+ }
467
1672
  const outerMain = item.targetMain + item.paddingMain;
468
- const box = row ? {
469
- x: container.x + mainCursor,
470
- y: container.y + line.crossOffset + crossOffset,
471
- width: outerMain,
472
- height: outerCross
473
- } : {
474
- x: container.x + line.crossOffset + crossOffset,
475
- y: container.y + mainCursor,
476
- width: outerCross,
477
- height: outerMain
1673
+ const x = row ? container.x + mainCursor + item.relativeX : container.x + line.crossOffset + crossOffset + item.relativeX;
1674
+ const layoutY = row ? container.y + line.crossOffset + crossOffset : container.y + mainCursor;
1675
+ const y = layoutY + item.relativeY;
1676
+ const box = {
1677
+ x: finiteRelativePlacement(x, "left", item.child, container),
1678
+ y: finiteRelativePlacement(y, "top", item.child, container),
1679
+ width: row ? outerMain : outerCross,
1680
+ height: row ? outerCross : outerMain
478
1681
  };
479
1682
  const usedStyle = {
480
1683
  ...item.normalized,
481
1684
  width: row ? item.targetMain : Math.max(0, outerCross - item.paddingCross),
482
1685
  height: row ? Math.max(0, outerCross - item.paddingCross) : item.targetMain
483
1686
  };
484
- placements.push({
1687
+ const element = childWithUsedSize(
1688
+ item.child,
1689
+ usedStyle,
1690
+ usedStyle.width,
1691
+ usedStyle.height,
1692
+ item.receiverToken,
1693
+ item.query
1694
+ );
1695
+ attachPreparedLayoutSlot(element, item.structuralBaselineSlot);
1696
+ placementsBySource[item.sourceIndex] = {
1697
+ usedWidth: usedStyle.width,
1698
+ usedHeight: usedStyle.height,
1699
+ layoutY: finiteRelativePlacement(layoutY, "top", item.child, container),
485
1700
  box,
486
- element: childWithUsedSize(
487
- item.child,
488
- usedStyle,
489
- usedStyle.width,
490
- usedStyle.height,
491
- item.receiverToken,
492
- item.query
493
- )
494
- });
1701
+ element
1702
+ };
495
1703
  mainCursor += outerMain + mainGap + distribution.between;
496
1704
  }
497
1705
  }
498
- return placements;
1706
+ for (let sourceIndex = 0; sourceIndex < placementsBySource.length; sourceIndex++) {
1707
+ if (!placementsBySource[sourceIndex]) throw new Error("Flex placement did not resolve one direct child.");
1708
+ }
1709
+ region?.pruneAbsoluteMeasurements(absoluteMeasurementTokens);
1710
+ return placementsBySource;
1711
+ }
1712
+ function resolveFlexContainingBox(style, content) {
1713
+ const resolved = style;
1714
+ const inherited = resolved[FLEX_INHERITED_CONTAINING_BOX];
1715
+ if (inherited) return inherited;
1716
+ const specified = resolved[FLEX_ABSOLUTE_BOX_STYLE] ?? style;
1717
+ if (specified.position === "static") {
1718
+ return getLogicalContainingBox();
1719
+ }
1720
+ return resolveFlexAbsolutePaddingBox(specified, content);
1721
+ }
1722
+ function resolveFlexAbsolutePaddingBox(style, content) {
1723
+ const paddingOnly = normalizeBoxInsets({
1724
+ ...style,
1725
+ borderWidth: void 0,
1726
+ borderStartWidth: void 0,
1727
+ borderEndWidth: void 0
1728
+ }, {
1729
+ component: "Flex",
1730
+ algorithm: "flex absolute",
1731
+ constraints: constraintsFor(content)
1732
+ });
1733
+ return Object.freeze({
1734
+ x: content.x - paddingOnly.left,
1735
+ y: content.y - paddingOnly.top,
1736
+ width: content.width + paddingOnly.left + paddingOnly.right,
1737
+ height: content.height + paddingOnly.top + paddingOnly.bottom
1738
+ });
1739
+ }
1740
+ function resolveAbsoluteFlexPlacement(paddingBox, child, style, receiverToken, query, content, options, measurement, region, measurementToken) {
1741
+ const left = resolveFlexInset(absoluteLeftInset(style, options.layoutDirection), "left", child, paddingBox);
1742
+ const right = resolveFlexInset(absoluteRightInset(style, options.layoutDirection), "right", child, paddingBox);
1743
+ const top = resolveFlexInset(style.top, "top", child, paddingBox);
1744
+ const bottom = resolveFlexInset(style.bottom, "bottom", child, paddingBox);
1745
+ const specifiedWidth = resolveAbsoluteSize(style.width, "width", paddingBox.width, child, paddingBox);
1746
+ const specifiedHeight = resolveAbsoluteSize(style.height, "height", paddingBox.height, child, paddingBox);
1747
+ const specifiedMinWidth = resolveAbsoluteSize(style.minWidth, "minWidth", paddingBox.width, child, paddingBox);
1748
+ const specifiedMaxWidth = resolveAbsoluteSize(style.maxWidth, "maxWidth", paddingBox.width, child, paddingBox);
1749
+ const specifiedMinHeight = resolveAbsoluteSize(style.minHeight, "minHeight", paddingBox.height, child, paddingBox);
1750
+ const specifiedMaxHeight = resolveAbsoluteSize(style.maxHeight, "maxHeight", paddingBox.height, child, paddingBox);
1751
+ const sizingStyle = specifiedWidth === style.width && specifiedHeight === style.height && specifiedMinWidth === style.minWidth && specifiedMaxWidth === style.maxWidth && specifiedMinHeight === style.minHeight && specifiedMaxHeight === style.maxHeight ? style : {
1752
+ ...style,
1753
+ width: specifiedWidth,
1754
+ height: specifiedHeight,
1755
+ minWidth: specifiedMinWidth,
1756
+ maxWidth: specifiedMaxWidth,
1757
+ minHeight: specifiedMinHeight,
1758
+ maxHeight: specifiedMaxHeight
1759
+ };
1760
+ const automaticWidth = specifiedWidth === void 0 || specifiedWidth === "auto";
1761
+ const automaticHeight = specifiedHeight === void 0 || specifiedHeight === "auto";
1762
+ let measuredWidth;
1763
+ let measuredHeight;
1764
+ if (measurement) {
1765
+ const measurementAxis = automaticWidth && automaticHeight ? "both" : automaticWidth ? "width" : "height";
1766
+ const measuredChild = clonePibblElement(child);
1767
+ const measuredStyle = child.type === Text ? measurementAxis === "both" ? { ...sizingStyle, width: void 0, height: void 0 } : measurementAxis === "width" ? { ...sizingStyle, width: void 0 } : { ...sizingStyle, height: void 0 } : sizingStyle;
1768
+ setPreNormalizedStyle(measuredChild, measuredStyle, child, receiverToken, query);
1769
+ const fixedAxis = measurementAxis === "both" ? 0 : measurementAxis === "width" ? specifiedHeight : specifiedWidth;
1770
+ const result = measureConstrainedIntrinsicElement(measuredChild, measurementAxis === "both" ? {
1771
+ minWidth: 0,
1772
+ maxWidth: Number.POSITIVE_INFINITY,
1773
+ minHeight: 0,
1774
+ maxHeight: Number.POSITIVE_INFINITY
1775
+ } : measurementAxis === "width" ? {
1776
+ minWidth: 0,
1777
+ maxWidth: Number.POSITIVE_INFINITY,
1778
+ minHeight: fixedAxis,
1779
+ maxHeight: fixedAxis
1780
+ } : {
1781
+ minWidth: fixedAxis,
1782
+ maxWidth: fixedAxis,
1783
+ minHeight: 0,
1784
+ maxHeight: Number.POSITIVE_INFINITY
1785
+ }, measurement.service, region && measurementToken ? {
1786
+ cache: region,
1787
+ token: measurementToken,
1788
+ key: measurementAxis === "both" ? `absolute-size:both:${allocationStructuralRevision()}` : `absolute-size:${measurementAxis}:${allocationStructuralRevision()}:${fixedAxis}`,
1789
+ recordMeasurement: recordWasmMeasurement
1790
+ } : void 0);
1791
+ if (result.status !== "measured") {
1792
+ throw childDiagnostic(child, measurementAxis, "auto", paddingBox, `absolute natural ${measurementAxis} requires supported pure measurement: ${result.reason}`);
1793
+ }
1794
+ if (measurementAxis !== "height") measuredWidth = result.size.width;
1795
+ if (measurementAxis !== "width") measuredHeight = result.size.height;
1796
+ }
1797
+ const settledStyle = automaticWidth || automaticHeight ? {
1798
+ ...sizingStyle,
1799
+ width: automaticWidth ? measuredWidth ?? resolveAbsoluteAutoSize(left, right, paddingBox.width, "width", child, paddingBox, sizingStyle.aspectRatio === void 0 ? void 0 : specifiedHeight * sizingStyle.aspectRatio) : specifiedWidth,
1800
+ height: automaticHeight ? measuredHeight ?? resolveAbsoluteAutoSize(top, bottom, paddingBox.height, "height", child, paddingBox, sizingStyle.aspectRatio === void 0 ? void 0 : specifiedWidth / sizingStyle.aspectRatio) : specifiedHeight
1801
+ } : sizingStyle;
1802
+ if (automaticWidth || automaticHeight) markDerivedAbsoluteAxes(settledStyle, automaticWidth, automaticHeight);
1803
+ const resolved = resolveDirectChildBox(paddingBox, child, "absolute", settledStyle, void 0, receiverToken);
1804
+ const width = resolved.borderBox.width;
1805
+ const height = resolved.borderBox.height;
1806
+ const row = isRowDirection(options.flexDirection);
1807
+ const mainReversed = (options.flexDirection === "row-reverse" || options.flexDirection === "column-reverse") !== (row && options.layoutDirection === "rtl");
1808
+ const crossReversed = options.flexWrap === "wrap-reverse" !== (!row && options.layoutDirection === "rtl");
1809
+ const x = left !== void 0 || right !== void 0 ? options.layoutDirection === "rtl" ? right === void 0 ? paddingBox.x + left : paddingBox.x + paddingBox.width - right - width : left === void 0 ? paddingBox.x + paddingBox.width - right - width : paddingBox.x + left : row ? resolveAbsoluteMainAlignment(content, width, options.justifyContent, mainReversed, true) : resolveAbsoluteCrossAlignment(content, width, options.alignItems, crossReversed, false);
1810
+ const y = top !== void 0 || bottom !== void 0 ? top === void 0 ? paddingBox.y + paddingBox.height - bottom - height : paddingBox.y + top : row ? resolveAbsoluteCrossAlignment(content, height, options.alignItems, crossReversed, true) : resolveAbsoluteMainAlignment(content, height, options.justifyContent, mainReversed, false);
1811
+ const usedWidth = resolved.contentBox.width;
1812
+ const usedHeight = resolved.contentBox.height;
1813
+ return {
1814
+ box: { x: finiteRelativePlacement(x, "left", child, paddingBox), y: finiteRelativePlacement(y, "top", child, paddingBox), width, height },
1815
+ usedWidth,
1816
+ usedHeight,
1817
+ layoutY: finiteRelativePlacement(y, "top", child, paddingBox),
1818
+ element: childWithUsedSize(child, settledStyle, usedWidth, usedHeight, receiverToken, query)
1819
+ };
1820
+ }
1821
+ function resolveAbsoluteAutoSize(start, end, available, property, child, container, aspectSize) {
1822
+ if ((start === void 0 || end === void 0) && aspectSize === void 0) {
1823
+ throw childDiagnostic(child, property, "auto", container, "PIBBL_LAYOUT_UNSUPPORTED_POSITION: automatic absolute size requires opposing physical insets or one definite aspect-ratio axis");
1824
+ }
1825
+ const size = start !== void 0 && end !== void 0 ? available - start - end : aspectSize;
1826
+ if (!Number.isFinite(size)) {
1827
+ throw childDiagnostic(child, property, size, container, "derived absolute size must remain finite");
1828
+ }
1829
+ return Math.max(0, size);
1830
+ }
1831
+ function resolveAbsoluteMainAlignment(content, size, justifyContent, reversed, horizontal) {
1832
+ let alignment = justifyContent === "flex-end" ? "flex-end" : justifyContent === "flex-start" || justifyContent === "space-between" ? "flex-start" : "center";
1833
+ if (reversed) {
1834
+ if (alignment === "flex-start") alignment = "flex-end";
1835
+ else if (alignment === "flex-end") alignment = "flex-start";
1836
+ }
1837
+ return horizontal ? content.x + alignmentOffset(alignment, content.width, size) : content.y + alignmentOffset(alignment, content.height, size);
1838
+ }
1839
+ function resolveAbsoluteCrossAlignment(content, size, alignItems, reversed, vertical) {
1840
+ let alignment = alignItems === "stretch" ? "flex-start" : alignItems;
1841
+ if (reversed) {
1842
+ if (alignment === "flex-start") alignment = "flex-end";
1843
+ else if (alignment === "flex-end") alignment = "flex-start";
1844
+ }
1845
+ return vertical ? content.y + alignmentOffset(alignment, content.height, size) : content.x + alignmentOffset(alignment, content.width, size);
1846
+ }
1847
+ function genericTextFont(style) {
1848
+ return isGenericCanvasFont(String(style.font ?? "13px sans-serif"));
1849
+ }
1850
+ function measurementStyle(style) {
1851
+ const { fill: _fill, stroke: _stroke, opacity: _opacity, cursor: _cursor, filter: _filter, ...metrics } = style;
1852
+ const owned = metrics;
1853
+ if (owned.flexDirection === "row-reverse") owned.flexDirection = "row";
1854
+ else if (owned.flexDirection === "column-reverse") owned.flexDirection = "column";
1855
+ return owned;
1856
+ }
1857
+ function intrinsicTextSnapshot(child, style, constraints) {
1858
+ if (child.type !== Flex || !isColumnDirection(style.flexDirection) || (style.flexWrap ?? "nowrap") !== "nowrap" || typeof style.width !== "number" || style.height !== void 0 && style.height !== "auto") return;
1859
+ return withSignalWriteForbidden("Signal writes are forbidden during Pibbl measurement", () => withIsolatedRenderState(() => {
1860
+ const previous = GLOBAL_STATE.primitiveReceiverToken;
1861
+ const visiting = /* @__PURE__ */ new Set();
1862
+ function visit(column, columnStyle, parent, width) {
1863
+ if (visiting.has(column)) return;
1864
+ visiting.add(column);
1865
+ GLOBAL_STATE.primitiveReceiverToken = parent;
1866
+ try {
1867
+ const snapshot = [];
1868
+ for (const [index, leaf] of prepareLayoutChildren(column.props.children, "Flex").entries()) {
1869
+ const receiver = getChildPrimitiveReceiverToken(GLOBAL_STATE.renderTransaction, parent, index);
1870
+ const prepared = prepareDirectChildStyle(leaf, receiver, { x: 0, y: 0, width, height: constraints.maxHeight });
1871
+ const leafStyle = preparedStyleValue(prepared);
1872
+ if (preparedStyleQuery(prepared) || hasPercentageBounds(leafStyle) || isPercentage(leafStyle.width) || isPercentage(leafStyle.height)) return;
1873
+ let content;
1874
+ if (leaf.type === Text) {
1875
+ if (!genericTextFont(leafStyle)) return;
1876
+ content = prepareLayoutTextContent(leaf.props, { receiverToken: receiver });
1877
+ } else if (leaf.type === Flex && isColumnDirection(leafStyle.flexDirection) && (leafStyle.flexWrap ?? "nowrap") === "nowrap" && (leafStyle.height === void 0 || leafStyle.height === "auto")) {
1878
+ const padding = normalizeBoxInsets(leafStyle, childContext(leaf, { x: 0, y: 0, width, height: constraints.maxHeight }));
1879
+ const available = typeof leafStyle.width === "number" ? leafStyle.width : Math.max(0, width - padding.left - padding.right);
1880
+ const usedWidth = clamp(available, typeof leafStyle.minWidth === "number" ? leafStyle.minWidth : 0, typeof leafStyle.maxWidth === "number" ? leafStyle.maxWidth : Infinity);
1881
+ content = visit(leaf, leafStyle, receiver, usedWidth);
1882
+ if (content === void 0) return;
1883
+ } else {
1884
+ if (typeof leafStyle.width !== "number" || typeof leafStyle.height !== "number" || !Number.isFinite(leafStyle.width) || !Number.isFinite(leafStyle.height)) return;
1885
+ content = null;
1886
+ }
1887
+ snapshot.push([leaf.key, content, measurementStyle(leafStyle)]);
1888
+ GLOBAL_STATE.primitiveReceiverToken = parent;
1889
+ }
1890
+ return [measurementStyle(columnStyle), snapshot];
1891
+ } finally {
1892
+ visiting.delete(column);
1893
+ GLOBAL_STATE.primitiveReceiverToken = parent;
1894
+ }
1895
+ }
1896
+ try {
1897
+ return visit(child, style, getPrimitiveReceiverToken(child), style.width);
1898
+ } finally {
1899
+ GLOBAL_STATE.primitiveReceiverToken = previous;
1900
+ }
1901
+ }));
1902
+ }
1903
+ function preparedRowMeasurement(child, style) {
1904
+ try {
1905
+ return withSignalWriteForbidden(
1906
+ "Signal writes are forbidden during Pibbl measurement",
1907
+ () => withStyleMeasurement("recursive", () => withIsolatedRenderState(() => {
1908
+ const previous = GLOBAL_STATE.primitiveReceiverToken;
1909
+ try {
1910
+ const root = prepareLayoutComponent(child);
1911
+ if (root.type !== Flex) return;
1912
+ const rootReceiver = getPrimitiveReceiverToken(root);
1913
+ if (!rootReceiver) return;
1914
+ GLOBAL_STATE.primitiveReceiverToken = rootReceiver;
1915
+ const rootStyle = style;
1916
+ if ((rootStyle.flexDirection ?? "row") !== "row" || (rootStyle.flexWrap ?? "nowrap") !== "nowrap" || (rootStyle.layoutDirection ?? getLayoutDirection()) !== "ltr" || typeof rootStyle.width !== "number" || !Number.isFinite(rootStyle.width) || rootStyle.width < 0 || rootStyle.height !== void 0 && rootStyle.height !== "auto") return;
1917
+ const snapshot = ["prepared-row", root.type, root.key];
1918
+ if (!appendPreparedProgramSnapshot(snapshot, getPrimitiveProgramProps(child))) return;
1919
+ if (!appendPreparedProgramSnapshot(snapshot, getPrimitiveProgramProps(root), true)) return;
1920
+ if (!appendPreparedStyleSnapshot(snapshot, rootStyle)) return;
1921
+ const children = prepareLayoutChildren(root.props.children, "Flex");
1922
+ snapshot.push(children.length);
1923
+ const receivers = [];
1924
+ for (let index = 0; index < children.length; index++) {
1925
+ const leaf = children[index];
1926
+ const directReceiver = getChildPrimitiveReceiverToken(GLOBAL_STATE.renderTransaction, rootReceiver, index);
1927
+ const directPrepared = prepareDirectChildStyle(leaf, directReceiver, void 0, true);
1928
+ if (preparedStyleQuery(directPrepared)) return;
1929
+ const directStyle = preparedStyleValue(directPrepared);
1930
+ let measuredLeaf = leaf;
1931
+ let receiver = directReceiver;
1932
+ let wrapped = false;
1933
+ if (isLayoutComponent(leaf.type)) {
1934
+ measuredLeaf = prepareLayoutComponent(leaf, { receiverToken: directReceiver });
1935
+ if (isLayoutComponent(measuredLeaf.type)) return;
1936
+ const preparedReceiver = getPrimitiveReceiverToken(measuredLeaf);
1937
+ if (!preparedReceiver) return;
1938
+ receiver = preparedReceiver;
1939
+ wrapped = true;
1940
+ }
1941
+ const paired = getPrimitiveDefinition(measuredLeaf.type);
1942
+ const emptyRectangle = !wrapped && measuredLeaf.type === Rectangle && !Object.hasOwn(measuredLeaf.props, "children");
1943
+ if (!emptyRectangle && !(paired?.measureIntrinsic && paired.measure)) return;
1944
+ if (!appendPreparedProgramSnapshot(snapshot, getPrimitiveProgramProps(leaf)) || !appendPreparedStyleSnapshot(snapshot, directStyle) || wrapped && !appendPreparedProgramSnapshot(snapshot, getPrimitiveProgramProps(measuredLeaf))) return;
1945
+ snapshot.push(index, leaf.type, leaf.key, wrapped, measuredLeaf.type, measuredLeaf.key);
1946
+ receivers.push(receiver);
1947
+ }
1948
+ return { snapshot, receivers };
1949
+ } finally {
1950
+ GLOBAL_STATE.primitiveReceiverToken = previous;
1951
+ }
1952
+ }))
1953
+ );
1954
+ } catch (error) {
1955
+ if (error instanceof UnsupportedResponsiveMeasurement) return void 0;
1956
+ throw error;
1957
+ }
1958
+ }
1959
+ function appendPreparedProgramSnapshot(snapshot, props, omitChildren = false) {
1960
+ const keys = Reflect.ownKeys(props);
1961
+ let count = 0;
1962
+ for (let index = 0; index < keys.length; index++) if (!omitChildren || keys[index] !== "children") count++;
1963
+ snapshot.push(count);
1964
+ for (let index = 0; index < keys.length; index++) {
1965
+ const key = keys[index];
1966
+ if (omitChildren && key === "children") continue;
1967
+ const value = props[key];
1968
+ if (typeof value === "function" || value !== null && typeof value === "object" && !isSignal(value)) return false;
1969
+ snapshot.push(key, value);
1970
+ }
1971
+ return true;
1972
+ }
1973
+ function appendPreparedStyleSnapshot(snapshot, style) {
1974
+ const keys = Reflect.ownKeys(style);
1975
+ snapshot.push(keys.length);
1976
+ for (let index = 0; index < keys.length; index++) {
1977
+ const key = keys[index];
1978
+ const value = style[key];
1979
+ if (typeof value === "function" || value !== null && typeof value === "object") return false;
1980
+ snapshot.push(key, value);
1981
+ }
1982
+ return true;
1983
+ }
1984
+ function currentFlexMeasurementInput() {
1985
+ const context = GLOBAL_STATE.renderContext;
1986
+ if (!context) throw new Error("A mounted Flex query requires its current Canvas context.");
1987
+ const service = canvasMeasurementService(context);
1988
+ return { service, measureElement: (element, constraints) => measureElement(element, constraints, service) };
1989
+ }
1990
+ function bindFlexMeasurementInput(input) {
1991
+ return isCurrentCanvasMeasurementService(input.service) ? currentFlexMeasurementInput : () => input;
1992
+ }
1993
+ function measureTextIntrinsicWidths(child, style, receiver, measurement, region) {
1994
+ const resolveMeasurement = bindFlexMeasurementInput(measurement);
1995
+ const element = clonePibblElement(child);
1996
+ setPreNormalizedStyle(element, style, child, receiver);
1997
+ return allocationMeasurement(element, (current) => {
1998
+ const measurement2 = resolveMeasurement();
1999
+ const normalized = peekPreNormalizedStyle(current).style;
2000
+ const receiverToken = getPrimitiveReceiverToken(current);
2001
+ const font = normalized.font ?? "13px sans-serif";
2002
+ const content = prepareLayoutTextContent(current.props, { receiverToken });
2003
+ if (region) recordWasmMeasurement();
2004
+ const maximum = normalized.wrap === true ? measureLayoutTextNaturalRun(content, { font, service: measurement2.service }) : measurement2.service.measureText(content, font).width;
2005
+ const minimum = normalized.wrap === true ? measureLayoutTextMinimumWidth(current.props, { font, service: measurement2.service, receiverToken }) : maximum;
2006
+ return { minimum, maximum };
2007
+ });
2008
+ }
2009
+ function measureTextContentMinimum(child, style, receiver, measurement, region) {
2010
+ const resolveMeasurement = bindFlexMeasurementInput(measurement);
2011
+ const element = clonePibblElement(child);
2012
+ setPreNormalizedStyle(element, style, child, receiver);
2013
+ return allocationMeasurement(element, (current) => {
2014
+ const measurement2 = resolveMeasurement();
2015
+ const normalized = peekPreNormalizedStyle(current).style;
2016
+ const receiverToken = getPrimitiveReceiverToken(current);
2017
+ const font = normalized.font ?? "13px sans-serif";
2018
+ if (region) recordWasmMeasurement();
2019
+ return normalized.wrap === true ? measureLayoutTextMinimumWidth(current.props, { font, service: measurement2.service, receiverToken }) : measurement2.service.measureText(prepareLayoutTextContent(current.props, { receiverToken }), font).width;
2020
+ });
2021
+ }
2022
+ function measureTextNaturalWidth(child, style, receiver, token, measurement, region) {
2023
+ const resolveMeasurement = bindFlexMeasurementInput(measurement);
2024
+ const element = clonePibblElement(child);
2025
+ setPreNormalizedStyle(element, style, child, receiver);
2026
+ return allocationMeasurement(element, (current) => {
2027
+ const measurement2 = resolveMeasurement();
2028
+ const normalized = peekPreNormalizedStyle(current).style;
2029
+ const receiverToken = getPrimitiveReceiverToken(current);
2030
+ const font = normalized.font ?? "13px sans-serif";
2031
+ const content = prepareLayoutTextContent(current.props, { receiverToken });
2032
+ let width = genericTextFont(normalized) ? region?.readTextMaximum(token, content, font) : void 0;
2033
+ if (width === void 0) {
2034
+ if (region) recordWasmMeasurement();
2035
+ width = normalized.wrap === true ? measureLayoutTextNaturalRun(content, { font, service: measurement2.service }) : measurement2.service.measureText(content, font).width;
2036
+ if (genericTextFont(normalized)) region?.writeTextMaximum(token, content, font, width);
2037
+ }
2038
+ return width;
2039
+ });
2040
+ }
2041
+ function prepareLayoutTextContent(props, options) {
2042
+ declineUnrecordedAllocationMeasurement();
2043
+ return readLayoutTextContent(props, options);
2044
+ }
2045
+ function measureFlexChild(child, constraints, style, token, measurement, region, query, constrainedProvider = false, parentMainAxis, ordinaryProvider = false) {
2046
+ const resolveMeasurement = bindFlexMeasurementInput(measurement);
2047
+ return allocationMeasurement(child, (current) => measureFlexChildUncached(
2048
+ current,
2049
+ constraints,
2050
+ peekPreNormalizedStyle(current)?.style ?? style,
2051
+ token,
2052
+ resolveMeasurement(),
2053
+ region,
2054
+ query,
2055
+ constrainedProvider,
2056
+ parentMainAxis,
2057
+ ordinaryProvider
2058
+ ));
2059
+ }
2060
+ function measureFlexChildUncached(child, constraints, style, token, measurement, region, query, constrainedProvider = false, parentMainAxis, ordinaryProvider = false) {
2061
+ const measuredRoot = !query && isLayoutComponent(child.type) && (constrainedProvider || ordinaryProvider || parentMainAxis !== void 0) ? prepareLayoutComponent(child) : child;
2062
+ const rootAxis = style.flexDirection === "column" || style.flexDirection === "column-reverse" ? "column" : "row";
2063
+ const contributionReceiver = parentMainAxis !== void 0 && measuredRoot.type === Flex && rootAxis === parentMainAxis ? getPrimitiveReceiverToken(measuredRoot) : void 0;
2064
+ if (contributionReceiver) {
2065
+ const previousContribution = requestedIntrinsicContribution;
2066
+ requestedIntrinsicContribution = { receiver: contributionReceiver, axis: parentMainAxis, normalOwner: true };
2067
+ try {
2068
+ if (region) recordWasmMeasurement();
2069
+ return measurement.measureElement(child, constraints);
2070
+ } finally {
2071
+ requestedIntrinsicContribution = previousContribution;
2072
+ }
2073
+ }
2074
+ if (region && !query && isLayoutComponent(child.type)) {
2075
+ const prepared = preparedRowMeasurement(child, style);
2076
+ if (prepared) {
2077
+ return measurePreparedLayoutElement(child, constraints, measurement.service, {
2078
+ cache: region,
2079
+ token,
2080
+ key: JSON.stringify(["prepared-row", allocationStructuralRevision(), measurementStyle(style), constraints]),
2081
+ recordMeasurement: recordWasmMeasurement
2082
+ }, prepared.snapshot, prepared.receivers);
2083
+ }
2084
+ }
2085
+ const definition = (constrainedProvider || ordinaryProvider) && !query ? getPrimitiveDefinition(measuredRoot.type) : void 0;
2086
+ if (measuredRoot.type !== Text && !isKnownLayoutType(measuredRoot.type) && definition?.measure && (definition.measureIntrinsic || ordinaryProvider)) return measureConstrainedIntrinsicElement(child, constraints, measurement.service, region ? { cache: region, token, key: JSON.stringify([allocationStructuralRevision(), measurementStyle(style), constraints]), recordMeasurement: recordWasmMeasurement } : void 0);
2087
+ const content = region && child.type === Text ? prepareLayoutTextContent(
2088
+ child.props,
2089
+ { receiverToken: getPrimitiveReceiverToken(child) }
2090
+ ) : void 0;
2091
+ const intrinsic = region && !query ? intrinsicTextSnapshot(child, style, constraints) : void 0;
2092
+ const cacheable = !query && (content !== void 0 && genericTextFont(style) || intrinsic !== void 0);
2093
+ const key = cacheable ? JSON.stringify([content, intrinsic, measurementStyle(style), constraints]) : void 0;
2094
+ const cached = key ? region.readMeasurement(token, key) : void 0;
2095
+ if (cached) return { status: "measured", size: cached };
2096
+ if (region) recordWasmMeasurement();
2097
+ const result = measurement.measureElement(child, constraints);
2098
+ if (key && result.status === "measured") region.writeMeasurement(token, key, result.size);
2099
+ return result;
499
2100
  }
500
2101
  function collectLines(items, mainSize, gap, wrap) {
501
2102
  const lines = [];
@@ -519,16 +2120,12 @@ function collectLines(items, mainSize, gap, wrap) {
519
2120
  }
520
2121
  function resolveFlexibleLengths(line, mainSize, gap) {
521
2122
  const gapSpace = Math.max(0, line.items.length - 1) * gap;
522
- const baseOuter = line.items.reduce(
523
- (total, item) => total + item.baseMain + item.paddingMain,
524
- 0
525
- );
526
2123
  const hypotheticalOuter = line.items.reduce(
527
2124
  (total, item) => total + clamp(item.baseMain, item.minMain, item.maxMain) + item.paddingMain,
528
2125
  0
529
2126
  );
530
2127
  const growing = hypotheticalOuter + gapSpace < mainSize;
531
- const initialFree = mainSize - gapSpace - baseOuter;
2128
+ let initialOuter = gapSpace;
532
2129
  const frozen = /* @__PURE__ */ new Set();
533
2130
  for (const item of line.items) {
534
2131
  item.targetMain = item.baseMain;
@@ -537,7 +2134,10 @@ function resolveFlexibleLengths(line, mainSize, gap) {
537
2134
  item.targetMain = hypothetical;
538
2135
  frozen.add(item);
539
2136
  }
2137
+ initialOuter += item.targetMain + item.paddingMain;
540
2138
  }
2139
+ const initialFree = mainSize - initialOuter;
2140
+ if (!Number.isFinite(initialFree)) throw new Error("Flex numeric overflow during allocation");
541
2141
  while (frozen.size < line.items.length) {
542
2142
  const fixed = line.items.reduce(
543
2143
  (total, item) => total + (frozen.has(item) ? item.targetMain : item.baseMain) + item.paddingMain,
@@ -546,7 +2146,10 @@ function resolveFlexibleLengths(line, mainSize, gap) {
546
2146
  let free = mainSize - fixed;
547
2147
  const unfrozen = line.items.filter((item) => !frozen.has(item));
548
2148
  const rawFactor = growing ? unfrozen.reduce((total, item) => total + item.grow, 0) : unfrozen.reduce((total, item) => total + item.shrink, 0);
549
- const scaledFactor = growing ? rawFactor : unfrozen.reduce((total, item) => total + item.shrink * item.baseMain, 0);
2149
+ const maxFactor = unfrozen.reduce((max, item) => Math.max(max, growing ? item.grow : item.shrink), 0);
2150
+ const maxBasis = growing ? 1 : unfrozen.reduce((max, item) => Math.max(max, item.baseMain), 0);
2151
+ const weight = (item) => maxFactor === 0 || maxBasis === 0 ? 0 : (growing ? item.grow : item.shrink) / maxFactor * (growing ? 1 : item.baseMain / maxBasis);
2152
+ const scaledFactor = unfrozen.reduce((total, item) => total + weight(item), 0);
550
2153
  if (scaledFactor === 0) {
551
2154
  for (const item of unfrozen) {
552
2155
  item.targetMain = clamp(item.baseMain, item.minMain, item.maxMain);
@@ -560,8 +2163,9 @@ function resolveFlexibleLengths(line, mainSize, gap) {
560
2163
  }
561
2164
  const violations = [];
562
2165
  for (const item of unfrozen) {
563
- const share = growing ? item.grow / scaledFactor : item.shrink * item.baseMain / scaledFactor;
2166
+ const share = weight(item) / scaledFactor;
564
2167
  const candidate = item.baseMain + free * share;
2168
+ if (!Number.isFinite(candidate)) throw new Error("Flex numeric overflow during allocation");
565
2169
  const clamped = clamp(candidate, item.minMain, item.maxMain);
566
2170
  item.targetMain = clamped;
567
2171
  if (clamped !== candidate) {
@@ -612,7 +2216,7 @@ function distributeAlignment(alignment, free, count) {
612
2216
  }
613
2217
  if (free < 0) {
614
2218
  if (alignment === "flex-end") return { start: free, between: 0 };
615
- if (alignment === "center" || alignment === "space-around" || alignment === "space-evenly") {
2219
+ if (alignment === "center") {
616
2220
  return { start: free / 2, between: 0 };
617
2221
  }
618
2222
  return { start: 0, between: 0 };
@@ -632,47 +2236,249 @@ function distributeAlignment(alignment, free, count) {
632
2236
  }
633
2237
  return { start: 0, between: 0 };
634
2238
  }
2239
+ function prepareKnownStructuralBaseline(item, container, measurement, parentSlot, lastSource = false) {
2240
+ const root = item.baselineRoot ?? item.child;
2241
+ if (root.type !== Flex && root.type !== Flow && root.type !== Grid) return;
2242
+ const resolveMeasurement = bindFlexMeasurementInput(measurement);
2243
+ const { targetMain, preferredCross, paddingCross, layoutOccurrence } = item;
2244
+ const child = clonePibblElement(item.child);
2245
+ setPreNormalizedStyle(child, item.normalized, item.child, item.receiverToken, item.query);
2246
+ const offset = allocationMeasurement(child, (current) => {
2247
+ const normalized = peekPreNormalizedStyle(current).style;
2248
+ const receiverToken = getPrimitiveReceiverToken(current);
2249
+ if (!receiverToken) throw new Error("A structural baseline query requires its current receiver.");
2250
+ const baselineRoot = isLayoutComponent(current.type) ? prepareLayoutComponent(current, { receiverToken }) : current;
2251
+ return prepareKnownStructuralBaselineUncached({
2252
+ child: current,
2253
+ normalized,
2254
+ receiverToken,
2255
+ baselineRoot,
2256
+ targetMain,
2257
+ preferredCross,
2258
+ paddingCross,
2259
+ layoutOccurrence
2260
+ }, container, resolveMeasurement(), parentSlot, lastSource).offset;
2261
+ });
2262
+ const slot = currentPreparedReceiverSlot(item.receiverToken);
2263
+ if (!slot) throw new Error("A structural baseline demand must stage its current receiver allocation.");
2264
+ return { slot, offset };
2265
+ }
2266
+ function prepareKnownStructuralBaselineUncached(item, container, measurement, parentSlot, lastSource) {
2267
+ const alignment = lastSource ? "last-baseline" : "first-baseline";
2268
+ const root = item.baselineRoot ?? item.child;
2269
+ const style = item.normalized;
2270
+ const staticOwner = root.type === Flex && style.position === "static";
2271
+ const content = { x: 0, y: 0, width: item.targetMain, height: Math.max(0, item.preferredCross - item.paddingCross) };
2272
+ const direction = style.layoutDirection ?? getLayoutDirection();
2273
+ const currentSlot = currentPreparedReceiverSlot(item.receiverToken);
2274
+ const currentPlan = currentSlot && peekPreparedLayoutPlan(currentSlot, content, direction);
2275
+ const slot = currentPlan ? currentSlot : preflightKnownLayout(
2276
+ item.child,
2277
+ item.normalized,
2278
+ content,
2279
+ item.receiverToken,
2280
+ item.layoutOccurrence,
2281
+ parentSlot,
2282
+ "row",
2283
+ staticOwner ? { deferStaticContainingDescendants: true } : void 0
2284
+ );
2285
+ if (!slot) throw childDiagnostic(
2286
+ item.child,
2287
+ "alignItems",
2288
+ alignment,
2289
+ container,
2290
+ "PIBBL_LAYOUT_UNSUPPORTED_BASELINE: the selected known layout root did not prepare its allocation"
2291
+ );
2292
+ const plan = root.type === Flex ? peekPreparedFlexPlan(slot, content, direction) : peekPreparedLayoutPlan(slot, content, direction);
2293
+ if (!plan) throw childDiagnostic(
2294
+ item.child,
2295
+ "alignItems",
2296
+ alignment,
2297
+ container,
2298
+ "PIBBL_LAYOUT_UNSUPPORTED_BASELINE: the selected known layout root has no current settled allocation"
2299
+ );
2300
+ return { slot, offset: readPreparedKnownBaseline(
2301
+ plan,
2302
+ root.type === Flex ? "flex" : root.type === Flow ? "flow" : "grid",
2303
+ measurement,
2304
+ direction,
2305
+ root.type === Flex && (style.flexWrap ?? "nowrap") !== "nowrap",
2306
+ lastSource
2307
+ ) };
2308
+ }
2309
+ function readPreparedKnownBaseline(plan, kind, measurement, direction, wrapped, lastSource) {
2310
+ const alignment = lastSource ? "last-baseline" : "first-baseline";
2311
+ const content = plan.content;
2312
+ const flexPlan = kind === "flex" ? plan : void 0;
2313
+ const lineCount = wrapped ? lastSource ? flexPlan.region.lastWrapLineCount() : flexPlan.region.firstWrapLineCount() : void 0;
2314
+ const pending = flexPlan ? deferredStaticState(flexPlan) : void 0;
2315
+ const step = lastSource ? -1 : 1;
2316
+ for (let index = lastSource ? plan.children.length - 1 : 0; index >= 0 && index < plan.children.length; index += step) {
2317
+ if (pending?.slots[index]) continue;
2318
+ const source = plan.children[index];
2319
+ const placement = plan.placements[index];
2320
+ const prepared = peekPreNormalizedStyle(placement.element);
2321
+ if (!prepared) throw new Error("Known Flex baseline selection requires settled child inputs.");
2322
+ const selectedStyle = prepared.style;
2323
+ if (selectedStyle.position === "absolute") continue;
2324
+ if (lineCount === 0) throw new Error("Structural baseline source has no native endpoint-line membership.");
2325
+ const receiver = getPrimitiveReceiverToken(placement.element);
2326
+ const root = isLayoutComponent(source.type) ? prepareLayoutComponent(source, { receiverToken: receiver }) : placement.element;
2327
+ const usedWidth = "usedWidth" in placement ? placement.usedWidth : void 0;
2328
+ const usedHeight = "usedHeight" in placement ? placement.usedHeight : void 0;
2329
+ if (typeof usedWidth !== "number" || !Number.isFinite(usedWidth) || usedWidth < 0 || typeof usedHeight !== "number" || !Number.isFinite(usedHeight) || usedHeight < 0) {
2330
+ throw new Error("Prepared known baseline placement is missing settled content geometry.");
2331
+ }
2332
+ const allocation = { x: 0, y: 0, width: usedWidth, height: usedHeight };
2333
+ const insets = normalizeBoxInsets(selectedStyle, childContext(source, content));
2334
+ let offset = allocation.height;
2335
+ if (root.type === Flex || root.type === Flow || root.type === Grid) {
2336
+ const slot = getElementMetadata(placement.element)?.preparedLayoutSlot;
2337
+ const childDirection = selectedStyle.layoutDirection ?? direction;
2338
+ const nested = root.type === Flex ? slot && peekPreparedFlexPlan(slot, allocation, childDirection) : slot && peekPreparedLayoutPlan(slot, allocation, childDirection);
2339
+ if (!nested) throw childDiagnostic(
2340
+ source,
2341
+ "alignItems",
2342
+ alignment,
2343
+ content,
2344
+ "PIBBL_LAYOUT_UNSUPPORTED_BASELINE: selected known layout root requires its current prepared allocation"
2345
+ );
2346
+ offset = readPreparedKnownBaseline(
2347
+ nested,
2348
+ root.type === Flex ? "flex" : root.type === Flow ? "flow" : "grid",
2349
+ measurement,
2350
+ childDirection,
2351
+ root.type === Flex && (selectedStyle.flexWrap ?? "nowrap") !== "nowrap",
2352
+ lastSource
2353
+ );
2354
+ } else {
2355
+ const definition = getPrimitiveDefinition(root.type);
2356
+ if (!definition || isKnownLayoutType(root.type)) throw childDiagnostic(
2357
+ source,
2358
+ "alignItems",
2359
+ alignment,
2360
+ content,
2361
+ "PIBBL_LAYOUT_UNSUPPORTED_BASELINE: selected structural source must resolve to a primitive or prepared known layout root"
2362
+ );
2363
+ if (definition.measureBaselines) {
2364
+ const measurementChild = clonePibblElement(root);
2365
+ setPreNormalizedStyle(measurementChild, selectedStyle, root, getPrimitiveReceiverToken(root) ?? receiver, prepared.query);
2366
+ if (prepared.query) setPreparedBaselineOwner(measurementChild, content);
2367
+ const result = measureBaselineElement(measurementChild, allocation, measurement.service);
2368
+ if (result.status === "unsupported") throw childDiagnostic(
2369
+ source,
2370
+ "measureBaselines",
2371
+ "unsupported",
2372
+ content,
2373
+ `${alignment} alignment requires a baseline result: ${result.reason}`
2374
+ );
2375
+ offset = lastSource ? result.last : result.first;
2376
+ }
2377
+ }
2378
+ const layoutY = kind === "flex" ? placement.layoutY : placement.box.y;
2379
+ if (!Number.isFinite(layoutY)) throw new Error("Prepared known baseline placement has no finite physical y origin.");
2380
+ return layoutY + insets.top + offset;
2381
+ }
2382
+ if (lineCount !== void 0 && lineCount !== 0) throw new Error("Empty structural baseline source disagrees with native endpoint-line membership.");
2383
+ return content.height;
2384
+ }
2385
+ function assertSupportedBaselineFlex(options, items, container, mounted) {
2386
+ const alignment = options[FLEX_LAST_BASELINE] ? "last-baseline" : "first-baseline";
2387
+ if (!mounted || !nativeLayout || !isRowDirection(options.flexDirection)) {
2388
+ throw optionDiagnostic("alignItems", alignment, container, "requires mounted experimental horizontal Flex");
2389
+ }
2390
+ for (const item of items) {
2391
+ const style = item.normalized;
2392
+ const baselineRoot = isLayoutComponent(item.child.type) ? prepareLayoutComponent(item.child, { receiverToken: item.receiverToken }) : item.child;
2393
+ if (baselineRoot !== item.child) item.baselineRoot = baselineRoot;
2394
+ if (baselineRoot.type === Flex || baselineRoot.type === Flow || baselineRoot.type === Grid) {
2395
+ if (item.crossAuto || !Number.isFinite(item.targetMain) || item.targetMain < 0 || !Number.isFinite(item.preferredCross) || item.preferredCross < item.paddingCross) {
2396
+ throw childDiagnostic(
2397
+ item.child,
2398
+ "alignItems",
2399
+ alignment,
2400
+ container,
2401
+ "PIBBL_LAYOUT_UNSUPPORTED_BASELINE: a structural baseline requires settled finite known-layout geometry"
2402
+ );
2403
+ }
2404
+ continue;
2405
+ }
2406
+ const textLeaf = baselineRoot.type === Text;
2407
+ const textStyle = style;
2408
+ const fontSize = textLeaf ? /(?:^| )(\d+(?:\.\d+)?)px(?:\s*\/\s*(?:normal|\d+(?:\.\d+)?(?:px|%)?))?\s+\S/.exec(String(textStyle.font ?? "13px sans-serif")) : null;
2409
+ const supportedTextLeaf = !textLeaf || fontSize !== null && Number.isFinite(Number(fontSize[1])) && Number(fontSize[1]) > 0 && typeof (textStyle.lineHeight ?? 13) === "number" && Number.isFinite(textStyle.lineHeight ?? 13) && (textStyle.lineHeight ?? 13) >= 0 && (textStyle.wrap === void 0 || typeof textStyle.wrap === "boolean");
2410
+ const sharesBaseline = item.alignSelf === "auto" && !item.autoCrossBefore && !item.autoCrossAfter;
2411
+ if (!getPrimitiveDefinition(baselineRoot.type) || isKnownLayoutType(baselineRoot.type) || isLayoutComponent(baselineRoot.type) || !supportedTextLeaf && sharesBaseline || style.position !== void 0 && style.position !== "static" && style.position !== "relative" || item.crossAuto && item.alignSelf !== "stretch" || !Number.isFinite(item.targetMain) || item.targetMain < 0 || !Number.isFinite(item.preferredCross) || item.preferredCross < item.paddingCross) {
2412
+ throw childDiagnostic(item.child, "alignItems", alignment, container, "PIBBL_LAYOUT_UNSUPPORTED_BASELINE: requires primitive roots with settled finite content boxes and no absolute position");
2413
+ }
2414
+ }
2415
+ }
2416
+ function isRowDirection(direction) {
2417
+ return direction === void 0 || direction === "row" || direction === "row-reverse";
2418
+ }
2419
+ function isColumnDirection(direction) {
2420
+ return direction === "column" || direction === "column-reverse";
2421
+ }
635
2422
  function normalizeFlexOptions(style, container) {
636
- const flexDirection = supported(style.flexDirection ?? "row", ["row", "column"], "flexDirection", container);
637
- const flexWrap = supported(style.flexWrap ?? "nowrap", ["nowrap", "wrap"], "flexWrap", container);
2423
+ const layoutDirection = style.layoutDirection ?? getLayoutDirection();
2424
+ if (layoutDirection !== "ltr" && !(nativeLayout && layoutDirection === "rtl")) {
2425
+ throw optionDiagnostic("layoutDirection", layoutDirection, container);
2426
+ }
2427
+ const flexDirection = style.flexDirection ?? "row";
2428
+ if (flexDirection !== "row" && flexDirection !== "column" && !(nativeLayout && (flexDirection === "row-reverse" || flexDirection === "column-reverse"))) {
2429
+ throw optionDiagnostic("flexDirection", flexDirection, container, "uses an unsupported flex direction in this build");
2430
+ }
2431
+ const flexWrap = style.flexWrap ?? "nowrap";
2432
+ if (flexWrap !== "nowrap" && flexWrap !== "wrap" && !(nativeLayout && flexWrap === "wrap-reverse")) {
2433
+ throw optionDiagnostic("flexWrap", flexWrap, container, "uses an unsupported flex wrap in this build");
2434
+ }
638
2435
  const justifyContent = supported(
639
- style.justifyContent ?? "flex-start",
2436
+ normalizeLogicalAlignment(style.justifyContent ?? "flex-start", flexDirection === "row-reverse" || flexDirection === "column-reverse"),
640
2437
  ["flex-start", "flex-end", "center", "space-between", "space-around", "space-evenly"],
641
2438
  "justifyContent",
642
2439
  container
643
2440
  );
2441
+ const requestedAlignItems = normalizeLogicalAlignment(style[FLEX_LAST_BASELINE] ? "last-baseline" : style[FLEX_BASELINE_GROUP] ? "first-baseline" : style.alignItems ?? "stretch", flexWrap === "wrap-reverse");
644
2442
  const alignItems = supported(
645
- style.alignItems ?? "stretch",
646
- ["stretch", "flex-start", "flex-end", "center"],
2443
+ requestedAlignItems,
2444
+ nativeLayout ? ["stretch", "flex-start", "flex-end", "center", "first-baseline", "last-baseline"] : ["stretch", "flex-start", "flex-end", "center"],
647
2445
  "alignItems",
648
2446
  container
649
2447
  );
650
2448
  const alignContent = supported(
651
- style.alignContent ?? "stretch",
2449
+ normalizeLogicalAlignment(style.alignContent ?? "stretch", flexWrap === "wrap-reverse"),
652
2450
  ["stretch", "flex-start", "flex-end", "center", "space-between", "space-around", "space-evenly"],
653
2451
  "alignContent",
654
2452
  container
655
2453
  );
656
- const gap = nonnegativeGap(style.gap ?? 0, "gap", container);
2454
+ const gap = style.gap ?? 0;
2455
+ const columnGap = nonnegativeGap(gap, "gap", container, container.width);
2456
+ const rowGap = typeof gap === "number" ? columnGap : nonnegativeGap(gap, "gap", container, container.height);
657
2457
  return {
2458
+ layoutDirection,
658
2459
  flexDirection,
659
2460
  flexWrap,
660
2461
  justifyContent,
661
- alignItems,
2462
+ // Yoga resolves baseline alignment on column axes to logical flex-start
2463
+ // before placement. It neither measures nor forms a vertical baseline group.
2464
+ alignItems: alignItems === "first-baseline" ? "flex-start" : alignItems === "last-baseline" ? isRowDirection(flexDirection) ? "flex-start" : "flex-end" : alignItems,
2465
+ [FLEX_BASELINE_GROUP]: (alignItems === "first-baseline" || alignItems === "last-baseline") && isRowDirection(flexDirection),
2466
+ [FLEX_LAST_BASELINE]: alignItems === "last-baseline" && isRowDirection(flexDirection),
662
2467
  alignContent,
663
- rowGap: nonnegativeGap(style.rowGap ?? gap, "rowGap", container),
664
- columnGap: nonnegativeGap(style.columnGap ?? gap, "columnGap", container)
2468
+ rowGap: style.rowGap === void 0 ? rowGap : nonnegativeGap(style.rowGap, "rowGap", container, container.height),
2469
+ columnGap: style.columnGap === void 0 ? columnGap : nonnegativeGap(style.columnGap, "columnGap", container, container.width)
665
2470
  };
666
2471
  }
667
2472
  function supported(value, accepted, property, container) {
668
2473
  if (!accepted.includes(value)) throw optionDiagnostic(property, value, container);
669
2474
  return value;
670
2475
  }
671
- function nonnegativeGap(value, property, container) {
672
- if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
2476
+ function nonnegativeGap(value, property, container, reference) {
2477
+ const resolved = nativeLayout && isPercentage(value) ? resolveScalarSizingLength(value, reference, property, { component: "Flex", algorithm: "flex", constraints: constraintsFor(container) }) : value;
2478
+ if (typeof resolved !== "number" || !Number.isFinite(resolved) || resolved < 0) {
673
2479
  throw optionDiagnostic(property, value, container);
674
2480
  }
675
- return value;
2481
+ return resolved;
676
2482
  }
677
2483
  function nonnegativeFactor(value, property, child, container) {
678
2484
  if (!Number.isFinite(value) || value < 0) {
@@ -686,6 +2492,25 @@ function nonnegativeFactor(value, property, child, container) {
686
2492
  }
687
2493
  return value;
688
2494
  }
2495
+ function resolveIntrinsicMainBound(value, minimum, maximum, property, reference, child, container) {
2496
+ if (minimum === void 0 || maximum === void 0) {
2497
+ throw childDiagnostic(child, property, value, container, "requires a direct finite horizontal Flex intrinsic-sizing owner");
2498
+ }
2499
+ const request = normalizeSizingLength(value, {
2500
+ reference,
2501
+ property,
2502
+ context: childContext(child, container),
2503
+ allowAuto: false,
2504
+ allowIntrinsic: true
2505
+ });
2506
+ return resolveIntrinsicMainBasis(request, minimum, maximum, child, container);
2507
+ }
2508
+ function resolveIntrinsicMainBasis(request, minimum, maximum, child, container) {
2509
+ if (request.kind === "min-content") return minimum;
2510
+ if (request.kind === "max-content") return maximum;
2511
+ if (request.kind === "fit-content") return Math.min(maximum, Math.max(minimum, request.limit));
2512
+ throw childDiagnostic(child, "flexBasis", request, container, "requires min-content, max-content or fit-content");
2513
+ }
689
2514
  function resolveBasis(basis, specifiedMain, measuredMain, reference, property, child, container) {
690
2515
  const value = basis === "auto" || basis === void 0 ? specifiedMain : basis;
691
2516
  if (value === void 0 || value === "auto") {
@@ -703,7 +2528,7 @@ function resolveBasis(basis, specifiedMain, measuredMain, reference, property, c
703
2528
  return resolveItemLength(value, reference, "flexBasis", child, container);
704
2529
  }
705
2530
  function resolveItemLength(value, reference, property, child, container) {
706
- const resolved = resolveLength(value, reference, property, childContext(child, container));
2531
+ const resolved = resolveScalarSizingLength(value, reference, property, childContext(child, container));
707
2532
  if (resolved === void 0 || resolved < 0) {
708
2533
  throw childDiagnostic(
709
2534
  child,
@@ -719,8 +2544,15 @@ function resolveOptionalBound(value, reference, property, fallback, child, conta
719
2544
  if (value === void 0) return fallback;
720
2545
  return resolveItemLength(value, reference, property, child, container);
721
2546
  }
722
- function normalizeItemAlignment(value, child, container) {
2547
+ function normalizeLogicalAlignment(value, reversed) {
2548
+ if (value === "start") return reversed ? "flex-end" : "flex-start";
2549
+ if (value === "end") return reversed ? "flex-start" : "flex-end";
2550
+ return value;
2551
+ }
2552
+ function normalizeItemAlignment(value, child, container, reverseCross = false) {
723
2553
  if (value === void 0 || value === "auto") return "auto";
2554
+ if (value === "start") return reverseCross ? "flex-end" : "flex-start";
2555
+ if (value === "end") return reverseCross ? "flex-start" : "flex-end";
724
2556
  if (value === "stretch" || value === "flex-start" || value === "flex-end" || value === "center") return value;
725
2557
  throw childDiagnostic(
726
2558
  child,
@@ -738,8 +2570,87 @@ function alignmentOffset(alignment, lineSize, itemSize) {
738
2570
  if (alignment === "flex-end") return lineSize - itemSize;
739
2571
  return 0;
740
2572
  }
2573
+ function finiteRelativePlacement(value, property, child, container) {
2574
+ if (!Number.isFinite(value)) {
2575
+ throw childDiagnostic(child, property, value, container, "resolved relative placement arithmetic must remain finite");
2576
+ }
2577
+ return value;
2578
+ }
2579
+ function assertSupportedAbsoluteFlexPosition(child, style, container, direction, query, naturalWidth = false, naturalHeight = false) {
2580
+ if (isKnownLayoutType(child.type) || isLayoutComponent(child.type)) {
2581
+ throw childDiagnostic(child, "position", style.position, container, "PIBBL_LAYOUT_UNSUPPORTED_POSITION: absolute layout children and nested containing blocks are not supported in this slice");
2582
+ }
2583
+ if (!nativeLayout) {
2584
+ throw childDiagnostic(child, "position", style.position, container, "PIBBL_LAYOUT_UNSUPPORTED_POSITION: absolute requires experimental Flex");
2585
+ }
2586
+ const automaticWidth = style.width === void 0 || style.width === "auto";
2587
+ const automaticHeight = style.height === void 0 || style.height === "auto";
2588
+ if (!automaticWidth && !isAbsoluteSizeInput(style.width) || !automaticHeight && !isAbsoluteSizeInput(style.height)) {
2589
+ throw childDiagnostic(child, "position", style.position, container, "PIBBL_LAYOUT_UNSUPPORTED_POSITION: absolute currently requires finite nonnegative numeric or percentage dimensions, or admitted automatic dimensions");
2590
+ }
2591
+ if (style.aspectRatio !== void 0 && automaticWidth === automaticHeight) {
2592
+ throw childDiagnostic(child, "aspectRatio", style.aspectRatio, container, "PIBBL_LAYOUT_UNSUPPORTED_POSITION: absolute aspectRatio currently requires exactly one automatic axis and one finite numeric or percentage axis");
2593
+ }
2594
+ if (style.aspectRatio === void 0 && (!naturalWidth && automaticWidth && (absoluteLeftInset(style, direction) === void 0 || absoluteRightInset(style, direction) === void 0) || !naturalHeight && automaticHeight && (style.top === void 0 || style.bottom === void 0))) {
2595
+ throw childDiagnostic(child, "position", style.position, container, "PIBBL_LAYOUT_UNSUPPORTED_POSITION: automatic absolute size requires opposing insets on its axis");
2596
+ }
2597
+ if (style.alignSelf !== void 0) {
2598
+ throw childDiagnostic(child, "alignSelf", style.alignSelf, container, "PIBBL_LAYOUT_UNSUPPORTED_POSITION: absolute currently uses parent alignItems only");
2599
+ }
2600
+ validateAbsoluteBound(style.minWidth, "minWidth", child, container);
2601
+ validateAbsoluteBound(style.maxWidth, "maxWidth", child, container);
2602
+ validateAbsoluteBound(style.minHeight, "minHeight", child, container);
2603
+ validateAbsoluteBound(style.maxHeight, "maxHeight", child, container);
2604
+ if (query || style.flexBasis !== void 0 && style.flexBasis !== "auto" || style.flexGrow !== void 0 && style.flexGrow !== 0 || style.flexShrink !== void 0 && style.flexShrink !== 0 || style.boxSizing !== void 0 || style.padding !== void 0 || style.paddingStart !== void 0 || style.paddingEnd !== void 0 || style.borderWidth !== void 0 || style.borderStartWidth !== void 0 || style.borderEndWidth !== void 0 || hasFlexMargin(style)) {
2605
+ throw childDiagnostic(child, "position", style.position, container, "PIBBL_LAYOUT_UNSUPPORTED_POSITION: absolute excludes nonzero flex factors, margins, and child box decoration in this slice");
2606
+ }
2607
+ }
2608
+ function validateAbsoluteBound(value, property, child, container) {
2609
+ if (value === void 0) return;
2610
+ if (!isAbsoluteSizeInput(value)) {
2611
+ throw childDiagnostic(child, property, value, container, "PIBBL_LAYOUT_UNSUPPORTED_POSITION: absolute size bounds currently require nonnegative finite numbers or percentages");
2612
+ }
2613
+ }
2614
+ function isAbsoluteSizeInput(value) {
2615
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 || isPercentage(value);
2616
+ }
2617
+ function resolveAbsoluteSize(value, property, reference, child, container) {
2618
+ if (!isPercentage(value)) return value;
2619
+ const resolved = resolveScalarSizingLength(value, reference, property, childContext(child, container));
2620
+ if (resolved < 0) throw childDiagnostic(child, property, value, container, "absolute sizes must resolve to nonnegative finite numbers");
2621
+ return resolved;
2622
+ }
2623
+ function absoluteLeftInset(style, direction) {
2624
+ const logical = direction === "rtl" ? style.insetEnd : style.insetStart;
2625
+ return logical === void 0 ? style.left : logical;
2626
+ }
2627
+ function absoluteRightInset(style, direction) {
2628
+ const logical = direction === "rtl" ? style.insetStart : style.insetEnd;
2629
+ return logical === void 0 ? style.right : logical;
2630
+ }
2631
+ function resolveFlexInset(value, property, child, container) {
2632
+ if (value === void 0) return;
2633
+ if (typeof value === "number" && Number.isFinite(value)) return value;
2634
+ if (isPercentage(value)) {
2635
+ return resolveScalarSizingLength(
2636
+ value,
2637
+ property === "left" || property === "right" ? container.width : container.height,
2638
+ property,
2639
+ childContext(child, container)
2640
+ );
2641
+ }
2642
+ throw childDiagnostic(child, property, value, container, "currently requires a finite numeric inset or a signed decimal percentage");
2643
+ }
2644
+ function assertSupportedRelativeFlexPosition(child, style, _options, container) {
2645
+ const position = style.position;
2646
+ if (!nativeLayout || position !== "static" && position !== "relative") {
2647
+ throw childDiagnostic(child, "position", position, container, "PIBBL_LAYOUT_UNSUPPORTED_POSITION: uses an unsupported Flex placement mode");
2648
+ }
2649
+ }
741
2650
  function rejectUnsupportedItemFields(child, style, container) {
742
- for (const property of ["order", "margin", "marginLeft", "marginRight", "marginTop", "marginBottom"]) {
2651
+ if (!nativeLayout && hasFlexMargin(style)) throw childDiagnostic(child, "margin", style.margin, container, "margins require the experimental Flex engine");
2652
+ for (let propertyIndex = 0; propertyIndex < unsupportedProperties.length; propertyIndex++) {
2653
+ const property = unsupportedProperties[propertyIndex];
743
2654
  if (style[property] !== void 0) {
744
2655
  throw childDiagnostic(
745
2656
  child,
@@ -751,6 +2662,23 @@ function rejectUnsupportedItemFields(child, style, container) {
751
2662
  }
752
2663
  }
753
2664
  }
2665
+ function hasFlexMargin(style) {
2666
+ return style.margin !== void 0 || style.marginTop !== void 0 || style.marginRight !== void 0 || style.marginBottom !== void 0 || style.marginLeft !== void 0 || style.marginStart !== void 0 || style.marginEnd !== void 0;
2667
+ }
2668
+ function allocatedMargin(value, property, child, container) {
2669
+ if (nativeLayout && isPercentage(value)) {
2670
+ return resolveScalarSizingLength(value, container.width, property, childContext(child, container));
2671
+ }
2672
+ return numericMargin(value, property, child, container);
2673
+ }
2674
+ function numericMargin(value, property, child, container) {
2675
+ if (value === void 0) return 0;
2676
+ if (typeof value !== "number" || !Number.isFinite(value)) throw childDiagnostic(child, property, value, container, "margin must be a finite number in logical Canvas units");
2677
+ return value;
2678
+ }
2679
+ function hasEmptyRectangleMinimum(child, style, query, percentageSizes = false) {
2680
+ return nativeLayout && child.type === Rectangle && !Object.hasOwn(child.props, "children") && !query && (typeof style.width === "number" && Number.isFinite(style.width) && style.width >= 0 || percentageSizes && isPercentage(style.width)) && (typeof style.height === "number" && Number.isFinite(style.height) && style.height >= 0 || percentageSizes && isPercentage(style.height));
2681
+ }
754
2682
  function clamp(value, minimum, maximum) {
755
2683
  return Math.min(maximum, Math.max(minimum, value));
756
2684
  }
@@ -761,14 +2689,14 @@ function assertFiniteBox(container) {
761
2689
  }
762
2690
  }
763
2691
  }
764
- function optionDiagnostic(property, value, container) {
2692
+ function optionDiagnostic(property, value, container, reason = "uses an unsupported flex value") {
765
2693
  return layoutDiagnostic({
766
2694
  component: "Flex",
767
2695
  property,
768
2696
  value,
769
2697
  algorithm: "flex",
770
2698
  constraints: constraintsFor(container),
771
- reason: "uses an unsupported flex value"
2699
+ reason
772
2700
  });
773
2701
  }
774
2702
  function childDiagnostic(child, property, value, container, reason) {
@@ -798,6 +2726,7 @@ function constraintsFor(container) {
798
2726
  }
799
2727
  export {
800
2728
  Flex,
801
- layoutFlex
2729
+ layoutFlex,
2730
+ resolveAbsoluteFlexPlacement
802
2731
  };
803
2732
  //# sourceMappingURL=flex.js.map