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

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 (615) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +2 -4
  3. package/dist/assets/errors.js +4 -5
  4. package/dist/assets/errors.js.map +1 -1
  5. package/dist/assets/scope.d.ts +1 -1
  6. package/dist/assets/scope.d.ts.map +1 -1
  7. package/dist/assets/scope.js +1 -1
  8. package/dist/assets/scope.js.map +1 -1
  9. package/dist/attributes/audio/schedule.d.ts +3 -18
  10. package/dist/attributes/audio/schedule.d.ts.map +1 -1
  11. package/dist/attributes/audio/schedule.js.map +1 -1
  12. package/dist/attributes/index.d.ts +3 -5
  13. package/dist/attributes/index.d.ts.map +1 -1
  14. package/dist/attributes/index.js +2 -2
  15. package/dist/attributes/index.js.map +1 -1
  16. package/dist/attributes/layout/insets.d.ts +1 -1
  17. package/dist/attributes/layout/insets.js.map +1 -1
  18. package/dist/attributes/layout/size.d.ts +1 -1
  19. package/dist/attributes/layout/size.js +1 -1
  20. package/dist/attributes/layout/size.js.map +1 -1
  21. package/dist/attributes/properties/decorator.d.ts +44 -11
  22. package/dist/attributes/properties/decorator.d.ts.map +1 -1
  23. package/dist/attributes/properties/decorator.js +37 -9
  24. package/dist/attributes/properties/decorator.js.map +1 -1
  25. package/dist/attributes/properties/inputs.d.ts +1 -1
  26. package/dist/attributes/properties/inputs.js +1 -1
  27. package/dist/attributes/properties/inputs.js.map +1 -1
  28. package/dist/attributes/properties/typed.d.ts +19 -140
  29. package/dist/attributes/properties/typed.d.ts.map +1 -1
  30. package/dist/attributes/properties/typed.js +12 -108
  31. package/dist/attributes/properties/typed.js.map +1 -1
  32. package/dist/attributes/shape/corners/corner-radius.d.ts +1 -1
  33. package/dist/attributes/shape/corners/corner-radius.js +1 -1
  34. package/dist/attributes/shape/corners/corner-radius.js.map +1 -1
  35. package/dist/attributes/shape/effects/implementations/drop-shadow.d.ts +1 -1
  36. package/dist/attributes/shape/effects/implementations/drop-shadow.js.map +1 -1
  37. package/dist/attributes/shape/fill/color/parser.d.ts +1 -1
  38. package/dist/attributes/shape/fill/color/parser.js +1 -1
  39. package/dist/attributes/shape/fill/color/parser.js.map +1 -1
  40. package/dist/attributes/shape/fill/implementations/canvas3d.d.ts +2 -2
  41. package/dist/attributes/shape/fill/implementations/canvas3d.js.map +1 -1
  42. package/dist/attributes/shape/fill/implementations/shader.d.ts +2 -2
  43. package/dist/attributes/shape/fill/implementations/shader.js.map +1 -1
  44. package/dist/attributes/shape/fill/implementations/video.d.ts +1 -1
  45. package/dist/attributes/shape/fill/implementations/video.js +1 -1
  46. package/dist/attributes/shape/fill/implementations/video.js.map +1 -1
  47. package/dist/attributes/shape/fill/lerp.d.ts +1 -1
  48. package/dist/attributes/shape/fill/lerp.js.map +1 -1
  49. package/dist/attributes/shape/filters/chain.d.ts +1 -1
  50. package/dist/attributes/shape/filters/chain.js +1 -1
  51. package/dist/attributes/shape/filters/chain.js.map +1 -1
  52. package/dist/attributes/shape/filters/union.d.ts +4 -3
  53. package/dist/attributes/shape/filters/union.d.ts.map +1 -1
  54. package/dist/attributes/shape/filters/union.js.map +1 -1
  55. package/dist/attributes/shape/path/ops.d.ts +1 -2
  56. package/dist/attributes/shape/path/ops.d.ts.map +1 -1
  57. package/dist/attributes/shape/path/ops.js.map +1 -1
  58. package/dist/attributes/shared/operators.d.ts +2 -2
  59. package/dist/attributes/shared/operators.js.map +1 -1
  60. package/dist/attributes/text/types.d.ts +2 -3
  61. package/dist/attributes/text/types.d.ts.map +1 -1
  62. package/dist/attributes/text/types.js.map +1 -1
  63. package/dist/browser/chunks/chunk-D4FSTPML.js +14 -0
  64. package/dist/browser/chunks/chunk-D4FSTPML.js.map +7 -0
  65. package/dist/browser/chunks/chunk-LKUYVFU3.js +2 -0
  66. package/dist/browser/chunks/chunk-LKUYVFU3.js.map +7 -0
  67. package/dist/browser/chunks/chunk-RTNATFWX.js +5 -0
  68. package/dist/browser/chunks/chunk-RTNATFWX.js.map +7 -0
  69. package/dist/browser/chunks/chunk-ZRPZPWZU.js +3 -0
  70. package/dist/browser/chunks/chunk-ZRPZPWZU.js.map +7 -0
  71. package/dist/browser/component.js +1 -1
  72. package/dist/browser/component.js.map +4 -4
  73. package/dist/browser/experimental.js +2 -0
  74. package/dist/browser/index.js +1 -1
  75. package/dist/browser/index.js.map +4 -4
  76. package/dist/browser/manifest.json +3 -4
  77. package/dist/browser/sdk.js +1 -1
  78. package/dist/component/api.d.ts +508 -0
  79. package/dist/component/api.d.ts.map +1 -0
  80. package/dist/component/api.js +4 -0
  81. package/dist/component/api.js.map +1 -0
  82. package/dist/component/builtins/audio.d.ts +26 -0
  83. package/dist/component/builtins/audio.d.ts.map +1 -0
  84. package/dist/component/builtins/audio.js +41 -0
  85. package/dist/component/builtins/audio.js.map +1 -0
  86. package/dist/component/builtins/canvas3d.d.ts +98 -0
  87. package/dist/component/builtins/canvas3d.d.ts.map +1 -0
  88. package/dist/component/builtins/canvas3d.js +21 -0
  89. package/dist/component/builtins/canvas3d.js.map +1 -0
  90. package/dist/component/builtins/composite.d.ts +56 -0
  91. package/dist/component/builtins/composite.d.ts.map +1 -0
  92. package/dist/component/builtins/composite.js +25 -0
  93. package/dist/component/builtins/composite.js.map +1 -0
  94. package/dist/component/builtins/geometry.d.ts +505 -0
  95. package/dist/component/builtins/geometry.d.ts.map +1 -0
  96. package/dist/component/builtins/geometry.js +107 -0
  97. package/dist/component/builtins/geometry.js.map +1 -0
  98. package/dist/component/builtins/layout.d.ts +88 -0
  99. package/dist/component/builtins/layout.d.ts.map +1 -0
  100. package/dist/component/builtins/layout.js +84 -0
  101. package/dist/component/builtins/layout.js.map +1 -0
  102. package/dist/component/builtins/media.d.ts +95 -0
  103. package/dist/component/builtins/media.d.ts.map +1 -0
  104. package/dist/component/builtins/media.js +149 -0
  105. package/dist/component/builtins/media.js.map +1 -0
  106. package/dist/component/builtins/providers.d.ts +23 -0
  107. package/dist/component/builtins/providers.d.ts.map +1 -0
  108. package/dist/component/builtins/providers.js +30 -0
  109. package/dist/component/builtins/providers.js.map +1 -0
  110. package/dist/component/builtins/text.d.ts +193 -0
  111. package/dist/component/builtins/text.d.ts.map +1 -0
  112. package/dist/component/builtins/text.js +113 -0
  113. package/dist/component/builtins/text.js.map +1 -0
  114. package/dist/component/builtins/three.d.ts +1085 -0
  115. package/dist/component/builtins/three.d.ts.map +1 -0
  116. package/dist/component/builtins/three.js +265 -0
  117. package/dist/component/builtins/three.js.map +1 -0
  118. package/dist/component/clip-of.d.ts +5 -0
  119. package/dist/component/clip-of.d.ts.map +1 -0
  120. package/dist/component/clip-of.js +33 -0
  121. package/dist/component/clip-of.js.map +1 -0
  122. package/dist/component/commands-for.d.ts +19 -0
  123. package/dist/component/commands-for.d.ts.map +1 -0
  124. package/dist/component/commands-for.js +5 -0
  125. package/dist/component/commands-for.js.map +1 -0
  126. package/dist/component/component-audio.d.ts +9 -0
  127. package/dist/component/component-audio.d.ts.map +1 -0
  128. package/dist/component/component-audio.js +18 -0
  129. package/dist/component/component-audio.js.map +1 -0
  130. package/dist/component/component2d.d.ts +9 -0
  131. package/dist/component/component2d.d.ts.map +1 -0
  132. package/dist/component/component2d.js +239 -0
  133. package/dist/component/component2d.js.map +1 -0
  134. package/dist/component/component3d.d.ts +9 -0
  135. package/dist/component/component3d.d.ts.map +1 -0
  136. package/dist/component/component3d.js +99 -0
  137. package/dist/component/component3d.js.map +1 -0
  138. package/dist/component/factory.d.ts +63 -0
  139. package/dist/component/factory.d.ts.map +1 -0
  140. package/dist/component/factory.js +313 -0
  141. package/dist/component/factory.js.map +1 -0
  142. package/dist/component/modules/aim.d.ts +30 -0
  143. package/dist/component/modules/aim.d.ts.map +1 -0
  144. package/dist/component/modules/aim.js +39 -0
  145. package/dist/component/modules/aim.js.map +1 -0
  146. package/dist/component/modules/corners.d.ts +13 -0
  147. package/dist/component/modules/corners.d.ts.map +1 -0
  148. package/dist/component/modules/corners.js +12 -0
  149. package/dist/component/modules/corners.js.map +1 -0
  150. package/dist/component/modules/flow.d.ts +26 -0
  151. package/dist/component/modules/flow.d.ts.map +1 -0
  152. package/dist/component/modules/flow.js +55 -0
  153. package/dist/component/modules/flow.js.map +1 -0
  154. package/dist/component/modules/material.d.ts +40 -0
  155. package/dist/component/modules/material.d.ts.map +1 -0
  156. package/dist/component/modules/material.js +75 -0
  157. package/dist/component/modules/material.js.map +1 -0
  158. package/dist/component/modules/paint.d.ts +71 -0
  159. package/dist/component/modules/paint.d.ts.map +1 -0
  160. package/dist/component/modules/paint.js +106 -0
  161. package/dist/component/modules/paint.js.map +1 -0
  162. package/dist/component/modules/shapes.d.ts +31 -0
  163. package/dist/component/modules/shapes.d.ts.map +1 -0
  164. package/dist/component/modules/shapes.js +43 -0
  165. package/dist/component/modules/shapes.js.map +1 -0
  166. package/dist/component/modules/text-layout.d.ts +26 -0
  167. package/dist/component/modules/text-layout.d.ts.map +1 -0
  168. package/dist/component/modules/text-layout.js +57 -0
  169. package/dist/component/modules/text-layout.js.map +1 -0
  170. package/dist/component/modules/text-style.d.ts +48 -0
  171. package/dist/component/modules/text-style.d.ts.map +1 -0
  172. package/dist/component/modules/text-style.js +63 -0
  173. package/dist/component/modules/text-style.js.map +1 -0
  174. package/dist/component/modules/three-entries.d.ts +23 -0
  175. package/dist/component/modules/three-entries.d.ts.map +1 -0
  176. package/dist/component/modules/three-entries.js +41 -0
  177. package/dist/component/modules/three-entries.js.map +1 -0
  178. package/dist/component/modules/view3d.d.ts +55 -0
  179. package/dist/component/modules/view3d.d.ts.map +1 -0
  180. package/dist/component/modules/view3d.js +160 -0
  181. package/dist/component/modules/view3d.js.map +1 -0
  182. package/dist/component/timeline.d.ts +22 -0
  183. package/dist/component/timeline.d.ts.map +1 -0
  184. package/dist/component/timeline.js +128 -0
  185. package/dist/component/timeline.js.map +1 -0
  186. package/dist/component/type-def.d.ts +26 -0
  187. package/dist/component/type-def.d.ts.map +1 -0
  188. package/dist/component/type-def.js +16 -0
  189. package/dist/component/type-def.js.map +1 -0
  190. package/dist/component/types.d.ts +91 -0
  191. package/dist/component/types.d.ts.map +1 -0
  192. package/dist/component/types.js +88 -0
  193. package/dist/component/types.js.map +1 -0
  194. package/dist/component/views.d.ts +121 -0
  195. package/dist/component/views.d.ts.map +1 -0
  196. package/dist/component/views.js +413 -0
  197. package/dist/component/views.js.map +1 -0
  198. package/dist/component.d.ts +10 -19
  199. package/dist/component.d.ts.map +1 -1
  200. package/dist/component.js +10 -19
  201. package/dist/component.js.map +1 -1
  202. package/dist/components/builtins/audio/audio.d.ts +53 -0
  203. package/dist/components/builtins/audio/audio.d.ts.map +1 -0
  204. package/dist/components/builtins/audio/audio.js +41 -0
  205. package/dist/components/builtins/audio/audio.js.map +1 -0
  206. package/dist/components/builtins/geometry/composite.d.ts +93 -0
  207. package/dist/components/builtins/geometry/composite.d.ts.map +1 -0
  208. package/dist/components/builtins/geometry/composite.js +25 -0
  209. package/dist/components/builtins/geometry/composite.js.map +1 -0
  210. package/dist/components/builtins/geometry/geometry.d.ts +921 -0
  211. package/dist/components/builtins/geometry/geometry.d.ts.map +1 -0
  212. package/dist/components/builtins/geometry/geometry.js +107 -0
  213. package/dist/components/builtins/geometry/geometry.js.map +1 -0
  214. package/dist/components/builtins/geometry/shape-outline.d.ts +93 -0
  215. package/dist/components/builtins/geometry/shape-outline.d.ts.map +1 -0
  216. package/dist/components/builtins/geometry/shape-outline.js +470 -0
  217. package/dist/components/builtins/geometry/shape-outline.js.map +1 -0
  218. package/dist/components/builtins/layout/layout.d.ts +186 -0
  219. package/dist/components/builtins/layout/layout.d.ts.map +1 -0
  220. package/dist/components/builtins/layout/layout.js +84 -0
  221. package/dist/components/builtins/layout/layout.js.map +1 -0
  222. package/dist/components/builtins/media/media.d.ts +240 -0
  223. package/dist/components/builtins/media/media.d.ts.map +1 -0
  224. package/dist/components/builtins/media/media.js +149 -0
  225. package/dist/components/builtins/media/media.js.map +1 -0
  226. package/dist/components/builtins/providers/providers.d.ts +47 -0
  227. package/dist/components/builtins/providers/providers.d.ts.map +1 -0
  228. package/dist/components/builtins/providers/providers.js +30 -0
  229. package/dist/components/builtins/providers/providers.js.map +1 -0
  230. package/dist/components/builtins/text/number-format.d.ts +66 -0
  231. package/dist/components/builtins/text/number-format.d.ts.map +1 -0
  232. package/dist/components/builtins/text/number-format.js +227 -0
  233. package/dist/components/builtins/text/number-format.js.map +1 -0
  234. package/dist/components/builtins/text/number-pattern.d.ts +51 -0
  235. package/dist/components/builtins/text/number-pattern.d.ts.map +1 -0
  236. package/dist/components/builtins/text/number-pattern.js +77 -0
  237. package/dist/components/builtins/text/number-pattern.js.map +1 -0
  238. package/dist/components/builtins/text/text-defaults.d.ts +32 -0
  239. package/dist/components/builtins/text/text-defaults.d.ts.map +1 -0
  240. package/dist/components/builtins/text/text-defaults.js +37 -0
  241. package/dist/components/builtins/text/text-defaults.js.map +1 -0
  242. package/dist/components/builtins/text/text-layout.d.ts +82 -0
  243. package/dist/components/builtins/text/text-layout.d.ts.map +1 -0
  244. package/dist/components/builtins/text/text-layout.js +331 -0
  245. package/dist/components/builtins/text/text-layout.js.map +1 -0
  246. package/dist/components/builtins/text/text.d.ts +409 -0
  247. package/dist/components/builtins/text/text.d.ts.map +1 -0
  248. package/dist/components/builtins/text/text.js +113 -0
  249. package/dist/components/builtins/text/text.js.map +1 -0
  250. package/dist/components/builtins/three/canvas3d.d.ts +245 -0
  251. package/dist/components/builtins/three/canvas3d.d.ts.map +1 -0
  252. package/dist/components/builtins/three/canvas3d.js +21 -0
  253. package/dist/components/builtins/three/canvas3d.js.map +1 -0
  254. package/dist/components/builtins/three/grid-geometry3d.d.ts +62 -0
  255. package/dist/components/builtins/three/grid-geometry3d.d.ts.map +1 -0
  256. package/dist/components/builtins/three/grid-geometry3d.js +114 -0
  257. package/dist/components/builtins/three/grid-geometry3d.js.map +1 -0
  258. package/dist/components/builtins/three/three.d.ts +1889 -0
  259. package/dist/components/builtins/three/three.d.ts.map +1 -0
  260. package/dist/components/builtins/three/three.js +305 -0
  261. package/dist/components/builtins/three/three.js.map +1 -0
  262. package/dist/components/factory/api.d.ts +516 -0
  263. package/dist/components/factory/api.d.ts.map +1 -0
  264. package/dist/components/factory/api.js +4 -0
  265. package/dist/components/factory/api.js.map +1 -0
  266. package/dist/components/factory/clip-of.d.ts +5 -0
  267. package/dist/components/factory/clip-of.d.ts.map +1 -0
  268. package/dist/components/factory/clip-of.js +33 -0
  269. package/dist/components/factory/clip-of.js.map +1 -0
  270. package/dist/components/factory/commands-for.d.ts +19 -0
  271. package/dist/components/factory/commands-for.d.ts.map +1 -0
  272. package/dist/components/factory/commands-for.js +5 -0
  273. package/dist/components/factory/commands-for.js.map +1 -0
  274. package/dist/components/factory/component-audio.d.ts +9 -0
  275. package/dist/components/factory/component-audio.d.ts.map +1 -0
  276. package/dist/components/factory/component-audio.js +18 -0
  277. package/dist/components/factory/component-audio.js.map +1 -0
  278. package/dist/components/factory/component2d.d.ts +8 -0
  279. package/dist/components/factory/component2d.d.ts.map +1 -0
  280. package/dist/components/factory/component2d.js +240 -0
  281. package/dist/components/factory/component2d.js.map +1 -0
  282. package/dist/components/factory/component3d.d.ts +9 -0
  283. package/dist/components/factory/component3d.d.ts.map +1 -0
  284. package/dist/components/factory/component3d.js +99 -0
  285. package/dist/components/factory/component3d.js.map +1 -0
  286. package/dist/components/factory/factory.d.ts +63 -0
  287. package/dist/components/factory/factory.d.ts.map +1 -0
  288. package/dist/components/factory/factory.js +313 -0
  289. package/dist/components/factory/factory.js.map +1 -0
  290. package/dist/components/factory/timeline.d.ts +22 -0
  291. package/dist/components/factory/timeline.d.ts.map +1 -0
  292. package/dist/components/factory/timeline.js +128 -0
  293. package/dist/components/factory/timeline.js.map +1 -0
  294. package/dist/components/factory/type-def.d.ts +26 -0
  295. package/dist/components/factory/type-def.d.ts.map +1 -0
  296. package/dist/components/factory/type-def.js +16 -0
  297. package/dist/components/factory/type-def.js.map +1 -0
  298. package/dist/components/factory/types.d.ts +91 -0
  299. package/dist/components/factory/types.d.ts.map +1 -0
  300. package/dist/components/factory/types.js +88 -0
  301. package/dist/components/factory/types.js.map +1 -0
  302. package/dist/components/factory/views.d.ts +121 -0
  303. package/dist/components/factory/views.d.ts.map +1 -0
  304. package/dist/components/factory/views.js +413 -0
  305. package/dist/components/factory/views.js.map +1 -0
  306. package/dist/components/modules/aim.d.ts +30 -0
  307. package/dist/components/modules/aim.d.ts.map +1 -0
  308. package/dist/components/modules/aim.js +39 -0
  309. package/dist/components/modules/aim.js.map +1 -0
  310. package/dist/components/modules/corners.d.ts +13 -0
  311. package/dist/components/modules/corners.d.ts.map +1 -0
  312. package/dist/components/modules/corners.js +12 -0
  313. package/dist/components/modules/corners.js.map +1 -0
  314. package/dist/components/modules/flow.d.ts +26 -0
  315. package/dist/components/modules/flow.d.ts.map +1 -0
  316. package/dist/components/modules/flow.js +57 -0
  317. package/dist/components/modules/flow.js.map +1 -0
  318. package/dist/components/modules/material.d.ts +40 -0
  319. package/dist/components/modules/material.d.ts.map +1 -0
  320. package/dist/components/modules/material.js +75 -0
  321. package/dist/components/modules/material.js.map +1 -0
  322. package/dist/components/modules/paint.d.ts +71 -0
  323. package/dist/components/modules/paint.d.ts.map +1 -0
  324. package/dist/components/modules/paint.js +106 -0
  325. package/dist/components/modules/paint.js.map +1 -0
  326. package/dist/components/modules/shapes.d.ts +31 -0
  327. package/dist/components/modules/shapes.d.ts.map +1 -0
  328. package/dist/components/modules/shapes.js +43 -0
  329. package/dist/components/modules/shapes.js.map +1 -0
  330. package/dist/components/modules/text-layout.d.ts +26 -0
  331. package/dist/components/modules/text-layout.d.ts.map +1 -0
  332. package/dist/components/modules/text-layout.js +57 -0
  333. package/dist/components/modules/text-layout.js.map +1 -0
  334. package/dist/components/modules/text-style.d.ts +48 -0
  335. package/dist/components/modules/text-style.d.ts.map +1 -0
  336. package/dist/components/modules/text-style.js +63 -0
  337. package/dist/components/modules/text-style.js.map +1 -0
  338. package/dist/components/modules/three-entries.d.ts +23 -0
  339. package/dist/components/modules/three-entries.d.ts.map +1 -0
  340. package/dist/components/modules/three-entries.js +41 -0
  341. package/dist/components/modules/three-entries.js.map +1 -0
  342. package/dist/components/modules/view3d.d.ts +59 -0
  343. package/dist/components/modules/view3d.d.ts.map +1 -0
  344. package/dist/components/modules/view3d.js +171 -0
  345. package/dist/components/modules/view3d.js.map +1 -0
  346. package/dist/components/trees/2d/group-bounds.d.ts +56 -0
  347. package/dist/components/trees/2d/group-bounds.d.ts.map +1 -0
  348. package/dist/components/trees/2d/group-bounds.js +87 -0
  349. package/dist/components/trees/2d/group-bounds.js.map +1 -0
  350. package/dist/components/trees/2d/node-lifecycle.d.ts +46 -0
  351. package/dist/components/trees/2d/node-lifecycle.d.ts.map +1 -0
  352. package/dist/components/trees/2d/node-lifecycle.js +264 -0
  353. package/dist/components/trees/2d/node-lifecycle.js.map +1 -0
  354. package/dist/components/trees/2d/node-motion.d.ts +56 -0
  355. package/dist/components/trees/2d/node-motion.d.ts.map +1 -0
  356. package/dist/components/trees/2d/node-motion.js +86 -0
  357. package/dist/components/trees/2d/node-motion.js.map +1 -0
  358. package/dist/components/trees/2d/node-render.d.ts +36 -0
  359. package/dist/components/trees/2d/node-render.d.ts.map +1 -0
  360. package/dist/components/trees/2d/node-render.js +67 -0
  361. package/dist/components/trees/2d/node-render.js.map +1 -0
  362. package/dist/components/trees/2d/node-space.d.ts +63 -0
  363. package/dist/components/trees/2d/node-space.d.ts.map +1 -0
  364. package/dist/components/trees/2d/node-space.js +131 -0
  365. package/dist/components/trees/2d/node-space.js.map +1 -0
  366. package/dist/components/trees/2d/node-transform.d.ts +55 -0
  367. package/dist/components/trees/2d/node-transform.d.ts.map +1 -0
  368. package/dist/components/trees/2d/node-transform.js +73 -0
  369. package/dist/components/trees/2d/node-transform.js.map +1 -0
  370. package/dist/components/trees/2d/node2d.d.ts +1020 -0
  371. package/dist/components/trees/2d/node2d.d.ts.map +1 -0
  372. package/dist/components/trees/2d/node2d.js +1481 -0
  373. package/dist/components/trees/2d/node2d.js.map +1 -0
  374. package/dist/components/trees/audio/index.d.ts +2 -0
  375. package/dist/components/trees/audio/index.d.ts.map +1 -0
  376. package/dist/components/trees/audio/index.js +2 -0
  377. package/dist/components/trees/audio/index.js.map +1 -0
  378. package/dist/components/trees/audio/node-audio.d.ts +109 -0
  379. package/dist/components/trees/audio/node-audio.d.ts.map +1 -0
  380. package/dist/components/trees/audio/node-audio.js +167 -0
  381. package/dist/components/trees/audio/node-audio.js.map +1 -0
  382. package/dist/components/trees/index.d.ts +10 -0
  383. package/dist/components/trees/index.d.ts.map +1 -0
  384. package/dist/components/trees/index.js +14 -0
  385. package/dist/components/trees/index.js.map +1 -0
  386. package/dist/components/trees/node/node-editor-state.d.ts +53 -0
  387. package/dist/components/trees/node/node-editor-state.d.ts.map +1 -0
  388. package/dist/components/trees/node/node-editor-state.js +23 -0
  389. package/dist/components/trees/node/node-editor-state.js.map +1 -0
  390. package/dist/components/trees/node/node-reactive.d.ts +89 -0
  391. package/dist/components/trees/node/node-reactive.d.ts.map +1 -0
  392. package/dist/components/trees/node/node-reactive.js +135 -0
  393. package/dist/components/trees/node/node-reactive.js.map +1 -0
  394. package/dist/components/trees/node/node-time.d.ts +39 -0
  395. package/dist/components/trees/node/node-time.d.ts.map +1 -0
  396. package/dist/components/trees/node/node-time.js +14 -0
  397. package/dist/components/trees/node/node-time.js.map +1 -0
  398. package/dist/components/trees/node/node-walk.d.ts +46 -0
  399. package/dist/components/trees/node/node-walk.d.ts.map +1 -0
  400. package/dist/components/trees/node/node-walk.js +74 -0
  401. package/dist/components/trees/node/node-walk.js.map +1 -0
  402. package/dist/components/trees/node/node.d.ts +401 -0
  403. package/dist/components/trees/node/node.d.ts.map +1 -0
  404. package/dist/components/trees/node/node.js +680 -0
  405. package/dist/components/trees/node/node.js.map +1 -0
  406. package/dist/components/trees/root/canvas2d-node.d.ts +163 -0
  407. package/dist/components/trees/root/canvas2d-node.d.ts.map +1 -0
  408. package/dist/components/trees/root/canvas2d-node.js +216 -0
  409. package/dist/components/trees/root/canvas2d-node.js.map +1 -0
  410. package/dist/components/trees/three/node3d.d.ts +222 -0
  411. package/dist/components/trees/three/node3d.d.ts.map +1 -0
  412. package/dist/components/trees/three/node3d.js +289 -0
  413. package/dist/components/trees/three/node3d.js.map +1 -0
  414. package/dist/document/audio.d.ts +9 -1
  415. package/dist/document/audio.d.ts.map +1 -1
  416. package/dist/document/audio.js +41 -0
  417. package/dist/document/audio.js.map +1 -1
  418. package/dist/document/builtins.d.ts.map +1 -1
  419. package/dist/document/builtins.js +13 -31
  420. package/dist/document/builtins.js.map +1 -1
  421. package/dist/document/command-traits.d.ts +2 -2
  422. package/dist/document/command-traits.js +4 -1
  423. package/dist/document/command-traits.js.map +1 -1
  424. package/dist/document/deny-globals.d.ts +2 -2
  425. package/dist/document/deny-globals.js +2 -2
  426. package/dist/document/deny-globals.js.map +1 -1
  427. package/dist/document/diff.d.ts.map +1 -1
  428. package/dist/document/diff.js +3 -3
  429. package/dist/document/diff.js.map +1 -1
  430. package/dist/document/doc-index.d.ts.map +1 -1
  431. package/dist/document/doc-index.js +3 -3
  432. package/dist/document/doc-index.js.map +1 -1
  433. package/dist/document/expression/index.d.ts +1 -1
  434. package/dist/document/expression/index.js +1 -1
  435. package/dist/document/expression/index.js.map +1 -1
  436. package/dist/document/expression/ops.js +1 -1
  437. package/dist/document/expression/ops.js.map +1 -1
  438. package/dist/document/index.d.ts +1 -2
  439. package/dist/document/index.d.ts.map +1 -1
  440. package/dist/document/index.js +1 -2
  441. package/dist/document/index.js.map +1 -1
  442. package/dist/document/node-decorator.d.ts +14 -10
  443. package/dist/document/node-decorator.d.ts.map +1 -1
  444. package/dist/document/node-decorator.js +14 -10
  445. package/dist/document/node-decorator.js.map +1 -1
  446. package/dist/document/node-descriptor.d.ts +9 -3
  447. package/dist/document/node-descriptor.d.ts.map +1 -1
  448. package/dist/document/node-descriptor.js.map +1 -1
  449. package/dist/document/placement.js +2 -2
  450. package/dist/document/placement.js.map +1 -1
  451. package/dist/document/registry.d.ts +29 -36
  452. package/dist/document/registry.d.ts.map +1 -1
  453. package/dist/document/registry.js +29 -35
  454. package/dist/document/registry.js.map +1 -1
  455. package/dist/document/settled-index.d.ts +49 -0
  456. package/dist/document/settled-index.d.ts.map +1 -0
  457. package/dist/document/settled-index.js +247 -0
  458. package/dist/document/settled-index.js.map +1 -0
  459. package/dist/document/timeline.d.ts +29 -3
  460. package/dist/document/timeline.d.ts.map +1 -1
  461. package/dist/document/timeline.js +99 -3
  462. package/dist/document/timeline.js.map +1 -1
  463. package/dist/document/types.d.ts +4 -4
  464. package/dist/document/types.js.map +1 -1
  465. package/dist/document/validate.d.ts +1 -1
  466. package/dist/document/validate.js.map +1 -1
  467. package/dist/experimental.d.ts +22 -0
  468. package/dist/experimental.d.ts.map +1 -0
  469. package/dist/experimental.js +20 -0
  470. package/dist/experimental.js.map +1 -0
  471. package/dist/index.d.ts +10 -2
  472. package/dist/index.d.ts.map +1 -1
  473. package/dist/index.js +10 -2
  474. package/dist/index.js.map +1 -1
  475. package/dist/layout/types.d.ts +1 -1
  476. package/dist/layout/types.js.map +1 -1
  477. package/dist/nodes/audio/index.d.ts +2 -2
  478. package/dist/nodes/audio/index.d.ts.map +1 -1
  479. package/dist/nodes/audio/index.js +0 -2
  480. package/dist/nodes/audio/index.js.map +1 -1
  481. package/dist/nodes/audio/sound-node.d.ts +2 -1
  482. package/dist/nodes/audio/sound-node.d.ts.map +1 -1
  483. package/dist/nodes/audio/sound-node.js +3 -0
  484. package/dist/nodes/audio/sound-node.js.map +1 -1
  485. package/dist/nodes/index.d.ts +39 -27
  486. package/dist/nodes/index.d.ts.map +1 -1
  487. package/dist/nodes/index.js +16 -30
  488. package/dist/nodes/index.js.map +1 -1
  489. package/dist/nodes/node/node.d.ts +7 -1
  490. package/dist/nodes/node/node.d.ts.map +1 -1
  491. package/dist/nodes/node/node.js +23 -8
  492. package/dist/nodes/node/node.js.map +1 -1
  493. package/dist/nodes/root/canvas2d-node.d.ts +2 -1
  494. package/dist/nodes/root/canvas2d-node.d.ts.map +1 -1
  495. package/dist/nodes/root/canvas2d-node.js +3 -0
  496. package/dist/nodes/root/canvas2d-node.js.map +1 -1
  497. package/dist/nodes/text/richtext-node.d.ts +0 -5
  498. package/dist/nodes/text/richtext-node.d.ts.map +1 -1
  499. package/dist/nodes/text/richtext-node.js +5 -71
  500. package/dist/nodes/text/richtext-node.js.map +1 -1
  501. package/dist/nodes/text/text-base.d.ts +5 -22
  502. package/dist/nodes/text/text-base.d.ts.map +1 -1
  503. package/dist/nodes/text/text-base.js +12 -363
  504. package/dist/nodes/text/text-base.js.map +1 -1
  505. package/dist/nodes/text/text-layout.d.ts +87 -0
  506. package/dist/nodes/text/text-layout.d.ts.map +1 -0
  507. package/dist/nodes/text/text-layout.js +368 -0
  508. package/dist/nodes/text/text-layout.js.map +1 -0
  509. package/dist/nodes/three/canvas3d-node.d.ts +3 -1
  510. package/dist/nodes/three/canvas3d-node.d.ts.map +1 -1
  511. package/dist/nodes/three/canvas3d-node.js +6 -0
  512. package/dist/nodes/three/canvas3d-node.js.map +1 -1
  513. package/dist/props/host.d.ts +1 -1
  514. package/dist/props/host.js.map +1 -1
  515. package/dist/props/slot.d.ts +1 -1
  516. package/dist/props/slot.js +1 -1
  517. package/dist/props/slot.js.map +1 -1
  518. package/dist/render/clip.d.ts +1 -1
  519. package/dist/render/clip.js +1 -1
  520. package/dist/render/clip.js.map +1 -1
  521. package/dist/render/descriptors/rect.js.map +1 -1
  522. package/dist/render/descriptors/text.d.ts +11 -5
  523. package/dist/render/descriptors/text.d.ts.map +1 -1
  524. package/dist/render/descriptors/text.js +7 -1
  525. package/dist/render/descriptors/text.js.map +1 -1
  526. package/dist/render/render-context2d.d.ts +2 -2
  527. package/dist/render/render-context2d.js.map +1 -1
  528. package/dist/render3d/builders.d.ts +1 -1
  529. package/dist/render3d/builders.js +1 -1
  530. package/dist/render3d/builders.js.map +1 -1
  531. package/dist/render3d/graphics3d.d.ts +13 -19
  532. package/dist/render3d/graphics3d.d.ts.map +1 -1
  533. package/dist/render3d/graphics3d.js +13 -19
  534. package/dist/render3d/graphics3d.js.map +1 -1
  535. package/dist/render3d/scene3d.d.ts +1 -1
  536. package/dist/render3d/scene3d.js +1 -1
  537. package/dist/render3d/scene3d.js.map +1 -1
  538. package/dist/render3d/texture.d.ts +2 -2
  539. package/dist/render3d/texture.d.ts.map +1 -1
  540. package/dist/render3d/texture.js.map +1 -1
  541. package/dist/render3d/vector3.d.ts +2 -2
  542. package/dist/render3d/vector3.js +2 -2
  543. package/dist/render3d/vector3.js.map +1 -1
  544. package/dist/runtime/asset-refine.d.ts +1 -1
  545. package/dist/runtime/asset-refine.d.ts.map +1 -1
  546. package/dist/runtime/asset-refine.js +1 -1
  547. package/dist/runtime/asset-refine.js.map +1 -1
  548. package/dist/runtime/asset-update.js +1 -1
  549. package/dist/runtime/asset-update.js.map +1 -1
  550. package/dist/runtime/audio-index.d.ts +0 -11
  551. package/dist/runtime/audio-index.d.ts.map +1 -1
  552. package/dist/runtime/audio-index.js +0 -25
  553. package/dist/runtime/audio-index.js.map +1 -1
  554. package/dist/runtime/clip-instance.d.ts +7 -4
  555. package/dist/runtime/clip-instance.d.ts.map +1 -1
  556. package/dist/runtime/clip-instance.js +21 -7
  557. package/dist/runtime/clip-instance.js.map +1 -1
  558. package/dist/runtime/clip-store.d.ts +11 -3
  559. package/dist/runtime/clip-store.d.ts.map +1 -1
  560. package/dist/runtime/clip-store.js +83 -23
  561. package/dist/runtime/clip-store.js.map +1 -1
  562. package/dist/runtime/engine.d.ts +3 -3
  563. package/dist/runtime/engine.js +2 -2
  564. package/dist/runtime/engine.js.map +1 -1
  565. package/dist/runtime/node-picking.d.ts +2 -2
  566. package/dist/runtime/node-picking.d.ts.map +1 -1
  567. package/dist/runtime/node-picking.js +9 -10
  568. package/dist/runtime/node-picking.js.map +1 -1
  569. package/dist/runtime/node-picking3d.d.ts +12 -5
  570. package/dist/runtime/node-picking3d.d.ts.map +1 -1
  571. package/dist/runtime/node-picking3d.js +6 -1
  572. package/dist/runtime/node-picking3d.js.map +1 -1
  573. package/dist/runtime/playback-controller.d.ts +2 -2
  574. package/dist/runtime/playback-controller.d.ts.map +1 -1
  575. package/dist/runtime/playback-controller.js +1 -1
  576. package/dist/runtime/playback-controller.js.map +1 -1
  577. package/dist/runtime/state-evaluator.d.ts +2 -2
  578. package/dist/runtime/state-evaluator.d.ts.map +1 -1
  579. package/dist/runtime/state-evaluator.js.map +1 -1
  580. package/dist/runtime/text-geometry.d.ts +1 -1
  581. package/dist/runtime/text-geometry.d.ts.map +1 -1
  582. package/dist/runtime/text-geometry.js +6 -3
  583. package/dist/runtime/text-geometry.js.map +1 -1
  584. package/dist/sdk/index.d.ts +46 -21
  585. package/dist/sdk/index.d.ts.map +1 -1
  586. package/dist/sdk/index.js +47 -43
  587. package/dist/sdk/index.js.map +1 -1
  588. package/dist/tween/command-decorator.d.ts +7 -9
  589. package/dist/tween/command-decorator.d.ts.map +1 -1
  590. package/dist/tween/command-decorator.js +2 -2
  591. package/dist/tween/command-decorator.js.map +1 -1
  592. package/dist/tween/command.d.ts +13 -1
  593. package/dist/tween/command.d.ts.map +1 -1
  594. package/dist/tween/command.js +14 -0
  595. package/dist/tween/command.js.map +1 -1
  596. package/dist/tween/index.d.ts +2 -1
  597. package/dist/tween/index.d.ts.map +1 -1
  598. package/dist/tween/index.js +1 -1
  599. package/dist/tween/index.js.map +1 -1
  600. package/dist/tween/loop.d.ts +1 -1
  601. package/dist/tween/loop.js +1 -1
  602. package/dist/tween/loop.js.map +1 -1
  603. package/dist/util/reference.d.ts +6 -6
  604. package/dist/util/reference.js.map +1 -1
  605. package/package.json +7 -10
  606. package/dist/browser/chunks/chunk-FUZVFT3W.js +0 -18
  607. package/dist/browser/chunks/chunk-FUZVFT3W.js.map +0 -7
  608. package/dist/browser/chunks/chunk-QG6C23IJ.js +0 -3
  609. package/dist/browser/chunks/chunk-QG6C23IJ.js.map +0 -7
  610. package/dist/browser/chunks/chunk-SFNJRPBV.js +0 -2
  611. package/dist/browser/chunks/chunk-SFNJRPBV.js.map +0 -7
  612. package/dist/browser/jsx-jsx-dev-runtime.js +0 -2
  613. package/dist/browser/jsx-jsx-runtime.js +0 -2
  614. package/dist/browser/jsx-jsx-runtime.js.map +0 -7
  615. /package/dist/browser/{jsx-jsx-dev-runtime.js.map → experimental.js.map} +0 -0
@@ -0,0 +1,1481 @@
1
+ import { _observer, PropSlot } from "../../../props/slot.js";
2
+ import { LAYOUT_SLOT } from "../../../props/observer.js";
3
+ import { AssetNotLoadedError } from "../../../assets/errors.js";
4
+ import { declareMembers, property } from "../../../attributes/properties/decorator.js";
5
+ import { effectsProperty, insetsProperty, alignmentProperty } from "../../../attributes/properties/typed.js";
6
+ import { createMotionHistory, sampleMotion, primeMotion } from "./node-motion.js";
7
+ import { addChildAtAnimated, removeChildAtAnimated, reparentAnimated } from "./node-lifecycle.js";
8
+ import { alignmentOps } from "../../../attributes/layout/alignment.js";
9
+ import { Node } from "../../../components/trees/node/node.js";
10
+ import { applyToPoint, facesAway, hasProjection3D, invert, multiply, } from "../../../attributes/layout/matrix2d.js";
11
+ import { expandTransform3D } from "../../../attributes/layout/transform3d.js";
12
+ import { multiplyAffine3, nodeSpaceMatrix } from "../../../attributes/layout/space3d.js";
13
+ import { localMatrix, rotateOffset, worldAnchors } from "./node-transform.js";
14
+ import { spaceChildFrame, spaceChildOrder, spaceRootFrame } from "./node-space.js";
15
+ import { applyBackdropEffects as applyBackdropEffectsImpl, applyContentEffectScope, computeSpaceRects, } from "./node-render.js";
16
+ import { command } from "../../../tween/command-decorator.js";
17
+ import { PathBuilder } from "../../../render/descriptors/path-builder.js";
18
+ import { pathOps } from "../../../attributes/shape/path/ops.js";
19
+ import { size2DOps, sizeInputOps } from "../../../attributes/layout/size.js";
20
+ import { insetsOps } from "../../../attributes/layout/insets.js";
21
+ import { lerpPerspective } from "../../../tween/lerp.js";
22
+ import { flowOps } from "../../../layout/ops.js";
23
+ /**
24
+ * Stand-in for a node's reference rects when the context never reads them.
25
+ * Shared and empty — `computeSpaceRects` returns the same shape for a node with
26
+ * no parent, so consumers already handle it.
27
+ */
28
+ const NO_SPACE_RECTS = {};
29
+ /** The node centre in the normalised `[-1, 1]` alignment space — `pivot`'s own default. */
30
+ const ORIGIN_2D = { x: 0, y: 0 };
31
+ const NO_HANDLES = [];
32
+ // Filled per call and read synchronously by the matrix builders, like `_projectionScratch`.
33
+ const SLOT_PROJECTION = {
34
+ rotationX: 0, rotationY: 0, rotationZ: 0, depth: 0, perspective: 0,
35
+ flipHorizontal: false, flipVertical: false,
36
+ };
37
+ function slotProjection(placement) {
38
+ SLOT_PROJECTION.rotationX = placement.rotationX;
39
+ SLOT_PROJECTION.rotationY = placement.rotationY;
40
+ SLOT_PROJECTION.depth = placement.depth;
41
+ return SLOT_PROJECTION;
42
+ }
43
+ /** No settings: centred freeform, which is how a plain node arranges its children. */
44
+ const DEFAULT_FLOW = Object.freeze({});
45
+ const NO_CONTENT = { width: 0, height: 0 };
46
+ // WorldTransform, PropInput, and PropInputs now live in dedicated
47
+ // modules (see imports above) and are re-exported below so existing
48
+ // `from ".../node2d"` imports keep resolving.
49
+ export { Node } from "../../../components/trees/node/node.js";
50
+ /**
51
+ * The 2D tree's base: what every `component2d` lowers onto, and the scene root
52
+ * ({@link Canvas2D}). It wires together three systems:
53
+ *
54
+ * **Properties** — each declared prop is backed by a {@link PropSlot}, which
55
+ * holds either a value or a thunk. {@link set} updates props imperatively, and
56
+ * a callback `() => expr` binds one to a derived value.
57
+ *
58
+ * **Tweening** — `to({ data, duration, easing })` returns a {@link Command}
59
+ * that animates props to target values, evaluable at a time via `at(t)`.
60
+ * `moveTo`, `fadeTo`, `rotateTo`, `scaleTo` and the rest wrap it.
61
+ *
62
+ * **Layout** — `measure()` is called top-down to resolve sizes, then
63
+ * `layout()` places the node in its allocated `BoxBounds` and its children in
64
+ * its content box.
65
+ *
66
+ * ### Built-in visual props
67
+ * | prop | default | unit / notes |
68
+ * |-----------|----------|---------------------------------------|
69
+ * | `x` | 0 | horizontal offset in scene pixels |
70
+ * | `y` | 0 | vertical offset (positive = up) |
71
+ * | `width` | `'fill'` | `SizeInput`: px, `'fill'`, `'auto'` |
72
+ * | `height` | `'fill'` | same |
73
+ * | `size` | — | sugar: sets `width` and `height` together |
74
+ * | `scale` | 1 | uniform scale factor |
75
+ * | `rotate` | 0 | degrees, clockwise |
76
+ * | `opacity` | 1 | 0–1 |
77
+ * | `blend` | `'pass-through'` | layer blend mode (`NodeBlendMode`) |
78
+ * | `effects` | [] | post-process / blend effects |
79
+ * | `padding` | 0 | inner spacing, all four edges |
80
+ */
81
+ export class Node2D extends Node {
82
+ get dimension() { return "2d"; }
83
+ /**
84
+ * This node's parent, when that parent is itself 2D.
85
+ *
86
+ * A `Node2D` can only ever be adopted by another `Node2D` (see
87
+ * {@link Node.acceptsChild}), so this is `null` only for a detached node or
88
+ * the root — but it is typed honestly rather than cast, because the base
89
+ * tree holds both dimensions.
90
+ */
91
+ get parent2D() {
92
+ const parent = this._parent;
93
+ return parent instanceof Node2D ? parent : null;
94
+ }
95
+ /**
96
+ * This node's parent, narrowed to the 2D tree.
97
+ *
98
+ * Only a `Node2D` can adopt a `Node2D` (see {@link Node.acceptsChild}), so
99
+ * this never hides a real parent — it just spares every 2D caller a cast.
100
+ */
101
+ get parent() {
102
+ if (_observer !== null)
103
+ _observer.read(this._structureSlot());
104
+ return this.parent2D;
105
+ }
106
+ /**
107
+ * This node's children **in the 2D tree**.
108
+ *
109
+ * `Canvas3D` is the one node that holds both dimensions, and its `Node3D`
110
+ * children are not part of the 2D tree — they describe a scene it paints,
111
+ * not boxes it lays out — so they are reached through its own accessor
112
+ * instead. Every other node's list is already 2D, and this returns the live
113
+ * array untouched in that case rather than allocating a copy per read.
114
+ */
115
+ get children() {
116
+ if (_observer !== null)
117
+ _observer.read(this._structureSlot());
118
+ const all = this._children;
119
+ for (let i = 0; i < all.length; i++) {
120
+ if (!(all[i] instanceof Node2D)) {
121
+ return all.filter((c) => c instanceof Node2D);
122
+ }
123
+ }
124
+ return all;
125
+ }
126
+ constructor(props) {
127
+ super(props);
128
+ // Expand the `size` and `transform3D` sugar into the props they name
129
+ // before anything reads either — in place, so the single object `super()`
130
+ // retained as `_props` already carries the expanded values.
131
+ if (props) {
132
+ size2DOps.expand(props);
133
+ expandTransform3D(props);
134
+ }
135
+ // Fires the ref, adopts the seed, and applies every `property` default.
136
+ // Deferred to here rather than run by `super()` because the cells those
137
+ // props write into are this class's own fields, and a subclass's field
138
+ // initializers only run once `super()` has returned.
139
+ this.initProps(props);
140
+ // Specifying `flex` signals intent to fill the parent's main axis, so an
141
+ // unspecified width/height defaults to 'fill' (flex is a no-op on a
142
+ // fixed/hug axis) and skips the has-children default below.
143
+ if (props && props.flex !== undefined) {
144
+ if (props.width === undefined)
145
+ this.applyProp("width", "fill", { tween: sizeInputOps.lerp });
146
+ if (props.height === undefined)
147
+ this.applyProp("height", "fill", { tween: sizeInputOps.lerp });
148
+ }
149
+ else {
150
+ this.applyDefaultSize(props);
151
+ }
152
+ // Alignment-based positioning: validate, derive pivot, bind x/y. The pivot
153
+ // and centre offset math lives in alignmentOps (shared with the
154
+ // `to()` path); here we use its reactive binding form.
155
+ if (props) {
156
+ alignmentOps.validateProps(props);
157
+ const alignmentKey = alignmentOps.findKey(props);
158
+ if (alignmentKey) {
159
+ const raw = props[alignmentKey];
160
+ const getTarget = typeof raw === 'function' ? raw : () => raw;
161
+ const { pivot, x, y } = alignmentOps.bindTarget(alignmentKey, getTarget, () => this._layoutBounds.get());
162
+ this._writeProp('pivot', pivot);
163
+ this._writeProp('x', x);
164
+ this._writeProp('y', y);
165
+ }
166
+ }
167
+ this.adoptChildrenProp(props);
168
+ }
169
+ /**
170
+ * The 2D half of `set()`: `size` and `transform3D` are sugar with no slot of
171
+ * their own, so they are distributed into the props that do have one before
172
+ * the generic write loop runs.
173
+ */
174
+ set(props) {
175
+ // `size` has no slot of its own — it's sugar written straight to
176
+ // width/height (explicit width/height in the same call still wins).
177
+ const sizeVal = props.size;
178
+ // Same for `transform3D`, but expanded up front rather than after the
179
+ // loop: its fields are real props, so distributing them into `props`
180
+ // first means the generic loop writes them like any other key. Only the
181
+ // present-and-an-object case allocates, which is the rare one.
182
+ if (props.transform3D !== undefined) {
183
+ props = { ...props };
184
+ expandTransform3D(props);
185
+ }
186
+ super.set(props);
187
+ if (sizeVal !== undefined) {
188
+ if (props.width === undefined)
189
+ this._writeProp('width', sizeVal);
190
+ if (props.height === undefined)
191
+ this._writeProp('height', sizeVal);
192
+ }
193
+ }
194
+ /**
195
+ * The 2D half of `_prepareStep`: expand the positional sugar into the props
196
+ * that actually have cells, then let the base resolve the step.
197
+ *
198
+ * `to` is mutated in place, so the base sees the expanded target — which is
199
+ * why this can run entirely before `super`.
200
+ */
201
+ _prepareStep(to, duration, easing) {
202
+ // `size` has no slot of its own — expand it into width/height targets
203
+ // before anchor validation and the per-key tween setup below see it.
204
+ // `transform3D` is sugar in the same way, so it expands here too and its
205
+ // fields tween individually, exactly as if they had been named directly.
206
+ size2DOps.expand(to);
207
+ expandTransform3D(to);
208
+ // `pivot`: an explicit, transient origin for *this step's* rotation and
209
+ // scale — `moveTo`/`rotateTo`/`scaleTo`'s own option (see their object-form
210
+ // overloads below), or just as well a bare key on a `to()` target. Not a
211
+ // real prop — nothing on the node holds a value named `pivot` that a tween
212
+ // interpolates — so it's read and stripped before anything else here (the
213
+ // alignment validation included) ever sees it.
214
+ const explicitPivot = to.pivot;
215
+ if (explicitPivot !== undefined)
216
+ delete to.pivot;
217
+ alignmentOps.validateProps(to);
218
+ // If an alignment key is in the tween target, resolve it to x/y targets and
219
+ // set the transform origin (one-shot form of the shared alignment math in
220
+ // alignmentOps).
221
+ const alignmentKey = alignmentOps.findKey(to);
222
+ if (alignmentKey) {
223
+ const raw = to[alignmentKey];
224
+ const { pivot, x, y } = alignmentOps.resolveTargetOnce(alignmentKey, this._layoutBounds.get(), raw);
225
+ // Was `this._writeProp('pivot', pivot)`. `pivot` is the node's
226
+ // *permanent* rotation/scale origin — set once, reactively, at
227
+ // construction (see `alignmentOps.bindTarget`) from whichever alignment prop
228
+ // positions it there. A *tween's* target used to overwrite that
229
+ // permanent value with its own alignment every time one was used to
230
+ // state a position, which means a `moveTo` aligned differently from
231
+ // the node quietly re-pointed every rotation that ran after it.
232
+ // `transformOrigin` (see its own doc) is the right prop for this
233
+ // instead: it wins for the whole transform without being the node's
234
+ // one true pivot. An explicit `pivot` given on this same step (via
235
+ // `moveTo`/`rotateTo`/`scaleTo`'s object form) overrides the
236
+ // alignment-derived value in turn — the point a position is stated
237
+ // against and the point a rotation turns about are two different
238
+ // questions once a step can state them separately.
239
+ this._writeProp('transformOrigin', explicitPivot !== undefined ? alignmentOps.resolve(explicitPivot) : pivot);
240
+ to.x = x;
241
+ to.y = y;
242
+ }
243
+ else if (explicitPivot !== undefined) {
244
+ this._writeProp('transformOrigin', alignmentOps.resolve(explicitPivot));
245
+ }
246
+ return super._prepareStep(to, duration, easing);
247
+ }
248
+ /**
249
+ * A component's paint entries declare themselves, so only a node painting
250
+ * something its attributes do not describe has anything to add.
251
+ */
252
+ declareAssets(assets) {
253
+ assets.effects(this.effects);
254
+ }
255
+ /** Sample this node's own derived render state for the current frame. */
256
+ _sample() {
257
+ this._sampleMotion();
258
+ }
259
+ /**
260
+ * Record this node's current position as the motion history's previous
261
+ * frame, stamped `at`, deriving no velocity — see the base's note.
262
+ */
263
+ _primeMotion(at) {
264
+ const r = this.layoutBounds;
265
+ const o = this._offset();
266
+ primeMotion(this._motionHistory, (r?.x ?? 0) + o.x, (r?.y ?? 0) - o.y, this.rotation, this.scale, at);
267
+ }
268
+ _layoutBounds = new PropSlot({ x: 0, y: 0, width: 0, height: 0 }, this, LAYOUT_SLOT);
269
+ /**
270
+ * The size limits and the measurer threaded through this node's last
271
+ * {@link measure} pass.
272
+ *
273
+ * Retained so off-tree work can measure a not-yet-attached child *in
274
+ * isolation* — the animated child-insert in `node-lifecycle.ts` needs a hug
275
+ * child's natural size without putting it in this node's flow first, or the
276
+ * siblings shift for a frame. Undefined until this node is first measured.
277
+ *
278
+ * One object rather than two loose fields, because the two are only ever
279
+ * useful together and were previously reached through a
280
+ * `{ constraints?; _lastScope? }` structural cast from two other modules —
281
+ * a cast that would have gone on compiling through any rename.
282
+ *
283
+ * @internal
284
+ */
285
+ lastMeasure;
286
+ /**
287
+ * The box the last layout pass allocated this node: its size, and where it
288
+ * sits in its parent's space (canvas y-down).
289
+ *
290
+ * Reactive — a read inside a binding is tracked, so a prop bound to another
291
+ * node's box re-evaluates when that box moves.
292
+ *
293
+ * **Public, and a single member.** It used to be a `protected layoutRect`
294
+ * plus a public `measuredRect` alias that existed only so the picking walk
295
+ * could reach it — and, in practice, a `(node as any).layoutRect` cast in
296
+ * every test that needed a box. Two names for one value, one of them
297
+ * reachable only by lying to the compiler, is worse than the thing
298
+ * `protected` was buying. Writing it is still {@link setLayoutBounds}, which
299
+ * is where the layout engine's invariants live.
300
+ */
301
+ get layoutBounds() { return this._layoutBounds.get(); }
302
+ /**
303
+ * {@link flattenChildrenProp}, narrowed to the children this node will
304
+ * actually lay out — a 3D or audio child sits in the same `children` prop but
305
+ * takes no part in 2D layout, so it can't inform the size defaults either.
306
+ */
307
+ static flowChildrenProp(props) {
308
+ return Node2D.flattenChildrenProp(props).filter((c) => c instanceof Node2D);
309
+ }
310
+ /**
311
+ * True if any of `children` requests `"fill"` on `axis` — the signal a
312
+ * component's size default reads to decide whether hugging on that axis
313
+ * would strand the child with no space to fill into.
314
+ */
315
+ static hasFillChild(children, axis) {
316
+ return children.some((c) => (axis === "width" ? c.width : c.height) === "fill");
317
+ }
318
+ /**
319
+ * Default for `width`/`height`: hug-to-content when the node is given
320
+ * children, fill-the-parent when it's empty. Called once from the
321
+ * constructor (skipped when `flex` is set, since that already implies
322
+ * 'fill'); `component2d` replaces it with the component rule.
323
+ */
324
+ applyDefaultSize(props) {
325
+ const hasChildren = Node2D.flowChildrenProp(props).length > 0;
326
+ const defaultSize = hasChildren ? "hug" : "fill";
327
+ if (!props || props.width === undefined)
328
+ this.applyProp("width", defaultSize, { tween: sizeInputOps.lerp });
329
+ if (!props || props.height === undefined)
330
+ this.applyProp("height", defaultSize, { tween: sizeInputOps.lerp });
331
+ }
332
+ // ---- Motion helpers ---------------------------------------------------
333
+ //
334
+ // Each returns the `Command` it delegates to rather than wrapping it in
335
+ // anything, because the wrapper would discard the thing worth having: a
336
+ // `Command` can be *evaluated* at a time, and anything that merely advances
337
+ // can only be run to one.
338
+ /**
339
+ * Animate `x`/`y` to the given position, along `path`, or onto another node.
340
+ * `pivot` (optional) sets {@link Node2DProps.transformOrigin} — the point
341
+ * later rotate/scale turn about — independent of the node's own permanent
342
+ * {@link pivot}, and it carries forward like any other prop until something
343
+ * restates it.
344
+ *
345
+ * `path` replaces the destination rather than qualifying it — stating both is
346
+ * an error, since the path's own end is where the move ends — and the node
347
+ * walks it by **arc length**, so easing shapes the travel rather than the
348
+ * curve's parameter. Its coordinates *are* `x`/`y` values, in the same y-up
349
+ * space a `PathCommand[]` is authored in library-wide: the path says where
350
+ * the node is at `t`, not how far it has come from wherever the previous
351
+ * command left it.
352
+ *
353
+ * `target` is a node id and `targetAnchor` the point of its box to land on
354
+ * (centre when absent), resolved when the command is built — so moving the
355
+ * target re-aims the move with nothing to re-author, and a target absent at
356
+ * that moment leaves the node where it is. Like `path`, it replaces `x`/`y`.
357
+ * Given a `path` as well, the path is turned and scaled about its own start
358
+ * until its end lands on the target, which is exact where the two already
359
+ * agree and keeps the curve's shape where the target has since moved.
360
+ *
361
+ * @example
362
+ * node.moveTo({ data: { x: 200, y: 100, pivot: 'topRight' }, duration: 0.5 });
363
+ * node.moveTo({ data: { path: new PathBuilder().arc({ width: 600, startAngle: 180, sweep: -180 }) }, duration: 2 });
364
+ * node.moveTo({ data: { target: 'card', targetAnchor: 'topRight' }, duration: 1 });
365
+ */
366
+ moveTo(args) {
367
+ const { path, target, targetAnchor, ...destination } = args.data ?? {};
368
+ const positioned = destination.x !== undefined || destination.y !== undefined;
369
+ const aimed = typeof target === "string" && target !== "";
370
+ if (aimed && positioned) {
371
+ throw new Error("moveTo takes a `target` or an `x`/`y` destination, not both — the target's anchor is where the move ends.");
372
+ }
373
+ const aim = aimed ? this._pointOnNode(target, targetAnchor) : null;
374
+ if (path === undefined || path === null) {
375
+ return this.to({ data: { ...destination, ...aim }, duration: args.duration, easing: args.easing });
376
+ }
377
+ if (positioned) {
378
+ throw new Error("moveTo takes a `path` or an `x`/`y` destination, not both — the path's own end is where the move ends.");
379
+ }
380
+ const sampler = pathOps.sampler(path instanceof PathBuilder ? path.toCommands() : path);
381
+ const { length } = sampler;
382
+ const first = sampler.frameAt(0);
383
+ const last = sampler.frameAt(length);
384
+ const fit = aim && first && last ? pathOps.endFit(first, last, aim) : null;
385
+ const origin = destination.pivot;
386
+ return this.command((t) => {
387
+ const frame = sampler.frameAt(length * t);
388
+ // A degenerate path has no point to be at, so the move writes
389
+ // nothing rather than collapsing the node onto the origin.
390
+ if (!frame)
391
+ return {};
392
+ const point = fit ? fit(frame) : frame;
393
+ const at = { x: point.x, y: point.y };
394
+ if (origin !== undefined)
395
+ at.transformOrigin = origin;
396
+ return at;
397
+ }, args.duration, args.easing);
398
+ }
399
+ /** Animate `opacity` to the target value, in `[0, 1]`. */
400
+ fadeTo(args) {
401
+ return this.to({ data: args.data, duration: args.duration, easing: args.easing });
402
+ }
403
+ /**
404
+ * Animate `rotation` to the target angle (degrees, clockwise). `pivot`
405
+ * (optional) behaves as in {@link moveTo}.
406
+ *
407
+ * @example
408
+ * node.rotateTo({ data: { rotation: 180, pivot: 'topRight' }, duration: 0.6 });
409
+ */
410
+ rotateTo(args) {
411
+ return this.to({ data: args.data, duration: args.duration, easing: args.easing });
412
+ }
413
+ /**
414
+ * Animate `scale` to the target factor. `pivot` (optional) behaves as in
415
+ * {@link moveTo}.
416
+ *
417
+ * @example
418
+ * node.scaleTo({ data: { scale: 2, pivot: 'topRight' }, duration: 0.4 });
419
+ */
420
+ scaleTo(args) {
421
+ return this.to({ data: args.data, duration: args.duration, easing: args.easing });
422
+ }
423
+ /**
424
+ * Animate the box: `width`, `height` and `padding`, whichever are given.
425
+ * A size keyword (`'fill'`, `'hug'`) snaps; a number interpolates.
426
+ *
427
+ * @example
428
+ * node.layoutTo({ data: { width: 640, height: 360 }, duration: 0.5 });
429
+ */
430
+ layoutTo(args) {
431
+ return this.to({ data: _stated(args.data), duration: args.duration, easing: args.easing });
432
+ }
433
+ /**
434
+ * Swell to `factor` times the node's size and settle back: a nudge of the
435
+ * eye toward it. It ends as it began, so nothing after it needs restating.
436
+ *
437
+ * @example
438
+ * node.pulse({ data: { factor: 1.3 }, duration: 0.6 });
439
+ */
440
+ pulse(args) {
441
+ const rest = this.scale;
442
+ const factor = args.data?.factor ?? 1.2;
443
+ return this.command((t) => ({ scale: rest * (1 + (factor - 1) * Math.sin(Math.PI * t)) }), args.duration, args.easing);
444
+ }
445
+ /**
446
+ * Rock about the node's own turn, `angle` degrees each way for `turns`
447
+ * swings, building up and dying away. It ends as it began.
448
+ *
449
+ * @example
450
+ * node.wiggle({ data: { angle: 10, turns: 4 }, duration: 0.8 });
451
+ */
452
+ wiggle(args) {
453
+ const rest = this.rotation;
454
+ const angle = args.data?.angle ?? 8;
455
+ const turns = args.data?.turns ?? 3;
456
+ return this.command((t) => ({ rotation: rest + angle * Math.sin(2 * Math.PI * turns * t) * Math.sin(Math.PI * t) }), args.duration, args.easing);
457
+ }
458
+ /** Animate the `effects` stack to another one. */
459
+ effectTo(args) {
460
+ return this.to({ data: _stated(args.data), duration: args.duration, easing: args.easing });
461
+ }
462
+ // ---- Layout queries ---------------------------------------------------
463
+ get measuredWidth() {
464
+ return this.layoutBounds.width;
465
+ }
466
+ get measuredHeight() {
467
+ return this.layoutBounds.height;
468
+ }
469
+ // ---- Alignment points ----------------------------------------------------
470
+ // All getters read `layoutBounds` and the x/y/rotation props, and a bound prop
471
+ // recomputes on every read — so a callback built from them is always current.
472
+ /** Rotate offset (ox, oy) by this node's rotation (degrees clockwise) around the node center. */
473
+ _rotateOffset(ox, oy) {
474
+ const o = this._offset();
475
+ return rotateOffset(o.x, o.y, this.rotation, ox, oy);
476
+ }
477
+ /** Center of the node — equivalent to its x/y position (0,0 is the center of the layout cell). */
478
+ get center() {
479
+ const o = this._offset();
480
+ return { x: o.x, y: o.y };
481
+ }
482
+ get topLeft() {
483
+ const r = this.layoutBounds;
484
+ return this._rotateOffset(-r.width / 2, r.height / 2);
485
+ }
486
+ get topRight() {
487
+ const r = this.layoutBounds;
488
+ return this._rotateOffset(r.width / 2, r.height / 2);
489
+ }
490
+ get bottomLeft() {
491
+ const r = this.layoutBounds;
492
+ return this._rotateOffset(-r.width / 2, -r.height / 2);
493
+ }
494
+ get bottomRight() {
495
+ const r = this.layoutBounds;
496
+ return this._rotateOffset(r.width / 2, -r.height / 2);
497
+ }
498
+ get topCenter() {
499
+ const r = this.layoutBounds;
500
+ return this._rotateOffset(0, r.height / 2);
501
+ }
502
+ get bottomCenter() {
503
+ const r = this.layoutBounds;
504
+ return this._rotateOffset(0, -r.height / 2);
505
+ }
506
+ get centerLeft() {
507
+ const r = this.layoutBounds;
508
+ return this._rotateOffset(-r.width / 2, 0);
509
+ }
510
+ get centerRight() {
511
+ const r = this.layoutBounds;
512
+ return this._rotateOffset(r.width / 2, 0);
513
+ }
514
+ // ---- Global (world-space) transform -----------------------------------
515
+ // The local alignment getters above are relative to this node's *parent*; their
516
+ // global counterparts below fold in the full ancestor chain so a node can be
517
+ // aligned to another regardless of where each sits in the tree:
518
+ // new Rect({ x: () => other().global.x, y: () => other().global.y })
519
+ // Each read walks this node's and every ancestor's live
520
+ // layout/x/y/rotation/scale/pivot props, so a binding over them stays current.
521
+ /**
522
+ * This node's local transform in canvas (y-down) space — position, rotation,
523
+ * scale, about its origin. Composed with the parent chain by
524
+ * {@link worldMatrix}, and the matrix every world-space *reading* of the node
525
+ * comes from: {@link global}, `runtime/node-picking.ts`, and so any editor
526
+ * overlay drawn on top of a scene.
527
+ *
528
+ * **It is flat, deliberately, and the renderer's is not.** A node that
529
+ * mirrors or tilts ({@link Node2DProps.rotationX}, {@link Node2DProps.perspective},
530
+ * {@link Node2DProps.flipHorizontal}, …) is *painted* through a projected
531
+ * matrix, but goes on measuring, reporting and hit-testing as the upright
532
+ * rectangle it was — see {@link applyTransform}.
533
+ *
534
+ * That is a choice, not an oversight. Everything that reads a node's box
535
+ * reads it to put a handle on: a selection outline, a resize grip, a rotation
536
+ * dial, `other.global.topRight` as an alignment target. Those all mean
537
+ * something on a rectangle and stop meaning it on a trapezoid — a "width"
538
+ * handle on a foreshortened edge does not correspond to any number, and a
539
+ * corner that has swung behind the viewer has no screen position at all.
540
+ * Letting the projection through would make the tilt a thing that quietly
541
+ * breaks every other tool in the editor; keeping the geometry flat makes it
542
+ * exactly what it looks like, a way of drawing the node.
543
+ */
544
+ /** @internal Composed with the camera scopes in between by `runtime/node-picking.ts`. */
545
+ _localMatrix() {
546
+ const r = this.layoutBounds;
547
+ const slot = this._slotMatrix();
548
+ const { x: ox, y: oy } = this._offset();
549
+ if (slot) {
550
+ return multiply(slot, localMatrix(ox, -oy, this.rotation, this.scale, this._transformOrigin(), r?.width ?? 0, r?.height ?? 0));
551
+ }
552
+ const cx = (r?.x ?? 0) + ox;
553
+ const cy = (r?.y ?? 0) - oy;
554
+ // The accessor stores the resolved normalised pivot via the mapper.
555
+ // No projection: see the note above for why a node's *geometry* stays
556
+ // flat while its paint does not.
557
+ return localMatrix(cx, cy, this.rotation, this.scale, this._transformOrigin(), r?.width ?? 0, r?.height ?? 0);
558
+ }
559
+ /** @internal The slot {@link _placementOf} puts this node in, from its parent. */
560
+ _placement() {
561
+ return this.parent2D?._placementOf(this) ?? null;
562
+ }
563
+ /**
564
+ * The slot this node places `child` in beyond its layout box, or `null` —
565
+ * the default — when the box says it all. A layout that turns, scales or
566
+ * fades each of its children answers here, and the renderer, picking and
567
+ * `global` all follow. See {@link ChildPlacement}.
568
+ */
569
+ /** @internal */
570
+ _placementOf(_child) {
571
+ return null;
572
+ }
573
+ /**
574
+ * The coordinates `child`'s `x`/`y` are in, or `null` — the default — when
575
+ * they are pixels. A `null` child asks for one that is not here yet: where
576
+ * a host would drop or paste it. See {@link ChildPlane}.
577
+ */
578
+ /** @internal */
579
+ _planeOf(_child) {
580
+ return null;
581
+ }
582
+ /**
583
+ * Where its own layout would centre a child of `size` that is not here yet,
584
+ * y-down from its centre, or `null` when it arranges its children in a run
585
+ * or a grid (the run decides) or has not laid any out.
586
+ */
587
+ /** @internal */
588
+ _slotFor(size) {
589
+ const space = this._childSpace;
590
+ const box = space ? flowOps.freeSlot(space.settings, space.inner, size) : null;
591
+ return space && box ? { x: space.inner.x + box.x, y: space.inner.y - box.y } : null;
592
+ }
593
+ /**
594
+ * Where its centre sits from the point its `x`/`y` place, in its parent's
595
+ * frame, y-down, at `rotation` and `scale`: what turning or scaling about an
596
+ * off-centre pivot adds.
597
+ */
598
+ /** @internal */
599
+ _centreShift(rotation = this.rotation, scale = this.scale) {
600
+ const r = this.layoutBounds;
601
+ const own = localMatrix(0, 0, rotation, scale, this._transformOrigin(), r?.width ?? 0, r?.height ?? 0);
602
+ return applyToPoint(own, { x: 0, y: 0 });
603
+ }
604
+ /** The points an editor may drag on this node, where they sit now; none by default. See {@link NodeHandle}. */
605
+ /** @internal */
606
+ _handles() {
607
+ return NO_HANDLES;
608
+ }
609
+ /** The value `prop` takes for its handle to sit at `at`, in this node's own frame; `null` when it has none. */
610
+ /** @internal */
611
+ _handleValue(_prop, _at) {
612
+ return null;
613
+ }
614
+ _offsetScratch = { x: 0, y: 0 };
615
+ /**
616
+ * This node's `x`/`y` as the pixel offset its parent sees. Every position
617
+ * read goes through here, which is what keeps paint, picking and `global`
618
+ * agreeing under a {@link ChildPlane}. The result is reused: read it at once.
619
+ */
620
+ /** @internal */
621
+ _offset() {
622
+ const plane = this.parent2D?._planeOf(this);
623
+ if (plane)
624
+ return plane.toOffset(this.x, this.y);
625
+ const o = this._offsetScratch;
626
+ o.x = this.x;
627
+ o.y = this.y;
628
+ return o;
629
+ }
630
+ /**
631
+ * The flat part of this node's slot, as the frame its own `x`/`y` move in —
632
+ * the layout box's centre, turned and scaled by the slot. `null` when it has
633
+ * no slot. With `paint`, the slot's tilt as well, which only paint sees.
634
+ */
635
+ /** @internal Also the plane `runtime/node-picking.ts` drags a placed node across. */
636
+ _slotMatrix(paint = false) {
637
+ const slot = this._placement();
638
+ if (!slot)
639
+ return null;
640
+ const r = this.layoutBounds;
641
+ return localMatrix(r?.x ?? 0, r?.y ?? 0, slot.rotation, slot.scale, ORIGIN_2D, 0, 0, paint ? slotProjection(slot) : undefined);
642
+ }
643
+ /** @internal {@link _slotMatrix} in a space, where the slot's tilt and depth are geometry. */
644
+ _slotAffine() {
645
+ const slot = this._placement();
646
+ if (!slot)
647
+ return null;
648
+ const r = this.layoutBounds;
649
+ return nodeSpaceMatrix(r?.x ?? 0, r?.y ?? 0, slot.rotation, slot.scale, 0, 0, slotProjection(slot));
650
+ }
651
+ /**
652
+ * The point this node's transform turns about, normalised: `transformOrigin`
653
+ * where one is set, the alignment-derived `pivot` otherwise. One resolution,
654
+ * read by {@link _localMatrix} and {@link applyTransform} alike.
655
+ */
656
+ _transformOrigin() {
657
+ return this.transformOrigin ?? this.pivot;
658
+ }
659
+ // Reused for the same reason `_transformScratch` is: `_localMatrix` runs once
660
+ // per ancestor per `global` read, and the two functions that take a
661
+ // Projection3D read it synchronously and never retain it.
662
+ _projectionScratch = {
663
+ rotationX: 0, rotationY: 0, rotationZ: 0, depth: 0, perspective: 0,
664
+ flipHorizontal: false, flipVertical: false,
665
+ };
666
+ /**
667
+ * This node's out-of-plane fields, gathered for the matrix builders — and for
668
+ * the backface test. A space root overrides it, because its 3D props aim the
669
+ * camera rather than turn the root.
670
+ */
671
+ _projection() {
672
+ const p = this._projectionScratch;
673
+ p.rotationX = this.rotationX;
674
+ p.rotationY = this.rotationY;
675
+ p.rotationZ = this.rotationZ;
676
+ p.depth = this.depth;
677
+ p.perspective = this.perspective;
678
+ p.flipHorizontal = this.flipHorizontal;
679
+ p.flipVertical = this.flipVertical;
680
+ return p;
681
+ }
682
+ /** @internal This node's transform in its parent's 3D frame, when it is inside a space. See `node-space.ts`. */
683
+ _spaceMatrix() {
684
+ const r = this.layoutBounds;
685
+ const width = r?.width ?? 0;
686
+ const height = r?.height ?? 0;
687
+ const origin = this._transformOrigin();
688
+ const slot = this._slotAffine();
689
+ const { x: ox, y: oy } = this._offset();
690
+ if (slot) {
691
+ return multiplyAffine3(slot, nodeSpaceMatrix(ox, -oy, this.rotation, this.scale, origin.x * (width / 2), -origin.y * (height / 2), this._projection()));
692
+ }
693
+ return nodeSpaceMatrix((r?.x ?? 0) + ox, (r?.y ?? 0) - oy, this.rotation, this.scale, origin.x * (width / 2), -origin.y * (height / 2), this._projection());
694
+ }
695
+ /**
696
+ * This node's full transform in canvas (y-down) world space — the product of
697
+ * every ancestor's local matrix from the root down to this node. Walks the
698
+ * live parent chain on every call, reading each node's transform props.
699
+ */
700
+ worldMatrix() {
701
+ const local = this._localMatrix();
702
+ const parent = this.parent2D;
703
+ return parent ? multiply(parent.worldMatrix(), local) : local;
704
+ }
705
+ /**
706
+ * Resolved world-space transform — the same alignment points and metrics as the
707
+ * local getters (`center`, `topRight`, `rotation`, …) but folded through the
708
+ * full ancestor chain, so values are absolute scene coordinates rather than
709
+ * parent-relative ones. See {@link WorldTransform}. Every field is reactive.
710
+ *
711
+ * @example
712
+ * // Read another node's absolute corner, regardless of its parent:
713
+ * const p = other.global.topRight; // world-space {x, y}
714
+ *
715
+ * ### Reading vs. placing
716
+ * `global` is for *reading* world coordinates. `x`/`y` (and the alignment props)
717
+ * are **parent-relative**, so assigning a world value to them does not by
718
+ * itself place this node in world space — it offsets it from this node's own
719
+ * parent. To land exactly on another node regardless of either parent,
720
+ * subtract this node's parent's world contribution:
721
+ *
722
+ * @example
723
+ * // Place this node's origin exactly on `other`, any parent:
724
+ * new Rect({
725
+ * x: () => other.global.x - (myParent.global.x),
726
+ * y: () => other.global.y - (myParent.global.y),
727
+ * });
728
+ *
729
+ * When both nodes share the same parent origin (e.g. both at the scene root),
730
+ * `x: () => other.global.x` already lands on target with no compensation.
731
+ */
732
+ get global() {
733
+ const r = this.layoutBounds;
734
+ const anchors = worldAnchors(this.worldMatrix(), (r?.width ?? 0) / 2, (r?.height ?? 0) / 2);
735
+ // Accumulate ancestor rotation/scale/opacity up the chain (rotation sums,
736
+ // scale and opacity multiply — all match the renderer's nested transforms
737
+ // and its pass-through alpha fold).
738
+ let rotation = 0;
739
+ let scale = 1;
740
+ let opacity = 1;
741
+ for (let n = this; n; n = n.parent2D) {
742
+ const slot = n._placement();
743
+ rotation += n.rotation + (slot?.rotation ?? 0);
744
+ scale *= n.scale * (slot?.scale ?? 1);
745
+ opacity *= n.opacity * (slot?.opacity ?? 1);
746
+ }
747
+ return {
748
+ x: anchors.center.x,
749
+ y: anchors.center.y,
750
+ ...anchors,
751
+ rotation,
752
+ scale,
753
+ opacity,
754
+ };
755
+ }
756
+ /**
757
+ * The `x`/`y` that put this node on `anchor` of the node `id` names, in this
758
+ * tree — or `null` when there is no such 2D node here right now.
759
+ */
760
+ _pointOnNode(id, anchor) {
761
+ const target = findNode2D(this, id);
762
+ if (!target)
763
+ return null;
764
+ const a = alignmentOps.resolve(anchor ?? "center");
765
+ const box = target.layoutBounds;
766
+ const world = applyToPoint(target.worldMatrix(), {
767
+ x: a.x * ((box?.width ?? 0) / 2),
768
+ y: -a.y * ((box?.height ?? 0) / 2),
769
+ });
770
+ const parent = this.parent2D;
771
+ const toParent = parent ? invert(parent.worldMatrix()) : null;
772
+ if (parent && !toParent)
773
+ return null;
774
+ const local = toParent ? applyToPoint(toParent, world) : world;
775
+ const own = this.layoutBounds;
776
+ const x = local.x - (own?.x ?? 0);
777
+ const y = (own?.y ?? 0) - local.y;
778
+ return parent?._planeOf(this)?.toCoords(x, y) ?? { x, y };
779
+ }
780
+ addChildAt(args) {
781
+ const { child, index } = args.data;
782
+ this.assertAcceptsChild(child);
783
+ if (args.duration === undefined) {
784
+ this._insertChildAt(child, index);
785
+ return;
786
+ }
787
+ // Past the guard, so this is a 2D child: the animated insert measures it
788
+ // off-tree, which only a laid-out node can do.
789
+ return addChildAtAnimated(this, child, index, args.duration, args.easing);
790
+ }
791
+ removeChildAt(args) {
792
+ const index = args.data.index;
793
+ if (args.duration === undefined) {
794
+ if (index < 0 || index >= this._children.length)
795
+ return null;
796
+ if (_observer !== null)
797
+ this._structureChanged(this._children[index]);
798
+ const [removed] = this._children.splice(index, 1);
799
+ if (removed) {
800
+ removed._parent = null;
801
+ removed.detach();
802
+ }
803
+ return removed ?? null;
804
+ }
805
+ return removeChildAtAnimated(this, index, args.duration, args.easing);
806
+ }
807
+ // ---- Rendering --------------------------------------------------------
808
+ // Reused each frame so applyTransform doesn't allocate a fresh descriptor
809
+ // per node per frame. ctx.transform reads it synchronously and never retains
810
+ // it, so a single mutated instance is safe.
811
+ _transformScratch = {
812
+ x: 0, y: 0, width: 0, height: 0,
813
+ scale: 1, rotation: 0, opacity: 1, blend: 'pass-through',
814
+ effects: [], pivot: { x: 0, y: 0 },
815
+ };
816
+ // ---- Motion sampling --------------------------------------------------
817
+ // Per-node motion (velocity/direction/speed/angular/scale) is sampled once
818
+ // per frame from ellapse() (see its call site) as a backward difference
819
+ // against the previous frame. Sampling every advanced frame — not just
820
+ // rendered ones — is what keeps velocity correct through a scrub/rewind,
821
+ // which advances through frames without rendering them. Because ellapse()
822
+ // runs before the frame's generator.next(), x/y here hold the *previous*
823
+ // frame's value, so the velocity trails the rendered position by one frame;
824
+ // the lag is constant and identical forward vs. scrub. Layout-dependent
825
+ // fields (rects) can't be resolved here — layout hasn't run for advanced-
826
+ // but-unrendered frames — so renderState() fills those in at draw time,
827
+ // leaving the motion fields untouched.
828
+ /** Rolling history for the backward-difference velocity estimate. Allocated once (not per frame); mutated in place by {@link _sampleMotion}. */
829
+ _motionHistory = createMotionHistory();
830
+ /** Reused per-node state handed to `ctx.begin()` (mirrors `_transformScratch`). */
831
+ _renderState = {
832
+ id: this.id,
833
+ rects: {},
834
+ elapsed: 0,
835
+ dt: 0,
836
+ velocity: { x: 0, y: 0 },
837
+ direction: 0,
838
+ speed: 0,
839
+ angularVelocity: 0,
840
+ scaleVelocity: 0,
841
+ };
842
+ /**
843
+ * Compute this frame's motion (velocity/direction/speed/angular/scale) into
844
+ * {@link _renderState} as a backward difference against the previous frame,
845
+ * and roll the history forward. Velocity is `0`/`{0,0}` when no trustworthy
846
+ * delta exists — the first frame, or after a non-monotonic time jump (only
847
+ * `0 < dt <= MAX` is trusted, so a scrub that resets the clock reads as
848
+ * "unknown" rather than a spurious huge velocity). The world position
849
+ * matches {@link applyTransform} (`layoutBounds + x`, `layoutBounds - y`,
850
+ * y-down). Called via {@link _sample} every frame; layout-dependent fields
851
+ * (`rects`/`elapsed`) are filled in by {@link renderState} at draw time.
852
+ */
853
+ _sampleMotion() {
854
+ // Resolve the reactive world position (y-down, matching applyTransform);
855
+ // the backward-difference math lives in sampleMotion (no per-frame alloc).
856
+ const r = this.layoutBounds;
857
+ const o = this._offset();
858
+ const x = (r?.x ?? 0) + o.x;
859
+ const y = (r?.y ?? 0) - o.y;
860
+ sampleMotion(this._renderState, this._motionHistory, x, y, this.rotation, this.scale, this._time.total);
861
+ }
862
+ /**
863
+ * Push this node's transform (position, scale, rotate, opacity, effects).
864
+ *
865
+ * The decomposed fields are the whole story for a node in its own plane, and
866
+ * that path is untouched: the backend translates, rotates and scales exactly
867
+ * as it always has. A node that mirrors or tilts hands over a precomposed
868
+ * {@link TransformState.matrix} instead, built by the same `localMatrix`
869
+ * {@link _localMatrix} calls — with the out-of-plane half switched on.
870
+ *
871
+ * **This is the one place that half is applied.** The mirrors and the tilt
872
+ * are paint, not geometry: the node goes on measuring and hit-testing as the
873
+ * upright rectangle it was, and only what is drawn is projected. See
874
+ * {@link _localMatrix} for why.
875
+ */
876
+ applyTransform(ctx) {
877
+ const r = this.layoutBounds;
878
+ const s = this._transformScratch;
879
+ const { x: ox, y: oy } = this._offset();
880
+ s.x = (r?.x ?? 0) + ox;
881
+ s.y = (r?.y ?? 0) - oy;
882
+ s.width = r?.width ?? 0;
883
+ s.height = r?.height ?? 0;
884
+ s.scale = this.scale;
885
+ s.rotation = this.rotation;
886
+ s.opacity = this.opacity;
887
+ s.blend = this.blend;
888
+ s.effects = this.effects;
889
+ s.pivot = this._transformOrigin();
890
+ const slotOpacity = this._placement()?.opacity;
891
+ if (slotOpacity !== undefined)
892
+ s.opacity *= slotOpacity;
893
+ const frame = this._spaceFrame;
894
+ const slot = frame ? null : this._slotMatrix(true);
895
+ if (frame) {
896
+ s.matrix = frame.local;
897
+ }
898
+ else if (slot) {
899
+ s.matrix = multiply(slot, localMatrix(ox, -oy, s.rotation, s.scale, s.pivot, s.width, s.height, this._projection()));
900
+ }
901
+ else {
902
+ const projection = this._projection();
903
+ s.matrix = hasProjection3D(projection)
904
+ ? localMatrix(s.x, s.y, s.rotation, s.scale, s.pivot, s.width, s.height, projection)
905
+ : undefined;
906
+ }
907
+ ctx.transform(s);
908
+ }
909
+ /** What the node paints under its children, between the transform push and the children render: the root's fill. */
910
+ renderSelf(ctx) { }
911
+ /** What the node paints over its children, clipped to its silhouette: the root's overlay. */
912
+ renderOverlay(ctx) { }
913
+ /**
914
+ * This node's outline as a {@link Clip}: the boundary `clip` confines its
915
+ * children to, and the silhouette its backdrop effects are confined to.
916
+ * `null` (the default) is no outline, so its children render unclipped and
917
+ * it gets no backdrop effects. A component answers with the shape its
918
+ * `render` paints.
919
+ */
920
+ clipSelf() { return null; }
921
+ /**
922
+ * The camera scope this node pushes around its **children** (`beginCamera`),
923
+ * or `null` when it pushes none. Only {@link Canvas2D} and a component whose
924
+ * `render` opens a camera answer, each non-null exactly when it actually
925
+ * opens one — so a consumer can reproduce the renderer's transform *and* its
926
+ * viewport clip without knowing which types have a camera.
927
+ *
928
+ * Read by `runtime/node-picking.ts`: a camera is applied at render time only,
929
+ * so it is not part of {@link worldMatrix}, and a node's on-screen box would
930
+ * be offset without it. `@internal`.
931
+ */
932
+ /** @internal */
933
+ _cameraScope() { return null; }
934
+ /**
935
+ * The camera this node opens a 2.5D space with, or `null` when it opens none.
936
+ * Only a space root overrides it: its children, and theirs, are then placed
937
+ * in one 3D frame and seen through this camera. See `node-space.ts`.
938
+ */
939
+ /** @internal */
940
+ _spaceCamera() { return null; }
941
+ /**
942
+ * Whether this node hands its children on into the space it sits in. False
943
+ * for a node that composites its children itself — a mask, a boolean, a
944
+ * nested camera — which flattens its subtree into its own plane, where the
945
+ * per-node 3D rules apply again. Picking reads it; the renderer gets the same
946
+ * answer because such a node never reaches the base {@link renderChildren}.
947
+ */
948
+ /** @internal */
949
+ _rendersChildrenInSpace() { return true; }
950
+ /** @internal Set by the parent for the length of this node's render while it is inside a space. */
951
+ _spaceFrame = null;
952
+ /**
953
+ * Whether the renderer confines this node's children to its own box — either
954
+ * because `clip` is set *and* the node has an outline to clip to (a bare
955
+ * `clip` with no {@link clipSelf} is a no-op, see {@link applyClip}), or
956
+ * because it opens a camera scope, which clips to the viewport rect.
957
+ *
958
+ * Read by `runtime/node-picking.ts`: a point outside a confining node cannot
959
+ * hit anything inside it, so the whole subtree is skipped. `@internal`.
960
+ */
961
+ /** @internal */
962
+ _confinesChildren() {
963
+ if (this._cameraScope() !== null)
964
+ return true;
965
+ if (!this.clip)
966
+ return false;
967
+ const clip = this.clipSelf();
968
+ return clip !== null && !clip.isEmpty();
969
+ }
970
+ /**
971
+ * Whether `local` — a point in this node's local space (centred on the node,
972
+ * y-up, rotation and scale already removed) — is inside the node, within
973
+ * `tolerance` scene units of its edge.
974
+ *
975
+ * The default is the layout box, which is the right answer for containers,
976
+ * text, and media: their box *is* their extent. A component narrows it to
977
+ * the outline its `render` paints.
978
+ *
979
+ * `tolerance` is grab-slop, applied outward. An editor passes its
980
+ * zoom-corrected pixel slop so the grab area stays constant on screen
981
+ * regardless of preview zoom.
982
+ */
983
+ hitTestSelf(local, tolerance) {
984
+ const b = this._localBounds();
985
+ return Math.abs(local.x - b.x) <= b.width / 2 + tolerance
986
+ && Math.abs(local.y - b.y) <= b.height / 2 + tolerance;
987
+ }
988
+ /**
989
+ * The extent of this node's ink in its own local space — what an editor draws
990
+ * a selection box around, and the region the default {@link hitTestSelf}
991
+ * grabs.
992
+ *
993
+ * The returned {@link BoxBounds} is **y-up and relative to the node's own
994
+ * centre**: `x`/`y` are where the ink's centre sits relative to the node,
995
+ * normally `(0, 0)`. That is a different space from `layoutBounds`, which is
996
+ * the same type but canvas y-down and relative to the parent — see
997
+ * `BoxBounds`, which deliberately does not encode a space.
998
+ *
999
+ * Defaults to the layout box, centred on the node, which is right for every
1000
+ * node whose drawing fills its cell. It is a separate seam from the layout
1001
+ * rect because for some nodes the two genuinely differ: a boolean group or
1002
+ * a mask is drawn where its children's ink is, which can be both a different
1003
+ * size *and* off-centre from its own cell. A component's `bounds` answers
1004
+ * here, fixing the box and the grab region together without perturbing layout.
1005
+ */
1006
+ /** @internal */
1007
+ _localBounds() {
1008
+ return { x: 0, y: 0, width: this.measuredWidth, height: this.measuredHeight };
1009
+ }
1010
+ /** @internal Dispatch seam so `node-picking.ts` can reach the protected override. */
1011
+ _hitTestSelf(local, tolerance) {
1012
+ return this.hitTestSelf(local, tolerance);
1013
+ }
1014
+ /**
1015
+ * Open `clipSelf()`'s outline as a clip scope, confining whatever is drawn
1016
+ * until the matching `ctx.endClip()` to the shape. Returns `true` when a
1017
+ * clip was actually opened (so the caller knows to close it) and `false`
1018
+ * when the node has no outline (the default).
1019
+ */
1020
+ applyClip(ctx) {
1021
+ const clip = this.clipSelf();
1022
+ if (!clip || clip.isEmpty())
1023
+ return false;
1024
+ ctx.beginClip(clip);
1025
+ return true;
1026
+ }
1027
+ /**
1028
+ * Apply backdrop effects (any `mode: "backdrop"` effect — blur, grayscale, …;
1029
+ * plus magnify and backdrop SkSL) beneath this node, clipped to its
1030
+ * silhouette, before the node's own content is drawn — so the content
1031
+ * underneath is filtered/warped while the node's own edges stay sharp. One
1032
+ * backdrop effect scope, confined to the silhouette clip, runs the lot; the
1033
+ * renderer routes each effect to a filter or shader pass. A no-op for nodes
1034
+ * without a {@link clipSelf} outline (there's no silhouette to confine to).
1035
+ */
1036
+ applyBackdropEffects(ctx) {
1037
+ const effects = this.effects;
1038
+ // Bail before building the silhouette. `applyBackdropEffectsImpl` returns
1039
+ // immediately when there are no backdrop effects, but by then `clipSelf()`
1040
+ // has already allocated a Clip and its op list for a node that will never
1041
+ // use it — and a node with no effects at all is the overwhelmingly common
1042
+ // case, so that allocation was pure waste on nearly every node, every frame.
1043
+ if (effects.length === 0)
1044
+ return;
1045
+ applyBackdropEffectsImpl(ctx, effects, this.clipSelf(), this.layoutBounds?.width ?? 0, this.layoutBounds?.height ?? 0);
1046
+ }
1047
+ /**
1048
+ * Run `body` (this node's own painting + children) inside the node's effect
1049
+ * scopes, so effects behave identically however a node draws. The caller
1050
+ * has already pushed the node's transform ({@link applyTransform}).
1051
+ * Outermost-first: {@link applyBackdropEffects} beneath the node, confined
1052
+ * to its {@link clipSelf} silhouette, then a `foreground` effect scope
1053
+ * capturing everything `body` paints.
1054
+ */
1055
+ renderContentWithEffects(ctx, body) {
1056
+ this.applyBackdropEffects(ctx);
1057
+ applyContentEffectScope(ctx, this.effects, this.layoutBounds?.width ?? 0, this.layoutBounds?.height ?? 0, body);
1058
+ }
1059
+ renderChildren(ctx) {
1060
+ // A node opening a space of its own flattens its subtree into its own
1061
+ // plane, whatever space it sits in — the same answer picking's
1062
+ // `spaceFrameOf` gives, which asks for a camera before anything else.
1063
+ const camera = this._spaceCamera();
1064
+ if (camera) {
1065
+ this._renderInSpace(ctx, spaceRootFrame(this, camera));
1066
+ return;
1067
+ }
1068
+ const frame = this._spaceFrame;
1069
+ if (frame) {
1070
+ this._renderInSpace(ctx, frame);
1071
+ return;
1072
+ }
1073
+ for (const child of this._children)
1074
+ if (child instanceof Node2D)
1075
+ child.render(ctx);
1076
+ }
1077
+ /**
1078
+ * Paint the children placed in `frame`, far to near rather than in authored
1079
+ * order — each with its frame set for exactly the length of its own render,
1080
+ * so a node reached any other way (a mask's children, a `Tex.surface`
1081
+ * source) draws flat.
1082
+ */
1083
+ /** @internal A space root opens its space through this. */
1084
+ _renderInSpace(ctx, frame) {
1085
+ const children = [];
1086
+ for (const child of this._children)
1087
+ if (child instanceof Node2D)
1088
+ children.push(child);
1089
+ const frames = children.map((child) => spaceChildFrame(frame, child));
1090
+ // Order is invisible to a walk that only discovers assets.
1091
+ const order = ctx.drawsVisibleOnly ? spaceChildOrder(frames) : frames.map((_, i) => i);
1092
+ for (const i of order) {
1093
+ const child = children[i];
1094
+ child._spaceFrame = frames[i];
1095
+ try {
1096
+ child.render(ctx);
1097
+ }
1098
+ finally {
1099
+ child._spaceFrame = null;
1100
+ }
1101
+ }
1102
+ }
1103
+ /** Run `paint` confined to `cut` — the part of the node in front of the lens — when there is one. */
1104
+ _paintInFront(ctx, cut, paint) {
1105
+ if (!cut) {
1106
+ paint();
1107
+ return;
1108
+ }
1109
+ ctx.beginClip(cut);
1110
+ try {
1111
+ paint();
1112
+ }
1113
+ finally {
1114
+ ctx.endClip();
1115
+ }
1116
+ }
1117
+ /**
1118
+ * This node's per-frame render state, resolved for the scope {@link render}
1119
+ * is about to open.
1120
+ *
1121
+ * Motion was already sampled when the clock advanced; only the
1122
+ * layout-dependent fields are filled in here, where layout is current.
1123
+ */
1124
+ renderState(ctx) {
1125
+ const s = this._renderState;
1126
+ // Skipped for contexts that never resolve a `space:'parent'` fill — the
1127
+ // precomp pass walks every node's render every frame purely to discover
1128
+ // assets, and this is an object allocation per node per frame that nothing
1129
+ // there would ever read.
1130
+ s.rects = ctx.readsSpaceRects ? this._spaceRects() : NO_SPACE_RECTS;
1131
+ s.elapsed = this._time.elapsed;
1132
+ return s;
1133
+ }
1134
+ /**
1135
+ * Reference rects for fills with `space:'parent'`, expressed in this node's
1136
+ * local space (origin = this node's positioned centre, y-down to match the
1137
+ * canvas). The viewport (`space:'global'`) is resolved by the renderer, which
1138
+ * knows the surface size. Rotation/scale of this node are not folded in —
1139
+ * the rect is the axis-aligned parent box, which is what gradients expect.
1140
+ */
1141
+ _spaceRects() {
1142
+ const o = this._offset();
1143
+ return computeSpaceRects(this.parent2D?.layoutBounds, this.layoutBounds, o.x, o.y);
1144
+ }
1145
+ /**
1146
+ * Draw this node and its subtree: the skip checks, then this node's draw
1147
+ * scope around {@link renderContent}.
1148
+ *
1149
+ * Takes a {@link RenderPass2D} rather than a bare {@link RenderContext2D}
1150
+ * because opening this node's draw scope is *this* method's job; what it
1151
+ * calls is handed the narrower surface, so nothing below can open one.
1152
+ */
1153
+ render(ctx) {
1154
+ // Not in the tree ⇒ no box, no surface, nothing to draw.
1155
+ if (!this.mounted)
1156
+ return;
1157
+ // A subtree at zero opacity paints nothing, so on a context that only
1158
+ // draws what can be seen there is no reason to walk it. Not a niche case:
1159
+ // a chart carries a full second axis at `opacity: 0` purely to reserve a
1160
+ // gutter, and every cross-fade spends its first and last frames here.
1161
+ //
1162
+ // `drawsVisibleOnly` is false on the tracking walk, which must still
1163
+ // descend — an invisible node's font and images have to be discovered or
1164
+ // they will not have loaded by the time it fades in. See the flag's doc.
1165
+ if (ctx.drawsVisibleOnly && this.opacity * (this._placement()?.opacity ?? 1) <= 0)
1166
+ return;
1167
+ // Hidden by the editor. Same exemption as the two checks around it: the
1168
+ // tracking walk still descends, or a node hidden and shown again would
1169
+ // come back before its fonts and images had been discovered.
1170
+ if (ctx.drawsVisibleOnly && this.hidden)
1171
+ return;
1172
+ // A node that has turned past edge-on and declines to show its back
1173
+ // paints nothing either — same reasoning, same walk skipped, and the same
1174
+ // exemption for the tracking pass, which still has to discover the assets
1175
+ // of a card that is currently face-down and will be face-up in a moment.
1176
+ // In a space the camera decides which way a node faces, not its own tilt.
1177
+ const frame = this._spaceFrame;
1178
+ if (ctx.drawsVisibleOnly && !this.backfaceVisible && this._facesAway(frame))
1179
+ return;
1180
+ // Edge-on or behind the lens, a node whose children lie in its own plane
1181
+ // has nothing anywhere to show.
1182
+ if (ctx.drawsVisibleOnly && frame && !frame.paints && !this._rendersChildrenInSpace())
1183
+ return;
1184
+ try {
1185
+ ctx.begin(this.renderState(ctx));
1186
+ try {
1187
+ this.renderContent(ctx);
1188
+ }
1189
+ finally {
1190
+ ctx.end();
1191
+ }
1192
+ }
1193
+ catch (error) {
1194
+ // The innermost node claims it, so the runtime can learn the segment against the node that drew.
1195
+ if (error instanceof AssetNotLoadedError)
1196
+ error.nodeId ??= this.id;
1197
+ throw error;
1198
+ }
1199
+ }
1200
+ /**
1201
+ * Everything this node paints: its transform, its effect envelope, its own
1202
+ * drawing, its children and its overlay. A component's `render` replaces it,
1203
+ * keeping every guard {@link render} performs above it.
1204
+ */
1205
+ renderContent(ctx) {
1206
+ this.applyTransform(ctx);
1207
+ const frame = this._spaceFrame;
1208
+ // Edge-on or behind the lens: nothing of its own to draw and no plane to
1209
+ // draw it on, but its children are placed by frames of their own.
1210
+ if (frame && !frame.paints) {
1211
+ this.renderChildren(ctx);
1212
+ return;
1213
+ }
1214
+ const cut = frame?.nearCut ?? null;
1215
+ this.renderContentWithEffects(ctx, () => {
1216
+ this._paintInFront(ctx, cut, () => this.renderSelf(ctx));
1217
+ // Confine children to this node's outline. Built once from clipSelf();
1218
+ // skipped when the node has no outline (clipped === false) so the
1219
+ // endClip() below stays balanced.
1220
+ const clipped = this.clip && this.applyClip(ctx);
1221
+ this.renderChildren(ctx);
1222
+ if (clipped)
1223
+ ctx.endClip();
1224
+ this._paintInFront(ctx, cut, () => this.renderOverlay(ctx));
1225
+ });
1226
+ }
1227
+ /** Whether the node shows its back — to the space's camera when it is in one, else by its own tilt. */
1228
+ _facesAway(frame) {
1229
+ if (frame)
1230
+ return frame.facesAway;
1231
+ const p = this._projection();
1232
+ return facesAway(p.rotationX, p.rotationY);
1233
+ }
1234
+ // ---- Layout -----------------------------------------------------------
1235
+ /** What {@link measure} hands {@link layoutChildren} within a pass; consumed there. */
1236
+ _flowMeasure = null;
1237
+ /**
1238
+ * The content box its children were last placed in, y-down from this
1239
+ * node's centre, and the flow that placed them: what {@link _slotFor}
1240
+ * answers from. A component's flow layout records it too (`Flow.layout`).
1241
+ */
1242
+ /** @internal */
1243
+ _childSpace = null;
1244
+ _flowWarned = false;
1245
+ /**
1246
+ * Record this node's allocated bounds without touching children.
1247
+ *
1248
+ * Compared field by field, because every caller builds a fresh object literal,
1249
+ * so identity always differs — including on every frame of a node that is
1250
+ * simply sitting still. Skipping the write keeps the object stable for the
1251
+ * aliasing reason below.
1252
+ */
1253
+ setLayoutBounds(rect) {
1254
+ const current = this._layoutBounds.get();
1255
+ if (current.x === rect.x
1256
+ && current.y === rect.y
1257
+ && current.width === rect.width
1258
+ && current.height === rect.height)
1259
+ return;
1260
+ // Stores the *new* object rather than mutating the old one in place:
1261
+ // `layoutBounds` is handed out by `get()` to its public reader, to
1262
+ // `computeSpaceRects` and to bound anchor computations, and mutating it
1263
+ // under them would be an aliasing change none of them could see coming.
1264
+ this._layoutBounds.set(rect);
1265
+ }
1266
+ /**
1267
+ * The children this node lays out itself — its 2D children, minus the hidden
1268
+ * ones. Every measure and layout pass in a container iterates *this*, not
1269
+ * `children`.
1270
+ *
1271
+ * Returns the live array untouched in the common case, so an ordinary tree
1272
+ * allocates nothing per pass.
1273
+ */
1274
+ flowChildren() {
1275
+ const children = this._children;
1276
+ // Only a hidden child — or a 3D child under a `Canvas3D` — can leave the
1277
+ // flow, and both are rare enough to be worth checking for before
1278
+ // allocating.
1279
+ let i = 0;
1280
+ for (; i < children.length; i++) {
1281
+ const child = children[i];
1282
+ if (!(child instanceof Node2D) || child.hidden)
1283
+ break;
1284
+ }
1285
+ if (i === children.length)
1286
+ return children;
1287
+ // A hidden child gives up its cell *and* its gap — `display: none`, not
1288
+ // `visibility: hidden`. Leaving the slot would put a hole in a row
1289
+ // wherever someone folded a layer away.
1290
+ return children.filter((c) => c instanceof Node2D && !c.hidden);
1291
+ }
1292
+ /**
1293
+ * The inset children are laid out within. A node with a stroke to clear adds
1294
+ * the part of it that intrudes (see `Paint.inset`).
1295
+ */
1296
+ effectivePadding() {
1297
+ return this.padding;
1298
+ }
1299
+ /**
1300
+ * How this node arranges its children: centred freeform. The root answers
1301
+ * with its own layout props; a component lays its children out with `Flow`.
1302
+ */
1303
+ flowArrangement() {
1304
+ return DEFAULT_FLOW;
1305
+ }
1306
+ /** Record `rect`, then place the flow children in it — see {@link layoutChildren}. */
1307
+ layout(rect, scope) {
1308
+ this.setLayoutBounds(rect);
1309
+ this.layoutChildren(rect, scope);
1310
+ }
1311
+ /**
1312
+ * Place the flow children in `rect`'s content box by {@link flowArrangement}.
1313
+ *
1314
+ * Reuses what {@link measure} found when the box is the one it measured in —
1315
+ * or, on an axis that hugs, exactly what it hugged — and measures again
1316
+ * otherwise: a parent laying this node out at a size it did not measure it
1317
+ * for would leave the children arranged for the wrong box.
1318
+ */
1319
+ layoutChildren(rect, scope) {
1320
+ const pending = this._flowMeasure;
1321
+ this._flowMeasure = null;
1322
+ const inner = insetsOps.insetBounds(rect.width, rect.height, this.effectivePadding());
1323
+ const settings = this.flowArrangement();
1324
+ this._childSpace = { settings, inner };
1325
+ const children = this.flowChildren();
1326
+ if (children.length === 0)
1327
+ return;
1328
+ const measured = pending && flowOps.reusable(pending, inner)
1329
+ ? pending
1330
+ : flowOps.measure(settings, children, {
1331
+ width: inner.width,
1332
+ height: inner.height,
1333
+ hugWidth: this.width === "hug",
1334
+ hugHeight: this.height === "hug",
1335
+ }, scope);
1336
+ // The boxes are y-up from the content box's centre; a layout rect is y-down
1337
+ // from this node's.
1338
+ const boxes = flowOps.place(measured, settings, inner);
1339
+ for (let i = 0; i < boxes.length; i++) {
1340
+ const box = boxes[i];
1341
+ measured.items[i].layout({ x: inner.x + box.x, y: inner.y - box.y, width: box.width, height: box.height }, scope);
1342
+ }
1343
+ if (this._flowWarned)
1344
+ return;
1345
+ const warning = flowOps.collapsedRun(measured, rect);
1346
+ if (warning === null)
1347
+ return;
1348
+ this._flowWarned = true;
1349
+ console.warn(`[motionscript] "${this.className}" ${warning}`);
1350
+ }
1351
+ /**
1352
+ * Resolve `width`/`height`, measuring the flow children by
1353
+ * {@link flowArrangement}: a `'hug'` axis wraps what they come to, plus this
1354
+ * node's padding. What it finds is kept for {@link layoutChildren}.
1355
+ *
1356
+ * Only flow children are measured: a canvas-pinned child is sized against the
1357
+ * canvas, so hugging it would shrink-wrap a box this node never contains.
1358
+ */
1359
+ measure(constraints, scope) {
1360
+ this.lastMeasure = { constraints, measurer: scope };
1361
+ const padding = this.effectivePadding();
1362
+ const children = this.flowChildren();
1363
+ if (children.length === 0) {
1364
+ this._flowMeasure = null;
1365
+ return flowOps.size(this, constraints, padding, NO_CONTENT);
1366
+ }
1367
+ const space = flowOps.contentBox(this, constraints, padding);
1368
+ const measured = flowOps.measure(this.flowArrangement(), children, space, scope);
1369
+ this._flowMeasure = measured;
1370
+ return flowOps.size(this, constraints, padding, measured.hug);
1371
+ }
1372
+ reparent(args) {
1373
+ const newParent = args.data.newParent;
1374
+ if (args.duration === undefined) {
1375
+ const old = this.parent;
1376
+ if (old)
1377
+ old.remove(this);
1378
+ newParent.add(this);
1379
+ return;
1380
+ }
1381
+ return reparentAnimated(this, newParent, args.duration, args.easing);
1382
+ }
1383
+ }
1384
+ declareMembers(Node2D, {
1385
+ x: property({ default: 0 }),
1386
+ y: property({ default: 0 }),
1387
+ width: property({ default: 'fill', tween: sizeInputOps.lerp }),
1388
+ height: property({ default: 'fill', tween: sizeInputOps.lerp }),
1389
+ scale: property({ default: 1 }),
1390
+ rotation: property({ default: 0 }),
1391
+ opacity: property({ default: 1 }),
1392
+ blend: property({ default: 'pass-through' }),
1393
+ effects: effectsProperty(),
1394
+ padding: insetsProperty(),
1395
+ pivot: alignmentProperty(),
1396
+ flipHorizontal: property({ default: false }),
1397
+ flipVertical: property({ default: false }),
1398
+ rotationX: property({ default: 0 }),
1399
+ rotationY: property({ default: 0 }),
1400
+ rotationZ: property({ default: 0 }),
1401
+ depth: property({ default: 0 }),
1402
+ perspective: property({ default: 0, tween: lerpPerspective }),
1403
+ backfaceVisible: property({ default: true }),
1404
+ transformOrigin: property({
1405
+ default: undefined,
1406
+ // `null` is unset too: a document read back from JSON has no `undefined`.
1407
+ mapper: (v) => (v == null ? undefined : alignmentOps.resolve(v)),
1408
+ // Tweening *into* an origin from "no origin set" starts where it ends —
1409
+ // there is no point to travel from, and snapping to the target's own
1410
+ // start is the one reading that isn't an invented one.
1411
+ tween: (from, to, t) => alignmentOps.lerp(from ?? to ?? ORIGIN_2D, to ?? ORIGIN_2D, t),
1412
+ }),
1413
+ clip: property({ default: false }),
1414
+ flex: property({ default: 1 }),
1415
+ gapScale: property({ default: 1 }),
1416
+ column: property({ default: undefined }),
1417
+ row: property({ default: undefined }),
1418
+ colSpan: property({ default: 1 }),
1419
+ rowSpan: property({ default: 1 }),
1420
+ moveTo: command({
1421
+ args: [
1422
+ "x",
1423
+ "y",
1424
+ { key: "path", kind: "path" },
1425
+ { key: "target", kind: "nodeRef" },
1426
+ { key: "targetAnchor", kind: "alignment" },
1427
+ ],
1428
+ }),
1429
+ fadeTo: command({ args: ["opacity"] }),
1430
+ rotateTo: command({ args: ["rotation"] }),
1431
+ scaleTo: command({ args: ["scale"] }),
1432
+ layoutTo: command({ args: [{ key: "width", kind: "size" }, { key: "height", kind: "size" }, { key: "padding", kind: "insets" }] }),
1433
+ pulse: command({ args: [{ key: "factor", kind: "number", min: 0, step: 0.05, unit: "×", default: 1.2 }] }),
1434
+ wiggle: command({
1435
+ args: [
1436
+ { key: "angle", kind: "number", min: 0, unit: "°", default: 8 },
1437
+ { key: "turns", kind: "number", min: 1, step: 1, default: 3 },
1438
+ ],
1439
+ }),
1440
+ effectTo: command({ args: [{ key: "effects", kind: "effects" }] }),
1441
+ removeChildAt: command({ args: ["index"] }),
1442
+ reparent: command({ args: ["newParent"] }),
1443
+ });
1444
+ /** A command's `data` without the arguments a document left out, which arrive as `undefined` and must not be tweened to. */
1445
+ function _stated(data) {
1446
+ const stated = {};
1447
+ for (const key in data) {
1448
+ if (data[key] !== undefined)
1449
+ stated[key] = data[key];
1450
+ }
1451
+ return stated;
1452
+ }
1453
+ /** The 2D node `id` names anywhere in the tree `from` is in, or `null`. */
1454
+ export function findNode2D(from, id) {
1455
+ let root = from;
1456
+ while (root.parent)
1457
+ root = root.parent;
1458
+ return findUnder(root, id);
1459
+ }
1460
+ function findUnder(at, id) {
1461
+ if (at.id === id)
1462
+ return at instanceof Node2D ? at : null;
1463
+ for (const child of at._allChildren) {
1464
+ const found = findUnder(child, id);
1465
+ if (found)
1466
+ return found;
1467
+ }
1468
+ return null;
1469
+ }
1470
+ /**
1471
+ * Where `node`'s frame sits in `host`'s, wherever each is in the tree: its
1472
+ * centre as an offset (y-up) from `host`'s, and its turn and scale relative to it.
1473
+ */
1474
+ export function frameIn(host, node) {
1475
+ const there = node.global;
1476
+ const here = host.global;
1477
+ const inverse = here.scale === 0 ? 0 : 1 / here.scale;
1478
+ const offset = rotateOffset(0, 0, -here.rotation, (there.x - here.x) * inverse, (there.y - here.y) * inverse);
1479
+ return { x: offset.x, y: offset.y, rotation: there.rotation - here.rotation, scale: there.scale * inverse };
1480
+ }
1481
+ //# sourceMappingURL=node2d.js.map