@bydiorama/motion 0.0.0-stage → 0.4.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 (354) hide show
  1. package/CREDITS.md +53 -0
  2. package/LICENSE +21 -0
  3. package/README.md +137 -2
  4. package/catalog.json +4697 -0
  5. package/dist/npm/brief/brief.d.ts +28 -0
  6. package/dist/npm/brief/brief.js +159 -0
  7. package/dist/npm/brief/types.d.ts +75 -0
  8. package/dist/npm/brief/types.js +2 -0
  9. package/dist/npm/browser/motion.js +1039 -0
  10. package/dist/npm/browser/page.js +4821 -0
  11. package/dist/npm/browser/wizard.js +1511 -0
  12. package/dist/npm/build/design.d.ts +54 -0
  13. package/dist/npm/build/design.js +91 -0
  14. package/dist/npm/build/index.d.ts +39 -0
  15. package/dist/npm/build/index.js +66 -0
  16. package/dist/npm/build/iso.d.ts +41 -0
  17. package/dist/npm/build/iso.js +71 -0
  18. package/dist/npm/catalog.d.ts +24 -0
  19. package/dist/npm/catalog.js +23 -0
  20. package/dist/npm/cli/browser.d.ts +26 -0
  21. package/dist/npm/cli/browser.js +66 -0
  22. package/dist/npm/cli/capture.d.ts +26 -0
  23. package/dist/npm/cli/capture.js +94 -0
  24. package/dist/npm/cli/files.d.ts +14 -0
  25. package/dist/npm/cli/files.js +87 -0
  26. package/dist/npm/cli/frames.d.ts +27 -0
  27. package/dist/npm/cli/frames.js +125 -0
  28. package/dist/npm/cli/guard.d.ts +23 -0
  29. package/dist/npm/cli/guard.js +158 -0
  30. package/dist/npm/cli/library.d.ts +2 -0
  31. package/dist/npm/cli/library.js +55 -0
  32. package/dist/npm/cli/main.d.ts +17 -0
  33. package/dist/npm/cli/main.js +964 -0
  34. package/dist/npm/cli/motion.d.ts +2 -0
  35. package/dist/npm/cli/motion.js +6 -0
  36. package/dist/npm/cli/record.d.ts +36 -0
  37. package/dist/npm/cli/record.js +142 -0
  38. package/dist/npm/cli/review.d.ts +45 -0
  39. package/dist/npm/cli/review.js +139 -0
  40. package/dist/npm/cli/schema.d.ts +852 -0
  41. package/dist/npm/cli/schema.js +120 -0
  42. package/dist/npm/cli/server.d.ts +17 -0
  43. package/dist/npm/cli/server.js +135 -0
  44. package/dist/npm/core/ease.d.ts +39 -0
  45. package/dist/npm/core/ease.js +176 -0
  46. package/dist/npm/core/frame.d.ts +52 -0
  47. package/dist/npm/core/frame.js +60 -0
  48. package/dist/npm/core/shapes.d.ts +8 -0
  49. package/dist/npm/core/shapes.js +88 -0
  50. package/dist/npm/core/stagger.d.ts +19 -0
  51. package/dist/npm/core/stagger.js +77 -0
  52. package/dist/npm/core/tap.d.ts +19 -0
  53. package/dist/npm/core/tap.js +42 -0
  54. package/dist/npm/core/track.d.ts +4 -0
  55. package/dist/npm/core/track.js +23 -0
  56. package/dist/npm/dom/mount.d.ts +127 -0
  57. package/dist/npm/dom/mount.js +950 -0
  58. package/dist/npm/dom/page.d.ts +37 -0
  59. package/dist/npm/dom/page.js +77 -0
  60. package/dist/npm/dom/soundtrack.d.ts +13 -0
  61. package/dist/npm/dom/soundtrack.js +37 -0
  62. package/dist/npm/dom/stage.css.d.ts +1 -0
  63. package/dist/npm/dom/stage.css.js +44 -0
  64. package/dist/npm/dom/tokens.d.ts +10 -0
  65. package/dist/npm/dom/tokens.js +38 -0
  66. package/dist/npm/dom/ui-themes.css.d.ts +8 -0
  67. package/dist/npm/dom/ui-themes.css.js +9 -0
  68. package/dist/npm/film/beats.d.ts +64 -0
  69. package/dist/npm/film/beats.js +282 -0
  70. package/dist/npm/film/pace.d.ts +94 -0
  71. package/dist/npm/film/pace.js +396 -0
  72. package/dist/npm/film/resolve.d.ts +16 -0
  73. package/dist/npm/film/resolve.js +997 -0
  74. package/dist/npm/film/tempo.d.ts +19 -0
  75. package/dist/npm/film/tempo.js +34 -0
  76. package/dist/npm/film/tune.d.ts +17 -0
  77. package/dist/npm/film/tune.js +68 -0
  78. package/dist/npm/film/types.d.ts +416 -0
  79. package/dist/npm/film/types.js +16 -0
  80. package/dist/npm/index.d.ts +18 -0
  81. package/dist/npm/index.js +11 -0
  82. package/dist/npm/primitives/blur.d.ts +14 -0
  83. package/dist/npm/primitives/blur.js +59 -0
  84. package/dist/npm/primitives/canvas.d.ts +5 -0
  85. package/dist/npm/primitives/canvas.js +13 -0
  86. package/dist/npm/primitives/el/box.d.ts +2 -0
  87. package/dist/npm/primitives/el/box.js +24 -0
  88. package/dist/npm/primitives/el/frames.d.ts +15 -0
  89. package/dist/npm/primitives/el/frames.js +71 -0
  90. package/dist/npm/primitives/el/html.d.ts +2 -0
  91. package/dist/npm/primitives/el/html.js +14 -0
  92. package/dist/npm/primitives/el/image.d.ts +2 -0
  93. package/dist/npm/primitives/el/image.js +43 -0
  94. package/dist/npm/primitives/el/slot.d.ts +2 -0
  95. package/dist/npm/primitives/el/slot.js +25 -0
  96. package/dist/npm/primitives/el/text.d.ts +2 -0
  97. package/dist/npm/primitives/el/text.js +13 -0
  98. package/dist/npm/primitives/el/video.d.ts +6 -0
  99. package/dist/npm/primitives/el/video.js +179 -0
  100. package/dist/npm/primitives/fx/counter-roll.d.ts +2 -0
  101. package/dist/npm/primitives/fx/counter-roll.js +32 -0
  102. package/dist/npm/primitives/fx/depth-drift.d.ts +2 -0
  103. package/dist/npm/primitives/fx/depth-drift.js +44 -0
  104. package/dist/npm/primitives/fx/grid-ripple.d.ts +2 -0
  105. package/dist/npm/primitives/fx/grid-ripple.js +59 -0
  106. package/dist/npm/primitives/fx/odometer.d.ts +2 -0
  107. package/dist/npm/primitives/fx/odometer.js +80 -0
  108. package/dist/npm/primitives/fx/pan-across.d.ts +17 -0
  109. package/dist/npm/primitives/fx/pan-across.js +76 -0
  110. package/dist/npm/primitives/fx/path-draw.d.ts +2 -0
  111. package/dist/npm/primitives/fx/path-draw.js +105 -0
  112. package/dist/npm/primitives/fx/pin-drop.d.ts +2 -0
  113. package/dist/npm/primitives/fx/pin-drop.js +92 -0
  114. package/dist/npm/primitives/fx/shape-morph.d.ts +2 -0
  115. package/dist/npm/primitives/fx/shape-morph.js +65 -0
  116. package/dist/npm/primitives/fx/slow-push.d.ts +13 -0
  117. package/dist/npm/primitives/fx/slow-push.js +56 -0
  118. package/dist/npm/primitives/fx/stagger-fill.d.ts +2 -0
  119. package/dist/npm/primitives/fx/stagger-fill.js +33 -0
  120. package/dist/npm/primitives/index.d.ts +4 -0
  121. package/dist/npm/primitives/index.js +78 -0
  122. package/dist/npm/primitives/rig/browser-window.d.ts +2 -0
  123. package/dist/npm/primitives/rig/browser-window.js +142 -0
  124. package/dist/npm/primitives/rig/camera.d.ts +36 -0
  125. package/dist/npm/primitives/rig/camera.js +81 -0
  126. package/dist/npm/primitives/rig/footage-plane.d.ts +27 -0
  127. package/dist/npm/primitives/rig/footage-plane.js +257 -0
  128. package/dist/npm/primitives/rig/layer-stack.d.ts +39 -0
  129. package/dist/npm/primitives/rig/layer-stack.js +276 -0
  130. package/dist/npm/primitives/rig/orbit-ring.d.ts +2 -0
  131. package/dist/npm/primitives/rig/orbit-ring.js +59 -0
  132. package/dist/npm/primitives/rig/tab-stack.d.ts +9 -0
  133. package/dist/npm/primitives/rig/tab-stack.js +143 -0
  134. package/dist/npm/primitives/scene/bar-chart.d.ts +2 -0
  135. package/dist/npm/primitives/scene/bar-chart.js +83 -0
  136. package/dist/npm/primitives/scene/bento-grid.d.ts +49 -0
  137. package/dist/npm/primitives/scene/bento-grid.js +293 -0
  138. package/dist/npm/primitives/scene/grid-wall.d.ts +18 -0
  139. package/dist/npm/primitives/scene/grid-wall.js +110 -0
  140. package/dist/npm/primitives/scene/line-chart.d.ts +2 -0
  141. package/dist/npm/primitives/scene/line-chart.js +121 -0
  142. package/dist/npm/primitives/scene/logo-reveal.d.ts +2 -0
  143. package/dist/npm/primitives/scene/logo-reveal.js +117 -0
  144. package/dist/npm/primitives/scene/marquee-wall.d.ts +2 -0
  145. package/dist/npm/primitives/scene/marquee-wall.js +82 -0
  146. package/dist/npm/primitives/scene/post-carousel.d.ts +16 -0
  147. package/dist/npm/primitives/scene/post-carousel.js +195 -0
  148. package/dist/npm/primitives/scene/strip-cycle.d.ts +49 -0
  149. package/dist/npm/primitives/scene/strip-cycle.js +237 -0
  150. package/dist/npm/primitives/split.d.ts +34 -0
  151. package/dist/npm/primitives/split.js +105 -0
  152. package/dist/npm/primitives/texture/beat-field.d.ts +13 -0
  153. package/dist/npm/primitives/texture/beat-field.js +113 -0
  154. package/dist/npm/primitives/texture/gradient-drift.d.ts +2 -0
  155. package/dist/npm/primitives/texture/gradient-drift.js +56 -0
  156. package/dist/npm/primitives/texture/grain.d.ts +2 -0
  157. package/dist/npm/primitives/texture/grain.js +54 -0
  158. package/dist/npm/primitives/texture/halftone-field.d.ts +2 -0
  159. package/dist/npm/primitives/texture/halftone-field.js +36 -0
  160. package/dist/npm/primitives/texture/signal-field.d.ts +4 -0
  161. package/dist/npm/primitives/texture/signal-field.js +107 -0
  162. package/dist/npm/primitives/texture/vignette.d.ts +2 -0
  163. package/dist/npm/primitives/texture/vignette.js +23 -0
  164. package/dist/npm/primitives/transition/band-sweep.d.ts +22 -0
  165. package/dist/npm/primitives/transition/band-sweep.js +111 -0
  166. package/dist/npm/primitives/transition/beat-cut.d.ts +2 -0
  167. package/dist/npm/primitives/transition/beat-cut.js +10 -0
  168. package/dist/npm/primitives/transition/blur-dissolve.d.ts +2 -0
  169. package/dist/npm/primitives/transition/blur-dissolve.js +28 -0
  170. package/dist/npm/primitives/transition/camera-travel.d.ts +2 -0
  171. package/dist/npm/primitives/transition/camera-travel.js +69 -0
  172. package/dist/npm/primitives/transition/cover-reveal.d.ts +2 -0
  173. package/dist/npm/primitives/transition/cover-reveal.js +52 -0
  174. package/dist/npm/primitives/transition/curtain.d.ts +2 -0
  175. package/dist/npm/primitives/transition/curtain.js +40 -0
  176. package/dist/npm/primitives/transition/dive-in.d.ts +2 -0
  177. package/dist/npm/primitives/transition/dive-in.js +52 -0
  178. package/dist/npm/primitives/transition/fly-past.d.ts +2 -0
  179. package/dist/npm/primitives/transition/fly-past.js +87 -0
  180. package/dist/npm/primitives/transition/iris.d.ts +2 -0
  181. package/dist/npm/primitives/transition/iris.js +38 -0
  182. package/dist/npm/primitives/transition/overlay.d.ts +4 -0
  183. package/dist/npm/primitives/transition/overlay.js +24 -0
  184. package/dist/npm/primitives/transition/push.d.ts +2 -0
  185. package/dist/npm/primitives/transition/push.js +35 -0
  186. package/dist/npm/primitives/transition/signal-wipe.d.ts +2 -0
  187. package/dist/npm/primitives/transition/signal-wipe.js +67 -0
  188. package/dist/npm/primitives/transition/slant-wipe.d.ts +2 -0
  189. package/dist/npm/primitives/transition/slant-wipe.js +30 -0
  190. package/dist/npm/primitives/transition/stack-over.d.ts +2 -0
  191. package/dist/npm/primitives/transition/stack-over.js +38 -0
  192. package/dist/npm/primitives/transition/step-wipe.d.ts +2 -0
  193. package/dist/npm/primitives/transition/step-wipe.js +29 -0
  194. package/dist/npm/primitives/transition/strip-wipe.d.ts +40 -0
  195. package/dist/npm/primitives/transition/strip-wipe.js +121 -0
  196. package/dist/npm/primitives/transition/whip-pan.d.ts +2 -0
  197. package/dist/npm/primitives/transition/whip-pan.js +45 -0
  198. package/dist/npm/primitives/type/block-reveal.d.ts +2 -0
  199. package/dist/npm/primitives/type/block-reveal.js +61 -0
  200. package/dist/npm/primitives/type/char-cascade.d.ts +2 -0
  201. package/dist/npm/primitives/type/char-cascade.js +45 -0
  202. package/dist/npm/primitives/type/echo.d.ts +2 -0
  203. package/dist/npm/primitives/type/echo.js +57 -0
  204. package/dist/npm/primitives/type/fill-text.d.ts +14 -0
  205. package/dist/npm/primitives/type/fill-text.js +82 -0
  206. package/dist/npm/primitives/type/mask-reveal.d.ts +2 -0
  207. package/dist/npm/primitives/type/mask-reveal.js +58 -0
  208. package/dist/npm/primitives/type/scramble.d.ts +2 -0
  209. package/dist/npm/primitives/type/scramble.js +34 -0
  210. package/dist/npm/primitives/type/scribble-highlight.d.ts +2 -0
  211. package/dist/npm/primitives/type/scribble-highlight.js +84 -0
  212. package/dist/npm/primitives/type/shimmer.d.ts +2 -0
  213. package/dist/npm/primitives/type/shimmer.js +35 -0
  214. package/dist/npm/primitives/type/tracking-in.d.ts +2 -0
  215. package/dist/npm/primitives/type/tracking-in.js +37 -0
  216. package/dist/npm/primitives/type/typed-title.d.ts +2 -0
  217. package/dist/npm/primitives/type/typed-title.js +33 -0
  218. package/dist/npm/primitives/type/word-build.d.ts +2 -0
  219. package/dist/npm/primitives/type/word-build.js +44 -0
  220. package/dist/npm/primitives/type/word-roller.d.ts +2 -0
  221. package/dist/npm/primitives/type/word-roller.js +80 -0
  222. package/dist/npm/primitives/types.d.ts +183 -0
  223. package/dist/npm/primitives/types.js +5 -0
  224. package/dist/npm/primitives/ui/cursor-click.d.ts +4 -0
  225. package/dist/npm/primitives/ui/cursor-click.js +68 -0
  226. package/dist/npm/primitives/ui/page-scroll.d.ts +17 -0
  227. package/dist/npm/primitives/ui/page-scroll.js +98 -0
  228. package/dist/npm/review/fft.d.ts +4 -0
  229. package/dist/npm/review/fft.js +71 -0
  230. package/dist/npm/review/measure.d.ts +170 -0
  231. package/dist/npm/review/measure.js +577 -0
  232. package/dist/npm/tokens.d.ts +50 -0
  233. package/dist/npm/tokens.js +49 -0
  234. package/dist/npm/version.d.ts +1 -0
  235. package/dist/npm/version.js +1 -0
  236. package/examples/builder.film.mjs +18 -0
  237. package/films/feature-announcement.film.json +70 -0
  238. package/library/narratives/app-demo.md +64 -0
  239. package/library/narratives/brand-identity.md +78 -0
  240. package/library/narratives/capability-through-type.md +53 -0
  241. package/library/narratives/data-story.md +59 -0
  242. package/library/narratives/explainer.md +64 -0
  243. package/library/narratives/feature-announcement.md +68 -0
  244. package/library/narratives/infinite-loop.md +28 -0
  245. package/library/narratives/platform-launch.md +81 -0
  246. package/library/narratives/social-teaser.md +45 -0
  247. package/library/narratives/title-sequence.md +55 -0
  248. package/library/narratives/website-launch.md +65 -0
  249. package/library/primitives/fx/card-arrangements.md +26 -0
  250. package/library/primitives/fx/counter-roll.md +27 -0
  251. package/library/primitives/fx/depth-drift.md +32 -0
  252. package/library/primitives/fx/grid-ripple.md +58 -0
  253. package/library/primitives/fx/letter-interleave.md +26 -0
  254. package/library/primitives/fx/marquee-highlight.md +27 -0
  255. package/library/primitives/fx/mosaic-fill.md +23 -0
  256. package/library/primitives/fx/odometer.md +44 -0
  257. package/library/primitives/fx/pan-across.md +63 -0
  258. package/library/primitives/fx/path-draw.md +54 -0
  259. package/library/primitives/fx/pin-drop.md +51 -0
  260. package/library/primitives/fx/radial-burst.md +33 -0
  261. package/library/primitives/fx/shape-morph.md +45 -0
  262. package/library/primitives/fx/slow-push.md +63 -0
  263. package/library/primitives/fx/stagger-fill.md +28 -0
  264. package/library/primitives/rig/browser-window.md +113 -0
  265. package/library/primitives/rig/flip-ticker.md +26 -0
  266. package/library/primitives/rig/footage-plane.md +90 -0
  267. package/library/primitives/rig/layer-stack.md +168 -0
  268. package/library/primitives/rig/orbit-ring.md +43 -0
  269. package/library/primitives/rig/rolodex.md +31 -0
  270. package/library/primitives/rig/tab-stack.md +116 -0
  271. package/library/primitives/rig/tumbling-object.md +27 -0
  272. package/library/primitives/scene/bar-chart.md +49 -0
  273. package/library/primitives/scene/bento-grid.md +74 -0
  274. package/library/primitives/scene/end-card.md +28 -0
  275. package/library/primitives/scene/grid-wall.md +61 -0
  276. package/library/primitives/scene/hero-object.md +33 -0
  277. package/library/primitives/scene/kinetic-headline.md +34 -0
  278. package/library/primitives/scene/line-chart.md +47 -0
  279. package/library/primitives/scene/logo-reveal.md +53 -0
  280. package/library/primitives/scene/marquee-wall.md +33 -0
  281. package/library/primitives/scene/mosaic.md +28 -0
  282. package/library/primitives/scene/post-carousel.md +68 -0
  283. package/library/primitives/scene/specimen-grid.md +28 -0
  284. package/library/primitives/scene/stat-with-evidence.md +34 -0
  285. package/library/primitives/scene/strip-cycle.md +122 -0
  286. package/library/primitives/scene/zoomed-ui.md +29 -0
  287. package/library/primitives/texture/ascii.md +22 -0
  288. package/library/primitives/texture/beat-field.md +85 -0
  289. package/library/primitives/texture/depth-fade.md +23 -0
  290. package/library/primitives/texture/dither.md +27 -0
  291. package/library/primitives/texture/gradient-drift.md +50 -0
  292. package/library/primitives/texture/grain.md +39 -0
  293. package/library/primitives/texture/halftone-field.md +26 -0
  294. package/library/primitives/texture/signal-field.md +61 -0
  295. package/library/primitives/texture/vignette.md +53 -0
  296. package/library/primitives/transition/band-sweep.md +63 -0
  297. package/library/primitives/transition/beat-cut.md +27 -0
  298. package/library/primitives/transition/blur-dissolve.md +36 -0
  299. package/library/primitives/transition/camera-travel.md +57 -0
  300. package/library/primitives/transition/collapse-to-anchor.md +27 -0
  301. package/library/primitives/transition/cover-reveal.md +47 -0
  302. package/library/primitives/transition/curtain.md +42 -0
  303. package/library/primitives/transition/dive-in.md +51 -0
  304. package/library/primitives/transition/fly-past.md +51 -0
  305. package/library/primitives/transition/iris.md +49 -0
  306. package/library/primitives/transition/layout-locked-swap.md +28 -0
  307. package/library/primitives/transition/light-dark-flip.md +27 -0
  308. package/library/primitives/transition/push.md +47 -0
  309. package/library/primitives/transition/signal-wipe.md +52 -0
  310. package/library/primitives/transition/slant-wipe.md +44 -0
  311. package/library/primitives/transition/stack-over.md +51 -0
  312. package/library/primitives/transition/step-wipe.md +32 -0
  313. package/library/primitives/transition/strip-wipe.md +80 -0
  314. package/library/primitives/transition/torn-edge.md +26 -0
  315. package/library/primitives/transition/whip-pan.md +47 -0
  316. package/library/primitives/transition/zoom-through-letter.md +27 -0
  317. package/library/primitives/type/accent-number.md +22 -0
  318. package/library/primitives/type/block-reveal.md +41 -0
  319. package/library/primitives/type/char-cascade.md +65 -0
  320. package/library/primitives/type/echo.md +44 -0
  321. package/library/primitives/type/fill-text.md +63 -0
  322. package/library/primitives/type/focus-blur.md +22 -0
  323. package/library/primitives/type/inline-chips.md +27 -0
  324. package/library/primitives/type/mask-reveal.md +65 -0
  325. package/library/primitives/type/parting.md +23 -0
  326. package/library/primitives/type/per-word-restyle.md +28 -0
  327. package/library/primitives/type/scramble.md +26 -0
  328. package/library/primitives/type/scribble-highlight.md +47 -0
  329. package/library/primitives/type/shimmer.md +39 -0
  330. package/library/primitives/type/split-flap.md +26 -0
  331. package/library/primitives/type/style-multiply.md +23 -0
  332. package/library/primitives/type/tracking-in.md +40 -0
  333. package/library/primitives/type/typed-title.md +27 -0
  334. package/library/primitives/type/word-build.md +37 -0
  335. package/library/primitives/type/word-roller.md +52 -0
  336. package/library/primitives/type/writing-ticker.md +27 -0
  337. package/library/primitives/ui/collab-cursors.md +27 -0
  338. package/library/primitives/ui/cursor-click.md +61 -0
  339. package/library/primitives/ui/page-scroll.md +58 -0
  340. package/library/primitives/ui/prompt-typing.md +29 -0
  341. package/library/primitives/ui/streamed-result.md +23 -0
  342. package/library/primitives/ui/tour-hold.md +27 -0
  343. package/library/styles/brand-system.md +49 -0
  344. package/library/styles/clean-explainer.md +42 -0
  345. package/library/styles/dark-showcase.md +48 -0
  346. package/library/styles/editorial-type.md +37 -0
  347. package/library/styles/kinetic-poster.md +54 -0
  348. package/library/styles/product-ui.md +44 -0
  349. package/library/styles/studio-loop.md +41 -0
  350. package/library.json +1467 -0
  351. package/package.json +64 -4
  352. package/schema/film.schema.json +1316 -0
  353. package/showcase/vendor/DIALKIT-LICENSE +21 -0
  354. package/src/studio/theme/fonts/OFL.txt +94 -0
@@ -0,0 +1,120 @@
1
+ export function filmSchema(c) {
2
+ const beats = { type: 'string', pattern: '^\\s*\\d+(\\.\\d+)?\\s*(b|beats?|bars?)\\s*$', description: 'Beats or bars at the film tempo, e.g. "2b" or "1bar"' };
3
+ const seconds = { anyOf: [{ type: 'number', minimum: 0 }, { type: 'string', pattern: '^\\$' }, beats] };
4
+ const timeRef = { anyOf: [{ type: 'number', minimum: 0 }, { type: 'string', description: 'e.g. "headline.end + 0.2", "scene.end - 1", "title.end + 1b" or, with a tempo, "4b"' }] };
5
+ const ease = {
6
+ anyOf: [
7
+ { enum: c.eases }, { type: 'string', pattern: '^\\$' },
8
+ { type: 'array', items: { type: 'number' }, minItems: 4, maxItems: 4 },
9
+ { type: 'object', required: ['spring'], properties: { spring: { type: 'object', required: ['duration'], properties: { duration: { type: 'number' }, bounce: { type: 'number' } } } } },
10
+ ],
11
+ };
12
+ const pair = (min, max) => ({ type: 'array', items: { type: 'number', minimum: min, maximum: max }, minItems: 2, maxItems: 2 });
13
+ const tracks = {
14
+ type: 'object', additionalProperties: false,
15
+ properties: Object.fromEntries(c.tracks.map((p) => [p, { type: 'array', items: { type: 'array', minItems: 2, maxItems: 3, description: '[time, value] or [time, value, ease]; time in seconds or beats ("2b")' } }])),
16
+ };
17
+ const move = (exit) => ({
18
+ anyOf: [{ enum: c.moves }, {
19
+ type: 'object', required: ['move'], additionalProperties: false,
20
+ properties: { move: { enum: c.moves }, duration: seconds, ease, amount: { type: 'number' }, angle: { type: 'number', description: 'For wipe and slide: degrees, 0 rightwards, 90 downwards.' }, feather: { anyOf: [{ type: 'boolean' }, { type: 'number', minimum: 0, maximum: 200 }], description: 'For mask-* and wipe-*: a soft edge in px, or true for a tenth of the line height.' }, ...(exit ? { at: timeRef } : {}) },
21
+ }],
22
+ });
23
+ return {
24
+ $schema: 'https://json-schema.org/draft/2020-12/schema',
25
+ title: `Motion film (${c.motion})`,
26
+ type: 'object', required: ['motion', 'size', 'scenes'], additionalProperties: false,
27
+ properties: {
28
+ $schema: { type: 'string' },
29
+ motion: { type: 'string' }, title: { type: 'string' },
30
+ size: { type: 'array', items: { type: 'integer', minimum: 1 }, minItems: 2, maxItems: 2 },
31
+ fps: { type: 'integer', minimum: 1 }, seed: { type: 'integer' }, poster: { type: 'number', minimum: 0 }, loop: { type: 'boolean' },
32
+ narrative: { type: 'string' }, style: { type: 'string' }, tokens: { type: 'object' },
33
+ tempo: {
34
+ type: 'object', required: ['bpm'], additionalProperties: false,
35
+ description: 'One pulse for the whole film: times may then be written in beats and bars, and `motion pace` checks the grid.',
36
+ properties: { bpm: { type: 'number', minimum: 40, maximum: 240 }, bar: { type: 'integer', minimum: 2, maximum: 12 } },
37
+ },
38
+ audio: {
39
+ type: 'object', required: ['src'], additionalProperties: false,
40
+ description: 'A soundtrack: film time 0 plays the file from `from` seconds. The studio plays it with the playhead; render lays it under the video.',
41
+ properties: {
42
+ src: { type: 'string', description: 'Sound file, relative to the film' },
43
+ from: { type: 'number', minimum: 0, description: 'Seconds into the file that film time 0 plays: one of its downbeats' },
44
+ gain: { type: 'number', minimum: -30, maximum: 6, description: 'Level in dB' },
45
+ fade_in: { type: 'number', minimum: 0, maximum: 10 }, fade_out: { type: 'number', minimum: 0, maximum: 10 },
46
+ },
47
+ },
48
+ theme: { type: 'object', additionalProperties: false, properties: { scheme: { enum: ['light', 'dark'] }, accent: { type: 'string' }, onAccent: { type: 'string' }, ui: { enum: ['zero', 'graphite', 'hockney'] }, vars: { type: 'object', additionalProperties: { type: 'string' } } } },
49
+ scenes: {
50
+ type: 'array', minItems: 1,
51
+ items: {
52
+ type: 'object', required: ['id', 'layers'], additionalProperties: false,
53
+ properties: {
54
+ id: { type: 'string', pattern: '^[a-z][a-z0-9-]*$' },
55
+ length: { anyOf: [{ type: 'number', exclusiveMinimum: 0 }, beats] }, hold: seconds,
56
+ background: { anyOf: [{ enum: c.surfaces }, { type: 'string' }] }, scheme: { enum: ['light', 'dark'] },
57
+ layout: { type: 'object', additionalProperties: false, properties: { align: { enum: ['start', 'center', 'end'] }, justify: { enum: ['start', 'center', 'end', 'between'] }, gap: { type: 'number' }, padding: { type: 'number' } } },
58
+ artboard: {
59
+ type: 'object', required: ['width', 'height'], additionalProperties: false,
60
+ description: "A design's frame for layers placed in px: they keep its coordinates and sizes, and it is scaled to the stage as one.",
61
+ properties: { width: { type: 'number', minimum: 1, maximum: 20000 }, height: { type: 'number', minimum: 1, maximum: 20000 }, fit: { enum: ['cover', 'contain', 'width', 'height'] }, align: { type: 'array', items: { type: 'number', minimum: 0, maximum: 100 }, minItems: 2, maxItems: 2 } },
62
+ },
63
+ tracks, uses: { type: 'array', items: { type: 'string' } }, intent: { type: 'string' },
64
+ follow: {
65
+ type: 'object', required: ['layer'], additionalProperties: false,
66
+ description: 'The camera follows the tip of a line as it draws.',
67
+ properties: { layer: { type: 'string' }, at: { type: 'array', items: { type: 'number', minimum: 0, maximum: 100 }, minItems: 2, maxItems: 2 }, lag: { type: 'number', minimum: 0 }, blend: { type: 'number', minimum: 0 } },
68
+ },
69
+ camera: {
70
+ type: 'array', minItems: 1,
71
+ description: 'The framing camera: each key puts a layer (or a point) at an anchor on the screen, this big, tilted so. Replaces the x, y and scale tracks.',
72
+ items: {
73
+ type: 'object', required: ['at'], additionalProperties: false,
74
+ properties: {
75
+ at: { anyOf: [{ type: 'number', minimum: 0 }, beats] },
76
+ frame: { anyOf: [{ type: 'string' }, pair(0, 100)], description: 'A layer id, "layer#mark" for a mark recorded with a footage plane\'s footage, or [x, y] in % of the stage.' },
77
+ point: { ...pair(0, 1), description: 'The point of the layer box to frame, as shares of its width and height.' },
78
+ offset: { type: 'array', items: { type: 'number' }, minItems: 2, maxItems: 2 },
79
+ zoom: { type: 'number', exclusiveMinimum: 0 },
80
+ anchor: { ...pair(0, 100), description: 'Where the framed point sits on the screen, in % of the stage.' },
81
+ tilt: { type: 'array', items: { type: 'number', minimum: -80, maximum: 80 }, minItems: 2, maxItems: 2, description: 'Degrees about x and y, about the anchor.' },
82
+ rotate: { type: 'number' }, ease: {}, drift: { type: 'number' },
83
+ },
84
+ },
85
+ },
86
+ perspective: { type: 'number', minimum: 100 },
87
+ motionBlur: { anyOf: [{ type: 'boolean' }, { type: 'number', minimum: 0, maximum: 1 }] },
88
+ out: { type: 'object', required: ['use'], additionalProperties: false, properties: { use: { enum: c.transitions.map((t) => t.slug) }, duration: seconds, params: { type: 'object' } } },
89
+ layers: {
90
+ type: 'array',
91
+ items: {
92
+ type: 'object', required: ['id', 'use'], additionalProperties: false,
93
+ properties: {
94
+ id: { type: 'string', pattern: '^[a-z][a-z0-9-]*$' },
95
+ use: { enum: c.primitives.map((p) => p.slug) },
96
+ props: { type: 'object' }, params: { type: 'object' }, at: timeRef,
97
+ style: {
98
+ type: 'object', additionalProperties: false,
99
+ properties: { size: { enum: c.sizes }, color: { enum: c.colors }, font: { enum: ['display', 'body', 'mono'] }, weight: { type: 'number' }, align: { enum: ['left', 'center', 'right'] }, width: { type: 'number', exclusiveMinimum: 0, maximum: 100 }, css: { type: 'object', additionalProperties: { type: 'string' } } },
100
+ },
101
+ place: { type: 'object', required: ['x', 'y'], additionalProperties: false, properties: { x: { type: 'number' }, y: { type: 'number' }, anchor: { enum: c.anchors }, unit: { enum: ['%', 'px'], description: '% of the stage (default), or px of the scene\'s artboard.' } } },
102
+ screen: { type: 'boolean', description: 'Fixed to the screen: drawn outside the camera, so its travel, zoom and tilt leave the layer where it is.' }, reflow: { enum: ['glide'], description: 'glide: the layer takes no room until it enters and gives it up as it leaves; the layers around it glide over.' },
103
+ taps: {
104
+ type: 'array', description: 'Taps: the layer goes down under the finger, landing on each time, comes back up past rest, and an accent ring leaves it in its own shape.',
105
+ items: { anyOf: [timeRef, { type: 'object', required: ['at'], additionalProperties: false, properties: { at: timeRef, ring: { anyOf: [{ type: 'string', description: 'Another layer to draw the ring around.' }, { const: false }] }, mark: { type: 'string', description: 'On a rig/footage-plane: a mark recorded with the footage, to ring.' } } }] },
106
+ }, enter: move(false), exit: move(true), tracks,
107
+ parallax: {
108
+ description: 'Depth against the camera: 1 travels with the scene, above 1 nearer and faster, 0 holds still. Or { depth, home }.',
109
+ anyOf: [{ type: 'number', minimum: 0, maximum: 10 }, { type: 'object', required: ['depth'], additionalProperties: false, properties: { depth: { type: 'number', minimum: 0, maximum: 10 }, home: timeRef } }],
110
+ },
111
+ motionBlur: { anyOf: [{ type: 'boolean' }, { type: 'number', minimum: 0, maximum: 1 }] },
112
+ },
113
+ },
114
+ },
115
+ },
116
+ },
117
+ },
118
+ },
119
+ };
120
+ }
@@ -0,0 +1,17 @@
1
+ import type { FrameSequence } from '../primitives/types.ts';
2
+ export interface ServerOptions {
3
+ film: string;
4
+ css?: string[];
5
+ port?: number;
6
+ watch?: boolean;
7
+ /** Footage frames for el/video layers, by "<scene>/<layer>", served at /api/frames. */
8
+ frames?: Record<string, FrameSequence>;
9
+ /** Serve no tuning, as if the tune file were empty: stills, checks and renders of the film as written. */
10
+ noTune?: boolean;
11
+ }
12
+ export interface Preview {
13
+ url: string;
14
+ close(): Promise<void>;
15
+ }
16
+ export declare const shell: (head: string, body?: string) => string;
17
+ export declare function serve(options: ServerOptions): Promise<Preview>;
@@ -0,0 +1,135 @@
1
+ // The preview server. It serves the page, the film and tune files, and tells the
2
+ // page when the film file changes. It binds to this machine only.
3
+ import fs from 'node:fs';
4
+ import http from 'node:http';
5
+ import path from 'node:path';
6
+ import { bundle, readTune, tunePath, writeJson } from "./files.js";
7
+ const MIME = {
8
+ '.html': 'text/html; charset=utf-8', '.js': 'text/javascript; charset=utf-8', '.css': 'text/css; charset=utf-8',
9
+ '.json': 'application/json; charset=utf-8', '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.webp': 'image/webp',
10
+ '.svg': 'image/svg+xml', '.woff2': 'font/woff2', '.woff': 'font/woff', '.ttf': 'font/ttf', '.mp4': 'video/mp4',
11
+ '.m4v': 'video/mp4', '.mov': 'video/quicktime', '.webm': 'video/webm', '.ogv': 'video/ogg', '.avif': 'image/avif', '.gif': 'image/gif',
12
+ '.mp3': 'audio/mpeg', '.m4a': 'audio/mp4', '.aac': 'audio/aac', '.wav': 'audio/wav', '.ogg': 'audio/ogg', '.flac': 'audio/flac',
13
+ };
14
+ export const shell = (head, body = '') => `<!doctype html>
15
+ <html lang="en">
16
+ <head>
17
+ <meta charset="utf-8">
18
+ <meta name="viewport" content="width=device-width, initial-scale=1">
19
+ <title>Motion</title>
20
+ <link rel="icon" href="data:,">
21
+ <style>html, body { margin: 0; }</style>
22
+ ${head}
23
+ </head>
24
+ <body>
25
+ <div id="app"></div>
26
+ ${body}
27
+ </body>
28
+ </html>
29
+ `;
30
+ /** Resolves a request path inside a folder, or returns undefined if it would leave it. */
31
+ function inside(dir, rel) {
32
+ const target = path.resolve(dir, `.${path.posix.normalize(`/${rel}`)}`);
33
+ return target === dir || target.startsWith(dir + path.sep) ? target : undefined;
34
+ }
35
+ export async function serve(options) {
36
+ const filmPath = path.resolve(options.film), filmDir = path.dirname(filmPath);
37
+ const css = (options.css ?? []).map((f) => path.resolve(f));
38
+ const page = await bundle();
39
+ const clients = new Set();
40
+ const send = (res, status, type, body) => {
41
+ res.writeHead(status, { 'content-type': type, 'cache-control': 'no-store' });
42
+ res.end(body);
43
+ };
44
+ const file = (res, target, range) => {
45
+ if (!target || !fs.existsSync(target) || !fs.statSync(target).isFile())
46
+ return send(res, 404, 'text/plain', 'Not found');
47
+ const type = MIME[path.extname(target).toLowerCase()] ?? 'application/octet-stream';
48
+ // Byte ranges: a browser only seeks in a video it can fetch in parts.
49
+ const m = range ? /^bytes=(\d*)-(\d*)$/.exec(range) : null;
50
+ if (m && (m[1] || m[2])) {
51
+ const size = fs.statSync(target).size;
52
+ const start = m[1] ? Number(m[1]) : Math.max(0, size - Number(m[2]));
53
+ const end = m[1] && m[2] ? Math.min(size - 1, Number(m[2])) : size - 1;
54
+ if (start > end || start >= size) {
55
+ res.writeHead(416, { 'content-range': `bytes */${size}` });
56
+ return res.end();
57
+ }
58
+ res.writeHead(206, { 'content-type': type, 'content-range': `bytes ${start}-${end}/${size}`, 'content-length': end - start + 1, 'accept-ranges': 'bytes', 'cache-control': 'no-store' });
59
+ return fs.createReadStream(target, { start, end }).pipe(res);
60
+ }
61
+ res.writeHead(200, { 'content-type': type, 'cache-control': 'no-store', 'accept-ranges': 'bytes' });
62
+ return res.end(fs.readFileSync(target));
63
+ };
64
+ const server = http.createServer((req, res) => {
65
+ const url = new URL(req.url ?? '/', 'http://localhost');
66
+ const p = decodeURIComponent(url.pathname);
67
+ if (p === '/') {
68
+ const links = css.map((f, i) => `<link rel="stylesheet" href="/css/${i}/${encodeURIComponent(path.basename(f))}">`).join('\n');
69
+ return send(res, 200, MIME['.html'], shell(links, '<script type="module" src="/page.js"></script>'));
70
+ }
71
+ if (p === '/page.js')
72
+ return file(res, page);
73
+ if (p === '/api/film')
74
+ return file(res, filmPath);
75
+ if (p === '/api/frames')
76
+ return send(res, 200, MIME['.json'], JSON.stringify(options.frames ?? {}));
77
+ if (p === '/api/tune' && req.method === 'GET')
78
+ return send(res, 200, MIME['.json'], JSON.stringify(options.noTune ? { set: {}, notes: [] } : readTune(filmPath)));
79
+ if (p === '/api/tune' && req.method === 'PUT') {
80
+ const chunks = [];
81
+ req.on('data', (c) => chunks.push(c));
82
+ req.on('end', () => {
83
+ try {
84
+ const tune = JSON.parse(Buffer.concat(chunks).toString('utf8'));
85
+ writeJson(tunePath(filmPath), { set: tune.set ?? {}, notes: tune.notes ?? [] });
86
+ send(res, 200, MIME['.json'], '{"ok":true}');
87
+ }
88
+ catch {
89
+ send(res, 400, 'text/plain', 'The tune must be JSON');
90
+ }
91
+ });
92
+ return;
93
+ }
94
+ if (p === '/api/events') {
95
+ res.writeHead(200, { 'content-type': 'text/event-stream', 'cache-control': 'no-store', connection: 'keep-alive' });
96
+ res.write(': connected\n\n');
97
+ clients.add(res);
98
+ req.on('close', () => clients.delete(res));
99
+ return;
100
+ }
101
+ const m = /^\/css\/(\d+)\/(.+)$/.exec(p);
102
+ if (m) {
103
+ const sheet = css[Number(m[1])];
104
+ return file(res, sheet ? inside(path.dirname(sheet), m[2]) : undefined);
105
+ }
106
+ return file(res, inside(filmDir, p), req.headers.range);
107
+ });
108
+ let watcher, timer;
109
+ if (options.watch) {
110
+ // Watch the folder, not the file: editors and agents often replace a file rather than write into it.
111
+ watcher = fs.watch(filmDir, (_event, name) => {
112
+ if (name !== path.basename(filmPath))
113
+ return;
114
+ clearTimeout(timer);
115
+ timer = setTimeout(() => {
116
+ let text;
117
+ try {
118
+ text = JSON.stringify(JSON.parse(fs.readFileSync(filmPath, 'utf8')));
119
+ }
120
+ catch {
121
+ return;
122
+ } // half-written: wait for the next change
123
+ for (const c of clients)
124
+ c.write(`event: film\ndata: ${text}\n\n`);
125
+ }, 80);
126
+ });
127
+ }
128
+ await new Promise((resolve, reject) => { server.once('error', reject); server.listen(options.port ?? 0, '127.0.0.1', resolve); });
129
+ const { port } = server.address();
130
+ return {
131
+ url: `http://127.0.0.1:${port}/`,
132
+ close: () => new Promise((resolve) => { watcher?.close(); for (const c of clients)
133
+ c.end(); server.close(() => resolve()); server.closeAllConnections(); }),
134
+ };
135
+ }
@@ -0,0 +1,39 @@
1
+ export declare const clamp: (x: number, lo?: number, hi?: number) => number;
2
+ export declare const lerp: (a: number, b: number, k: number) => number;
3
+ export type Bezier = readonly [number, number, number, number];
4
+ export interface SpringSpec {
5
+ /** Seconds until the move first looks finished. */
6
+ duration: number;
7
+ /** 0 = no overshoot, 0.5 = lively. */
8
+ bounce?: number;
9
+ }
10
+ /** How long a move eased by a spring should last, so the overshoot has time to settle. */
11
+ export declare const springSpan: (s: SpringSpec) => number;
12
+ /** A named curve, a cubic-bezier, or a spring. */
13
+ export type EaseSpec = string | Bezier | {
14
+ spring: SpringSpec;
15
+ };
16
+ /** Solves a CSS cubic-bezier for x, the same curve the browser would draw. */
17
+ export declare function bezier(x1: number, y1: number, x2: number, y2: number): (x: number) => number;
18
+ /** Progress of a spring that looks settled after `duration` seconds. May overshoot 1. */
19
+ export declare function spring({ duration, bounce }: SpringSpec): (x: number) => number;
20
+ /**
21
+ * The `ui.*` curves are the theme easing tokens (`--ui-ease-*`). A page that
22
+ * loads a ui theme replaces them with the theme's own values (see dom/tokens.ts).
23
+ */
24
+ export declare const UI_EASE: Record<string, Bezier>;
25
+ /**
26
+ * Asymmetric curves for film: arrivals that spend most of their time settling,
27
+ * exits that leave fast and late. Shared with the craft guide (docs/CRAFT.md).
28
+ */
29
+ export declare const EXPRESSIVE: Record<string, Bezier>;
30
+ /** The nearest cubic-bezier to each named curve: what a curve editor shows for it. */
31
+ export declare const EASE_BEZIER: Record<string, Bezier>;
32
+ export declare const EASE_NAMES: readonly string[];
33
+ export declare const isEaseSpec: (v: unknown) => v is EaseSpec;
34
+ /** Turns a spec into a function of progress 0..1. `overrides` carries theme curves. */
35
+ export declare function resolveEase(spec: EaseSpec | undefined, overrides?: Record<string, Bezier>): (x: number) => number;
36
+ /** Eased progress 0..1 of a move that starts at `start` and lasts `duration` seconds. */
37
+ export declare function progress(t: number, start: number, duration: number, ease: (x: number) => number): number;
38
+ /** Seeded random, so renders repeat exactly. */
39
+ export declare function rng(seed?: number): () => number;
@@ -0,0 +1,176 @@
1
+ // Easing. Every curve is a pure function of progress or of elapsed seconds, so a
2
+ // film can be drawn at any time, in any order.
3
+ export const clamp = (x, lo = 0, hi = 1) => Math.min(hi, Math.max(lo, x));
4
+ export const lerp = (a, b, k) => a + (b - a) * k;
5
+ /** How long a move eased by a spring should last, so the overshoot has time to settle. */
6
+ export const springSpan = (s) => s.duration * (1 + 2 * (s.bounce ?? 0));
7
+ /** Solves a CSS cubic-bezier for x, the same curve the browser would draw. */
8
+ export function bezier(x1, y1, x2, y2) {
9
+ const cx = 3 * x1, bx = 3 * (x2 - x1) - cx, ax = 1 - cx - bx;
10
+ const cy = 3 * y1, by = 3 * (y2 - y1) - cy, ay = 1 - cy - by;
11
+ const fx = (u) => ((ax * u + bx) * u + cx) * u;
12
+ const fy = (u) => ((ay * u + by) * u + cy) * u;
13
+ return (x) => {
14
+ if (x <= 0)
15
+ return 0;
16
+ if (x >= 1)
17
+ return 1;
18
+ let u = x;
19
+ for (let i = 0; i < 8; i++) {
20
+ const d = (3 * ax * u + 2 * bx) * u + cx;
21
+ if (Math.abs(d) < 1e-6)
22
+ break;
23
+ u -= (fx(u) - x) / d;
24
+ }
25
+ // Newton can leave the unit interval on steep curves; bisect to be safe.
26
+ if (u < 0 || u > 1 || Math.abs(fx(u) - x) > 1e-4) {
27
+ let lo = 0, hi = 1;
28
+ for (let i = 0; i < 24; i++) {
29
+ u = (lo + hi) / 2;
30
+ if (fx(u) < x)
31
+ lo = u;
32
+ else
33
+ hi = u;
34
+ }
35
+ }
36
+ return fy(u);
37
+ };
38
+ }
39
+ /** Progress of a spring that looks settled after `duration` seconds. May overshoot 1. */
40
+ export function spring({ duration, bounce = 0 }) {
41
+ const w0 = (2 * Math.PI) / (Math.max(0.05, duration) * 1.2);
42
+ const z = clamp(1 - bounce, 0.05, 1);
43
+ return (x) => {
44
+ if (x <= 0)
45
+ return 0;
46
+ if (x >= 1)
47
+ return 1;
48
+ // Progress 0..1 covers the whole settling time, not just the first arrival.
49
+ const dt = x * duration * (1 + 2 * bounce);
50
+ if (z < 1) {
51
+ const wd = w0 * Math.sqrt(1 - z * z);
52
+ return 1 - Math.exp(-z * w0 * dt) * (Math.cos(wd * dt) + ((z * w0) / wd) * Math.sin(wd * dt));
53
+ }
54
+ return 1 - Math.exp(-w0 * dt) * (1 + w0 * dt);
55
+ };
56
+ }
57
+ /**
58
+ * The `ui.*` curves are the theme easing tokens (`--ui-ease-*`). A page that
59
+ * loads a ui theme replaces them with the theme's own values (see dom/tokens.ts).
60
+ */
61
+ export const UI_EASE = {
62
+ 'ui.default': [0.2, 0, 0, 1],
63
+ 'ui.in': [0.4, 0, 1, 1],
64
+ 'ui.out': [0, 0, 0.2, 1],
65
+ 'ui.spring': [0.22, 1, 0.36, 1],
66
+ };
67
+ /**
68
+ * Asymmetric curves for film: arrivals that spend most of their time settling,
69
+ * exits that leave fast and late. Shared with the craft guide (docs/CRAFT.md).
70
+ */
71
+ export const EXPRESSIVE = {
72
+ 'expressive.out': [0.05, 0.7, 0.1, 1],
73
+ 'expressive.in': [0.3, 0, 0.8, 0.15],
74
+ 'expressive.inOut': [0.7, 0, 0.1, 1],
75
+ // A hard ease-out with a finite start: things are placed, not floated in.
76
+ 'snap.out': [0.3, 0.9, 0.1, 1],
77
+ // Pulls back a little, then whips away: exits with weight.
78
+ 'anticipate.in': [0.45, -0.48, 1, -0.82],
79
+ // A camera punch-in: nearly all of the move in the first frames, then a long settle. 150–225 ms.
80
+ punch: [0.16, 1, 0.3, 1],
81
+ // A press let go: back past rest and home. For a tapped control coming back up.
82
+ 'bounce.out': [0.34, 1.36, 0.64, 1],
83
+ };
84
+ /** The nearest cubic-bezier to each named curve: what a curve editor shows for it. */
85
+ export const EASE_BEZIER = {
86
+ linear: [0, 0, 1, 1], smooth: [0.45, 0, 0.55, 1],
87
+ 'sine.in': [0.12, 0, 0.39, 0], 'sine.out': [0.61, 1, 0.88, 1], 'sine.inOut': [0.37, 0, 0.63, 1],
88
+ 'cubic.in': [0.32, 0, 0.67, 0], 'cubic.out': [0.33, 1, 0.68, 1], 'cubic.inOut': [0.65, 0, 0.35, 1],
89
+ 'expo.in': [0.7, 0, 0.84, 0], 'expo.out': [0.16, 1, 0.3, 1], 'expo.inOut': [0.87, 0, 0.13, 1],
90
+ 'quad.in': [0.11, 0, 0.5, 0], 'quad.out': [0.5, 1, 0.89, 1], 'quad.inOut': [0.45, 0, 0.55, 1],
91
+ 'quart.in': [0.5, 0, 0.75, 0], 'quart.out': [0.25, 1, 0.5, 1], 'quart.inOut': [0.76, 0, 0.24, 1],
92
+ 'quint.in': [0.64, 0, 0.78, 0], 'quint.out': [0.22, 1, 0.36, 1], 'quint.inOut': [0.83, 0, 0.17, 1],
93
+ 'circ.in': [0.55, 0, 1, 0.45], 'circ.out': [0, 0.55, 0.45, 1], 'circ.inOut': [0.85, 0, 0.15, 1],
94
+ 'back.in': [0.36, 0, 0.66, -0.56], 'back.out': [0.34, 1.56, 0.64, 1], 'back.inOut': [0.68, -0.6, 0.32, 1.6],
95
+ // No cubic matches an elastic; the curve editor shows the nearest overshoot.
96
+ 'elastic.out': [0.34, 1.56, 0.64, 1],
97
+ ...EXPRESSIVE,
98
+ ...UI_EASE,
99
+ };
100
+ const NAMED = {
101
+ linear: (x) => x,
102
+ 'sine.in': (x) => 1 - Math.cos((x * Math.PI) / 2),
103
+ 'sine.out': (x) => Math.sin((x * Math.PI) / 2),
104
+ 'sine.inOut': (x) => -(Math.cos(Math.PI * x) - 1) / 2,
105
+ 'cubic.in': (x) => x * x * x,
106
+ 'cubic.out': (x) => 1 - Math.pow(1 - x, 3),
107
+ 'cubic.inOut': (x) => (x < 0.5 ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2),
108
+ 'expo.in': (x) => (x <= 0 ? 0 : Math.pow(2, 10 * x - 10)),
109
+ 'expo.out': (x) => (x >= 1 ? 1 : 1 - Math.pow(2, -10 * x)),
110
+ 'expo.inOut': (x) => x <= 0 ? 0 : x >= 1 ? 1 : x < 0.5 ? Math.pow(2, 20 * x - 10) / 2 : (2 - Math.pow(2, -20 * x + 10)) / 2,
111
+ 'back.out': (x) => 1 + 2.70158 * Math.pow(x - 1, 3) + 1.70158 * Math.pow(x - 1, 2),
112
+ smooth: (x) => x * x * x * (x * (x * 6 - 15) + 10),
113
+ 'quad.in': (x) => x * x,
114
+ 'quad.out': (x) => 1 - (1 - x) * (1 - x),
115
+ 'quad.inOut': (x) => (x < 0.5 ? 2 * x * x : 1 - Math.pow(-2 * x + 2, 2) / 2),
116
+ 'quart.in': (x) => x * x * x * x,
117
+ 'quart.out': (x) => 1 - Math.pow(1 - x, 4),
118
+ 'quart.inOut': (x) => (x < 0.5 ? 8 * x * x * x * x : 1 - Math.pow(-2 * x + 2, 4) / 2),
119
+ 'quint.in': (x) => x * x * x * x * x,
120
+ 'quint.out': (x) => 1 - Math.pow(1 - x, 5),
121
+ 'quint.inOut': (x) => (x < 0.5 ? 16 * Math.pow(x, 5) : 1 - Math.pow(-2 * x + 2, 5) / 2),
122
+ 'circ.in': (x) => 1 - Math.sqrt(1 - x * x),
123
+ 'circ.out': (x) => Math.sqrt(1 - Math.pow(x - 1, 2)),
124
+ 'circ.inOut': (x) => (x < 0.5 ? (1 - Math.sqrt(1 - Math.pow(2 * x, 2))) / 2 : (Math.sqrt(1 - Math.pow(-2 * x + 2, 2)) + 1) / 2),
125
+ 'back.in': (x) => 2.70158 * x * x * x - 1.70158 * x * x,
126
+ 'back.inOut': (x) => {
127
+ const c = 1.70158 * 1.525;
128
+ return x < 0.5 ? (Math.pow(2 * x, 2) * ((c + 1) * 2 * x - c)) / 2 : (Math.pow(2 * x - 2, 2) * ((c + 1) * (x * 2 - 2) + c) + 2) / 2;
129
+ },
130
+ 'elastic.out': (x) => (x <= 0 ? 0 : x >= 1 ? 1 : Math.pow(2, -10 * x) * Math.sin((x * 10 - 0.75) * ((2 * Math.PI) / 3)) + 1),
131
+ };
132
+ export const EASE_NAMES = [...Object.keys(NAMED), ...Object.keys(EXPRESSIVE), ...Object.keys(UI_EASE)];
133
+ export const isEaseSpec = (v) => {
134
+ if (typeof v === 'string')
135
+ return true;
136
+ if (Array.isArray(v))
137
+ return v.length === 4 && v.every((n) => typeof n === 'number');
138
+ if (v && typeof v === 'object' && 'spring' in v) {
139
+ const s = v.spring;
140
+ return !!s && typeof s === 'object' && typeof s.duration === 'number';
141
+ }
142
+ return false;
143
+ };
144
+ /** Turns a spec into a function of progress 0..1. `overrides` carries theme curves. */
145
+ export function resolveEase(spec, overrides = {}) {
146
+ if (spec === undefined)
147
+ return NAMED['expo.out'];
148
+ if (typeof spec === 'string') {
149
+ const themed = overrides[spec] ?? UI_EASE[spec] ?? EXPRESSIVE[spec];
150
+ if (themed)
151
+ return bezier(...themed);
152
+ const named = NAMED[spec];
153
+ if (!named)
154
+ throw new Error(`Unknown ease "${spec}". Known: ${EASE_NAMES.join(', ')}`);
155
+ return (x) => named(clamp(x));
156
+ }
157
+ if (Array.isArray(spec))
158
+ return bezier(...spec);
159
+ return spring(spec.spring);
160
+ }
161
+ /** Eased progress 0..1 of a move that starts at `start` and lasts `duration` seconds. */
162
+ export function progress(t, start, duration, ease) {
163
+ if (duration <= 0)
164
+ return t >= start ? 1 : 0;
165
+ return ease(clamp((t - start) / duration));
166
+ }
167
+ /** Seeded random, so renders repeat exactly. */
168
+ export function rng(seed = 1) {
169
+ let s = seed >>> 0 || 1;
170
+ return () => {
171
+ s = (s + 0x6d2b79f5) >>> 0;
172
+ let r = Math.imul(s ^ (s >>> 15), 1 | s);
173
+ r = (r + Math.imul(r ^ (r >>> 7), 61 | r)) ^ r;
174
+ return ((r ^ (r >>> 14)) >>> 0) / 4294967296;
175
+ };
176
+ }
@@ -0,0 +1,52 @@
1
+ /** An ease: progress 0..1 to eased progress. */
2
+ export type Ease = (x: number) => number;
3
+ /** A camera key with its target already found in the world (camera space, untransformed px). */
4
+ export interface FrameKey {
5
+ /** Seconds from the scene start. */
6
+ t: number;
7
+ /** The world point to frame, px. */
8
+ target: readonly [number, number];
9
+ /** Size: 2 shows the world twice as big. */
10
+ zoom: number;
11
+ /** Where on the screen the target sits, px. */
12
+ anchor: readonly [number, number];
13
+ /** Degrees about x and y, turned about the anchor. */
14
+ tilt: readonly [number, number];
15
+ /** Degrees in the screen plane. */
16
+ rotate: number;
17
+ /** Shapes the move arriving at this key. */
18
+ ease: Ease;
19
+ /** On the last key: zoom per second, linear, from the key to the end of the scene, so the shot never comes to rest. */
20
+ drift: number;
21
+ }
22
+ export interface FramePose {
23
+ /** Translation of the world, px, applied about the stage centre (as the .m-cam transform). */
24
+ x: number;
25
+ y: number;
26
+ scale: number;
27
+ rotate: number;
28
+ rotateX: number;
29
+ rotateY: number;
30
+ /** The tilt's pivot on the screen, px. */
31
+ pivot: [number, number];
32
+ }
33
+ /** Where the camera is at time t, for keys sorted by time, on a stage of the given size. */
34
+ export declare function frameAt(keys: readonly FrameKey[], t: number, size: readonly [number, number]): FramePose;
35
+ /**
36
+ * The translation that puts world point P at screen point A when the world turns by `rotate`
37
+ * degrees and scales by `zoom` about the stage centre C: A − C − R·S·(P − C).
38
+ */
39
+ export declare function place(P: readonly [number, number], A: readonly [number, number], zoom: number, rotate: number, size: readonly [number, number]): {
40
+ x: number;
41
+ y: number;
42
+ };
43
+ /** Where a world point lands on the screen under a pose without tilt: the inverse check of `place`. */
44
+ export declare function onScreen(P: readonly [number, number], pose: FramePose, size: readonly [number, number]): [number, number];
45
+ /**
46
+ * The camera's speed at time t, as px per second at the screen's edge: how far the frame's
47
+ * content travels, pan and zoom together. For motion blur, and for the review of a plan.
48
+ */
49
+ export declare function frameSpeed(keys: readonly FrameKey[], t: number, size: readonly [number, number], dt?: number): {
50
+ pan: [number, number];
51
+ zoom: number;
52
+ };
@@ -0,0 +1,60 @@
1
+ const lerp = (a, b, p) => a + (b - a) * p;
2
+ /** Where the camera is at time t, for keys sorted by time, on a stage of the given size. */
3
+ export function frameAt(keys, t, size) {
4
+ if (!keys.length)
5
+ throw new Error('frameAt needs at least one key');
6
+ let a = keys[0], b = a, p = 0;
7
+ if (t > a.t) {
8
+ let i = 1;
9
+ while (i < keys.length && keys[i].t < t)
10
+ i++;
11
+ if (i >= keys.length) {
12
+ a = b = keys[keys.length - 1];
13
+ p = 0;
14
+ }
15
+ else {
16
+ a = keys[i - 1];
17
+ b = keys[i];
18
+ const span = b.t - a.t;
19
+ p = span <= 0 ? 1 : b.ease((t - a.t) / span);
20
+ }
21
+ }
22
+ // A drift runs on from the last key to the end of the scene.
23
+ const drift = a === b && t > a.t ? 1 + a.drift * (t - a.t) : 1;
24
+ const zoom = Math.exp(lerp(Math.log(a.zoom), Math.log(b.zoom), p)) * Math.max(0.01, drift);
25
+ const target = [lerp(a.target[0], b.target[0], p), lerp(a.target[1], b.target[1], p)];
26
+ const anchor = [lerp(a.anchor[0], b.anchor[0], p), lerp(a.anchor[1], b.anchor[1], p)];
27
+ const rotate = lerp(a.rotate, b.rotate, p);
28
+ return {
29
+ ...place(target, anchor, zoom, rotate, size),
30
+ scale: zoom, rotate,
31
+ rotateX: lerp(a.tilt[0], b.tilt[0], p), rotateY: lerp(a.tilt[1], b.tilt[1], p),
32
+ pivot: [anchor[0] - size[0] / 2, anchor[1] - size[1] / 2],
33
+ };
34
+ }
35
+ /**
36
+ * The translation that puts world point P at screen point A when the world turns by `rotate`
37
+ * degrees and scales by `zoom` about the stage centre C: A − C − R·S·(P − C).
38
+ */
39
+ export function place(P, A, zoom, rotate, size) {
40
+ const C = [size[0] / 2, size[1] / 2], r = (rotate * Math.PI) / 180;
41
+ const dx = P[0] - C[0], dy = P[1] - C[1];
42
+ return {
43
+ x: A[0] - C[0] - zoom * (Math.cos(r) * dx - Math.sin(r) * dy),
44
+ y: A[1] - C[1] - zoom * (Math.sin(r) * dx + Math.cos(r) * dy),
45
+ };
46
+ }
47
+ /** Where a world point lands on the screen under a pose without tilt: the inverse check of `place`. */
48
+ export function onScreen(P, pose, size) {
49
+ const C = [size[0] / 2, size[1] / 2], r = (pose.rotate * Math.PI) / 180;
50
+ const dx = P[0] - C[0], dy = P[1] - C[1];
51
+ return [C[0] + pose.x + pose.scale * (Math.cos(r) * dx - Math.sin(r) * dy), C[1] + pose.y + pose.scale * (Math.sin(r) * dx + Math.cos(r) * dy)];
52
+ }
53
+ /**
54
+ * The camera's speed at time t, as px per second at the screen's edge: how far the frame's
55
+ * content travels, pan and zoom together. For motion blur, and for the review of a plan.
56
+ */
57
+ export function frameSpeed(keys, t, size, dt = 1 / 120) {
58
+ const a = frameAt(keys, t - dt / 2, size), b = frameAt(keys, t + dt / 2, size);
59
+ return { pan: [(b.x - a.x) / dt, (b.y - a.y) / dt], zoom: Math.log(b.scale / a.scale) / dt };
60
+ }
@@ -0,0 +1,8 @@
1
+ export declare const SHAPES: readonly ["circle", "square", "squircle", "triangle", "diamond", "hexagon", "star", "pill", "plus", "blob"];
2
+ export type ShapeName = (typeof SHAPES)[number];
3
+ export type Pt = [number, number];
4
+ /** `n` points around a named shape that fills a box from -1 to 1. */
5
+ export declare function shapePoints(name: ShapeName | string, n?: number, seed?: number): Pt[];
6
+ export declare const lerpPoints: (a: Pt[], b: Pt[], k: number) => Pt[];
7
+ /** SVG path data for a closed point list, scaled by r around cx, cy. */
8
+ export declare const pointsPath: (pts: Pt[], cx: number, cy: number, r: number) => string;