@pairdraw/core 0.21.0 → 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 (626) 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/canvas/shaders/compile.d.ts +3 -1
  81. package/dist/canvas/shaders/compile.d.ts.map +1 -1
  82. package/dist/canvas/shaders/compile.js +12 -3
  83. package/dist/canvas/shaders/compile.js.map +1 -1
  84. package/dist/canvas/shaders/draw.d.ts.map +1 -1
  85. package/dist/canvas/shaders/draw.js +10 -3
  86. package/dist/canvas/shaders/draw.js.map +1 -1
  87. package/dist/canvas/shaders/effect.d.ts.map +1 -1
  88. package/dist/canvas/shaders/effect.js +6 -16
  89. package/dist/canvas/shaders/effect.js.map +1 -1
  90. package/dist/clipboard/pairdraw.d.ts.map +1 -1
  91. package/dist/clipboard/pairdraw.js +1 -0
  92. package/dist/clipboard/pairdraw.js.map +1 -1
  93. package/dist/editor/bridges/clipboard.d.ts +2 -0
  94. package/dist/editor/bridges/clipboard.d.ts.map +1 -1
  95. package/dist/editor/bridges/clipboard.js +1 -0
  96. package/dist/editor/bridges/clipboard.js.map +1 -1
  97. package/dist/editor/bridges/components.d.ts +14 -7
  98. package/dist/editor/bridges/components.d.ts.map +1 -1
  99. package/dist/editor/bridges/components.js +6 -0
  100. package/dist/editor/bridges/components.js.map +1 -1
  101. package/dist/editor/bridges/structure.d.ts +1 -1
  102. package/dist/editor/bridges/structure.d.ts.map +1 -1
  103. package/dist/editor/bridges/undo.d.ts +1 -1
  104. package/dist/editor/clipboard/code.d.ts +32 -0
  105. package/dist/editor/clipboard/code.d.ts.map +1 -0
  106. package/dist/editor/clipboard/code.js +30 -0
  107. package/dist/editor/clipboard/code.js.map +1 -0
  108. package/dist/editor/clipboard/export.js +2 -2
  109. package/dist/editor/clipboard/export.js.map +1 -1
  110. package/dist/editor/clipboard/paste/dependencies.d.ts +14 -0
  111. package/dist/editor/clipboard/paste/dependencies.d.ts.map +1 -0
  112. package/dist/editor/clipboard/paste/dependencies.js +0 -0
  113. package/dist/editor/clipboard/paste/run.d.ts +14 -0
  114. package/dist/editor/clipboard/paste/run.d.ts.map +1 -0
  115. package/dist/editor/clipboard/paste/run.js +47 -0
  116. package/dist/editor/clipboard/paste/run.js.map +1 -0
  117. package/dist/editor/clipboard/styled.d.ts +2 -8
  118. package/dist/editor/clipboard/styled.d.ts.map +1 -1
  119. package/dist/editor/clipboard/styled.js +2 -32
  120. package/dist/editor/clipboard/styled.js.map +1 -1
  121. package/dist/editor/clipboard.d.ts +2 -0
  122. package/dist/editor/clipboard.d.ts.map +1 -1
  123. package/dist/editor/clipboard.js +34 -0
  124. package/dist/editor/clipboard.js.map +1 -1
  125. package/dist/editor/components/instances.d.ts +5 -0
  126. package/dist/editor/components/instances.d.ts.map +1 -1
  127. package/dist/editor/components/instances.js +69 -4
  128. package/dist/editor/components/instances.js.map +1 -1
  129. package/dist/editor/components/slots/index.d.ts.map +1 -1
  130. package/dist/editor/components/slots/index.js +7 -0
  131. package/dist/editor/components/slots/index.js.map +1 -1
  132. package/dist/editor/components.d.ts +6 -0
  133. package/dist/editor/components.d.ts.map +1 -1
  134. package/dist/editor/components.js +14 -2
  135. package/dist/editor/components.js.map +1 -1
  136. package/dist/editor/create.d.ts +30 -3
  137. package/dist/editor/create.d.ts.map +1 -1
  138. package/dist/editor/create.js +11 -2
  139. package/dist/editor/create.js.map +1 -1
  140. package/dist/editor/design-tokens.d.ts +1 -1
  141. package/dist/editor/design-tokens.d.ts.map +1 -1
  142. package/dist/editor/design-tokens.js +4 -18
  143. package/dist/editor/design-tokens.js.map +1 -1
  144. package/dist/editor/image-edit.d.ts.map +1 -1
  145. package/dist/editor/image-edit.js +1 -2
  146. package/dist/editor/image-edit.js.map +1 -1
  147. package/dist/editor/index.d.ts +4 -4
  148. package/dist/editor/index.js +1 -1
  149. package/dist/editor/layout-mode.d.ts +3 -1
  150. package/dist/editor/layout-mode.d.ts.map +1 -1
  151. package/dist/editor/layout-mode.js +97 -2
  152. package/dist/editor/layout-mode.js.map +1 -1
  153. package/dist/editor/nodes.d.ts +2 -0
  154. package/dist/editor/nodes.d.ts.map +1 -1
  155. package/dist/editor/nodes.js +22 -7
  156. package/dist/editor/nodes.js.map +1 -1
  157. package/dist/editor/read-only/actions.js +6 -0
  158. package/dist/editor/read-only/actions.js.map +1 -1
  159. package/dist/editor/selection/overlays.d.ts +1 -0
  160. package/dist/editor/selection/overlays.d.ts.map +1 -1
  161. package/dist/editor/selection/overlays.js +7 -0
  162. package/dist/editor/selection/overlays.js.map +1 -1
  163. package/dist/editor/selection/read.d.ts +8 -0
  164. package/dist/editor/selection.d.ts +9 -0
  165. package/dist/editor/selection.d.ts.map +1 -1
  166. package/dist/editor/state/shared.js +1 -0
  167. package/dist/editor/state/shared.js.map +1 -1
  168. package/dist/editor/state/view.d.ts.map +1 -1
  169. package/dist/editor/state/view.js +2 -0
  170. package/dist/editor/state/view.js.map +1 -1
  171. package/dist/editor/structure/boolean.d.ts +1 -1
  172. package/dist/editor/structure/boolean.d.ts.map +1 -1
  173. package/dist/editor/structure/boolean.js +20 -1
  174. package/dist/editor/structure/boolean.js.map +1 -1
  175. package/dist/editor/structure/container-wrap.d.ts +8 -2
  176. package/dist/editor/structure/container-wrap.d.ts.map +1 -1
  177. package/dist/editor/structure/container-wrap.js +17 -5
  178. package/dist/editor/structure/container-wrap.js.map +1 -1
  179. package/dist/editor/structure/flatten.d.ts.map +1 -1
  180. package/dist/editor/structure/flatten.js +8 -7
  181. package/dist/editor/structure/flatten.js.map +1 -1
  182. package/dist/editor/structure/group/ungroup.d.ts.map +1 -1
  183. package/dist/editor/structure/group/ungroup.js +2 -0
  184. package/dist/editor/structure/group/ungroup.js.map +1 -1
  185. package/dist/editor/structure/outline-stroke.d.ts.map +1 -1
  186. package/dist/editor/structure/outline-stroke.js +5 -0
  187. package/dist/editor/structure/outline-stroke.js.map +1 -1
  188. package/dist/editor/structure.d.ts +1 -1
  189. package/dist/editor/structure.d.ts.map +1 -1
  190. package/dist/editor/styles.d.ts +26 -0
  191. package/dist/editor/styles.d.ts.map +1 -0
  192. package/dist/editor/styles.js +127 -0
  193. package/dist/editor/styles.js.map +1 -0
  194. package/dist/editor/text/selection-style.d.ts +1 -0
  195. package/dist/editor/text/selection-style.d.ts.map +1 -1
  196. package/dist/editor/text/selection-style.js +10 -2
  197. package/dist/editor/text/selection-style.js.map +1 -1
  198. package/dist/editor/tool-registry.d.ts.map +1 -1
  199. package/dist/editor/tool-registry.js +6 -0
  200. package/dist/editor/tool-registry.js.map +1 -1
  201. package/dist/editor/types.d.ts +14 -2
  202. package/dist/editor/types.d.ts.map +1 -1
  203. package/dist/editor/variable-bindings.d.ts.map +1 -1
  204. package/dist/editor/variable-bindings.js +6 -1
  205. package/dist/editor/variable-bindings.js.map +1 -1
  206. package/dist/figma-api/accessors/basic.d.ts.map +1 -1
  207. package/dist/figma-api/accessors/basic.js +22 -1
  208. package/dist/figma-api/accessors/basic.js.map +1 -1
  209. package/dist/figma-api/accessors/shape.js +1 -1
  210. package/dist/figma-api/accessors/text/index.js +1 -1
  211. package/dist/figma-api/accessors/text/ranges.js +1 -1
  212. package/dist/figma-api/accessors/text/references.js +1 -1
  213. package/dist/figma-api/accessors/variables.js +1 -1
  214. package/dist/figma-api/accessors/vector.d.ts.map +1 -1
  215. package/dist/figma-api/accessors/vector.js +8 -22
  216. package/dist/figma-api/accessors/vector.js.map +1 -1
  217. package/dist/figma-api/accessors/visual.js +1 -1
  218. package/dist/figma-api/compatibility.d.ts +1 -1
  219. package/dist/figma-api/compatibility.d.ts.map +1 -1
  220. package/dist/figma-api/component-scope.d.ts +14 -0
  221. package/dist/figma-api/component-scope.d.ts.map +1 -0
  222. package/dist/figma-api/component-scope.js +28 -0
  223. package/dist/figma-api/component-scope.js.map +1 -0
  224. package/dist/figma-api/components.d.ts.map +1 -1
  225. package/dist/figma-api/components.js +26 -2
  226. package/dist/figma-api/components.js.map +1 -1
  227. package/dist/figma-api/flatten.js +3 -3
  228. package/dist/figma-api/flatten.js.map +1 -1
  229. package/dist/figma-api/index.d.ts +77 -6
  230. package/dist/figma-api/index.d.ts.map +1 -1
  231. package/dist/figma-api/index.js +188 -2
  232. package/dist/figma-api/index.js.map +1 -1
  233. package/dist/figma-api/node-types.d.ts +2 -1
  234. package/dist/figma-api/node-types.d.ts.map +1 -1
  235. package/dist/figma-api/overrides.d.ts +26 -1
  236. package/dist/figma-api/overrides.d.ts.map +1 -1
  237. package/dist/figma-api/overrides.js +157 -10
  238. package/dist/figma-api/overrides.js.map +1 -1
  239. package/dist/figma-api/proxy.d.ts +2 -0
  240. package/dist/figma-api/proxy.d.ts.map +1 -1
  241. package/dist/figma-api/proxy.js +10 -2
  242. package/dist/figma-api/proxy.js.map +1 -1
  243. package/dist/figma-api/reactions.d.ts +61 -5
  244. package/dist/figma-api/reactions.d.ts.map +1 -1
  245. package/dist/figma-api/reactions.js +144 -11
  246. package/dist/figma-api/reactions.js.map +1 -1
  247. package/dist/figma-api/shape-with-text.js +1 -1
  248. package/dist/figma-api/slots.d.ts +3 -1
  249. package/dist/figma-api/slots.d.ts.map +1 -1
  250. package/dist/figma-api/slots.js +9 -8
  251. package/dist/figma-api/slots.js.map +1 -1
  252. package/dist/index.d.ts +4 -4
  253. package/dist/index.js +1 -1
  254. package/dist/io/formats/code/detect.d.ts +23 -0
  255. package/dist/io/formats/code/detect.d.ts.map +1 -0
  256. package/dist/io/formats/code/detect.js +46 -0
  257. package/dist/io/formats/code/detect.js.map +1 -0
  258. package/dist/io/formats/code/index.d.ts +5 -0
  259. package/dist/io/formats/code/index.js +5 -0
  260. package/dist/io/formats/code/read.d.ts +45 -0
  261. package/dist/io/formats/code/read.d.ts.map +1 -0
  262. package/dist/io/formats/code/read.js +86 -0
  263. package/dist/io/formats/code/read.js.map +1 -0
  264. package/dist/io/formats/code/stylesheet.d.ts +13 -0
  265. package/dist/io/formats/code/stylesheet.d.ts.map +1 -0
  266. package/dist/io/formats/code/stylesheet.js +21 -0
  267. package/dist/io/formats/code/stylesheet.js.map +1 -0
  268. package/dist/io/formats/code/tokens.d.ts +18 -0
  269. package/dist/io/formats/code/tokens.d.ts.map +1 -0
  270. package/dist/io/formats/code/tokens.js +135 -0
  271. package/dist/io/formats/code/tokens.js.map +1 -0
  272. package/dist/io/formats/design-tokens/apply.d.ts +7 -3
  273. package/dist/io/formats/design-tokens/apply.d.ts.map +1 -1
  274. package/dist/io/formats/design-tokens/apply.js.map +1 -1
  275. package/dist/io/formats/drawio/warnings.d.ts +17 -2
  276. package/dist/io/formats/drawio/warnings.d.ts.map +1 -1
  277. package/dist/io/formats/drawio/warnings.js +14 -7
  278. package/dist/io/formats/drawio/warnings.js.map +1 -1
  279. package/dist/io/formats/fig/export/patch/fields.js +5 -0
  280. package/dist/io/formats/fig/export/patch/fields.js.map +1 -1
  281. package/dist/io/formats/fig/export/patch/index.d.ts.map +1 -1
  282. package/dist/io/formats/fig/export/patch/index.js +20 -20
  283. package/dist/io/formats/fig/export/patch/index.js.map +1 -1
  284. package/dist/io/formats/fig/export/setup.d.ts.map +1 -1
  285. package/dist/io/formats/fig/export/setup.js +5 -1
  286. package/dist/io/formats/fig/export/setup.js.map +1 -1
  287. package/dist/io/formats/fig/index.d.ts +3 -2
  288. package/dist/io/formats/fig/index.js +2 -2
  289. package/dist/io/formats/fig/read.d.ts.map +1 -1
  290. package/dist/io/formats/fig/read.js +5 -2
  291. package/dist/io/formats/fig/read.js.map +1 -1
  292. package/dist/io/formats/html/index.d.ts +1 -0
  293. package/dist/io/formats/html/index.d.ts.map +1 -1
  294. package/dist/io/formats/html/index.js +5 -3
  295. package/dist/io/formats/html/index.js.map +1 -1
  296. package/dist/io/formats/html/layers.d.ts +3 -1
  297. package/dist/io/formats/html/layers.d.ts.map +1 -1
  298. package/dist/io/formats/html/layers.js +6 -1
  299. package/dist/io/formats/html/layers.js.map +1 -1
  300. package/dist/io/formats/pdf/export.d.ts.map +1 -1
  301. package/dist/io/formats/pdf/export.js +7 -3
  302. package/dist/io/formats/pdf/export.js.map +1 -1
  303. package/dist/io/formats/pdf/plan.d.ts +3 -0
  304. package/dist/io/formats/pdf/plan.d.ts.map +1 -1
  305. package/dist/io/formats/pdf/plan.js +60 -36
  306. package/dist/io/formats/pdf/plan.js.map +1 -1
  307. package/dist/io/formats/pen/index.d.ts.map +1 -1
  308. package/dist/io/formats/pen/index.js +13 -4
  309. package/dist/io/formats/pen/index.js.map +1 -1
  310. package/dist/io/formats/raster/headless.d.ts.map +1 -1
  311. package/dist/io/formats/raster/headless.js +3 -2
  312. package/dist/io/formats/raster/headless.js.map +1 -1
  313. package/dist/io/formats/raster/index.d.ts +2 -2
  314. package/dist/io/formats/raster/index.js +2 -2
  315. package/dist/io/formats/raster/render.d.ts +10 -2
  316. package/dist/io/formats/raster/render.d.ts.map +1 -1
  317. package/dist/io/formats/raster/render.js +35 -9
  318. package/dist/io/formats/raster/render.js.map +1 -1
  319. package/dist/io/formats/svg/defs.d.ts.map +1 -1
  320. package/dist/io/formats/svg/defs.js +19 -1
  321. package/dist/io/formats/svg/defs.js.map +1 -1
  322. package/dist/io/formats/svg/export.d.ts +5 -2
  323. package/dist/io/formats/svg/export.d.ts.map +1 -1
  324. package/dist/io/formats/svg/export.js +59 -10
  325. package/dist/io/formats/svg/export.js.map +1 -1
  326. package/dist/io/formats/svg/index.d.ts +2 -2
  327. package/dist/io/formats/svg/index.js +2 -2
  328. package/dist/io/formats/svg/text/layout.d.ts.map +1 -1
  329. package/dist/io/formats/svg/text/layout.js +4 -2
  330. package/dist/io/formats/svg/text/layout.js.map +1 -1
  331. package/dist/io/formats/video/record.d.ts.map +1 -1
  332. package/dist/io/formats/video/record.js +24 -9
  333. package/dist/io/formats/video/record.js.map +1 -1
  334. package/dist/io/formats.d.ts.map +1 -1
  335. package/dist/io/formats.js +30 -17
  336. package/dist/io/formats.js.map +1 -1
  337. package/dist/io/index.d.ts +2 -2
  338. package/dist/io/types.d.ts +11 -2
  339. package/dist/io/types.d.ts.map +1 -1
  340. package/dist/kiwi/fig/population/client.d.ts.map +1 -1
  341. package/dist/kiwi/fig/population/client.js +2 -1
  342. package/dist/kiwi/fig/population/client.js.map +1 -1
  343. package/dist/kiwi/fig/session/document-state.d.ts +46 -2
  344. package/dist/kiwi/fig/session/document-state.d.ts.map +1 -1
  345. package/dist/kiwi/fig/session/document-state.js +113 -5
  346. package/dist/kiwi/fig/session/document-state.js.map +1 -1
  347. package/dist/kiwi/fig/session/options.d.ts +4 -0
  348. package/dist/kiwi/fig/session/options.d.ts.map +1 -1
  349. package/dist/kiwi/fig/session/options.js.map +1 -1
  350. package/dist/layout/apply.d.ts.map +1 -1
  351. package/dist/layout/apply.js +8 -4
  352. package/dist/layout/apply.js.map +1 -1
  353. package/dist/layout/auto-layout-handles.js +1 -1
  354. package/dist/layout/auto-layout-handles.js.map +1 -1
  355. package/dist/layout/axis-sizing.d.ts.map +1 -1
  356. package/dist/layout/axis-sizing.js +1 -1
  357. package/dist/layout/axis-sizing.js.map +1 -1
  358. package/dist/layout/derived.d.ts.map +1 -1
  359. package/dist/layout/derived.js +1 -1
  360. package/dist/layout/derived.js.map +1 -1
  361. package/dist/layout/effective-generated-text.js +1 -1
  362. package/dist/layout/effective-generated-text.js.map +1 -1
  363. package/dist/layout/grid.d.ts +3 -1
  364. package/dist/layout/grid.d.ts.map +1 -1
  365. package/dist/layout/grid.js +57 -16
  366. package/dist/layout/grid.js.map +1 -1
  367. package/dist/layout.d.ts +1 -1
  368. package/dist/layout.js +6 -5
  369. package/dist/layout.js.map +1 -1
  370. package/dist/node/fs.d.ts.map +1 -1
  371. package/dist/node/fs.js +28 -7
  372. package/dist/node/fs.js.map +1 -1
  373. package/dist/prototype/easing.d.ts +13 -5
  374. package/dist/prototype/easing.d.ts.map +1 -1
  375. package/dist/prototype/easing.js +46 -6
  376. package/dist/prototype/easing.js.map +1 -1
  377. package/dist/prototype/scenes.d.ts +31 -0
  378. package/dist/prototype/scenes.d.ts.map +1 -1
  379. package/dist/prototype/scenes.js +220 -31
  380. package/dist/prototype/scenes.js.map +1 -1
  381. package/dist/prototype/session.d.ts.map +1 -1
  382. package/dist/prototype/session.js +1 -0
  383. package/dist/prototype/session.js.map +1 -1
  384. package/dist/prototype/smart-animate/animation.d.ts +2 -1
  385. package/dist/prototype/smart-animate/animation.d.ts.map +1 -1
  386. package/dist/prototype/smart-animate/animation.js +2 -2
  387. package/dist/prototype/smart-animate/animation.js.map +1 -1
  388. package/dist/prototype/timeline.d.ts +10 -1
  389. package/dist/prototype/timeline.d.ts.map +1 -1
  390. package/dist/prototype/timeline.js +69 -23
  391. package/dist/prototype/timeline.js.map +1 -1
  392. package/dist/prototype/variables.d.ts +23 -0
  393. package/dist/prototype/variables.d.ts.map +1 -0
  394. package/dist/prototype/variables.js +237 -0
  395. package/dist/prototype/variables.js.map +1 -0
  396. package/dist/rpc/read-commands.d.ts +5 -0
  397. package/dist/rpc/read-commands.d.ts.map +1 -1
  398. package/dist/rpc/read-commands.js +4 -1
  399. package/dist/rpc/read-commands.js.map +1 -1
  400. package/dist/text/character-style.d.ts +8 -1
  401. package/dist/text/character-style.d.ts.map +1 -1
  402. package/dist/text/character-style.js +39 -1
  403. package/dist/text/character-style.js.map +1 -1
  404. package/dist/text/index.d.ts +2 -2
  405. package/dist/text/index.js +2 -2
  406. package/dist/tools/create/basic.js +3 -4
  407. package/dist/tools/create/basic.js.map +1 -1
  408. package/dist/tools/create/behaviours.js +1 -1
  409. package/dist/tools/create/code.d.ts +6 -0
  410. package/dist/tools/create/code.d.ts.map +1 -0
  411. package/dist/tools/create/code.js +68 -0
  412. package/dist/tools/create/code.js.map +1 -0
  413. package/dist/tools/create/html.d.ts.map +1 -1
  414. package/dist/tools/create/html.js +9 -57
  415. package/dist/tools/create/html.js.map +1 -1
  416. package/dist/tools/create/icons.js +1 -1
  417. package/dist/tools/create/inputs.d.ts +11 -0
  418. package/dist/tools/create/inputs.d.ts.map +1 -0
  419. package/dist/tools/create/inputs.js +15 -0
  420. package/dist/tools/create/inputs.js.map +1 -0
  421. package/dist/tools/create/mermaid.d.ts.map +1 -1
  422. package/dist/tools/create/mermaid.js +5 -6
  423. package/dist/tools/create/mermaid.js.map +1 -1
  424. package/dist/tools/create/place.d.ts +30 -0
  425. package/dist/tools/create/place.d.ts.map +1 -0
  426. package/dist/tools/create/place.js +70 -0
  427. package/dist/tools/create/place.js.map +1 -0
  428. package/dist/tools/create/render.js +1 -1
  429. package/dist/tools/create/svg.js +1 -1
  430. package/dist/tools/create/vector.js +1 -1
  431. package/dist/tools/create.d.ts +2 -1
  432. package/dist/tools/create.js +2 -1
  433. package/dist/tools/css/gradient.d.ts +28 -0
  434. package/dist/tools/css/gradient.d.ts.map +1 -0
  435. package/dist/tools/css/gradient.js +118 -0
  436. package/dist/tools/css/gradient.js.map +1 -0
  437. package/dist/tools/image-ai/generate.js +1 -1
  438. package/dist/tools/modify/geometry.js +5 -5
  439. package/dist/tools/modify/geometry.js.map +1 -1
  440. package/dist/tools/modify/layout.d.ts.map +1 -1
  441. package/dist/tools/modify/layout.js +7 -1
  442. package/dist/tools/modify/layout.js.map +1 -1
  443. package/dist/tools/modify/matching.js +1 -1
  444. package/dist/tools/modify/overrides.d.ts +6 -0
  445. package/dist/tools/modify/overrides.d.ts.map +1 -0
  446. package/dist/tools/modify/overrides.js +27 -0
  447. package/dist/tools/modify/overrides.js.map +1 -0
  448. package/dist/tools/modify/paint.d.ts.map +1 -1
  449. package/dist/tools/modify/paint.js +84 -39
  450. package/dist/tools/modify/paint.js.map +1 -1
  451. package/dist/tools/modify/text.d.ts +2 -1
  452. package/dist/tools/modify/text.d.ts.map +1 -1
  453. package/dist/tools/modify/text.js +79 -8
  454. package/dist/tools/modify/text.js.map +1 -1
  455. package/dist/tools/modify/update.d.ts.map +1 -1
  456. package/dist/tools/modify/update.js +18 -2
  457. package/dist/tools/modify/update.js.map +1 -1
  458. package/dist/tools/modify.d.ts +3 -2
  459. package/dist/tools/modify.js +3 -2
  460. package/dist/tools/read/css.d.ts.map +1 -1
  461. package/dist/tools/read/css.js +29 -12
  462. package/dist/tools/read/css.js.map +1 -1
  463. package/dist/tools/read/libraries.js +1 -1
  464. package/dist/tools/read/nodes.d.ts.map +1 -1
  465. package/dist/tools/read/nodes.js +19 -5
  466. package/dist/tools/read/nodes.js.map +1 -1
  467. package/dist/tools/registry/extended.d.ts.map +1 -1
  468. package/dist/tools/registry/extended.js +6 -1
  469. package/dist/tools/registry/extended.js.map +1 -1
  470. package/dist/tools/text-range.d.ts +11 -0
  471. package/dist/tools/text-range.d.ts.map +1 -0
  472. package/dist/tools/text-range.js +26 -0
  473. package/dist/tools/text-range.js.map +1 -0
  474. package/dist/tools/variables/bindings.js +1 -1
  475. package/dist/tools/variables/bindings.js.map +1 -1
  476. package/dist/tools/variables/unbind.js +1 -1
  477. package/dist/tools/variables/unbind.js.map +1 -1
  478. package/dist/tools/vector/path.d.ts.map +1 -1
  479. package/dist/tools/vector/path.js +7 -21
  480. package/dist/tools/vector/path.js.map +1 -1
  481. package/dist/vector/rebase.d.ts +17 -0
  482. package/dist/vector/rebase.d.ts.map +1 -0
  483. package/dist/vector/rebase.js +32 -0
  484. package/dist/vector/rebase.js.map +1 -0
  485. package/package.json +14 -9
  486. package/src/canvas/boolean.ts +12 -1
  487. package/src/canvas/color-space.ts +73 -0
  488. package/src/canvas/fills.ts +130 -83
  489. package/src/canvas/flatten.ts +92 -7
  490. package/src/canvas/index.ts +9 -0
  491. package/src/canvas/layout-grids.ts +15 -2
  492. package/src/canvas/noise/render.ts +35 -7
  493. package/src/canvas/noise/shader.ts +8 -10
  494. package/src/canvas/overlays/annotations.ts +117 -0
  495. package/src/canvas/overlays/auto-layout-hover.ts +41 -1
  496. package/src/canvas/overlays/feedback.ts +7 -2
  497. package/src/canvas/overlays/index.ts +1 -1
  498. package/src/canvas/overlays/measurement.ts +49 -3
  499. package/src/canvas/overlays/presence.ts +35 -32
  500. package/src/canvas/renderer/colors.ts +14 -0
  501. package/src/canvas/renderer/document-surface.ts +16 -6
  502. package/src/canvas/renderer/lifecycle.ts +2 -2
  503. package/src/canvas/renderer/methods.ts +4 -0
  504. package/src/canvas/renderer/overlay-pass.ts +4 -0
  505. package/src/canvas/renderer/pipeline.ts +8 -0
  506. package/src/canvas/renderer/types.ts +8 -0
  507. package/src/canvas/renderer.ts +21 -2
  508. package/src/canvas/scene.ts +15 -7
  509. package/src/canvas/shaders/compile.ts +14 -3
  510. package/src/canvas/shaders/draw.ts +11 -4
  511. package/src/canvas/shaders/effect.ts +6 -18
  512. package/src/clipboard/pairdraw.ts +1 -0
  513. package/src/editor/bridges/clipboard.ts +1 -0
  514. package/src/editor/bridges/components.ts +10 -0
  515. package/src/editor/clipboard/code.ts +50 -0
  516. package/src/editor/clipboard/export.ts +2 -2
  517. package/src/editor/clipboard/paste/dependencies.ts +18 -0
  518. package/src/editor/clipboard/paste/run.ts +64 -0
  519. package/src/editor/clipboard/styled.ts +4 -52
  520. package/src/editor/clipboard.ts +40 -0
  521. package/src/editor/components/instances.ts +92 -4
  522. package/src/editor/components/slots/index.ts +7 -0
  523. package/src/editor/components.ts +16 -2
  524. package/src/editor/create.ts +15 -1
  525. package/src/editor/design-tokens.ts +3 -23
  526. package/src/editor/image-edit.ts +5 -2
  527. package/src/editor/index.ts +1 -0
  528. package/src/editor/layout-mode.ts +131 -3
  529. package/src/editor/nodes.ts +30 -5
  530. package/src/editor/read-only/actions.ts +6 -0
  531. package/src/editor/selection/overlays.ts +8 -0
  532. package/src/editor/state/shared.ts +1 -0
  533. package/src/editor/state/view.ts +2 -0
  534. package/src/editor/structure/boolean.ts +29 -1
  535. package/src/editor/structure/container-wrap.ts +20 -4
  536. package/src/editor/structure/flatten.ts +15 -8
  537. package/src/editor/structure/group/ungroup.ts +2 -0
  538. package/src/editor/structure/outline-stroke.ts +5 -0
  539. package/src/editor/styles.ts +203 -0
  540. package/src/editor/text/selection-style.ts +18 -1
  541. package/src/editor/tool-registry.ts +2 -0
  542. package/src/editor/types.ts +14 -0
  543. package/src/editor/variable-bindings.ts +11 -0
  544. package/src/figma-api/accessors/basic.ts +33 -1
  545. package/src/figma-api/accessors/vector.ts +6 -13
  546. package/src/figma-api/compatibility.ts +1 -0
  547. package/src/figma-api/component-scope.ts +36 -0
  548. package/src/figma-api/components.ts +24 -0
  549. package/src/figma-api/flatten.ts +7 -3
  550. package/src/figma-api/index.ts +302 -6
  551. package/src/figma-api/node-types.ts +1 -0
  552. package/src/figma-api/overrides.ts +192 -5
  553. package/src/figma-api/proxy.ts +16 -1
  554. package/src/figma-api/reactions.ts +163 -12
  555. package/src/figma-api/slots.ts +10 -9
  556. package/src/io/formats/code/detect.ts +67 -0
  557. package/src/io/formats/code/index.ts +17 -0
  558. package/src/io/formats/code/read.ts +143 -0
  559. package/src/io/formats/code/stylesheet.ts +24 -0
  560. package/src/io/formats/code/tokens.ts +159 -0
  561. package/src/io/formats/design-tokens/apply.ts +3 -2
  562. package/src/io/formats/drawio/warnings.ts +27 -8
  563. package/src/io/formats/fig/export/patch/fields.ts +11 -0
  564. package/src/io/formats/fig/export/patch/index.ts +23 -19
  565. package/src/io/formats/fig/export/setup.ts +8 -1
  566. package/src/io/formats/fig/index.ts +6 -0
  567. package/src/io/formats/fig/read.ts +11 -2
  568. package/src/io/formats/html/index.ts +9 -3
  569. package/src/io/formats/html/layers.ts +7 -0
  570. package/src/io/formats/pdf/export.ts +19 -7
  571. package/src/io/formats/pdf/plan.ts +71 -32
  572. package/src/io/formats/pen/index.ts +14 -6
  573. package/src/io/formats/raster/headless.ts +3 -1
  574. package/src/io/formats/raster/index.ts +2 -0
  575. package/src/io/formats/raster/render.ts +49 -9
  576. package/src/io/formats/svg/defs.ts +27 -1
  577. package/src/io/formats/svg/export.ts +75 -13
  578. package/src/io/formats/svg/index.ts +1 -0
  579. package/src/io/formats/svg/text/layout.ts +5 -3
  580. package/src/io/formats/video/record.ts +33 -9
  581. package/src/io/formats.ts +45 -19
  582. package/src/io/index.ts +1 -0
  583. package/src/io/types.ts +10 -0
  584. package/src/kiwi/fig/population/client.ts +6 -1
  585. package/src/kiwi/fig/session/document-state.ts +195 -5
  586. package/src/kiwi/fig/session/options.ts +2 -0
  587. package/src/layout/apply.ts +12 -4
  588. package/src/layout/auto-layout-handles.ts +1 -1
  589. package/src/layout/axis-sizing.ts +3 -1
  590. package/src/layout/derived.ts +3 -1
  591. package/src/layout/effective-generated-text.ts +1 -1
  592. package/src/layout/grid.ts +91 -21
  593. package/src/layout.ts +16 -3
  594. package/src/node/fs.ts +32 -7
  595. package/src/prototype/easing.ts +79 -7
  596. package/src/prototype/scenes.ts +244 -15
  597. package/src/prototype/session.ts +1 -0
  598. package/src/prototype/smart-animate/animation.ts +4 -3
  599. package/src/prototype/timeline.ts +118 -26
  600. package/src/prototype/variables.ts +189 -0
  601. package/src/rpc/read-commands.ts +19 -1
  602. package/src/text/character-style.ts +47 -0
  603. package/src/text/index.ts +1 -1
  604. package/src/tools/create/basic.ts +2 -3
  605. package/src/tools/create/code.ts +85 -0
  606. package/src/tools/create/html.ts +9 -46
  607. package/src/tools/create/inputs.ts +12 -0
  608. package/src/tools/create/mermaid.ts +6 -6
  609. package/src/tools/create/place.ts +80 -0
  610. package/src/tools/create.ts +1 -0
  611. package/src/tools/css/gradient.ts +147 -0
  612. package/src/tools/modify/geometry.ts +5 -5
  613. package/src/tools/modify/layout.ts +19 -0
  614. package/src/tools/modify/overrides.ts +35 -0
  615. package/src/tools/modify/paint.ts +124 -54
  616. package/src/tools/modify/text.ts +91 -7
  617. package/src/tools/modify/update.ts +23 -2
  618. package/src/tools/modify.ts +9 -1
  619. package/src/tools/read/css.ts +46 -12
  620. package/src/tools/read/nodes.ts +26 -4
  621. package/src/tools/registry/extended.ts +6 -0
  622. package/src/tools/text-range.ts +29 -0
  623. package/src/tools/variables/bindings.ts +4 -1
  624. package/src/tools/variables/unbind.ts +4 -1
  625. package/src/tools/vector/path.ts +11 -13
  626. package/src/vector/rebase.ts +33 -0
@@ -1,19 +1,52 @@
1
- import { DEFAULT_PROTOTYPE_EASING, PROTOTYPE_EASING_CURVES } from "@pairdraw/scene-graph/constants";
1
+ import { DEFAULT_PROTOTYPE_EASING, PROTOTYPE_EASING_CURVES, PROTOTYPE_SPRING_PRESETS } from "@pairdraw/scene-graph/constants";
2
2
  //#region src/prototype/easing.ts
3
3
  /** Bisection steps that solve a curve's x for its t; 32 halvings are far below a pixel. */
4
4
  const BISECTION_STEPS = 32;
5
5
  function bezier(t, p1, p2) {
6
6
  return 3 * (1 - t) * (1 - t) * t * p1 + 3 * (1 - t) * t * t * p2 + t * t * t;
7
7
  }
8
+ function springAt(spring, progress, duration) {
9
+ const time = progress * duration;
10
+ const { mass, stiffness, damping, initialVelocity } = spring;
11
+ if (mass <= 0 || stiffness <= 0) return progress;
12
+ const omega = Math.sqrt(stiffness / mass);
13
+ const zeta = damping / (2 * Math.sqrt(stiffness * mass));
14
+ if (zeta < 1) {
15
+ const damped = omega * Math.sqrt(1 - zeta * zeta);
16
+ return 1 - Math.exp(-zeta * omega * time) * (Math.cos(damped * time) + (zeta * omega + initialVelocity) / damped * Math.sin(damped * time));
17
+ }
18
+ if (zeta === 1) return 1 - Math.exp(-omega * time) * (1 + (omega + initialVelocity) * time);
19
+ const root = omega * Math.sqrt(zeta * zeta - 1);
20
+ const r1 = -zeta * omega + root;
21
+ const r2 = -zeta * omega - root;
22
+ const e1 = Math.exp(r1 * time);
23
+ const e2 = Math.exp(r2 * time);
24
+ return 1 + (r2 * e1 - r1 * e2) / (r1 - r2) + initialVelocity * (e1 - e2) / (r1 - r2);
25
+ }
8
26
  /**
9
27
  * How far along a transition eased by `easing` is at `progress` of its time, from 0 to 1; no
10
28
  * easing eases as Figma's default does. The player and a recording both read it, so they move
11
- * alike.
29
+ * alike. A spring plays its damped-oscillator solution over the transition's own duration, which
30
+ * Figma exposes beside the spring in the transition panel.
12
31
  */
13
- function easingAt(easing, progress) {
32
+ function easingAt(easing, progress, playback = {}) {
14
33
  if (progress <= 0) return 0;
15
34
  if (progress >= 1) return 1;
16
- const [x1, y1, x2, y2] = PROTOTYPE_EASING_CURVES[easing ?? DEFAULT_PROTOTYPE_EASING];
35
+ const type = easing ?? DEFAULT_PROTOTYPE_EASING;
36
+ if (type === "CUSTOM_SPRING" || type in PROTOTYPE_SPRING_PRESETS) return springAt(type === "CUSTOM_SPRING" ? playback.spring ?? PROTOTYPE_SPRING_PRESETS.GENTLE : PROTOTYPE_SPRING_PRESETS[type], progress, playback.duration ?? .45);
37
+ const curve = type === "CUSTOM_CUBIC_BEZIER" && playback.curve ? playback.curve : void 0;
38
+ const DEFAULT_CURVE = PROTOTYPE_EASING_CURVES[DEFAULT_PROTOTYPE_EASING] ?? [
39
+ 0,
40
+ 0,
41
+ .58,
42
+ 1
43
+ ];
44
+ const [x1, y1, x2, y2] = curve ? [
45
+ curve.x1,
46
+ curve.y1,
47
+ curve.x2,
48
+ curve.y2
49
+ ] : PROTOTYPE_EASING_CURVES[type] ?? DEFAULT_CURVE;
17
50
  if (x1 === y1 && x2 === y2) return progress;
18
51
  let low = 0;
19
52
  let high = 1;
@@ -25,8 +58,15 @@ function easingAt(easing, progress) {
25
58
  return bezier((low + high) / 2, y1, y2);
26
59
  }
27
60
  /** `easing` as a CSS timing function, for a transition the browser animates. */
28
- function easingCSS(easing) {
29
- const [x1, y1, x2, y2] = PROTOTYPE_EASING_CURVES[easing ?? DEFAULT_PROTOTYPE_EASING];
61
+ function easingCSS(easing, curve) {
62
+ if (easing === "CUSTOM_CUBIC_BEZIER" && curve) return `cubic-bezier(${curve.x1}, ${curve.y1}, ${curve.x2}, ${curve.y2})`;
63
+ if (easing === "CUSTOM_SPRING" || easing !== void 0 && easing in PROTOTYPE_SPRING_PRESETS) return "ease-out";
64
+ const [x1, y1, x2, y2] = PROTOTYPE_EASING_CURVES[easing ?? DEFAULT_PROTOTYPE_EASING] ?? PROTOTYPE_EASING_CURVES[DEFAULT_PROTOTYPE_EASING] ?? [
65
+ 0,
66
+ 0,
67
+ .58,
68
+ 1
69
+ ];
30
70
  if (x1 === y1 && x2 === y2) return "linear";
31
71
  return `cubic-bezier(${x1}, ${y1}, ${x2}, ${y2})`;
32
72
  }
@@ -1 +1 @@
1
- {"version":3,"file":"easing.js","names":[],"sources":["../../src/prototype/easing.ts"],"sourcesContent":["import type { PrototypeEasingType } from '@pairdraw/scene-graph'\nimport { DEFAULT_PROTOTYPE_EASING, PROTOTYPE_EASING_CURVES } from '@pairdraw/scene-graph/constants'\n\n/** Bisection steps that solve a curve's x for its t; 32 halvings are far below a pixel. */\nconst BISECTION_STEPS = 32\n\nfunction bezier(t: number, p1: number, p2: number): number {\n return 3 * (1 - t) * (1 - t) * t * p1 + 3 * (1 - t) * t * t * p2 + t * t * t\n}\n\n/**\n * How far along a transition eased by `easing` is at `progress` of its time, from 0 to 1; no\n * easing eases as Figma's default does. The player and a recording both read it, so they move\n * alike.\n */\nexport function easingAt(easing: PrototypeEasingType | undefined, progress: number): number {\n if (progress <= 0) return 0\n if (progress >= 1) return 1\n const [x1, y1, x2, y2] = PROTOTYPE_EASING_CURVES[easing ?? DEFAULT_PROTOTYPE_EASING]\n if (x1 === y1 && x2 === y2) return progress\n // x(t) rises monotonically, so bisection finds the t whose x is `progress`.\n let low = 0\n let high = 1\n for (let index = 0; index < BISECTION_STEPS; index++) {\n const middle = (low + high) / 2\n if (bezier(middle, x1, x2) < progress) low = middle\n else high = middle\n }\n return bezier((low + high) / 2, y1, y2)\n}\n\n/** `easing` as a CSS timing function, for a transition the browser animates. */\nexport function easingCSS(easing: PrototypeEasingType | undefined): string {\n const [x1, y1, x2, y2] = PROTOTYPE_EASING_CURVES[easing ?? DEFAULT_PROTOTYPE_EASING]\n if (x1 === y1 && x2 === y2) return 'linear'\n return `cubic-bezier(${x1}, ${y1}, ${x2}, ${y2})`\n}\n"],"mappings":";;;AAIA,MAAM,kBAAkB;AAExB,SAAS,OAAO,GAAW,IAAY,IAAoB;CACzD,OAAO,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,KAAK,IAAI,KAAK,IAAI,IAAI,KAAK,IAAI,IAAI;AAC7E;;;;;;AAOA,SAAgB,SAAS,QAAyC,UAA0B;CAC1F,IAAI,YAAY,GAAG,OAAO;CAC1B,IAAI,YAAY,GAAG,OAAO;CAC1B,MAAM,CAAC,IAAI,IAAI,IAAI,MAAM,wBAAwB,UAAU;CAC3D,IAAI,OAAO,MAAM,OAAO,IAAI,OAAO;CAEnC,IAAI,MAAM;CACV,IAAI,OAAO;CACX,KAAK,IAAI,QAAQ,GAAG,QAAQ,iBAAiB,SAAS;EACpD,MAAM,UAAU,MAAM,QAAQ;EAC9B,IAAI,OAAO,QAAQ,IAAI,EAAE,IAAI,UAAU,MAAM;OACxC,OAAO;CACd;CACA,OAAO,QAAQ,MAAM,QAAQ,GAAG,IAAI,EAAE;AACxC;;AAGA,SAAgB,UAAU,QAAiD;CACzE,MAAM,CAAC,IAAI,IAAI,IAAI,MAAM,wBAAwB,UAAU;CAC3D,IAAI,OAAO,MAAM,OAAO,IAAI,OAAO;CACnC,OAAO,gBAAgB,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG;AACjD"}
1
+ {"version":3,"file":"easing.js","names":[],"sources":["../../src/prototype/easing.ts"],"sourcesContent":["import type {\n PrototypeCubicBezier,\n PrototypeEasingType,\n PrototypeSpring\n} from '@pairdraw/scene-graph'\nimport {\n DEFAULT_PROTOTYPE_EASING,\n PROTOTYPE_EASING_CURVES,\n PROTOTYPE_SPRING_PRESETS\n} from '@pairdraw/scene-graph/constants'\n\n/** Bisection steps that solve a curve's x for its t; 32 halvings are far below a pixel. */\nconst BISECTION_STEPS = 32\n\nfunction bezier(t: number, p1: number, p2: number): number {\n return 3 * (1 - t) * (1 - t) * t * p1 + 3 * (1 - t) * t * t * p2 + t * t * t\n}\n\n/** How a transition's easing plays: its type and the data a custom type needs. */\nexport interface EasingPlayback {\n curve?: PrototypeCubicBezier\n spring?: PrototypeSpring\n /** The transition's length in seconds; a spring settles over it. */\n duration?: number\n}\n\nfunction springAt(spring: PrototypeSpring, progress: number, duration: number): number {\n const time = progress * duration\n const { mass, stiffness, damping, initialVelocity } = spring\n if (mass <= 0 || stiffness <= 0) return progress\n const omega = Math.sqrt(stiffness / mass)\n const zeta = damping / (2 * Math.sqrt(stiffness * mass))\n if (zeta < 1) {\n const damped = omega * Math.sqrt(1 - zeta * zeta)\n return (\n 1 -\n Math.exp(-zeta * omega * time) *\n (Math.cos(damped * time) +\n ((zeta * omega + initialVelocity) / damped) * Math.sin(damped * time))\n )\n }\n if (zeta === 1) return 1 - Math.exp(-omega * time) * (1 + (omega + initialVelocity) * time)\n // Overdamped: two real roots, not the critical-damping approximation.\n const root = omega * Math.sqrt(zeta * zeta - 1)\n const r1 = -zeta * omega + root\n const r2 = -zeta * omega - root\n const e1 = Math.exp(r1 * time)\n const e2 = Math.exp(r2 * time)\n return 1 + (r2 * e1 - r1 * e2) / (r1 - r2) + (initialVelocity * (e1 - e2)) / (r1 - r2)\n}\n\n/**\n * How far along a transition eased by `easing` is at `progress` of its time, from 0 to 1; no\n * easing eases as Figma's default does. The player and a recording both read it, so they move\n * alike. A spring plays its damped-oscillator solution over the transition's own duration, which\n * Figma exposes beside the spring in the transition panel.\n */\nexport function easingAt(\n easing: PrototypeEasingType | undefined,\n progress: number,\n playback: EasingPlayback = {}\n): number {\n if (progress <= 0) return 0\n if (progress >= 1) return 1\n const type = easing ?? DEFAULT_PROTOTYPE_EASING\n if (type === 'CUSTOM_SPRING' || type in PROTOTYPE_SPRING_PRESETS) {\n const spring =\n type === 'CUSTOM_SPRING'\n ? (playback.spring ?? PROTOTYPE_SPRING_PRESETS.GENTLE)\n : PROTOTYPE_SPRING_PRESETS[type as keyof typeof PROTOTYPE_SPRING_PRESETS]\n return springAt(spring, progress, playback.duration ?? 0.45)\n }\n const curve = type === 'CUSTOM_CUBIC_BEZIER' && playback.curve ? playback.curve : undefined\n const DEFAULT_CURVE =\n PROTOTYPE_EASING_CURVES[DEFAULT_PROTOTYPE_EASING] ?? ([0, 0, 0.58, 1] as const)\n const [x1, y1, x2, y2] = curve\n ? [curve.x1, curve.y1, curve.x2, curve.y2]\n : (PROTOTYPE_EASING_CURVES[type] ?? DEFAULT_CURVE)\n if (x1 === y1 && x2 === y2) return progress\n // x(t) rises monotonically, so bisection finds the t whose x is `progress`.\n let low = 0\n let high = 1\n for (let index = 0; index < BISECTION_STEPS; index++) {\n const middle = (low + high) / 2\n if (bezier(middle, x1, x2) < progress) low = middle\n else high = middle\n }\n return bezier((low + high) / 2, y1, y2)\n}\n\n/** `easing` as a CSS timing function, for a transition the browser animates. */\nexport function easingCSS(\n easing: PrototypeEasingType | undefined,\n curve?: PrototypeCubicBezier\n): string {\n if (easing === 'CUSTOM_CUBIC_BEZIER' && curve)\n return `cubic-bezier(${curve.x1}, ${curve.y1}, ${curve.x2}, ${curve.y2})`\n // The app baseline predates CSS `linear()` (Chrome 111, Safari 16.4), so a spring dissolve\n // snapshot eases out instead of sampling the physical curve; documented on the roadmap.\n if (easing === 'CUSTOM_SPRING' || (easing !== undefined && easing in PROTOTYPE_SPRING_PRESETS))\n return 'ease-out'\n const points =\n PROTOTYPE_EASING_CURVES[easing ?? DEFAULT_PROTOTYPE_EASING] ??\n PROTOTYPE_EASING_CURVES[DEFAULT_PROTOTYPE_EASING] ??\n ([0, 0, 0.58, 1] as const)\n const [x1, y1, x2, y2] = points\n if (x1 === y1 && x2 === y2) return 'linear'\n return `cubic-bezier(${x1}, ${y1}, ${x2}, ${y2})`\n}\n"],"mappings":";;;AAYA,MAAM,kBAAkB;AAExB,SAAS,OAAO,GAAW,IAAY,IAAoB;CACzD,OAAO,KAAK,IAAI,MAAM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;CAE7D,MAAM,QAAQ,SAAS,yBAAyB,SAAS,QAAQ,SAAS,QAAQ,KAAA;CAClF,MAAM,gBACJ,wBAAwB,6BAA8B;EAAC;EAAG;EAAG;EAAM;CAAC;CACtE,MAAM,CAAC,IAAI,IAAI,IAAI,MAAM,QACrB;EAAC,MAAM;EAAI,MAAM;EAAI,MAAM;EAAI,MAAM;CAAE,IACtC,wBAAwB,SAAS;CACtC,IAAI,OAAO,MAAM,OAAO,IAAI,OAAO;CAEnC,IAAI,MAAM;CACV,IAAI,OAAO;CACX,KAAK,IAAI,QAAQ,GAAG,QAAQ,iBAAiB,SAAS;EACpD,MAAM,UAAU,MAAM,QAAQ;EAC9B,IAAI,OAAO,QAAQ,IAAI,EAAE,IAAI,UAAU,MAAM;OACxC,OAAO;CACd;CACA,OAAO,QAAQ,MAAM,QAAQ,GAAG,IAAI,EAAE;AACxC;;AAGA,SAAgB,UACd,QACA,OACQ;CACR,IAAI,WAAW,yBAAyB,OACtC,OAAO,gBAAgB,MAAM,GAAG,IAAI,MAAM,GAAG,IAAI,MAAM,GAAG,IAAI,MAAM,GAAG;CAGzE,IAAI,WAAW,mBAAoB,WAAW,KAAA,KAAa,UAAU,0BACnE,OAAO;CAKT,MAAM,CAAC,IAAI,IAAI,IAAI,MAHjB,wBAAwB,UAAU,6BAClC,wBAAwB,6BACvB;EAAC;EAAG;EAAG;EAAM;CAAC;CAEjB,IAAI,OAAO,MAAM,OAAO,IAAI,OAAO;CACnC,OAAO,gBAAgB,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG;AACjD"}
@@ -36,6 +36,12 @@ interface PlayStep {
36
36
  * the player to run over the transition's duration; the copy shows the change at once.
37
37
  */
38
38
  animation?: SmartAnimation;
39
+ /** Why a variable action could not run; the player shows it instead of guessing a value. */
40
+ variablesRefused?: string;
41
+ /** The action actually run, after a Conditional picked a branch. */
42
+ action?: PrototypeAction;
43
+ /** Whether play's variable values changed, so a frame showing them must be drawn again. */
44
+ repaint?: boolean;
39
45
  }
40
46
  /**
41
47
  * The frames play changed, each kept as a private copy so the document never changes. Frames move
@@ -45,6 +51,31 @@ interface PlayStep {
45
51
  interface PlayScenes {
46
52
  /** The graph play reads a top-level frame from: its copy once changed, else the document. */
47
53
  graphFor(rootId: string): SceneGraph;
54
+ /**
55
+ * A fresh copy of `rootId` with the session's variable values and modes applied, for a caller
56
+ * that must keep the state it sees after play moves on (a video's earlier frames).
57
+ */
58
+ cloneGraphFor(rootId: string): SceneGraph;
59
+ /**
60
+ * The action a Conditional would run now, resolving nested conditionals; a condition this build
61
+ * cannot evaluate is refused with its reason.
62
+ */
63
+ resolve(action: PrototypeAction, rootId?: string): {
64
+ action: PrototypeAction;
65
+ } | {
66
+ refused: string;
67
+ };
68
+ /**
69
+ * The actions of the first matching Conditional branch, or `[action]` for any other action; a
70
+ * condition this build cannot evaluate is refused with its reason.
71
+ */
72
+ resolveBranch(action: PrototypeAction, rootId?: string): {
73
+ actions: readonly PrototypeAction[];
74
+ } | {
75
+ refused: string;
76
+ };
77
+ /** Whether this session has changed a variable's value or a collection's mode. */
78
+ hasVariables(): boolean;
48
79
  /** The changed frames the canvas draws from their copies, by frame id. */
49
80
  readonly views: ReadonlyMap<string, PlaySceneView>;
50
81
  /** How far play scrolled each frame that scrolls, by frame id. */
@@ -1 +1 @@
1
- {"version":3,"file":"scenes.d.ts","names":[],"sources":["../../src/prototype/scenes.ts"],"mappings":";;;;;;;;;cA8Ba;;;;;;UAOI;EACf;;EAEA;EACA;EACA,QAAQ;EACR;;;;;;;UAQe;EACf,SAAS;EACT,SAAS;EACT,WAAW;EACX,SAAS;;;;;EAKT,YAAY;;;;;;;UAQG;;EAEf,SAAS,iBAAiB;;WAEjB,OAAO,oBAAoB;;WAE3B,QAAQ,oBAAoB;;;;;EAKrC,SAAS,gBAAgB,yBAAyB,YAAY,aAAa;;EAE3E,UAAU,YAAY,QAAQ;;EAE9B,IAAI,SAAS,aAAa,OAAO,WAAW,kBAAkB;;;;;EAK9D,OAAO,SAAS,aAAa,QAAQ,aAAa;;;;;EAKlD,iBAAiB,iBAAiB;;;;;EAKlC,OAAO,SAAS;EAChB;;iBAGc,iBACd,mBAAmB,YACnB,iBACC"}
1
+ {"version":3,"file":"scenes.d.ts","names":[],"sources":["../../src/prototype/scenes.ts"],"mappings":";;;;;;;;;cAmCa;;;;;;UAOI;EACf;;EAEA;EACA;EACA,QAAQ;EACR;;;;;;;UAQe;EACf,SAAS;EACT,SAAS;EACT,WAAW;EACX,SAAS;;;;;EAKT,YAAY;;EAEZ;;EAEA,SAAS;;EAET;;;;;;;UAQe;;EAEf,SAAS,iBAAiB;;;;;EAK1B,cAAc,iBAAiB;;;;;EAK/B,QACE,QAAQ,iBACR;IACG,QAAQ;;IAAsB;;;;;;EAKnC,cACE,QAAQ,iBACR;IACG,kBAAkB;;IAAwB;;;EAE/C;;WAES,OAAO,oBAAoB;;WAE3B,QAAQ,oBAAoB;;;;;EAKrC,SAAS,gBAAgB,yBAAyB,YAAY,aAAa;;EAE3E,UAAU,YAAY,QAAQ;;EAE9B,IAAI,SAAS,aAAa,OAAO,WAAW,kBAAkB;;;;;EAK9D,OAAO,SAAS,aAAa,QAAQ,aAAa;;;;;EAKlD,iBAAiB,iBAAiB;;;;;EAKlC,OAAO,SAAS;EAChB;;iBAGc,iBACd,mBAAmB,YACnB,iBACC"}
@@ -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, rootId) || held) scenes.delete(rootId)\n }\n }\n },\n clear() {\n scenes.clear()\n scroll.clear()\n }\n }\n}\n"],"mappings":";;;;;;;;;AA8BA,MAAa,mBAAmB;AAwEhC,SAAgB,iBACd,aACA,QAAA,GACY;CAEZ,MAAM,yBAAS,IAAI,IAAuB;CAC1C,MAAM,yBAAS,IAAI,IAAoB;CAEvC,SAAS,SAAS,QAA4B;EAC5C,OAAO,OAAO,IAAI,MAAM,CAAC,EAAE,SAAS,YAAY;CAClD;;;;;CAMA,SAAS,YAAY,QAA2B;EAC9C,MAAM,QAAQ,OAAO,IAAI,MAAM;EAC/B,IAAI,CAAC,OAAO,OAAO;GAAE,OAAO,YAAY;GAAG;EAAO;EAClD,MAAM,SAAS,WAAW,MAAM,OAAO,MAAM,KAAK,MAAM,MAAM;EAC9D,OAAO;GACL,OAAO,mBAAmB,MAAM,OAAO,QAAQ,CAAC,MAAM,GAAG,EAAE,aAAa,KAAK,CAAC;GAC9E;EACF;CACF;;;;;CAMA,SAAS,WACP,QACA,UACA,W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AAS,mBAAmB,cAAc,QAAQ;KAClF,IAAI,CAAC,QAAQ;KACb,SAAS,KAAK;MACZ,UAAU,KAAK;MACf;MACA,YAAY,SAAS;MACrB;MACA,SAAS,SAAS,QAAQ,QAAQ;KACpC,CAAC;IACH;GACF;GACA,MAAM,SAAS,OAAe;IAC5B,KAAK,MAAM,SAAS,MAAM,YAAY,EAAE,GAAG;KACzC,IAAI,MAAM,SAAS,YAAY;MAC7B,MAAM,OAAO,sBAAsB,OAAO,KAAK;MAC/C,IAAI,MAAM,QAAQ,OAAO,KAAK,IAAI,KAAK,kBAAkB;KAC3D,OAAO;MAGL,MAAM,SAAS,SAAS,KAAK;MAC7B,IAAI,UAAU,OAAO,OAAO,MAAM,IAChC,QAAQ,OAAO,OAAO,IAAI,OAAO,kBAAkB;KACvD;KACA,MAAM,MAAM,EAAE;IAChB;GACF;GACA,MAAM,MAAM;GACZ,OAAO;EACT;EACA,OAAO,SAAS;GACd,MAAM,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;CAEjE;CAEA,SAAS,QAAQ,YAAoB,QAAqD;EACxF,MAAM,UAAU,OAAO,IAAI,UAAU;EACrC,IAAI,YAAY,KAAA,GAAW,OAAO;EAClC,MAAM,QAAQ,SAAS,SAAS,MAAM,CAAC,CAAC,QAAQ,MAAM,IAAI,KAAA;EAC1D,MAAM,YAAY,SAAS,SAAS,MAAM,CAAC,CAAC,YAAY,YAAY,CAAC,CAAC,UAAA,CAAW,IAAI,UAAU;EAC/F,IAAI,CAAC,UAAU,OAAO,KAAA;EACtB,MAAM,YAAY,QAAQ,MAAM,cAAc,SAAS,gBAAgB,KAAA;EACvE,MAAM,cAAc,YAAY,CAAC,CAAC,oBAAoB,IAAI,SAAS,YAAY,CAAC,EAAE,MAAM,EAAE,EACtF;EACJ,MAAM,OAAO,MAAM,IAAI,SAAS,YAAY,KAAK,aAAa;EAC9D,OAAO,OAAO,UAAU,SAAS,aAAa,KAAK,IAAI,KAAA;CACzD;CAEA,SAAS,eAAe,OAAyB;EAE/C,IAAI,MAAM,cAAc,Y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AS,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;CAC9F,MAAM,SAAS,aAAa,OAAO,MAAM;CACzC,MAAM,MAAM,IAAI,IAAI,OAAO,KAAK,UAAU,MAAM,EAAE,CAAC;CACnD,KAAK,MAAM,MAAM,aAAa;EAC5B,IAAI,IAAI,IAAI,EAAE,GAAG,OAAO;EACxB,MAAM,QAAQ,WAAW,OAAO,MAAM,QAAQ,EAAE,CAAC;EACjD,IAAI,SAAS,IAAI,IAAI,MAAM,EAAE,GAAG,OAAO,MAAM;CAC/C;CACA,OAAO,OAAO,EAAE,EAAE,MAAM;AAC1B;;;;;AAMA,SAAgB,WACd,OACA,MACkB;CAClB,IAAI,MAAM,QAAQ;CAClB,OAAO,KAAK,UAAU;EACpB,MAAM,SAAS,MAAM,QAAQ,IAAI,QAAQ;EACzC,IAAI,CAAC,UAAU,OAAO,SAAS,UAAU;EACzC,MAAM;CACR;CACA,OAAO,KAAK,SAAS,UAAU,MAAM;AACvC;;AAGA,SAAgB,aAAa,SAA8B;CACzD,OAAO;EAAE;EAAS,cAAc;EAAS,SAAS,C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AO;CAC3B,IAAI,WAAW,OAAO,MAAM,QAAQ,OAAO,MAAM,CAAC,CAAC,EAAE,OAAO,OAAO,QAAQ,OAAO;CAClF,IAAI,OAAO,eAAe,WAAW;EACnC,IAAI,OAAO,WAAW,WAAW,OAAO,GAAG,OAAO;EAClD,OAAO;GAAE,GAAG;GAAS,UAAU,CAAC,GAAG,QAAQ,UAAU,OAAO,MAAM;EAAE;CACtE;CACA,IAAI,OAAO,WAAW,QAAQ,SAAS,OAAO;CAC9C,OAAO;EACL,GAAG;EACH,SAAS,OAAO;EAChB,SAAS,CAAC,GAAG,QAAQ,SAAS,QAAQ,OAAO;EAC7C,UAAU,CAAC;CACb;AACF;;;;;AAMA,SAAgB,iBACd,OACA,SACgD;CAChD,MAAM,OAAO,MAAM,QAAQ,WAAW,OAAO,CAAC;CAC9C,IAAI,CAAC,MAAM,OAAO,CAAC;CACnB,OAAO,KAAK,mBACT,QAAQ,aAAa,SAAS,QAAQ,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,IAAI,OAAO,KAAK,UAAU,MAAM,EAAE,CAAC;CACnD,KAAK,MAAM,MAAM,aAAa;EAC5B,IAAI,IAAI,IAAI,EAAE,GAAG,OAAO;EACxB,MAAM,QAAQ,WAAW,OAAO,MAAM,QAAQ,EAAE,CAAC;EACjD,IAAI,SAAS,IAAI,IAAI,MAAM,EAAE,GAAG,OAAO,MAAM;CAC/C;CACA,OAAO,OAAO,EAAE,EAAE,MAAM;AAC1B;;;;;AAMA,SAAgB,WACd,OACA,MACkB;CAClB,IAAI,MAAM,QAAQ;CAClB,OAAO,KAAK,UAAU;EACpB,MAAM,SAAS,MAAM,QAAQ,IAAI,QAAQ;EACzC,IAAI,CAAC,UAAU,OAAO,SAAS,UAAU;EACzC,MAAM;CACR;CACA,OAAO,KAAK,SAAS,UAAU,MAAM;AACvC;;AAGA,SAAgB,aAAa,SAA8B;CACzD,OAAO;EAAE;EAAS,cAAc;EAAS,SAAS,CAAC;EAAG,UAAU,CAAC;CAAE;AACrE;;AAGA,SAAgB,WAAW,SAA8B;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AO,MAAM,QAAQ,OAAO,MAAM,CAAC,CAAC,EAAE,OAAO,OAAO,QAAQ,OAAO;CAClF,IAAI,OAAO,eAAe,WAAW;EACnC,IAAI,OAAO,WAAW,WAAW,OAAO,GAAG,OAAO;EAClD,OAAO;GAAE,GAAG;GAAS,UAAU,CAAC,GAAG,QAAQ,UAAU,OAAO,MAAM;EAAE;CACtE;CACA,IAAI,OAAO,WAAW,QAAQ,SAAS,OAAO;CAC9C,OAAO;EACL,GAAG;EACH,SAAS,OAAO;EAChB,SAAS,CAAC,GAAG,QAAQ,SAAS,QAAQ,OAAO;EAC7C,UAAU,CAAC;CACb;AACF;;;;;AAMA,SAAgB,iBACd,OACA,SACgD;CAChD,MAAM,OAAO,MAAM,QAAQ,WAAW,OAAO,CAAC;CAC9C,IAAI,CAAC,MAAM,OAAO,CAAC;CACnB,OAAO,KAAK,mBACT,QAAQ,aAAa,SAAS,QAAQ,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,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) {