@motionscript/core 0.1.0-alpha.3 → 0.1.0-alpha.5

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 (746) hide show
  1. package/CHANGELOG.md +220 -0
  2. package/LICENSE +201 -201
  3. package/NOTICE +48 -0
  4. package/README.md +93 -72
  5. package/dist/assets/asset-index.js.map +1 -1
  6. package/dist/assets/catalog.d.ts +9 -0
  7. package/dist/assets/catalog.d.ts.map +1 -1
  8. package/dist/assets/catalog.js +11 -0
  9. package/dist/assets/catalog.js.map +1 -1
  10. package/dist/assets/errors.d.ts.map +1 -1
  11. package/dist/assets/errors.js +8 -3
  12. package/dist/assets/errors.js.map +1 -1
  13. package/dist/assets/index.js.map +1 -1
  14. package/dist/assets/manager.d.ts +26 -1
  15. package/dist/assets/manager.d.ts.map +1 -1
  16. package/dist/assets/manager.js +79 -4
  17. package/dist/assets/manager.js.map +1 -1
  18. package/dist/assets/manifest.js.map +1 -1
  19. package/dist/assets/record.js.map +1 -1
  20. package/dist/assets/scope.d.ts +3 -3
  21. package/dist/assets/scope.d.ts.map +1 -1
  22. package/dist/assets/scope.js.map +1 -1
  23. package/dist/attributes/audio/filters/chain.d.ts +1 -1
  24. package/dist/attributes/audio/filters/chain.js.map +1 -1
  25. package/dist/attributes/audio/filters/curve.d.ts +8 -8
  26. package/dist/attributes/audio/filters/curve.d.ts.map +1 -1
  27. package/dist/attributes/audio/filters/curve.js +20 -19
  28. package/dist/attributes/audio/filters/curve.js.map +1 -1
  29. package/dist/attributes/audio/filters/implementations/echo.js.map +1 -1
  30. package/dist/attributes/audio/filters/implementations/gain.js.map +1 -1
  31. package/dist/attributes/audio/filters/implementations/highpass.js.map +1 -1
  32. package/dist/attributes/audio/filters/implementations/lowpass.js.map +1 -1
  33. package/dist/attributes/audio/filters/implementations/speed.d.ts +2 -2
  34. package/dist/attributes/audio/filters/implementations/speed.js.map +1 -1
  35. package/dist/attributes/audio/filters/implementations/tremolo.js.map +1 -1
  36. package/dist/attributes/audio/filters/index.d.ts +1 -1
  37. package/dist/attributes/audio/filters/index.d.ts.map +1 -1
  38. package/dist/attributes/audio/filters/index.js +1 -1
  39. package/dist/attributes/audio/filters/index.js.map +1 -1
  40. package/dist/attributes/audio/filters/registry.js.map +1 -1
  41. package/dist/attributes/audio/filters/union.js.map +1 -1
  42. package/dist/attributes/audio/request.d.ts +17 -2
  43. package/dist/attributes/audio/request.d.ts.map +1 -1
  44. package/dist/attributes/audio/request.js.map +1 -1
  45. package/dist/attributes/audio/schedule.d.ts +4 -2
  46. package/dist/attributes/audio/schedule.d.ts.map +1 -1
  47. package/dist/attributes/audio/schedule.js +15 -8
  48. package/dist/attributes/audio/schedule.js.map +1 -1
  49. package/dist/attributes/audio/sound.d.ts +4 -2
  50. package/dist/attributes/audio/sound.d.ts.map +1 -1
  51. package/dist/attributes/audio/sound.js +8 -4
  52. package/dist/attributes/audio/sound.js.map +1 -1
  53. package/dist/attributes/index.js.map +1 -1
  54. package/dist/attributes/layout/alignment.js +1 -1
  55. package/dist/attributes/layout/alignment.js.map +1 -1
  56. package/dist/attributes/layout/index.js.map +1 -1
  57. package/dist/attributes/layout/insets.js.map +1 -1
  58. package/dist/attributes/layout/matrix2d.js.map +1 -1
  59. package/dist/attributes/layout/size.js.map +1 -1
  60. package/dist/attributes/layout/transform3d.js.map +1 -1
  61. package/dist/attributes/layout/vector2.js.map +1 -1
  62. package/dist/attributes/layout/world-transform.js.map +1 -1
  63. package/dist/attributes/mask/boolean.js.map +1 -1
  64. package/dist/attributes/mask/mask.js.map +1 -1
  65. package/dist/attributes/properties/decorator.d.ts +3 -1
  66. package/dist/attributes/properties/decorator.d.ts.map +1 -1
  67. package/dist/attributes/properties/decorator.js.map +1 -1
  68. package/dist/attributes/properties/inputs.js.map +1 -1
  69. package/dist/attributes/properties/typed.d.ts +9 -2
  70. package/dist/attributes/properties/typed.d.ts.map +1 -1
  71. package/dist/attributes/properties/typed.js +15 -1
  72. package/dist/attributes/properties/typed.js.map +1 -1
  73. package/dist/attributes/render3d/orbit.d.ts +8 -8
  74. package/dist/attributes/render3d/orbit.js +7 -7
  75. package/dist/attributes/render3d/orbit.js.map +1 -1
  76. package/dist/attributes/shape/corners/corner-radius.js.map +1 -1
  77. package/dist/attributes/shape/corners/corner-style.js.map +1 -1
  78. package/dist/attributes/shape/corners/corners.js.map +1 -1
  79. package/dist/attributes/shape/corners/index.js.map +1 -1
  80. package/dist/attributes/shape/effects/backdrop.d.ts +4 -4
  81. package/dist/attributes/shape/effects/backdrop.d.ts.map +1 -1
  82. package/dist/attributes/shape/effects/backdrop.js.map +1 -1
  83. package/dist/attributes/shape/effects/chain.d.ts +28 -120
  84. package/dist/attributes/shape/effects/chain.d.ts.map +1 -1
  85. package/dist/attributes/shape/effects/chain.js +16 -88
  86. package/dist/attributes/shape/effects/chain.js.map +1 -1
  87. package/dist/attributes/shape/effects/effect-data.js.map +1 -1
  88. package/dist/attributes/shape/effects/implementations/ascii.js.map +1 -1
  89. package/dist/attributes/shape/effects/implementations/bit-crush.js.map +1 -1
  90. package/dist/attributes/shape/effects/implementations/block-displace.js.map +1 -1
  91. package/dist/attributes/shape/effects/implementations/bloom.js.map +1 -1
  92. package/dist/attributes/shape/effects/implementations/blur.js.map +1 -1
  93. package/dist/attributes/shape/effects/implementations/bulge.js.map +1 -1
  94. package/dist/attributes/shape/effects/implementations/chromatic-aberration.js.map +1 -1
  95. package/dist/attributes/shape/effects/implementations/color-adjustment.d.ts +2 -2
  96. package/dist/attributes/shape/effects/implementations/color-adjustment.js.map +1 -1
  97. package/dist/attributes/shape/effects/implementations/curves.d.ts +1 -1
  98. package/dist/attributes/shape/effects/implementations/curves.js.map +1 -1
  99. package/dist/attributes/shape/effects/implementations/directional-blur.js.map +1 -1
  100. package/dist/attributes/shape/effects/implementations/dither.js.map +1 -1
  101. package/dist/attributes/shape/effects/implementations/drop-shadow.js.map +1 -1
  102. package/dist/attributes/shape/effects/implementations/duotone.js.map +1 -1
  103. package/dist/attributes/shape/effects/implementations/edges.js.map +1 -1
  104. package/dist/attributes/shape/effects/implementations/glass.d.ts +15 -24
  105. package/dist/attributes/shape/effects/implementations/glass.d.ts.map +1 -1
  106. package/dist/attributes/shape/effects/implementations/glass.js.map +1 -1
  107. package/dist/attributes/shape/effects/implementations/glow.js.map +1 -1
  108. package/dist/attributes/shape/effects/implementations/grain.js.map +1 -1
  109. package/dist/attributes/shape/effects/implementations/grayscale.js.map +1 -1
  110. package/dist/attributes/shape/effects/implementations/halftone.js.map +1 -1
  111. package/dist/attributes/shape/effects/implementations/invert.js.map +1 -1
  112. package/dist/attributes/shape/effects/implementations/kaleidoscope.js.map +1 -1
  113. package/dist/attributes/shape/effects/implementations/lut.d.ts +1 -1
  114. package/dist/attributes/shape/effects/implementations/lut.js.map +1 -1
  115. package/dist/attributes/shape/effects/implementations/magnify.js.map +1 -1
  116. package/dist/attributes/shape/effects/implementations/motion-blur.js.map +1 -1
  117. package/dist/attributes/shape/effects/implementations/oil-paint.js.map +1 -1
  118. package/dist/attributes/shape/effects/implementations/outline.js.map +1 -1
  119. package/dist/attributes/shape/effects/implementations/pixelate.js.map +1 -1
  120. package/dist/attributes/shape/effects/implementations/posterize.js.map +1 -1
  121. package/dist/attributes/shape/effects/implementations/progressive-blur.js.map +1 -1
  122. package/dist/attributes/shape/effects/implementations/radial-blur.js.map +1 -1
  123. package/dist/attributes/shape/effects/implementations/rgb-shift.js.map +1 -1
  124. package/dist/attributes/shape/effects/implementations/scanlines.js.map +1 -1
  125. package/dist/attributes/shape/effects/implementations/scatter.js.map +1 -1
  126. package/dist/attributes/shape/effects/implementations/shader.d.ts.map +1 -1
  127. package/dist/attributes/shape/effects/implementations/shader.js +15 -8
  128. package/dist/attributes/shape/effects/implementations/shader.js.map +1 -1
  129. package/dist/attributes/shape/effects/implementations/sharpen.js.map +1 -1
  130. package/dist/attributes/shape/effects/implementations/streak.js.map +1 -1
  131. package/dist/attributes/shape/effects/implementations/threshold.js.map +1 -1
  132. package/dist/attributes/shape/effects/implementations/twirl.js.map +1 -1
  133. package/dist/attributes/shape/effects/implementations/vignette.js.map +1 -1
  134. package/dist/attributes/shape/effects/implementations/vintage.js.map +1 -1
  135. package/dist/attributes/shape/effects/implementations/wave.js.map +1 -1
  136. package/dist/attributes/shape/effects/index.d.ts +2 -6
  137. package/dist/attributes/shape/effects/index.d.ts.map +1 -1
  138. package/dist/attributes/shape/effects/index.js.map +1 -1
  139. package/dist/attributes/shape/effects/registry.d.ts +23 -6
  140. package/dist/attributes/shape/effects/registry.d.ts.map +1 -1
  141. package/dist/attributes/shape/effects/registry.js +44 -10
  142. package/dist/attributes/shape/effects/registry.js.map +1 -1
  143. package/dist/attributes/shape/effects/union.d.ts +2 -6
  144. package/dist/attributes/shape/effects/union.d.ts.map +1 -1
  145. package/dist/attributes/shape/effects/union.js.map +1 -1
  146. package/dist/attributes/shape/fill/blend.js.map +1 -1
  147. package/dist/attributes/shape/fill/chain.js.map +1 -1
  148. package/dist/attributes/shape/fill/coerce.js.map +1 -1
  149. package/dist/attributes/shape/fill/color/constants.js.map +1 -1
  150. package/dist/attributes/shape/fill/color/parser.d.ts.map +1 -1
  151. package/dist/attributes/shape/fill/color/parser.js +81 -44
  152. package/dist/attributes/shape/fill/color/parser.js.map +1 -1
  153. package/dist/attributes/shape/fill/gradient-stops.d.ts +16 -0
  154. package/dist/attributes/shape/fill/gradient-stops.d.ts.map +1 -0
  155. package/dist/attributes/shape/fill/gradient-stops.js +65 -0
  156. package/dist/attributes/shape/fill/gradient-stops.js.map +1 -0
  157. package/dist/attributes/shape/fill/implementations/canvas3d.js.map +1 -1
  158. package/dist/attributes/shape/fill/implementations/color.js.map +1 -1
  159. package/dist/attributes/shape/fill/implementations/conic-gradient.d.ts.map +1 -1
  160. package/dist/attributes/shape/fill/implementations/conic-gradient.js +2 -5
  161. package/dist/attributes/shape/fill/implementations/conic-gradient.js.map +1 -1
  162. package/dist/attributes/shape/fill/implementations/dot-grid.js.map +1 -1
  163. package/dist/attributes/shape/fill/implementations/fractal-noise.d.ts.map +1 -1
  164. package/dist/attributes/shape/fill/implementations/fractal-noise.js +2 -10
  165. package/dist/attributes/shape/fill/implementations/fractal-noise.js.map +1 -1
  166. package/dist/attributes/shape/fill/implementations/grid.js.map +1 -1
  167. package/dist/attributes/shape/fill/implementations/image.d.ts.map +1 -1
  168. package/dist/attributes/shape/fill/implementations/image.js +5 -4
  169. package/dist/attributes/shape/fill/implementations/image.js.map +1 -1
  170. package/dist/attributes/shape/fill/implementations/linear-gradient.d.ts.map +1 -1
  171. package/dist/attributes/shape/fill/implementations/linear-gradient.js +2 -6
  172. package/dist/attributes/shape/fill/implementations/linear-gradient.js.map +1 -1
  173. package/dist/attributes/shape/fill/implementations/noise.js.map +1 -1
  174. package/dist/attributes/shape/fill/implementations/radial-gradient.d.ts.map +1 -1
  175. package/dist/attributes/shape/fill/implementations/radial-gradient.js +2 -5
  176. package/dist/attributes/shape/fill/implementations/radial-gradient.js.map +1 -1
  177. package/dist/attributes/shape/fill/implementations/shader.js.map +1 -1
  178. package/dist/attributes/shape/fill/implementations/stripe.js.map +1 -1
  179. package/dist/attributes/shape/fill/implementations/video.js +1 -1
  180. package/dist/attributes/shape/fill/implementations/video.js.map +1 -1
  181. package/dist/attributes/shape/fill/index.js.map +1 -1
  182. package/dist/attributes/shape/fill/lerp.js.map +1 -1
  183. package/dist/attributes/shape/fill/media-preset.js.map +1 -1
  184. package/dist/attributes/shape/fill/registry.js.map +1 -1
  185. package/dist/attributes/shape/fill/union.js.map +1 -1
  186. package/dist/attributes/shape/filters/chain.d.ts +4 -10
  187. package/dist/attributes/shape/filters/chain.d.ts.map +1 -1
  188. package/dist/attributes/shape/filters/chain.js +1 -13
  189. package/dist/attributes/shape/filters/chain.js.map +1 -1
  190. package/dist/attributes/shape/filters/implementations/alpha.js.map +1 -1
  191. package/dist/attributes/shape/filters/implementations/blur.js.map +1 -1
  192. package/dist/attributes/shape/filters/implementations/color-adjustment.js.map +1 -1
  193. package/dist/attributes/shape/filters/implementations/color-matrix.js.map +1 -1
  194. package/dist/attributes/shape/filters/implementations/curves.js.map +1 -1
  195. package/dist/attributes/shape/filters/implementations/echo.js.map +1 -1
  196. package/dist/attributes/shape/filters/implementations/exposure.js.map +1 -1
  197. package/dist/attributes/shape/filters/implementations/grayscale.js.map +1 -1
  198. package/dist/attributes/shape/filters/implementations/posterize-time.js.map +1 -1
  199. package/dist/attributes/shape/filters/index.d.ts +1 -1
  200. package/dist/attributes/shape/filters/index.js.map +1 -1
  201. package/dist/attributes/shape/filters/registry.d.ts +2 -2
  202. package/dist/attributes/shape/filters/registry.js +3 -3
  203. package/dist/attributes/shape/filters/registry.js.map +1 -1
  204. package/dist/attributes/shape/filters/union.d.ts +6 -7
  205. package/dist/attributes/shape/filters/union.d.ts.map +1 -1
  206. package/dist/attributes/shape/filters/union.js.map +1 -1
  207. package/dist/attributes/shape/path/anchors.d.ts.map +1 -1
  208. package/dist/attributes/shape/path/anchors.js +12 -5
  209. package/dist/attributes/shape/path/anchors.js.map +1 -1
  210. package/dist/attributes/shape/path/bezier.js.map +1 -1
  211. package/dist/attributes/shape/path/index.js.map +1 -1
  212. package/dist/attributes/shape/path/measure.js.map +1 -1
  213. package/dist/attributes/shape/path/morph.d.ts.map +1 -1
  214. package/dist/attributes/shape/path/morph.js +16 -4
  215. package/dist/attributes/shape/path/morph.js.map +1 -1
  216. package/dist/attributes/shape/path/ops.js.map +1 -1
  217. package/dist/attributes/shape/path/types.js.map +1 -1
  218. package/dist/attributes/shape/path/walk.js.map +1 -1
  219. package/dist/attributes/shape/shaders/index.js.map +1 -1
  220. package/dist/attributes/shape/shaders/pack.js.map +1 -1
  221. package/dist/attributes/shape/shaders/resolve.js.map +1 -1
  222. package/dist/attributes/shape/shadow/index.js.map +1 -1
  223. package/dist/attributes/shape/shadow/shadow.js.map +1 -1
  224. package/dist/attributes/shape/stroke/index.d.ts +2 -2
  225. package/dist/attributes/shape/stroke/index.d.ts.map +1 -1
  226. package/dist/attributes/shape/stroke/index.js +1 -1
  227. package/dist/attributes/shape/stroke/index.js.map +1 -1
  228. package/dist/attributes/shape/stroke/stroke.d.ts +27 -6
  229. package/dist/attributes/shape/stroke/stroke.d.ts.map +1 -1
  230. package/dist/attributes/shape/stroke/stroke.js +22 -2
  231. package/dist/attributes/shape/stroke/stroke.js.map +1 -1
  232. package/dist/attributes/shared/operators.js.map +1 -1
  233. package/dist/attributes/text/index.js.map +1 -1
  234. package/dist/attributes/text/ops.d.ts +6 -0
  235. package/dist/attributes/text/ops.d.ts.map +1 -1
  236. package/dist/attributes/text/ops.js +1 -0
  237. package/dist/attributes/text/ops.js.map +1 -1
  238. package/dist/attributes/text/types.js.map +1 -1
  239. package/dist/browser/chunks/chunk-FUZVFT3W.js +18 -0
  240. package/dist/browser/chunks/chunk-FUZVFT3W.js.map +7 -0
  241. package/dist/browser/chunks/chunk-QG6C23IJ.js +3 -0
  242. package/dist/browser/chunks/chunk-QG6C23IJ.js.map +7 -0
  243. package/dist/browser/chunks/chunk-SFNJRPBV.js +2 -0
  244. package/dist/browser/chunks/chunk-SFNJRPBV.js.map +7 -0
  245. package/dist/browser/component.js +1 -1
  246. package/dist/browser/component.js.map +1 -1
  247. package/dist/browser/index.js +1 -1
  248. package/dist/browser/index.js.map +4 -4
  249. package/dist/browser/jsx-jsx-dev-runtime.js +1 -1
  250. package/dist/browser/jsx-jsx-runtime.js +1 -1
  251. package/dist/browser/manifest.json +3 -2
  252. package/dist/browser/sdk.js +1 -1
  253. package/dist/component.js.map +1 -1
  254. package/dist/document/audio.d.ts +1 -1
  255. package/dist/document/audio.js +4 -4
  256. package/dist/document/audio.js.map +1 -1
  257. package/dist/document/builtins.d.ts.map +1 -1
  258. package/dist/document/builtins.js +8 -14
  259. package/dist/document/builtins.js.map +1 -1
  260. package/dist/document/command-traits.d.ts +1 -1
  261. package/dist/document/command-traits.js +13 -1
  262. package/dist/document/command-traits.js.map +1 -1
  263. package/dist/document/deny-globals.js.map +1 -1
  264. package/dist/document/diff.js.map +1 -1
  265. package/dist/document/doc-index.d.ts +2 -2
  266. package/dist/document/doc-index.d.ts.map +1 -1
  267. package/dist/document/doc-index.js.map +1 -1
  268. package/dist/document/expression/compile.d.ts.map +1 -1
  269. package/dist/document/expression/compile.js +8 -5
  270. package/dist/document/expression/compile.js.map +1 -1
  271. package/dist/document/expression/index.js.map +1 -1
  272. package/dist/document/expression/ops.js +1 -1
  273. package/dist/document/expression/ops.js.map +1 -1
  274. package/dist/document/expression/parse.d.ts.map +1 -1
  275. package/dist/document/expression/parse.js +15 -6
  276. package/dist/document/expression/parse.js.map +1 -1
  277. package/dist/document/expression/refs.d.ts +1 -1
  278. package/dist/document/expression/refs.js +1 -1
  279. package/dist/document/expression/refs.js.map +1 -1
  280. package/dist/document/expression/types.js.map +1 -1
  281. package/dist/document/expression/walk.d.ts.map +1 -1
  282. package/dist/document/expression/walk.js +2 -1
  283. package/dist/document/expression/walk.js.map +1 -1
  284. package/dist/document/index.d.ts +2 -0
  285. package/dist/document/index.d.ts.map +1 -1
  286. package/dist/document/index.js +2 -0
  287. package/dist/document/index.js.map +1 -1
  288. package/dist/document/node-decorator.js.map +1 -1
  289. package/dist/document/node-descriptor.d.ts +19 -0
  290. package/dist/document/node-descriptor.d.ts.map +1 -1
  291. package/dist/document/node-descriptor.js.map +1 -1
  292. package/dist/document/placement.d.ts +70 -0
  293. package/dist/document/placement.d.ts.map +1 -0
  294. package/dist/document/placement.js +83 -0
  295. package/dist/document/placement.js.map +1 -0
  296. package/dist/document/project.d.ts +2 -2
  297. package/dist/document/project.d.ts.map +1 -1
  298. package/dist/document/project.js.map +1 -1
  299. package/dist/document/registry.d.ts +17 -0
  300. package/dist/document/registry.d.ts.map +1 -1
  301. package/dist/document/registry.js +29 -2
  302. package/dist/document/registry.js.map +1 -1
  303. package/dist/document/timeline-patch.js.map +1 -1
  304. package/dist/document/timeline.d.ts +73 -18
  305. package/dist/document/timeline.d.ts.map +1 -1
  306. package/dist/document/timeline.js +192 -40
  307. package/dist/document/timeline.js.map +1 -1
  308. package/dist/document/types.d.ts +12 -12
  309. package/dist/document/types.d.ts.map +1 -1
  310. package/dist/document/types.js +2 -2
  311. package/dist/document/types.js.map +1 -1
  312. package/dist/document/validate.d.ts +2 -2
  313. package/dist/document/validate.d.ts.map +1 -1
  314. package/dist/document/validate.js +37 -31
  315. package/dist/document/validate.js.map +1 -1
  316. package/dist/document/withdraw.d.ts +28 -0
  317. package/dist/document/withdraw.d.ts.map +1 -0
  318. package/dist/document/withdraw.js +61 -0
  319. package/dist/document/withdraw.js.map +1 -0
  320. package/dist/index.d.ts +1 -0
  321. package/dist/index.d.ts.map +1 -1
  322. package/dist/index.js +1 -0
  323. package/dist/index.js.map +1 -1
  324. package/dist/jsx/jsx-dev-runtime.js.map +1 -1
  325. package/dist/jsx/jsx-runtime.d.ts +9 -1
  326. package/dist/jsx/jsx-runtime.d.ts.map +1 -1
  327. package/dist/jsx/jsx-runtime.js +13 -3
  328. package/dist/jsx/jsx-runtime.js.map +1 -1
  329. package/dist/layout/bounds.d.ts +0 -1
  330. package/dist/layout/bounds.d.ts.map +1 -1
  331. package/dist/layout/bounds.js.map +1 -1
  332. package/dist/layout/constraints.js.map +1 -1
  333. package/dist/layout/flex.d.ts +4 -2
  334. package/dist/layout/flex.d.ts.map +1 -1
  335. package/dist/layout/flex.js +27 -11
  336. package/dist/layout/flex.js.map +1 -1
  337. package/dist/layout/freeform.js.map +1 -1
  338. package/dist/layout/grid.js.map +1 -1
  339. package/dist/layout/index.js.map +1 -1
  340. package/dist/layout/item.js.map +1 -1
  341. package/dist/layout/ops.d.ts +6 -0
  342. package/dist/layout/ops.d.ts.map +1 -1
  343. package/dist/layout/ops.js +6 -0
  344. package/dist/layout/ops.js.map +1 -1
  345. package/dist/layout/types.js.map +1 -1
  346. package/dist/nodes/2d/node-lifecycle.js.map +1 -1
  347. package/dist/nodes/2d/node-motion.js.map +1 -1
  348. package/dist/nodes/2d/node-render.d.ts +3 -3
  349. package/dist/nodes/2d/node-render.d.ts.map +1 -1
  350. package/dist/nodes/2d/node-render.js.map +1 -1
  351. package/dist/nodes/2d/node-transform.js.map +1 -1
  352. package/dist/nodes/2d/node2d.d.ts +115 -3
  353. package/dist/nodes/2d/node2d.d.ts.map +1 -1
  354. package/dist/nodes/2d/node2d.js +180 -28
  355. package/dist/nodes/2d/node2d.js.map +1 -1
  356. package/dist/nodes/2d/paint-node.d.ts +27 -0
  357. package/dist/nodes/2d/paint-node.d.ts.map +1 -1
  358. package/dist/nodes/2d/paint-node.js +42 -0
  359. package/dist/nodes/2d/paint-node.js.map +1 -1
  360. package/dist/nodes/audio/audio-bus.js.map +1 -1
  361. package/dist/nodes/audio/index.js.map +1 -1
  362. package/dist/nodes/audio/node-audio.js.map +1 -1
  363. package/dist/nodes/audio/sound-node.d.ts +2 -2
  364. package/dist/nodes/audio/sound-node.d.ts.map +1 -1
  365. package/dist/nodes/audio/sound-node.js +1 -1
  366. package/dist/nodes/audio/sound-node.js.map +1 -1
  367. package/dist/nodes/geometry/bounds-shape-node.d.ts +4 -4
  368. package/dist/nodes/geometry/bounds-shape-node.js +2 -2
  369. package/dist/nodes/geometry/bounds-shape-node.js.map +1 -1
  370. package/dist/nodes/geometry/box-path-node.d.ts +3 -3
  371. package/dist/nodes/geometry/box-path-node.js +2 -2
  372. package/dist/nodes/geometry/box-path-node.js.map +1 -1
  373. package/dist/nodes/geometry/ellipse-node.js.map +1 -1
  374. package/dist/nodes/geometry/group-bounds.d.ts +2 -2
  375. package/dist/nodes/geometry/group-bounds.d.ts.map +1 -1
  376. package/dist/nodes/geometry/group-bounds.js +1 -2
  377. package/dist/nodes/geometry/group-bounds.js.map +1 -1
  378. package/dist/nodes/geometry/path-node.d.ts.map +1 -1
  379. package/dist/nodes/geometry/path-node.js +6 -0
  380. package/dist/nodes/geometry/path-node.js.map +1 -1
  381. package/dist/nodes/geometry/polygon-node.js.map +1 -1
  382. package/dist/nodes/geometry/polygram-node.js.map +1 -1
  383. package/dist/nodes/geometry/rect-node.js.map +1 -1
  384. package/dist/nodes/geometry/shape-node.js.map +1 -1
  385. package/dist/nodes/geometry/shape-outline.d.ts +2 -2
  386. package/dist/nodes/geometry/shape-outline.d.ts.map +1 -1
  387. package/dist/nodes/geometry/shape-outline.js +2 -13
  388. package/dist/nodes/geometry/shape-outline.js.map +1 -1
  389. package/dist/nodes/index.d.ts +3 -8
  390. package/dist/nodes/index.d.ts.map +1 -1
  391. package/dist/nodes/index.js +3 -8
  392. package/dist/nodes/index.js.map +1 -1
  393. package/dist/nodes/layout/camera-node.d.ts +9 -0
  394. package/dist/nodes/layout/camera-node.d.ts.map +1 -1
  395. package/dist/nodes/layout/camera-node.js +38 -3
  396. package/dist/nodes/layout/camera-node.js.map +1 -1
  397. package/dist/nodes/layout/orbit-camera-node.d.ts +1 -1
  398. package/dist/nodes/layout/orbit-camera-node.js +1 -1
  399. package/dist/nodes/layout/orbit-camera-node.js.map +1 -1
  400. package/dist/nodes/layout/rotated-box.js.map +1 -1
  401. package/dist/nodes/media/video-node.d.ts.map +1 -1
  402. package/dist/nodes/media/video-node.js +2 -0
  403. package/dist/nodes/media/video-node.js.map +1 -1
  404. package/dist/nodes/node/declare-paints.js.map +1 -1
  405. package/dist/nodes/node/node-editor-state.js.map +1 -1
  406. package/dist/nodes/node/node-reactive.js.map +1 -1
  407. package/dist/nodes/node/node-time.d.ts +3 -3
  408. package/dist/nodes/node/node-time.d.ts.map +1 -1
  409. package/dist/nodes/node/node-time.js +1 -1
  410. package/dist/nodes/node/node-time.js.map +1 -1
  411. package/dist/nodes/node/node-walk.js.map +1 -1
  412. package/dist/nodes/node/node.d.ts +5 -3
  413. package/dist/nodes/node/node.d.ts.map +1 -1
  414. package/dist/nodes/node/node.js +44 -19
  415. package/dist/nodes/node/node.js.map +1 -1
  416. package/dist/nodes/node/text-defaults.d.ts +10 -12
  417. package/dist/nodes/node/text-defaults.d.ts.map +1 -1
  418. package/dist/nodes/node/text-defaults.js +10 -12
  419. package/dist/nodes/node/text-defaults.js.map +1 -1
  420. package/dist/nodes/{scene → root}/canvas2d-node.d.ts +2 -2
  421. package/dist/nodes/root/canvas2d-node.d.ts.map +1 -0
  422. package/dist/nodes/{scene → root}/canvas2d-node.js +2 -2
  423. package/dist/nodes/root/canvas2d-node.js.map +1 -0
  424. package/dist/nodes/root/provider-node.d.ts.map +1 -0
  425. package/dist/nodes/root/provider-node.js.map +1 -0
  426. package/dist/nodes/root/theme-provider-node.d.ts.map +1 -0
  427. package/dist/nodes/root/theme-provider-node.js.map +1 -0
  428. package/dist/nodes/text/default-text-style-node.d.ts +5 -2
  429. package/dist/nodes/text/default-text-style-node.d.ts.map +1 -1
  430. package/dist/nodes/text/default-text-style-node.js +10 -4
  431. package/dist/nodes/text/default-text-style-node.js.map +1 -1
  432. package/dist/nodes/text/number-format.d.ts +1 -1
  433. package/dist/nodes/text/number-format.js +1 -1
  434. package/dist/nodes/text/number-format.js.map +1 -1
  435. package/dist/nodes/text/number-node.js.map +1 -1
  436. package/dist/nodes/text/number-pattern.js.map +1 -1
  437. package/dist/nodes/text/richtext-node.js +1 -1
  438. package/dist/nodes/text/richtext-node.js.map +1 -1
  439. package/dist/nodes/text/text-base.d.ts.map +1 -1
  440. package/dist/nodes/text/text-base.js +1 -1
  441. package/dist/nodes/text/text-base.js.map +1 -1
  442. package/dist/nodes/text/text-node.js.map +1 -1
  443. package/dist/nodes/text/text-selection.js.map +1 -1
  444. package/dist/nodes/three/camera-nodes.d.ts +21 -3
  445. package/dist/nodes/three/camera-nodes.d.ts.map +1 -1
  446. package/dist/nodes/three/camera-nodes.js +42 -1
  447. package/dist/nodes/three/camera-nodes.js.map +1 -1
  448. package/dist/nodes/three/canvas3d-node.d.ts +29 -6
  449. package/dist/nodes/three/canvas3d-node.d.ts.map +1 -1
  450. package/dist/nodes/three/canvas3d-node.js +44 -2
  451. package/dist/nodes/three/canvas3d-node.js.map +1 -1
  452. package/dist/nodes/three/drawable-nodes.d.ts +25 -11
  453. package/dist/nodes/three/drawable-nodes.d.ts.map +1 -1
  454. package/dist/nodes/three/drawable-nodes.js +43 -13
  455. package/dist/nodes/three/drawable-nodes.js.map +1 -1
  456. package/dist/nodes/three/environment-nodes.d.ts +9 -3
  457. package/dist/nodes/three/environment-nodes.d.ts.map +1 -1
  458. package/dist/nodes/three/environment-nodes.js.map +1 -1
  459. package/dist/nodes/three/geometry-nodes.d.ts +2 -2
  460. package/dist/nodes/three/geometry-nodes.js +2 -2
  461. package/dist/nodes/three/geometry-nodes.js.map +1 -1
  462. package/dist/nodes/three/grid-geometry3d.js.map +1 -1
  463. package/dist/nodes/three/group3d.js.map +1 -1
  464. package/dist/nodes/three/light-nodes.d.ts.map +1 -1
  465. package/dist/nodes/three/light-nodes.js +3 -3
  466. package/dist/nodes/three/light-nodes.js.map +1 -1
  467. package/dist/nodes/three/mesh3d.js.map +1 -1
  468. package/dist/nodes/three/node3d.d.ts +48 -0
  469. package/dist/nodes/three/node3d.d.ts.map +1 -1
  470. package/dist/nodes/three/node3d.js +53 -3
  471. package/dist/nodes/three/node3d.js.map +1 -1
  472. package/dist/platform/audio-sink.d.ts +2 -2
  473. package/dist/platform/audio-sink.d.ts.map +1 -1
  474. package/dist/platform/audio-sink.js.map +1 -1
  475. package/dist/platform/exporter.d.ts +13 -8
  476. package/dist/platform/exporter.d.ts.map +1 -1
  477. package/dist/platform/exporter.js.map +1 -1
  478. package/dist/platform/index.d.ts +1 -1
  479. package/dist/platform/index.d.ts.map +1 -1
  480. package/dist/platform/index.js.map +1 -1
  481. package/dist/platform/stepped-clock.js.map +1 -1
  482. package/dist/platform/storage-adapter.d.ts +12 -6
  483. package/dist/platform/storage-adapter.d.ts.map +1 -1
  484. package/dist/platform/storage-adapter.js +4 -0
  485. package/dist/platform/storage-adapter.js.map +1 -1
  486. package/dist/platform/ticker.d.ts +6 -0
  487. package/dist/platform/ticker.d.ts.map +1 -1
  488. package/dist/platform/ticker.js +6 -0
  489. package/dist/platform/ticker.js.map +1 -1
  490. package/dist/project/config.js.map +1 -1
  491. package/dist/project/index.js.map +1 -1
  492. package/dist/project/tree.d.ts +3 -3
  493. package/dist/project/tree.d.ts.map +1 -1
  494. package/dist/project/tree.js.map +1 -1
  495. package/dist/props/host.js.map +1 -1
  496. package/dist/props/index.js.map +1 -1
  497. package/dist/props/observer.js.map +1 -1
  498. package/dist/props/slot.js.map +1 -1
  499. package/dist/renamed-scene-names.d.ts +17 -0
  500. package/dist/renamed-scene-names.d.ts.map +1 -0
  501. package/dist/renamed-scene-names.js +9 -0
  502. package/dist/renamed-scene-names.js.map +1 -0
  503. package/dist/render/canvas-render-context2d.d.ts +2 -2
  504. package/dist/render/canvas-render-context2d.d.ts.map +1 -1
  505. package/dist/render/canvas-render-context2d.js.map +1 -1
  506. package/dist/render/clip-contains.js.map +1 -1
  507. package/dist/render/clip.js.map +1 -1
  508. package/dist/render/descriptors/ellipse.js.map +1 -1
  509. package/dist/render/descriptors/latex.js.map +1 -1
  510. package/dist/render/descriptors/line.js.map +1 -1
  511. package/dist/render/descriptors/path-builder.js.map +1 -1
  512. package/dist/render/descriptors/path.js.map +1 -1
  513. package/dist/render/descriptors/polygon.js.map +1 -1
  514. package/dist/render/descriptors/polygram.js.map +1 -1
  515. package/dist/render/descriptors/rect.js.map +1 -1
  516. package/dist/render/descriptors/richtext.js.map +1 -1
  517. package/dist/render/descriptors/shape.d.ts +12 -0
  518. package/dist/render/descriptors/shape.d.ts.map +1 -1
  519. package/dist/render/descriptors/shape.js.map +1 -1
  520. package/dist/render/descriptors/text.d.ts +2 -2
  521. package/dist/render/descriptors/text.js +2 -2
  522. package/dist/render/descriptors/text.js.map +1 -1
  523. package/dist/render/descriptors/transform.d.ts +2 -2
  524. package/dist/render/descriptors/transform.d.ts.map +1 -1
  525. package/dist/render/descriptors/transform.js.map +1 -1
  526. package/dist/render/graphics2d.d.ts +3 -3
  527. package/dist/render/graphics2d.d.ts.map +1 -1
  528. package/dist/render/graphics2d.js +1 -1
  529. package/dist/render/graphics2d.js.map +1 -1
  530. package/dist/render/index.js.map +1 -1
  531. package/dist/render/measure-context.js.map +1 -1
  532. package/dist/render/null-render-context.js.map +1 -1
  533. package/dist/render/render-context2d.d.ts +2 -2
  534. package/dist/render/render-context2d.d.ts.map +1 -1
  535. package/dist/render/render-context2d.js.map +1 -1
  536. package/dist/render/surface.js.map +1 -1
  537. package/dist/render/text-defaults.js.map +1 -1
  538. package/dist/render/text-layout.js.map +1 -1
  539. package/dist/render3d/bounds3d.d.ts.map +1 -1
  540. package/dist/render3d/bounds3d.js +4 -2
  541. package/dist/render3d/bounds3d.js.map +1 -1
  542. package/dist/render3d/builders.js.map +1 -1
  543. package/dist/render3d/camera.d.ts +6 -0
  544. package/dist/render3d/camera.d.ts.map +1 -1
  545. package/dist/render3d/camera.js +5 -3
  546. package/dist/render3d/camera.js.map +1 -1
  547. package/dist/render3d/fill3d.d.ts +2 -9
  548. package/dist/render3d/fill3d.d.ts.map +1 -1
  549. package/dist/render3d/fill3d.js +2 -13
  550. package/dist/render3d/fill3d.js.map +1 -1
  551. package/dist/render3d/geometry.d.ts +8 -1
  552. package/dist/render3d/geometry.d.ts.map +1 -1
  553. package/dist/render3d/geometry.js.map +1 -1
  554. package/dist/render3d/graphics3d.d.ts +8 -4
  555. package/dist/render3d/graphics3d.d.ts.map +1 -1
  556. package/dist/render3d/graphics3d.js +18 -10
  557. package/dist/render3d/graphics3d.js.map +1 -1
  558. package/dist/render3d/index.d.ts +1 -1
  559. package/dist/render3d/index.js +1 -1
  560. package/dist/render3d/index.js.map +1 -1
  561. package/dist/render3d/inert.d.ts +14 -0
  562. package/dist/render3d/inert.d.ts.map +1 -0
  563. package/dist/render3d/inert.js +62 -0
  564. package/dist/render3d/inert.js.map +1 -0
  565. package/dist/render3d/light.js.map +1 -1
  566. package/dist/render3d/material.d.ts +10 -5
  567. package/dist/render3d/material.d.ts.map +1 -1
  568. package/dist/render3d/material.js.map +1 -1
  569. package/dist/render3d/matrix4.js.map +1 -1
  570. package/dist/render3d/render-context3d.js.map +1 -1
  571. package/dist/render3d/resources.js.map +1 -1
  572. package/dist/render3d/rounded-box.js.map +1 -1
  573. package/dist/render3d/scene-settings.d.ts +23 -4
  574. package/dist/render3d/scene-settings.d.ts.map +1 -1
  575. package/dist/render3d/scene-settings.js.map +1 -1
  576. package/dist/render3d/scene3d.d.ts +11 -0
  577. package/dist/render3d/scene3d.d.ts.map +1 -1
  578. package/dist/render3d/scene3d.js +39 -6
  579. package/dist/render3d/scene3d.js.map +1 -1
  580. package/dist/render3d/segments.js.map +1 -1
  581. package/dist/render3d/texture.d.ts +9 -0
  582. package/dist/render3d/texture.d.ts.map +1 -1
  583. package/dist/render3d/texture.js +13 -0
  584. package/dist/render3d/texture.js.map +1 -1
  585. package/dist/render3d/tracking.js.map +1 -1
  586. package/dist/render3d/transform.d.ts +1 -1
  587. package/dist/render3d/transform.js.map +1 -1
  588. package/dist/render3d/vector3.d.ts +18 -1
  589. package/dist/render3d/vector3.d.ts.map +1 -1
  590. package/dist/render3d/vector3.js +27 -0
  591. package/dist/render3d/vector3.js.map +1 -1
  592. package/dist/render3d/walk.d.ts +1 -1
  593. package/dist/render3d/walk.d.ts.map +1 -1
  594. package/dist/render3d/walk.js +5 -1
  595. package/dist/render3d/walk.js.map +1 -1
  596. package/dist/runtime/asset-refine.js.map +1 -1
  597. package/dist/runtime/asset-timeline.js.map +1 -1
  598. package/dist/runtime/asset-update.js.map +1 -1
  599. package/dist/runtime/audio-index.js.map +1 -1
  600. package/dist/runtime/builtin-context.js.map +1 -1
  601. package/dist/runtime/clip-instance.d.ts +5 -3
  602. package/dist/runtime/clip-instance.d.ts.map +1 -1
  603. package/dist/runtime/clip-instance.js +10 -6
  604. package/dist/runtime/clip-instance.js.map +1 -1
  605. package/dist/runtime/clip-store.d.ts +9 -0
  606. package/dist/runtime/clip-store.d.ts.map +1 -1
  607. package/dist/runtime/clip-store.js +19 -0
  608. package/dist/runtime/clip-store.js.map +1 -1
  609. package/dist/runtime/engine.d.ts +5 -0
  610. package/dist/runtime/engine.d.ts.map +1 -1
  611. package/dist/runtime/engine.js +2 -0
  612. package/dist/runtime/engine.js.map +1 -1
  613. package/dist/runtime/frame-time.d.ts +31 -0
  614. package/dist/runtime/frame-time.d.ts.map +1 -0
  615. package/dist/runtime/frame-time.js +29 -0
  616. package/dist/runtime/frame-time.js.map +1 -0
  617. package/dist/runtime/index.d.ts +1 -0
  618. package/dist/runtime/index.d.ts.map +1 -1
  619. package/dist/runtime/index.js +1 -0
  620. package/dist/runtime/index.js.map +1 -1
  621. package/dist/runtime/node-picking.d.ts +44 -3
  622. package/dist/runtime/node-picking.d.ts.map +1 -1
  623. package/dist/runtime/node-picking.js +118 -3
  624. package/dist/runtime/node-picking.js.map +1 -1
  625. package/dist/runtime/node-picking3d.d.ts +2 -1
  626. package/dist/runtime/node-picking3d.d.ts.map +1 -1
  627. package/dist/runtime/node-picking3d.js +5 -2
  628. package/dist/runtime/node-picking3d.js.map +1 -1
  629. package/dist/runtime/placement.d.ts.map +1 -1
  630. package/dist/runtime/placement.js +4 -5
  631. package/dist/runtime/placement.js.map +1 -1
  632. package/dist/runtime/playback-controller.d.ts +31 -2
  633. package/dist/runtime/playback-controller.d.ts.map +1 -1
  634. package/dist/runtime/playback-controller.js +63 -6
  635. package/dist/runtime/playback-controller.js.map +1 -1
  636. package/dist/runtime/playback.js.map +1 -1
  637. package/dist/runtime/precompisition.js.map +1 -1
  638. package/dist/runtime/project-assets.js.map +1 -1
  639. package/dist/runtime/session.d.ts +9 -7
  640. package/dist/runtime/session.d.ts.map +1 -1
  641. package/dist/runtime/session.js +12 -4
  642. package/dist/runtime/session.js.map +1 -1
  643. package/dist/runtime/settle.js.map +1 -1
  644. package/dist/runtime/state-evaluator.d.ts +1 -1
  645. package/dist/runtime/state-evaluator.d.ts.map +1 -1
  646. package/dist/runtime/state-evaluator.js +4 -3
  647. package/dist/runtime/state-evaluator.js.map +1 -1
  648. package/dist/runtime/text-geometry.js.map +1 -1
  649. package/dist/sdk/index.d.ts +19 -15
  650. package/dist/sdk/index.d.ts.map +1 -1
  651. package/dist/sdk/index.js +11 -6
  652. package/dist/sdk/index.js.map +1 -1
  653. package/dist/tween/command-decorator.d.ts +2 -0
  654. package/dist/tween/command-decorator.d.ts.map +1 -1
  655. package/dist/tween/command-decorator.js.map +1 -1
  656. package/dist/tween/command.js.map +1 -1
  657. package/dist/tween/ease/constants.d.ts.map +1 -1
  658. package/dist/tween/ease/constants.js +8 -5
  659. package/dist/tween/ease/constants.js.map +1 -1
  660. package/dist/tween/ease/curve.d.ts.map +1 -1
  661. package/dist/tween/ease/curve.js +4 -3
  662. package/dist/tween/ease/curve.js.map +1 -1
  663. package/dist/tween/ease/describe.d.ts +15 -0
  664. package/dist/tween/ease/describe.d.ts.map +1 -0
  665. package/dist/tween/ease/describe.js +37 -0
  666. package/dist/tween/ease/describe.js.map +1 -0
  667. package/dist/tween/ease/type.js.map +1 -1
  668. package/dist/tween/index.js.map +1 -1
  669. package/dist/tween/inert.js.map +1 -1
  670. package/dist/tween/lerp.js.map +1 -1
  671. package/dist/tween/loop.js.map +1 -1
  672. package/dist/tween/prepare.d.ts +3 -3
  673. package/dist/tween/prepare.js +3 -3
  674. package/dist/tween/prepare.js.map +1 -1
  675. package/dist/tween/seekable.d.ts +1 -1
  676. package/dist/tween/seekable.js.map +1 -1
  677. package/dist/tween/stepper.js.map +1 -1
  678. package/dist/tween/to-command.js.map +1 -1
  679. package/dist/util/clamp.js.map +1 -1
  680. package/dist/util/context.js.map +1 -1
  681. package/dist/util/csv.js.map +1 -1
  682. package/dist/util/generateList.js.map +1 -1
  683. package/dist/util/index.js.map +1 -1
  684. package/dist/util/metrics.d.ts +1 -1
  685. package/dist/util/metrics.js +1 -1
  686. package/dist/util/metrics.js.map +1 -1
  687. package/dist/util/random.js.map +1 -1
  688. package/dist/util/reference.js.map +1 -1
  689. package/dist/util/scheduler.js.map +1 -1
  690. package/package.json +2 -1
  691. package/dist/attributes/shape/effects/implementations/displace.d.ts +0 -48
  692. package/dist/attributes/shape/effects/implementations/displace.d.ts.map +0 -1
  693. package/dist/attributes/shape/effects/implementations/displace.js +0 -30
  694. package/dist/attributes/shape/effects/implementations/displace.js.map +0 -1
  695. package/dist/attributes/shape/effects/implementations/god-rays.d.ts +0 -28
  696. package/dist/attributes/shape/effects/implementations/god-rays.d.ts.map +0 -1
  697. package/dist/attributes/shape/effects/implementations/god-rays.js +0 -26
  698. package/dist/attributes/shape/effects/implementations/god-rays.js.map +0 -1
  699. package/dist/attributes/shape/effects/implementations/texture.d.ts +0 -28
  700. package/dist/attributes/shape/effects/implementations/texture.d.ts.map +0 -1
  701. package/dist/attributes/shape/effects/implementations/texture.js +0 -25
  702. package/dist/attributes/shape/effects/implementations/texture.js.map +0 -1
  703. package/dist/attributes/shape/effects/implementations/trails.d.ts +0 -41
  704. package/dist/attributes/shape/effects/implementations/trails.d.ts.map +0 -1
  705. package/dist/attributes/shape/effects/implementations/trails.js +0 -22
  706. package/dist/attributes/shape/effects/implementations/trails.js.map +0 -1
  707. package/dist/browser/chunks/chunk-2T3HXSC2.js +0 -2
  708. package/dist/browser/chunks/chunk-2T3HXSC2.js.map +0 -7
  709. package/dist/browser/chunks/chunk-KJXGRHOL.js +0 -3
  710. package/dist/browser/chunks/chunk-KJXGRHOL.js.map +0 -7
  711. package/dist/browser/chunks/chunk-TGDX2SS2.js +0 -18
  712. package/dist/browser/chunks/chunk-TGDX2SS2.js.map +0 -7
  713. package/dist/nodes/geometry/dot-grid-node.d.ts +0 -105
  714. package/dist/nodes/geometry/dot-grid-node.d.ts.map +0 -1
  715. package/dist/nodes/geometry/dot-grid-node.js +0 -142
  716. package/dist/nodes/geometry/dot-grid-node.js.map +0 -1
  717. package/dist/nodes/geometry/grid-lines.d.ts +0 -101
  718. package/dist/nodes/geometry/grid-lines.d.ts.map +0 -1
  719. package/dist/nodes/geometry/grid-lines.js +0 -128
  720. package/dist/nodes/geometry/grid-lines.js.map +0 -1
  721. package/dist/nodes/geometry/grid-pattern-node.d.ts +0 -58
  722. package/dist/nodes/geometry/grid-pattern-node.d.ts.map +0 -1
  723. package/dist/nodes/geometry/grid-pattern-node.js +0 -172
  724. package/dist/nodes/geometry/grid-pattern-node.js.map +0 -1
  725. package/dist/nodes/geometry/line-grid-node.d.ts +0 -62
  726. package/dist/nodes/geometry/line-grid-node.d.ts.map +0 -1
  727. package/dist/nodes/geometry/line-grid-node.js +0 -127
  728. package/dist/nodes/geometry/line-grid-node.js.map +0 -1
  729. package/dist/nodes/geometry/line-node.d.ts +0 -58
  730. package/dist/nodes/geometry/line-node.d.ts.map +0 -1
  731. package/dist/nodes/geometry/line-node.js +0 -123
  732. package/dist/nodes/geometry/line-node.js.map +0 -1
  733. package/dist/nodes/geometry/viewport-pattern-node.d.ts +0 -39
  734. package/dist/nodes/geometry/viewport-pattern-node.d.ts.map +0 -1
  735. package/dist/nodes/geometry/viewport-pattern-node.js +0 -79
  736. package/dist/nodes/geometry/viewport-pattern-node.js.map +0 -1
  737. package/dist/nodes/scene/canvas2d-node.d.ts.map +0 -1
  738. package/dist/nodes/scene/canvas2d-node.js.map +0 -1
  739. package/dist/nodes/scene/provider-node.d.ts.map +0 -1
  740. package/dist/nodes/scene/provider-node.js.map +0 -1
  741. package/dist/nodes/scene/theme-provider-node.d.ts.map +0 -1
  742. package/dist/nodes/scene/theme-provider-node.js.map +0 -1
  743. /package/dist/nodes/{scene → root}/provider-node.d.ts +0 -0
  744. /package/dist/nodes/{scene → root}/provider-node.js +0 -0
  745. /package/dist/nodes/{scene → root}/theme-provider-node.d.ts +0 -0
  746. /package/dist/nodes/{scene → root}/theme-provider-node.js +0 -0
@@ -50,14 +50,8 @@ export function measureRun(items, horizontal, gap, space, measurer) {
50
50
  let share;
51
51
  let size;
52
52
  if (hugsMain) {
53
- // Nothing to share on an axis the container hugs — Figma disallows
54
- // `fill` there — so the item measures unconstrained, like a hug item. A
55
- // bare `fill` leaf echoes that back as Infinity, which would take the
56
- // container's hug size with it; it collapses to 0 instead.
57
- size = measureItem(item, horizontal
58
- ? { maxWidth: Infinity, maxHeight: space.height }
59
- : { maxWidth: space.width, maxHeight: Infinity }, measurer);
60
- share = Number.isFinite(size[main]) ? size[main] : 0;
53
+ size = measureFillOnHugAxis(item, horizontal, space, measurer);
54
+ share = size[main];
61
55
  }
62
56
  else {
63
57
  share = flexSum > 0 ? free * sanitizeFlex(item.flex) / flexSum : 0;
@@ -82,6 +76,21 @@ export function measureRun(items, horizontal, gap, space, measurer) {
82
76
  hug: horizontal ? { width: extent, height: depth } : { width: depth, height: extent },
83
77
  };
84
78
  }
79
+ /**
80
+ * A `fill`-main item on a main axis the container hugs. There is nothing to
81
+ * share on such an axis — Figma disallows `fill` there — so the item measures
82
+ * unconstrained along it, like a hug item. A bare `fill` leaf echoes that back as
83
+ * Infinity, which would take the container's hug size with it; it collapses to 0
84
+ * instead. Shared by {@link measureRun} and {@link measureWrap}, so a run hugs to
85
+ * the same size whether or not it wraps.
86
+ */
87
+ function measureFillOnHugAxis(item, horizontal, space, measurer) {
88
+ const size = measureItem(item, horizontal
89
+ ? { maxWidth: Infinity, maxHeight: space.height }
90
+ : { maxWidth: space.width, maxHeight: Infinity }, measurer);
91
+ const main = horizontal ? "width" : "height";
92
+ return Number.isFinite(size[main]) ? size : { ...size, [main]: 0 };
93
+ }
85
94
  /**
86
95
  * Measures a wrapped run: every item at its natural size, broken greedily into
87
96
  * lines that fit the main axis. Two rules differ from {@link measureRun}, both
@@ -90,8 +99,10 @@ export function measureRun(items, horizontal, gap, space, measurer) {
90
99
  * - **A hugging main axis does not wrap** — there is nothing to break against.
91
100
  * - **`fill` on the main axis is not divided.** Which line an item lands on is
92
101
  * what this pass decides, so it measures to the whole main axis and takes a
93
- * line to itself. Cross-axis `fill` stretches to its own line rather than the
94
- * whole stack, the only reading that survives a reflow.
102
+ * line to itself. (On a hugging main axis there is no line to break and no
103
+ * extent to fill, so it measures as {@link measureRun} measures it.)
104
+ * Cross-axis `fill` stretches to its own line rather than the whole stack, the
105
+ * only reading that survives a reflow.
95
106
  */
96
107
  export function measureWrap(items, horizontal, gap, crossGap, space, measurer) {
97
108
  const main = horizontal ? "width" : "height";
@@ -103,7 +114,12 @@ export function measureWrap(items, horizontal, gap, crossGap, space, measurer) {
103
114
  // in a wrapped run slides instead of collapsing its gap.
104
115
  const step = gap === "auto" ? 0 : gap;
105
116
  const bounded = { maxWidth: space.width, maxHeight: space.height };
106
- const sizes = items.map((item) => measureItem(item, bounded, measurer));
117
+ // A `fill` item on a hugging main axis measures as it does unwrapped (see
118
+ // `measureFillOnHugAxis`): the full extent is what a *bounded* axis offers it,
119
+ // and a hugging one offers none.
120
+ const sizes = items.map((item) => hugsMain && item[main] === "fill"
121
+ ? measureFillOnHugAxis(item, horizontal, space, measurer)
122
+ : measureItem(item, bounded, measurer));
107
123
  const lines = [];
108
124
  let widest = 0;
109
125
  let stack = 0;
@@ -1 +1 @@
1
- {"version":3,"file":"flex.js","sourceRoot":"","sources":["../../src/layout/flex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAOrC,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAIrC;;;GAGG;AACH,MAAM,UAAU,UAAU,CACtB,KAA4B,EAC5B,UAAmB,EACnB,GAAY,EACZ,KAAgB,EAChB,QAAsC;IAEtC,MAAM,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC;IAC7C,MAAM,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC;IAC9C,MAAM,QAAQ,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC;IAC1E,MAAM,SAAS,GAAG,CAAC,UAAU,CAAC,CAAC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AAU,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;AACrG,CAAC;AAED,SAAS,YAAY,CAAC,KAAyB;IAC3C,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,CAAC,CAAC;IAC5B,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED,uFAAuF;AACvF,SAAS,gBAAgB,CAAC,KAAyB;IAC/C,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,CAAC,CAAC;IAC5B,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3D,CAAC","sourcesContent":["import { clamp } from \"@/util/clamp\";\nimport type { Size2D } from \"@/attributes/layout/size\";\nimport type { Vector2 } from \"@/attributes/layout/vector2\";\nimport type { MeasureContext2D } from \"@/render/measure-context\";\nimport type { BoxBounds } from \"./bounds\";\nimport type { SizeConstraints } from \"./constraints\";\nimport type { FlowLine, FlowMeasure, FlowSpace, GapSize, LayoutItem } from \"./types\";\nimport { measureItem } from \"./item\";\n\ntype RunMeasure = Pick<FlowMeasure, \"sizes\" | \"lines\" | \"gapScales\" | \"hug\">;\n\n/**\n * Measures an unwrapped run, as one line: fixed items first, then `fill` items\n * share what is left of the main axis by `flex`.\n */\nexport function measureRun(\n items: readonly LayoutItem[],\n horizontal: boolean,\n gap: GapSize,\n space: FlowSpace,\n measurer: MeasureContext2D | undefined,\n): RunMeasure {\n const main = horizontal ? \"width\" : \"height\";\n const cross = horizontal ? \"height\" : \"width\";\n const hugsMain = (horizontal ? space.hugWidth : space.hugHeight) === true;\n const hugsCross = (horizontal ? space.hugHeight : space.hugWidth) === true;\n const bounded: SizeConstraints = { maxWidth: space.width, maxHeight: space.height };\n\n const n = items.length;\n const sizes: Size2D[] = new Array(n);\n const gapScales = items.map((item) => sanitizeGapScale(item.gapScale));\n // Weighted rather than a flat `n - 1`, so an item collapsing mid insert/remove\n // gives back exactly one gap wherever it sits. All weights 1 is `gap * (n - 1)`.\n const totalGap = gap === \"auto\" ? 0 : gap * Math.max(0, gapScales.reduce((sum, w) => sum + w, 0) - 1);\n\n // Fixed-main items first. On a hugging cross axis, `fill`-cross items wait:\n // what they fill is the deepest of these.\n let fixedMain = 0;\n let deepest = 0;\n for (let i = 0; i < n; i++) {\n if (items[i][main] === \"fill\" || (hugsCross && items[i][cross] === \"fill\")) continue;\n sizes[i] = measureItem(items[i], bounded, measurer);\n fixedMain += sizes[i][main];\n if (sizes[i][cross] > deepest) deepest = sizes[i][cross];\n }\n const fillCross = hugsCross ? deepest : space[cross];\n if (hugsCross) {\n for (let i = 0; i < n; i++) {\n if (items[i][main] === \"fill\" || items[i][cross] !== \"fill\") continue;\n const size = measureItem(items[i], bounded, measurer);\n sizes[i] = withCross(size, fillCross, horizontal);\n fixedMain += size[main];\n }\n }\n\n const free = Math.max(0, space[main] - totalGap - fixedMain);\n let flexSum = 0;\n for (const item of items) if (item[main] === \"fill\") flexSum += sanitizeFlex(item.flex);\n\n for (let i = 0; i < n; i++) {\n const item = items[i];\n if (item[main] !== \"fill\") continue;\n let share: number;\n let size: Size2D;\n if (hugsMain) {\n // Nothing to share on an axis the container hugs — Figma disallows\n // `fill` there — so the item measures unconstrained, like a hug item. A\n // bare `fill` leaf echoes that back as Infinity, which would take the\n // container's hug size with it; it collapses to 0 instead.\n size = measureItem(item, horizontal\n ? { maxWidth: Infinity, maxHeight: space.height }\n : { maxWidth: space.width, maxHeight: Infinity }, measurer);\n share = Number.isFinite(size[main]) ? size[main] : 0;\n } else {\n share = flexSum > 0 ? free * sanitizeFlex(item.flex) / flexSum : 0;\n size = measureItem(item, horizontal\n ? { maxWidth: share, maxHeight: space.height }\n : { maxWidth: space.width, maxHeight: share }, measurer);\n }\n const depth = item[cross] === \"fill\" ? fillCross : size[cross];\n sizes[i] = horizontal ? { width: share, height: depth } : { width: depth, height: share };\n }\n\n let extent = totalGap;\n let depth = 0;\n for (const size of sizes) {\n extent += size[main];\n if (size[cross] > depth) depth = size[cross];\n }\n return {\n sizes,\n lines: n > 0 ? [{ start: 0, end: n, cross: depth }] : [],\n gapScales,\n hug: horizontal ? { width: extent, height: depth } : { width: depth, height: extent },\n };\n}\n\n/**\n * Measures a wrapped run: every item at its natural size, broken greedily into\n * lines that fit the main axis. Two rules differ from {@link measureRun}, both\n * Figma's:\n *\n * - **A hugging main axis does not wrap** — there is nothing to break against.\n * - **`fill` on the main axis is not divided.** Which line an item lands on is\n * what this pass decides, so it measures to the whole main axis and takes a\n * line to itself. Cross-axis `fill` stretches to its own line rather than the\n * whole stack, the only reading that survives a reflow.\n */\nexport function measureWrap(\n items: readonly LayoutItem[],\n horizontal: boolean,\n gap: GapSize,\n crossGap: number,\n space: FlowSpace,\n measurer: MeasureContext2D | undefined,\n): RunMeasure {\n const main = horizontal ? \"width\" : \"height\";\n const cross = horizontal ? \"height\" : \"width\";\n const hugsMain = (horizontal ? space.hugWidth : space.hugHeight) === true;\n const limit = hugsMain ? Infinity : space[main];\n // Flat, not gapScale-weighted: placement spaces the lines this breaks, and a\n // weighting across a break would put the two out of step. An animated insert\n // in a wrapped run slides instead of collapsing its gap.\n const step = gap === \"auto\" ? 0 : gap;\n const bounded: SizeConstraints = { maxWidth: space.width, maxHeight: space.height };\n const sizes = items.map((item) => measureItem(item, bounded, measurer));\n\n const lines: FlowLine[] = [];\n let widest = 0;\n let stack = 0;\n let start = 0;\n while (start < sizes.length) {\n // A line always takes at least one item, so an over-long one overflows its\n // own line rather than being pushed onto an empty one forever.\n let end = start + 1;\n let extent = sizes[start][main];\n while (end < sizes.length && extent + step + sizes[end][main] <= limit) {\n extent += step + sizes[end][main];\n end++;\n }\n // A line's thickness is its deepest item, not counting the ones that fill\n // the cross axis — what they fill is the answer being computed.\n let depth = 0;\n for (let i = start; i < end; i++) {\n if (items[i][cross] !== \"fill\" && sizes[i][cross] > depth) depth = sizes[i][cross];\n }\n for (let i = start; i < end; i++) {\n if (items[i][cross] === \"fill\") sizes[i] = withCross(sizes[i], depth, horizontal);\n }\n lines.push({ start, end, cross: depth });\n if (extent > widest) widest = extent;\n stack += depth;\n start = end;\n }\n stack += crossGap * Math.max(0, lines.length - 1);\n return {\n sizes,\n lines,\n gapScales: sizes.map(() => 1),\n hug: horizontal ? { width: widest, height: stack } : { width: stack, height: widest },\n };\n}\n\n/**\n * Places a run's lines in the content box, centre-relative and y-up. Positions\n * are worked out in reading order — from the main axis's start edge (left, or\n * top) and the cross axis's (top, or left) — and converted once, at the end.\n */\nexport function placeRun(\n sizes: readonly Size2D[],\n lines: readonly FlowLine[],\n gapScales: readonly number[],\n horizontal: boolean,\n gap: GapSize,\n crossGap: number,\n align: Vector2,\n inner: Size2D,\n): BoxBounds[] {\n const main = horizontal ? \"width\" : \"height\";\n const cross = horizontal ? \"height\" : \"width\";\n // `align` is y-up and a run reads top-down, so y's fraction is flipped.\n const mainFraction = horizontal ? (1 + align.x) / 2 : (1 - align.y) / 2;\n const crossFraction = horizontal ? (1 - align.y) / 2 : (1 + align.x) / 2;\n\n let stack = crossGap * Math.max(0, lines.length - 1);\n for (const line of lines) stack += line.cross;\n let lineStart = crossFraction * (inner[cross] - stack);\n\n const boxes: BoxBounds[] = new Array(sizes.length);\n for (const line of lines) {\n const count = line.end - line.start;\n let extent = 0;\n let weight = 0;\n for (let i = line.start; i < line.end; i++) {\n extent += sizes[i][main];\n weight += gapScales[i];\n }\n\n let gapAfter: (i: number) => number;\n let lead = 0;\n if (gap === \"auto\") {\n // Spread within each line, so a short last line is as loose as the full ones.\n const spread = count > 1 ? Math.max(0, inner[main] - extent) / (count - 1) : 0;\n gapAfter = () => spread;\n extent += spread * (count - 1);\n } else {\n // A boundary takes the mean of its neighbours' weights, so the run spans\n // `gap * (Σweight − 1)` — what measureRun reserved. That leaves half a gap\n // over for a collapsing first item, which hangs before the visible run so\n // the content edge holds still at any alignment.\n const weightAt = (i: number): number => (i < line.end ? gapScales[i] : 1);\n gapAfter = (i) => gap * (gapScales[i] + weightAt(i + 1)) / 2;\n extent += gap * Math.max(0, weight - 1);\n lead = gap * (1 - gapScales[line.start]) / 2;\n }\n\n let at = mainFraction * (inner[main] - extent) - lead;\n for (let i = line.start; i < line.end; i++) {\n const size = sizes[i];\n const across = lineStart + crossFraction * (line.cross - size[cross]);\n boxes[i] = fromReadingOrder(horizontal ? at : across, horizontal ? across : at, size, inner);\n at += size[main] + gapAfter(i);\n }\n lineStart += line.cross + crossGap;\n }\n return boxes;\n}\n\n// From a top-left corner in the content box (y-down) to the content box's centre, y-up.\nfunction fromReadingOrder(left: number, top: number, size: Size2D, inner: Size2D): BoxBounds {\n return {\n x: left + size.width / 2 - inner.width / 2,\n y: inner.height / 2 - top - size.height / 2,\n width: size.width,\n height: size.height,\n };\n}\n\nfunction withCross(size: Size2D, depth: number, horizontal: boolean): Size2D {\n return horizontal ? { width: size.width, height: depth } : { width: depth, height: size.height };\n}\n\nfunction sanitizeFlex(value: number | undefined): number {\n if (value == null) return 1;\n return Number.isFinite(value) && value >= 0 ? value : 1;\n}\n\n// Clamped so an eased tween overshooting 0 ↔ 1 can't push a gap negative or past full.\nfunction sanitizeGapScale(value: number | undefined): number {\n if (value == null) return 1;\n return Number.isFinite(value) ? clamp(value, 0, 1) : 1;\n}\n"]}
1
+ {"version":3,"file":"flex.js","sourceRoot":"","sources":["../../src/layout/flex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAOrC,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAIrC;;;GAGG;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AAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED,uFAAuF;AACvF,SAAS,gBAAgB,CAAC,KAAyB;IAC/C,IAAI,KAAK,IAAI,IAAI;QAAE,OAAO,CAAC,CAAC;IAC5B,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3D,CAAC","sourcesContent":["import { clamp } from \"@/util/clamp\";\r\nimport type { Size2D } from \"@/attributes/layout/size\";\r\nimport type { Vector2 } from \"@/attributes/layout/vector2\";\r\nimport type { MeasureContext2D } from \"@/render/measure-context\";\r\nimport type { BoxBounds } from \"./bounds\";\r\nimport type { SizeConstraints } from \"./constraints\";\r\nimport type { FlowLine, FlowMeasure, FlowSpace, GapSize, LayoutItem } from \"./types\";\r\nimport { measureItem } from \"./item\";\r\n\r\ntype RunMeasure = Pick<FlowMeasure, \"sizes\" | \"lines\" | \"gapScales\" | \"hug\">;\r\n\r\n/**\r\n * Measures an unwrapped run, as one line: fixed items first, then `fill` items\r\n * share what is left of the main axis by `flex`.\r\n */\r\nexport function measureRun(\r\n items: readonly LayoutItem[],\r\n horizontal: boolean,\r\n gap: GapSize,\r\n space: FlowSpace,\r\n measurer: MeasureContext2D | undefined,\r\n): RunMeasure {\r\n const main = horizontal ? \"width\" : \"height\";\r\n const cross = horizontal ? \"height\" : \"width\";\r\n const hugsMain = (horizontal ? space.hugWidth : space.hugHeight) === true;\r\n const hugsCross = (horizontal ? space.hugHeight : space.hugWidth) === true;\r\n const bounded: SizeConstraints = { maxWidth: space.width, maxHeight: space.height };\r\n\r\n const n = items.length;\r\n const sizes: Size2D[] = new Array(n);\r\n const gapScales = items.map((item) => sanitizeGapScale(item.gapScale));\r\n // Weighted rather than a flat `n - 1`, so an item collapsing mid insert/remove\r\n // gives back exactly one gap wherever it sits. All weights 1 is `gap * (n - 1)`.\r\n const totalGap = gap === \"auto\" ? 0 : gap * Math.max(0, gapScales.reduce((sum, w) => sum + w, 0) - 1);\r\n\r\n // Fixed-main items first. On a hugging cross axis, `fill`-cross items wait:\r\n // what they fill is the deepest of these.\r\n let fixedMain = 0;\r\n let deepest = 0;\r\n for (let i = 0; i < n; i++) {\r\n if (items[i][main] === \"fill\" || (hugsCross && items[i][cross] === \"fill\")) continue;\r\n sizes[i] = measureItem(items[i], bounded, measurer);\r\n fixedMain += sizes[i][main];\r\n if (sizes[i][cross] > deepest) deepest = sizes[i][cross];\r\n }\r\n const fillCross = hugsCross ? deepest : space[cross];\r\n if (hugsCross) {\r\n for (let i = 0; i < n; i++) {\r\n if (items[i][main] === \"fill\" || items[i][cross] !== \"fill\") continue;\r\n const size = measureItem(items[i], bounded, measurer);\r\n sizes[i] = withCross(size, fillCross, horizontal);\r\n fixedMain += size[main];\r\n }\r\n }\r\n\r\n const free = Math.max(0, space[main] - totalGap - fixedMain);\r\n let flexSum = 0;\r\n for (const item of items) if (item[main] === \"fill\") flexSum += sanitizeFlex(item.flex);\r\n\r\n for (let i = 0; i < n; i++) {\r\n const item = items[i];\r\n if (item[main] !== \"fill\") continue;\r\n let share: number;\r\n let size: Size2D;\r\n if (hugsMain) {\r\n size = measureFillOnHugAxis(item, horizontal, space, measurer);\r\n share = size[main];\r\n } else {\r\n share = flexSum > 0 ? free * sanitizeFlex(item.flex) / flexSum : 0;\r\n size = measureItem(item, horizontal\r\n ? { maxWidth: share, maxHeight: space.height }\r\n : { maxWidth: space.width, maxHeight: share }, measurer);\r\n }\r\n const depth = item[cross] === \"fill\" ? fillCross : size[cross];\r\n sizes[i] = horizontal ? { width: share, height: depth } : { width: depth, height: share };\r\n }\r\n\r\n let extent = totalGap;\r\n let depth = 0;\r\n for (const size of sizes) {\r\n extent += size[main];\r\n if (size[cross] > depth) depth = size[cross];\r\n }\r\n return {\r\n sizes,\r\n lines: n > 0 ? [{ start: 0, end: n, cross: depth }] : [],\r\n gapScales,\r\n hug: horizontal ? { width: extent, height: depth } : { width: depth, height: extent },\r\n };\r\n}\r\n\r\n/**\r\n * A `fill`-main item on a main axis the container hugs. There is nothing to\r\n * share on such an axis — Figma disallows `fill` there — so the item measures\r\n * unconstrained along it, like a hug item. A bare `fill` leaf echoes that back as\r\n * Infinity, which would take the container's hug size with it; it collapses to 0\r\n * instead. Shared by {@link measureRun} and {@link measureWrap}, so a run hugs to\r\n * the same size whether or not it wraps.\r\n */\r\nfunction measureFillOnHugAxis(\r\n item: LayoutItem,\r\n horizontal: boolean,\r\n space: FlowSpace,\r\n measurer: MeasureContext2D | undefined,\r\n): Size2D {\r\n const size = measureItem(item, horizontal\r\n ? { maxWidth: Infinity, maxHeight: space.height }\r\n : { maxWidth: space.width, maxHeight: Infinity }, measurer);\r\n const main = horizontal ? \"width\" : \"height\";\r\n return Number.isFinite(size[main]) ? size : { ...size, [main]: 0 };\r\n}\r\n\r\n/**\r\n * Measures a wrapped run: every item at its natural size, broken greedily into\r\n * lines that fit the main axis. Two rules differ from {@link measureRun}, both\r\n * Figma's:\r\n *\r\n * - **A hugging main axis does not wrap** — there is nothing to break against.\r\n * - **`fill` on the main axis is not divided.** Which line an item lands on is\r\n * what this pass decides, so it measures to the whole main axis and takes a\r\n * line to itself. (On a hugging main axis there is no line to break and no\r\n * extent to fill, so it measures as {@link measureRun} measures it.)\r\n * Cross-axis `fill` stretches to its own line rather than the whole stack, the\r\n * only reading that survives a reflow.\r\n */\r\nexport function measureWrap(\r\n items: readonly LayoutItem[],\r\n horizontal: boolean,\r\n gap: GapSize,\r\n crossGap: number,\r\n space: FlowSpace,\r\n measurer: MeasureContext2D | undefined,\r\n): RunMeasure {\r\n const main = horizontal ? \"width\" : \"height\";\r\n const cross = horizontal ? \"height\" : \"width\";\r\n const hugsMain = (horizontal ? space.hugWidth : space.hugHeight) === true;\r\n const limit = hugsMain ? Infinity : space[main];\r\n // Flat, not gapScale-weighted: placement spaces the lines this breaks, and a\r\n // weighting across a break would put the two out of step. An animated insert\r\n // in a wrapped run slides instead of collapsing its gap.\r\n const step = gap === \"auto\" ? 0 : gap;\r\n const bounded: SizeConstraints = { maxWidth: space.width, maxHeight: space.height };\r\n // A `fill` item on a hugging main axis measures as it does unwrapped (see\r\n // `measureFillOnHugAxis`): the full extent is what a *bounded* axis offers it,\r\n // and a hugging one offers none.\r\n const sizes = items.map((item) => hugsMain && item[main] === \"fill\"\r\n ? measureFillOnHugAxis(item, horizontal, space, measurer)\r\n : measureItem(item, bounded, measurer));\r\n\r\n const lines: FlowLine[] = [];\r\n let widest = 0;\r\n let stack = 0;\r\n let start = 0;\r\n while (start < sizes.length) {\r\n // A line always takes at least one item, so an over-long one overflows its\r\n // own line rather than being pushed onto an empty one forever.\r\n let end = start + 1;\r\n let extent = sizes[start][main];\r\n while (end < sizes.length && extent + step + sizes[end][main] <= limit) {\r\n extent += step + sizes[end][main];\r\n end++;\r\n }\r\n // A line's thickness is its deepest item, not counting the ones that fill\r\n // the cross axis — what they fill is the answer being computed.\r\n let depth = 0;\r\n for (let i = start; i < end; i++) {\r\n if (items[i][cross] !== \"fill\" && sizes[i][cross] > depth) depth = sizes[i][cross];\r\n }\r\n for (let i = start; i < end; i++) {\r\n if (items[i][cross] === \"fill\") sizes[i] = withCross(sizes[i], depth, horizontal);\r\n }\r\n lines.push({ start, end, cross: depth });\r\n if (extent > widest) widest = extent;\r\n stack += depth;\r\n start = end;\r\n }\r\n stack += crossGap * Math.max(0, lines.length - 1);\r\n return {\r\n sizes,\r\n lines,\r\n gapScales: sizes.map(() => 1),\r\n hug: horizontal ? { width: widest, height: stack } : { width: stack, height: widest },\r\n };\r\n}\r\n\r\n/**\r\n * Places a run's lines in the content box, centre-relative and y-up. Positions\r\n * are worked out in reading order — from the main axis's start edge (left, or\r\n * top) and the cross axis's (top, or left) — and converted once, at the end.\r\n */\r\nexport function placeRun(\r\n sizes: readonly Size2D[],\r\n lines: readonly FlowLine[],\r\n gapScales: readonly number[],\r\n horizontal: boolean,\r\n gap: GapSize,\r\n crossGap: number,\r\n align: Vector2,\r\n inner: Size2D,\r\n): BoxBounds[] {\r\n const main = horizontal ? \"width\" : \"height\";\r\n const cross = horizontal ? \"height\" : \"width\";\r\n // `align` is y-up and a run reads top-down, so y's fraction is flipped.\r\n const mainFraction = horizontal ? (1 + align.x) / 2 : (1 - align.y) / 2;\r\n const crossFraction = horizontal ? (1 - align.y) / 2 : (1 + align.x) / 2;\r\n\r\n let stack = crossGap * Math.max(0, lines.length - 1);\r\n for (const line of lines) stack += line.cross;\r\n let lineStart = crossFraction * (inner[cross] - stack);\r\n\r\n const boxes: BoxBounds[] = new Array(sizes.length);\r\n for (const line of lines) {\r\n const count = line.end - line.start;\r\n let extent = 0;\r\n let weight = 0;\r\n for (let i = line.start; i < line.end; i++) {\r\n extent += sizes[i][main];\r\n weight += gapScales[i];\r\n }\r\n\r\n let gapAfter: (i: number) => number;\r\n let lead = 0;\r\n if (gap === \"auto\") {\r\n // Spread within each line, so a short last line is as loose as the full ones.\r\n const spread = count > 1 ? Math.max(0, inner[main] - extent) / (count - 1) : 0;\r\n gapAfter = () => spread;\r\n extent += spread * (count - 1);\r\n } else {\r\n // A boundary takes the mean of its neighbours' weights, so the run spans\r\n // `gap * (Σweight − 1)` — what measureRun reserved. That leaves half a gap\r\n // over for a collapsing first item, which hangs before the visible run so\r\n // the content edge holds still at any alignment.\r\n const weightAt = (i: number): number => (i < line.end ? gapScales[i] : 1);\r\n gapAfter = (i) => gap * (gapScales[i] + weightAt(i + 1)) / 2;\r\n extent += gap * Math.max(0, weight - 1);\r\n lead = gap * (1 - gapScales[line.start]) / 2;\r\n }\r\n\r\n let at = mainFraction * (inner[main] - extent) - lead;\r\n for (let i = line.start; i < line.end; i++) {\r\n const size = sizes[i];\r\n const across = lineStart + crossFraction * (line.cross - size[cross]);\r\n boxes[i] = fromReadingOrder(horizontal ? at : across, horizontal ? across : at, size, inner);\r\n at += size[main] + gapAfter(i);\r\n }\r\n lineStart += line.cross + crossGap;\r\n }\r\n return boxes;\r\n}\r\n\r\n// From a top-left corner in the content box (y-down) to the content box's centre, y-up.\r\nfunction fromReadingOrder(left: number, top: number, size: Size2D, inner: Size2D): BoxBounds {\r\n return {\r\n x: left + size.width / 2 - inner.width / 2,\r\n y: inner.height / 2 - top - size.height / 2,\r\n width: size.width,\r\n height: size.height,\r\n };\r\n}\r\n\r\nfunction withCross(size: Size2D, depth: number, horizontal: boolean): Size2D {\r\n return horizontal ? { width: size.width, height: depth } : { width: depth, height: size.height };\r\n}\r\n\r\nfunction sanitizeFlex(value: number | undefined): number {\r\n if (value == null) return 1;\r\n return Number.isFinite(value) && value >= 0 ? value : 1;\r\n}\r\n\r\n// Clamped so an eased tween overshooting 0 ↔ 1 can't push a gap negative or past full.\r\nfunction sanitizeGapScale(value: number | undefined): number {\r\n if (value == null) return 1;\r\n return Number.isFinite(value) ? clamp(value, 0, 1) : 1;\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"freeform.js","sourceRoot":"","sources":["../../src/layout/freeform.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,6FAA6F;AAC7F,MAAM,UAAU,eAAe,CAC3B,KAA4B,EAC5B,KAAgB,EAChB,QAAsC;IAEtC,MAAM,WAAW,GAAG,EAAE,QAAQ,EAAE,KAAK,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;IACvE,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,GAAG,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;IACpC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACvB,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC;QACtD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjB,IAAI,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK;YAAE,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACnD,IAAI,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM;YAAE,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC3D,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;AAC1B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,KAAwB,EAAE,KAAa,EAAE,KAAc;IACjF,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACxB,CAAC,EAAE,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;QACtD,CAAC,EAAE,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;QACxD,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,MAAM,EAAE,IAAI,CAAC,MAAM;KACtB,CAAC,CAAC,CAAC;AACR,CAAC","sourcesContent":["import type { Size2D } from \"@/attributes/layout/size\";\nimport type { Vector2 } from \"@/attributes/layout/vector2\";\nimport type { MeasureContext2D } from \"@/render/measure-context\";\nimport type { BoxBounds } from \"./bounds\";\nimport type { FlowSpace, LayoutItem } from \"./types\";\nimport { measureItem } from \"./item\";\n\n/** Every item measured against the whole content box; the content is the largest of them. */\nexport function measureFreeform(\n items: readonly LayoutItem[],\n space: FlowSpace,\n measurer: MeasureContext2D | undefined,\n): { sizes: Size2D[]; hug: Size2D } {\n const constraints = { maxWidth: space.width, maxHeight: space.height };\n const sizes: Size2D[] = [];\n const hug = { width: 0, height: 0 };\n for (const item of items) {\n const size = measureItem(item, constraints, measurer);\n sizes.push(size);\n if (size.width > hug.width) hug.width = size.width;\n if (size.height > hug.height) hug.height = size.height;\n }\n return { sizes, hug };\n}\n\n/**\n * Each item aligned in the content box, centre-relative and y-up. Slack is\n * clamped at 0, so an item larger than the box stays centred on it.\n */\nexport function placeFreeform(sizes: readonly Size2D[], inner: Size2D, align: Vector2): BoxBounds[] {\n return sizes.map((size) => ({\n x: align.x * Math.max(0, inner.width - size.width) / 2,\n y: align.y * Math.max(0, inner.height - size.height) / 2,\n width: size.width,\n height: size.height,\n }));\n}\n"]}
1
+ {"version":3,"file":"freeform.js","sourceRoot":"","sources":["../../src/layout/freeform.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,6FAA6F;AAC7F,MAAM,UAAU,eAAe,CAC3B,KAA4B,EAC5B,KAAgB,EAChB,QAAsC;IAEtC,MAAM,WAAW,GAAG,EAAE,QAAQ,EAAE,KAAK,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC;IACvE,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,GAAG,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;IACpC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACvB,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC;QACtD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjB,IAAI,IAAI,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK;YAAE,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACnD,IAAI,IAAI,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM;YAAE,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC3D,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC;AAC1B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,KAAwB,EAAE,KAAa,EAAE,KAAc;IACjF,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACxB,CAAC,EAAE,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;QACtD,CAAC,EAAE,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;QACxD,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,MAAM,EAAE,IAAI,CAAC,MAAM;KACtB,CAAC,CAAC,CAAC;AACR,CAAC","sourcesContent":["import type { Size2D } from \"@/attributes/layout/size\";\r\nimport type { Vector2 } from \"@/attributes/layout/vector2\";\r\nimport type { MeasureContext2D } from \"@/render/measure-context\";\r\nimport type { BoxBounds } from \"./bounds\";\r\nimport type { FlowSpace, LayoutItem } from \"./types\";\r\nimport { measureItem } from \"./item\";\r\n\r\n/** Every item measured against the whole content box; the content is the largest of them. */\r\nexport function measureFreeform(\r\n items: readonly LayoutItem[],\r\n space: FlowSpace,\r\n measurer: MeasureContext2D | undefined,\r\n): { sizes: Size2D[]; hug: Size2D } {\r\n const constraints = { maxWidth: space.width, maxHeight: space.height };\r\n const sizes: Size2D[] = [];\r\n const hug = { width: 0, height: 0 };\r\n for (const item of items) {\r\n const size = measureItem(item, constraints, measurer);\r\n sizes.push(size);\r\n if (size.width > hug.width) hug.width = size.width;\r\n if (size.height > hug.height) hug.height = size.height;\r\n }\r\n return { sizes, hug };\r\n}\r\n\r\n/**\r\n * Each item aligned in the content box, centre-relative and y-up. Slack is\r\n * clamped at 0, so an item larger than the box stays centred on it.\r\n */\r\nexport function placeFreeform(sizes: readonly Size2D[], inner: Size2D, align: Vector2): BoxBounds[] {\r\n return sizes.map((size) => ({\r\n x: align.x * Math.max(0, inner.width - size.width) / 2,\r\n y: align.y * Math.max(0, inner.height - size.height) / 2,\r\n width: size.width,\r\n height: size.height,\r\n }));\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"grid.js","sourceRoot":"","sources":["../../src/layout/grid.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CACvB,KAA4B,EAC5B,OAAe,EACf,SAAiB,EACjB,MAAc,EACd,KAAgB,EAChB,QAAsC;IAEtC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;IAC/C,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,GAAG,SAAS,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;IAC3E,MAAM,UAAU,GAAG,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC3C,MAAM,QAAQ,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;IAEpF,MAAM,OAAO,GAAG,KAAK,CAAC,SAAS,KAAK,IAAI,IAAI,QAAQ,GAAG,CAAC,CAAC;IACzD,MAAM,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM,GAAG,CA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M,CAAC;QAC3C,OAAO;IACX,CAAC;IACD,MAAM,KAAK,GAAG,MAAM,GAAG,WAAW,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;IAC5D,IAAI,KAAK,GAAG,CAAC;QAAE,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC;AACtC,CAAC;AAED,SAAS,IAAI,CAAC,KAAa,EAAE,KAAa,EAAE,GAAW;IACnD,OAAO,KAAK,GAAG,KAAK,GAAG,GAAG,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;AAC7C,CAAC;AAED,SAAS,WAAW,CAAC,IAAuB,EAAE,IAAY,EAAE,KAAa,EAAE,GAAW;IAClF,IAAI,MAAM,GAAG,GAAG,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;IAC/B,KAAK,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,GAAG,IAAI,GAAG,KAAK,EAAE,CAAC,EAAE;QAAE,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACjE,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import type { Size2D } from \"@/attributes/layout/size\";\nimport type { MeasureContext2D } from \"@/render/measure-context\";\nimport type { BoxBounds } from \"./bounds\";\nimport type { SizeConstraints } from \"./constraints\";\nimport type { FlowSpace, LayoutItem } from \"./types\";\nimport { measureItem } from \"./item\";\n\n/**\n * Measures a grid: `columns` equal tracks across the width, and rows sized to\n * their content — or, when the height is bounded, divided equally so a\n * `fill`-height item has a share to fill. Each item's cell comes back from the\n * content box's top-left, y-down.\n */\nexport function measureGrid(\n items: readonly LayoutItem[],\n columns: number,\n columnGap: number,\n rowGap: number,\n space: FlowSpace,\n measurer: MeasureContext2D | undefined,\n): { sizes: Size2D[]; cells: BoxBounds[]; hug: Size2D } {\n const count = Math.max(1, Math.round(columns));\n const track = Math.max(0, (space.width - columnGap * (count - 1)) / count);\n const placements = autoPlace(items, count);\n const rowCount = placements.reduce((max, p) => Math.max(max, p.row + p.rowSpan), 0);\n\n const bounded = space.hugHeight !== true && rowCount > 0;\n const equalRow = bounded ? Math.max(0, (space.height - rowGap * (rowCount - 1)) / rowCount) : 0;\n const rows = new Array<number>(rowCount).fill(equalRow);\n\n const sizes = items.map((item, i) => {\n const p = placements[i];\n const width = span(track, p.colSpan, columnGap);\n const constraints: SizeConstraints = bounded\n ? { maxWidth: width, maxHeight: span(equalRow, p.rowSpan, rowGap) }\n : { maxWidth: width };\n const size = measureItem(item, constraints, measurer);\n // Bounded rows are already equal, and content may not grow one past its share.\n if (!bounded) grow(rows, p.row, p.rowSpan, size.height, rowGap);\n return size;\n });\n\n const tops: number[] = [];\n let top = 0;\n for (const height of rows) {\n tops.push(top);\n top += height + rowGap;\n }\n const cells = placements.map((p) => ({\n x: p.col * (track + columnGap),\n y: tops[p.row] ?? 0,\n width: span(track, p.colSpan, columnGap),\n height: spannedRows(rows, p.row, p.rowSpan, rowGap),\n }));\n const height = rows.reduce((sum, h) => sum + h, 0) + rowGap * Math.max(0, rowCount - 1);\n return { sizes, cells, hug: { width: space.width, height } };\n}\n\n/** Each item's cell, clamped to the content box, centre-relative and y-up. */\nexport function placeGrid(cells: readonly BoxBounds[], inner: Size2D): BoxBounds[] {\n return cells.map((cell) => ({\n x: cell.x + cell.width / 2 - inner.width / 2,\n y: inner.height / 2 - cell.y - cell.height / 2,\n width: Math.min(cell.width, inner.width),\n height: Math.min(cell.height, inner.height),\n }));\n}\n\n// Left to right, wrapping when a span would overflow the columns. An item with\n// both `column` and `row` is placed there, 1-based, and left out of the flow.\nfunction autoPlace(items: readonly LayoutItem[], columns: number) {\n const placements: { col: number; row: number; colSpan: number; rowSpan: number }[] = [];\n const taken: boolean[][] = [];\n const isFree = (row: number, col: number, colSpan: number, rowSpan: number): boolean => {\n for (let r = 0; r < rowSpan; r++) {\n for (let c = 0; c < colSpan; c++) {\n if (taken[row + r]?.[col + c]) return false;\n }\n }\n return true;\n };\n const take = (row: number, col: number, colSpan: number, rowSpan: number): void => {\n for (let r = 0; r < rowSpan; r++) {\n taken[row + r] ??= [];\n for (let c = 0; c < colSpan; c++) taken[row + r][col + c] = true;\n }\n };\n\n let row = 0;\n let col = 0;\n for (const item of items) {\n const colSpan = Math.min(item.colSpan ?? 1, columns);\n const rowSpan = item.rowSpan ?? 1;\n if (item.column !== undefined && item.row !== undefined) {\n take(item.row - 1, item.column - 1, colSpan, rowSpan);\n placements.push({ col: item.column - 1, row: item.row - 1, colSpan, rowSpan });\n continue;\n }\n for (;;) {\n if (col + colSpan > columns) {\n row++;\n col = 0;\n }\n if (isFree(row, col, colSpan, rowSpan)) break;\n col++;\n }\n take(row, col, colSpan, rowSpan);\n placements.push({ col, row, colSpan, rowSpan });\n col += colSpan;\n }\n return placements;\n}\n\n// Content-sized rows grow to fit an item; a spanning item puts whatever its rows\n// are short of into the first of them.\nfunction grow(rows: number[], row: number, rowSpan: number, height: number, gap: number): void {\n if (rowSpan === 1) {\n if (height > rows[row]) rows[row] = height;\n return;\n }\n const short = height - spannedRows(rows, row, rowSpan, gap);\n if (short > 0) rows[row] += short;\n}\n\nfunction span(track: number, count: number, gap: number): number {\n return track * count + gap * (count - 1);\n}\n\nfunction spannedRows(rows: readonly number[], from: number, count: number, gap: number): number {\n let height = gap * (count - 1);\n for (let r = from; r < from + count; r++) height += rows[r] ?? 0;\n return height;\n}\n"]}
1
+ {"version":3,"file":"grid.js","sourceRoot":"","sources":["../../src/layout/grid.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CACvB,KAA4B,EAC5B,OAAe,EACf,SAAiB,EACjB,MAAc,EACd,KAAgB,EAChB,QAAsC;IAEtC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;IAC/C,MAAM,KAAK,G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;QAAE,MAAM,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACjE,OAAO,MAAM,CAAC;AAClB,CAAC","sourcesContent":["import type { Size2D } from \"@/attributes/layout/size\";\r\nimport type { MeasureContext2D } from \"@/render/measure-context\";\r\nimport type { BoxBounds } from \"./bounds\";\r\nimport type { SizeConstraints } from \"./constraints\";\r\nimport type { FlowSpace, LayoutItem } from \"./types\";\r\nimport { measureItem } from \"./item\";\r\n\r\n/**\r\n * Measures a grid: `columns` equal tracks across the width, and rows sized to\r\n * their content — or, when the height is bounded, divided equally so a\r\n * `fill`-height item has a share to fill. Each item's cell comes back from the\r\n * content box's top-left, y-down.\r\n */\r\nexport function measureGrid(\r\n items: readonly LayoutItem[],\r\n columns: number,\r\n columnGap: number,\r\n rowGap: number,\r\n space: FlowSpace,\r\n measurer: MeasureContext2D | undefined,\r\n): { sizes: Size2D[]; cells: BoxBounds[]; hug: Size2D } {\r\n const count = Math.max(1, Math.round(columns));\r\n const track = Math.max(0, (space.width - columnGap * (count - 1)) / count);\r\n const placements = autoPlace(items, count);\r\n const rowCount = placements.reduce((max, p) => Math.max(max, p.row + p.rowSpan), 0);\r\n\r\n const bounded = space.hugHeight !== true && rowCount > 0;\r\n const equalRow = bounded ? Math.max(0, (space.height - rowGap * (rowCount - 1)) / rowCount) : 0;\r\n const rows = new Array<number>(rowCount).fill(equalRow);\r\n\r\n const sizes = items.map((item, i) => {\r\n const p = placements[i];\r\n const width = span(track, p.colSpan, columnGap);\r\n const constraints: SizeConstraints = bounded\r\n ? { maxWidth: width, maxHeight: span(equalRow, p.rowSpan, rowGap) }\r\n : { maxWidth: width };\r\n const size = measureItem(item, constraints, measurer);\r\n // Bounded rows are already equal, and content may not grow one past its share.\r\n if (!bounded) grow(rows, p.row, p.rowSpan, size.height, rowGap);\r\n return size;\r\n });\r\n\r\n const tops: number[] = [];\r\n let top = 0;\r\n for (const height of rows) {\r\n tops.push(top);\r\n top += height + rowGap;\r\n }\r\n const cells = placements.map((p) => ({\r\n x: p.col * (track + columnGap),\r\n y: tops[p.row] ?? 0,\r\n width: span(track, p.colSpan, columnGap),\r\n height: spannedRows(rows, p.row, p.rowSpan, rowGap),\r\n }));\r\n const height = rows.reduce((sum, h) => sum + h, 0) + rowGap * Math.max(0, rowCount - 1);\r\n return { sizes, cells, hug: { width: space.width, height } };\r\n}\r\n\r\n/** Each item's cell, clamped to the content box, centre-relative and y-up. */\r\nexport function placeGrid(cells: readonly BoxBounds[], inner: Size2D): BoxBounds[] {\r\n return cells.map((cell) => ({\r\n x: cell.x + cell.width / 2 - inner.width / 2,\r\n y: inner.height / 2 - cell.y - cell.height / 2,\r\n width: Math.min(cell.width, inner.width),\r\n height: Math.min(cell.height, inner.height),\r\n }));\r\n}\r\n\r\n// Left to right, wrapping when a span would overflow the columns. An item with\r\n// both `column` and `row` is placed there, 1-based, and left out of the flow.\r\nfunction autoPlace(items: readonly LayoutItem[], columns: number) {\r\n const placements: { col: number; row: number; colSpan: number; rowSpan: number }[] = [];\r\n const taken: boolean[][] = [];\r\n const isFree = (row: number, col: number, colSpan: number, rowSpan: number): boolean => {\r\n for (let r = 0; r < rowSpan; r++) {\r\n for (let c = 0; c < colSpan; c++) {\r\n if (taken[row + r]?.[col + c]) return false;\r\n }\r\n }\r\n return true;\r\n };\r\n const take = (row: number, col: number, colSpan: number, rowSpan: number): void => {\r\n for (let r = 0; r < rowSpan; r++) {\r\n taken[row + r] ??= [];\r\n for (let c = 0; c < colSpan; c++) taken[row + r][col + c] = true;\r\n }\r\n };\r\n\r\n let row = 0;\r\n let col = 0;\r\n for (const item of items) {\r\n const colSpan = Math.min(item.colSpan ?? 1, columns);\r\n const rowSpan = item.rowSpan ?? 1;\r\n if (item.column !== undefined && item.row !== undefined) {\r\n take(item.row - 1, item.column - 1, colSpan, rowSpan);\r\n placements.push({ col: item.column - 1, row: item.row - 1, colSpan, rowSpan });\r\n continue;\r\n }\r\n for (;;) {\r\n if (col + colSpan > columns) {\r\n row++;\r\n col = 0;\r\n }\r\n if (isFree(row, col, colSpan, rowSpan)) break;\r\n col++;\r\n }\r\n take(row, col, colSpan, rowSpan);\r\n placements.push({ col, row, colSpan, rowSpan });\r\n col += colSpan;\r\n }\r\n return placements;\r\n}\r\n\r\n// Content-sized rows grow to fit an item; a spanning item puts whatever its rows\r\n// are short of into the first of them.\r\nfunction grow(rows: number[], row: number, rowSpan: number, height: number, gap: number): void {\r\n if (rowSpan === 1) {\r\n if (height > rows[row]) rows[row] = height;\r\n return;\r\n }\r\n const short = height - spannedRows(rows, row, rowSpan, gap);\r\n if (short > 0) rows[row] += short;\r\n}\r\n\r\nfunction span(track: number, count: number, gap: number): number {\r\n return track * count + gap * (count - 1);\r\n}\r\n\r\nfunction spannedRows(rows: readonly number[], from: number, count: number, gap: number): number {\r\n let height = gap * (count - 1);\r\n for (let r = from; r < from + count; r++) height += rows[r] ?? 0;\r\n return height;\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/layout/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC","sourcesContent":["/**\n * Layout.\n *\n * One value — {@link flowOps} — arranges items by the `flow` vocabulary: a node's\n * children, or anything a node lays out itself. It replaced `measureFlex`,\n * `layoutFlex`, their wrapped twins, `measureGrid`/`layoutGrid`,\n * `layoutFlowChildren` and the `FlowLayout` engine, which between them placed\n * freeform four times and a run twice.\n */\nexport { flowOps } from \"./ops\";\nexport type * from \"./types\";\nexport * from \"./bounds\";\nexport * from \"./constraints\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/layout/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC","sourcesContent":["/**\r\n * Layout.\r\n *\r\n * One value — {@link flowOps} — arranges items by the `flow` vocabulary: a node's\r\n * children, or anything a node lays out itself. It replaced `measureFlex`,\r\n * `layoutFlex`, their wrapped twins, `measureGrid`/`layoutGrid`,\r\n * `layoutFlowChildren` and the `FlowLayout` engine, which between them placed\r\n * freeform four times and a run twice.\r\n */\r\nexport { flowOps } from \"./ops\";\r\nexport type * from \"./types\";\r\nexport * from \"./bounds\";\r\nexport * from \"./constraints\";\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"item.js","sourceRoot":"","sources":["../../src/layout/item.ts"],"names":[],"mappings":"AAKA,sFAAsF;AACtF,MAAM,UAAU,WAAW,CACvB,IAAgB,EAChB,WAA4B,EAC5B,QAAsC;IAEtC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;QACjD,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;IAChE,CAAC;IACD,OAAO;QACH,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,WAAW,CAAC,QAAQ,CAAC;QACjD,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,SAAS,CAAC;KACvD,CAAC;AACN,CAAC;AAED,SAAS,QAAQ,CAAC,KAAgB,EAAE,SAA6B;IAC7D,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5C,OAAO,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACjD,CAAC","sourcesContent":["import type { Size2D, SizeInput } from \"@/attributes/layout/size\";\nimport type { MeasureContext2D } from \"@/render/measure-context\";\nimport type { SizeConstraints } from \"./constraints\";\nimport type { LayoutItem } from \"./types\";\n\n/** An item's size under `constraints` — through its own `measure` when it has one. */\nexport function measureItem(\n item: LayoutItem,\n constraints: SizeConstraints,\n measurer: MeasureContext2D | undefined,\n): Size2D {\n if (item.measure) {\n const size = item.measure(constraints, measurer);\n return { width: size.width ?? 0, height: size.height ?? 0 };\n }\n return {\n width: extentOf(item.width, constraints.maxWidth),\n height: extentOf(item.height, constraints.maxHeight),\n };\n}\n\nfunction extentOf(input: SizeInput, available: number | undefined): number {\n if (typeof input === \"number\") return input;\n return input === \"fill\" ? available ?? 0 : 0;\n}\n"]}
1
+ {"version":3,"file":"item.js","sourceRoot":"","sources":["../../src/layout/item.ts"],"names":[],"mappings":"AAKA,sFAAsF;AACtF,MAAM,UAAU,WAAW,CACvB,IAAgB,EAChB,WAA4B,EAC5B,QAAsC;IAEtC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;QACjD,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;IAChE,CAAC;IACD,OAAO;QACH,KAAK,EAAE,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,WAAW,CAAC,QAAQ,CAAC;QACjD,MAAM,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,SAAS,CAAC;KACvD,CAAC;AACN,CAAC;AAED,SAAS,QAAQ,CAAC,KAAgB,EAAE,SAA6B;IAC7D,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5C,OAAO,KAAK,KAAK,MAAM,CAAC,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACjD,CAAC","sourcesContent":["import type { Size2D, SizeInput } from \"@/attributes/layout/size\";\r\nimport type { MeasureContext2D } from \"@/render/measure-context\";\r\nimport type { SizeConstraints } from \"./constraints\";\r\nimport type { LayoutItem } from \"./types\";\r\n\r\n/** An item's size under `constraints` — through its own `measure` when it has one. */\r\nexport function measureItem(\r\n item: LayoutItem,\r\n constraints: SizeConstraints,\r\n measurer: MeasureContext2D | undefined,\r\n): Size2D {\r\n if (item.measure) {\r\n const size = item.measure(constraints, measurer);\r\n return { width: size.width ?? 0, height: size.height ?? 0 };\r\n }\r\n return {\r\n width: extentOf(item.width, constraints.maxWidth),\r\n height: extentOf(item.height, constraints.maxHeight),\r\n };\r\n}\r\n\r\nfunction extentOf(input: SizeInput, available: number | undefined): number {\r\n if (typeof input === \"number\") return input;\r\n return input === \"fill\" ? available ?? 0 : 0;\r\n}\r\n"]}
@@ -19,6 +19,12 @@ export interface FlowOps {
19
19
  place(measure: FlowMeasure, settings: FlowSettings, inner: Size2D): BoxBounds[];
20
20
  /** Whether `measure` still holds for a content box of `inner`'s size. */
21
21
  reusable(measure: FlowMeasure, inner: Size2D): boolean;
22
+ /**
23
+ * Where `settings` would put one more item of `size` in a content box of
24
+ * `inner`'s size, centred and y-up like `place`; `null` when they arrange
25
+ * their items in a run or a grid, where the slot depends on the others.
26
+ */
27
+ freeSlot(settings: FlowSettings, inner: Size2D, size: Size2D): BoxBounds | null;
22
28
  /** The content box a `width` × `height` container measures its items in. */
23
29
  contentBox(sizing: Pick<LayoutItem, "width" | "height">, constraints: SizeConstraints, padding: InsetsResolved): FlowSpace;
24
30
  /** The container's own size, given the `hug` extent its items came to. */
@@ -1 +1 @@
1
- {"version":3,"file":"ops.d.ts","sourceRoot":"","sources":["../../src/layout/ops.ts"],"names":[],"mappings":"AAeA,OAAO,EAAa,KAAK,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5E,OAAO,EAAgB,KAAK,MAAM,EAAkB,MAAM,0BAA0B,CAAC;AAErF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CA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AC;IAClB,2EAA2E;IAC3E,KAAK,CAAC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,CAAC;IAChF,yEAAyE;IACzE,QAAQ,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IACvD;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IAGhF,4EAA4E;IAC5E,UAAU,CACN,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,OAAO,GAAG,QAAQ,CAAC,EAAE,WAAW,EAAE,eAAe,EAAE,OAAO,EAAE,cAAc,GACpG,SAAS,CAAC;IACb,0EAA0E;IAC1E,IAAI,CACA,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,OAAO,GAAG,QAAQ,CAAC,EAAE,WAAW,EAAE,eAAe,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,GACjH,MAAM,CAAC;IAGV,6EAA6E;IAC7E,YAAY,CAAC,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;CAClE;AAiKD,eAAO,MAAM,OAAO,EAAE,YAAY,CAAC,QAAQ,EAAE,YAAY,CAAC,GAAG,OAc5D,CAAC"}
@@ -121,6 +121,11 @@ function placeMode(measure, settings, inner) {
121
121
  return placeFreeform(measure.sizes, inner, align);
122
122
  return placeRun(measure.sizes, measure.lines ?? [], measure.gapScales ?? [], measure.mode === "horizontal", settings.gap ?? 0, crossGap(settings), align, inner);
123
123
  }
124
+ function freeSlot(settings, inner, size) {
125
+ if ((settings.flow ?? "freeform") !== "freeform")
126
+ return null;
127
+ return placeFreeform([size], inner, alignOf(settings))[0];
128
+ }
124
129
  // A container stores `align` resolved, so only a named key needs resolving here.
125
130
  function alignOf(settings) {
126
131
  const align = settings.align;
@@ -160,6 +165,7 @@ export const flowOps = {
160
165
  measure,
161
166
  place,
162
167
  reusable,
168
+ freeSlot,
163
169
  contentBox,
164
170
  size,
165
171
  collapsedRun,
@@ -1 +1 @@
1
- {"version":3,"file":"ops.js","sourceRoot":"","sources":["../../src/layout/ops.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAuB,MAAM,4BAA4B,CAAC;AAC5E,OAAO,EAAE,YAAY,EAA+B,MAAM,0BAA0B,CAAC;AAIrF,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAsChD,MAAM,MAAM,GAAY,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AAEvC,SAAS,OAAO,CACZ,QAAsB,EAAE,KAAmB,EAAE,GAAW,EAAE,QAA2B;IAErF,MAAM,KAAK,GAAG,SAAS,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC;IACrG,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;IAChF,oEAAoE;IACpE,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAA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OAAO,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;AACzE,CAAC;AAED,SAAS,IAAI,CAAC,CAAS,EAAE,CAAS;IAC9B,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACzB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IAC7D,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3E,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,GAAmD;IACnE,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK;IACzB,IAAI;IAEJ,OAAO;IACP,OAAO;IACP,KAAK;IACL,QAAQ;IAER,UAAU;IACV,IAAI;IAEJ,YAAY;CACf,CAAC","sourcesContent":["/**\n * Every layout operation, on one object — for the node tree, and for anything a\n * node lays out itself, like a row of `Graphics2D` shapes inside `renderSelf`.\n *\n * It takes plain data and returns boxes, and writes to nothing it is handed: a\n * node keeps its own measure between passes. Its `resolve`/`lerp` pair is the\n * `flow` prop's, which is how a tween between two modes lives in the prop's value\n * and a seek that restores the prop restores the blend with it.\n *\n * Boxes are centred on the content box and y-up — the space `Graphics2D` draws\n * in. `Node2D` converts once, where it hands a box to a child.\n *\n * Each method is the module function of the same name.\n */\nimport { alignmentOps } from \"@/attributes/layout/alignment\";\nimport { insetsOps, type InsetsResolved } from \"@/attributes/layout/insets\";\nimport { sizeInputOps, type Size2D, type SizeInput } from \"@/attributes/layout/size\";\nimport type { Vector2 } from \"@/attributes/layout/vector2\";\nimport type { AttributeOps } from \"@/attributes/shared/operators\";\nimport type { MeasureContext2D } from \"@/render/measure-context\";\nimport { lerpNumber } from \"@/tween/lerp\";\nimport type { BoxBounds } from \"./bounds\";\nimport type { SizeConstraints } from \"./constraints\";\nimport { measureRun, measureWrap, placeRun } from \"./flex\";\nimport { measureFreeform, placeFreeform } from \"./freeform\";\nimport { measureGrid, placeGrid } from \"./grid\";\nimport type { FlowMeasure, FlowMode, FlowResolved, FlowSettings, FlowSpace, LayoutItem } from \"./types\";\n\n/** The `flow` attribute's operations beyond `resolve`/`lerp`. */\nexport interface FlowOps {\n // ── Arranging ──────────────────────────────────────────────────────────\n /**\n * Lay `items` out in a box of `box`'s size, inset by `settings.padding`.\n * Boxes come back centred on `box` and y-up. Pass a `measurer` when an item\n * measures text.\n */\n arrange<I extends LayoutItem>(\n settings: FlowSettings, items: readonly I[], box: Size2D, measurer?: MeasureContext2D,\n ): BoxBounds[];\n /** The first half of `arrange`: each item's size, and the extent a hugging container wraps. */\n measure<I extends LayoutItem>(\n settings: FlowSettings, items: readonly I[], space: FlowSpace, measurer?: MeasureContext2D,\n ): FlowMeasure<I>;\n /** The second half: each item's box in a content box of `inner`'s size. */\n place(measure: FlowMeasure, settings: FlowSettings, inner: Size2D): BoxBounds[];\n /** Whether `measure` still holds for a content box of `inner`'s size. */\n reusable(measure: FlowMeasure, inner: Size2D): boolean;\n\n // ── Sizing a container ─────────────────────────────────────────────────\n /** The content box a `width` × `height` container measures its items in. */\n contentBox(\n sizing: Pick<LayoutItem, \"width\" | \"height\">, constraints: SizeConstraints, padding: InsetsResolved,\n ): FlowSpace;\n /** The container's own size, given the `hug` extent its items came to. */\n size(\n sizing: Pick<LayoutItem, \"width\" | \"height\">, constraints: SizeConstraints, padding: InsetsResolved, hug: Size2D,\n ): Size2D;\n\n // ── Diagnostics ────────────────────────────────────────────────────────\n /** What is wrong with a run laid out in a box of `box`'s size, or `null`. */\n collapsedRun(measure: FlowMeasure, box: Size2D): string | null;\n}\n\nconst CENTRE: Vector2 = { x: 0, y: 0 };\n\nfunction arrange<I extends LayoutItem>(\n settings: FlowSettings, items: readonly I[], box: Size2D, measurer?: MeasureContext2D,\n): BoxBounds[] {\n const inner = insetsOps.insetBounds(box.width, box.height, insetsOps.resolve(settings.padding ?? 0));\n const boxes = place(measure(settings, items, inner, measurer), settings, inner);\n // `insetBounds` offsets the content box y-down; the boxes are y-up.\n return boxes.map((b) => ({ x: b.x + inner.x, y: b.y - inner.y, width: b.width, height: b.height }));\n}\n\nfunction measure<I extends LayoutItem>(\n settings: FlowSettings, items: readonly I[], space: FlowSpace, measurer?: MeasureContext2D,\n): FlowMeasure<I> {\n const flow = settings.flow ?? \"freeform\";\n if (typeof flow === \"string\") return measureMode(flow, settings, items, space, measurer);\n const from = measureMode(flow.from, settings, items, space, measurer);\n const to = measureMode(flow.to, settings, items, space, measurer);\n return { ...to, hug: lerpSize(from.hug, to.hug, flow.t), from, t: flow.t };\n}\n\nfunction place(measure: FlowMeasure, settings: FlowSettings, inner: Size2D): BoxBounds[] {\n const to = placeMode(measure, settings, inner);\n const from = measure.from;\n if (!from) return to;\n const fromBoxes = placeMode(from, settings, inner);\n const t = measure.t ?? 1;\n return to.map((box, i) => ({\n x: lerpNumber(fromBoxes[i].x, box.x, t),\n y: lerpNumber(fromBoxes[i].y, box.y, t),\n width: lerpNumber(fromBoxes[i].width, box.width, t),\n height: lerpNumber(fromBoxes[i].height, box.height, t),\n }));\n}\n\n// Yoga's rule: reuse on an axis laid out at the size it was measured in, or — on\n// an axis that hugs — at exactly what it hugged. Anything else, a parent laid this\n// out at a size it did not measure it for, and the measure is stale.\nfunction reusable(measure: FlowMeasure, inner: Size2D): boolean {\n const { space, hug } = measure;\n return fits(inner.width, space.width, space.hugWidth, hug.width)\n && fits(inner.height, space.height, space.hugHeight, hug.height);\n}\n\nfunction contentBox(\n sizing: Pick<LayoutItem, \"width\" | \"height\">, constraints: SizeConstraints, padding: InsetsResolved,\n): FlowSpace {\n const width = outerFor(sizing.width, constraints.maxWidth);\n const height = outerFor(sizing.height, constraints.maxHeight);\n const inner = insetsOps.insetBounds(width, height, padding);\n return {\n width: inner.width,\n height: inner.height,\n hugWidth: sizing.width === \"hug\",\n hugHeight: sizing.height === \"hug\",\n };\n}\n\nfunction size(\n sizing: Pick<LayoutItem, \"width\" | \"height\">, constraints: SizeConstraints, padding: InsetsResolved, hug: Size2D,\n): Size2D {\n const hugged = insetsOps.outsetSize(hug.width, hug.height, padding);\n return {\n width: sizing.width === \"hug\" ? hugged.width : outerFor(sizing.width, constraints.maxWidth),\n height: sizing.height === \"hug\" ? hugged.height : outerFor(sizing.height, constraints.maxHeight),\n };\n}\n\n/**\n * A run laid out in a box of length 0 on its main axis, with items that have a\n * size. Always a bug, and a quiet one: a run is placed from the box's centre, so\n * its first item's leading edge lands on the centre and everything after follows —\n * content displaced by half a box it does not visibly have, which reads as \"the\n * scene loaded at 0,0\" rather than as a layout fault. A box holding only collapsed\n * items is legitimately empty: an animated insert or remove mid-flight.\n */\nfunction collapsedRun(measure: FlowMeasure, box: Size2D): string | null {\n if (measure.mode !== \"horizontal\" && measure.mode !== \"vertical\") return null;\n if ((measure.mode === \"horizontal\" ? box.width : box.height) > 0) return null;\n const sized = measure.sizes.filter((s) => s.width > 0 || s.height > 0).length;\n if (sized === 0) return null;\n return `is laying out ${sized} sized child${sized === 1 ? \"\" : \"ren\"} in a run of length 0 `\n + `(${box.width}×${box.height}, ${measure.mode}). `\n + `They will be positioned from its centre rather than its leading edge.`;\n}\n\n// A `from` that is itself a blend — a tween built mid-blend — starts from where it was heading.\nfunction lerp(from: FlowResolved, to: FlowResolved, t: number): FlowResolved {\n const a = typeof from === \"string\" ? from : from.to;\n const b = typeof to === \"string\" ? to : to.to;\n return t >= 1 || a === b ? b : { from: a, to: b, t };\n}\n\nfunction measureMode<I extends LayoutItem>(\n mode: FlowMode, settings: FlowSettings, items: readonly I[], space: FlowSpace, measurer: MeasureContext2D | undefined,\n): FlowMeasure<I> {\n if (mode === \"freeform\") return { mode, items, space, ...measureFreeform(items, space, measurer) };\n if (mode === \"grid\") {\n const grid = measureGrid(items, settings.columns ?? 1, mainGap(settings), crossGap(settings), space, measurer);\n return { mode, items, space, ...grid };\n }\n const horizontal = mode === \"horizontal\";\n const run = settings.wrap\n ? measureWrap(items, horizontal, settings.gap ?? 0, crossGap(settings), space, measurer)\n : measureRun(items, horizontal, settings.gap ?? 0, space, measurer);\n return { mode, items, space, ...run };\n}\n\nfunction placeMode(measure: FlowMeasure, settings: FlowSettings, inner: Size2D): BoxBounds[] {\n if (measure.mode === \"grid\") return placeGrid(measure.cells ?? [], inner);\n const align = alignOf(settings);\n if (measure.mode === \"freeform\") return placeFreeform(measure.sizes, inner, align);\n return placeRun(\n measure.sizes, measure.lines ?? [], measure.gapScales ?? [], measure.mode === \"horizontal\",\n settings.gap ?? 0, crossGap(settings), align, inner,\n );\n}\n\n// A container stores `align` resolved, so only a named key needs resolving here.\nfunction alignOf(settings: FlowSettings): Vector2 {\n const align = settings.align;\n if (align === undefined) return CENTRE;\n return typeof align === \"string\" ? alignmentOps.resolve(align) : align;\n}\n\nfunction mainGap(settings: FlowSettings): number {\n const gap = settings.gap ?? 0;\n return gap === \"auto\" ? 0 : gap;\n}\n\nfunction crossGap(settings: FlowSettings): number {\n return settings.crossGap ?? mainGap(settings);\n}\n\n// A hugging axis measures its items against all the room it could have.\nfunction outerFor(input: SizeInput, max: number | undefined): number {\n const available = max ?? 0;\n return input === \"hug\" ? available : sizeInputOps.resolveLayout(input, available, 0);\n}\n\nfunction lerpSize(from: Size2D, to: Size2D, t: number): Size2D {\n return { width: lerpNumber(from.width, to.width, t), height: lerpNumber(from.height, to.height, t) };\n}\n\nfunction fits(laid: number, measured: number, hugs: boolean | undefined, hugged: number): boolean {\n return near(laid, measured) || (hugs === true && near(laid, hugged));\n}\n\nfunction near(a: number, b: number): boolean {\n if (a === b) return true;\n if (!Number.isFinite(a) || !Number.isFinite(b)) return false;\n return Math.abs(a - b) <= 1e-6 * Math.max(1, Math.abs(a), Math.abs(b));\n}\n\nexport const flowOps: AttributeOps<FlowMode, FlowResolved> & FlowOps = {\n resolve: (value) => value,\n lerp,\n\n arrange,\n measure,\n place,\n reusable,\n\n contentBox,\n size,\n\n collapsedRun,\n};\n"]}
1
+ {"version":3,"file":"ops.js","sourceRoot":"","sources":["../../src/layout/ops.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAuB,MAAM,4BAA4B,CAAC;AAC5E,OAAO,EAAE,YAAY,EAA+B,MAAM,0BAA0B,CAAC;AAIrF,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG1C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AA4ChD,MAAM,MAAM,GAAY,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AAEvC,SAAS,OAAO,CACZ,QAAsB,EAAE,KAAmB,EAAE,GAAW,EAAE,QAA2B;IAErF,MAAM,KAAK,GAAG,SAAS,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC;IACrG,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;IAChF,oEAAoE;IACpE,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CA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AAS,QAAQ,CAAC,IAAY,EAAE,EAAU,EAAE,CAAS;IACjD,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC;AACzG,CAAC;AAED,SAAS,IAAI,CAAC,IAAY,EAAE,QAAgB,EAAE,IAAyB,EAAE,MAAc;IACnF,OAAO,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;AACzE,CAAC;AAED,SAAS,IAAI,CAAC,CAAS,EAAE,CAAS;IAC9B,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACzB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IAC7D,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3E,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,GAAmD;IACnE,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK;IACzB,IAAI;IAEJ,OAAO;IACP,OAAO;IACP,KAAK;IACL,QAAQ;IACR,QAAQ;IAER,UAAU;IACV,IAAI;IAEJ,YAAY;CACf,CAAC","sourcesContent":["/**\r\n * Every layout operation, on one object — for the node tree, and for anything a\r\n * node lays out itself, like a row of `Graphics2D` shapes inside `renderSelf`.\r\n *\r\n * It takes plain data and returns boxes, and writes to nothing it is handed: a\r\n * node keeps its own measure between passes. Its `resolve`/`lerp` pair is the\r\n * `flow` prop's, which is how a tween between two modes lives in the prop's value\r\n * and a seek that restores the prop restores the blend with it.\r\n *\r\n * Boxes are centred on the content box and y-up — the space `Graphics2D` draws\r\n * in. `Node2D` converts once, where it hands a box to a child.\r\n *\r\n * Each method is the module function of the same name.\r\n */\r\nimport { alignmentOps } from \"@/attributes/layout/alignment\";\r\nimport { insetsOps, type InsetsResolved } from \"@/attributes/layout/insets\";\r\nimport { sizeInputOps, type Size2D, type SizeInput } from \"@/attributes/layout/size\";\r\nimport type { Vector2 } from \"@/attributes/layout/vector2\";\r\nimport type { AttributeOps } from \"@/attributes/shared/operators\";\r\nimport type { MeasureContext2D } from \"@/render/measure-context\";\r\nimport { lerpNumber } from \"@/tween/lerp\";\r\nimport type { BoxBounds } from \"./bounds\";\r\nimport type { SizeConstraints } from \"./constraints\";\r\nimport { measureRun, measureWrap, placeRun } from \"./flex\";\r\nimport { measureFreeform, placeFreeform } from \"./freeform\";\r\nimport { measureGrid, placeGrid } from \"./grid\";\r\nimport type { FlowMeasure, FlowMode, FlowResolved, FlowSettings, FlowSpace, LayoutItem } from \"./types\";\r\n\r\n/** The `flow` attribute's operations beyond `resolve`/`lerp`. */\r\nexport interface FlowOps {\r\n // ── Arranging ──────────────────────────────────────────────────────────\r\n /**\r\n * Lay `items` out in a box of `box`'s size, inset by `settings.padding`.\r\n * Boxes come back centred on `box` and y-up. Pass a `measurer` when an item\r\n * measures text.\r\n */\r\n arrange<I extends LayoutItem>(\r\n settings: FlowSettings, items: readonly I[], box: Size2D, measurer?: MeasureContext2D,\r\n ): BoxBounds[];\r\n /** The first half of `arrange`: each item's size, and the extent a hugging container wraps. */\r\n measure<I extends LayoutItem>(\r\n settings: FlowSettings, items: readonly I[], space: FlowSpace, measurer?: MeasureContext2D,\r\n ): FlowMeasure<I>;\r\n /** The second half: each item's box in a content box of `inner`'s size. */\r\n place(measure: FlowMeasure, settings: FlowSettings, inner: Size2D): BoxBounds[];\r\n /** Whether `measure` still holds for a content box of `inner`'s size. */\r\n reusable(measure: FlowMeasure, inner: Size2D): boolean;\r\n /**\r\n * Where `settings` would put one more item of `size` in a content box of\r\n * `inner`'s size, centred and y-up like `place`; `null` when they arrange\r\n * their items in a run or a grid, where the slot depends on the others.\r\n */\r\n freeSlot(settings: FlowSettings, inner: Size2D, size: Size2D): BoxBounds | null;\r\n\r\n // ── Sizing a container ─────────────────────────────────────────────────\r\n /** The content box a `width` × `height` container measures its items in. */\r\n contentBox(\r\n sizing: Pick<LayoutItem, \"width\" | \"height\">, constraints: SizeConstraints, padding: InsetsResolved,\r\n ): FlowSpace;\r\n /** The container's own size, given the `hug` extent its items came to. */\r\n size(\r\n sizing: Pick<LayoutItem, \"width\" | \"height\">, constraints: SizeConstraints, padding: InsetsResolved, hug: Size2D,\r\n ): Size2D;\r\n\r\n // ── Diagnostics ────────────────────────────────────────────────────────\r\n /** What is wrong with a run laid out in a box of `box`'s size, or `null`. */\r\n collapsedRun(measure: FlowMeasure, box: Size2D): string | null;\r\n}\r\n\r\nconst CENTRE: Vector2 = { x: 0, y: 0 };\r\n\r\nfunction arrange<I extends LayoutItem>(\r\n settings: FlowSettings, items: readonly I[], box: Size2D, measurer?: MeasureContext2D,\r\n): BoxBounds[] {\r\n const inner = insetsOps.insetBounds(box.width, box.height, insetsOps.resolve(settings.padding ?? 0));\r\n const boxes = place(measure(settings, items, inner, measurer), settings, inner);\r\n // `insetBounds` offsets the content box y-down; the boxes are y-up.\r\n return boxes.map((b) => ({ x: b.x + inner.x, y: b.y - inner.y, width: b.width, height: b.height }));\r\n}\r\n\r\nfunction measure<I extends LayoutItem>(\r\n settings: FlowSettings, items: readonly I[], space: FlowSpace, measurer?: MeasureContext2D,\r\n): FlowMeasure<I> {\r\n const flow = settings.flow ?? \"freeform\";\r\n if (typeof flow === \"string\") return measureMode(flow, settings, items, space, measurer);\r\n const from = measureMode(flow.from, settings, items, space, measurer);\r\n const to = measureMode(flow.to, settings, items, space, measurer);\r\n return { ...to, hug: lerpSize(from.hug, to.hug, flow.t), from, t: flow.t };\r\n}\r\n\r\nfunction place(measure: FlowMeasure, settings: FlowSettings, inner: Size2D): BoxBounds[] {\r\n const to = placeMode(measure, settings, inner);\r\n const from = measure.from;\r\n if (!from) return to;\r\n const fromBoxes = placeMode(from, settings, inner);\r\n const t = measure.t ?? 1;\r\n return to.map((box, i) => ({\r\n x: lerpNumber(fromBoxes[i].x, box.x, t),\r\n y: lerpNumber(fromBoxes[i].y, box.y, t),\r\n width: lerpNumber(fromBoxes[i].width, box.width, t),\r\n height: lerpNumber(fromBoxes[i].height, box.height, t),\r\n }));\r\n}\r\n\r\n// Yoga's rule: reuse on an axis laid out at the size it was measured in, or — on\r\n// an axis that hugs — at exactly what it hugged. Anything else, a parent laid this\r\n// out at a size it did not measure it for, and the measure is stale.\r\nfunction reusable(measure: FlowMeasure, inner: Size2D): boolean {\r\n const { space, hug } = measure;\r\n return fits(inner.width, space.width, space.hugWidth, hug.width)\r\n && fits(inner.height, space.height, space.hugHeight, hug.height);\r\n}\r\n\r\nfunction contentBox(\r\n sizing: Pick<LayoutItem, \"width\" | \"height\">, constraints: SizeConstraints, padding: InsetsResolved,\r\n): FlowSpace {\r\n const width = outerFor(sizing.width, constraints.maxWidth);\r\n const height = outerFor(sizing.height, constraints.maxHeight);\r\n const inner = insetsOps.insetBounds(width, height, padding);\r\n return {\r\n width: inner.width,\r\n height: inner.height,\r\n hugWidth: sizing.width === \"hug\",\r\n hugHeight: sizing.height === \"hug\",\r\n };\r\n}\r\n\r\nfunction size(\r\n sizing: Pick<LayoutItem, \"width\" | \"height\">, constraints: SizeConstraints, padding: InsetsResolved, hug: Size2D,\r\n): Size2D {\r\n const hugged = insetsOps.outsetSize(hug.width, hug.height, padding);\r\n return {\r\n width: sizing.width === \"hug\" ? hugged.width : outerFor(sizing.width, constraints.maxWidth),\r\n height: sizing.height === \"hug\" ? hugged.height : outerFor(sizing.height, constraints.maxHeight),\r\n };\r\n}\r\n\r\n/**\r\n * A run laid out in a box of length 0 on its main axis, with items that have a\r\n * size. Always a bug, and a quiet one: a run is placed from the box's centre, so\r\n * its first item's leading edge lands on the centre and everything after follows —\r\n * content displaced by half a box it does not visibly have, which reads as \"the\r\n * scene loaded at 0,0\" rather than as a layout fault. A box holding only collapsed\r\n * items is legitimately empty: an animated insert or remove mid-flight.\r\n */\r\nfunction collapsedRun(measure: FlowMeasure, box: Size2D): string | null {\r\n if (measure.mode !== \"horizontal\" && measure.mode !== \"vertical\") return null;\r\n if ((measure.mode === \"horizontal\" ? box.width : box.height) > 0) return null;\r\n const sized = measure.sizes.filter((s) => s.width > 0 || s.height > 0).length;\r\n if (sized === 0) return null;\r\n return `is laying out ${sized} sized child${sized === 1 ? \"\" : \"ren\"} in a run of length 0 `\r\n + `(${box.width}×${box.height}, ${measure.mode}). `\r\n + `They will be positioned from its centre rather than its leading edge.`;\r\n}\r\n\r\n// A `from` that is itself a blend — a tween built mid-blend — starts from where it was heading.\r\nfunction lerp(from: FlowResolved, to: FlowResolved, t: number): FlowResolved {\r\n const a = typeof from === \"string\" ? from : from.to;\r\n const b = typeof to === \"string\" ? to : to.to;\r\n return t >= 1 || a === b ? b : { from: a, to: b, t };\r\n}\r\n\r\nfunction measureMode<I extends LayoutItem>(\r\n mode: FlowMode, settings: FlowSettings, items: readonly I[], space: FlowSpace, measurer: MeasureContext2D | undefined,\r\n): FlowMeasure<I> {\r\n if (mode === \"freeform\") return { mode, items, space, ...measureFreeform(items, space, measurer) };\r\n if (mode === \"grid\") {\r\n const grid = measureGrid(items, settings.columns ?? 1, mainGap(settings), crossGap(settings), space, measurer);\r\n return { mode, items, space, ...grid };\r\n }\r\n const horizontal = mode === \"horizontal\";\r\n const run = settings.wrap\r\n ? measureWrap(items, horizontal, settings.gap ?? 0, crossGap(settings), space, measurer)\r\n : measureRun(items, horizontal, settings.gap ?? 0, space, measurer);\r\n return { mode, items, space, ...run };\r\n}\r\n\r\nfunction placeMode(measure: FlowMeasure, settings: FlowSettings, inner: Size2D): BoxBounds[] {\r\n if (measure.mode === \"grid\") return placeGrid(measure.cells ?? [], inner);\r\n const align = alignOf(settings);\r\n if (measure.mode === \"freeform\") return placeFreeform(measure.sizes, inner, align);\r\n return placeRun(\r\n measure.sizes, measure.lines ?? [], measure.gapScales ?? [], measure.mode === \"horizontal\",\r\n settings.gap ?? 0, crossGap(settings), align, inner,\r\n );\r\n}\r\n\r\nfunction freeSlot(settings: FlowSettings, inner: Size2D, size: Size2D): BoxBounds | null {\r\n if ((settings.flow ?? \"freeform\") !== \"freeform\") return null;\r\n return placeFreeform([size], inner, alignOf(settings))[0];\r\n}\r\n\r\n// A container stores `align` resolved, so only a named key needs resolving here.\r\nfunction alignOf(settings: FlowSettings): Vector2 {\r\n const align = settings.align;\r\n if (align === undefined) return CENTRE;\r\n return typeof align === \"string\" ? alignmentOps.resolve(align) : align;\r\n}\r\n\r\nfunction mainGap(settings: FlowSettings): number {\r\n const gap = settings.gap ?? 0;\r\n return gap === \"auto\" ? 0 : gap;\r\n}\r\n\r\nfunction crossGap(settings: FlowSettings): number {\r\n return settings.crossGap ?? mainGap(settings);\r\n}\r\n\r\n// A hugging axis measures its items against all the room it could have.\r\nfunction outerFor(input: SizeInput, max: number | undefined): number {\r\n const available = max ?? 0;\r\n return input === \"hug\" ? available : sizeInputOps.resolveLayout(input, available, 0);\r\n}\r\n\r\nfunction lerpSize(from: Size2D, to: Size2D, t: number): Size2D {\r\n return { width: lerpNumber(from.width, to.width, t), height: lerpNumber(from.height, to.height, t) };\r\n}\r\n\r\nfunction fits(laid: number, measured: number, hugs: boolean | undefined, hugged: number): boolean {\r\n return near(laid, measured) || (hugs === true && near(laid, hugged));\r\n}\r\n\r\nfunction near(a: number, b: number): boolean {\r\n if (a === b) return true;\r\n if (!Number.isFinite(a) || !Number.isFinite(b)) return false;\r\n return Math.abs(a - b) <= 1e-6 * Math.max(1, Math.abs(a), Math.abs(b));\r\n}\r\n\r\nexport const flowOps: AttributeOps<FlowMode, FlowResolved> & FlowOps = {\r\n resolve: (value) => value,\r\n lerp,\r\n\r\n arrange,\r\n measure,\r\n place,\r\n reusable,\r\n freeSlot,\r\n\r\n contentBox,\r\n size,\r\n\r\n collapsedRun,\r\n};\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/layout/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Alignment } from \"@/attributes/layout/alignment\";\nimport type { Insets } from \"@/attributes/layout/insets\";\nimport type { Size2D, SizeInput } from \"@/attributes/layout/size\";\nimport type { MeasureContext2D } from \"@/render/measure-context\";\nimport type { BoxBounds } from \"./bounds\";\nimport type { SizeConstraints } from \"./constraints\";\n\n/**\n * How a container arranges the items that take part in its layout:\n *\n * - `'freeform'` — items overlap, each aligned in the padded content box by\n * `align` and offset from there by its own `x`/`y`.\n * - `'horizontal'` — a run left-to-right.\n * - `'vertical'` — a run top-to-bottom.\n * - `'grid'` — N equal columns, rows sized to their content (or divided equally\n * when the container's height is bounded). Items place themselves with\n * `column`/`row` and span with `colSpan`/`rowSpan`; anything unplaced is\n * auto-flowed left-to-right.\n *\n * A run also answers `wrap` — \"and break onto a new line when you run out of\n * room\" — which is a property of the run rather than a fourth direction.\n */\nexport type FlowMode = \"horizontal\" | \"vertical\" | \"freeform\" | \"grid\";\n\n/** Spacing between items, or `\"auto\"` to spread the free space evenly between them. */\nexport type GapSize = number | \"auto\";\n\n/**\n * What a `flow` prop holds: a mode, or — mid-tween between two — both and how far\n * along. The blend lives in the value so that restoring the prop restores it.\n */\nexport type FlowResolved = FlowMode | { from: FlowMode; to: FlowMode; t: number };\n\n/** A container's author-facing layout props. */\nexport interface FlowProps {\n /**\n * Layout mode for children: a run (`horizontal` / `vertical`), overlapping\n * `freeform`, or a `grid` of N equal columns.\n */\n flow: FlowMode;\n /** Spacing between children along the layout's main axis. */\n gap: GapSize;\n /**\n * Break a `horizontal`/`vertical` run onto new lines once it runs out of\n * main-axis room. It needs a bounded main axis to break against, so an axis\n * set to `'hug'` stays one line.\n */\n wrap: boolean;\n /**\n * Spacing on the **cross** axis: between wrapped lines, and between a grid's\n * rows. Omitted, it follows `gap` — \"wrap this row\" almost never means \"and\n * stack the lines flush against each other\".\n */\n crossGap: number;\n /** Number of equal columns when `flow` is `'grid'`. At least 1. */\n columns: number;\n /**\n * Where children sit in the content box: a named position (`'center'`,\n * `'topLeft'`, …) or a per-axis `Vector2` (x: -1 left … +1 right, y: -1\n * bottom … +1 top).\n */\n align: Alignment;\n}\n\n/**\n * What `flowOps` arranges by: the {@link FlowProps} vocabulary, every field\n * optional and defaulting as the prop does. A `ShapeNode` or `Canvas2D` is one\n * as it stands.\n */\nexport interface FlowSettings {\n readonly flow?: FlowResolved;\n readonly gap?: GapSize;\n readonly wrap?: boolean;\n readonly crossGap?: number;\n readonly columns?: number;\n readonly align?: Alignment;\n /** Read by `flowOps.arrange` only; a node insets its own content box. */\n readonly padding?: Insets;\n}\n\n/** One thing a flow arranges — a `Node2D` as it stands, or a plain `{ width, height }`. */\nexport interface LayoutItem {\n readonly width: SizeInput;\n readonly height: SizeInput;\n /** Share of a run's free space among its `fill` items. Default 1. */\n readonly flex?: number;\n /** Fraction of a full gap this item opens on each side, `[0, 1]`. Default 1. */\n readonly gapScale?: number;\n /** 1-based grid column; with `row`, places the item explicitly. */\n readonly column?: number;\n readonly row?: number;\n readonly colSpan?: number;\n readonly rowSpan?: number;\n /**\n * The item's own size under `constraints`. Without one, a number is the size,\n * `'fill'` takes what is offered and `'hug'` is 0.\n */\n measure?(constraints: SizeConstraints, measurer?: MeasureContext2D): Partial<Size2D>;\n}\n\n/** The content box a flow measures in, and which of its axes hug their content. */\nexport interface FlowSpace {\n readonly width: number;\n readonly height: number;\n readonly hugWidth?: boolean;\n readonly hugHeight?: boolean;\n}\n\n/** One line of a `horizontal`/`vertical` run: items `[start, end)`. */\nexport interface FlowLine {\n readonly start: number;\n readonly end: number;\n /** The line's thickness — its deepest item — on the cross axis. */\n readonly cross: number;\n}\n\n/**\n * One measure pass: what `flowOps.place` needs to position the items, and the\n * extent a hugging container wraps.\n */\nexport interface FlowMeasure<I extends LayoutItem = LayoutItem> {\n readonly mode: FlowMode;\n readonly items: readonly I[];\n readonly sizes: readonly Size2D[];\n readonly hug: Size2D;\n /** The content box this was measured in — see `flowOps.reusable`. */\n readonly space: FlowSpace;\n /** Runs: the lines, and each item's clamped `gapScale` (all 1 when wrapped). */\n readonly lines?: readonly FlowLine[];\n readonly gapScales?: readonly number[];\n /** Grid: each item's cell, from the content box's top-left, y-down. */\n readonly cells?: readonly BoxBounds[];\n /** A blend between two modes: the measure of the mode being left, and how far along. */\n readonly from?: FlowMeasure<I>;\n readonly t?: number;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/layout/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Alignment } from \"@/attributes/layout/alignment\";\r\nimport type { Insets } from \"@/attributes/layout/insets\";\r\nimport type { Size2D, SizeInput } from \"@/attributes/layout/size\";\r\nimport type { MeasureContext2D } from \"@/render/measure-context\";\r\nimport type { BoxBounds } from \"./bounds\";\r\nimport type { SizeConstraints } from \"./constraints\";\r\n\r\n/**\r\n * How a container arranges the items that take part in its layout:\r\n *\r\n * - `'freeform'` — items overlap, each aligned in the padded content box by\r\n * `align` and offset from there by its own `x`/`y`.\r\n * - `'horizontal'` — a run left-to-right.\r\n * - `'vertical'` — a run top-to-bottom.\r\n * - `'grid'` — N equal columns, rows sized to their content (or divided equally\r\n * when the container's height is bounded). Items place themselves with\r\n * `column`/`row` and span with `colSpan`/`rowSpan`; anything unplaced is\r\n * auto-flowed left-to-right.\r\n *\r\n * A run also answers `wrap` — \"and break onto a new line when you run out of\r\n * room\" — which is a property of the run rather than a fourth direction.\r\n */\r\nexport type FlowMode = \"horizontal\" | \"vertical\" | \"freeform\" | \"grid\";\r\n\r\n/** Spacing between items, or `\"auto\"` to spread the free space evenly between them. */\r\nexport type GapSize = number | \"auto\";\r\n\r\n/**\r\n * What a `flow` prop holds: a mode, or — mid-tween between two — both and how far\r\n * along. The blend lives in the value so that restoring the prop restores it.\r\n */\r\nexport type FlowResolved = FlowMode | { from: FlowMode; to: FlowMode; t: number };\r\n\r\n/** A container's author-facing layout props. */\r\nexport interface FlowProps {\r\n /**\r\n * Layout mode for children: a run (`horizontal` / `vertical`), overlapping\r\n * `freeform`, or a `grid` of N equal columns.\r\n */\r\n flow: FlowMode;\r\n /** Spacing between children along the layout's main axis. */\r\n gap: GapSize;\r\n /**\r\n * Break a `horizontal`/`vertical` run onto new lines once it runs out of\r\n * main-axis room. It needs a bounded main axis to break against, so an axis\r\n * set to `'hug'` stays one line.\r\n */\r\n wrap: boolean;\r\n /**\r\n * Spacing on the **cross** axis: between wrapped lines, and between a grid's\r\n * rows. Omitted, it follows `gap` — \"wrap this row\" almost never means \"and\r\n * stack the lines flush against each other\".\r\n */\r\n crossGap: number;\r\n /** Number of equal columns when `flow` is `'grid'`. At least 1. */\r\n columns: number;\r\n /**\r\n * Where children sit in the content box: a named position (`'center'`,\r\n * `'topLeft'`, …) or a per-axis `Vector2` (x: -1 left … +1 right, y: -1\r\n * bottom … +1 top).\r\n */\r\n align: Alignment;\r\n}\r\n\r\n/**\r\n * What `flowOps` arranges by: the {@link FlowProps} vocabulary, every field\r\n * optional and defaulting as the prop does. A `ShapeNode` or `Canvas2D` is one\r\n * as it stands.\r\n */\r\nexport interface FlowSettings {\r\n readonly flow?: FlowResolved;\r\n readonly gap?: GapSize;\r\n readonly wrap?: boolean;\r\n readonly crossGap?: number;\r\n readonly columns?: number;\r\n readonly align?: Alignment;\r\n /** Read by `flowOps.arrange` only; a node insets its own content box. */\r\n readonly padding?: Insets;\r\n}\r\n\r\n/** One thing a flow arranges — a `Node2D` as it stands, or a plain `{ width, height }`. */\r\nexport interface LayoutItem {\r\n readonly width: SizeInput;\r\n readonly height: SizeInput;\r\n /** Share of a run's free space among its `fill` items. Default 1. */\r\n readonly flex?: number;\r\n /** Fraction of a full gap this item opens on each side, `[0, 1]`. Default 1. */\r\n readonly gapScale?: number;\r\n /** 1-based grid column; with `row`, places the item explicitly. */\r\n readonly column?: number;\r\n readonly row?: number;\r\n readonly colSpan?: number;\r\n readonly rowSpan?: number;\r\n /**\r\n * The item's own size under `constraints`. Without one, a number is the size,\r\n * `'fill'` takes what is offered and `'hug'` is 0.\r\n */\r\n measure?(constraints: SizeConstraints, measurer?: MeasureContext2D): Partial<Size2D>;\r\n}\r\n\r\n/** The content box a flow measures in, and which of its axes hug their content. */\r\nexport interface FlowSpace {\r\n readonly width: number;\r\n readonly height: number;\r\n readonly hugWidth?: boolean;\r\n readonly hugHeight?: boolean;\r\n}\r\n\r\n/** One line of a `horizontal`/`vertical` run: items `[start, end)`. */\r\nexport interface FlowLine {\r\n readonly start: number;\r\n readonly end: number;\r\n /** The line's thickness — its deepest item — on the cross axis. */\r\n readonly cross: number;\r\n}\r\n\r\n/**\r\n * One measure pass: what `flowOps.place` needs to position the items, and the\r\n * extent a hugging container wraps.\r\n */\r\nexport interface FlowMeasure<I extends LayoutItem = LayoutItem> {\r\n readonly mode: FlowMode;\r\n readonly items: readonly I[];\r\n readonly sizes: readonly Size2D[];\r\n readonly hug: Size2D;\r\n /** The content box this was measured in — see `flowOps.reusable`. */\r\n readonly space: FlowSpace;\r\n /** Runs: the lines, and each item's clamped `gapScale` (all 1 when wrapped). */\r\n readonly lines?: readonly FlowLine[];\r\n readonly gapScales?: readonly number[];\r\n /** Grid: each item's cell, from the content box's top-left, y-down. */\r\n readonly cells?: readonly BoxBounds[];\r\n /** A blend between two modes: the measure of the mode being left, and how far along. */\r\n readonly from?: FlowMeasure<I>;\r\n readonly t?: number;\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"node-lifecycle.js","sourceRoot":"","sources":["../../../src/nodes/2d/node-lifecycle.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE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ACX,IAAI,EACJ,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAA0B,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,EACjG,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,CAAC,EAA0B,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAC1F,EACD,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,aAAa,EAA0B,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CACrG,CAAC;IACN,CAAC,CAAC;IAEF,OAAO,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE;QAChC,IAAI,CAAC,SAAS;YAAE,SAAS,GAAG,KAAK,EAAE,CAAC;QACpC,MAAM,OAAO,GAAG,CAAC,GAAG,QAAQ,CAAC;QAC7B,MAAM,WAAW,GAAG,OAAO,IAAI,IAAI,CAAC;QACpC,IAAI,WAAW,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC3C,IAAI,SAAS;gBAAE,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACtC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC;aAAM,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YACnD,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACvB,IAAI,SAAS;gBAAE,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACvC,CAAC;QACD,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import { EasingFunction } from \"@/tween/ease/type\";\nimport { commandParallel, commandSequence, driveCommand, type Command } from \"@/tween/command\";\nimport { SizeConstraints } from \"@/layout/constraints\";\nimport type { Node2D, Node2DProps } from \"./node2d\";\n\n/**\n * Measure `child`'s natural size **without attaching it to `parent`** — so the\n * measurement never perturbs the parent's layout (siblings don't shift for a\n * frame). Uses the constraints + scope the parent retained from its last measure\n * pass; returns `null` if the parent hasn't been measured yet (nothing on screen\n * to reflow against), so the caller can fall back. Reads `parent.lastMeasure` —\n * internal layout state the lifecycle helpers are the\n * intended in-directory consumer of.\n */\nfunction measureDetached(parent: Node2D, child: Node2D): { width: number; height: number } | null {\n const pass = parent.lastMeasure;\n const scope = pass?.measurer;\n // The scope (text measurement) is the essential input and is only present once\n // the parent has been laid out; without it we can't size a hug child off-tree.\n if (!scope) return null;\n // The parent's own constraints bound the child; fall back to its laid-out box,\n // then to an unbounded space — a hug child shrink-wraps regardless, so a\n // generous ceiling is fine.\n const constraints: SizeConstraints = pass?.constraints ?? {\n maxWidth: parent.measuredWidth || Number.MAX_SAFE_INTEGER,\n maxHeight: parent.measuredHeight || Number.MAX_SAFE_INTEGER,\n };\n const size = child.measure(constraints, scope);\n return { width: size.width ?? 0, height: size.height ?? 0 };\n}\n\n/**\n * Companion for {@link Node2D}'s animated child-management methods. The sync\n * variants (add/remove/clear/addChildAt/\n * removeChildAt) stay inline on Node2D — each is a 3–5 line method that mutates\n * `_children`/`_parent` and calls `bindAssets`/`bindChildContext`, so there is\n * no body worth moving. These are the animated overloads, returned as\n * {@link Command}s built from `child.to(...)` composed with\n * {@link commandSequence}/{@link commandParallel} — the same choreography\n * primitives a node's own multi-step commands use.\n *\n * Each command's setup (measuring the child, collapsing it, attaching/\n * detaching/reparenting) runs **lazily, once, on the command's first\n * evaluation** rather than when the function below is called — mirroring the\n * generator these replaced, whose body didn't run a single line until the\n * caller's first `.next()`. That laziness is load-bearing: a caller often does\n * `const cmd = parent.addChildAt(child, i, dur); /* lay the parent out here *\\/\n * driveCmd(cmd)`, relying on the parent having a fresh `lastMeasure` by the time\n * the hug/fill measurement in {@link addChildAtAnimated} actually runs. Doing\n * that measurement eagerly — when this function is called, not when the\n * command is first driven — reads whatever scope the parent happened to have\n * at call time, which is often none at all.\n *\n * The container's `gap` is handled by the per-child `gapScale` prop these helpers\n * tween in parallel with the child's box (see {@link addChildAtAnimated}); the\n * flex layout (`flex.ts`) folds each child's `gapScale` into its gap budget, so\n * the gap opens/closes in lockstep with the size instead of popping. No helper\n * here needs to know the parent's axis or gap value.\n */\n\n/**\n * Fraction of an insert/remove's `duration` spent on the size + gap motion; the\n * remainder is the opacity fade. Splitting the two sequentially (grow → fade in,\n * fade out → shrink) keeps the fading child from overlapping siblings that are\n * still sliding: room is opened while it's invisible, then it fades in already in\n * place (and mirror-image on remove). The size phase gets the larger share since\n * it's the dominant motion and the fade only needs to read as a quick finish.\n */\nconst SIZE_PHASE = 0.7;\n\n/**\n * Animated `addChildAt`: insert the child at `index` **already collapsed to 0**,\n * then grow it in — fading opacity up and expanding its box from 0 → its natural\n * size so the surrounding siblings **slide over to make room** rather than\n * jumping. The mirror of {@link removeChildAtAnimated} (which pins to the\n * measured size and shrinks to 0).\n *\n * A numeric-sized axis has its target size in hand up front. A `\"hug\"`/`\"fill\"`\n * axis does not — its size is only known once laid out — so we measure the child\n * **detached** (via {@link measureDetached}, using the parent's retained\n * constraints + scope) *before* attaching it. That keeps the child out of the\n * parent's layout flow while we size it, so the siblings never see it at full\n * width for a frame — no reflow flash. The child is then added at 0 and the tween\n * grows it to that measured size. Because the tween needs *numeric* endpoints\n * (a string size only snaps, it can't interpolate), the original size token is\n * restored once the command reaches its end so the child resumes normal reflow.\n *\n * If the parent hasn't been measured yet (no retained scope — nothing is on\n * screen to reflow against), a non-numeric axis simply can't be pre-measured;\n * it falls back to its authored token and fades in without a width tween.\n */\nexport function addChildAtAnimated(\n parent: Node2D,\n child: Node2D,\n index: number,\n duration: number,\n easing?: EasingFunction,\n): Command<Record<string, never>> {\n let animation: Command<Node2DProps> | null = null;\n let isNumericW = false;\n let isNumericH = false;\n let origW: Node2DProps[\"width\"];\n let origH: Node2DProps[\"height\"];\n\n const setup = (): Command<Node2DProps> => {\n const targetOpacity = child.opacity;\n // Remember the authored size tokens so a hug/fill axis can be restored\n // after the numeric grow-in tween finishes.\n origW = child.width;\n origH = child.height;\n isNumericW = typeof origW === \"number\";\n isNumericH = typeof origH === \"number\";\n\n // Pre-measure any non-numeric axis while the child is still detached, so\n // sizing it can't shift the parent's existing children for a frame.\n const detached = isNumericW && isNumericH ? null : measureDetached(parent, child);\n\n // Resolve each axis' grow-to target: a numeric axis uses its authored\n // size; a hug/fill axis uses the detached measurement (or gives up the\n // width tween if the parent isn't measured yet).\n const tweenW = isNumericW || detached !== null;\n const tweenH = isNumericH || detached !== null;\n const targetW = isNumericW ? (origW as number) : (detached?.width ?? 0);\n const targetH = isNumericH ? (origH as number) : (detached?.height ?? 0);\n\n // Collapse the axes we can tween to 0 before inserting, so the child\n // enters taking no room and the siblings hold their positions.\n // `gapScale: 0` also suppresses the gap this child would add, so the\n // flanking gap opens from 0 rather than snapping in the instant it\n // attaches.\n child.set({\n opacity: 0,\n gapScale: 0,\n ...(tweenW ? { width: 0 } : {}),\n ...(tweenH ? { height: 0 } : {}),\n } as Partial<Node2DProps>);\n parent.addChildAt({ data: { child, index } });\n\n const sizeProps: Partial<Node2DProps> = {};\n if (tweenW) sizeProps.width = targetW;\n if (tweenH) sizeProps.height = targetH;\n // Two sequential phases so the fading-in child never overlaps siblings\n // that are still sliding: first open the box and the flanking gap\n // (opacity held at 0, so nothing is visible while the space is being\n // made), then fade the now-placed child in. `gapScale` 0 → 1 tracks the\n // size so siblings slide over continuously instead of jumping by `gap`.\n const grow = duration * SIZE_PHASE;\n const fade = duration - grow;\n return commandSequence<Node2DProps>(\n child,\n commandParallel<Node2DProps>(\n child,\n child.to({ data: sizeProps, duration: grow, easing }),\n child.to({ data: { gapScale: 1 } as Partial<Node2DProps>, duration: grow, easing }),\n ),\n child.to({ data: { opacity: targetOpacity } as Partial<Node2DProps>, duration: fade, easing }),\n );\n };\n\n return driveCommand(duration, (t) => {\n if (!animation) animation = setup();\n animation.at(t);\n if (t >= 1) {\n // Restore any hug/fill token so the child reflows naturally from\n // here on; the tween already landed the axis on its measured pixel\n // size, so this is seamless.\n const restore: Partial<Node2DProps> = {};\n if (!isNumericW) restore.width = origW;\n if (!isNumericH) restore.height = origH;\n if (!isNumericW || !isNumericH) child.set(restore as Partial<Node2DProps>);\n }\n });\n}\n\n/**\n * Animated `removeChildAt`: fade+size the child out, then detach it.\n *\n * The child stays in the tree — animating out — until the command reaches its\n * end (`t === 1`), matching the \"insert\"/\"remove\" seekability\n * `packages/components/code` established: a host asking for a time before the\n * end sees the child still present, mid-fade; only reaching the end detaches it.\n * Seeking back below the end after having reached it re-attaches the child at\n * its original index, so the animation stays a function of `t` in both\n * directions rather than a one-way commit.\n */\nexport function removeChildAtAnimated(\n parent: Node2D,\n index: number,\n duration: number,\n easing?: EasingFunction,\n): Command<Record<string, never>> {\n let child: Node2D | null = null;\n let animation: Command<Node2DProps> | null = null;\n let setupDone = false;\n\n const setup = (): void => {\n setupDone = true;\n // Out of range: nothing to animate — `child`/`animation` stay null, and\n // every apply() below becomes a no-op.\n if (index < 0 || index >= parent.children.length) return;\n child = parent.children[index];\n\n // Pin to current rendered size so the shrink reflows siblings in the\n // parent layout.\n const lw = child.measuredWidth;\n const lh = child.measuredHeight;\n child.set({ width: lw, height: lh } as Partial<Node2DProps>);\n\n // Mirror of the insert: fade the child out first (box held at full\n // size, so it doesn't overlap siblings mid-fade), then collapse the\n // box and close the gap. `gapScale` 1 → 0 tracks the shrink so the gap\n // closes continuously.\n const fade = duration * (1 - SIZE_PHASE);\n const shrink = duration - fade;\n animation = commandSequence<Node2DProps>(\n child,\n child.to({ data: { opacity: 0 } as Partial<Node2DProps>, duration: fade, easing }),\n commandParallel<Node2DProps>(\n child,\n child.to({ data: { width: 0, height: 0 } as Partial<Node2DProps>, duration: shrink, easing }),\n child.to({ data: { gapScale: 0 } as Partial<Node2DProps>, duration: shrink, easing }),\n ),\n );\n };\n\n return driveCommand(duration, (t) => {\n if (!setupDone) setup();\n if (!animation || !child) return;\n const done = t >= 1;\n if (!done && child.parent !== parent) {\n // Seeking back into the animation after it had reached the end —\n // the child is what's animating out, so put it back.\n parent.addChildAt({ data: { child, index: Math.min(index, parent.children.length) } });\n }\n animation.at(t);\n if (done) {\n parent.remove(child);\n // The child is detached now, so its 0 gapScale no longer affects any\n // layout — but the same node can be re-added later (scenes reuse\n // refs), and a plain (non-animated) addChild wouldn't reset it.\n // Restore the default so a stale 0 can't silently swallow a gap on\n // re-insert.\n child.set({ gapScale: 1 } as Partial<Node2DProps>);\n }\n });\n}\n\n/**\n * Animated `reparent`: fade+size the node out of its current parent, then\n * reparent it and fade+size it in. The handoff happens at the animation's\n * midpoint (`t === 0.5`) — seeking across it in either direction moves the node\n * between parents to match, the same bidirectional membership rule\n * {@link removeChildAtAnimated} uses.\n */\nexport function reparentAnimated(\n node: Node2D,\n newParent: Node2D,\n duration: number,\n easing?: EasingFunction,\n): Command<Record<string, never>> {\n const half = duration / 2;\n let animation: Command<Node2DProps> | null = null;\n let oldParent: Node2D | null = null;\n\n const setup = (): Command<Node2DProps> => {\n const targetOpacity = node.opacity;\n oldParent = node.parent;\n\n // Pin to current rendered size so exit shrink reflows the old parent.\n const lw = node.measuredWidth;\n const lh = node.measuredHeight;\n node.set({ width: lw, height: lh } as Partial<Node2DProps>);\n\n // Exit the old parent (fade out, then collapse the box + gap) over the\n // first half, then enter the new one (open the box + gap, then fade\n // in) over the second — one flat sequence, so evaluating any `t` walks\n // and settles every phase before it first. That is what makes the\n // *enter* tweens' `from` correct even when a driven host asks for a\n // time straight into the enter half without ever having evaluated the\n // exit half first: `commandSequence` re-settles every prior phase on\n // each call, so by the time an enter tween's `from` is lazily\n // snapshotted (its own first evaluation), the exit phase has already\n // collapsed the node to the state enter grows from.\n const exitFade = half * (1 - SIZE_PHASE);\n const exitShrink = half - exitFade;\n const enterGrow = half * SIZE_PHASE;\n const enterFade = half - enterGrow;\n return commandSequence<Node2DProps>(\n node,\n node.to({ data: { opacity: 0 } as Partial<Node2DProps>, duration: exitFade, easing }),\n commandParallel<Node2DProps>(\n node,\n node.to({ data: { width: 0, height: 0 } as Partial<Node2DProps>, duration: exitShrink, easing }),\n node.to({ data: { gapScale: 0 } as Partial<Node2DProps>, duration: exitShrink, easing }),\n ),\n commandParallel<Node2DProps>(\n node,\n node.to({ data: { width: lw, height: lh } as Partial<Node2DProps>, duration: enterGrow, easing }),\n node.to({ data: { gapScale: 1 } as Partial<Node2DProps>, duration: enterGrow, easing }),\n ),\n node.to({ data: { opacity: targetOpacity } as Partial<Node2DProps>, duration: enterFade, easing }),\n );\n };\n\n return driveCommand(duration, (t) => {\n if (!animation) animation = setup();\n const elapsed = t * duration;\n const inNewParent = elapsed >= half;\n if (inNewParent && node.parent !== newParent) {\n if (oldParent) oldParent.remove(node);\n newParent.add(node);\n } else if (!inNewParent && node.parent !== oldParent) {\n newParent.remove(node);\n if (oldParent) oldParent.add(node);\n }\n animation.at(t);\n });\n}\n"]}
1
+ {"version":3,"file":"node-lifecycle.js","sourceRoot":"","sources":["../../../src/nodes/2d/node-lifecycle.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,YAAY,EAAgB,MAAM,iBAAiB,CAAC;AAI/F;;;;;;;;GAQG;AACH,SAAS,eAAe,CAAC,MAAc,EAAE,KAAa;IAClD,MAAM,IAAI,GAAG,MAAM,CAAC,WAAW,CAAC;IAChC,MAAM,KAAK,GAAG,IAAI,EAAE,QAAQ,CAAC;IAC7B,+EAA+E;IAC/E,+EAA+E;IAC/E,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IACxB,+EAA+E;IAC/E,yEAAyE;IACzE,4BAA4B;IAC5B,MAAM,WAAW,GAAoB,IAAI,EAAE,WAAW,IAAI;QACtD,QAAQ,EAAE,MAAM,CAAC,aAAa,IAAI,MAAM,CAAC,gBAAgB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AAC,CAAC;IAEF,OAAO,YAAY,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE;QAChC,IAAI,CAAC,SAAS;YAAE,SAAS,GAAG,KAAK,EAAE,CAAC;QACpC,MAAM,OAAO,GAAG,CAAC,GAAG,QAAQ,CAAC;QAC7B,MAAM,WAAW,GAAG,OAAO,IAAI,IAAI,CAAC;QACpC,IAAI,WAAW,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC3C,IAAI,SAAS;gBAAE,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACtC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC;aAAM,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YACnD,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACvB,IAAI,SAAS;gBAAE,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACvC,CAAC;QACD,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import { EasingFunction } from \"@/tween/ease/type\";\r\nimport { commandParallel, commandSequence, driveCommand, type Command } from \"@/tween/command\";\r\nimport { SizeConstraints } from \"@/layout/constraints\";\r\nimport type { Node2D, Node2DProps } from \"./node2d\";\r\n\r\n/**\r\n * Measure `child`'s natural size **without attaching it to `parent`** — so the\r\n * measurement never perturbs the parent's layout (siblings don't shift for a\r\n * frame). Uses the constraints + scope the parent retained from its last measure\r\n * pass; returns `null` if the parent hasn't been measured yet (nothing on screen\r\n * to reflow against), so the caller can fall back. Reads `parent.lastMeasure` —\r\n * internal layout state the lifecycle helpers are the\r\n * intended in-directory consumer of.\r\n */\r\nfunction measureDetached(parent: Node2D, child: Node2D): { width: number; height: number } | null {\r\n const pass = parent.lastMeasure;\r\n const scope = pass?.measurer;\r\n // The scope (text measurement) is the essential input and is only present once\r\n // the parent has been laid out; without it we can't size a hug child off-tree.\r\n if (!scope) return null;\r\n // The parent's own constraints bound the child; fall back to its laid-out box,\r\n // then to an unbounded space — a hug child shrink-wraps regardless, so a\r\n // generous ceiling is fine.\r\n const constraints: SizeConstraints = pass?.constraints ?? {\r\n maxWidth: parent.measuredWidth || Number.MAX_SAFE_INTEGER,\r\n maxHeight: parent.measuredHeight || Number.MAX_SAFE_INTEGER,\r\n };\r\n const size = child.measure(constraints, scope);\r\n return { width: size.width ?? 0, height: size.height ?? 0 };\r\n}\r\n\r\n/**\r\n * Companion for {@link Node2D}'s animated child-management methods. The sync\r\n * variants (add/remove/clear/addChildAt/\r\n * removeChildAt) stay inline on Node2D — each is a 3–5 line method that mutates\r\n * `_children`/`_parent` and calls `bindAssets`/`bindChildContext`, so there is\r\n * no body worth moving. These are the animated overloads, returned as\r\n * {@link Command}s built from `child.to(...)` composed with\r\n * {@link commandSequence}/{@link commandParallel} — the same choreography\r\n * primitives a node's own multi-step commands use.\r\n *\r\n * Each command's setup (measuring the child, collapsing it, attaching/\r\n * detaching/reparenting) runs **lazily, once, on the command's first\r\n * evaluation** rather than when the function below is called — mirroring the\r\n * generator these replaced, whose body didn't run a single line until the\r\n * caller's first `.next()`. That laziness is load-bearing: a caller often does\r\n * `const cmd = parent.addChildAt(child, i, dur); /* lay the parent out here *\\/\r\n * driveCmd(cmd)`, relying on the parent having a fresh `lastMeasure` by the time\r\n * the hug/fill measurement in {@link addChildAtAnimated} actually runs. Doing\r\n * that measurement eagerly — when this function is called, not when the\r\n * command is first driven — reads whatever scope the parent happened to have\r\n * at call time, which is often none at all.\r\n *\r\n * The container's `gap` is handled by the per-child `gapScale` prop these helpers\r\n * tween in parallel with the child's box (see {@link addChildAtAnimated}); the\r\n * flex layout (`flex.ts`) folds each child's `gapScale` into its gap budget, so\r\n * the gap opens/closes in lockstep with the size instead of popping. No helper\r\n * here needs to know the parent's axis or gap value.\r\n */\r\n\r\n/**\r\n * Fraction of an insert/remove's `duration` spent on the size + gap motion; the\r\n * remainder is the opacity fade. Splitting the two sequentially (grow → fade in,\r\n * fade out → shrink) keeps the fading child from overlapping siblings that are\r\n * still sliding: room is opened while it's invisible, then it fades in already in\r\n * place (and mirror-image on remove). The size phase gets the larger share since\r\n * it's the dominant motion and the fade only needs to read as a quick finish.\r\n */\r\nconst SIZE_PHASE = 0.7;\r\n\r\n/**\r\n * Animated `addChildAt`: insert the child at `index` **already collapsed to 0**,\r\n * then grow it in — fading opacity up and expanding its box from 0 → its natural\r\n * size so the surrounding siblings **slide over to make room** rather than\r\n * jumping. The mirror of {@link removeChildAtAnimated} (which pins to the\r\n * measured size and shrinks to 0).\r\n *\r\n * A numeric-sized axis has its target size in hand up front. A `\"hug\"`/`\"fill\"`\r\n * axis does not — its size is only known once laid out — so we measure the child\r\n * **detached** (via {@link measureDetached}, using the parent's retained\r\n * constraints + scope) *before* attaching it. That keeps the child out of the\r\n * parent's layout flow while we size it, so the siblings never see it at full\r\n * width for a frame — no reflow flash. The child is then added at 0 and the tween\r\n * grows it to that measured size. Because the tween needs *numeric* endpoints\r\n * (a string size only snaps, it can't interpolate), the original size token is\r\n * restored once the command reaches its end so the child resumes normal reflow.\r\n *\r\n * If the parent hasn't been measured yet (no retained scope — nothing is on\r\n * screen to reflow against), a non-numeric axis simply can't be pre-measured;\r\n * it falls back to its authored token and fades in without a width tween.\r\n */\r\nexport function addChildAtAnimated(\r\n parent: Node2D,\r\n child: Node2D,\r\n index: number,\r\n duration: number,\r\n easing?: EasingFunction,\r\n): Command<Record<string, never>> {\r\n let animation: Command<Node2DProps> | null = null;\r\n let isNumericW = false;\r\n let isNumericH = false;\r\n let origW: Node2DProps[\"width\"];\r\n let origH: Node2DProps[\"height\"];\r\n\r\n const setup = (): Command<Node2DProps> => {\r\n const targetOpacity = child.opacity;\r\n // Remember the authored size tokens so a hug/fill axis can be restored\r\n // after the numeric grow-in tween finishes.\r\n origW = child.width;\r\n origH = child.height;\r\n isNumericW = typeof origW === \"number\";\r\n isNumericH = typeof origH === \"number\";\r\n\r\n // Pre-measure any non-numeric axis while the child is still detached, so\r\n // sizing it can't shift the parent's existing children for a frame.\r\n const detached = isNumericW && isNumericH ? null : measureDetached(parent, child);\r\n\r\n // Resolve each axis' grow-to target: a numeric axis uses its authored\r\n // size; a hug/fill axis uses the detached measurement (or gives up the\r\n // width tween if the parent isn't measured yet).\r\n const tweenW = isNumericW || detached !== null;\r\n const tweenH = isNumericH || detached !== null;\r\n const targetW = isNumericW ? (origW as number) : (detached?.width ?? 0);\r\n const targetH = isNumericH ? (origH as number) : (detached?.height ?? 0);\r\n\r\n // Collapse the axes we can tween to 0 before inserting, so the child\r\n // enters taking no room and the siblings hold their positions.\r\n // `gapScale: 0` also suppresses the gap this child would add, so the\r\n // flanking gap opens from 0 rather than snapping in the instant it\r\n // attaches.\r\n child.set({\r\n opacity: 0,\r\n gapScale: 0,\r\n ...(tweenW ? { width: 0 } : {}),\r\n ...(tweenH ? { height: 0 } : {}),\r\n } as Partial<Node2DProps>);\r\n parent.addChildAt({ data: { child, index } });\r\n\r\n const sizeProps: Partial<Node2DProps> = {};\r\n if (tweenW) sizeProps.width = targetW;\r\n if (tweenH) sizeProps.height = targetH;\r\n // Two sequential phases so the fading-in child never overlaps siblings\r\n // that are still sliding: first open the box and the flanking gap\r\n // (opacity held at 0, so nothing is visible while the space is being\r\n // made), then fade the now-placed child in. `gapScale` 0 → 1 tracks the\r\n // size so siblings slide over continuously instead of jumping by `gap`.\r\n const grow = duration * SIZE_PHASE;\r\n const fade = duration - grow;\r\n return commandSequence<Node2DProps>(\r\n child,\r\n commandParallel<Node2DProps>(\r\n child,\r\n child.to({ data: sizeProps, duration: grow, easing }),\r\n child.to({ data: { gapScale: 1 } as Partial<Node2DProps>, duration: grow, easing }),\r\n ),\r\n child.to({ data: { opacity: targetOpacity } as Partial<Node2DProps>, duration: fade, easing }),\r\n );\r\n };\r\n\r\n return driveCommand(duration, (t) => {\r\n if (!animation) animation = setup();\r\n animation.at(t);\r\n if (t >= 1) {\r\n // Restore any hug/fill token so the child reflows naturally from\r\n // here on; the tween already landed the axis on its measured pixel\r\n // size, so this is seamless.\r\n const restore: Partial<Node2DProps> = {};\r\n if (!isNumericW) restore.width = origW;\r\n if (!isNumericH) restore.height = origH;\r\n if (!isNumericW || !isNumericH) child.set(restore as Partial<Node2DProps>);\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Animated `removeChildAt`: fade+size the child out, then detach it.\r\n *\r\n * The child stays in the tree — animating out — until the command reaches its\r\n * end (`t === 1`), matching the \"insert\"/\"remove\" seekability\r\n * `packages/components/code` established: a host asking for a time before the\r\n * end sees the child still present, mid-fade; only reaching the end detaches it.\r\n * Seeking back below the end after having reached it re-attaches the child at\r\n * its original index, so the animation stays a function of `t` in both\r\n * directions rather than a one-way commit.\r\n */\r\nexport function removeChildAtAnimated(\r\n parent: Node2D,\r\n index: number,\r\n duration: number,\r\n easing?: EasingFunction,\r\n): Command<Record<string, never>> {\r\n let child: Node2D | null = null;\r\n let animation: Command<Node2DProps> | null = null;\r\n let setupDone = false;\r\n\r\n const setup = (): void => {\r\n setupDone = true;\r\n // Out of range: nothing to animate — `child`/`animation` stay null, and\r\n // every apply() below becomes a no-op.\r\n if (index < 0 || index >= parent.children.length) return;\r\n child = parent.children[index];\r\n\r\n // Pin to current rendered size so the shrink reflows siblings in the\r\n // parent layout.\r\n const lw = child.measuredWidth;\r\n const lh = child.measuredHeight;\r\n child.set({ width: lw, height: lh } as Partial<Node2DProps>);\r\n\r\n // Mirror of the insert: fade the child out first (box held at full\r\n // size, so it doesn't overlap siblings mid-fade), then collapse the\r\n // box and close the gap. `gapScale` 1 → 0 tracks the shrink so the gap\r\n // closes continuously.\r\n const fade = duration * (1 - SIZE_PHASE);\r\n const shrink = duration - fade;\r\n animation = commandSequence<Node2DProps>(\r\n child,\r\n child.to({ data: { opacity: 0 } as Partial<Node2DProps>, duration: fade, easing }),\r\n commandParallel<Node2DProps>(\r\n child,\r\n child.to({ data: { width: 0, height: 0 } as Partial<Node2DProps>, duration: shrink, easing }),\r\n child.to({ data: { gapScale: 0 } as Partial<Node2DProps>, duration: shrink, easing }),\r\n ),\r\n );\r\n };\r\n\r\n return driveCommand(duration, (t) => {\r\n if (!setupDone) setup();\r\n if (!animation || !child) return;\r\n const done = t >= 1;\r\n if (!done && child.parent !== parent) {\r\n // Seeking back into the animation after it had reached the end —\r\n // the child is what's animating out, so put it back.\r\n parent.addChildAt({ data: { child, index: Math.min(index, parent.children.length) } });\r\n }\r\n animation.at(t);\r\n if (done) {\r\n parent.remove(child);\r\n // The child is detached now, so its 0 gapScale no longer affects any\r\n // layout — but the same node can be re-added later (scenes reuse\r\n // refs), and a plain (non-animated) addChild wouldn't reset it.\r\n // Restore the default so a stale 0 can't silently swallow a gap on\r\n // re-insert.\r\n child.set({ gapScale: 1 } as Partial<Node2DProps>);\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Animated `reparent`: fade+size the node out of its current parent, then\r\n * reparent it and fade+size it in. The handoff happens at the animation's\r\n * midpoint (`t === 0.5`) — seeking across it in either direction moves the node\r\n * between parents to match, the same bidirectional membership rule\r\n * {@link removeChildAtAnimated} uses.\r\n */\r\nexport function reparentAnimated(\r\n node: Node2D,\r\n newParent: Node2D,\r\n duration: number,\r\n easing?: EasingFunction,\r\n): Command<Record<string, never>> {\r\n const half = duration / 2;\r\n let animation: Command<Node2DProps> | null = null;\r\n let oldParent: Node2D | null = null;\r\n\r\n const setup = (): Command<Node2DProps> => {\r\n const targetOpacity = node.opacity;\r\n oldParent = node.parent;\r\n\r\n // Pin to current rendered size so exit shrink reflows the old parent.\r\n const lw = node.measuredWidth;\r\n const lh = node.measuredHeight;\r\n node.set({ width: lw, height: lh } as Partial<Node2DProps>);\r\n\r\n // Exit the old parent (fade out, then collapse the box + gap) over the\r\n // first half, then enter the new one (open the box + gap, then fade\r\n // in) over the second — one flat sequence, so evaluating any `t` walks\r\n // and settles every phase before it first. That is what makes the\r\n // *enter* tweens' `from` correct even when a driven host asks for a\r\n // time straight into the enter half without ever having evaluated the\r\n // exit half first: `commandSequence` re-settles every prior phase on\r\n // each call, so by the time an enter tween's `from` is lazily\r\n // snapshotted (its own first evaluation), the exit phase has already\r\n // collapsed the node to the state enter grows from.\r\n const exitFade = half * (1 - SIZE_PHASE);\r\n const exitShrink = half - exitFade;\r\n const enterGrow = half * SIZE_PHASE;\r\n const enterFade = half - enterGrow;\r\n return commandSequence<Node2DProps>(\r\n node,\r\n node.to({ data: { opacity: 0 } as Partial<Node2DProps>, duration: exitFade, easing }),\r\n commandParallel<Node2DProps>(\r\n node,\r\n node.to({ data: { width: 0, height: 0 } as Partial<Node2DProps>, duration: exitShrink, easing }),\r\n node.to({ data: { gapScale: 0 } as Partial<Node2DProps>, duration: exitShrink, easing }),\r\n ),\r\n commandParallel<Node2DProps>(\r\n node,\r\n node.to({ data: { width: lw, height: lh } as Partial<Node2DProps>, duration: enterGrow, easing }),\r\n node.to({ data: { gapScale: 1 } as Partial<Node2DProps>, duration: enterGrow, easing }),\r\n ),\r\n node.to({ data: { opacity: targetOpacity } as Partial<Node2DProps>, duration: enterFade, easing }),\r\n );\r\n };\r\n\r\n return driveCommand(duration, (t) => {\r\n if (!animation) animation = setup();\r\n const elapsed = t * duration;\r\n const inNewParent = elapsed >= half;\r\n if (inNewParent && node.parent !== newParent) {\r\n if (oldParent) oldParent.remove(node);\r\n newParent.add(node);\r\n } else if (!inNewParent && node.parent !== oldParent) {\r\n newParent.remove(node);\r\n if (oldParent) oldParent.add(node);\r\n }\r\n animation.at(t);\r\n });\r\n}\r\n"]}