@pairdraw/core 0.21.1 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (590) hide show
  1. package/dist/canvas/boolean.d.ts +6 -1
  2. package/dist/canvas/boolean.d.ts.map +1 -1
  3. package/dist/canvas/boolean.js +10 -2
  4. package/dist/canvas/boolean.js.map +1 -1
  5. package/dist/canvas/color-space.d.ts +45 -0
  6. package/dist/canvas/color-space.d.ts.map +1 -0
  7. package/dist/canvas/color-space.js +39 -0
  8. package/dist/canvas/color-space.js.map +1 -0
  9. package/dist/canvas/fills.d.ts +10 -10
  10. package/dist/canvas/fills.d.ts.map +1 -1
  11. package/dist/canvas/fills.js +116 -62
  12. package/dist/canvas/fills.js.map +1 -1
  13. package/dist/canvas/flatten.d.ts +11 -3
  14. package/dist/canvas/flatten.d.ts.map +1 -1
  15. package/dist/canvas/flatten.js +62 -4
  16. package/dist/canvas/flatten.js.map +1 -1
  17. package/dist/canvas/index.d.ts +2 -1
  18. package/dist/canvas/index.js +2 -1
  19. package/dist/canvas/layout-grids.d.ts +5 -2
  20. package/dist/canvas/layout-grids.d.ts.map +1 -1
  21. package/dist/canvas/layout-grids.js +7 -2
  22. package/dist/canvas/layout-grids.js.map +1 -1
  23. package/dist/canvas/noise/render.d.ts +17 -4
  24. package/dist/canvas/noise/render.d.ts.map +1 -1
  25. package/dist/canvas/noise/render.js +21 -6
  26. package/dist/canvas/noise/render.js.map +1 -1
  27. package/dist/canvas/noise/shader.d.ts +4 -4
  28. package/dist/canvas/noise/shader.d.ts.map +1 -1
  29. package/dist/canvas/noise/shader.js +5 -6
  30. package/dist/canvas/noise/shader.js.map +1 -1
  31. package/dist/canvas/overlays/annotations.d.ts +19 -0
  32. package/dist/canvas/overlays/annotations.d.ts.map +1 -0
  33. package/dist/canvas/overlays/annotations.js +110 -0
  34. package/dist/canvas/overlays/annotations.js.map +1 -0
  35. package/dist/canvas/overlays/auto-layout-hover.d.ts +11 -1
  36. package/dist/canvas/overlays/auto-layout-hover.d.ts.map +1 -1
  37. package/dist/canvas/overlays/auto-layout-hover.js +25 -1
  38. package/dist/canvas/overlays/auto-layout-hover.js.map +1 -1
  39. package/dist/canvas/overlays/feedback.js +1 -1
  40. package/dist/canvas/overlays/feedback.js.map +1 -1
  41. package/dist/canvas/overlays/index.d.ts +2 -2
  42. package/dist/canvas/overlays/index.js +2 -2
  43. package/dist/canvas/overlays/measurement.d.ts +7 -1
  44. package/dist/canvas/overlays/measurement.d.ts.map +1 -1
  45. package/dist/canvas/overlays/measurement.js +42 -4
  46. package/dist/canvas/overlays/measurement.js.map +1 -1
  47. package/dist/canvas/overlays/presence.d.ts.map +1 -1
  48. package/dist/canvas/overlays/presence.js +21 -24
  49. package/dist/canvas/overlays/presence.js.map +1 -1
  50. package/dist/canvas/renderer/colors.d.ts +7 -1
  51. package/dist/canvas/renderer/colors.d.ts.map +1 -1
  52. package/dist/canvas/renderer/colors.js +9 -1
  53. package/dist/canvas/renderer/colors.js.map +1 -1
  54. package/dist/canvas/renderer/document-surface.d.ts +15 -6
  55. package/dist/canvas/renderer/document-surface.d.ts.map +1 -1
  56. package/dist/canvas/renderer/document-surface.js +1 -0
  57. package/dist/canvas/renderer/document-surface.js.map +1 -1
  58. package/dist/canvas/renderer/lifecycle.d.ts.map +1 -1
  59. package/dist/canvas/renderer/lifecycle.js +2 -2
  60. package/dist/canvas/renderer/lifecycle.js.map +1 -1
  61. package/dist/canvas/renderer/methods.d.ts +1 -0
  62. package/dist/canvas/renderer/methods.d.ts.map +1 -1
  63. package/dist/canvas/renderer/methods.js +4 -1
  64. package/dist/canvas/renderer/methods.js.map +1 -1
  65. package/dist/canvas/renderer/overlay-pass.d.ts.map +1 -1
  66. package/dist/canvas/renderer/overlay-pass.js +6 -1
  67. package/dist/canvas/renderer/overlay-pass.js.map +1 -1
  68. package/dist/canvas/renderer/pipeline.d.ts.map +1 -1
  69. package/dist/canvas/renderer/pipeline.js +7 -0
  70. package/dist/canvas/renderer/pipeline.js.map +1 -1
  71. package/dist/canvas/renderer/types.d.ts +10 -0
  72. package/dist/canvas/renderer/types.d.ts.map +1 -1
  73. package/dist/canvas/renderer.d.ts +10 -2
  74. package/dist/canvas/renderer.d.ts.map +1 -1
  75. package/dist/canvas/renderer.js +15 -3
  76. package/dist/canvas/renderer.js.map +1 -1
  77. package/dist/canvas/scene.d.ts.map +1 -1
  78. package/dist/canvas/scene.js +9 -9
  79. package/dist/canvas/scene.js.map +1 -1
  80. package/dist/clipboard/pairdraw.d.ts.map +1 -1
  81. package/dist/clipboard/pairdraw.js +1 -0
  82. package/dist/clipboard/pairdraw.js.map +1 -1
  83. package/dist/editor/bridges/clipboard.d.ts +2 -0
  84. package/dist/editor/bridges/clipboard.d.ts.map +1 -1
  85. package/dist/editor/bridges/clipboard.js +1 -0
  86. package/dist/editor/bridges/clipboard.js.map +1 -1
  87. package/dist/editor/bridges/components.d.ts +14 -7
  88. package/dist/editor/bridges/components.d.ts.map +1 -1
  89. package/dist/editor/bridges/components.js +6 -0
  90. package/dist/editor/bridges/components.js.map +1 -1
  91. package/dist/editor/bridges/structure.d.ts +1 -1
  92. package/dist/editor/bridges/structure.d.ts.map +1 -1
  93. package/dist/editor/clipboard/code.d.ts +32 -0
  94. package/dist/editor/clipboard/code.d.ts.map +1 -0
  95. package/dist/editor/clipboard/code.js +30 -0
  96. package/dist/editor/clipboard/code.js.map +1 -0
  97. package/dist/editor/clipboard/paste/dependencies.d.ts +14 -0
  98. package/dist/editor/clipboard/paste/dependencies.d.ts.map +1 -0
  99. package/dist/editor/clipboard/paste/dependencies.js +0 -0
  100. package/dist/editor/clipboard/paste/run.d.ts +14 -0
  101. package/dist/editor/clipboard/paste/run.d.ts.map +1 -0
  102. package/dist/editor/clipboard/paste/run.js +47 -0
  103. package/dist/editor/clipboard/paste/run.js.map +1 -0
  104. package/dist/editor/clipboard/styled.d.ts +2 -8
  105. package/dist/editor/clipboard/styled.d.ts.map +1 -1
  106. package/dist/editor/clipboard/styled.js +2 -32
  107. package/dist/editor/clipboard/styled.js.map +1 -1
  108. package/dist/editor/clipboard.d.ts +2 -0
  109. package/dist/editor/clipboard.d.ts.map +1 -1
  110. package/dist/editor/clipboard.js +34 -0
  111. package/dist/editor/clipboard.js.map +1 -1
  112. package/dist/editor/components/instances.d.ts +5 -0
  113. package/dist/editor/components/instances.d.ts.map +1 -1
  114. package/dist/editor/components/instances.js +69 -4
  115. package/dist/editor/components/instances.js.map +1 -1
  116. package/dist/editor/components/slots/index.d.ts.map +1 -1
  117. package/dist/editor/components/slots/index.js +7 -0
  118. package/dist/editor/components/slots/index.js.map +1 -1
  119. package/dist/editor/components.d.ts +6 -0
  120. package/dist/editor/components.d.ts.map +1 -1
  121. package/dist/editor/components.js +14 -2
  122. package/dist/editor/components.js.map +1 -1
  123. package/dist/editor/create.d.ts +29 -2
  124. package/dist/editor/create.d.ts.map +1 -1
  125. package/dist/editor/create.js +11 -2
  126. package/dist/editor/create.js.map +1 -1
  127. package/dist/editor/design-tokens.d.ts +1 -1
  128. package/dist/editor/design-tokens.d.ts.map +1 -1
  129. package/dist/editor/design-tokens.js +4 -18
  130. package/dist/editor/design-tokens.js.map +1 -1
  131. package/dist/editor/image-edit.d.ts.map +1 -1
  132. package/dist/editor/image-edit.js +1 -2
  133. package/dist/editor/image-edit.js.map +1 -1
  134. package/dist/editor/index.d.ts +4 -4
  135. package/dist/editor/index.js +1 -1
  136. package/dist/editor/layout-mode.d.ts +3 -1
  137. package/dist/editor/layout-mode.d.ts.map +1 -1
  138. package/dist/editor/layout-mode.js +97 -2
  139. package/dist/editor/layout-mode.js.map +1 -1
  140. package/dist/editor/nodes.d.ts +2 -0
  141. package/dist/editor/nodes.d.ts.map +1 -1
  142. package/dist/editor/nodes.js +22 -7
  143. package/dist/editor/nodes.js.map +1 -1
  144. package/dist/editor/read-only/actions.js +6 -0
  145. package/dist/editor/read-only/actions.js.map +1 -1
  146. package/dist/editor/selection/overlays.d.ts +1 -0
  147. package/dist/editor/selection/overlays.d.ts.map +1 -1
  148. package/dist/editor/selection/overlays.js +7 -0
  149. package/dist/editor/selection/overlays.js.map +1 -1
  150. package/dist/editor/selection/read.d.ts +8 -0
  151. package/dist/editor/selection.d.ts +9 -0
  152. package/dist/editor/selection.d.ts.map +1 -1
  153. package/dist/editor/state/shared.js +1 -0
  154. package/dist/editor/state/shared.js.map +1 -1
  155. package/dist/editor/state/view.d.ts.map +1 -1
  156. package/dist/editor/state/view.js +2 -0
  157. package/dist/editor/state/view.js.map +1 -1
  158. package/dist/editor/structure/boolean.d.ts +1 -1
  159. package/dist/editor/structure/boolean.d.ts.map +1 -1
  160. package/dist/editor/structure/boolean.js +20 -1
  161. package/dist/editor/structure/boolean.js.map +1 -1
  162. package/dist/editor/structure/container-wrap.d.ts +8 -2
  163. package/dist/editor/structure/container-wrap.d.ts.map +1 -1
  164. package/dist/editor/structure/container-wrap.js +17 -5
  165. package/dist/editor/structure/container-wrap.js.map +1 -1
  166. package/dist/editor/structure/flatten.d.ts.map +1 -1
  167. package/dist/editor/structure/flatten.js +8 -7
  168. package/dist/editor/structure/flatten.js.map +1 -1
  169. package/dist/editor/structure/group/ungroup.d.ts.map +1 -1
  170. package/dist/editor/structure/group/ungroup.js +2 -0
  171. package/dist/editor/structure/group/ungroup.js.map +1 -1
  172. package/dist/editor/structure/outline-stroke.d.ts.map +1 -1
  173. package/dist/editor/structure/outline-stroke.js +5 -0
  174. package/dist/editor/structure/outline-stroke.js.map +1 -1
  175. package/dist/editor/structure.d.ts +1 -1
  176. package/dist/editor/structure.d.ts.map +1 -1
  177. package/dist/editor/styles.d.ts +26 -0
  178. package/dist/editor/styles.d.ts.map +1 -0
  179. package/dist/editor/styles.js +127 -0
  180. package/dist/editor/styles.js.map +1 -0
  181. package/dist/editor/text/selection-style.d.ts +1 -0
  182. package/dist/editor/text/selection-style.d.ts.map +1 -1
  183. package/dist/editor/text/selection-style.js +10 -2
  184. package/dist/editor/text/selection-style.js.map +1 -1
  185. package/dist/editor/tool-registry.d.ts.map +1 -1
  186. package/dist/editor/tool-registry.js +6 -0
  187. package/dist/editor/tool-registry.js.map +1 -1
  188. package/dist/editor/types.d.ts +14 -2
  189. package/dist/editor/types.d.ts.map +1 -1
  190. package/dist/editor/variable-bindings.d.ts.map +1 -1
  191. package/dist/editor/variable-bindings.js +6 -1
  192. package/dist/editor/variable-bindings.js.map +1 -1
  193. package/dist/figma-api/accessors/basic.d.ts.map +1 -1
  194. package/dist/figma-api/accessors/basic.js +22 -1
  195. package/dist/figma-api/accessors/basic.js.map +1 -1
  196. package/dist/figma-api/accessors/shape.js +1 -1
  197. package/dist/figma-api/accessors/text/index.js +1 -1
  198. package/dist/figma-api/accessors/text/ranges.js +1 -1
  199. package/dist/figma-api/accessors/text/references.js +1 -1
  200. package/dist/figma-api/accessors/variables.js +1 -1
  201. package/dist/figma-api/accessors/vector.d.ts.map +1 -1
  202. package/dist/figma-api/accessors/vector.js +8 -22
  203. package/dist/figma-api/accessors/vector.js.map +1 -1
  204. package/dist/figma-api/accessors/visual.js +1 -1
  205. package/dist/figma-api/compatibility.d.ts +1 -1
  206. package/dist/figma-api/compatibility.d.ts.map +1 -1
  207. package/dist/figma-api/component-scope.d.ts +14 -0
  208. package/dist/figma-api/component-scope.d.ts.map +1 -0
  209. package/dist/figma-api/component-scope.js +28 -0
  210. package/dist/figma-api/component-scope.js.map +1 -0
  211. package/dist/figma-api/components.d.ts.map +1 -1
  212. package/dist/figma-api/components.js +26 -2
  213. package/dist/figma-api/components.js.map +1 -1
  214. package/dist/figma-api/flatten.js +3 -3
  215. package/dist/figma-api/flatten.js.map +1 -1
  216. package/dist/figma-api/index.d.ts +77 -6
  217. package/dist/figma-api/index.d.ts.map +1 -1
  218. package/dist/figma-api/index.js +188 -2
  219. package/dist/figma-api/index.js.map +1 -1
  220. package/dist/figma-api/node-types.d.ts +2 -1
  221. package/dist/figma-api/node-types.d.ts.map +1 -1
  222. package/dist/figma-api/overrides.d.ts +26 -1
  223. package/dist/figma-api/overrides.d.ts.map +1 -1
  224. package/dist/figma-api/overrides.js +157 -10
  225. package/dist/figma-api/overrides.js.map +1 -1
  226. package/dist/figma-api/proxy.d.ts +2 -0
  227. package/dist/figma-api/proxy.d.ts.map +1 -1
  228. package/dist/figma-api/proxy.js +10 -2
  229. package/dist/figma-api/proxy.js.map +1 -1
  230. package/dist/figma-api/reactions.d.ts +61 -5
  231. package/dist/figma-api/reactions.d.ts.map +1 -1
  232. package/dist/figma-api/reactions.js +144 -11
  233. package/dist/figma-api/reactions.js.map +1 -1
  234. package/dist/figma-api/shape-with-text.js +1 -1
  235. package/dist/figma-api/slots.d.ts +3 -1
  236. package/dist/figma-api/slots.d.ts.map +1 -1
  237. package/dist/figma-api/slots.js +9 -8
  238. package/dist/figma-api/slots.js.map +1 -1
  239. package/dist/index.d.ts +4 -4
  240. package/dist/index.js +1 -1
  241. package/dist/io/formats/code/detect.d.ts +23 -0
  242. package/dist/io/formats/code/detect.d.ts.map +1 -0
  243. package/dist/io/formats/code/detect.js +46 -0
  244. package/dist/io/formats/code/detect.js.map +1 -0
  245. package/dist/io/formats/code/index.d.ts +5 -0
  246. package/dist/io/formats/code/index.js +5 -0
  247. package/dist/io/formats/code/read.d.ts +45 -0
  248. package/dist/io/formats/code/read.d.ts.map +1 -0
  249. package/dist/io/formats/code/read.js +86 -0
  250. package/dist/io/formats/code/read.js.map +1 -0
  251. package/dist/io/formats/code/stylesheet.d.ts +13 -0
  252. package/dist/io/formats/code/stylesheet.d.ts.map +1 -0
  253. package/dist/io/formats/code/stylesheet.js +21 -0
  254. package/dist/io/formats/code/stylesheet.js.map +1 -0
  255. package/dist/io/formats/code/tokens.d.ts +18 -0
  256. package/dist/io/formats/code/tokens.d.ts.map +1 -0
  257. package/dist/io/formats/code/tokens.js +135 -0
  258. package/dist/io/formats/code/tokens.js.map +1 -0
  259. package/dist/io/formats/design-tokens/apply.d.ts +7 -3
  260. package/dist/io/formats/design-tokens/apply.d.ts.map +1 -1
  261. package/dist/io/formats/design-tokens/apply.js.map +1 -1
  262. package/dist/io/formats/fig/export/patch/fields.js +5 -0
  263. package/dist/io/formats/fig/export/patch/fields.js.map +1 -1
  264. package/dist/io/formats/fig/export/patch/index.d.ts.map +1 -1
  265. package/dist/io/formats/fig/export/patch/index.js +20 -20
  266. package/dist/io/formats/fig/export/patch/index.js.map +1 -1
  267. package/dist/io/formats/fig/export/setup.d.ts.map +1 -1
  268. package/dist/io/formats/fig/export/setup.js +5 -1
  269. package/dist/io/formats/fig/export/setup.js.map +1 -1
  270. package/dist/io/formats/fig/index.d.ts +3 -2
  271. package/dist/io/formats/fig/index.js +2 -2
  272. package/dist/io/formats/fig/read.d.ts.map +1 -1
  273. package/dist/io/formats/fig/read.js +5 -2
  274. package/dist/io/formats/fig/read.js.map +1 -1
  275. package/dist/io/formats/html/layers.d.ts +3 -1
  276. package/dist/io/formats/html/layers.d.ts.map +1 -1
  277. package/dist/io/formats/html/layers.js +6 -1
  278. package/dist/io/formats/html/layers.js.map +1 -1
  279. package/dist/io/formats/pdf/export.d.ts.map +1 -1
  280. package/dist/io/formats/pdf/export.js +7 -3
  281. package/dist/io/formats/pdf/export.js.map +1 -1
  282. package/dist/io/formats/pdf/plan.d.ts +3 -0
  283. package/dist/io/formats/pdf/plan.d.ts.map +1 -1
  284. package/dist/io/formats/pdf/plan.js +60 -36
  285. package/dist/io/formats/pdf/plan.js.map +1 -1
  286. package/dist/io/formats/raster/headless.d.ts.map +1 -1
  287. package/dist/io/formats/raster/headless.js +3 -2
  288. package/dist/io/formats/raster/headless.js.map +1 -1
  289. package/dist/io/formats/raster/index.d.ts +2 -2
  290. package/dist/io/formats/raster/index.js +2 -2
  291. package/dist/io/formats/raster/render.d.ts +10 -2
  292. package/dist/io/formats/raster/render.d.ts.map +1 -1
  293. package/dist/io/formats/raster/render.js +35 -9
  294. package/dist/io/formats/raster/render.js.map +1 -1
  295. package/dist/io/formats/svg/defs.d.ts.map +1 -1
  296. package/dist/io/formats/svg/defs.js +19 -1
  297. package/dist/io/formats/svg/defs.js.map +1 -1
  298. package/dist/io/formats/svg/export.d.ts +5 -2
  299. package/dist/io/formats/svg/export.d.ts.map +1 -1
  300. package/dist/io/formats/svg/export.js +59 -10
  301. package/dist/io/formats/svg/export.js.map +1 -1
  302. package/dist/io/formats/svg/index.d.ts +2 -2
  303. package/dist/io/formats/svg/index.js +2 -2
  304. package/dist/io/formats/svg/text/layout.d.ts.map +1 -1
  305. package/dist/io/formats/svg/text/layout.js +4 -2
  306. package/dist/io/formats/svg/text/layout.js.map +1 -1
  307. package/dist/io/formats/video/record.d.ts.map +1 -1
  308. package/dist/io/formats/video/record.js +24 -9
  309. package/dist/io/formats/video/record.js.map +1 -1
  310. package/dist/io/formats.d.ts.map +1 -1
  311. package/dist/io/formats.js +20 -13
  312. package/dist/io/formats.js.map +1 -1
  313. package/dist/kiwi/fig/population/client.d.ts.map +1 -1
  314. package/dist/kiwi/fig/population/client.js +2 -1
  315. package/dist/kiwi/fig/population/client.js.map +1 -1
  316. package/dist/kiwi/fig/session/document-state.d.ts +46 -2
  317. package/dist/kiwi/fig/session/document-state.d.ts.map +1 -1
  318. package/dist/kiwi/fig/session/document-state.js +113 -5
  319. package/dist/kiwi/fig/session/document-state.js.map +1 -1
  320. package/dist/kiwi/fig/session/options.d.ts +4 -0
  321. package/dist/kiwi/fig/session/options.d.ts.map +1 -1
  322. package/dist/kiwi/fig/session/options.js.map +1 -1
  323. package/dist/layout/apply.d.ts.map +1 -1
  324. package/dist/layout/apply.js +8 -4
  325. package/dist/layout/apply.js.map +1 -1
  326. package/dist/layout/auto-layout-handles.js +1 -1
  327. package/dist/layout/auto-layout-handles.js.map +1 -1
  328. package/dist/layout/axis-sizing.d.ts.map +1 -1
  329. package/dist/layout/axis-sizing.js +1 -1
  330. package/dist/layout/axis-sizing.js.map +1 -1
  331. package/dist/layout/derived.d.ts.map +1 -1
  332. package/dist/layout/derived.js +1 -1
  333. package/dist/layout/derived.js.map +1 -1
  334. package/dist/layout/effective-generated-text.js +1 -1
  335. package/dist/layout/effective-generated-text.js.map +1 -1
  336. package/dist/layout/grid.d.ts +3 -1
  337. package/dist/layout/grid.d.ts.map +1 -1
  338. package/dist/layout/grid.js +57 -16
  339. package/dist/layout/grid.js.map +1 -1
  340. package/dist/layout.d.ts +1 -1
  341. package/dist/layout.js +6 -5
  342. package/dist/layout.js.map +1 -1
  343. package/dist/node/fs.d.ts.map +1 -1
  344. package/dist/node/fs.js +28 -7
  345. package/dist/node/fs.js.map +1 -1
  346. package/dist/prototype/easing.d.ts +13 -5
  347. package/dist/prototype/easing.d.ts.map +1 -1
  348. package/dist/prototype/easing.js +46 -6
  349. package/dist/prototype/easing.js.map +1 -1
  350. package/dist/prototype/scenes.d.ts +31 -0
  351. package/dist/prototype/scenes.d.ts.map +1 -1
  352. package/dist/prototype/scenes.js +220 -31
  353. package/dist/prototype/scenes.js.map +1 -1
  354. package/dist/prototype/session.d.ts.map +1 -1
  355. package/dist/prototype/session.js +1 -0
  356. package/dist/prototype/session.js.map +1 -1
  357. package/dist/prototype/smart-animate/animation.d.ts +2 -1
  358. package/dist/prototype/smart-animate/animation.d.ts.map +1 -1
  359. package/dist/prototype/smart-animate/animation.js +2 -2
  360. package/dist/prototype/smart-animate/animation.js.map +1 -1
  361. package/dist/prototype/timeline.d.ts +10 -1
  362. package/dist/prototype/timeline.d.ts.map +1 -1
  363. package/dist/prototype/timeline.js +69 -23
  364. package/dist/prototype/timeline.js.map +1 -1
  365. package/dist/prototype/variables.d.ts +23 -0
  366. package/dist/prototype/variables.d.ts.map +1 -0
  367. package/dist/prototype/variables.js +237 -0
  368. package/dist/prototype/variables.js.map +1 -0
  369. package/dist/rpc/read-commands.d.ts +5 -0
  370. package/dist/rpc/read-commands.d.ts.map +1 -1
  371. package/dist/rpc/read-commands.js +4 -1
  372. package/dist/rpc/read-commands.js.map +1 -1
  373. package/dist/text/character-style.d.ts +8 -1
  374. package/dist/text/character-style.d.ts.map +1 -1
  375. package/dist/text/character-style.js +39 -1
  376. package/dist/text/character-style.js.map +1 -1
  377. package/dist/text/index.d.ts +2 -2
  378. package/dist/text/index.js +2 -2
  379. package/dist/tools/create/basic.js +3 -4
  380. package/dist/tools/create/basic.js.map +1 -1
  381. package/dist/tools/create/behaviours.js +1 -1
  382. package/dist/tools/create/code.d.ts +6 -0
  383. package/dist/tools/create/code.d.ts.map +1 -0
  384. package/dist/tools/create/code.js +68 -0
  385. package/dist/tools/create/code.js.map +1 -0
  386. package/dist/tools/create/html.d.ts.map +1 -1
  387. package/dist/tools/create/html.js +9 -57
  388. package/dist/tools/create/html.js.map +1 -1
  389. package/dist/tools/create/icons.js +1 -1
  390. package/dist/tools/create/inputs.d.ts +11 -0
  391. package/dist/tools/create/inputs.d.ts.map +1 -0
  392. package/dist/tools/create/inputs.js +15 -0
  393. package/dist/tools/create/inputs.js.map +1 -0
  394. package/dist/tools/create/mermaid.d.ts.map +1 -1
  395. package/dist/tools/create/mermaid.js +5 -6
  396. package/dist/tools/create/mermaid.js.map +1 -1
  397. package/dist/tools/create/place.d.ts +30 -0
  398. package/dist/tools/create/place.d.ts.map +1 -0
  399. package/dist/tools/create/place.js +70 -0
  400. package/dist/tools/create/place.js.map +1 -0
  401. package/dist/tools/create/render.js +1 -1
  402. package/dist/tools/create/svg.js +1 -1
  403. package/dist/tools/create/vector.js +1 -1
  404. package/dist/tools/create.d.ts +2 -1
  405. package/dist/tools/create.js +2 -1
  406. package/dist/tools/css/gradient.d.ts +28 -0
  407. package/dist/tools/css/gradient.d.ts.map +1 -0
  408. package/dist/tools/css/gradient.js +118 -0
  409. package/dist/tools/css/gradient.js.map +1 -0
  410. package/dist/tools/image-ai/generate.js +1 -1
  411. package/dist/tools/modify/geometry.js +5 -5
  412. package/dist/tools/modify/geometry.js.map +1 -1
  413. package/dist/tools/modify/layout.d.ts.map +1 -1
  414. package/dist/tools/modify/layout.js +7 -1
  415. package/dist/tools/modify/layout.js.map +1 -1
  416. package/dist/tools/modify/matching.js +1 -1
  417. package/dist/tools/modify/overrides.d.ts +6 -0
  418. package/dist/tools/modify/overrides.d.ts.map +1 -0
  419. package/dist/tools/modify/overrides.js +27 -0
  420. package/dist/tools/modify/overrides.js.map +1 -0
  421. package/dist/tools/modify/paint.d.ts.map +1 -1
  422. package/dist/tools/modify/paint.js +84 -39
  423. package/dist/tools/modify/paint.js.map +1 -1
  424. package/dist/tools/modify/text.d.ts +2 -1
  425. package/dist/tools/modify/text.d.ts.map +1 -1
  426. package/dist/tools/modify/text.js +79 -8
  427. package/dist/tools/modify/text.js.map +1 -1
  428. package/dist/tools/modify/update.d.ts.map +1 -1
  429. package/dist/tools/modify/update.js +18 -2
  430. package/dist/tools/modify/update.js.map +1 -1
  431. package/dist/tools/modify.d.ts +3 -2
  432. package/dist/tools/modify.js +3 -2
  433. package/dist/tools/read/css.d.ts.map +1 -1
  434. package/dist/tools/read/css.js +29 -12
  435. package/dist/tools/read/css.js.map +1 -1
  436. package/dist/tools/read/libraries.js +1 -1
  437. package/dist/tools/read/nodes.d.ts.map +1 -1
  438. package/dist/tools/read/nodes.js +19 -5
  439. package/dist/tools/read/nodes.js.map +1 -1
  440. package/dist/tools/registry/extended.d.ts.map +1 -1
  441. package/dist/tools/registry/extended.js +6 -1
  442. package/dist/tools/registry/extended.js.map +1 -1
  443. package/dist/tools/text-range.d.ts +11 -0
  444. package/dist/tools/text-range.d.ts.map +1 -0
  445. package/dist/tools/text-range.js +26 -0
  446. package/dist/tools/text-range.js.map +1 -0
  447. package/dist/tools/variables/bindings.js +1 -1
  448. package/dist/tools/variables/bindings.js.map +1 -1
  449. package/dist/tools/variables/unbind.js +1 -1
  450. package/dist/tools/variables/unbind.js.map +1 -1
  451. package/dist/tools/vector/path.d.ts.map +1 -1
  452. package/dist/tools/vector/path.js +7 -21
  453. package/dist/tools/vector/path.js.map +1 -1
  454. package/dist/vector/rebase.d.ts +17 -0
  455. package/dist/vector/rebase.d.ts.map +1 -0
  456. package/dist/vector/rebase.js +32 -0
  457. package/dist/vector/rebase.js.map +1 -0
  458. package/package.json +14 -9
  459. package/src/canvas/boolean.ts +12 -1
  460. package/src/canvas/color-space.ts +73 -0
  461. package/src/canvas/fills.ts +130 -83
  462. package/src/canvas/flatten.ts +92 -7
  463. package/src/canvas/index.ts +9 -0
  464. package/src/canvas/layout-grids.ts +15 -2
  465. package/src/canvas/noise/render.ts +35 -7
  466. package/src/canvas/noise/shader.ts +8 -10
  467. package/src/canvas/overlays/annotations.ts +117 -0
  468. package/src/canvas/overlays/auto-layout-hover.ts +41 -1
  469. package/src/canvas/overlays/feedback.ts +7 -2
  470. package/src/canvas/overlays/index.ts +1 -1
  471. package/src/canvas/overlays/measurement.ts +49 -3
  472. package/src/canvas/overlays/presence.ts +35 -32
  473. package/src/canvas/renderer/colors.ts +14 -0
  474. package/src/canvas/renderer/document-surface.ts +16 -6
  475. package/src/canvas/renderer/lifecycle.ts +2 -2
  476. package/src/canvas/renderer/methods.ts +4 -0
  477. package/src/canvas/renderer/overlay-pass.ts +4 -0
  478. package/src/canvas/renderer/pipeline.ts +8 -0
  479. package/src/canvas/renderer/types.ts +8 -0
  480. package/src/canvas/renderer.ts +21 -2
  481. package/src/canvas/scene.ts +15 -7
  482. package/src/clipboard/pairdraw.ts +1 -0
  483. package/src/editor/bridges/clipboard.ts +1 -0
  484. package/src/editor/bridges/components.ts +10 -0
  485. package/src/editor/clipboard/code.ts +50 -0
  486. package/src/editor/clipboard/paste/dependencies.ts +18 -0
  487. package/src/editor/clipboard/paste/run.ts +64 -0
  488. package/src/editor/clipboard/styled.ts +4 -52
  489. package/src/editor/clipboard.ts +40 -0
  490. package/src/editor/components/instances.ts +92 -4
  491. package/src/editor/components/slots/index.ts +7 -0
  492. package/src/editor/components.ts +16 -2
  493. package/src/editor/create.ts +15 -1
  494. package/src/editor/design-tokens.ts +3 -23
  495. package/src/editor/image-edit.ts +5 -2
  496. package/src/editor/index.ts +1 -0
  497. package/src/editor/layout-mode.ts +131 -3
  498. package/src/editor/nodes.ts +30 -5
  499. package/src/editor/read-only/actions.ts +6 -0
  500. package/src/editor/selection/overlays.ts +8 -0
  501. package/src/editor/state/shared.ts +1 -0
  502. package/src/editor/state/view.ts +2 -0
  503. package/src/editor/structure/boolean.ts +29 -1
  504. package/src/editor/structure/container-wrap.ts +20 -4
  505. package/src/editor/structure/flatten.ts +15 -8
  506. package/src/editor/structure/group/ungroup.ts +2 -0
  507. package/src/editor/structure/outline-stroke.ts +5 -0
  508. package/src/editor/styles.ts +203 -0
  509. package/src/editor/text/selection-style.ts +18 -1
  510. package/src/editor/tool-registry.ts +2 -0
  511. package/src/editor/types.ts +14 -0
  512. package/src/editor/variable-bindings.ts +11 -0
  513. package/src/figma-api/accessors/basic.ts +33 -1
  514. package/src/figma-api/accessors/vector.ts +6 -13
  515. package/src/figma-api/compatibility.ts +1 -0
  516. package/src/figma-api/component-scope.ts +36 -0
  517. package/src/figma-api/components.ts +24 -0
  518. package/src/figma-api/flatten.ts +7 -3
  519. package/src/figma-api/index.ts +302 -6
  520. package/src/figma-api/node-types.ts +1 -0
  521. package/src/figma-api/overrides.ts +192 -5
  522. package/src/figma-api/proxy.ts +16 -1
  523. package/src/figma-api/reactions.ts +163 -12
  524. package/src/figma-api/slots.ts +10 -9
  525. package/src/io/formats/code/detect.ts +67 -0
  526. package/src/io/formats/code/index.ts +17 -0
  527. package/src/io/formats/code/read.ts +143 -0
  528. package/src/io/formats/code/stylesheet.ts +24 -0
  529. package/src/io/formats/code/tokens.ts +159 -0
  530. package/src/io/formats/design-tokens/apply.ts +3 -2
  531. package/src/io/formats/fig/export/patch/fields.ts +11 -0
  532. package/src/io/formats/fig/export/patch/index.ts +23 -19
  533. package/src/io/formats/fig/export/setup.ts +8 -1
  534. package/src/io/formats/fig/index.ts +6 -0
  535. package/src/io/formats/fig/read.ts +11 -2
  536. package/src/io/formats/html/layers.ts +7 -0
  537. package/src/io/formats/pdf/export.ts +19 -7
  538. package/src/io/formats/pdf/plan.ts +71 -32
  539. package/src/io/formats/raster/headless.ts +3 -1
  540. package/src/io/formats/raster/index.ts +2 -0
  541. package/src/io/formats/raster/render.ts +49 -9
  542. package/src/io/formats/svg/defs.ts +27 -1
  543. package/src/io/formats/svg/export.ts +75 -13
  544. package/src/io/formats/svg/index.ts +1 -0
  545. package/src/io/formats/svg/text/layout.ts +5 -3
  546. package/src/io/formats/video/record.ts +33 -9
  547. package/src/io/formats.ts +35 -15
  548. package/src/kiwi/fig/population/client.ts +6 -1
  549. package/src/kiwi/fig/session/document-state.ts +195 -5
  550. package/src/kiwi/fig/session/options.ts +2 -0
  551. package/src/layout/apply.ts +12 -4
  552. package/src/layout/auto-layout-handles.ts +1 -1
  553. package/src/layout/axis-sizing.ts +3 -1
  554. package/src/layout/derived.ts +3 -1
  555. package/src/layout/effective-generated-text.ts +1 -1
  556. package/src/layout/grid.ts +91 -21
  557. package/src/layout.ts +16 -3
  558. package/src/node/fs.ts +32 -7
  559. package/src/prototype/easing.ts +79 -7
  560. package/src/prototype/scenes.ts +244 -15
  561. package/src/prototype/session.ts +1 -0
  562. package/src/prototype/smart-animate/animation.ts +4 -3
  563. package/src/prototype/timeline.ts +118 -26
  564. package/src/prototype/variables.ts +189 -0
  565. package/src/rpc/read-commands.ts +19 -1
  566. package/src/text/character-style.ts +47 -0
  567. package/src/text/index.ts +1 -1
  568. package/src/tools/create/basic.ts +2 -3
  569. package/src/tools/create/code.ts +85 -0
  570. package/src/tools/create/html.ts +9 -46
  571. package/src/tools/create/inputs.ts +12 -0
  572. package/src/tools/create/mermaid.ts +6 -6
  573. package/src/tools/create/place.ts +80 -0
  574. package/src/tools/create.ts +1 -0
  575. package/src/tools/css/gradient.ts +147 -0
  576. package/src/tools/modify/geometry.ts +5 -5
  577. package/src/tools/modify/layout.ts +19 -0
  578. package/src/tools/modify/overrides.ts +35 -0
  579. package/src/tools/modify/paint.ts +124 -54
  580. package/src/tools/modify/text.ts +91 -7
  581. package/src/tools/modify/update.ts +23 -2
  582. package/src/tools/modify.ts +9 -1
  583. package/src/tools/read/css.ts +46 -12
  584. package/src/tools/read/nodes.ts +26 -4
  585. package/src/tools/registry/extended.ts +6 -0
  586. package/src/tools/text-range.ts +29 -0
  587. package/src/tools/variables/bindings.ts +4 -1
  588. package/src/tools/variables/unbind.ts +4 -1
  589. package/src/tools/vector/path.ts +11 -13
  590. package/src/vector/rebase.ts +33 -0
@@ -4,6 +4,7 @@ import { componentLayerResolver, reactionsWithInherited } from "./reactions.js";
4
4
  import { primaryAction, shownFrame, step } from "./session.js";
5
5
  import { changeTarget, createPlayScene } from "./scene.js";
6
6
  import { createSmartAnimation } from "./smart-animate/animation.js";
7
+ import { evaluateVariable } from "./variables.js";
7
8
  import { instanceMainComponent } from "@pairdraw/scene-graph/instances";
8
9
  //#region src/prototype/scenes.ts
9
10
  /** How many changed frames play keeps; a frame dropped beyond them starts again as designed. */
@@ -11,8 +12,58 @@ const PLAY_SCENE_LIMIT = 4;
11
12
  function createPlayScenes(getDocument, limit = 4) {
12
13
  const scenes = /* @__PURE__ */ new Map();
13
14
  const scroll = /* @__PURE__ */ new Map();
15
+ const values = /* @__PURE__ */ new Map();
16
+ const modes = /* @__PURE__ */ new Map();
17
+ function literalOf(value) {
18
+ if (typeof value === "boolean" || typeof value === "number" || typeof value === "string") return value;
19
+ if (value && typeof value === "object" && "r" in value) return value;
20
+ }
21
+ function valueOf(variableId, rootId) {
22
+ const overlay = values.get(variableId);
23
+ if (overlay !== void 0) return overlay;
24
+ const frame = rootId ? graphFor(rootId).getNode(rootId) : void 0;
25
+ const variable = (rootId ? graphFor(rootId).variables : getDocument().variables).get(variableId);
26
+ if (!variable) return void 0;
27
+ const frameMode = frame ? frame.variableModes[variable.collectionId] : void 0;
28
+ const defaultMode = getDocument().variableCollections.get(variable.collectionId)?.modes[0]?.modeId;
29
+ const mode = modes.get(variable.collectionId) ?? frameMode ?? defaultMode;
30
+ return mode ? literalOf(variable.valuesByMode[mode]) : void 0;
31
+ }
32
+ function applyVariables(graph) {
33
+ if (graph.variables === getDocument().variables) graph.variables = new Map(graph.variables);
34
+ const root = [...graph.getAllNodes()].find((node) => node.parentId === null);
35
+ for (const [variableId, value] of values) {
36
+ const variable = graph.variables.get(variableId);
37
+ if (!variable) continue;
38
+ const rootMode = root ? root.variableModes[variable.collectionId] : void 0;
39
+ const defaultMode = graph.variableCollections.get(variable.collectionId)?.modes[0]?.modeId;
40
+ const mode = modes.get(variable.collectionId) ?? rootMode ?? defaultMode;
41
+ if (mode) graph.variables.set(variableId, {
42
+ ...variable,
43
+ valuesByMode: {
44
+ ...variable.valuesByMode,
45
+ [mode]: value
46
+ }
47
+ });
48
+ }
49
+ if (modes.size === 0) return;
50
+ for (const node of graph.getAllNodes()) {
51
+ const overrides = { ...node.variableModes };
52
+ for (const [collectionId, modeId] of modes) overrides[collectionId] = modeId;
53
+ graph.updateNode(node.id, { variableModes: overrides });
54
+ }
55
+ }
56
+ function sceneFor(rootId) {
57
+ const existing = scenes.get(rootId);
58
+ if (existing) return existing;
59
+ const scene = createPlayScene(getDocument(), rootId);
60
+ applyVariables(scene.graph);
61
+ scenes.set(rootId, scene);
62
+ return scene;
63
+ }
14
64
  function graphFor(rootId) {
15
- return scenes.get(rootId)?.graph ?? getDocument();
65
+ if (values.size === 0 && modes.size === 0) return scenes.get(rootId)?.graph ?? getDocument();
66
+ return sceneFor(rootId).graph;
16
67
  }
17
68
  /**
18
69
  * The frame as play shows it before a change: the document while play has not changed it, else
@@ -44,12 +95,16 @@ function createPlayScenes(getDocument, limit = 4) {
44
95
  };
45
96
  return {
46
97
  changed,
47
- animation: createSmartAnimation(from, to, transition?.easing)
98
+ animation: createSmartAnimation(from, to, transition?.easing, {
99
+ curve: transition?.easingCurve,
100
+ spring: transition?.easingSpring,
101
+ duration: transition?.duration
102
+ })
48
103
  };
49
104
  }
50
105
  function changeIn(rootId, sourceId, variantId) {
51
106
  if (!changeTarget(graphFor(rootId), rootId, sourceId, variantId)) return null;
52
- const scene = scenes.get(rootId) ?? createPlayScene(getDocument(), rootId);
107
+ const scene = sceneFor(rootId);
53
108
  const change = scene.changeTo(sourceId, variantId);
54
109
  scenes.delete(rootId);
55
110
  scenes.set(rootId, scene);
@@ -60,8 +115,168 @@ function createPlayScenes(getDocument, limit = 4) {
60
115
  if (change) clampScroll(scene.graph, scroll);
61
116
  return change;
62
117
  }
118
+ function setVariableStep(session, action, rootId) {
119
+ if (!action.variableId) return {
120
+ session,
121
+ changed: null,
122
+ action
123
+ };
124
+ const result = evaluateVariable(action.value, (id) => valueOf(id, rootId));
125
+ if (!result.ok) return {
126
+ session,
127
+ changed: null,
128
+ variablesRefused: result.reason,
129
+ action
130
+ };
131
+ values.set(action.variableId, result.value);
132
+ applyVariables(graphFor(rootId));
133
+ return {
134
+ session,
135
+ changed: null,
136
+ repaint: true,
137
+ action
138
+ };
139
+ }
140
+ function setModeStep(session, action, rootId) {
141
+ if (!action.collectionId || !action.modeId) return {
142
+ session,
143
+ changed: null,
144
+ action
145
+ };
146
+ modes.set(action.collectionId, action.modeId);
147
+ applyVariables(graphFor(rootId));
148
+ return {
149
+ session,
150
+ changed: null,
151
+ repaint: true,
152
+ action
153
+ };
154
+ }
155
+ /** Whether an evaluated variable counts as true for a Conditional. */
156
+ function truthy(value) {
157
+ return value === true || typeof value === "number" && value !== 0 || typeof value === "string" && value.length > 0;
158
+ }
159
+ function takenBranch(action, rootId) {
160
+ for (const block of action.blocks) {
161
+ if (block.condition) {
162
+ const result = evaluateVariable(block.condition, (id) => valueOf(id, rootId));
163
+ if (!result.ok) return { refused: result.reason };
164
+ if (!truthy(result.value)) continue;
165
+ }
166
+ return { actions: block.actions };
167
+ }
168
+ return { actions: [] };
169
+ }
170
+ function resolveBranch(action, rootId) {
171
+ if (action.type !== "CONDITIONAL") return { actions: [action] };
172
+ return takenBranch(action, rootId);
173
+ }
174
+ /** The first branch's action whose condition holds, resolving nested conditionals. */
175
+ function resolveAction(action, rootId) {
176
+ if (action.type !== "CONDITIONAL") return { action };
177
+ const branch = takenBranch(action, rootId);
178
+ if ("refused" in branch) return branch;
179
+ if (branch.actions.length === 0) return { action };
180
+ return resolveAction(branch.actions[0], rootId);
181
+ }
182
+ function mergeStep(target, next) {
183
+ target.session = next.session;
184
+ if (next.changed) target.changed = next.changed;
185
+ if (next.repaint) target.repaint = true;
186
+ if (next.scrolled?.length) target.scrolled = [...target.scrolled ?? [], ...next.scrolled];
187
+ if (next.reveal !== void 0) target.reveal = next.reveal;
188
+ if (next.animation) target.animation = next.animation;
189
+ }
190
+ function conditionalStep(session, action, sourceId, rootId) {
191
+ const branch = takenBranch(action, rootId);
192
+ if ("refused" in branch) return {
193
+ session,
194
+ changed: null,
195
+ variablesRefused: branch.refused,
196
+ action
197
+ };
198
+ if (branch.actions.length === 0) return {
199
+ session,
200
+ changed: null,
201
+ action
202
+ };
203
+ const merged = {
204
+ session,
205
+ changed: null,
206
+ action
207
+ };
208
+ let currentRoot = rootId;
209
+ let primary;
210
+ for (const item of branch.actions) {
211
+ const prevSession = merged.session;
212
+ const next = runAction(prevSession, {
213
+ sourceId,
214
+ action: item,
215
+ transition: item.type === "NODE" ? item.transition : null
216
+ }, currentRoot);
217
+ mergeStep(merged, next);
218
+ if (next.session !== prevSession) currentRoot = shownFrame(next.session);
219
+ const transitioned = next.session !== prevSession || next.changed !== null || Boolean(next.animation) || Boolean(next.scrolled?.length);
220
+ if (next.action) {
221
+ merged.action = next.action;
222
+ if (transitioned) primary = next.action;
223
+ }
224
+ if (next.variablesRefused) {
225
+ merged.variablesRefused = next.variablesRefused;
226
+ return merged;
227
+ }
228
+ }
229
+ if (primary) merged.action = primary;
230
+ return merged;
231
+ }
232
+ function runAction(session, click, rootId) {
233
+ const { sourceId, action } = click;
234
+ if (action.type === "SET_VARIABLE") return setVariableStep(session, action, rootId);
235
+ if (action.type === "SET_VARIABLE_MODE") return setModeStep(session, action, rootId);
236
+ if (action.type === "CONDITIONAL") return conditionalStep(session, action, sourceId, rootId);
237
+ if (action.type === "NODE" && action.navigation === "CHANGE_TO") {
238
+ if (!action.nodeId) return {
239
+ session,
240
+ changed: null,
241
+ action
242
+ };
243
+ return {
244
+ session,
245
+ action,
246
+ ...changeWith(rootId, sourceId, action.nodeId, action.transition)
247
+ };
248
+ }
249
+ if (action.type === "NODE" && action.navigation === "SCROLL_TO") {
250
+ if (!action.nodeId) return {
251
+ session,
252
+ changed: null,
253
+ scrolled: [],
254
+ reveal: null,
255
+ action
256
+ };
257
+ return {
258
+ session,
259
+ changed: null,
260
+ action,
261
+ ...scrollIntoView(graphFor(rootId), scroll, rootId, action.nodeId)
262
+ };
263
+ }
264
+ return {
265
+ session: step(getDocument(), session, action),
266
+ changed: null,
267
+ action
268
+ };
269
+ }
63
270
  return {
64
271
  graphFor,
272
+ cloneGraphFor(rootId) {
273
+ const copy = createPlayScene(getDocument(), rootId);
274
+ applyVariables(copy.graph);
275
+ return copy.graph;
276
+ },
277
+ resolve: resolveAction,
278
+ resolveBranch,
279
+ hasVariables: () => values.size > 0 || modes.size > 0,
65
280
  views: scenes,
66
281
  scroll,
67
282
  scrollBy(rootId, path, dx, dy) {
@@ -70,34 +285,8 @@ function createPlayScenes(getDocument, limit = 4) {
70
285
  setScroll(id, offset) {
71
286
  scroll.set(id, offset);
72
287
  },
73
- run(session, { sourceId, action }, rootId = shownFrame(session)) {
74
- if (action.type === "NODE" && action.navigation === "CHANGE_TO") {
75
- if (!action.nodeId) return {
76
- session,
77
- changed: null
78
- };
79
- return {
80
- session,
81
- ...changeWith(rootId, sourceId, action.nodeId, action.transition)
82
- };
83
- }
84
- if (action.type === "NODE" && action.navigation === "SCROLL_TO") {
85
- if (!action.nodeId) return {
86
- session,
87
- changed: null,
88
- scrolled: [],
89
- reveal: null
90
- };
91
- return {
92
- session,
93
- changed: null,
94
- ...scrollIntoView(graphFor(rootId), scroll, rootId, action.nodeId)
95
- };
96
- }
97
- return {
98
- session: step(getDocument(), session, action),
99
- changed: null
100
- };
288
+ run(session, click, rootId = shownFrame(session)) {
289
+ return runAction(session, click, rootId);
101
290
  },
102
291
  revert(session, revert) {
103
292
  if (revert.kind === "change") {
@@ -1 +1 @@
1
- {"version":3,"file":"scenes.js","names":[],"sources":["../../src/prototype/scenes.ts"],"sourcesContent":["import type {\n PrototypeAction,\n PrototypeReaction,\n PrototypeTransition,\n SceneGraph,\n SceneNode\n} from '@pairdraw/scene-graph'\nimport { instanceMainComponent } from '@pairdraw/scene-graph/instances'\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\n\nimport { extractPageContext, findPageId } from '#core/io/subgraph'\n\nimport type { PlayRevert } from './pointer'\nimport { componentLayerResolver, reactionsWithInherited } from './reactions'\nimport {\n changeTarget,\n createPlayScene,\n type PlayChange,\n type PlayScene,\n type PlaySceneView\n} from './scene'\nimport { clampScroll, scrollAlong, scrollIntoView, type ScrollChange } from './scroll'\nimport { primaryAction, shownFrame, step, type PlayClick, type PlaySession } from './session'\nimport {\n createSmartAnimation,\n type PlayFrame,\n type SmartAnimation\n} from './smart-animate/animation'\n\n/** How many changed frames play keeps; a frame dropped beyond them starts again as designed. */\nexport const PLAY_SCENE_LIMIT = 4\n\n/**\n * An After delay reaction the layers a frame shows add: the layer it runs from, which is an\n * instance or a copy inside one, the main component or layer it stands for, whose reaction it is,\n * the reaction, its action, and the delay in milliseconds.\n */\nexport interface PlayTimeout {\n sourceId: string\n /** The main component an instance shows, or the main layer a copy stands for. */\n variantId: string\n reactionId: string\n action: PrototypeAction\n delayMs: number\n}\n\n/**\n * What a reaction did: the session after it, and the Change to it made, if it made one. A Scroll\n * to also says which frames it scrolled, for an animation to step between, and where the layer it\n * scrolled to is drawn now, for a screen that scrolls by panning to bring into view.\n */\nexport interface PlayStep {\n session: PlaySession\n changed: PlayChange | null\n scrolled?: ScrollChange[]\n reveal?: Vector | null\n /**\n * A Smart animate Change to's animation from the frame as it was to its copy as it is now, for\n * the player to run over the transition's duration; the copy shows the change at once.\n */\n animation?: SmartAnimation\n}\n\n/**\n * The frames play changed, each kept as a private copy so the document never changes. Frames move\n * through the session as before; a Change to switches an instance on its frame's copy, which is\n * made at the first change, so a prototype without one copies nothing.\n */\nexport interface PlayScenes {\n /** The graph play reads a top-level frame from: its copy once changed, else the document. */\n graphFor(rootId: string): SceneGraph\n /** The changed frames the canvas draws from their copies, by frame id. */\n readonly views: ReadonlyMap<string, PlaySceneView>\n /** How far play scrolled each frame that scrolls, by frame id. */\n readonly scroll: ReadonlyMap<string, Vector>\n /**\n * Scrolls the frames along `path`, a pointer's path in `rootId`, innermost first, and returns\n * what none of them could take, for the canvas to pan by.\n */\n scrollBy(rootId: string, path: readonly string[], dx: number, dy: number): Vector\n /** Sets one frame's offset, as an animated Scroll to steps it toward where it ends. */\n setScroll(id: string, offset: Vector): void\n /** Runs a reaction of a layer in `rootId`, the shown frame unless a timer names another. */\n run(session: PlaySession, click: PlayClick, rootId?: string): PlayStep\n /**\n * Undoes a While hovering or While pressing reaction, unless play moved on from what it did: an\n * instance that shows another variant by now, or an overlay or frame no longer shown.\n */\n revert(session: PlaySession, revert: PlayRevert): PlayStep\n /**\n * The After delay reactions of the instances `rootId` shows and of the copies inside them, by\n * the variants and main layers they stand for now.\n */\n instanceTimeouts(rootId: string): PlayTimeout[]\n /**\n * Drops the copies of frames that hold any of these document layers, after an edit to them:\n * the frame's own layers and the variants its copy holds.\n */\n forget(nodeIds: Iterable<string>): void\n clear(): void\n}\n\nexport function createPlayScenes(\n getDocument: () => SceneGraph,\n limit = PLAY_SCENE_LIMIT\n): PlayScenes {\n // Insertion order is use order: a frame changed again moves to the end, and the first goes.\n const scenes = new Map<string, PlayScene>()\n const scroll = new Map<string, Vector>()\n\n function graphFor(rootId: string): SceneGraph {\n return scenes.get(rootId)?.graph ?? getDocument()\n }\n\n /**\n * The frame as play shows it before a change: the document while play has not changed it, else\n * a copy of play's copy, which the change is about to edit in place.\n */\n function frameBefore(rootId: string): PlayFrame {\n const scene = scenes.get(rootId)\n if (!scene) return { graph: getDocument(), rootId }\n const pageId = findPageId(scene.graph, rootId) ?? scene.graph.rootId\n return {\n graph: extractPageContext(scene.graph, pageId, [rootId], { shareTables: true }),\n rootId\n }\n }\n\n /**\n * Runs a Change to on `rootId`'s copy, and with a Smart animate transition the animation from the\n * frame as it was.\n */\n function changeWith(\n rootId: string,\n sourceId: string,\n variantId: string,\n transition: PrototypeTransition | null\n ): Pick<PlayStep, 'changed' | 'animation'> {\n const smart = transition?.type === 'SMART_ANIMATE' && transition.duration > 0\n const before = smart && changeTarget(graphFor(rootId), rootId, sourceId, variantId)\n const from = before ? frameBefore(rootId) : null\n const changed = changeIn(rootId, sourceId, variantId)\n if (!changed || !from) return { changed }\n const to = { graph: graphFor(rootId), rootId }\n return { changed, animation: createSmartAnimation(from, to, transition?.easing) }\n }\n\n function changeIn(rootId: string, sourceId: string, variantId: string): PlayChange | null {\n // Checked on what play shows now, so a Change to that cannot run copies nothing.\n if (!changeTarget(graphFor(rootId), rootId, sourceId, variantId)) return null\n const scene = scenes.get(rootId) ?? createPlayScene(getDocument(), rootId)\n const change = scene.changeTo(sourceId, variantId)\n scenes.delete(rootId)\n scenes.set(rootId, scene)\n for (const oldest of scenes.keys()) {\n if (scenes.size <= limit) break\n scenes.delete(oldest)\n }\n // What the switched instance holds may be shorter now than a frame scrolled past.\n if (change) clampScroll(scene.graph, scroll)\n return change\n }\n\n return {\n graphFor,\n views: scenes,\n scroll,\n scrollBy(rootId, path, dx, dy) {\n return scrollAlong(graphFor(rootId), scroll, path, dx, dy)\n },\n setScroll(id, offset) {\n scroll.set(id, offset)\n },\n run(session, { sourceId, action }, rootId = shownFrame(session)) {\n if (action.type === 'NODE' && action.navigation === 'CHANGE_TO') {\n if (!action.nodeId) return { session, changed: null }\n return { session, ...changeWith(rootId, sourceId, action.nodeId, action.transition) }\n }\n if (action.type === 'NODE' && action.navigation === 'SCROLL_TO') {\n if (!action.nodeId) return { session, changed: null, scrolled: [], reveal: null }\n const moved = scrollIntoView(graphFor(rootId), scroll, rootId, action.nodeId)\n return { session, changed: null, ...moved }\n }\n return { session: step(getDocument(), session, action), changed: null }\n },\n revert(session, revert) {\n if (revert.kind === 'change') {\n const graph = graphFor(revert.rootId)\n const instance = graph.getNode(revert.instanceId)\n if (!instance || instanceMainComponent(graph, instance)?.id !== revert.to) {\n return { session, changed: null }\n }\n const { rootId, instanceId, from, transition } = revert\n return { session, ...changeWith(rootId, instanceId, from, transition) }\n }\n const shown =\n revert.kind === 'overlay'\n ? session.overlays.at(-1) === revert.frameId\n : session.frameId === revert.frameId\n if (!shown) return { session, changed: null }\n const action = { type: revert.kind === 'overlay' ? 'CLOSE' : 'BACK' } as const\n return { session: step(getDocument(), session, action), changed: null }\n },\n instanceTimeouts(rootId) {\n const graph = graphFor(rootId)\n const timeouts: PlayTimeout[] = []\n const sourceOf = componentLayerResolver(graph)\n const collect = (node: SceneNode, variantId: string, inherited: PrototypeReaction[]) => {\n for (const reaction of reactionsWithInherited(node, inherited)) {\n const action = reaction.trigger.type === 'AFTER_TIMEOUT' && primaryAction(reaction)\n if (!action) continue\n timeouts.push({\n sourceId: node.id,\n variantId,\n reactionId: reaction.id,\n action,\n delayMs: reaction.trigger.delay * 1000\n })\n }\n }\n const visit = (id: string) => {\n for (const child of graph.getChildren(id)) {\n if (child.type === 'INSTANCE') {\n const main = instanceMainComponent(graph, child)\n if (main) collect(child, main.id, main.prototypeReactions)\n } else {\n // A plain copy inherits its main layer's After delay; the resolver reads each\n // instance's copy map once, so arming costs one search per instance, not per copy.\n const source = sourceOf(child)\n if (source && source.id !== child.id)\n collect(child, source.id, source.prototypeReactions)\n }\n visit(child.id)\n }\n }\n visit(rootId)\n return timeouts\n },\n forget(nodeIds) {\n const design = getDocument()\n for (const id of nodeIds) {\n for (const [rootId, scene] of scenes) {\n // The copy holds the frame and every variant its instances switch to, wherever they\n // are, under the page and document it copied, which an edit elsewhere touches too.\n const copied = scene.graph.getNode(id)\n const held = copied !== undefined && copied.type !== 'CANVAS' && id !== scene.graph.rootId\n if (design.isDescendant(id, root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M,SAAS,YAAY;GAC3B,KAAK,MAAM,MAAM,SACf,KAAK,MAAM,CAAC,QAAQ,UAAU,QAAQ;IAGpC,MAAM,SAAS,MAAM,MAAM,QAAQ,EAAE;IACrC,MAAM,OAAO,WAAW,KAAA,KAAa,OAAO,SAAS,YAAY,OAAO,MAAM,MAAM;IACpF,IAAI,OAAO,aAAa,IAAI,MAAM,KAAK,MAAM,OAAO,OAAO,MAAM;GACnE;EAEJ;EACA,QAAQ;GACN,OAAO,MAAM;GACb,OAAO,MAAM;EACf;CACF;AACF"}
1
+ {"version":3,"file":"scenes.js","names":[],"sources":["../../src/prototype/scenes.ts"],"sourcesContent":["import type {\n PrototypeAction,\n PrototypeConditionalAction,\n PrototypeReaction,\n PrototypeSetVariableAction,\n PrototypeSetVariableModeAction,\n PrototypeTransition,\n SceneGraph,\n SceneNode,\n VariableValue\n} from '@pairdraw/scene-graph'\nimport { instanceMainComponent } from '@pairdraw/scene-graph/instances'\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\n\nimport { extractPageContext, findPageId } from '#core/io/subgraph'\n\nimport type { PlayRevert } from './pointer'\nimport { componentLayerResolver, reactionsWithInherited } from './reactions'\nimport {\n changeTarget,\n createPlayScene,\n type PlayChange,\n type PlayScene,\n type PlaySceneView\n} from './scene'\nimport { clampScroll, scrollAlong, scrollIntoView, type ScrollChange } from './scroll'\nimport { primaryAction, shownFrame, step, type PlayClick, type PlaySession } from './session'\nimport {\n createSmartAnimation,\n type PlayFrame,\n type SmartAnimation\n} from './smart-animate/animation'\nimport { evaluateVariable, type PrototypeResolvedValue } from './variables'\n\n/** How many changed frames play keeps; a frame dropped beyond them starts again as designed. */\nexport const PLAY_SCENE_LIMIT = 4\n\n/**\n * An After delay reaction the layers a frame shows add: the layer it runs from, which is an\n * instance or a copy inside one, the main component or layer it stands for, whose reaction it is,\n * the reaction, its action, and the delay in milliseconds.\n */\nexport interface PlayTimeout {\n sourceId: string\n /** The main component an instance shows, or the main layer a copy stands for. */\n variantId: string\n reactionId: string\n action: PrototypeAction\n delayMs: number\n}\n\n/**\n * What a reaction did: the session after it, and the Change to it made, if it made one. A Scroll\n * to also says which frames it scrolled, for an animation to step between, and where the layer it\n * scrolled to is drawn now, for a screen that scrolls by panning to bring into view.\n */\nexport interface PlayStep {\n session: PlaySession\n changed: PlayChange | null\n scrolled?: ScrollChange[]\n reveal?: Vector | null\n /**\n * A Smart animate Change to's animation from the frame as it was to its copy as it is now, for\n * the player to run over the transition's duration; the copy shows the change at once.\n */\n animation?: SmartAnimation\n /** Why a variable action could not run; the player shows it instead of guessing a value. */\n variablesRefused?: string\n /** The action actually run, after a Conditional picked a branch. */\n action?: PrototypeAction\n /** Whether play's variable values changed, so a frame showing them must be drawn again. */\n repaint?: boolean\n}\n\n/**\n * The frames play changed, each kept as a private copy so the document never changes. Frames move\n * through the session as before; a Change to switches an instance on its frame's copy, which is\n * made at the first change, so a prototype without one copies nothing.\n */\nexport interface PlayScenes {\n /** The graph play reads a top-level frame from: its copy once changed, else the document. */\n graphFor(rootId: string): SceneGraph\n /**\n * A fresh copy of `rootId` with the session's variable values and modes applied, for a caller\n * that must keep the state it sees after play moves on (a video's earlier frames).\n */\n cloneGraphFor(rootId: string): SceneGraph\n /**\n * The action a Conditional would run now, resolving nested conditionals; a condition this build\n * cannot evaluate is refused with its reason.\n */\n resolve(\n action: PrototypeAction,\n rootId?: string\n ): { action: PrototypeAction } | { refused: string }\n /**\n * The actions of the first matching Conditional branch, or `[action]` for any other action; a\n * condition this build cannot evaluate is refused with its reason.\n */\n resolveBranch(\n action: PrototypeAction,\n rootId?: string\n ): { actions: readonly PrototypeAction[] } | { refused: string }\n /** Whether this session has changed a variable's value or a collection's mode. */\n hasVariables(): boolean\n /** The changed frames the canvas draws from their copies, by frame id. */\n readonly views: ReadonlyMap<string, PlaySceneView>\n /** How far play scrolled each frame that scrolls, by frame id. */\n readonly scroll: ReadonlyMap<string, Vector>\n /**\n * Scrolls the frames along `path`, a pointer's path in `rootId`, innermost first, and returns\n * what none of them could take, for the canvas to pan by.\n */\n scrollBy(rootId: string, path: readonly string[], dx: number, dy: number): Vector\n /** Sets one frame's offset, as an animated Scroll to steps it toward where it ends. */\n setScroll(id: string, offset: Vector): void\n /** Runs a reaction of a layer in `rootId`, the shown frame unless a timer names another. */\n run(session: PlaySession, click: PlayClick, rootId?: string): PlayStep\n /**\n * Undoes a While hovering or While pressing reaction, unless play moved on from what it did: an\n * instance that shows another variant by now, or an overlay or frame no longer shown.\n */\n revert(session: PlaySession, revert: PlayRevert): PlayStep\n /**\n * The After delay reactions of the instances `rootId` shows and of the copies inside them, by\n * the variants and main layers they stand for now.\n */\n instanceTimeouts(rootId: string): PlayTimeout[]\n /**\n * Drops the copies of frames that hold any of these document layers, after an edit to them:\n * the frame's own layers and the variants its copy holds.\n */\n forget(nodeIds: Iterable<string>): void\n clear(): void\n}\n\nexport function createPlayScenes(\n getDocument: () => SceneGraph,\n limit = PLAY_SCENE_LIMIT\n): PlayScenes {\n // Insertion order is use order: a frame changed again moves to the end, and the first goes.\n const scenes = new Map<string, PlayScene>()\n const scroll = new Map<string, Vector>()\n // The play session's variable values and mode overrides, applied only to frame copies.\n const values = new Map<string, PrototypeResolvedValue>()\n const modes = new Map<string, string>()\n\n function literalOf(value: VariableValue | undefined): PrototypeResolvedValue | undefined {\n if (typeof value === 'boolean' || typeof value === 'number' || typeof value === 'string')\n return value\n if (value && typeof value === 'object' && 'r' in value) return value\n return undefined\n }\n\n function valueOf(variableId: string, rootId?: string): PrototypeResolvedValue | undefined {\n const overlay = values.get(variableId)\n if (overlay !== undefined) return overlay\n const frame = rootId ? graphFor(rootId).getNode(rootId) : undefined\n const variable = (rootId ? graphFor(rootId).variables : getDocument().variables).get(variableId)\n if (!variable) return undefined\n const frameMode = frame ? frame.variableModes[variable.collectionId] : undefined\n const defaultMode = getDocument().variableCollections.get(variable.collectionId)?.modes[0]\n ?.modeId\n const mode = modes.get(variable.collectionId) ?? frameMode ?? defaultMode\n return mode ? literalOf(variable.valuesByMode[mode]) : undefined\n }\n\n function applyVariables(graph: SceneGraph): void {\n // A play scene shares the document's variable table; copy it before an override touches it.\n if (graph.variables === getDocument().variables) graph.variables = new Map(graph.variables)\n const root = [...graph.getAllNodes()].find((node) => node.parentId === null)\n for (const [variableId, value] of values) {\n const variable = graph.variables.get(variableId)\n if (!variable) continue\n const rootMode = root ? root.variableModes[variable.collectionId] : undefined\n const defaultMode = graph.variableCollections.get(variable.collectionId)?.modes[0]?.modeId\n const mode = modes.get(variable.collectionId) ?? rootMode ?? defaultMode\n if (mode)\n graph.variables.set(variableId, {\n ...variable,\n valuesByMode: { ...variable.valuesByMode, [mode]: value }\n })\n }\n if (modes.size === 0) return\n for (const node of graph.getAllNodes()) {\n const overrides = { ...node.variableModes }\n for (const [collectionId, modeId] of modes) overrides[collectionId] = modeId\n graph.updateNode(node.id, { variableModes: overrides })\n }\n }\n\n function sceneFor(rootId: string): PlayScene {\n const existing = scenes.get(rootId)\n if (existing) return existing\n const scene = createPlayScene(getDocument(), rootId)\n applyVariables(scene.graph)\n scenes.set(rootId, scene)\n return scene\n }\n\n function graphFor(rootId: string): SceneGraph {\n if (values.size === 0 && modes.size === 0) return scenes.get(rootId)?.graph ?? getDocument()\n return sceneFor(rootId).graph\n }\n\n /**\n * The frame as play shows it before a change: the document while play has not changed it, else\n * a copy of play's copy, which the change is about to edit in place.\n */\n function frameBefore(rootId: string): PlayFrame {\n const scene = scenes.get(rootId)\n if (!scene) return { graph: getDocument(), rootId }\n const pageId = findPageId(scene.graph, rootId) ?? scene.graph.rootId\n return {\n graph: extractPageContext(scene.graph, pageId, [rootId], { shareTables: true }),\n rootId\n }\n }\n\n /**\n * Runs a Change to on `rootId`'s copy, and with a Smart animate transition the animation from the\n * frame as it was.\n */\n function changeWith(\n rootId: string,\n sourceId: string,\n variantId: string,\n transition: PrototypeTransition | null\n ): Pick<PlayStep, 'changed' | 'animation'> {\n const smart = transition?.type === 'SMART_ANIMATE' && transition.duration > 0\n const before = smart && changeTarget(graphFor(rootId), rootId, sourceId, variantId)\n const from = before ? frameBefore(rootId) : null\n const changed = changeIn(rootId, sourceId, variantId)\n if (!changed || !from) return { changed }\n const to = { graph: graphFor(rootId), rootId }\n return {\n changed,\n animation: createSmartAnimation(from, to, transition?.easing, {\n curve: transition?.easingCurve,\n spring: transition?.easingSpring,\n duration: transition?.duration\n })\n }\n }\n\n function changeIn(rootId: string, sourceId: string, variantId: string): PlayChange | null {\n // Checked on what play shows now, so a Change to that cannot run copies nothing.\n if (!changeTarget(graphFor(rootId), rootId, sourceId, variantId)) return null\n const scene = sceneFor(rootId)\n const change = scene.changeTo(sourceId, variantId)\n scenes.delete(rootId)\n scenes.set(rootId, scene)\n for (const oldest of scenes.keys()) {\n if (scenes.size <= limit) break\n scenes.delete(oldest)\n }\n // What the switched instance holds may be shorter now than a frame scrolled past.\n if (change) clampScroll(scene.graph, scroll)\n return change\n }\n\n function setVariableStep(\n session: PlaySession,\n action: PrototypeSetVariableAction,\n rootId: string\n ): PlayStep {\n if (!action.variableId) return { session, changed: null, action }\n const result = evaluateVariable(action.value, (id) => valueOf(id, rootId))\n if (!result.ok) return { session, changed: null, variablesRefused: result.reason, action }\n values.set(action.variableId, result.value)\n applyVariables(graphFor(rootId))\n return { session, changed: null, repaint: true, action }\n }\n\n function setModeStep(\n session: PlaySession,\n action: PrototypeSetVariableModeAction,\n rootId: string\n ): PlayStep {\n if (!action.collectionId || !action.modeId) return { session, changed: null, action }\n modes.set(action.collectionId, action.modeId)\n applyVariables(graphFor(rootId))\n return { session, changed: null, repaint: true, action }\n }\n\n /** Whether an evaluated variable counts as true for a Conditional. */\n function truthy(value: PrototypeResolvedValue): boolean {\n return (\n value === true ||\n (typeof value === 'number' && value !== 0) ||\n (typeof value === 'string' && value.length > 0)\n )\n }\n\n function takenBranch(\n action: PrototypeConditionalAction,\n rootId?: string\n ): { actions: readonly PrototypeAction[] } | { refused: string } {\n for (const block of action.blocks) {\n if (block.condition) {\n const result = evaluateVariable(block.condition, (id) => valueOf(id, rootId))\n if (!result.ok) return { refused: result.reason }\n if (!truthy(result.value)) continue\n }\n return { actions: block.actions }\n }\n return { actions: [] }\n }\n\n function resolveBranch(\n action: PrototypeAction,\n rootId?: string\n ): { actions: readonly PrototypeAction[] } | { refused: string } {\n if (action.type !== 'CONDITIONAL') return { actions: [action] }\n return takenBranch(action, rootId)\n }\n\n /** The first branch's action whose condition holds, resolving nested conditionals. */\n function resolveAction(\n action: PrototypeAction,\n rootId?: string\n ): { action: PrototypeAction } | { refused: string } {\n if (action.type !== 'CONDITIONAL') return { action }\n const branch = takenBranch(action, rootId)\n if ('refused' in branch) return branch\n if (branch.actions.length === 0) return { action }\n return resolveAction(branch.actions[0], rootId)\n }\n\n function mergeStep(target: PlayStep, next: PlayStep): void {\n target.session = next.session\n if (next.changed) target.changed = next.changed\n if (next.repaint) target.repaint = true\n if (next.scrolled?.length) target.scrolled = [...(target.scrolled ?? []), ...next.scrolled]\n if (next.reveal !== undefined) target.reveal = next.reveal\n if (next.animation) target.animation = next.animation\n }\n\n function conditionalStep(\n session: PlaySession,\n action: PrototypeConditionalAction,\n sourceId: string,\n rootId: string\n ): PlayStep {\n const branch = takenBranch(action, rootId)\n if ('refused' in branch) {\n return { session, changed: null, variablesRefused: branch.refused, action }\n }\n if (branch.actions.length === 0) return { session, changed: null, action }\n const merged: PlayStep = { session, changed: null, action }\n let currentRoot = rootId\n let primary: PrototypeAction | undefined\n for (const item of branch.actions) {\n const prevSession = merged.session\n const transition = item.type === 'NODE' ? item.transition : null\n const next = runAction(prevSession, { sourceId, action: item, transition }, currentRoot)\n mergeStep(merged, next)\n if (next.session !== prevSession) currentRoot = shownFrame(next.session)\n const transitioned =\n next.session !== prevSession ||\n next.changed !== null ||\n Boolean(next.animation) ||\n Boolean(next.scrolled?.length)\n if (next.action) {\n merged.action = next.action\n if (transitioned) primary = next.action\n }\n if (next.variablesRefused) {\n merged.variablesRefused = next.variablesRefused\n return merged\n }\n }\n if (primary) merged.action = primary\n return merged\n }\n\n function runAction(session: PlaySession, click: PlayClick, rootId: string): PlayStep {\n const { sourceId, action } = click\n if (action.type === 'SET_VARIABLE') return setVariableStep(session, action, rootId)\n if (action.type === 'SET_VARIABLE_MODE') return setModeStep(session, action, rootId)\n if (action.type === 'CONDITIONAL') return conditionalStep(session, action, sourceId, rootId)\n if (action.type === 'NODE' && action.navigation === 'CHANGE_TO') {\n if (!action.nodeId) return { session, changed: null, action }\n return { session, action, ...changeWith(rootId, sourceId, action.nodeId, action.transition) }\n }\n if (action.type === 'NODE' && action.navigation === 'SCROLL_TO') {\n if (!action.nodeId) return { session, changed: null, scrolled: [], reveal: null, action }\n const moved = scrollIntoView(graphFor(rootId), scroll, rootId, action.nodeId)\n return { session, changed: null, action, ...moved }\n }\n return { session: step(getDocument(), session, action), changed: null, action }\n }\n\n return {\n graphFor,\n cloneGraphFor(rootId) {\n const copy = createPlayScene(getDocument(), rootId)\n applyVariables(copy.graph)\n return copy.graph\n },\n resolve: resolveAction,\n resolveBranch,\n hasVariables: () => values.size > 0 || modes.size > 0,\n views: scenes,\n scroll,\n scrollBy(rootId, path, dx, dy) {\n return scrollAlong(graphFor(rootId), scroll, path, dx, dy)\n },\n setScroll(id, offset) {\n scroll.set(id, offset)\n },\n run(session, click, rootId = shownFrame(session)) {\n return runAction(session, click, rootId)\n },\n revert(session, revert) {\n if (revert.kind === 'change') {\n const graph = graphFor(revert.rootId)\n const instance = graph.getNode(revert.instanceId)\n if (!instance || instanceMainComponent(graph, instance)?.id !== revert.to) {\n return { session, changed: null }\n }\n const { rootId, instanceId, from, transition } = revert\n return { session, ...changeWith(rootId, instanceId, from, transition) }\n }\n const shown =\n revert.kind === 'overlay'\n ? session.overlays.at(-1) === revert.frameId\n : session.frameId === revert.frameId\n if (!shown) return { session, changed: null }\n const action = { type: revert.kind === 'overlay' ? 'CLOSE' : 'BACK' } as const\n return { session: step(getDocument(), session, action), changed: null }\n },\n instanceTimeouts(rootId) {\n const graph = graphFor(rootId)\n const timeouts: PlayTimeout[] = []\n const sourceOf = componentLayerResolver(graph)\n const collect = (node: SceneNode, variantId: string, inherited: PrototypeReaction[]) => {\n for (const reaction of reactionsWithInherited(node, inherited)) {\n const action = reaction.trigger.type === 'AFTER_TIMEOUT' && primaryAction(reaction)\n if (!action) continue\n timeouts.push({\n sourceId: node.id,\n variantId,\n reactionId: reaction.id,\n action,\n delayMs: reaction.trigger.delay * 1000\n })\n }\n }\n const visit = (id: string) => {\n for (const child of graph.getChildren(id)) {\n if (child.type === 'INSTANCE') {\n const main = instanceMainComponent(graph, child)\n if (main) collect(child, main.id, main.prototypeReactions)\n } else {\n // A plain copy inherits its main layer's After delay; the resolver reads each\n // instance's copy map once, so arming costs one search per instance, not per copy.\n const source = sourceOf(child)\n if (source && source.id !== child.id)\n collect(child, source.id, source.prototypeReactions)\n }\n visit(child.id)\n }\n }\n visit(rootId)\n return timeouts\n },\n forget(nodeIds) {\n const design = getDocument()\n for (const id of nodeIds) {\n for (const [rootId, scene] of scenes) {\n // The copy holds the frame and every variant its instances switch to, wherever they\n // are, under the page and document it copied, which an edit elsewhere touches too.\n const copied = scene.graph.getNode(id)\n const held = copied !== undefined && copied.type !== 'CANVAS' && id !== scene.graph.rootId\n if (design.isDescendant(id, rootId) || held) scenes.delete(rootId)\n }\n }\n },\n clear() {\n scenes.clear()\n scroll.clear()\n }\n }\n}\n"],"mappings":";;;;;;;;;;AAmCA,MAAa,mBAAmB;AAqGhC,SAAgB,iBACd,aACA,QAAA,GACY;CAEZ,MAAM,yBAAS,IAAI,IAAuB;CAC1C,MAAM,yBAAS,IAAI,IAAoB;CAEvC,MAAM,yBAAS,IAAI,IAAoC;CACvD,MAAM,wBAAQ,IAAI,IAAoB;CAEtC,SAAS,UAAU,OAAsE;EACvF,IAAI,OAAO,UAAU,aAAa,OAAO,UAAU,YAAY,OAAO,UAAU,UAC9E,OAAO;EACT,IAAI,SAAS,OAAO,UAAU,YAAY,OAAO,OAAO,OAAO;C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S,YAAY,OAAO,MAAM,MAAM;IACpF,IAAI,OAAO,aAAa,IAAI,MAAM,KAAK,MAAM,OAAO,OAAO,MAAM;GACnE;EAEJ;EACA,QAAQ;GACN,OAAO,MAAM;GACb,OAAO,MAAM;EACf;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"session.d.ts","names":[],"sources":["../../src/prototype/session.ts"],"mappings":";;;;;;;iBAkBgB,cAAc,UAAU,oBAAoB;;UAK3C;;EAEf;;EAEA;;EAEA;;EAEA;;;;;;UAOe;;EAEf;EACA,QAAQ;EACR,YAAY;;;;;;iBAOE,WAAW,OAAO,YAAY,gBAAgB,aAAa;;;;;iBAe3D,WACd,OAAO,YACP,MAAM,+BACL;;iBAWa,aAAa,kBAAkB;;iBAK/B,WAAW,SAAS;;iBAKpB,eAAe,SAAS,cAAc;;;;;;;;iBAWtC,WACd,OAAO,YACP,SAAS,aACT,WACA,WACA,UAAS,sBACT,SAAS,oBAAoB,UAC5B;;;;;;;iBA8Ba,KACd,OAAO,YACP,SAAS,aACT,QAAQ,kBACP;;;;;iBAkCa,iBACd,OAAO,YACP,SAAS;EACN,QAAQ;EAAiB"}
1
+ {"version":3,"file":"session.d.ts","names":[],"sources":["../../src/prototype/session.ts"],"mappings":";;;;;;;iBAkBgB,cAAc,UAAU,oBAAoB;;UAK3C;;EAEf;;EAEA;;EAEA;;EAEA;;;;;;UAOe;;EAEf;EACA,QAAQ;EACR,YAAY;;;;;;iBAOE,WAAW,OAAO,YAAY,gBAAgB,aAAa;;;;;iBAe3D,WACd,OAAO,YACP,MAAM,+BACL;;iBAWa,aAAa,kBAAkB;;iBAK/B,WAAW,SAAS;;iBAKpB,eAAe,SAAS,cAAc;;;;;;;;iBAWtC,WACd,OAAO,YACP,SAAS,aACT,WACA,WACA,UAAS,sBACT,SAAS,oBAAoB,UAC5B;;;;;;;iBA8Ba,KACd,OAAO,YACP,SAAS,aACT,QAAQ,kBACP;;;;;iBAmCa,iBACd,OAAO,YACP,SAAS;EACN,QAAQ;EAAiB"}
@@ -100,6 +100,7 @@ function step(graph, session, action) {
100
100
  overlays: session.overlays.slice(0, -1)
101
101
  };
102
102
  }
103
+ if (action.type !== "NODE") return session;
103
104
  if (!action.nodeId) return session;
104
105
  if (topFrameOf(graph, graph.getNode(action.nodeId))?.id !== action.nodeId) return session;
105
106
  if (action.navigation === "OVERLAY") {
@@ -1 +1 @@
1
- {"version":3,"file":"session.js","names":[],"sources":["../../src/prototype/session.ts"],"sourcesContent":["import type {\n PrototypeAction,\n PrototypeReaction,\n PrototypeTransition,\n PrototypeTriggerType,\n SceneGraph,\n SceneNode\n} from '@pairdraw/scene-graph'\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\n\nimport { framesOnPage } from './frames'\nimport { playHitTest } from './hit'\nimport { effectiveReactions } from './reactions'\n\n/**\n * The action a reaction runs: its first, which the prototype panel edits alone in this version, as\n * Figma's first action row; `actions` keeps the array the `.fig` model and Figma's plugin API use.\n */\nexport function primaryAction(reaction: PrototypeReaction): PrototypeAction | null {\n return reaction.actions[0] ?? null\n}\n\n/** Where play is: the frame it shows, the frame it started from, and the frames it came through. */\nexport interface PlaySession {\n /** The base frame under any open overlays. */\n frameId: string\n /** The frame play started from, which Restart returns to. */\n startFrameId: string\n /** Frames shown before this one, oldest first; Back returns to the last. */\n history: string[]\n /** Overlay frames open over the base frame, bottom first; the last is the one shown. */\n overlays: string[]\n}\n\n/**\n * One reaction a pointer or a timer runs: the layer it runs from, its action, and the transition\n * that action asked for.\n */\nexport interface PlayClick {\n /** The layer whose reaction runs, which a Change to switches the instance of. */\n sourceId: string\n action: PrototypeAction\n transition: PrototypeTransition | null\n}\n\n/**\n * The frame play starts from: the selected frame, or the frame holding the selection; otherwise\n * the page's first frame. Null when the page has no frames, so there is nothing to play.\n */\nexport function startFrame(graph: SceneGraph, pageId: string, selectedIds: ReadonlySet<string>) {\n const frames = framesOnPage(graph, pageId)\n const ids = new Set(frames.map((frame) => frame.id))\n for (const id of selectedIds) {\n if (ids.has(id)) return id\n const frame = topFrameOf(graph, graph.getNode(id))\n if (frame && ids.has(frame.id)) return frame.id\n }\n return frames[0]?.id ?? null\n}\n\n/**\n * The top-level frame a node sits in: the page's direct child above it, when that child is a\n * frame. Play fits and hit-tests top-level frames, as Figma's presentation does.\n */\nexport function topFrameOf(\n graph: SceneGraph,\n node: SceneNode | null | undefined\n): SceneNode | null {\n let top = node ?? null\n while (top?.parentId) {\n const parent = graph.getNode(top.parentId)\n if (!parent || parent.type === 'CANVAS') break\n top = parent\n }\n return top?.type === 'FRAME' ? top : null\n}\n\n/** Starts playing the page from `frameId` with no history behind it. */\nexport function startSession(frameId: string): PlaySession {\n return { frameId, startFrameId: frameId, history: [], overlays: [] }\n}\n\n/** The frame the stage shows: the top overlay when one is open, else the base frame. */\nexport function shownFrame(session: PlaySession): string {\n return session.overlays.at(-1) ?? session.frameId\n}\n\n/** Plays again from where the session started, as Restart does. */\nexport function restartSession(session: PlaySession): PlaySession {\n return startSession(session.startFrameId)\n}\n\n/**\n * The reaction a click at a document point runs: the topmost layer under the point inside the\n * shown frame that has a reaction to `trigger`, over its whole box, or that shows a paint there,\n * and then its nearest ancestor with one, up to the frame, with the reaction's first action. An\n * unpainted layer without one lets the click through. An instance runs the reactions of the variant it shows, and a frame\n * play scrolled finds its layers where they are drawn.\n */\nexport function reactionAt(\n graph: SceneGraph,\n session: PlaySession,\n x: number,\n y: number,\n trigger: PrototypeTriggerType = 'ON_CLICK',\n scroll?: ReadonlyMap<string, Vector>\n): PlayClick | null {\n // A click on the frame's own background is the frame's, not a layer's; one outside it hits\n // nothing.\n const reacts = (layer: SceneNode) =>\n effectiveReactions(graph, layer).some((reaction) => reaction.trigger.type === trigger)\n let node = playHitTest(graph, shownFrame(session), x, y, scroll, reacts)\n while (node) {\n const reaction = effectiveReactions(graph, node).find(\n (candidate) => candidate.trigger.type === trigger\n )\n const action = reaction ? primaryAction(reaction) : null\n if (action) {\n return {\n sourceId: node.id,\n action,\n transition: action.type === 'NODE' ? action.transition : null\n }\n }\n if (node.id === shownFrame(session)) return null\n node = node.parentId ? (graph.getNode(node.parentId) ?? null) : null\n }\n return null\n}\n\n/**\n * The session after an action runs. `NAVIGATE` moves to its frame and remembers this one for\n * Back; `OVERLAY` opens a frame over the screen and `CLOSE` takes the top one away; `BACK`\n * returns to the previous screen and drops overlays, which are not history entries; an action\n * this version cannot show leaves the session as it is.\n */\nexport function step(\n graph: SceneGraph,\n session: PlaySession,\n action: PrototypeAction\n): PlaySession {\n if (action.type === 'BACK') {\n const previous = session.history.at(-1)\n if (!previous) return session\n return {\n ...session,\n frameId: previous,\n history: session.history.slice(0, -1),\n overlays: []\n }\n }\n if (action.type === 'CLOSE') {\n if (session.overlays.length === 0) return session\n return { ...session, overlays: session.overlays.slice(0, -1) }\n }\n if (!action.nodeId) return session\n if (topFrameOf(graph, graph.getNode(action.nodeId))?.id !== action.nodeId) return session\n if (action.navigation === 'OVERLAY') {\n if (action.nodeId === shownFrame(session)) return session\n return { ...session, overlays: [...session.overlays, action.nodeId] }\n }\n if (action.nodeId === session.frameId) return session\n return {\n ...session,\n frameId: action.nodeId,\n history: [...session.history, session.frameId],\n overlays: []\n }\n}\n\n/**\n * The `AFTER_TIMEOUT` reactions of the frame being shown, with their delays in milliseconds:\n * what the stage schedules whenever the shown frame changes.\n */\nexport function timeoutReactions(\n graph: SceneGraph,\n session: PlaySession\n): { action: PrototypeAction; delayMs: number }[] {\n const node = graph.getNode(shownFrame(session))\n if (!node) return []\n return node.prototypeReactions\n .filter((reaction) => reaction.trigger.type === 'AFTER_TIMEOUT')\n .map((reaction) => ({\n action: primaryAction(reaction),\n delayMs: reaction.trigger.delay * 1000\n }))\n .filter((entry): entry is { action: PrototypeAction; delayMs: number } => entry.action !== null)\n}\n"],"mappings":";;;;;;;;AAkBA,SAAgB,cAAc,UAAqD;CACjF,OAAO,SAAS,QAAQ,MAAM;AAChC;;;;;AA6BA,SAAgB,WAAW,OAAmB,QAAgB,aAAkC;CA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,SAAS,eAAe,CAAC,CAC/D,KAAK,cAAc;EAClB,QAAQ,cAAc,QAAQ;EAC9B,SAAS,SAAS,QAAQ,QAAQ;CACpC,EAAE,CAAC,CACF,QAAQ,UAAiE,MAAM,WAAW,IAAI;AACnG"}
1
+ {"version":3,"file":"session.js","names":[],"sources":["../../src/prototype/session.ts"],"sourcesContent":["import type {\n PrototypeAction,\n PrototypeReaction,\n PrototypeTransition,\n PrototypeTriggerType,\n SceneGraph,\n SceneNode\n} from '@pairdraw/scene-graph'\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\n\nimport { framesOnPage } from './frames'\nimport { playHitTest } from './hit'\nimport { effectiveReactions } from './reactions'\n\n/**\n * The action a reaction runs: its first, which the prototype panel edits alone in this version, as\n * Figma's first action row; `actions` keeps the array the `.fig` model and Figma's plugin API use.\n */\nexport function primaryAction(reaction: PrototypeReaction): PrototypeAction | null {\n return reaction.actions[0] ?? null\n}\n\n/** Where play is: the frame it shows, the frame it started from, and the frames it came through. */\nexport interface PlaySession {\n /** The base frame under any open overlays. */\n frameId: string\n /** The frame play started from, which Restart returns to. */\n startFrameId: string\n /** Frames shown before this one, oldest first; Back returns to the last. */\n history: string[]\n /** Overlay frames open over the base frame, bottom first; the last is the one shown. */\n overlays: string[]\n}\n\n/**\n * One reaction a pointer or a timer runs: the layer it runs from, its action, and the transition\n * that action asked for.\n */\nexport interface PlayClick {\n /** The layer whose reaction runs, which a Change to switches the instance of. */\n sourceId: string\n action: PrototypeAction\n transition: PrototypeTransition | null\n}\n\n/**\n * The frame play starts from: the selected frame, or the frame holding the selection; otherwise\n * the page's first frame. Null when the page has no frames, so there is nothing to play.\n */\nexport function startFrame(graph: SceneGraph, pageId: string, selectedIds: ReadonlySet<string>) {\n const frames = framesOnPage(graph, pageId)\n const ids = new Set(frames.map((frame) => frame.id))\n for (const id of selectedIds) {\n if (ids.has(id)) return id\n const frame = topFrameOf(graph, graph.getNode(id))\n if (frame && ids.has(frame.id)) return frame.id\n }\n return frames[0]?.id ?? null\n}\n\n/**\n * The top-level frame a node sits in: the page's direct child above it, when that child is a\n * frame. Play fits and hit-tests top-level frames, as Figma's presentation does.\n */\nexport function topFrameOf(\n graph: SceneGraph,\n node: SceneNode | null | undefined\n): SceneNode | null {\n let top = node ?? null\n while (top?.parentId) {\n const parent = graph.getNode(top.parentId)\n if (!parent || parent.type === 'CANVAS') break\n top = parent\n }\n return top?.type === 'FRAME' ? top : null\n}\n\n/** Starts playing the page from `frameId` with no history behind it. */\nexport function startSession(frameId: string): PlaySession {\n return { frameId, startFrameId: frameId, history: [], overlays: [] }\n}\n\n/** The frame the stage shows: the top overlay when one is open, else the base frame. */\nexport function shownFrame(session: PlaySession): string {\n return session.overlays.at(-1) ?? session.frameId\n}\n\n/** Plays again from where the session started, as Restart does. */\nexport function restartSession(session: PlaySession): PlaySession {\n return startSession(session.startFrameId)\n}\n\n/**\n * The reaction a click at a document point runs: the topmost layer under the point inside the\n * shown frame that has a reaction to `trigger`, over its whole box, or that shows a paint there,\n * and then its nearest ancestor with one, up to the frame, with the reaction's first action. An\n * unpainted layer without one lets the click through. An instance runs the reactions of the variant it shows, and a frame\n * play scrolled finds its layers where they are drawn.\n */\nexport function reactionAt(\n graph: SceneGraph,\n session: PlaySession,\n x: number,\n y: number,\n trigger: PrototypeTriggerType = 'ON_CLICK',\n scroll?: ReadonlyMap<string, Vector>\n): PlayClick | null {\n // A click on the frame's own background is the frame's, not a layer's; one outside it hits\n // nothing.\n const reacts = (layer: SceneNode) =>\n effectiveReactions(graph, layer).some((reaction) => reaction.trigger.type === trigger)\n let node = playHitTest(graph, shownFrame(session), x, y, scroll, reacts)\n while (node) {\n const reaction = effectiveReactions(graph, node).find(\n (candidate) => candidate.trigger.type === trigger\n )\n const action = reaction ? primaryAction(reaction) : null\n if (action) {\n return {\n sourceId: node.id,\n action,\n transition: action.type === 'NODE' ? action.transition : null\n }\n }\n if (node.id === shownFrame(session)) return null\n node = node.parentId ? (graph.getNode(node.parentId) ?? null) : null\n }\n return null\n}\n\n/**\n * The session after an action runs. `NAVIGATE` moves to its frame and remembers this one for\n * Back; `OVERLAY` opens a frame over the screen and `CLOSE` takes the top one away; `BACK`\n * returns to the previous screen and drops overlays, which are not history entries; an action\n * this version cannot show leaves the session as it is.\n */\nexport function step(\n graph: SceneGraph,\n session: PlaySession,\n action: PrototypeAction\n): PlaySession {\n if (action.type === 'BACK') {\n const previous = session.history.at(-1)\n if (!previous) return session\n return {\n ...session,\n frameId: previous,\n history: session.history.slice(0, -1),\n overlays: []\n }\n }\n if (action.type === 'CLOSE') {\n if (session.overlays.length === 0) return session\n return { ...session, overlays: session.overlays.slice(0, -1) }\n }\n if (action.type !== 'NODE') return session\n if (!action.nodeId) return session\n if (topFrameOf(graph, graph.getNode(action.nodeId))?.id !== action.nodeId) return session\n if (action.navigation === 'OVERLAY') {\n if (action.nodeId === shownFrame(session)) return session\n return { ...session, overlays: [...session.overlays, action.nodeId] }\n }\n if (action.nodeId === session.frameId) return session\n return {\n ...session,\n frameId: action.nodeId,\n history: [...session.history, session.frameId],\n overlays: []\n }\n}\n\n/**\n * The `AFTER_TIMEOUT` reactions of the frame being shown, with their delays in milliseconds:\n * what the stage schedules whenever the shown frame changes.\n */\nexport function timeoutReactions(\n graph: SceneGraph,\n session: PlaySession\n): { action: PrototypeAction; delayMs: number }[] {\n const node = graph.getNode(shownFrame(session))\n if (!node) return []\n return node.prototypeReactions\n .filter((reaction) => reaction.trigger.type === 'AFTER_TIMEOUT')\n .map((reaction) => ({\n action: primaryAction(reaction),\n delayMs: reaction.trigger.delay * 1000\n }))\n .filter((entry): entry is { action: PrototypeAction; delayMs: number } => entry.action !== null)\n}\n"],"mappings":";;;;;;;;AAkBA,SAAgB,cAAc,UAAqD;CACjF,OAAO,SAAS,QAAQ,MAAM;AAChC;;;;;AA6BA,SAAgB,WAAW,OAAmB,QAAgB,aAAkC;CAC9F,MAAM,SAAS,aAAa,OAAO,MAAM;CACzC,MAAM,MAAM,IAAI,IAA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D,KAAK,cAAc;EAClB,QAAQ,cAAc,QAAQ;EAC9B,SAAS,SAAS,QAAQ,QAAQ;CACpC,EAAE,CAAC,CACF,QAAQ,UAAiE,MAAM,WAAW,IAAI;AACnG"}
@@ -1,3 +1,4 @@
1
+ import { EasingPlayback } from "../easing.js";
1
2
  import { PlaySceneView } from "../scene.js";
2
3
  import { PrototypeEasingType, SceneGraph } from "@pairdraw/scene-graph";
3
4
  //#region src/prototype/smart-animate/animation.d.ts
@@ -28,7 +29,7 @@ interface SmartAnimation extends PlaySceneView {
28
29
  * keeps its place and size and blends its fill. Neither frame changes. Matching and the copy cost
29
30
  * one pass when it is made; a step writes only the layers that change.
30
31
  */
31
- declare function createSmartAnimation(from: PlayFrame, to: PlayFrame, easing?: PrototypeEasingType): SmartAnimation;
32
+ declare function createSmartAnimation(from: PlayFrame, to: PlayFrame, easing?: PrototypeEasingType, playback?: EasingPlayback): SmartAnimation;
32
33
  //#endregion
33
34
  export { PlayFrame, SmartAnimation, createSmartAnimation };
34
35
  //# sourceMappingURL=animation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"animation.d.ts","names":[],"sources":["../../../src/prototype/smart-animate/animation.ts"],"mappings":";;;;UAUiB;EACf,OAAO;EACP;;;;;;;UAQe,uBAAuB;;WAE7B;;;;;EAKT,KAAK;;;;;;;;;;iBAiMS,qBACd,MAAM,WACN,IAAI,WACJ,SAAS,sBACR"}
1
+ {"version":3,"file":"animation.d.ts","names":[],"sources":["../../../src/prototype/smart-animate/animation.ts"],"mappings":";;;;;UAUiB;EACf,OAAO;EACP;;;;;;;UAQe,uBAAuB;;WAE7B;;;;;EAKT,KAAK;;;;;;;;;;iBAiMS,qBACd,MAAM,WACN,IAAI,WACJ,SAAS,qBACT,WAAW,iBACV"}
@@ -170,7 +170,7 @@ function animationTracks(from, graph, rootId) {
170
170
  * keeps its place and size and blends its fill. Neither frame changes. Matching and the copy cost
171
171
  * one pass when it is made; a step writes only the layers that change.
172
172
  */
173
- function createSmartAnimation(from, to, easing) {
173
+ function createSmartAnimation(from, to, easing, playback) {
174
174
  const pageId = findPageId(to.graph, to.rootId) ?? to.graph.rootId;
175
175
  const graph = extractPageContext(to.graph, pageId, [to.rootId], { shareTables: true });
176
176
  const tracks = animationTracks(from, graph, to.rootId);
@@ -180,7 +180,7 @@ function createSmartAnimation(from, to, easing) {
180
180
  return node.id === to.rootId;
181
181
  });
182
182
  function pose(progress) {
183
- const amount = easingAt(easing, progress);
183
+ const amount = easingAt(easing, progress, playback);
184
184
  for (const track of tracks) {
185
185
  const changes = {};
186
186
  for (const { field, from: start, to: end } of track.numbers) {
@@ -1 +1 @@
1
- {"version":3,"file":"animation.js","names":[],"sources":["../../../src/prototype/smart-animate/animation.ts"],"sourcesContent":["import type { Fill, PrototypeEasingType, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport type { Color } from '@pairdraw/scene-graph/primitives'\n\nimport { extractPageContext, findPageId } from '#core/io/subgraph'\nimport { easingAt } from '#core/prototype/easing'\nimport type { PlaySceneView } from '#core/prototype/scene'\n\nimport { matchLayers } from './match'\n\n/** A top-level frame and the graph play reads it from: the document, or play's copy of it. */\nexport interface PlayFrame {\n graph: SceneGraph\n rootId: string\n}\n\n/**\n * A Smart animate from one frame to another, drawn as a view of the destination frame: a private\n * copy of it, which `seek` poses at a moment of the transition. The canvas draws `graph` in place\n * of `rootId` and redraws `touched` whenever `revision` grows; a recording draws it the same way.\n */\nexport interface SmartAnimation extends PlaySceneView {\n /** The destination frame, which the copy draws in its place. */\n readonly rootId: string\n /**\n * Poses the copy `progress` of the way through the transition's time, from 0 to 1, eased as the\n * transition asks. Writes only the layers that change.\n */\n seek(progress: number): void\n}\n\n/** The numbers Smart animate moves from one layer's value to its match's. */\nconst ANIMATED_FIELDS = [\n 'x',\n 'y',\n 'width',\n 'height',\n 'rotation',\n 'opacity',\n 'cornerRadius',\n 'topLeftRadius',\n 'topRightRadius',\n 'bottomRightRadius',\n 'bottomLeftRadius'\n] as const satisfies readonly (keyof SceneNode)[]\n\ntype AnimatedField = (typeof ANIMATED_FIELDS)[number]\n\n/** One field moving from `from` to `to`. */\ninterface NumberTrack {\n field: AnimatedField\n from: number\n to: number\n}\n\n/** A layer of the copy and what moves on it: numbers, and solid fills whose colours blend. */\ninterface LayerTrack {\n id: string\n numbers: NumberTrack[]\n fills: { from: readonly Fill[]; to: readonly Fill[] } | null\n}\n\n/** A copy's own id for a layer of the start frame that fades out, which never names a real one. */\nfunction leavingId(id: string): string {\n return `smart-animate:${id}`\n}\n\nfunction lerp(from: number, to: number, amount: number): number {\n return from + (to - from) * amount\n}\n\n/** Wraps an angle into (-180, 180], the range a layer's rotation keeps. */\nfunction wrapAngle(degrees: number): number {\n const wrapped = ((degrees % 360) + 360) % 360\n return wrapped > 180 ? wrapped - 360 : wrapped\n}\n\nfunction blend(from: Color, to: Color, amount: number): Color {\n return {\n r: lerp(from.r, to.r, amount),\n g: lerp(from.g, to.g, amount),\n b: lerp(from.b, to.b, amount),\n a: lerp(from.a, to.a, amount)\n }\n}\n\n/**\n * The fills to blend between two layers: lists of the same length whose fills are solid at the\n * same places. Others, and fills that do not differ, take the destination's at once.\n */\nfunction fillTrack(from: readonly Fill[], to: readonly Fill[]): LayerTrack['fills'] {\n if (from.length !== to.length || from.length === 0) return null\n let differs = false\n for (const [index, fill] of to.entries()) {\n const start = from.at(index)\n if (start?.type !== 'SOLID' || fill.type !== 'SOLID') return null\n const { r, g, b, a } = start.color\n const end = fill.color\n if (\n r !== end.r ||\n g !== end.g ||\n b !== end.b ||\n a !== end.a ||\n start.opacity !== fill.opacity\n ) {\n differs = true\n }\n }\n return differs ? { from, to } : null\n}\n\nfunction blendFills(track: NonNullable<LayerTrack['fills']>, amount: number): Fill[] {\n return track.to.map((fill, index) => {\n const start = track.from.at(index)\n if (!start) return fill\n return {\n ...fill,\n color: blend(start.color, fill.color, amount),\n opacity: lerp(start.opacity, fill.opacity, amount)\n }\n })\n}\n\n/** What moves on a matched layer, or null when nothing does. Rotation turns the short way. */\nfunction pairTrack(from: SceneNode, to: SceneNode, fields: readonly AnimatedField[]) {\n const numbers = fields.flatMap((field) => {\n const start = from[field]\n const end = to[field]\n if (start === end) return []\n // Rotation lives in (-180, 180]; across ±180 the short way is under half a turn.\n const delta = field === 'rotation' ? ((((end - start) % 360) + 540) % 360) - 180 : end - start\n return [{ field, from: start, to: start + delta }]\n })\n const fills = fillTrack(from.fills, to.fills)\n return numbers.length > 0 || fills ? { id: to.id, numbers, fills } : null\n}\n\n/**\n * Copies a start-frame layer that fades out, with all it holds, under `parentId` in the copy at\n * `index`, under ids of its own so it never shares a cached drawing with a real layer.\n */\nfunction carryLeaving(\n from: SceneGraph,\n graph: SceneGraph,\n id: string,\n parentId: string,\n index: number\n): string | null {\n const parent = graph.getNode(parentId)\n const source = from.getNode(id)\n if (!parent || !source) return null\n const copy = (node: SceneNode, copyParentId: string): string => {\n const cloned = structuredClone(node)\n cloned.id = leavingId(node.id)\n cloned.parentId = copyParentId\n cloned.childIds = node.childIds.flatMap((childId) => {\n const child = from.getNode(childId)\n return child ? [copy(child, cloned.id)] : []\n })\n graph.nodes.set(cloned.id, cloned)\n return cloned.id\n }\n const copied = copy(source, parent.id)\n const at = Math.min(index, parent.childIds.length)\n parent.childIds = [...parent.childIds.slice(0, at), copied, ...parent.childIds.slice(at)]\n return copied\n}\n\n/** A fade of one layer's opacity, or null for a layer already invisible. */\nfunction fadeTrack(id: string, from: number, to: number): LayerTrack | null {\n return from === to ? null : { id, numbers: [{ field: 'opacity', from, to }], fills: null }\n}\n\n/**\n * What moves in `graph`, the copy of the destination frame `rootId`: its fill, the layers that\n * match the start frame's, the destination's layers that fade in, and the start frame's that fade\n * out, which this carries into the copy under the match of their parent.\n */\nfunction animationTracks(from: PlayFrame, graph: SceneGraph, rootId: string): LayerTrack[] {\n const match = matchLayers(from.graph, from.rootId, graph, rootId)\n const tracks: LayerTrack[] = []\n const add = (track: LayerTrack | null) => {\n if (track) tracks.push(track)\n }\n const fromRoot = from.graph.getNode(from.rootId)\n const toRoot = graph.getNode(rootId)\n if (fromRoot && toRoot) add(pairTrack(fromRoot, toRoot, []))\n const matchOf = new Map<string, string>([[from.rootId, rootId]])\n for (const pair of match.pairs) {\n matchOf.set(pair.from, pair.to)\n const start = from.graph.getNode(pair.from)\n const end = graph.getNode(pair.to)\n if (start && end) add(pairTrack(start, end, ANIMATED_FIELDS))\n }\n // A layer hidden at an end draws nothing there, so it needs no fade: one hidden in both frames\n // costs nothing at all, and one hidden at the far end only fades at the end that shows it.\n for (const id of match.entering) {\n const node = graph.getNode(id)\n if (node?.visible) add(fadeTrack(id, 0, node.opacity))\n }\n for (const id of match.leaving) {\n const node = from.graph.getNode(id)\n if (!node?.visible) continue\n const parentId = node.parentId ? matchOf.get(node.parentId) : undefined\n if (!node.parentId || !parentId) continue\n const index = from.graph.getNode(node.parentId)?.childIds.indexOf(id) ?? 0\n const copied = carryLeaving(from.graph, graph, id, parentId, index)\n if (copied) add(fadeTrack(copied, node.opacity, 0))\n }\n graph.clearAbsPosCache()\n return tracks\n}\n\n/**\n * A Smart animate from `from` to `to`: a copy of the destination frame in which each layer that\n * matches one of the start frame (`matchLayers`) moves from the start layer's position, size,\n * rotation, opacity, corner radius and solid fill colours to its own, the start frame's layers\n * with no match fade out where they were, and the destination's fade in. The destination frame\n * keeps its place and size and blends its fill. Neither frame changes. Matching and the copy cost\n * one pass when it is made; a step writes only the layers that change.\n */\nexport function createSmartAnimation(\n from: PlayFrame,\n to: PlayFrame,\n easing?: PrototypeEasingType\n): SmartAnimation {\n const pageId = findPageId(to.graph, to.rootId) ?? to.graph.rootId\n const graph = extractPageContext(to.graph, pageId, [to.rootId], { shareTables: true })\n const tracks = animationTracks(from, graph, to.rootId)\n\n // A layer's cached drawing holds what it contains, so its frame and the layers between redraw.\n const touched = new Set<string>()\n for (const track of tracks) {\n graph.closest(track.id, (node) => {\n touched.add(node.id)\n return node.id === to.rootId\n })\n }\n\n function pose(progress: number): void {\n const amount = easingAt(easing, progress)\n for (const track of tracks) {\n const changes: Partial<SceneNode> = {}\n for (const { field, from: start, to: end } of track.numbers) {\n const value = lerp(start, end, amount)\n changes[field] = field === 'rotation' ? wrapAngle(value) : value\n }\n if (track.fills) changes.fills = blendFills(track.fills, amount)\n graph.updateNode(track.id, changes)\n }\n }\n\n // Made at its start, so the first drawing shows the start frame's layout.\n pose(0)\n let revision = 0\n return {\n graph,\n rootId: to.rootId,\n touched,\n get revision() {\n return revision\n },\n seek(progress) {\n pose(progress)\n revision += 1\n }\n }\n}\n"],"mappings":";;;;;AA+BA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAmBA,SAAS,UAAU,IAAoB;CACrC,OAAO,iBAAiB;AAC1B;AAEA,SAAS,KAAK,MAAc,IAAY,QAAwB;CAC9D,OAAO,QAAQ,KAAK,QAAQ;AAC9B;;AAGA,SAAS,UAAU,SAAyB;CAC1C,MAAM,WAAY,UAAU,MAAO,OAAO;CAC1C,OAAO,UAAU,MAAM,UAAU,MAAM;AACzC;AAEA,SAAS,MAAM,MAAa,IAAW,QAAuB;CAC5D,OAAO;EACL,GAAG,KAAK,KAAK,GAAG,GAAG,GAAG,MAAM;EAC5B,GAAG,KAAK,KAAK,GAAG,GAAG,GAAG,MAAM;EAC5B,GAAG,KAAK,KAAK,GAAG,GAAG,GAAG,MAAM;EAC5B,GAAG,KAAK,KAAK,GAAG,GAAG,GAAG,MAAM;CAC9B;AACF;;;;;AAMA,SAAS,UAAU,MAAuB,IAA0C;CAClF,IAAI,KAAK,WAAW,GAAG,UAAU,KAAK,WAAW,GAAG,OAAO;CAC3D,IAAI,UAAU;CACd,KAAK,MAAM,CAAC,OAAO,SAAS,GAAG,QAAQ,GAAG;EACxC,MAAM,QAAQ,KAAK,GAAG,KAAK;EAC3B,IAAI,OAAO,SAAS,WAAW,KAAK,SAAS,SAAS,OAAO;EAC7D,MAAM,EAAE,GAAG,GAAG,GAA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AO,MAAM,OAAO,IAAI,SAAS,MAAM,SAAS;IAC3D,MAAM,QAAQ,KAAK,OAAO,KAAK,MAAM;IACrC,QAAQ,SAAS,UAAU,aAAa,UAAU,KAAK,IAAI;GAC7D;GACA,IAAI,MAAM,OAAO,QAAQ,QAAQ,WAAW,MAAM,OAAO,MAAM;GAC/D,MAAM,WAAW,MAAM,IAAI,OAAO;EACpC;CACF;CAGA,KAAK,CAAC;CACN,IAAI,WAAW;CACf,OAAO;EACL;EACA,QAAQ,GAAG;EACX;EACA,IAAI,WAAW;GACb,OAAO;EACT;EACA,KAAK,UAAU;GACb,KAAK,QAAQ;GACb,YAAY;EACd;CACF;AACF"}
1
+ {"version":3,"file":"animation.js","names":[],"sources":["../../../src/prototype/smart-animate/animation.ts"],"sourcesContent":["import type { Fill, PrototypeEasingType, SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport type { Color } from '@pairdraw/scene-graph/primitives'\n\nimport { extractPageContext, findPageId } from '#core/io/subgraph'\nimport { easingAt, type EasingPlayback } from '#core/prototype/easing'\nimport type { PlaySceneView } from '#core/prototype/scene'\n\nimport { matchLayers } from './match'\n\n/** A top-level frame and the graph play reads it from: the document, or play's copy of it. */\nexport interface PlayFrame {\n graph: SceneGraph\n rootId: string\n}\n\n/**\n * A Smart animate from one frame to another, drawn as a view of the destination frame: a private\n * copy of it, which `seek` poses at a moment of the transition. The canvas draws `graph` in place\n * of `rootId` and redraws `touched` whenever `revision` grows; a recording draws it the same way.\n */\nexport interface SmartAnimation extends PlaySceneView {\n /** The destination frame, which the copy draws in its place. */\n readonly rootId: string\n /**\n * Poses the copy `progress` of the way through the transition's time, from 0 to 1, eased as the\n * transition asks. Writes only the layers that change.\n */\n seek(progress: number): void\n}\n\n/** The numbers Smart animate moves from one layer's value to its match's. */\nconst ANIMATED_FIELDS = [\n 'x',\n 'y',\n 'width',\n 'height',\n 'rotation',\n 'opacity',\n 'cornerRadius',\n 'topLeftRadius',\n 'topRightRadius',\n 'bottomRightRadius',\n 'bottomLeftRadius'\n] as const satisfies readonly (keyof SceneNode)[]\n\ntype AnimatedField = (typeof ANIMATED_FIELDS)[number]\n\n/** One field moving from `from` to `to`. */\ninterface NumberTrack {\n field: AnimatedField\n from: number\n to: number\n}\n\n/** A layer of the copy and what moves on it: numbers, and solid fills whose colours blend. */\ninterface LayerTrack {\n id: string\n numbers: NumberTrack[]\n fills: { from: readonly Fill[]; to: readonly Fill[] } | null\n}\n\n/** A copy's own id for a layer of the start frame that fades out, which never names a real one. */\nfunction leavingId(id: string): string {\n return `smart-animate:${id}`\n}\n\nfunction lerp(from: number, to: number, amount: number): number {\n return from + (to - from) * amount\n}\n\n/** Wraps an angle into (-180, 180], the range a layer's rotation keeps. */\nfunction wrapAngle(degrees: number): number {\n const wrapped = ((degrees % 360) + 360) % 360\n return wrapped > 180 ? wrapped - 360 : wrapped\n}\n\nfunction blend(from: Color, to: Color, amount: number): Color {\n return {\n r: lerp(from.r, to.r, amount),\n g: lerp(from.g, to.g, amount),\n b: lerp(from.b, to.b, amount),\n a: lerp(from.a, to.a, amount)\n }\n}\n\n/**\n * The fills to blend between two layers: lists of the same length whose fills are solid at the\n * same places. Others, and fills that do not differ, take the destination's at once.\n */\nfunction fillTrack(from: readonly Fill[], to: readonly Fill[]): LayerTrack['fills'] {\n if (from.length !== to.length || from.length === 0) return null\n let differs = false\n for (const [index, fill] of to.entries()) {\n const start = from.at(index)\n if (start?.type !== 'SOLID' || fill.type !== 'SOLID') return null\n const { r, g, b, a } = start.color\n const end = fill.color\n if (\n r !== end.r ||\n g !== end.g ||\n b !== end.b ||\n a !== end.a ||\n start.opacity !== fill.opacity\n ) {\n differs = true\n }\n }\n return differs ? { from, to } : null\n}\n\nfunction blendFills(track: NonNullable<LayerTrack['fills']>, amount: number): Fill[] {\n return track.to.map((fill, index) => {\n const start = track.from.at(index)\n if (!start) return fill\n return {\n ...fill,\n color: blend(start.color, fill.color, amount),\n opacity: lerp(start.opacity, fill.opacity, amount)\n }\n })\n}\n\n/** What moves on a matched layer, or null when nothing does. Rotation turns the short way. */\nfunction pairTrack(from: SceneNode, to: SceneNode, fields: readonly AnimatedField[]) {\n const numbers = fields.flatMap((field) => {\n const start = from[field]\n const end = to[field]\n if (start === end) return []\n // Rotation lives in (-180, 180]; across ±180 the short way is under half a turn.\n const delta = field === 'rotation' ? ((((end - start) % 360) + 540) % 360) - 180 : end - start\n return [{ field, from: start, to: start + delta }]\n })\n const fills = fillTrack(from.fills, to.fills)\n return numbers.length > 0 || fills ? { id: to.id, numbers, fills } : null\n}\n\n/**\n * Copies a start-frame layer that fades out, with all it holds, under `parentId` in the copy at\n * `index`, under ids of its own so it never shares a cached drawing with a real layer.\n */\nfunction carryLeaving(\n from: SceneGraph,\n graph: SceneGraph,\n id: string,\n parentId: string,\n index: number\n): string | null {\n const parent = graph.getNode(parentId)\n const source = from.getNode(id)\n if (!parent || !source) return null\n const copy = (node: SceneNode, copyParentId: string): string => {\n const cloned = structuredClone(node)\n cloned.id = leavingId(node.id)\n cloned.parentId = copyParentId\n cloned.childIds = node.childIds.flatMap((childId) => {\n const child = from.getNode(childId)\n return child ? [copy(child, cloned.id)] : []\n })\n graph.nodes.set(cloned.id, cloned)\n return cloned.id\n }\n const copied = copy(source, parent.id)\n const at = Math.min(index, parent.childIds.length)\n parent.childIds = [...parent.childIds.slice(0, at), copied, ...parent.childIds.slice(at)]\n return copied\n}\n\n/** A fade of one layer's opacity, or null for a layer already invisible. */\nfunction fadeTrack(id: string, from: number, to: number): LayerTrack | null {\n return from === to ? null : { id, numbers: [{ field: 'opacity', from, to }], fills: null }\n}\n\n/**\n * What moves in `graph`, the copy of the destination frame `rootId`: its fill, the layers that\n * match the start frame's, the destination's layers that fade in, and the start frame's that fade\n * out, which this carries into the copy under the match of their parent.\n */\nfunction animationTracks(from: PlayFrame, graph: SceneGraph, rootId: string): LayerTrack[] {\n const match = matchLayers(from.graph, from.rootId, graph, rootId)\n const tracks: LayerTrack[] = []\n const add = (track: LayerTrack | null) => {\n if (track) tracks.push(track)\n }\n const fromRoot = from.graph.getNode(from.rootId)\n const toRoot = graph.getNode(rootId)\n if (fromRoot && toRoot) add(pairTrack(fromRoot, toRoot, []))\n const matchOf = new Map<string, string>([[from.rootId, rootId]])\n for (const pair of match.pairs) {\n matchOf.set(pair.from, pair.to)\n const start = from.graph.getNode(pair.from)\n const end = graph.getNode(pair.to)\n if (start && end) add(pairTrack(start, end, ANIMATED_FIELDS))\n }\n // A layer hidden at an end draws nothing there, so it needs no fade: one hidden in both frames\n // costs nothing at all, and one hidden at the far end only fades at the end that shows it.\n for (const id of match.entering) {\n const node = graph.getNode(id)\n if (node?.visible) add(fadeTrack(id, 0, node.opacity))\n }\n for (const id of match.leaving) {\n const node = from.graph.getNode(id)\n if (!node?.visible) continue\n const parentId = node.parentId ? matchOf.get(node.parentId) : undefined\n if (!node.parentId || !parentId) continue\n const index = from.graph.getNode(node.parentId)?.childIds.indexOf(id) ?? 0\n const copied = carryLeaving(from.graph, graph, id, parentId, index)\n if (copied) add(fadeTrack(copied, node.opacity, 0))\n }\n graph.clearAbsPosCache()\n return tracks\n}\n\n/**\n * A Smart animate from `from` to `to`: a copy of the destination frame in which each layer that\n * matches one of the start frame (`matchLayers`) moves from the start layer's position, size,\n * rotation, opacity, corner radius and solid fill colours to its own, the start frame's layers\n * with no match fade out where they were, and the destination's fade in. The destination frame\n * keeps its place and size and blends its fill. Neither frame changes. Matching and the copy cost\n * one pass when it is made; a step writes only the layers that change.\n */\nexport function createSmartAnimation(\n from: PlayFrame,\n to: PlayFrame,\n easing?: PrototypeEasingType,\n playback?: EasingPlayback\n): SmartAnimation {\n const pageId = findPageId(to.graph, to.rootId) ?? to.graph.rootId\n const graph = extractPageContext(to.graph, pageId, [to.rootId], { shareTables: true })\n const tracks = animationTracks(from, graph, to.rootId)\n\n // A layer's cached drawing holds what it contains, so its frame and the layers between redraw.\n const touched = new Set<string>()\n for (const track of tracks) {\n graph.closest(track.id, (node) => {\n touched.add(node.id)\n return node.id === to.rootId\n })\n }\n\n function pose(progress: number): void {\n const amount = easingAt(easing, progress, playback)\n for (const track of tracks) {\n const changes: Partial<SceneNode> = {}\n for (const { field, from: start, to: end } of track.numbers) {\n const value = lerp(start, end, amount)\n changes[field] = field === 'rotation' ? wrapAngle(value) : value\n }\n if (track.fills) changes.fills = blendFills(track.fills, amount)\n graph.updateNode(track.id, changes)\n }\n }\n\n // Made at its start, so the first drawing shows the start frame's layout.\n pose(0)\n let revision = 0\n return {\n graph,\n rootId: to.rootId,\n touched,\n get revision() {\n return revision\n },\n seek(progress) {\n pose(progress)\n revision += 1\n }\n }\n}\n"],"mappings":";;;;;AA+BA,MAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;AAmBA,SAAS,UAAU,IAAoB;CACrC,OAAO,iBAAiB;AAC1B;AAEA,SAAS,KAAK,MAAc,IAAY,QAAwB;CAC9D,OAAO,QAAQ,KAAK,QAAQ;AAC9B;;AAGA,SAAS,UAAU,SAAyB;CAC1C,MAAM,WAAY,UAAU,MAAO,OAAO;CAC1C,OAAO,UAAU,MAAM,UAAU,MAAM;AACzC;AAEA,SAAS,MAAM,MAAa,IAAW,QAAuB;CAC5D,OAAO;EACL,GAAG,KAAK,KAAK,GAAG,GAAG,GAAG,MAAM;EAC5B,GAAG,KAAK,KAAK,GAAG,GAAG,GAAG,MAAM;EAC5B,GAAG,KAAK,KAAK,GAAG,GAAG,GAAG,MAAM;EAC5B,GAAG,KAAK,KAAK,GAAG,GAAG,GAAG,MAAM;CAC9B;AACF;;;;;AAMA,SAAS,UAAU,MAAuB,IAA0C;CAClF,IAAI,KAAK,WAAW,GAAG,UAAU,KAAK,WAAW,GAAG,OAAO;CAC3D,IAAI,UAAU;CACd,KAAK,MAAM,CAAC,OAAO,SAAS,GAAG,QAAQ,GAAG;EACxC,MAAM,QAAQ,KAAK,GAAG,KAAK;EAC3B,IAAI,OAAO,SAAS,WAAW,KAAK,SA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,QAAQ;GAC1B,MAAM,UAA8B,CAAC;GACrC,KAAK,MAAM,EAAE,OAAO,MAAM,OAAO,IAAI,SAAS,MAAM,SAAS;IAC3D,MAAM,QAAQ,KAAK,OAAO,KAAK,MAAM;IACrC,QAAQ,SAAS,UAAU,aAAa,UAAU,KAAK,IAAI;GAC7D;GACA,IAAI,MAAM,OAAO,QAAQ,QAAQ,WAAW,MAAM,OAAO,MAAM;GAC/D,MAAM,WAAW,MAAM,IAAI,OAAO;EACpC;CACF;CAGA,KAAK,CAAC;CACN,IAAI,WAAW;CACf,OAAO;EACL;EACA,QAAQ,GAAG;EACX;EACA,IAAI,WAAW;GACb,OAAO;EACT;EACA,KAAK,UAAU;GACb,KAAK,QAAQ;GACb,YAAY;EACd;CACF;AACF"}
@@ -1,5 +1,5 @@
1
1
  import { PlaySession } from "./session.js";
2
- import { PrototypeAction, PrototypeEasingType, PrototypeOverlayPositionType, PrototypeTransitionType, SceneGraph } from "@pairdraw/scene-graph";
2
+ import { PrototypeAction, PrototypeCubicBezier, PrototypeEasingType, PrototypeOverlayPositionType, PrototypeSpring, PrototypeTransitionType, SceneGraph } from "@pairdraw/scene-graph";
3
3
  //#region src/prototype/timeline.d.ts
4
4
  /** A scripted click: the layer clicked, and when, in milliseconds from the start of play. */
5
5
  interface TimelineClick {
@@ -25,6 +25,11 @@ interface TimelineTransition {
25
25
  /** The transition's own length, which keeps its pace when a later step cuts it short. */
26
26
  fadeMs: number;
27
27
  easing?: PrototypeEasingType;
28
+ easingCurve?: PrototypeCubicBezier;
29
+ easingSpring?: PrototypeSpring;
30
+ /** The screens as play showed them, with its variable values and modes applied. */
31
+ fromGraph?: SceneGraph;
32
+ toGraph?: SceneGraph;
28
33
  }
29
34
  /**
30
35
  * A stretch of play: one screen held still, a crossfade from one screen to the next, or a Smart
@@ -35,6 +40,7 @@ type TimelineSegment = {
35
40
  session: PlaySession;
36
41
  startMs: number;
37
42
  endMs: number;
43
+ graph?: SceneGraph;
38
44
  } | ({
39
45
  kind: 'dissolve';
40
46
  } & TimelineTransition) | ({
@@ -70,10 +76,13 @@ interface Timeline {
70
76
  */
71
77
  type TimelineFrame = {
72
78
  session: PlaySession;
79
+ graph?: SceneGraph;
73
80
  } | {
74
81
  from: PlaySession;
75
82
  to: PlaySession;
76
83
  mix: number;
84
+ fromGraph?: SceneGraph;
85
+ toGraph?: SceneGraph;
77
86
  } | {
78
87
  smart: TimelineSmartSegment;
79
88
  progress: number;
@@ -1 +1 @@
1
- {"version":3,"file":"timeline.d.ts","names":[],"sources":["../../src/prototype/timeline.ts"],"mappings":";;;;UAqBiB;EACf;EACA;;UAGe;;EAEf;;EAEA,kBAAkB;;EAElB;;EAEA;;;UAIQ;EACR,MAAM;EACN,IAAI;EACJ;EACA;;EAEA;EACA,SAAS;;;;;;KAOC;EACN;EAAc,SAAS;EAAa;EAAiB;;EACpD;IAAqB;EACrB;IAAkB;;KAGb,uBAAuB,QAAQ;EAAmB;;;UAG7C;EACf;EACA;EACA;EACA,YAAY;;UAGG;EACf,UAAU;EACV;;EAEA,eAAe;;EAEf;;EAEA;EACA,OAAO;;EAEP,kBAAkB,eAAe;;;;;;KAOvB;EACN,SAAS;;EACT,MAAM;EAAa,IAAI;EAAa;;EACpC,OAAO;EAAsB;;;KAGvB;;cAGC,sBAAsB;WAItB,QAAQ;EAHV;EAEP,YAAA,iBACS,SAAQ;;;iBAUL,aAAa,QAAQ;;KAMzB;;;;;;iBAOI,aAAa,SAAS,aAAa,QAAQ,kBAAkB;;;;;;cAYhE;;;;;;;cAGA;;iBAGG,eAAe;;;;;;iBASf,eAAe,SAAS;;;;;;;;iBAsMxB,aAAa,OAAO,YAAY,SAAS,kBAAkB;;iBAyC3D,QAAQ,UAAU,UAAU,eAAe"}
1
+ {"version":3,"file":"timeline.d.ts","names":[],"sources":["../../src/prototype/timeline.ts"],"mappings":";;;;UAuBiB;EACf;EACA;;UAGe;;EAEf;;EAEA,kBAAkB;;EAElB;;EAEA;;;UAIQ;EACR,MAA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