@open-pencil/scene-graph 0.17.0-beta.7 → 0.18.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (423) hide show
  1. package/dist/behaviours/index.d.ts +3 -2
  2. package/dist/behaviours/index.js +2 -1
  3. package/dist/behaviours/kinds.d.ts.map +1 -1
  4. package/dist/behaviours/kinds.js +15 -8
  5. package/dist/behaviours/kinds.js.map +1 -1
  6. package/dist/behaviours/model.d.ts +2 -2
  7. package/dist/behaviours/model.d.ts.map +1 -1
  8. package/dist/behaviours/model.js.map +1 -1
  9. package/dist/behaviours/schema.d.ts +136 -1
  10. package/dist/behaviours/schema.d.ts.map +1 -1
  11. package/dist/behaviours/schema.js +17 -2
  12. package/dist/behaviours/schema.js.map +1 -1
  13. package/dist/behaviours/spec.d.ts.map +1 -1
  14. package/dist/behaviours/spec.js +4 -0
  15. package/dist/behaviours/spec.js.map +1 -1
  16. package/dist/behaviours/transition.d.ts +23 -0
  17. package/dist/behaviours/transition.d.ts.map +1 -0
  18. package/dist/behaviours/transition.js +36 -0
  19. package/dist/behaviours/transition.js.map +1 -0
  20. package/dist/checkpoint.d.ts.map +1 -1
  21. package/dist/checkpoint.js +2 -0
  22. package/dist/checkpoint.js.map +1 -1
  23. package/dist/color/index.d.ts +12 -9
  24. package/dist/color/index.d.ts.map +1 -1
  25. package/dist/color/index.js +15 -25
  26. package/dist/color/index.js.map +1 -1
  27. package/dist/color/management.d.ts +51 -23
  28. package/dist/color/management.d.ts.map +1 -1
  29. package/dist/color/management.js +154 -149
  30. package/dist/color/management.js.map +1 -1
  31. package/dist/color/okhcl.d.ts +28 -10
  32. package/dist/color/okhcl.d.ts.map +1 -1
  33. package/dist/color/okhcl.js +56 -40
  34. package/dist/color/okhcl.js.map +1 -1
  35. package/dist/color/schema.d.ts +6 -1
  36. package/dist/color/schema.d.ts.map +1 -1
  37. package/dist/color/schema.js +10 -1
  38. package/dist/color/schema.js.map +1 -1
  39. package/dist/constraints.d.ts.map +1 -1
  40. package/dist/constraints.js +2 -1
  41. package/dist/constraints.js.map +1 -1
  42. package/dist/copy.d.ts +7 -1
  43. package/dist/copy.d.ts.map +1 -1
  44. package/dist/copy.js +22 -1
  45. package/dist/copy.js.map +1 -1
  46. package/dist/corners.d.ts +3 -1
  47. package/dist/corners.d.ts.map +1 -1
  48. package/dist/corners.js +3 -1
  49. package/dist/corners.js.map +1 -1
  50. package/dist/css/grid.js +1 -1
  51. package/dist/css/index.d.ts +3 -2
  52. package/dist/css/index.js +3 -2
  53. package/dist/css/motion.d.ts +12 -0
  54. package/dist/css/motion.d.ts.map +1 -0
  55. package/dist/css/motion.js +60 -0
  56. package/dist/css/motion.js.map +1 -0
  57. package/dist/css/shadows.d.ts +4 -3
  58. package/dist/css/shadows.d.ts.map +1 -1
  59. package/dist/css/shadows.js +8 -18
  60. package/dist/css/shadows.js.map +1 -1
  61. package/dist/css/values.d.ts +6 -3
  62. package/dist/css/values.d.ts.map +1 -1
  63. package/dist/css/values.js +23 -5
  64. package/dist/css/values.js.map +1 -1
  65. package/dist/fields/index.d.ts +2 -2
  66. package/dist/fields/index.js +2 -2
  67. package/dist/fields/layout.d.ts +3 -1
  68. package/dist/fields/layout.d.ts.map +1 -1
  69. package/dist/fields/layout.js +9 -1
  70. package/dist/fields/layout.js.map +1 -1
  71. package/dist/figjam/palette.js +1 -1
  72. package/dist/font-style.d.ts.map +1 -1
  73. package/dist/font-style.js +7 -3
  74. package/dist/font-style.js.map +1 -1
  75. package/dist/generated/index.d.ts +6 -2
  76. package/dist/generated/index.d.ts.map +1 -1
  77. package/dist/generated/index.js +14 -4
  78. package/dist/generated/index.js.map +1 -1
  79. package/dist/geometry.d.ts +6 -1
  80. package/dist/geometry.d.ts.map +1 -1
  81. package/dist/geometry.js +10 -2
  82. package/dist/geometry.js.map +1 -1
  83. package/dist/graph.d.ts +29 -4
  84. package/dist/graph.d.ts.map +1 -1
  85. package/dist/graph.js +59 -9
  86. package/dist/graph.js.map +1 -1
  87. package/dist/group-bounds.d.ts +5 -2
  88. package/dist/group-bounds.d.ts.map +1 -1
  89. package/dist/group-bounds.js +38 -8
  90. package/dist/group-bounds.js.map +1 -1
  91. package/dist/hit-test.d.ts.map +1 -1
  92. package/dist/hit-test.js +19 -8
  93. package/dist/hit-test.js.map +1 -1
  94. package/dist/index.d.ts +2 -2
  95. package/dist/index.js +2 -2
  96. package/dist/instances/content-size.js +1 -1
  97. package/dist/instances/fields.d.ts +2 -2
  98. package/dist/instances/fields.d.ts.map +1 -1
  99. package/dist/instances/fields.js +2 -0
  100. package/dist/instances/fields.js.map +1 -1
  101. package/dist/instances/index.d.ts.map +1 -1
  102. package/dist/instances/index.js +50 -11
  103. package/dist/instances/index.js.map +1 -1
  104. package/dist/instances/sync.js +67 -7
  105. package/dist/instances/sync.js.map +1 -1
  106. package/dist/layout/flow.d.ts +16 -0
  107. package/dist/layout/flow.d.ts.map +1 -0
  108. package/dist/layout/flow.js +34 -0
  109. package/dist/layout/flow.js.map +1 -0
  110. package/dist/layout/index.d.ts +4 -3
  111. package/dist/layout/index.js +4 -3
  112. package/dist/layout/keywords.d.ts.map +1 -1
  113. package/dist/layout/keywords.js +7 -1
  114. package/dist/layout/keywords.js.map +1 -1
  115. package/dist/layout/sizing.d.ts +9 -1
  116. package/dist/layout/sizing.d.ts.map +1 -1
  117. package/dist/layout/sizing.js +17 -1
  118. package/dist/layout/sizing.js.map +1 -1
  119. package/dist/layout/spacing.d.ts +7 -1
  120. package/dist/layout/spacing.d.ts.map +1 -1
  121. package/dist/layout/spacing.js +10 -1
  122. package/dist/layout/spacing.js.map +1 -1
  123. package/dist/mesh/geometry.d.ts +83 -0
  124. package/dist/mesh/geometry.d.ts.map +1 -0
  125. package/dist/mesh/geometry.js +441 -0
  126. package/dist/mesh/geometry.js.map +1 -0
  127. package/dist/mesh/index.d.ts +4 -0
  128. package/dist/mesh/index.js +4 -0
  129. package/dist/mesh/model.d.ts +28 -0
  130. package/dist/mesh/model.d.ts.map +1 -0
  131. package/dist/mesh/model.js +40 -0
  132. package/dist/mesh/model.js.map +1 -0
  133. package/dist/mesh/schema.d.ts +191 -0
  134. package/dist/mesh/schema.d.ts.map +1 -0
  135. package/dist/mesh/schema.js +56 -0
  136. package/dist/mesh/schema.js.map +1 -0
  137. package/dist/mutation-impact.d.ts +2 -0
  138. package/dist/mutation-impact.d.ts.map +1 -1
  139. package/dist/mutation-impact.js +18 -7
  140. package/dist/mutation-impact.js.map +1 -1
  141. package/dist/node-defaults.d.ts +3 -1
  142. package/dist/node-defaults.d.ts.map +1 -1
  143. package/dist/node-defaults.js +22 -6
  144. package/dist/node-defaults.js.map +1 -1
  145. package/dist/paints/index.d.ts +5 -3
  146. package/dist/paints/index.js +5 -3
  147. package/dist/paints/pattern.d.ts +5 -1
  148. package/dist/paints/pattern.d.ts.map +1 -1
  149. package/dist/paints/pattern.js +33 -1
  150. package/dist/paints/pattern.js.map +1 -1
  151. package/dist/paints/shows.d.ts +4 -1
  152. package/dist/paints/shows.d.ts.map +1 -1
  153. package/dist/paints/shows.js +8 -1
  154. package/dist/paints/shows.js.map +1 -1
  155. package/dist/paints/solid.d.ts +11 -0
  156. package/dist/paints/solid.d.ts.map +1 -0
  157. package/dist/paints/solid.js +18 -0
  158. package/dist/paints/solid.js.map +1 -0
  159. package/dist/paints/stills.d.ts +74 -0
  160. package/dist/paints/stills.d.ts.map +1 -0
  161. package/dist/paints/stills.js +113 -0
  162. package/dist/paints/stills.js.map +1 -0
  163. package/dist/plugin-data/field.d.ts.map +1 -1
  164. package/dist/plugin-data/field.js +2 -0
  165. package/dist/plugin-data/field.js.map +1 -1
  166. package/dist/plugin-data/fields.d.ts +67 -0
  167. package/dist/plugin-data/fields.d.ts.map +1 -1
  168. package/dist/plugin-data/fields.js +12 -7
  169. package/dist/plugin-data/fields.js.map +1 -1
  170. package/dist/resize.d.ts +10 -3
  171. package/dist/resize.d.ts.map +1 -1
  172. package/dist/resize.js +34 -3
  173. package/dist/resize.js.map +1 -1
  174. package/dist/scaling/index.d.ts +2 -2
  175. package/dist/scaling/index.js +2 -2
  176. package/dist/scaling/node.d.ts +2 -1
  177. package/dist/scaling/node.d.ts.map +1 -1
  178. package/dist/scaling/node.js +27 -7
  179. package/dist/scaling/node.js.map +1 -1
  180. package/dist/shaders/index.d.ts +2 -3
  181. package/dist/shaders/index.js +2 -3
  182. package/dist/shaders/model.d.ts +3 -11
  183. package/dist/shaders/model.d.ts.map +1 -1
  184. package/dist/shaders/model.js +13 -36
  185. package/dist/shaders/model.js.map +1 -1
  186. package/dist/shaders/schema.d.ts +1 -1
  187. package/dist/shaders/schema.js +1 -1
  188. package/dist/shaders/schema.js.map +1 -1
  189. package/dist/shape-with-text/document.js +276 -0
  190. package/dist/shape-with-text/document.js.map +1 -0
  191. package/dist/shape-with-text/geometry.d.ts +13 -1
  192. package/dist/shape-with-text/geometry.d.ts.map +1 -1
  193. package/dist/shape-with-text/geometry.js +103 -41
  194. package/dist/shape-with-text/geometry.js.map +1 -1
  195. package/dist/shape-with-text/index.d.ts +2 -2
  196. package/dist/shape-with-text/index.js +2 -2
  197. package/dist/shared-style-index.d.ts +21 -0
  198. package/dist/shared-style-index.d.ts.map +1 -0
  199. package/dist/shared-style-index.js +72 -0
  200. package/dist/shared-style-index.js.map +1 -0
  201. package/dist/shared-styles.d.ts +3 -3
  202. package/dist/shared-styles.d.ts.map +1 -1
  203. package/dist/shared-styles.js +16 -7
  204. package/dist/shared-styles.js.map +1 -1
  205. package/dist/slides/drop.d.ts +32 -0
  206. package/dist/slides/drop.d.ts.map +1 -0
  207. package/dist/slides/drop.js +81 -0
  208. package/dist/slides/drop.js.map +1 -0
  209. package/dist/slides/index.d.ts +56 -0
  210. package/dist/slides/index.d.ts.map +1 -0
  211. package/dist/slides/index.js +134 -0
  212. package/dist/slides/index.js.map +1 -0
  213. package/dist/slides/motion.d.ts +55 -0
  214. package/dist/slides/motion.d.ts.map +1 -0
  215. package/dist/slides/motion.js +142 -0
  216. package/dist/slides/motion.js.map +1 -0
  217. package/dist/slides/playback.d.ts +59 -0
  218. package/dist/slides/playback.d.ts.map +1 -0
  219. package/dist/slides/playback.js +188 -0
  220. package/dist/slides/playback.js.map +1 -0
  221. package/dist/slides/types.d.ts +62 -0
  222. package/dist/slides/types.d.ts.map +1 -0
  223. package/dist/slides/types.js +39 -0
  224. package/dist/slides/types.js.map +1 -0
  225. package/dist/statuses/workflow.js +1 -1
  226. package/dist/text/direction.d.ts +6 -3
  227. package/dist/text/direction.d.ts.map +1 -1
  228. package/dist/text/direction.js +12 -12
  229. package/dist/text/direction.js.map +1 -1
  230. package/dist/text/index.d.ts +2 -1
  231. package/dist/text/index.js +3 -2
  232. package/dist/text/name.d.ts +22 -0
  233. package/dist/text/name.d.ts.map +1 -0
  234. package/dist/text/name.js +38 -0
  235. package/dist/text/name.js.map +1 -0
  236. package/dist/text/references.d.ts.map +1 -1
  237. package/dist/text/references.js +1 -2
  238. package/dist/text/references.js.map +1 -1
  239. package/dist/thumbnail.d.ts +23 -0
  240. package/dist/thumbnail.d.ts.map +1 -0
  241. package/dist/thumbnail.js +47 -0
  242. package/dist/thumbnail.js.map +1 -0
  243. package/dist/transfer/apply.d.ts.map +1 -1
  244. package/dist/transfer/apply.js +14 -3
  245. package/dist/transfer/apply.js.map +1 -1
  246. package/dist/transfer/copied.d.ts +6 -1
  247. package/dist/transfer/copied.d.ts.map +1 -1
  248. package/dist/transfer/copied.js +2 -2
  249. package/dist/transfer/copied.js.map +1 -1
  250. package/dist/transfer/dependencies.d.ts +4 -1
  251. package/dist/transfer/dependencies.d.ts.map +1 -1
  252. package/dist/transfer/dependencies.js +10 -1
  253. package/dist/transfer/dependencies.js.map +1 -1
  254. package/dist/transfer/history.js +2 -0
  255. package/dist/transfer/history.js.map +1 -1
  256. package/dist/transfer/identity.js +18 -3
  257. package/dist/transfer/identity.js.map +1 -1
  258. package/dist/transfer/index.d.ts +2 -1
  259. package/dist/transfer/index.js +4 -3
  260. package/dist/transfer/library.d.ts +45 -0
  261. package/dist/transfer/library.d.ts.map +1 -0
  262. package/dist/transfer/library.js +102 -0
  263. package/dist/transfer/library.js.map +1 -0
  264. package/dist/transfer/nodes.d.ts.map +1 -1
  265. package/dist/transfer/nodes.js +9 -0
  266. package/dist/transfer/nodes.js.map +1 -1
  267. package/dist/transfer/plan.d.ts +9 -0
  268. package/dist/transfer/plan.d.ts.map +1 -1
  269. package/dist/transfer/plan.js +51 -6
  270. package/dist/transfer/plan.js.map +1 -1
  271. package/dist/transfer/remove.js +7 -1
  272. package/dist/transfer/remove.js.map +1 -1
  273. package/dist/transfer/validation.js +8 -4
  274. package/dist/transfer/validation.js.map +1 -1
  275. package/dist/transfer/variables.d.ts.map +1 -1
  276. package/dist/transfer/variables.js +2 -1
  277. package/dist/transfer/variables.js.map +1 -1
  278. package/dist/types.d.ts +91 -13
  279. package/dist/types.d.ts.map +1 -1
  280. package/dist/types.js +33 -1
  281. package/dist/types.js.map +1 -1
  282. package/dist/variables/bindings.d.ts +11 -6
  283. package/dist/variables/bindings.d.ts.map +1 -1
  284. package/dist/variables/bindings.js +162 -38
  285. package/dist/variables/bindings.js.map +1 -1
  286. package/dist/variables/easing.d.ts +48 -0
  287. package/dist/variables/easing.d.ts.map +1 -0
  288. package/dist/variables/easing.js +321 -0
  289. package/dist/variables/easing.js.map +1 -0
  290. package/dist/variables/formula/index.d.ts +4 -2
  291. package/dist/variables/formula/index.d.ts.map +1 -1
  292. package/dist/variables/formula/index.js +26 -9
  293. package/dist/variables/formula/index.js.map +1 -1
  294. package/dist/variables/formula/parse.js +1 -1
  295. package/dist/variables/formula/schema.js +1 -1
  296. package/dist/variables/formula/signatures.d.ts +2 -2
  297. package/dist/variables/formula/signatures.d.ts.map +1 -1
  298. package/dist/variables/formula/signatures.js.map +1 -1
  299. package/dist/variables/formula/tree.d.ts +2 -2
  300. package/dist/variables/formula/tree.d.ts.map +1 -1
  301. package/dist/variables/formula/tree.js.map +1 -1
  302. package/dist/variables/index.d.ts +22 -5
  303. package/dist/variables/index.d.ts.map +1 -1
  304. package/dist/variables/index.js +67 -17
  305. package/dist/variables/index.js.map +1 -1
  306. package/dist/variables/lookup.js +1 -1
  307. package/dist/variables/lookup.js.map +1 -1
  308. package/dist/variables/motion.d.ts +46 -0
  309. package/dist/variables/motion.d.ts.map +1 -0
  310. package/dist/variables/motion.js +107 -0
  311. package/dist/variables/motion.js.map +1 -0
  312. package/dist/variables/paints.d.ts +10 -2
  313. package/dist/variables/paints.d.ts.map +1 -1
  314. package/dist/variables/paints.js +24 -10
  315. package/dist/variables/paints.js.map +1 -1
  316. package/dist/variables/resolution.d.ts.map +1 -1
  317. package/dist/variables/resolution.js +10 -9
  318. package/dist/variables/resolution.js.map +1 -1
  319. package/dist/variables/schema.d.ts +59 -1
  320. package/dist/variables/schema.d.ts.map +1 -1
  321. package/dist/variables/schema.js +36 -1
  322. package/dist/variables/schema.js.map +1 -1
  323. package/dist/variables/style-bindings.d.ts +23 -0
  324. package/dist/variables/style-bindings.d.ts.map +1 -0
  325. package/dist/variables/style-bindings.js +83 -0
  326. package/dist/variables/style-bindings.js.map +1 -0
  327. package/package.json +21 -2
  328. package/src/behaviours/index.ts +1 -0
  329. package/src/behaviours/kinds.ts +5 -1
  330. package/src/behaviours/model.ts +2 -2
  331. package/src/behaviours/schema.ts +19 -2
  332. package/src/behaviours/spec.ts +5 -0
  333. package/src/behaviours/transition.ts +46 -0
  334. package/src/checkpoint.ts +2 -0
  335. package/src/color/index.ts +15 -24
  336. package/src/color/management.ts +144 -168
  337. package/src/color/okhcl.ts +62 -43
  338. package/src/color/schema.ts +13 -0
  339. package/src/constraints.ts +2 -1
  340. package/src/copy.ts +29 -0
  341. package/src/corners.ts +3 -0
  342. package/src/css/index.ts +2 -0
  343. package/src/css/motion.ts +51 -0
  344. package/src/css/shadows.ts +8 -23
  345. package/src/css/values.ts +34 -4
  346. package/src/fields/layout.ts +9 -0
  347. package/src/font-style.ts +8 -3
  348. package/src/generated/index.ts +15 -3
  349. package/src/geometry.ts +13 -1
  350. package/src/graph.ts +72 -9
  351. package/src/group-bounds.ts +54 -13
  352. package/src/hit-test.ts +13 -8
  353. package/src/instances/fields.ts +2 -0
  354. package/src/instances/index.ts +71 -12
  355. package/src/instances/sync.ts +93 -11
  356. package/src/layout/flow.ts +34 -0
  357. package/src/layout/index.ts +1 -0
  358. package/src/layout/keywords.ts +7 -1
  359. package/src/layout/sizing.ts +30 -0
  360. package/src/layout/spacing.ts +12 -0
  361. package/src/mesh/geometry.ts +433 -0
  362. package/src/mesh/index.ts +3 -0
  363. package/src/mesh/model.ts +50 -0
  364. package/src/mesh/schema.ts +81 -0
  365. package/src/mutation-impact.ts +23 -7
  366. package/src/node-defaults.ts +22 -5
  367. package/src/paints/index.ts +2 -0
  368. package/src/paints/pattern.ts +55 -0
  369. package/src/paints/shows.ts +9 -0
  370. package/src/paints/solid.ts +10 -0
  371. package/src/paints/stills.ts +182 -0
  372. package/src/plugin-data/field.ts +3 -0
  373. package/src/plugin-data/fields.ts +15 -2
  374. package/src/resize.ts +32 -20
  375. package/src/scaling/index.ts +1 -1
  376. package/src/scaling/node.ts +43 -6
  377. package/src/shaders/index.ts +0 -1
  378. package/src/shaders/model.ts +19 -49
  379. package/src/shaders/schema.ts +1 -1
  380. package/src/shape-with-text/document.ts +175 -0
  381. package/src/shape-with-text/geometry.ts +99 -27
  382. package/src/shared-style-index.ts +106 -0
  383. package/src/shared-styles.ts +21 -14
  384. package/src/slides/drop.ts +94 -0
  385. package/src/slides/index.ts +125 -0
  386. package/src/slides/motion.ts +169 -0
  387. package/src/slides/playback.ts +200 -0
  388. package/src/slides/types.ts +94 -0
  389. package/src/text/direction.ts +13 -23
  390. package/src/text/index.ts +1 -0
  391. package/src/text/name.ts +39 -0
  392. package/src/text/references.ts +3 -3
  393. package/src/thumbnail.ts +52 -0
  394. package/src/transfer/apply.ts +16 -3
  395. package/src/transfer/copied.ts +7 -2
  396. package/src/transfer/dependencies.ts +10 -1
  397. package/src/transfer/history.ts +2 -0
  398. package/src/transfer/identity.ts +34 -2
  399. package/src/transfer/index.ts +6 -0
  400. package/src/transfer/library.ts +153 -0
  401. package/src/transfer/nodes.ts +20 -0
  402. package/src/transfer/plan.ts +96 -10
  403. package/src/transfer/remove.ts +6 -2
  404. package/src/transfer/validation.ts +15 -7
  405. package/src/transfer/variables.ts +8 -2
  406. package/src/types.ts +115 -11
  407. package/src/variables/bindings.ts +260 -36
  408. package/src/variables/easing.ts +282 -0
  409. package/src/variables/formula/index.ts +33 -14
  410. package/src/variables/formula/signatures.ts +6 -2
  411. package/src/variables/formula/tree.ts +3 -3
  412. package/src/variables/index.ts +90 -37
  413. package/src/variables/lookup.ts +1 -1
  414. package/src/variables/motion.ts +151 -0
  415. package/src/variables/paints.ts +29 -7
  416. package/src/variables/resolution.ts +11 -5
  417. package/src/variables/schema.ts +41 -0
  418. package/src/variables/style-bindings.ts +137 -0
  419. package/dist/shaders/still.d.ts +0 -18
  420. package/dist/shaders/still.d.ts.map +0 -1
  421. package/dist/shaders/still.js +0 -36
  422. package/dist/shaders/still.js.map +0 -1
  423. package/src/shaders/still.ts +0 -41
@@ -0,0 +1,94 @@
1
+ import type { SceneGraph } from '../graph'
2
+ import type { Rect, Vector } from '../primitives'
3
+ import type { SceneNode } from '../types'
4
+
5
+ /** Where moved slides go: beside a slide, or as a new section before another one or at the end. */
6
+ export type SlidePlacement =
7
+ | { type: 'beside'; slideId: string; side: 'before' | 'after' }
8
+ | { type: 'section'; before: string | null }
9
+
10
+ /** The line that shows where a drop lands, in canvas units. */
11
+ export interface SlideDropLine {
12
+ x: number
13
+ y: number
14
+ length: number
15
+ direction: 'HORIZONTAL' | 'VERTICAL'
16
+ }
17
+
18
+ export interface SlideDrop {
19
+ placement: SlidePlacement
20
+ line: SlideDropLine
21
+ }
22
+
23
+ function boxOf(graph: SceneGraph, node: SceneNode): Rect {
24
+ const { x, y } = graph.getAbsolutePosition(node.id)
25
+ return { x, y, width: node.width, height: node.height }
26
+ }
27
+
28
+ function distanceTo(box: Rect, point: Vector): number {
29
+ const dx = Math.max(box.x - point.x, 0, point.x - box.x - box.width)
30
+ const dy = Math.max(box.y - point.y, 0, point.y - box.y - box.height)
31
+ return Math.hypot(dx, dy)
32
+ }
33
+
34
+ /** Beside the slide of `row` nearest the point, on the side of its middle the point is on. */
35
+ function besideNearest(graph: SceneGraph, row: SceneNode, point: Vector): SlideDrop | null {
36
+ const slides = graph
37
+ .getChildren(row.id)
38
+ .filter((node) => node.type === 'SLIDE')
39
+ .map((slide) => ({ slide, box: boxOf(graph, slide) }))
40
+ let nearest = slides.at(0)
41
+ for (const candidate of slides) {
42
+ if (nearest && distanceTo(candidate.box, point) < distanceTo(nearest.box, point)) {
43
+ nearest = candidate
44
+ }
45
+ }
46
+ if (!nearest) return null
47
+ const { slide, box } = nearest
48
+ const side = point.x < box.x + box.width / 2 ? 'before' : 'after'
49
+ const half = row.itemSpacing / 2
50
+ return {
51
+ placement: { type: 'beside', slideId: slide.id, side },
52
+ line: {
53
+ x: side === 'before' ? box.x - half : box.x + box.width + half,
54
+ y: box.y,
55
+ length: box.height,
56
+ direction: 'VERTICAL'
57
+ }
58
+ }
59
+ }
60
+
61
+ /**
62
+ * Where slides dragged to a point on the page's deck land, as in Figma's grid: in a section's band,
63
+ * beside its nearest slide; between sections, above the first, or below the last, as a new section
64
+ * there. Null on a page without a deck.
65
+ */
66
+ export function slideDropAt(graph: SceneGraph, pageId: string, point: Vector): SlideDrop | null {
67
+ const grid = graph.getChildren(pageId).find((node) => node.type === 'SLIDE_GRID')
68
+ if (!grid) return null
69
+ const rows = graph
70
+ .getChildren(grid.id)
71
+ .filter((node) => node.type === 'SLIDE_ROW')
72
+ .map((row) => ({ row, box: boxOf(graph, row) }))
73
+ const within = rows.find(({ box }) => point.y >= box.y && point.y <= box.y + box.height)
74
+ if (within) return besideNearest(graph, within.row, point)
75
+
76
+ const index = rows.findIndex(({ box }) => point.y < box.y)
77
+ const next = index === -1 ? undefined : rows[index]
78
+ const previous = index === -1 ? rows.at(-1) : rows[index - 1]
79
+ const half = grid.itemSpacing / 2
80
+ const gridBox = boxOf(graph, grid)
81
+ let y = gridBox.y + grid.paddingTop - half
82
+ if (previous && next) y = (previous.box.y + previous.box.height + next.box.y) / 2
83
+ else if (previous) y = previous.box.y + previous.box.height + half
84
+ else if (next) y = next.box.y - half
85
+ return {
86
+ placement: { type: 'section', before: next?.row.id ?? null },
87
+ line: {
88
+ x: gridBox.x + grid.paddingLeft,
89
+ y,
90
+ length: gridBox.width - grid.paddingLeft - grid.paddingRight,
91
+ direction: 'HORIZONTAL'
92
+ }
93
+ }
94
+ }
@@ -0,0 +1,125 @@
1
+ import type { SceneGraph } from '../graph'
2
+ import type { SceneNode } from '../types'
3
+ import type { SlideSettings } from './types'
4
+
5
+ export * from './drop'
6
+ export * from './motion'
7
+ export * from './playback'
8
+ export * from './types'
9
+
10
+ /** Figma's slide: 1920 by 1080, with 240 between slides and 600 between the rows of a grid. */
11
+ export const DEFAULT_SLIDE_SIZE = { width: 1920, height: 1080 } as const
12
+
13
+ /** The sizes a deck offers its slides, by shape; any other size is a custom one. */
14
+ export const SLIDE_SIZE_PRESETS = [
15
+ { id: 'wide', width: 1920, height: 1080 },
16
+ { id: 'standard', width: 1440, height: 1080 },
17
+ { id: 'square', width: 1080, height: 1080 },
18
+ { id: 'portrait', width: 1080, height: 1920 }
19
+ ] as const
20
+ export type SlideSizePreset = (typeof SLIDE_SIZE_PRESETS)[number]
21
+ const SLIDE_GAP = 240
22
+ const ROW_GAP = 600
23
+ const SLIDES_PER_LINE = 20
24
+
25
+ const WHITE = { r: 1, g: 1, b: 1, a: 1 } as const
26
+
27
+ export function defaultSlideSettings(): SlideSettings {
28
+ return { skipped: false, notes: '', transition: null }
29
+ }
30
+
31
+ /** What a slide keeps, whether or not it was ever set; null for any other layer. */
32
+ export function slideSettings(node: Pick<SceneNode, 'type' | 'slide'>): SlideSettings | null {
33
+ return node.type === 'SLIDE' ? (node.slide ?? defaultSlideSettings()) : null
34
+ }
35
+
36
+ /** The grid that holds a deck's slides on a page, if the page has one. */
37
+ export function slideGrid(graph: SceneGraph, pageId: string): SceneNode | undefined {
38
+ return graph.getChildren(pageId).find((node) => node.type === 'SLIDE_GRID')
39
+ }
40
+
41
+ /** A page's slides by row, in the order a deck presents them. */
42
+ export function slideRows(graph: SceneGraph, pageId: string): SceneNode[][] {
43
+ const grid = slideGrid(graph, pageId)
44
+ if (!grid) return []
45
+ return graph
46
+ .getChildren(grid.id)
47
+ .filter((row) => row.type === 'SLIDE_ROW')
48
+ .map((row) => graph.getChildren(row.id).filter((node) => node.type === 'SLIDE'))
49
+ }
50
+
51
+ /** The slide the deck moves on to from `slide`, passing by skipped slides, or undefined at the end. */
52
+ export function nextSlide(graph: SceneGraph, slide: SceneNode): SceneNode | undefined {
53
+ const page = slide.parentId
54
+ ? graph.closest(slide.parentId, (node) => node.type === 'CANVAS')
55
+ : undefined
56
+ if (!page) return undefined
57
+ const slides = slideRows(graph, page.id).flat()
58
+ const index = slides.findIndex((node) => node.id === slide.id)
59
+ if (index === -1) return undefined
60
+ return slides.slice(index + 1).find((node) => !slideSettings(node)?.skipped)
61
+ }
62
+
63
+ /**
64
+ * Each slide's number, by ID, in the order a deck presents them: skipped slides have none and are
65
+ * not counted, as in Figma.
66
+ */
67
+ export function slideNumbers(graph: SceneGraph, pageId: string): Map<string, number | null> {
68
+ let shown = 0
69
+ return new Map(
70
+ slideRows(graph, pageId)
71
+ .flat()
72
+ .map((slide) => [slide.id, slideSettings(slide)?.skipped ? null : ++shown])
73
+ )
74
+ }
75
+
76
+ /** Names a page's slides by their numbers, and a skipped one `-`, as Figma does. */
77
+ export function renumberSlides(graph: SceneGraph, pageId: string): void {
78
+ for (const [id, number] of slideNumbers(graph, pageId)) {
79
+ const name = number === null ? '-' : String(number)
80
+ if (graph.getNode(id)?.name !== name) graph.updateNode(id, { name })
81
+ }
82
+ }
83
+
84
+ /** Adds the grid a deck's slides sit in to a page. */
85
+ export function createSlideGrid(graph: SceneGraph, pageId: string): SceneNode {
86
+ return graph.createNode('SLIDE_GRID', pageId, {
87
+ name: 'Presentation',
88
+ layoutMode: 'VERTICAL',
89
+ itemSpacing: ROW_GAP,
90
+ // Figma pads a grid before its slides only.
91
+ paddingTop: SLIDE_GAP,
92
+ paddingLeft: SLIDE_GAP,
93
+ primaryAxisSizing: 'HUG',
94
+ counterAxisSizing: 'HUG'
95
+ })
96
+ }
97
+
98
+ /** Adds a row, which Figma calls a section, to the end of a grid. */
99
+ export function createSlideRow(graph: SceneGraph, gridId: string): SceneNode {
100
+ return graph.createNode('SLIDE_ROW', gridId, {
101
+ name: 'Section',
102
+ layoutMode: 'HORIZONTAL',
103
+ layoutWrap: 'WRAP',
104
+ layoutAlignSelf: 'STRETCH',
105
+ itemSpacing: SLIDE_GAP,
106
+ counterAxisSpacing: SLIDE_GAP,
107
+ primaryAxisSizing: 'FIXED',
108
+ counterAxisSizing: 'HUG',
109
+ maxWidth: SLIDES_PER_LINE * (DEFAULT_SLIDE_SIZE.width + SLIDE_GAP) + SLIDE_GAP
110
+ })
111
+ }
112
+
113
+ /** Adds an empty slide to the end of a row, at the size of the slide before it. */
114
+ export function createSlide(graph: SceneGraph, rowId: string): SceneNode {
115
+ const before = graph.getChildren(rowId).findLast((node) => node.type === 'SLIDE')
116
+ const { width, height } = before ?? DEFAULT_SLIDE_SIZE
117
+ return graph.createNode('SLIDE', rowId, {
118
+ name: 'Slide',
119
+ width,
120
+ height,
121
+ clipsContent: true,
122
+ fills: [{ type: 'SOLID', color: { ...WHITE }, opacity: 1, visible: true }],
123
+ slide: defaultSlideSettings()
124
+ })
125
+ }
@@ -0,0 +1,169 @@
1
+ import { compact } from 'es-toolkit/array'
2
+
3
+ import type { SceneGraph } from '../graph'
4
+ import type { SceneNode } from '../types'
5
+ import { easingPreset } from '../variables/easing'
6
+ import {
7
+ mapMotionVariables,
8
+ motionVariableIds,
9
+ resolveMotion,
10
+ resolveTiming,
11
+ type ResolvedMotion
12
+ } from '../variables/motion'
13
+ import type { LayerAnimation, SlideTransition, SlideTransitionStyle } from './types'
14
+
15
+ /** The transition a slide starts with when one is added. */
16
+ export function defaultSlideTransition(): SlideTransition {
17
+ return {
18
+ style: 'DISSOLVE',
19
+ duration: 0.3,
20
+ easing: easingPreset('OUT_CUBIC'),
21
+ timing: { type: 'ON_CLICK' }
22
+ }
23
+ }
24
+
25
+ /** Figma's curve for layer animations, which its panel does not offer to change. */
26
+ const LAYER_ANIMATION_BEZIER = { x1: 0.17, y1: 0, x2: 0.2, y2: 1 }
27
+
28
+ /** The animation a layer starts with when one is added, as in Figma: it slides in from the left. */
29
+ export function defaultLayerAnimation(order: number): LayerAnimation {
30
+ return {
31
+ style: 'SLIDE_FROM_LEFT',
32
+ phase: 'IN',
33
+ trigger: 'ON_CLICK',
34
+ duration: 0.6,
35
+ easing: { easing: 'CUSTOM_CUBIC', bezier: { ...LAYER_ANIMATION_BEZIER } },
36
+ order
37
+ }
38
+ }
39
+
40
+ /** A slide's transition as it plays, with its variables read for the slide. */
41
+ export interface ResolvedSlideTransition extends ResolvedMotion {
42
+ style: SlideTransitionStyle
43
+ /** Seconds before the deck moves on by itself, or null when it waits for the presenter. */
44
+ delay: number | null
45
+ }
46
+
47
+ export function resolveSlideTransition(
48
+ graph: SceneGraph,
49
+ slide: SceneNode
50
+ ): ResolvedSlideTransition | null {
51
+ const transition = slide.slide?.transition
52
+ if (!transition) return null
53
+ const { timing } = transition
54
+ return {
55
+ style: transition.style,
56
+ ...resolveMotion(graph, transition, slide.id),
57
+ delay:
58
+ timing.type === 'AFTER_DELAY'
59
+ ? resolveTiming(graph, timing.delayVariableId, slide.id, timing.delay)
60
+ : null
61
+ }
62
+ }
63
+
64
+ /** The variables a layer's slide transition and animation follow. */
65
+ export function slideVariableIds(node: Pick<SceneNode, 'slide' | 'animation'>): string[] {
66
+ const transition = node.slide?.transition
67
+ return [
68
+ ...(transition ? motionVariableIds(transition) : []),
69
+ ...compact([transition?.timing.type === 'AFTER_DELAY' && transition.timing.delayVariableId]),
70
+ ...(node.animation ? motionVariableIds(node.animation) : [])
71
+ ]
72
+ }
73
+
74
+ /**
75
+ * A layer's slide transition and animation following other variables, as a copy into another
76
+ * document names them; a variable `map` gives nothing for is let go, keeping the value.
77
+ */
78
+ export function mapSlideVariables(
79
+ node: Pick<SceneNode, 'slide' | 'animation'>,
80
+ map: (variableId: string) => string | undefined
81
+ ): Pick<SceneNode, 'slide' | 'animation'> {
82
+ const transition = node.slide?.transition
83
+ let slide = node.slide && structuredClone(node.slide)
84
+ if (slide && transition) {
85
+ const mapped = mapMotionVariables(transition, map)
86
+ if (transition.timing.type === 'AFTER_DELAY') {
87
+ const { delayVariableId, ...timing } = transition.timing
88
+ const delay = delayVariableId === undefined ? undefined : map(delayVariableId)
89
+ mapped.timing = delay === undefined ? timing : { ...timing, delayVariableId: delay }
90
+ }
91
+ slide = { ...slide, transition: mapped }
92
+ }
93
+ return { slide, animation: node.animation && mapMotionVariables(node.animation, map) }
94
+ }
95
+
96
+ /** A layer's animation, with the layer it moves. */
97
+ export interface AnimatedLayer {
98
+ id: string
99
+ animation: LayerAnimation
100
+ }
101
+
102
+ /**
103
+ * A step of a slide's build: its layers' animations, one after another. A step waits for the
104
+ * presenter, except a first one made only of `AFTER_PREVIOUS` animations, which plays as the slide
105
+ * appears.
106
+ */
107
+ export interface BuildStep {
108
+ onClick: boolean
109
+ layers: AnimatedLayer[]
110
+ }
111
+
112
+ /** The animated layers of a slide, in the order they play: by `order`, then by layer order. */
113
+ export function animatedLayers(graph: SceneGraph, slideId: string): AnimatedLayer[] {
114
+ const layers: AnimatedLayer[] = []
115
+ const visit = (id: string) => {
116
+ for (const child of graph.getChildren(id)) {
117
+ if (child.animation) layers.push({ id: child.id, animation: child.animation })
118
+ visit(child.id)
119
+ }
120
+ }
121
+ visit(slideId)
122
+ // Array sort is stable, so equal orders keep layer order.
123
+ return layers.sort((a, b) => a.animation.order - b.animation.order)
124
+ }
125
+
126
+ /** A slide's build: its animations grouped into the steps a presenter clicks through. */
127
+ export function slideBuild(graph: SceneGraph, slideId: string): BuildStep[] {
128
+ const steps: BuildStep[] = []
129
+ for (const layer of animatedLayers(graph, slideId)) {
130
+ const last = steps.at(-1)
131
+ if (layer.animation.trigger === 'AFTER_PREVIOUS' && last) last.layers.push(layer)
132
+ else steps.push({ onClick: layer.animation.trigger === 'ON_CLICK', layers: [layer] })
133
+ }
134
+ return steps
135
+ }
136
+
137
+ /**
138
+ * The slide a layer animates on, or undefined for a layer that cannot have an animation: one on no
139
+ * slide, a slide itself, or a layer inside an instance, whose component gives it its fields.
140
+ */
141
+ export function animationSlide(graph: SceneGraph, layerId: string): SceneNode | undefined {
142
+ const node = graph.getNode(layerId)
143
+ if (!node?.parentId || node.type === 'SLIDE') return undefined
144
+ if (graph.closest(node.parentId, (item) => item.type === 'INSTANCE')) return undefined
145
+ return graph.closest(node.parentId, (item) => item.type === 'SLIDE') ?? undefined
146
+ }
147
+
148
+ /**
149
+ * The layer an animation for `layerId` goes on, as Figma's Animate panel picks it: the layer
150
+ * itself, or for a layer inside an instance the outermost instance on the slide, which Figma
151
+ * animates instead. Undefined for a layer on no slide, or a slide.
152
+ */
153
+ export function animationTarget(graph: SceneGraph, layerId: string): string | undefined {
154
+ const node = graph.getNode(layerId)
155
+ if (!node || node.type === 'SLIDE') return undefined
156
+ let target = layerId
157
+ let id = node.parentId
158
+ // A parent cycle in bad data ends the walk.
159
+ const seen = new Set<string>()
160
+ while (id && !seen.has(id)) {
161
+ seen.add(id)
162
+ const parent = graph.getNode(id)
163
+ if (!parent) return undefined
164
+ if (parent.type === 'SLIDE') return target
165
+ if (parent.type === 'INSTANCE') target = parent.id
166
+ id = parent.parentId
167
+ }
168
+ return undefined
169
+ }
@@ -0,0 +1,200 @@
1
+ import type { Vector } from '../primitives'
2
+ import type { LayerAnimation, SlideTransitionStyle } from './types'
3
+
4
+ /**
5
+ * How a slide is drawn at a moment of a transition: moved by fractions of its own width and
6
+ * height, faded, and darkened towards black.
7
+ */
8
+ export interface SlideFrame {
9
+ x: number
10
+ y: number
11
+ opacity: number
12
+ /** How dark: 0 is the slide as it is, 1 black. */
13
+ dim: number
14
+ }
15
+
16
+ /** The two slides of a transition, the one drawn first below the other. */
17
+ export interface TransitionFrames {
18
+ from: SlideFrame
19
+ to: SlideFrame
20
+ /** Which slide is drawn on top. */
21
+ above: 'from' | 'to'
22
+ }
23
+
24
+ /** How far the slide underneath moves in Slide in and Slide out, as Figma moves it. */
25
+ const PARALLAX = 0.25
26
+ /** How dark the slide underneath gets in Slide in and Slide out. */
27
+ const UNDERNEATH_DIM = 0.5
28
+
29
+ type Direction = readonly [number, number]
30
+ const RIGHTWARDS: Direction = [1, 0]
31
+ const LEFTWARDS: Direction = [-1, 0]
32
+ const DOWNWARDS: Direction = [0, 1]
33
+ const UPWARDS: Direction = [0, -1]
34
+
35
+ /**
36
+ * The way a style moves its slides. A `FROM` side is the side the slide comes from. Figma's `OUT_TO`
37
+ * names are mirrored: its panel shows SLIDE_OUT_TO_LEFT as → and plays it moving right.
38
+ */
39
+ function directionOf(style: SlideTransitionStyle): Direction {
40
+ if (style.endsWith('FROM_LEFT') || style.endsWith('OUT_TO_LEFT')) return RIGHTWARDS
41
+ if (style.endsWith('FROM_RIGHT') || style.endsWith('OUT_TO_RIGHT')) return LEFTWARDS
42
+ if (style.endsWith('FROM_TOP') || style.endsWith('OUT_TO_TOP')) return DOWNWARDS
43
+ return UPWARDS
44
+ }
45
+
46
+ function clamp01(value: number): number {
47
+ return Math.min(1, Math.max(0, value))
48
+ }
49
+
50
+ /** A direction scaled by `amount`, with no negative zero where the direction has no part. */
51
+ function along(direction: Direction, amount: number): Vector {
52
+ return { x: direction[0] * amount || 0, y: direction[1] * amount || 0 }
53
+ }
54
+
55
+ function frame(direction: Direction, offset: number, dim = 0, opacity = 1): SlideFrame {
56
+ return { ...along(direction, offset), opacity, dim: clamp01(dim) }
57
+ }
58
+
59
+ const STILL: SlideFrame = { x: 0, y: 0, opacity: 1, dim: 0 }
60
+
61
+ /**
62
+ * Where the slides of a transition are when its easing is at `position`: 0 at the start, 1 at the
63
+ * end, past 1 while a spring overshoots. Smart animate plays as Dissolve for now.
64
+ */
65
+ export function transitionFrames(style: SlideTransitionStyle, position: number): TransitionFrames {
66
+ const p = position
67
+ if (style === 'NONE') return { from: STILL, to: STILL, above: 'to' }
68
+ if (style === 'DISSOLVE' || style === 'SMART_ANIMATE')
69
+ return { from: STILL, to: { ...STILL, opacity: clamp01(p) }, above: 'to' }
70
+ const direction = directionOf(style)
71
+ if (style.startsWith('PUSH_'))
72
+ return { from: frame(direction, p), to: frame(direction, p - 1), above: 'to' }
73
+ if (style.startsWith('MOVE_FROM_'))
74
+ return { from: STILL, to: frame(direction, p - 1), above: 'to' }
75
+ if (style.startsWith('MOVE_OUT_')) return { from: frame(direction, p), to: STILL, above: 'from' }
76
+ if (style.startsWith('SLIDE_FROM_')) {
77
+ return {
78
+ from: frame(direction, PARALLAX * p, UNDERNEATH_DIM * p),
79
+ to: frame(direction, p - 1),
80
+ above: 'to'
81
+ }
82
+ }
83
+ return {
84
+ from: frame(direction, p),
85
+ to: frame(direction, PARALLAX * (p - 1), UNDERNEATH_DIM * (1 - p)),
86
+ above: 'from'
87
+ }
88
+ }
89
+
90
+ /** How far, in slide pixels, a layer slides on or off, whatever its size, as in Figma. */
91
+ export const LAYER_SLIDE_DISTANCE = 300
92
+
93
+ /** Where a layer animating onto or off its slide is drawn, relative to where it is. */
94
+ export interface LayerFrame {
95
+ x: number
96
+ y: number
97
+ opacity: number
98
+ }
99
+
100
+ const LAYER_DIRECTIONS: Record<Exclude<LayerAnimation['style'], 'FADE'>, Direction> = {
101
+ SLIDE_FROM_LEFT: RIGHTWARDS,
102
+ SLIDE_FROM_RIGHT: LEFTWARDS,
103
+ SLIDE_FROM_TOP: DOWNWARDS,
104
+ SLIDE_FROM_BOTTOM: UPWARDS
105
+ }
106
+
107
+ /**
108
+ * Where an animating layer is when its easing is at `position`. A layer coming in fades in as it
109
+ * slides the last stretch to its place; one going out keeps moving the same way as it fades.
110
+ */
111
+ export function layerFrame(
112
+ animation: Pick<LayerAnimation, 'style' | 'phase'>,
113
+ position: number
114
+ ): LayerFrame {
115
+ const shown = animation.phase === 'IN' ? position : 1 - position
116
+ const opacity = clamp01(shown)
117
+ if (animation.style === 'FADE') return { x: 0, y: 0, opacity }
118
+ const offset = LAYER_SLIDE_DISTANCE * (animation.phase === 'IN' ? position - 1 : position)
119
+ return { ...along(LAYER_DIRECTIONS[animation.style], offset), opacity }
120
+ }
121
+
122
+ /** Where a layer is drawn before its step has played, or after. */
123
+ export function layerAtRest(animation: Pick<LayerAnimation, 'phase'>, played: boolean): LayerFrame {
124
+ const shown = animation.phase === 'IN' ? played : !played
125
+ return { x: 0, y: 0, opacity: shown ? 1 : 0 }
126
+ }
127
+
128
+ /** The transitions Figma's panel offers, each but the first three in four directions. */
129
+ export const SLIDE_TRANSITION_KINDS = [
130
+ 'NONE',
131
+ 'SMART_ANIMATE',
132
+ 'DISSOLVE',
133
+ 'PUSH',
134
+ 'SLIDE_IN',
135
+ 'SLIDE_OUT',
136
+ 'MOVE_IN',
137
+ 'MOVE_OUT'
138
+ ] as const
139
+ export type SlideTransitionKind = (typeof SLIDE_TRANSITION_KINDS)[number]
140
+
141
+ /** Which way a transition or a layer moves, as Figma's arrows show it. */
142
+ export const MOTION_DIRECTIONS = ['LEFT', 'RIGHT', 'DOWN', 'UP'] as const
143
+ export type MotionDirection = (typeof MOTION_DIRECTIONS)[number]
144
+
145
+ /** The record names' prefix for each kind that moves. */
146
+ const KIND_PREFIXES = {
147
+ PUSH: 'PUSH_FROM_',
148
+ SLIDE_IN: 'SLIDE_FROM_',
149
+ SLIDE_OUT: 'SLIDE_OUT_TO_',
150
+ MOVE_IN: 'MOVE_FROM_',
151
+ MOVE_OUT: 'MOVE_OUT_TO_'
152
+ } as const
153
+
154
+ /**
155
+ * The side a record names for a way of moving: what moves rightwards comes from the left, and,
156
+ * as Figma names them, an `OUT_TO_LEFT` moves rightwards too.
157
+ */
158
+ const SIDES: Record<MotionDirection, 'LEFT' | 'RIGHT' | 'TOP' | 'BOTTOM'> = {
159
+ RIGHT: 'LEFT',
160
+ LEFT: 'RIGHT',
161
+ DOWN: 'TOP',
162
+ UP: 'BOTTOM'
163
+ }
164
+
165
+ function directionName(direction: Direction): MotionDirection {
166
+ if (direction[0] > 0) return 'RIGHT'
167
+ if (direction[0] < 0) return 'LEFT'
168
+ return direction[1] > 0 ? 'DOWN' : 'UP'
169
+ }
170
+
171
+ /** A style's kind, as Figma's panel lists it. */
172
+ export function transitionKind(style: SlideTransitionStyle): SlideTransitionKind {
173
+ for (const [kind, prefix] of Object.entries(KIND_PREFIXES))
174
+ if (style.startsWith(prefix)) return kind as SlideTransitionKind
175
+ return style === 'NONE' || style === 'SMART_ANIMATE' ? style : 'DISSOLVE'
176
+ }
177
+
178
+ /** Which way a style moves its slides, or null for one that does not move them. */
179
+ export function transitionDirection(style: SlideTransitionStyle): MotionDirection | null {
180
+ return transitionKind(style) in KIND_PREFIXES ? directionName(directionOf(style)) : null
181
+ }
182
+
183
+ /** The style of a kind moving `direction`; a kind that does not move ignores it. */
184
+ export function transitionStyle(
185
+ kind: SlideTransitionKind,
186
+ direction: MotionDirection
187
+ ): SlideTransitionStyle {
188
+ if (kind === 'NONE' || kind === 'SMART_ANIMATE' || kind === 'DISSOLVE') return kind
189
+ return `${KIND_PREFIXES[kind]}${SIDES[direction]}` as SlideTransitionStyle
190
+ }
191
+
192
+ /** Which way a layer animation moves its layer, or null for a fade. */
193
+ export function layerAnimationDirection(style: LayerAnimation['style']): MotionDirection | null {
194
+ return style === 'FADE' ? null : directionName(LAYER_DIRECTIONS[style])
195
+ }
196
+
197
+ /** The layer animation that slides its layer `direction`, or fades it with null. */
198
+ export function layerAnimationStyle(direction: MotionDirection | null): LayerAnimation['style'] {
199
+ return direction ? `SLIDE_FROM_${SIDES[direction]}` : 'FADE'
200
+ }
@@ -0,0 +1,94 @@
1
+ import type { Easing } from '../types'
2
+
3
+ /** How a slide gives way to the next, by Figma's names for its slide transitions. */
4
+ export const SLIDE_TRANSITION_STYLES = [
5
+ 'NONE',
6
+ 'DISSOLVE',
7
+ 'SLIDE_FROM_LEFT',
8
+ 'SLIDE_FROM_RIGHT',
9
+ 'SLIDE_FROM_BOTTOM',
10
+ 'SLIDE_FROM_TOP',
11
+ 'PUSH_FROM_LEFT',
12
+ 'PUSH_FROM_RIGHT',
13
+ 'PUSH_FROM_BOTTOM',
14
+ 'PUSH_FROM_TOP',
15
+ 'MOVE_FROM_LEFT',
16
+ 'MOVE_FROM_RIGHT',
17
+ 'MOVE_FROM_TOP',
18
+ 'MOVE_FROM_BOTTOM',
19
+ 'SLIDE_OUT_TO_LEFT',
20
+ 'SLIDE_OUT_TO_RIGHT',
21
+ 'SLIDE_OUT_TO_TOP',
22
+ 'SLIDE_OUT_TO_BOTTOM',
23
+ 'MOVE_OUT_TO_LEFT',
24
+ 'MOVE_OUT_TO_RIGHT',
25
+ 'MOVE_OUT_TO_TOP',
26
+ 'MOVE_OUT_TO_BOTTOM',
27
+ 'SMART_ANIMATE'
28
+ ] as const
29
+ export type SlideTransitionStyle = (typeof SLIDE_TRANSITION_STYLES)[number]
30
+
31
+ /** What moves the deck on from a slide: a click, or `delay` seconds passing. */
32
+ export type SlideTransitionTiming =
33
+ | { type: 'ON_CLICK' }
34
+ | {
35
+ type: 'AFTER_DELAY'
36
+ delay: number
37
+ /** The TIMING variable the delay follows while it exists; `delay` is kept beside it. */
38
+ delayVariableId?: string
39
+ }
40
+
41
+ /**
42
+ * How a deck moves on from a slide. It names no slide: the next one is the next in the grid. The
43
+ * duration and easing may follow TIMING and EASING variables, keeping their values beside them
44
+ * for when the variables are gone, as a behaviour's transition does.
45
+ */
46
+ export interface SlideTransition {
47
+ style: SlideTransitionStyle
48
+ /** In seconds; a spring easing settles in its own time instead. */
49
+ duration: number
50
+ easing: Easing
51
+ durationVariableId?: string
52
+ easingVariableId?: string
53
+ timing: SlideTransitionTiming
54
+ }
55
+
56
+ /** How a layer comes onto or leaves its slide, by Figma's names: a slide moves from that side. */
57
+ export const LAYER_ANIMATION_STYLES = [
58
+ 'FADE',
59
+ 'SLIDE_FROM_LEFT',
60
+ 'SLIDE_FROM_RIGHT',
61
+ 'SLIDE_FROM_TOP',
62
+ 'SLIDE_FROM_BOTTOM'
63
+ ] as const
64
+ export type LayerAnimationStyle = (typeof LAYER_ANIMATION_STYLES)[number]
65
+
66
+ /**
67
+ * A layer's animation on its slide: a step of the slide's build. Steps play in `order`; one that
68
+ * plays `ON_CLICK` waits for the presenter, one that plays `AFTER_PREVIOUS` follows the step before
69
+ * it. It lives on the layer so a copied layer or slide keeps it, and a layer has one at most, as in
70
+ * Figma.
71
+ */
72
+ export interface LayerAnimation {
73
+ style: LayerAnimationStyle
74
+ /** `IN` brings the layer on, so it is hidden until its step; `OUT` takes it away. */
75
+ phase: 'IN' | 'OUT'
76
+ trigger: 'ON_CLICK' | 'AFTER_PREVIOUS'
77
+ /** In seconds. */
78
+ duration: number
79
+ easing: Easing
80
+ durationVariableId?: string
81
+ easingVariableId?: string
82
+ /** Where the step plays among the slide's; ties play in layer order. */
83
+ order: number
84
+ }
85
+
86
+ /** What a slide keeps besides its layers. */
87
+ export interface SlideSettings {
88
+ /** Whether presenting passes the slide by; a skipped slide has no number either. */
89
+ skipped: boolean
90
+ /** The presenter's notes as plain text, a paragraph per line. */
91
+ notes: string
92
+ /** How the deck moves on from the slide, or null when it was never set. */
93
+ transition: SlideTransition | null
94
+ }