@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,59 @@
1
+ // Directional motion blur. CSS blur() is round, but a moving thing only smears
2
+ // along its path. An SVG Gaussian takes a separate deviation across and down, so
3
+ // a whip blurs sideways and a vertical camera move blurs vertically, never both.
4
+ //
5
+ // One filter per element, kept in a zero-size <svg> inside the stage. The filter
6
+ // region is grown with the deviation, so a long streak is not cut at the box.
7
+ const SVG = 'http://www.w3.org/2000/svg';
8
+ const filters = new WeakMap();
9
+ let count = 0;
10
+ /**
11
+ * Gaussian deviation, in px, of the streak left by something moving `speed` px
12
+ * per frame, seen through a shutter open for `shutter` of a frame (0.5 is the
13
+ * 180° film shutter). A streak of length L is a box, whose deviation is L/√12.
14
+ */
15
+ export const streak = (speed, shutter) => (Math.abs(speed) * Math.max(0, shutter)) / Math.sqrt(12);
16
+ /** Below this deviation the smear is invisible, so no filter is set. */
17
+ export const MIN_BLUR = 0.25;
18
+ /**
19
+ * A CSS `filter` value that smears `el` by deviations `sx` across and `sy` down
20
+ * (px), or '' when both are too small to see. Combine it with other filters by
21
+ * joining with a space.
22
+ */
23
+ export function directionalBlur(el, sx, sy, max = 48) {
24
+ const x = Math.min(max, Math.abs(sx)), y = Math.min(max, Math.abs(sy));
25
+ if (x < MIN_BLUR && y < MIN_BLUR)
26
+ return '';
27
+ let f = filters.get(el);
28
+ if (!f) {
29
+ const doc = el.ownerDocument;
30
+ const host = el.closest('.m-stage') ?? doc.body;
31
+ let svg = host.querySelector(':scope > svg.m-filters');
32
+ if (!svg) {
33
+ svg = doc.createElementNS(SVG, 'svg');
34
+ svg.setAttribute('class', 'm-filters');
35
+ svg.setAttribute('aria-hidden', 'true');
36
+ // Not display: none, which switches the filters off in some engines.
37
+ svg.style.cssText = 'position:absolute;width:0;height:0;overflow:hidden;pointer-events:none';
38
+ host.appendChild(svg);
39
+ }
40
+ const id = `m-dblur-${++count}`;
41
+ const filter = doc.createElementNS(SVG, 'filter');
42
+ filter.setAttribute('id', id);
43
+ filter.setAttribute('color-interpolation-filters', 'sRGB');
44
+ const blur = doc.createElementNS(SVG, 'feGaussianBlur');
45
+ filter.appendChild(blur);
46
+ svg.appendChild(filter);
47
+ f = { id, filter, blur };
48
+ filters.set(el, f);
49
+ }
50
+ // Three deviations each side hold the whole tail of the Gaussian.
51
+ const w = Math.max(1, el.offsetWidth), h = Math.max(1, el.offsetHeight);
52
+ const mx = (3 * x) / w, my = (3 * y) / h;
53
+ f.filter.setAttribute('x', (-mx).toFixed(4));
54
+ f.filter.setAttribute('y', (-my).toFixed(4));
55
+ f.filter.setAttribute('width', (1 + 2 * mx).toFixed(4));
56
+ f.filter.setAttribute('height', (1 + 2 * my).toFixed(4));
57
+ f.blur.setAttribute('stdDeviation', `${x.toFixed(2)} ${y.toFixed(2)}`);
58
+ return `url(#${f.id})`;
59
+ }
@@ -0,0 +1,5 @@
1
+ import type { Ctx } from './types.ts';
2
+ /** The largest bitmap side drawn: past it a close-up is drawn a little soft rather than not at all. */
3
+ export declare const MAX_BITMAP = 8192;
4
+ /** Sizes the bitmap for this frame and sets the transform so drawing is in stage px. Call at the top of seek. */
5
+ export declare function fitBitmap(canvas: HTMLCanvasElement, g: CanvasRenderingContext2D, size: readonly [number, number], ctx: Pick<Ctx, 'cameraScale'>): void;
@@ -0,0 +1,13 @@
1
+ /** The largest bitmap side drawn: past it a close-up is drawn a little soft rather than not at all. */
2
+ export const MAX_BITMAP = 8192;
3
+ /** Sizes the bitmap for this frame and sets the transform so drawing is in stage px. Call at the top of seek. */
4
+ export function fitBitmap(canvas, g, size, ctx) {
5
+ const [W, H] = size;
6
+ const scale = Math.min(2 * Math.max(1, ctx.cameraScale?.() ?? 1), MAX_BITMAP / Math.max(W, H));
7
+ const bw = Math.round(W * scale), bh = Math.round(H * scale);
8
+ if (canvas.width !== bw || canvas.height !== bh) {
9
+ canvas.width = bw;
10
+ canvas.height = bh;
11
+ }
12
+ g.setTransform(bw / W, 0, 0, bh / H, 0, 0);
13
+ }
@@ -0,0 +1,2 @@
1
+ import { type Primitive } from '../types.ts';
2
+ export declare const box: Primitive;
@@ -0,0 +1,24 @@
1
+ import { num, str } from "../types.js";
2
+ const SURFACE = {
3
+ base: 'var(--m-bg-base)', surface: 'var(--m-bg-surface)', sunken: 'var(--m-bg-sunken)',
4
+ accent: 'var(--m-bg-accent)', inverse: 'var(--m-bg-inverse)',
5
+ };
6
+ export const box = {
7
+ slug: 'el/box',
8
+ summary: 'A plain rectangle: a card, a rule, a colour field.',
9
+ props: { fill: { type: 'string', default: 'surface', label: 'Surface name (base, surface, sunken, accent, inverse) or a CSS colour' } },
10
+ params: {
11
+ width: { type: 'number', default: 480, min: 1, max: 4000, step: 1, unit: 'px', label: 'Width' },
12
+ height: { type: 'number', default: 270, min: 1, max: 4000, step: 1, unit: 'px', label: 'Height' },
13
+ radius: { type: 'number', default: 16, min: 0, max: 400, step: 1, unit: 'px', label: 'Corner radius' },
14
+ },
15
+ duration: () => 0,
16
+ build(el, props, params) {
17
+ const fill = str(props.fill, 'surface');
18
+ el.style.width = `${num(params.width)}px`;
19
+ el.style.height = `${num(params.height)}px`;
20
+ el.style.borderRadius = `${num(params.radius)}px`;
21
+ el.style.background = SURFACE[fill] ?? fill;
22
+ return { seek() { } };
23
+ },
24
+ };
@@ -0,0 +1,15 @@
1
+ import { type Primitive } from '../types.ts';
2
+ /** `shot/f%03d.jpg` with n = 7 is `shot/f007.jpg`. `%d` is the bare number. */
3
+ export declare const frameSrc: (pattern: string, n: number) => string;
4
+ /**
5
+ * Index of the frame on screen t seconds into the layer. Holds the first frame through `delay` and the
6
+ * last after the run. With `last` before `first` the run plays backwards.
7
+ */
8
+ export declare function frameAt(t: number, p: {
9
+ first: number;
10
+ last: number;
11
+ fps: number;
12
+ rate: number;
13
+ delay: number;
14
+ }): number;
15
+ export declare const frames: Primitive;
@@ -0,0 +1,71 @@
1
+ // el/frames: footage as one layer. A numbered run of stills plays as film: the
2
+ // frame on screen is a pure function of the layer's time, so footage scrubs,
3
+ // repeats and renders like everything else. (A <video> seeks to the nearest
4
+ // decoded frame, which is not always the same one twice.)
5
+ import { clamp } from "../../core/ease.js";
6
+ import { num, str } from "../types.js";
7
+ /** `shot/f%03d.jpg` with n = 7 is `shot/f007.jpg`. `%d` is the bare number. */
8
+ export const frameSrc = (pattern, n) => pattern.replace(/%(?:0(\d+))?d/, (_, pad) => String(n).padStart(pad ? Number(pad) : 0, '0'));
9
+ /**
10
+ * Index of the frame on screen t seconds into the layer. Holds the first frame through `delay` and the
11
+ * last after the run. With `last` before `first` the run plays backwards.
12
+ */
13
+ export function frameAt(t, p) {
14
+ const played = Math.floor(Math.max(0, t - p.delay) * p.rate * p.fps + 1e-6);
15
+ const count = Math.abs(p.last - p.first);
16
+ return p.first + Math.sign(p.last - p.first) * clamp(played, 0, count);
17
+ }
18
+ const read = (p) => ({
19
+ first: Math.round(num(p.first)), last: Math.round(num(p.last)), fps: num(p.fps, 24), rate: num(p.rate, 1), delay: num(p.delay),
20
+ });
21
+ export const frames = {
22
+ slug: 'el/frames',
23
+ summary: 'Footage as a numbered run of stills, played at its own frame rate. Holds its first and last frame.',
24
+ props: {
25
+ src: { type: 'string', required: true, label: 'Path pattern with the frame number, e.g. footage/shot/f%03d.jpg' },
26
+ alt: { type: 'string', default: '', label: 'Description of the footage' },
27
+ },
28
+ params: {
29
+ first: { type: 'number', default: 0, min: 0, max: 100000, step: 1, unit: 'frame', label: 'First frame played' },
30
+ last: { type: 'number', default: 23, min: 0, max: 100000, step: 1, unit: 'frame', label: 'Last frame played, then held. Before the first frame, the run plays backwards' },
31
+ fps: { type: 'number', default: 24, min: 1, max: 120, step: 1, unit: 'fps', label: 'Frame rate the footage was shot at' },
32
+ rate: { type: 'number', default: 1, min: 0.1, max: 4, step: 0.01, unit: '×', label: 'Playback speed' },
33
+ delay: { type: 'number', default: 0, min: 0, max: 30, step: 0.05, unit: 's', label: 'Time held on the first frame before it plays' },
34
+ width: { type: 'number', default: 640, min: 1, max: 4000, step: 1, unit: 'px', label: 'Width' },
35
+ radius: { type: 'number', default: 0, min: 0, max: 400, step: 1, unit: 'px', label: 'Corner radius' },
36
+ },
37
+ // Footage and ambient drift are not moves: the pace check skips them.
38
+ cues: () => [],
39
+ duration: (_props, params) => {
40
+ const p = read(params);
41
+ return p.delay + (Math.abs(p.last - p.first) + 1) / p.fps / p.rate;
42
+ },
43
+ build(el, props, params) {
44
+ const doc = el.ownerDocument, p = read(params), pattern = str(props.src);
45
+ // Every frame sits in the same grid cell; only the current one is shown.
46
+ el.style.cssText += `;display:grid;width:${num(params.width)}px;border-radius:${num(params.radius)}px;overflow:hidden`;
47
+ const imgs = [];
48
+ const lo = Math.min(p.first, p.last), hi = Math.max(p.first, p.last);
49
+ for (let n = lo; n <= hi; n++) {
50
+ const img = doc.createElement('img');
51
+ img.src = frameSrc(pattern, n);
52
+ img.alt = n === p.first ? str(props.alt) : '';
53
+ img.decoding = 'sync';
54
+ img.style.cssText = 'grid-area:1/1;display:block;width:100%;height:auto;visibility:hidden';
55
+ el.appendChild(img);
56
+ imgs.push(img);
57
+ }
58
+ let shown = -1;
59
+ return {
60
+ seek(t) {
61
+ const i = frameAt(t, p) - lo;
62
+ if (i === shown)
63
+ return;
64
+ if (shown >= 0)
65
+ imgs[shown].style.visibility = 'hidden';
66
+ imgs[i].style.visibility = 'inherit';
67
+ shown = i;
68
+ },
69
+ };
70
+ },
71
+ };
@@ -0,0 +1,2 @@
1
+ import { type Primitive } from '../types.ts';
2
+ export declare const html: Primitive;
@@ -0,0 +1,14 @@
1
+ import { str } from "../types.js";
2
+ // The markup is inserted as written. A film is authored content, like a page's
3
+ // own source: do not build one from text you would not put in a page.
4
+ export const html = {
5
+ slug: 'el/html',
6
+ summary: 'Static markup, for content no primitive covers. Style it with --ui-* tokens.',
7
+ props: { html: { type: 'html', required: true, label: 'Markup' } },
8
+ params: {},
9
+ duration: () => 0,
10
+ build(el, props) {
11
+ el.innerHTML = str(props.html);
12
+ return { seek() { } };
13
+ },
14
+ };
@@ -0,0 +1,2 @@
1
+ import { type Primitive } from '../types.ts';
2
+ export declare const image: Primitive;
@@ -0,0 +1,43 @@
1
+ import { num, str } from "../types.js";
2
+ export const image = {
3
+ slug: 'el/image',
4
+ summary: 'A picture. The path is relative to the film file.',
5
+ props: {
6
+ src: { type: 'string', required: true, label: 'Image path or URL' },
7
+ alt: { type: 'string', default: '', label: 'Description of the picture' },
8
+ },
9
+ params: {
10
+ width: { type: 'number', default: 640, min: 1, max: 4000, step: 1, unit: 'px', label: 'Width' },
11
+ height: { type: 'number', default: 0, min: 0, max: 4000, step: 1, unit: 'px', label: 'Height; 0 keeps the picture\'s own proportions, otherwise it is cropped to fill' },
12
+ radius: { type: 'number', default: 16, min: 0, max: 400, step: 1, unit: 'px', label: 'Corner radius' },
13
+ frame: { type: 'number', default: 0, min: 0, max: 24, step: 0.5, unit: 'px', label: 'Ring drawn inside the edge, in the border colour (--m-frame to change it)' },
14
+ bevel: { type: 'number', default: 0, min: 0, max: 1, step: 0.05, unit: 'strength', label: 'A light top edge and a dark bottom edge, as on a printed card' },
15
+ },
16
+ duration: () => 0,
17
+ build(el, props, params) {
18
+ const doc = el.ownerDocument;
19
+ const radius = `${num(params.radius)}px`;
20
+ const img = doc.createElement('img');
21
+ img.src = str(props.src);
22
+ img.alt = str(props.alt);
23
+ img.decoding = 'sync';
24
+ const h = num(params.height);
25
+ img.style.cssText = `display:block;width:${num(params.width)}px;height:${h > 0 ? `${h}px` : 'auto'};object-fit:cover;border-radius:${radius}`;
26
+ el.appendChild(img);
27
+ // The layer's own box takes the radius too, so a shadow, outline or ring
28
+ // set on it with style.css follows the picture's corners.
29
+ el.style.borderRadius = radius;
30
+ const frame = num(params.frame), bevel = num(params.bevel);
31
+ if (frame > 0 || bevel > 0) {
32
+ const ring = doc.createElement('div');
33
+ const shadows = [
34
+ frame > 0 ? `inset 0 0 0 ${frame}px var(--m-frame, var(--m-border))` : '',
35
+ bevel > 0 ? `inset 0 1px 0 rgb(255 255 255 / ${(0.55 * bevel).toFixed(3)}), inset 0 -1px 0 rgb(0 0 0 / ${(0.35 * bevel).toFixed(3)})` : '',
36
+ ].filter(Boolean).join(', ');
37
+ ring.style.cssText = `position:absolute;inset:0;border-radius:${radius};box-shadow:${shadows};pointer-events:none`;
38
+ // The ring is positioned against the layer, which is relative or absolute already.
39
+ el.appendChild(ring);
40
+ }
41
+ return { seek() { } };
42
+ },
43
+ };
@@ -0,0 +1,2 @@
1
+ import { type Primitive } from '../types.ts';
2
+ export declare const slot: Primitive;
@@ -0,0 +1,25 @@
1
+ import { num, str } from "../types.js";
2
+ export const slot = {
3
+ slug: 'el/slot',
4
+ summary: 'An empty frame the host page fills, e.g. with a rendered UI component.',
5
+ props: { name: { type: 'string', required: true, label: 'Slot name the host fills' } },
6
+ params: {
7
+ width: { type: 'number', default: 640, min: 1, max: 4000, step: 1, unit: 'px', label: 'Width' },
8
+ height: { type: 'number', default: 360, min: 1, max: 4000, step: 1, unit: 'px', label: 'Height' },
9
+ },
10
+ duration: () => 0,
11
+ build(el, props, params, ctx) {
12
+ const name = str(props.name);
13
+ el.dataset.motionSlot = name;
14
+ el.style.width = `${num(params.width)}px`;
15
+ el.style.minHeight = `${num(params.height)}px`;
16
+ const fill = ctx.slots[name];
17
+ if (fill)
18
+ fill(el);
19
+ else {
20
+ el.style.cssText += ';display:grid;place-items:center;border:2px dashed var(--m-border);border-radius:16px;font:500 24px var(--m-font-mono);color:var(--m-text-muted)';
21
+ el.textContent = `slot: ${name}`;
22
+ }
23
+ return { seek() { } };
24
+ },
25
+ };
@@ -0,0 +1,2 @@
1
+ import { type Primitive } from '../types.ts';
2
+ export declare const text: Primitive;
@@ -0,0 +1,13 @@
1
+ import { str } from "../types.js";
2
+ export const text = {
3
+ slug: 'el/text',
4
+ summary: 'A block of text. Animate it with enter, exit and tracks.',
5
+ props: { text: { type: 'string', required: true, label: 'Text. Use \\n for a line break.' } },
6
+ params: {},
7
+ duration: () => 0,
8
+ build(el, props) {
9
+ el.style.whiteSpace = 'pre-line';
10
+ el.textContent = str(props.text);
11
+ return { seek() { } };
12
+ },
13
+ };
@@ -0,0 +1,6 @@
1
+ import { type Primitive } from '../types.ts';
2
+ /** The crop as [x, y, width, height] in % of the source; the whole frame when not given. */
3
+ export declare function cropOf(v: unknown): [number, number, number, number];
4
+ /** Source seconds at `t` seconds into the layer. Pure, so the CLI extracts exactly what seek reads. */
5
+ export declare function sourceTime(t: number, props: Record<string, unknown>, params: Record<string, unknown>): number;
6
+ export declare const video: Primitive;
@@ -0,0 +1,179 @@
1
+ // el/video. Footage as one layer instead of one image layer per frame.
2
+ //
3
+ // Two ways of drawing, one timing:
4
+ // for a render (render, check, stills) the CLI pulls the frames the film
5
+ // needs with ffmpeg, and seek swaps one image to the exact frame;
6
+ // in the studio and a built page a <video> element is moved to the time.
7
+ // Either way the source time at t seconds into the layer is
8
+ // from + t × rate, wrapping between from and to when it loops.
9
+ import { frameUrl, nums, num, str } from "../types.js";
10
+ /** The crop as [x, y, width, height] in % of the source; the whole frame when not given. */
11
+ export function cropOf(v) {
12
+ const c = nums(v);
13
+ return c.length === 4 && c[2] > 0 && c[3] > 0 ? [c[0], c[1], c[2], c[3]] : [0, 0, 100, 100];
14
+ }
15
+ /** Source seconds at `t` seconds into the layer. Pure, so the CLI extracts exactly what seek reads. */
16
+ export function sourceTime(t, props, params) {
17
+ const from = num(props.from), to = num(props.to), rate = num(params.rate, 1);
18
+ const run = Math.max(0, t) * rate;
19
+ if (params.loop === true && to > from)
20
+ return from + (run % (to - from));
21
+ return to > from ? Math.min(to, from + run) : from + run;
22
+ }
23
+ export const video = {
24
+ slug: 'el/video',
25
+ summary: 'Footage. Plays a stretch of a video file; the path is relative to the film file.',
26
+ props: {
27
+ src: { type: 'string', required: true, label: 'Video path or URL' },
28
+ from: { type: 'number', default: 0, label: 'Source time the layer opens on, in seconds' },
29
+ to: { type: 'number', default: 0, label: 'Source time it ends on, in seconds; 0 plays on until the scene ends' },
30
+ crop: { type: 'number[]', default: [], label: 'Part of the picture to show: [x, y, width, height] in % of the source' },
31
+ continues: { type: 'string', default: '', label: 'Open on the frame after another video layer ends, as "scene.layer": a seamless loop through footage' },
32
+ },
33
+ params: {
34
+ rate: { type: 'number', default: 1, min: 0.1, max: 4, step: 0.05, unit: '×', label: 'Playback speed' },
35
+ loop: { type: 'boolean', default: false, label: 'Wrap from "to" back to "from" until the scene ends' },
36
+ width: { type: 'number', default: 1280, min: 1, max: 8000, step: 1, unit: 'px', label: 'Width' },
37
+ height: { type: 'number', default: 0, min: 0, max: 8000, step: 1, unit: 'px', label: 'Height; 0 keeps the shot\'s proportions' },
38
+ radius: { type: 'number', default: 0, min: 0, max: 400, step: 1, unit: 'px', label: 'Corner radius' },
39
+ },
40
+ // Without an end the footage plays for as long as the scene: the scene's length or hold sets it.
41
+ // Footage and ambient drift are not moves: the pace check skips them.
42
+ cues: () => [],
43
+ duration: (props, p) => {
44
+ const from = num(props.from), to = num(props.to);
45
+ return p.loop === true || !(to > from) ? 0 : (to - from) / num(p.rate, 1);
46
+ },
47
+ check(props, p) {
48
+ const out = [];
49
+ const from = num(props.from), to = num(props.to);
50
+ if (from < 0)
51
+ out.push({ path: 'props.from', message: 'from is a source time in seconds, zero or more.' });
52
+ if (to !== 0 && to <= from)
53
+ out.push({ path: 'props.to', message: `to (${to} s) must come after from (${from} s).`, hint: 'Leave it at 0 to play on until the scene ends.' });
54
+ if (p.loop === true && !(to > from))
55
+ out.push({ path: 'params.loop', message: 'A loop needs both ends: set props.to after props.from.' });
56
+ const c = nums(props.crop);
57
+ if (c.length && (c.length !== 4 || c[2] <= 0 || c[3] <= 0 || c[0] < 0 || c[1] < 0 || c[0] + c[2] > 100.001 || c[1] + c[3] > 100.001)) {
58
+ out.push({ path: 'props.crop', message: 'crop is [x, y, width, height] in % of the source, inside 0–100.', hint: 'For the middle half: [25, 25, 50, 50].' });
59
+ }
60
+ const cont = str(props.continues);
61
+ if (cont && !/^[a-z][a-z0-9-]*\.[a-z][a-z0-9-]*$/.test(cont))
62
+ out.push({ path: 'props.continues', message: 'continues names a video layer as "scene.layer".' });
63
+ if (cont && num(props.from) !== 0) {
64
+ out.push({ path: 'props.from', message: 'from is worked out from "continues"; the value given is ignored.', hint: 'Remove from, or remove continues.' });
65
+ }
66
+ return out;
67
+ },
68
+ build(el, props, p, ctx) {
69
+ const doc = el.ownerDocument;
70
+ const [cx, cy, cw, ch] = cropOf(props.crop);
71
+ const width = num(p.width), height = num(p.height), radius = num(p.radius);
72
+ // The frame is a window; the picture inside it is scaled so the crop fills it.
73
+ const frame = doc.createElement('div');
74
+ frame.style.cssText = `position:relative;overflow:hidden;width:${width}px;border-radius:${radius}px;${height > 0 ? `height:${height}px` : 'aspect-ratio:16 / 9'}`;
75
+ el.style.borderRadius = `${radius}px`;
76
+ const inner = doc.createElement('div');
77
+ inner.style.cssText = `position:absolute;left:${(-cx / cw) * 100}%;top:${(-cy / ch) * 100}%;width:${(100 / cw) * 100}%;height:${(100 / ch) * 100}%`;
78
+ frame.appendChild(inner);
79
+ el.appendChild(frame);
80
+ const media = 'object-fit:fill;display:block;width:100%;height:100%';
81
+ // Once the source size is known: with no height the window takes the crop's
82
+ // own proportions; with both sides given, the crop is scaled about its
83
+ // centre to fill the window without being stretched.
84
+ const shape = (w, h) => {
85
+ if (!(w > 0 && h > 0))
86
+ return;
87
+ if (height <= 0) {
88
+ frame.style.aspectRatio = `${(w * cw).toFixed(3)} / ${(h * ch).toFixed(3)}`;
89
+ return;
90
+ }
91
+ const ratio = ((w * cw) / (h * ch)) / (width / height);
92
+ inner.style.transformOrigin = `${cx + cw / 2}% ${cy + ch / 2}%`;
93
+ inner.style.transform = `scale(${Math.max(1, ratio).toFixed(5)}, ${Math.max(1, 1 / ratio).toFixed(5)})`;
94
+ };
95
+ const frames = ctx.frames;
96
+ if (frames) {
97
+ const img = doc.createElement('img');
98
+ img.decoding = 'sync';
99
+ img.alt = '';
100
+ img.style.cssText = media;
101
+ img.src = frameUrl(frames, 0);
102
+ inner.appendChild(img);
103
+ shape(frames.width, frames.height);
104
+ let shown = 0, request = 0, waiting = Promise.resolve();
105
+ // Decoding a frame fails when a later seek swaps the image first; only the
106
+ // latest request counts, and only a frame that truly did not load is an error.
107
+ const loaded = (id, url) => img.decode().catch(() => {
108
+ if (id !== request || (img.complete && img.naturalWidth > 0))
109
+ return;
110
+ return new Promise((resolve, reject) => {
111
+ img.addEventListener('load', () => resolve(), { once: true });
112
+ img.addEventListener('error', () => (id === request ? reject(new Error(`Video frame did not load: ${url}`)) : resolve()), { once: true });
113
+ });
114
+ });
115
+ return {
116
+ seek(t) {
117
+ const n = Math.round((sourceTime(t, props, p) - frames.start) * frames.rate + 1e-6);
118
+ const clamped = Math.min(frames.count - 1, Math.max(0, n));
119
+ if (clamped === shown)
120
+ return;
121
+ shown = clamped;
122
+ const url = frameUrl(frames, clamped);
123
+ img.src = url;
124
+ waiting = loaded(++request, url);
125
+ },
126
+ pending: () => waiting,
127
+ };
128
+ }
129
+ const vid = doc.createElement('video');
130
+ vid.muted = true;
131
+ vid.playsInline = true;
132
+ vid.preload = 'auto';
133
+ vid.src = str(props.src);
134
+ vid.style.cssText = media;
135
+ inner.appendChild(vid);
136
+ vid.addEventListener('loadedmetadata', () => shape(vid.videoWidth, vid.videoHeight));
137
+ // A render without extracted frames waits for every seek; the studio lets the
138
+ // video play while the playhead moves at real speed, and seeks only on a jump.
139
+ const render = () => doc.documentElement.classList.contains('render');
140
+ const rate = num(p.rate, 1);
141
+ let waiting = Promise.resolve(), lastT = -1, lastWall = 0, idle;
142
+ const seekTo = (s) => {
143
+ if (Math.abs(vid.currentTime - s) < 0.5 / ctx.fps)
144
+ return;
145
+ waiting = new Promise((resolve) => {
146
+ const done = () => { vid.removeEventListener('seeked', done); resolve(); };
147
+ vid.addEventListener('seeked', done);
148
+ vid.currentTime = s;
149
+ });
150
+ };
151
+ return {
152
+ seek(t) {
153
+ const s = sourceTime(t, props, p);
154
+ if (render()) {
155
+ seekTo(s);
156
+ return;
157
+ }
158
+ const now = performance.now(), dt = t - lastT, wall = (now - lastWall) / 1000;
159
+ lastT = t;
160
+ lastWall = now;
161
+ const playing = dt > 0 && dt < 0.25 && Math.abs(dt - wall) < 0.1;
162
+ if (playing) {
163
+ if (Math.abs(vid.currentTime - s) > 0.2)
164
+ vid.currentTime = s;
165
+ vid.playbackRate = rate;
166
+ if (vid.paused)
167
+ void vid.play().catch(() => undefined);
168
+ clearTimeout(idle);
169
+ idle = setTimeout(() => vid.pause(), 120);
170
+ }
171
+ else {
172
+ vid.pause();
173
+ seekTo(s);
174
+ }
175
+ },
176
+ pending: () => waiting,
177
+ };
178
+ },
179
+ };
@@ -0,0 +1,2 @@
1
+ import { type Primitive } from '../types.ts';
2
+ export declare const counterRoll: Primitive;
@@ -0,0 +1,32 @@
1
+ // fx/counter-roll. See library/primitives/fx/counter-roll.md.
2
+ import { progress } from "../../core/ease.js";
3
+ import { num, str } from "../types.js";
4
+ export const counterRoll = {
5
+ slug: 'fx/counter-roll',
6
+ summary: 'A number rolls up to its value.',
7
+ props: {
8
+ value: { type: 'number', required: true, label: 'The number to land on' },
9
+ from: { type: 'number', default: 0, label: 'The number to start from' },
10
+ decimals: { type: 'number', default: 0, label: 'Decimal places' },
11
+ prefix: { type: 'string', default: '', label: 'Text before the number' },
12
+ suffix: { type: 'string', default: '', label: 'Text after the number' },
13
+ },
14
+ params: {
15
+ duration: { type: 'number', default: 1.0, min: 0.6, max: 1.5, step: 0.05, unit: 's', label: 'Time to roll' },
16
+ },
17
+ duration: (_props, p) => num(p.duration),
18
+ build(el, props, p, ctx) {
19
+ const ease = ctx.ease(ctx.tokens.ease_enter);
20
+ const to = num(props.value), from = num(props.from), decimals = Math.max(0, Math.round(num(props.decimals)));
21
+ const dur = num(p.duration);
22
+ el.style.fontVariantNumeric = 'tabular-nums';
23
+ el.style.whiteSpace = 'pre';
24
+ return {
25
+ seek(t) {
26
+ // At and after the end the exact value is written, never an eased near-miss.
27
+ const v = t >= dur ? to : from + (to - from) * progress(t, 0, dur, ease);
28
+ el.textContent = `${str(props.prefix)}${v.toFixed(decimals)}${str(props.suffix)}`;
29
+ },
30
+ };
31
+ },
32
+ };
@@ -0,0 +1,2 @@
1
+ import { type Primitive } from '../types.ts';
2
+ export declare const depthDrift: Primitive;
@@ -0,0 +1,44 @@
1
+ // fx/depth-drift. See library/primitives/fx/depth-drift.md.
2
+ import { rng } from "../../core/ease.js";
3
+ import { list, num } from "../types.js";
4
+ export const depthDrift = {
5
+ slug: 'fx/depth-drift',
6
+ summary: 'A floating collage on several depth planes.',
7
+ props: { items: { type: 'string[]', required: true, label: 'Labels of the floating pieces' } },
8
+ params: {
9
+ planes: { type: 'number', default: 3, min: 2, max: 3, step: 1, unit: 'planes', label: 'Depth planes' },
10
+ speed: { type: 'number', default: 20, min: 10, max: 30, step: 1, unit: 'px/s', label: 'Drift speed of the nearest plane' },
11
+ },
12
+ // Ambient backdrop: it drifts for as long as its scene.
13
+ duration: () => 0,
14
+ build(el, props, p, ctx) {
15
+ const [W, H] = ctx.size, u = W / 100;
16
+ const planes = Math.max(1, Math.round(num(p.planes))), speed = num(p.speed);
17
+ const random = rng(ctx.seed * 101 + 7);
18
+ const fade = ctx.ease(ctx.tokens.ease_enter), each = ctx.tokens.duration.base, stagger = ctx.tokens.stagger.base;
19
+ el.style.cssText += ';position:absolute;inset:0;max-width:none;pointer-events:none';
20
+ const items = list(props.items).map((label, i, all) => {
21
+ // Pieces sit on a ring around the middle, so the centre stays free for text.
22
+ const angle = ((i + random() * 0.6) / all.length) * Math.PI * 2;
23
+ const reach = 0.3 + random() * 0.14;
24
+ const x = W / 2 + Math.cos(angle) * W * reach, y = H / 2 + Math.sin(angle) * H * (reach + 0.04);
25
+ const plane = i % planes, depth = planes === 1 ? 1 : 1 - plane / planes; // 1 = nearest
26
+ const n = document.createElement('span');
27
+ n.textContent = label;
28
+ n.style.cssText = `position:absolute;left:0;top:0;padding:${0.7 * u}px ${1.4 * u}px;border-radius:999px;white-space:nowrap;background:var(--m-bg-surface);` +
29
+ `font:500 ${1.4 * u}px var(--m-font-mono);color:var(--m-text-primary)${plane === 0 && planes > 1 ? `;filter:blur(${0.06 * u}px)` : ''}`;
30
+ el.appendChild(n);
31
+ return { n, x, y, depth, delay: i * stagger };
32
+ });
33
+ return {
34
+ seek(t) {
35
+ for (const it of items) {
36
+ // Near pieces are larger and faster; far ones smaller and slower.
37
+ const dx = (t - 2) * speed * it.depth;
38
+ it.n.style.transform = `translate(${it.x + dx}px, ${it.y}px) translate(-50%, -50%) scale(${0.72 + it.depth * 0.42})`;
39
+ it.n.style.opacity = String(fade(Math.min(1, Math.max(0, (t - it.delay) / each))) * (0.35 + it.depth * 0.5));
40
+ }
41
+ },
42
+ };
43
+ },
44
+ };
@@ -0,0 +1,2 @@
1
+ import { type Primitive } from '../types.ts';
2
+ export declare const gridRipple: Primitive;