@open-take/compositor 0.5.2 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (439) hide show
  1. package/dist/cdp-CzT5BKNY.js +3 -0
  2. package/dist/cdp-QXbQfXna.js +373 -0
  3. package/dist/cdp-QXbQfXna.js.map +1 -0
  4. package/dist/index.d.ts +4327 -195
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +26282 -160
  7. package/dist/index.js.map +1 -1
  8. package/dist/server-841PMF2H.js +163 -0
  9. package/dist/server-841PMF2H.js.map +1 -0
  10. package/dist/server-C2aVv4-t.js +3 -0
  11. package/kit/audio.mjs +2366 -0
  12. package/kit/camera.js +587 -0
  13. package/kit/cursor.js +264 -0
  14. package/kit/cut.js +427 -0
  15. package/kit/draw.js +346 -0
  16. package/kit/look.js +589 -0
  17. package/kit/map.js +170 -0
  18. package/kit/media.js +3568 -0
  19. package/kit/motion.js +1115 -0
  20. package/kit/seams.js +1006 -0
  21. package/kit/stage.js +923 -0
  22. package/kit/time.js +812 -0
  23. package/kit/world.js +1072 -0
  24. package/package.json +7 -3
  25. package/src/ffmpeg.ts +63 -0
  26. package/src/film/beats.ts +1285 -0
  27. package/src/film/carry.ts +221 -0
  28. package/src/film/changes.ts +330 -0
  29. package/src/film/check.ts +996 -0
  30. package/src/film/clock.ts +2530 -0
  31. package/src/film/components-probe.ts +809 -0
  32. package/src/film/components.ts +1566 -0
  33. package/src/film/frames.ts +389 -0
  34. package/src/film/gallery.ts +3276 -0
  35. package/src/film/kit.ts +515 -0
  36. package/src/film/layout.ts +701 -0
  37. package/src/film/listen.ts +1979 -0
  38. package/src/film/look.ts +3829 -0
  39. package/src/film/materials.ts +976 -0
  40. package/src/film/moving.ts +248 -0
  41. package/src/film/part-files.ts +729 -0
  42. package/src/film/picture.ts +74 -0
  43. package/src/film/probe-text.ts +843 -0
  44. package/src/film/probe.ts +3456 -0
  45. package/src/film/provenance.ts +596 -0
  46. package/src/film/render.ts +2447 -0
  47. package/src/film/report.ts +1631 -0
  48. package/src/film/sheet.ts +156 -0
  49. package/src/film/study-declared.ts +123 -0
  50. package/src/film/study-picture.ts +791 -0
  51. package/src/film/study-sound.ts +416 -0
  52. package/src/film/study.ts +864 -0
  53. package/src/film/tuning.ts +155 -0
  54. package/src/film/viewer.ts +174 -0
  55. package/src/html/cdp.ts +575 -0
  56. package/src/html/server.ts +208 -0
  57. package/src/index.ts +202 -0
  58. package/src/launch-render.ts +3 -2
  59. package/src/math.ts +3 -3
  60. package/src/mjpeg-matroska.ts +228 -0
  61. package/src/render.ts +6 -4
  62. package/src/state-diff.ts +215 -0
  63. package/src/state-index.ts +99 -0
  64. package/src/types.ts +59 -1
  65. package/starter/PLAN.md +84 -0
  66. package/starter/START.md +460 -0
  67. package/starter/lib/anim.js +760 -0
  68. package/starter/lib/devices.js +1402 -0
  69. package/starter/lib/handoff.js +421 -0
  70. package/starter/lib/hud.js +1879 -0
  71. package/starter/lib/measure.mjs +154 -0
  72. package/starter/lib/moves.js +1095 -0
  73. package/starter/lib/palette.mjs +803 -0
  74. package/starter/lib/physics-seeds.mjs +198 -0
  75. package/starter/lib/physics.js +738 -0
  76. package/starter/lib/sampler.mjs +242 -0
  77. package/starter/lib/solid.js +727 -0
  78. package/starter/lib/space.js +1227 -0
  79. package/starter/lib/swarm.js +1398 -0
  80. package/starter/reference/motion.md +276 -0
  81. package/starter/reference/structure.md +466 -0
  82. package/starter/reference/travel/motion.md +433 -0
  83. package/starter/reference/travel/sound.md +241 -0
  84. package/starter/reference/travel/structure.md +518 -0
  85. package/starter/samples/NOTICE.txt +55 -0
  86. package/starter/samples/celli/celli_24_1.opus +0 -0
  87. package/starter/samples/celli/celli_24_3.opus +0 -0
  88. package/starter/samples/celli/celli_28_1.opus +0 -0
  89. package/starter/samples/celli/celli_28_3.opus +0 -0
  90. package/starter/samples/celli/celli_31_1.opus +0 -0
  91. package/starter/samples/celli/celli_31_3.opus +0 -0
  92. package/starter/samples/celli/celli_35_1.opus +0 -0
  93. package/starter/samples/celli/celli_35_3.opus +0 -0
  94. package/starter/samples/celli/celli_38_1.opus +0 -0
  95. package/starter/samples/celli/celli_38_3.opus +0 -0
  96. package/starter/samples/celli/celli_41_1.opus +0 -0
  97. package/starter/samples/celli/celli_41_3.opus +0 -0
  98. package/starter/samples/celli/celli_45_1.opus +0 -0
  99. package/starter/samples/celli/celli_45_3.opus +0 -0
  100. package/starter/samples/celli/celli_48_1.opus +0 -0
  101. package/starter/samples/celli/celli_48_3.opus +0 -0
  102. package/starter/samples/celli/celli_52_1.opus +0 -0
  103. package/starter/samples/celli/celli_52_3.opus +0 -0
  104. package/starter/samples/celli/celli_55_1.opus +0 -0
  105. package/starter/samples/celli/celli_55_3.opus +0 -0
  106. package/starter/samples/celli/celli_59_1.opus +0 -0
  107. package/starter/samples/celli/celli_59_3.opus +0 -0
  108. package/starter/samples/celli/celli_62_1.opus +0 -0
  109. package/starter/samples/celli/celli_62_3.opus +0 -0
  110. package/starter/samples/celli/celli_65_1.opus +0 -0
  111. package/starter/samples/celli/celli_65_3.opus +0 -0
  112. package/starter/samples/crash/crash_f_1.flac +0 -0
  113. package/starter/samples/crash/crash_fff_1.flac +0 -0
  114. package/starter/samples/ebass/ebass_0_x.flac +0 -0
  115. package/starter/samples/ebass/ebass_10_x.flac +0 -0
  116. package/starter/samples/ebass/ebass_11_x.flac +0 -0
  117. package/starter/samples/ebass/ebass_1_x.flac +0 -0
  118. package/starter/samples/ebass/ebass_2_x.flac +0 -0
  119. package/starter/samples/ebass/ebass_3_x.flac +0 -0
  120. package/starter/samples/ebass/ebass_4_x.flac +0 -0
  121. package/starter/samples/ebass/ebass_5_x.flac +0 -0
  122. package/starter/samples/ebass/ebass_6_x.flac +0 -0
  123. package/starter/samples/ebass/ebass_7_x.flac +0 -0
  124. package/starter/samples/ebass/ebass_8_x.flac +0 -0
  125. package/starter/samples/ebass/ebass_9_x.flac +0 -0
  126. package/starter/samples/ek_clap/ek_clap_1_1.flac +0 -0
  127. package/starter/samples/ek_hat/ek_hat_1_1.flac +0 -0
  128. package/starter/samples/ek_hat/ek_hat_1_2.flac +0 -0
  129. package/starter/samples/ek_kick/ek_kick_1_1.flac +0 -0
  130. package/starter/samples/ek_kick/ek_kick_1_2.flac +0 -0
  131. package/starter/samples/glock/glock_67_x.flac +0 -0
  132. package/starter/samples/glock/glock_72_x.flac +0 -0
  133. package/starter/samples/glock/glock_79_x.flac +0 -0
  134. package/starter/samples/glock/glock_84_x.flac +0 -0
  135. package/starter/samples/glock/glock_91_x.flac +0 -0
  136. package/starter/samples/glock/glock_96_x.flac +0 -0
  137. package/starter/samples/harp/harp_101_f.opus +0 -0
  138. package/starter/samples/harp/harp_28_f.opus +0 -0
  139. package/starter/samples/harp/harp_31_mp.opus +0 -0
  140. package/starter/samples/harp/harp_35_mf.opus +0 -0
  141. package/starter/samples/harp/harp_38_mf.opus +0 -0
  142. package/starter/samples/harp/harp_41_mf.opus +0 -0
  143. package/starter/samples/harp/harp_45_mf.opus +0 -0
  144. package/starter/samples/harp/harp_48_mf.opus +0 -0
  145. package/starter/samples/harp/harp_52_mf.opus +0 -0
  146. package/starter/samples/harp/harp_55_mf.opus +0 -0
  147. package/starter/samples/harp/harp_59_mf.opus +0 -0
  148. package/starter/samples/harp/harp_62_mf.opus +0 -0
  149. package/starter/samples/harp/harp_65_mf.opus +0 -0
  150. package/starter/samples/harp/harp_69_mf.opus +0 -0
  151. package/starter/samples/harp/harp_72_mf.opus +0 -0
  152. package/starter/samples/harp/harp_76_mf.opus +0 -0
  153. package/starter/samples/harp/harp_79_mf.opus +0 -0
  154. package/starter/samples/harp/harp_83_mf.opus +0 -0
  155. package/starter/samples/harp/harp_86_mf.opus +0 -0
  156. package/starter/samples/harp/harp_89_mf.opus +0 -0
  157. package/starter/samples/harp/harp_93_mf.opus +0 -0
  158. package/starter/samples/harp/harp_95_mf.opus +0 -0
  159. package/starter/samples/harp/harp_98_f.opus +0 -0
  160. package/starter/samples/manifest.json +2951 -0
  161. package/starter/samples/marimba/marimba_29_x.flac +0 -0
  162. package/starter/samples/marimba/marimba_36_x.flac +0 -0
  163. package/starter/samples/marimba/marimba_43_x.flac +0 -0
  164. package/starter/samples/marimba/marimba_47_x.flac +0 -0
  165. package/starter/samples/marimba/marimba_53_x.flac +0 -0
  166. package/starter/samples/marimba/marimba_60_x.flac +0 -0
  167. package/starter/samples/marimba/marimba_67_x.flac +0 -0
  168. package/starter/samples/marimba/marimba_71_x.flac +0 -0
  169. package/starter/samples/marimba/marimba_77_x.flac +0 -0
  170. package/starter/samples/marimba/marimba_84_x.flac +0 -0
  171. package/starter/samples/piano/piano_102_12.opus +0 -0
  172. package/starter/samples/piano/piano_102_16.opus +0 -0
  173. package/starter/samples/piano/piano_102_4.opus +0 -0
  174. package/starter/samples/piano/piano_102_8.opus +0 -0
  175. package/starter/samples/piano/piano_105_12.opus +0 -0
  176. package/starter/samples/piano/piano_105_16.opus +0 -0
  177. package/starter/samples/piano/piano_105_4.opus +0 -0
  178. package/starter/samples/piano/piano_105_8.opus +0 -0
  179. package/starter/samples/piano/piano_108_12.opus +0 -0
  180. package/starter/samples/piano/piano_108_16.opus +0 -0
  181. package/starter/samples/piano/piano_108_4.opus +0 -0
  182. package/starter/samples/piano/piano_108_8.opus +0 -0
  183. package/starter/samples/piano/piano_21_12.opus +0 -0
  184. package/starter/samples/piano/piano_21_16.opus +0 -0
  185. package/starter/samples/piano/piano_21_4.opus +0 -0
  186. package/starter/samples/piano/piano_21_8.opus +0 -0
  187. package/starter/samples/piano/piano_24_12.opus +0 -0
  188. package/starter/samples/piano/piano_24_16.opus +0 -0
  189. package/starter/samples/piano/piano_24_4.opus +0 -0
  190. package/starter/samples/piano/piano_24_8.opus +0 -0
  191. package/starter/samples/piano/piano_27_12.opus +0 -0
  192. package/starter/samples/piano/piano_27_16.opus +0 -0
  193. package/starter/samples/piano/piano_27_4.opus +0 -0
  194. package/starter/samples/piano/piano_27_8.opus +0 -0
  195. package/starter/samples/piano/piano_30_12.opus +0 -0
  196. package/starter/samples/piano/piano_30_16.opus +0 -0
  197. package/starter/samples/piano/piano_30_4.opus +0 -0
  198. package/starter/samples/piano/piano_30_8.opus +0 -0
  199. package/starter/samples/piano/piano_33_12.opus +0 -0
  200. package/starter/samples/piano/piano_33_16.opus +0 -0
  201. package/starter/samples/piano/piano_33_4.opus +0 -0
  202. package/starter/samples/piano/piano_33_8.opus +0 -0
  203. package/starter/samples/piano/piano_36_12.opus +0 -0
  204. package/starter/samples/piano/piano_36_16.opus +0 -0
  205. package/starter/samples/piano/piano_36_4.opus +0 -0
  206. package/starter/samples/piano/piano_36_8.opus +0 -0
  207. package/starter/samples/piano/piano_39_12.opus +0 -0
  208. package/starter/samples/piano/piano_39_16.opus +0 -0
  209. package/starter/samples/piano/piano_39_4.opus +0 -0
  210. package/starter/samples/piano/piano_39_8.opus +0 -0
  211. package/starter/samples/piano/piano_42_12.opus +0 -0
  212. package/starter/samples/piano/piano_42_16.opus +0 -0
  213. package/starter/samples/piano/piano_42_4.opus +0 -0
  214. package/starter/samples/piano/piano_42_8.opus +0 -0
  215. package/starter/samples/piano/piano_45_12.opus +0 -0
  216. package/starter/samples/piano/piano_45_16.opus +0 -0
  217. package/starter/samples/piano/piano_45_4.opus +0 -0
  218. package/starter/samples/piano/piano_45_8.opus +0 -0
  219. package/starter/samples/piano/piano_48_12.opus +0 -0
  220. package/starter/samples/piano/piano_48_16.opus +0 -0
  221. package/starter/samples/piano/piano_48_4.opus +0 -0
  222. package/starter/samples/piano/piano_48_8.opus +0 -0
  223. package/starter/samples/piano/piano_51_12.opus +0 -0
  224. package/starter/samples/piano/piano_51_16.opus +0 -0
  225. package/starter/samples/piano/piano_51_4.opus +0 -0
  226. package/starter/samples/piano/piano_51_8.opus +0 -0
  227. package/starter/samples/piano/piano_54_12.opus +0 -0
  228. package/starter/samples/piano/piano_54_16.opus +0 -0
  229. package/starter/samples/piano/piano_54_4.opus +0 -0
  230. package/starter/samples/piano/piano_54_8.opus +0 -0
  231. package/starter/samples/piano/piano_57_12.opus +0 -0
  232. package/starter/samples/piano/piano_57_16.opus +0 -0
  233. package/starter/samples/piano/piano_57_4.opus +0 -0
  234. package/starter/samples/piano/piano_57_8.opus +0 -0
  235. package/starter/samples/piano/piano_60_12.opus +0 -0
  236. package/starter/samples/piano/piano_60_16.opus +0 -0
  237. package/starter/samples/piano/piano_60_4.opus +0 -0
  238. package/starter/samples/piano/piano_60_8.opus +0 -0
  239. package/starter/samples/piano/piano_63_12.opus +0 -0
  240. package/starter/samples/piano/piano_63_16.opus +0 -0
  241. package/starter/samples/piano/piano_63_4.opus +0 -0
  242. package/starter/samples/piano/piano_63_8.opus +0 -0
  243. package/starter/samples/piano/piano_66_12.opus +0 -0
  244. package/starter/samples/piano/piano_66_16.opus +0 -0
  245. package/starter/samples/piano/piano_66_4.opus +0 -0
  246. package/starter/samples/piano/piano_66_8.opus +0 -0
  247. package/starter/samples/piano/piano_69_12.opus +0 -0
  248. package/starter/samples/piano/piano_69_16.opus +0 -0
  249. package/starter/samples/piano/piano_69_4.opus +0 -0
  250. package/starter/samples/piano/piano_69_8.opus +0 -0
  251. package/starter/samples/piano/piano_72_12.opus +0 -0
  252. package/starter/samples/piano/piano_72_16.opus +0 -0
  253. package/starter/samples/piano/piano_72_4.opus +0 -0
  254. package/starter/samples/piano/piano_72_8.opus +0 -0
  255. package/starter/samples/piano/piano_75_12.opus +0 -0
  256. package/starter/samples/piano/piano_75_16.opus +0 -0
  257. package/starter/samples/piano/piano_75_4.opus +0 -0
  258. package/starter/samples/piano/piano_75_8.opus +0 -0
  259. package/starter/samples/piano/piano_78_12.opus +0 -0
  260. package/starter/samples/piano/piano_78_16.opus +0 -0
  261. package/starter/samples/piano/piano_78_4.opus +0 -0
  262. package/starter/samples/piano/piano_78_8.opus +0 -0
  263. package/starter/samples/piano/piano_81_12.opus +0 -0
  264. package/starter/samples/piano/piano_81_16.opus +0 -0
  265. package/starter/samples/piano/piano_81_4.opus +0 -0
  266. package/starter/samples/piano/piano_81_8.opus +0 -0
  267. package/starter/samples/piano/piano_84_12.opus +0 -0
  268. package/starter/samples/piano/piano_84_16.opus +0 -0
  269. package/starter/samples/piano/piano_84_4.opus +0 -0
  270. package/starter/samples/piano/piano_84_8.opus +0 -0
  271. package/starter/samples/piano/piano_87_12.opus +0 -0
  272. package/starter/samples/piano/piano_87_16.opus +0 -0
  273. package/starter/samples/piano/piano_87_4.opus +0 -0
  274. package/starter/samples/piano/piano_87_8.opus +0 -0
  275. package/starter/samples/piano/piano_90_12.opus +0 -0
  276. package/starter/samples/piano/piano_90_16.opus +0 -0
  277. package/starter/samples/piano/piano_90_4.opus +0 -0
  278. package/starter/samples/piano/piano_90_8.opus +0 -0
  279. package/starter/samples/piano/piano_93_12.opus +0 -0
  280. package/starter/samples/piano/piano_93_16.opus +0 -0
  281. package/starter/samples/piano/piano_93_4.opus +0 -0
  282. package/starter/samples/piano/piano_93_8.opus +0 -0
  283. package/starter/samples/piano/piano_96_12.opus +0 -0
  284. package/starter/samples/piano/piano_96_16.opus +0 -0
  285. package/starter/samples/piano/piano_96_4.opus +0 -0
  286. package/starter/samples/piano/piano_96_8.opus +0 -0
  287. package/starter/samples/piano/piano_99_12.opus +0 -0
  288. package/starter/samples/piano/piano_99_16.opus +0 -0
  289. package/starter/samples/piano/piano_99_4.opus +0 -0
  290. package/starter/samples/piano/piano_99_8.opus +0 -0
  291. package/starter/samples/piano/piano_rel_102_x.opus +0 -0
  292. package/starter/samples/piano/piano_rel_105_x.opus +0 -0
  293. package/starter/samples/piano/piano_rel_108_x.opus +0 -0
  294. package/starter/samples/piano/piano_rel_21_x.opus +0 -0
  295. package/starter/samples/piano/piano_rel_24_x.opus +0 -0
  296. package/starter/samples/piano/piano_rel_27_x.opus +0 -0
  297. package/starter/samples/piano/piano_rel_30_x.opus +0 -0
  298. package/starter/samples/piano/piano_rel_33_x.opus +0 -0
  299. package/starter/samples/piano/piano_rel_36_x.opus +0 -0
  300. package/starter/samples/piano/piano_rel_39_x.opus +0 -0
  301. package/starter/samples/piano/piano_rel_42_x.opus +0 -0
  302. package/starter/samples/piano/piano_rel_45_x.opus +0 -0
  303. package/starter/samples/piano/piano_rel_48_x.opus +0 -0
  304. package/starter/samples/piano/piano_rel_51_x.opus +0 -0
  305. package/starter/samples/piano/piano_rel_54_x.opus +0 -0
  306. package/starter/samples/piano/piano_rel_57_x.opus +0 -0
  307. package/starter/samples/piano/piano_rel_60_x.opus +0 -0
  308. package/starter/samples/piano/piano_rel_63_x.opus +0 -0
  309. package/starter/samples/piano/piano_rel_66_x.opus +0 -0
  310. package/starter/samples/piano/piano_rel_69_x.opus +0 -0
  311. package/starter/samples/piano/piano_rel_72_x.opus +0 -0
  312. package/starter/samples/piano/piano_rel_75_x.opus +0 -0
  313. package/starter/samples/piano/piano_rel_78_x.opus +0 -0
  314. package/starter/samples/piano/piano_rel_81_x.opus +0 -0
  315. package/starter/samples/piano/piano_rel_84_x.opus +0 -0
  316. package/starter/samples/piano/piano_rel_87_x.opus +0 -0
  317. package/starter/samples/piano/piano_rel_90_x.opus +0 -0
  318. package/starter/samples/piano/piano_rel_93_x.opus +0 -0
  319. package/starter/samples/piano/piano_rel_96_x.opus +0 -0
  320. package/starter/samples/piano/piano_rel_99_x.opus +0 -0
  321. package/starter/samples/pizz/pizz_24_2.flac +0 -0
  322. package/starter/samples/pizz/pizz_28_2.flac +0 -0
  323. package/starter/samples/pizz/pizz_31_2.flac +0 -0
  324. package/starter/samples/pizz/pizz_35_2.flac +0 -0
  325. package/starter/samples/pizz/pizz_38_2.flac +0 -0
  326. package/starter/samples/pizz/pizz_41_2.flac +0 -0
  327. package/starter/samples/pizz/pizz_45_2.flac +0 -0
  328. package/starter/samples/pizz/pizz_48_2.flac +0 -0
  329. package/starter/samples/pizz/pizz_52_2.flac +0 -0
  330. package/starter/samples/pizz/pizz_57_2.flac +0 -0
  331. package/starter/samples/pizz/pizz_60_2.flac +0 -0
  332. package/starter/samples/pizz/pizz_64_2.flac +0 -0
  333. package/starter/samples/pizz/pizz_67_2.flac +0 -0
  334. package/starter/samples/pizz/pizz_71_2.flac +0 -0
  335. package/starter/samples/pizz/pizz_74_2.flac +0 -0
  336. package/starter/samples/pk_hat/pk_hat_2_1.flac +0 -0
  337. package/starter/samples/pk_hat/pk_hat_2_2.flac +0 -0
  338. package/starter/samples/pk_hat/pk_hat_6_1.flac +0 -0
  339. package/starter/samples/pk_hat/pk_hat_6_2.flac +0 -0
  340. package/starter/samples/pk_kick/pk_kick_3_1.flac +0 -0
  341. package/starter/samples/pk_kick/pk_kick_3_2.flac +0 -0
  342. package/starter/samples/pk_kick/pk_kick_7_1.flac +0 -0
  343. package/starter/samples/pk_kick/pk_kick_7_2.flac +0 -0
  344. package/starter/samples/pk_ohat/pk_ohat_3_1.flac +0 -0
  345. package/starter/samples/pk_ohat/pk_ohat_3_2.flac +0 -0
  346. package/starter/samples/pk_ohat/pk_ohat_6_1.flac +0 -0
  347. package/starter/samples/pk_ohat/pk_ohat_6_2.flac +0 -0
  348. package/starter/samples/pk_rim/pk_rim_2_1.flac +0 -0
  349. package/starter/samples/pk_rim/pk_rim_2_2.flac +0 -0
  350. package/starter/samples/pk_rim/pk_rim_5_1.flac +0 -0
  351. package/starter/samples/pk_rim/pk_rim_5_2.flac +0 -0
  352. package/starter/samples/pk_snare/pk_snare_3_1.flac +0 -0
  353. package/starter/samples/pk_snare/pk_snare_3_2.flac +0 -0
  354. package/starter/samples/pk_snare/pk_snare_7_1.flac +0 -0
  355. package/starter/samples/pk_snare/pk_snare_7_2.flac +0 -0
  356. package/starter/samples/shaker/shaker_1_1.flac +0 -0
  357. package/starter/samples/shaker/shaker_2_1.flac +0 -0
  358. package/starter/samples/snap/snap_r_1.flac +0 -0
  359. package/starter/samples/snap/snap_r_2.flac +0 -0
  360. package/starter/samples/snap/snap_r_3.flac +0 -0
  361. package/starter/samples/snap/snap_r_4.flac +0 -0
  362. package/starter/samples/snap/snap_r_5.flac +0 -0
  363. package/starter/samples/snap/snap_r_6.flac +0 -0
  364. package/starter/samples/tom/tom_3_1.flac +0 -0
  365. package/starter/samples/tom/tom_3_2.flac +0 -0
  366. package/starter/samples/tom/tom_4_1.flac +0 -0
  367. package/starter/samples/tom/tom_4_2.flac +0 -0
  368. package/starter/samples/vibes/vibes_41_1.opus +0 -0
  369. package/starter/samples/vibes/vibes_41_2.opus +0 -0
  370. package/starter/samples/vibes/vibes_45_1.opus +0 -0
  371. package/starter/samples/vibes/vibes_45_2.opus +0 -0
  372. package/starter/samples/vibes/vibes_48_1.opus +0 -0
  373. package/starter/samples/vibes/vibes_48_2.opus +0 -0
  374. package/starter/samples/vibes/vibes_52_1.opus +0 -0
  375. package/starter/samples/vibes/vibes_52_2.opus +0 -0
  376. package/starter/samples/vibes/vibes_55_1.opus +0 -0
  377. package/starter/samples/vibes/vibes_55_2.opus +0 -0
  378. package/starter/samples/vibes/vibes_59_1.opus +0 -0
  379. package/starter/samples/vibes/vibes_59_2.opus +0 -0
  380. package/starter/samples/vibes/vibes_62_1.opus +0 -0
  381. package/starter/samples/vibes/vibes_62_2.opus +0 -0
  382. package/starter/samples/vibes/vibes_65_1.opus +0 -0
  383. package/starter/samples/vibes/vibes_65_2.opus +0 -0
  384. package/starter/samples/vibes/vibes_69_1.opus +0 -0
  385. package/starter/samples/vibes/vibes_69_2.opus +0 -0
  386. package/starter/samples/vibes/vibes_72_1.opus +0 -0
  387. package/starter/samples/vibes/vibes_72_2.opus +0 -0
  388. package/starter/samples/vibes/vibes_76_1.opus +0 -0
  389. package/starter/samples/vibes/vibes_76_2.opus +0 -0
  390. package/starter/samples/violas/violas_36_1.opus +0 -0
  391. package/starter/samples/violas/violas_36_2.opus +0 -0
  392. package/starter/samples/violas/violas_38_1.opus +0 -0
  393. package/starter/samples/violas/violas_38_2.opus +0 -0
  394. package/starter/samples/violas/violas_40_1.opus +0 -0
  395. package/starter/samples/violas/violas_40_2.opus +0 -0
  396. package/starter/samples/violas/violas_43_1.opus +0 -0
  397. package/starter/samples/violas/violas_43_2.opus +0 -0
  398. package/starter/samples/violas/violas_47_1.opus +0 -0
  399. package/starter/samples/violas/violas_47_2.opus +0 -0
  400. package/starter/samples/violas/violas_50_1.opus +0 -0
  401. package/starter/samples/violas/violas_50_2.opus +0 -0
  402. package/starter/samples/violas/violas_53_1.opus +0 -0
  403. package/starter/samples/violas/violas_53_2.opus +0 -0
  404. package/starter/samples/violas/violas_57_1.opus +0 -0
  405. package/starter/samples/violas/violas_57_2.opus +0 -0
  406. package/starter/samples/violas/violas_60_1.opus +0 -0
  407. package/starter/samples/violas/violas_60_2.opus +0 -0
  408. package/starter/samples/violas/violas_64_1.opus +0 -0
  409. package/starter/samples/violas/violas_64_2.opus +0 -0
  410. package/starter/samples/violas/violas_67_1.opus +0 -0
  411. package/starter/samples/violas/violas_67_2.opus +0 -0
  412. package/starter/samples/violas/violas_71_1.opus +0 -0
  413. package/starter/samples/violas/violas_71_2.opus +0 -0
  414. package/starter/samples/violas/violas_74_1.opus +0 -0
  415. package/starter/samples/violas/violas_74_2.opus +0 -0
  416. package/starter/samples/violins/violins_43_1.opus +0 -0
  417. package/starter/samples/violins/violins_43_2.opus +0 -0
  418. package/starter/samples/violins/violins_45_1.opus +0 -0
  419. package/starter/samples/violins/violins_45_2.opus +0 -0
  420. package/starter/samples/violins/violins_47_1.opus +0 -0
  421. package/starter/samples/violins/violins_47_2.opus +0 -0
  422. package/starter/samples/violins/violins_50_1.opus +0 -0
  423. package/starter/samples/violins/violins_50_2.opus +0 -0
  424. package/starter/samples/violins/violins_54_1.opus +0 -0
  425. package/starter/samples/violins/violins_54_2.opus +0 -0
  426. package/starter/samples/violins/violins_57_1.opus +0 -0
  427. package/starter/samples/violins/violins_57_2.opus +0 -0
  428. package/starter/samples/violins/violins_60_1.opus +0 -0
  429. package/starter/samples/violins/violins_60_2.opus +0 -0
  430. package/starter/samples/violins/violins_64_1.opus +0 -0
  431. package/starter/samples/violins/violins_64_2.opus +0 -0
  432. package/starter/samples/violins/violins_67_1.opus +0 -0
  433. package/starter/samples/violins/violins_67_2.opus +0 -0
  434. package/starter/samples/violins/violins_71_1.opus +0 -0
  435. package/starter/samples/violins/violins_71_2.opus +0 -0
  436. package/starter/samples/violins/violins_74_1.opus +0 -0
  437. package/starter/samples/violins/violins_74_2.opus +0 -0
  438. package/starter/samples/woodblock/woodblock_f_1.flac +0 -0
  439. package/starter/samples/woodblock/woodblock_f_2.flac +0 -0
@@ -0,0 +1,1095 @@
1
+ // moves.js — camera and cut moves for a film built of flat layers (a desk,
2
+ // windows, cards, a screen): the 2.5D moves launch reels make out of them.
3
+ // Plain functions of film time t (s), no state, nothing here knows any film.
4
+ // Each gives back where each layer is — { x, y, s, … } with its CSS `css`
5
+ // and `origin` — for you to write onto your elements (`apply` does it).
6
+ // Their defaults are numbers measured frame by frame on launch reels; the
7
+ // comment over each says where. Read as px of a 1920 × 1080 frame unless a
8
+ // `view` says otherwise.
9
+ //
10
+ // import { windowHop, momentumCut, apply } from "./lib/moves.js";
11
+ //
12
+ // windowHop(t, t0, from, to, o) pull out of one window to the desk, a beat, the next window lifts
13
+ // to the lens while the desk only slides (layers, not one zoom);
14
+ // `from` a window, or the camera the take is on, still moving
15
+ // pullbackReveal(t, t0, o) the full frame pulls back into a plane in space, its width shrinking
16
+ // at an even rate on screen, then drifting on
17
+ // stations(t, list, o) a camera from station to station: quick to leave, eleven frames to
18
+ // slow, then creeping on until it leaves again
19
+ // station(rect, o) the camera that frames a rect the way each station did (0.635 W)
20
+ // stationTimes(list, o) when each leg peaks and lands, and how long each station is held
21
+ // camPose(cam, view) a camera { x, y, s } as the pose of the world's layer
22
+ // momentumCut(t, at, o) leave faster every frame, cut on the fastest, the next shot
23
+ // carrying on the same way and slowing; a scene's ground kept
24
+ // past its edge meanwhile
25
+ // rampJump(t, at, o) a push that speeds up, jumps 1.4× in one frame, and settles;
26
+ // its `cam` is where a further move carries on from
27
+ // exitDrift(t, t0, t1, o) a hold that drifts, then speeds away into the cut at t1
28
+ // arrivalShake(t, t0, o) the page kicked sideways for 3–4 frames when something lands
29
+ // blurBridge(t, at, o) out of focus, cut, into focus
30
+ // zoomThrough(t, start, end, rect, o) fly into a rect faster and faster, cut on the fastest frame
31
+ // toThumbnail(t, start, from, to, o) a flash, and the whole picture shrinks into its thumbnail
32
+ // implodeTo(t, start, items, to, o) a crowd collapses into a point that grows into one thing
33
+ // develop(t, start, o) a picture arriving as a duotone, then a second, then finished
34
+ // remap(t, keys, o) film time → the time a stretch is drawn at: ramps, freezes, on twos
35
+ // freeze(at, o) the keys of a freeze: slow, hold, speed up again
36
+ // onTwos(t, n, fps) time held for n frames at a time (drawn on twos)
37
+ // apply(el, pose) writes a pose onto an element
38
+ //
39
+ // A cut here falls between two frames of the film as it is drawn
40
+ // (window.__filmFps, which `film render` sets; else 60), so the master's
41
+ // shutter never mixes the two sides. Each move that cuts returns `cutAt`:
42
+ // declare it, `tl.event(m.cutAt, "cut")` — rampJump's jump, a cut hidden in
43
+ // the move, as `tl.event(j.cutAt, "hidden-cut")` — and the render report
44
+ // counts it as meant. A windowHop's lift is a picture jump the report cannot
45
+ // tell from a cut: declare its span as a segment of its own,
46
+ // `tl.segment(h.lifts, h.end, { handoff: "lift" })`. Nothing here blurs: the
47
+ // master's shutter smears what moves fast, and a move that cuts keeps moving
48
+ // at its last speed through the half of the last frame's shutter before the
49
+ // cut (and the next shot at its first speed through the half after), so the
50
+ // fastest frame is smeared whole. A draft has no shutter — `film still --at`
51
+ // shows a frame as the master will.
52
+ //
53
+ // One element per move. A pose is a whole transform: two moves applied to
54
+ // one element overwrite each other. A scene that comes in on one move and
55
+ // leaves on another is two elements, one inside the other, each given its
56
+ // own (`<div id="sceneOut"><div id="sceneIn">…</div></div>`). A Rect is in
57
+ // the layout of the element the pose is for — frame px when that element is
58
+ // at 0, 0 the size of the frame, as a desk, world or stage layer is — not
59
+ // where some other move has carried it on screen.
60
+ //
61
+ // One take, several moves: a camera is { x, y, s } — the world point at the
62
+ // frame's centre and the scale (anim.js cam2d) — and the moves that carry a
63
+ // take on read one where they start, as it is or as a function of t for one
64
+ // still moving: stations' `from`, windowHop's `from`, pullbackReveal's
65
+ // `from`, rampJump's `from`. Each gives a camera back (`cam`, or itself), so
66
+ // the world stays one element: `apply(world, camPose(stations(t, list,
67
+ // { from: (t) => rampJump(t, at, o).cam })))`. A move that starts from a
68
+ // camera still moving starts from rest on top of it (over `soft` s), so the
69
+ // picture's speed does not step where one move hands over to the next.
70
+
71
+ import { clamp, ease, lerp, named, prog } from "./anim.js";
72
+
73
+ /** @typedef {import("./anim.js").Ease} Ease */
74
+ /** @typedef {{ x: number, y: number, w: number, h: number }} Rect in frame px */
75
+ /** @typedef {{ width: number, height: number }} View */
76
+ /**
77
+ * @typedef {object} Pose where a layer is drawn, against its place at rest
78
+ * @property {number} x @property {number} y translation (px)
79
+ * @property {number} s scale
80
+ * @property {number} [r] rotation (deg)
81
+ * @property {number} [ry] turned about its vertical axis (deg)
82
+ * @property {number} [blur] px
83
+ * @property {number} [opacity]
84
+ * @property {boolean} [visible]
85
+ * @property {string} css its CSS transform
86
+ * @property {string} origin the transform-origin `css` is written for
87
+ * @property {{ px: number, view: View, ground?: string }} [cover] a scene's ground kept this far past
88
+ * its edge while it is carried (momentumCut); `apply` paints it
89
+ */
90
+ /** @typedef {Cam | ((t: number) => Cam)} CamFrom a camera, or one read from film time (still moving) */
91
+ /** @typedef {Record<string, number>} Cam a camera pose, e.g. anim.js cam2d's { x, y, s } (`s` mixes in log space) */
92
+
93
+ const FRAME = { width: 1920, height: 1080 };
94
+
95
+ /** the rate the film is drawn at: what `film render` tells the page, else 60 */
96
+ const filmFps = () => {
97
+ const f = /** @type {{ __filmFps?: number }} */ (globalThis).__filmFps;
98
+ return typeof f === "number" && f > 0 ? f : 60;
99
+ };
100
+ /** the frame t falls in, at fps @param {number} t @param {number} fps */
101
+ const frameOf = (t, fps) => Math.round(t * fps + 1e-9);
102
+ /** t is in the frame `at` falls in, or later @param {number} t @param {number} at @param {number} fps */
103
+ const crossed = (t, at, fps) => frameOf(t, fps) >= frameOf(at, fps);
104
+ const f3 = (/** @type {number} */ v) => +v.toFixed(3);
105
+
106
+ /**
107
+ * An ease run on past its ends for the half frame of shutter on either side
108
+ * of a cut: past 1 at the speed of its last frame, below 0 at the speed of
109
+ * its first, so the frame on each side of the cut is smeared by a move that
110
+ * is still going, not by one that stopped at the frame's own time.
111
+ * @param {Ease} f @param {number} u @param {number} h one frame, as a share of the move
112
+ */
113
+ function carried(f, u, h) {
114
+ const k = Math.min(1, Math.max(1e-6, h));
115
+ if (u > 1) return 1 + ((f(1) - f(1 - k)) / k) * (u - 1);
116
+ if (u < 0) return ((f(k) - f(0)) / k) * u;
117
+ return f(u);
118
+ }
119
+
120
+ /** a rect with a size, or a plain error naming the move @param {string} who @param {string} what @param {Rect} r */
121
+ function sized(who, what, r) {
122
+ if (!(r && r.w > 0 && r.h > 0))
123
+ throw new Error(`moves: ${who}'s ${what} needs a width and height above 0 (got ${JSON.stringify(r)})`);
124
+ }
125
+
126
+ /**
127
+ * A pose with its CSS. origin "0 0" or "50% 50%".
128
+ * @param {{ x?: number, y?: number, s?: number, r?: number, ry?: number, blur?: number, opacity?: number, visible?: boolean, perspective?: number }} p
129
+ * @param {string} [origin]
130
+ * @returns {Pose}
131
+ */
132
+ function pose(p, origin = "50% 50%") {
133
+ const { x = 0, y = 0, s = 1, r = 0, ry = 0, perspective = 2000 } = p;
134
+ let css = `translate(${f3(x)}px, ${f3(y)}px)`;
135
+ if (ry) css += ` perspective(${perspective}px) rotateY(${f3(ry)}deg)`;
136
+ css += ` scale(${+s.toFixed(5)})`;
137
+ if (r) css += ` rotate(${f3(r)}deg)`;
138
+ /** @type {Pose} */
139
+ const out = { x, y, s, css, origin };
140
+ if (r) out.r = r;
141
+ if (ry) out.ry = ry;
142
+ if (p.blur != null) out.blur = p.blur;
143
+ if (p.opacity != null) out.opacity = p.opacity;
144
+ if (p.visible != null) out.visible = p.visible;
145
+ return out;
146
+ }
147
+
148
+ /**
149
+ * Write a pose onto an element: its transform and transform-origin, and its
150
+ * opacity, blur and visibility when the pose has them. A pose that is
151
+ * visible shows the element whenever its parent shows, whatever the
152
+ * stylesheet says (a later scene hidden in CSS until its cut comes in); one
153
+ * that is not hides it.
154
+ * `apply(desk, hop.desk); apply(next, hop.to);`
155
+ * @param {Element} el @param {Pose} p
156
+ */
157
+ export function apply(el, p) {
158
+ const st = /** @type {HTMLElement} */ (el).style;
159
+ st.transform = p.css;
160
+ st.transformOrigin = p.origin;
161
+ if (p.opacity != null) st.opacity = String(p.opacity);
162
+ if (p.blur != null) st.filter = p.blur > 0.01 ? `blur(${f3(p.blur)}px)` : "none";
163
+ // shown as its parent is: "inherit" overrides a stylesheet's "hidden" yet
164
+ // stays hidden inside a scene that is hidden ("visible" would show it there)
165
+ if (p.visible != null) st.visibility = p.visible ? "inherit" : "hidden";
166
+ // a ground painted for a cut is taken off by the next pose without one
167
+ if (p.cover) ground(/** @type {HTMLElement} */ (el), p, p.cover);
168
+ else unground(/** @type {HTMLElement} */ (el));
169
+ }
170
+
171
+ /** take off the ground `apply` painted past an element's edge, if it did @param {HTMLElement} el */
172
+ function unground(el) {
173
+ if (el.dataset?.movesGround !== "1") return;
174
+ el.style.boxShadow = "";
175
+ delete el.dataset.movesGround;
176
+ }
177
+
178
+ /**
179
+ * A scene carried off its place keeps its ground past its edge: an element
180
+ * that covers the frame and paints one flat colour of its own has that
181
+ * colour painted `px` further out on every side (a box-shadow: nothing is
182
+ * laid out again, and the frame clips it); one that is, or is backed by, a
183
+ * picture or a gradient is drawn larger about its middle by just what the
184
+ * move uncovers; one that paints nothing of its own, or is smaller than the
185
+ * frame (a card, a title), is left alone — what shows past it does not move.
186
+ * @param {HTMLElement} el @param {Pose} p @param {{ px: number, view: View, ground?: string }} c
187
+ */
188
+ function ground(el, p, c) {
189
+ const st = el.style;
190
+ const clear = () => unground(el);
191
+ const w = el.offsetWidth, h = el.offsetHeight;
192
+ if (!(c.px > 0) || w < c.view.width - 1 || h < c.view.height - 1) return clear();
193
+ let colour = c.ground;
194
+ if (!colour) {
195
+ const cs = getComputedStyle(el);
196
+ const flat = cs.backgroundColor;
197
+ const picture = cs.backgroundImage !== "none" || /^(img|video|canvas)$/i.test(el.tagName);
198
+ if (picture) {
199
+ clear();
200
+ st.transform = `${p.css} scale(${(1 + 2 * Math.max(Math.abs(p.x) / w, Math.abs(p.y) / h)).toFixed(5)})`;
201
+ return;
202
+ }
203
+ if (!flat || flat === "transparent" || /,\s*0\)$/.test(flat)) return clear();
204
+ colour = flat;
205
+ }
206
+ st.boxShadow = `0 0 0 ${Math.ceil(c.px)}px ${colour}`;
207
+ el.dataset.movesGround = "1";
208
+ }
209
+
210
+ /**
211
+ * A curve through measured points [[u, v], …] (u and v both 0 → 1),
212
+ * monotone between them (Fritsch–Carlson), so a measured move is replayed
213
+ * through its own frames without wiggles of its own.
214
+ * @param {[number, number][]} pts @returns {Ease}
215
+ */
216
+ function measured(pts) {
217
+ const n = pts.length;
218
+ const xs = pts.map((p) => p[0]);
219
+ const ys = pts.map((p) => p[1]);
220
+ const d = [];
221
+ for (let i = 0; i < n - 1; i++) d.push((/** @type {number} */ (ys[i + 1]) - /** @type {number} */ (ys[i])) / (/** @type {number} */ (xs[i + 1]) - /** @type {number} */ (xs[i])));
222
+ const m = new Array(n).fill(0);
223
+ m[0] = d[0];
224
+ m[n - 1] = d[n - 2];
225
+ for (let i = 1; i < n - 1; i++) {
226
+ const a = /** @type {number} */ (d[i - 1]), b = /** @type {number} */ (d[i]);
227
+ m[i] = a * b <= 0 ? 0 : (2 * a * b) / (a + b);
228
+ }
229
+ return (u) => {
230
+ if (u <= /** @type {number} */ (xs[0])) return /** @type {number} */ (ys[0]);
231
+ if (u >= /** @type {number} */ (xs[n - 1])) return /** @type {number} */ (ys[n - 1]);
232
+ let i = 0;
233
+ while (u > /** @type {number} */ (xs[i + 1])) i++;
234
+ const x0 = /** @type {number} */ (xs[i]), x1 = /** @type {number} */ (xs[i + 1]);
235
+ const h = x1 - x0, q = (u - x0) / h;
236
+ const y0 = /** @type {number} */ (ys[i]), y1 = /** @type {number} */ (ys[i + 1]);
237
+ const q2 = q * q, q3 = q2 * q;
238
+ return (2 * q3 - 3 * q2 + 1) * y0 + (q3 - 2 * q2 + q) * h * m[i] + (-2 * q3 + 3 * q2) * y1 + (q3 - q2) * h * m[i + 1];
239
+ };
240
+ }
241
+
242
+ /** a direction's unit step @param {"up" | "down" | "left" | "right"} dir @returns {[number, number]} */
243
+ const unit = (dir) => (dir === "up" ? [0, -1] : dir === "down" ? [0, 1] : dir === "left" ? [-1, 0] : [1, 0]);
244
+ /** @param {Rect} r */
245
+ const mid = (r) => [r.x + r.w / 2, r.y + r.h / 2];
246
+
247
+ /** a camera at t: as given, or read from film time @param {CamFrom} c @param {number} t @param {string} who @returns {Cam} */
248
+ function camAt(c, t, who) {
249
+ const cam = typeof c === "function" ? c(t) : c;
250
+ if (!(cam && Number.isFinite(cam.x) && Number.isFinite(cam.y) && /** @type {number} */ (cam.s) > 0))
251
+ throw new Error(`moves: ${who}'s camera is { x, y, s } with s above 0 (got ${JSON.stringify(cam)})`);
252
+ return cam;
253
+ }
254
+
255
+ /**
256
+ * Time since a move began, started from rest: it lags the clock by `soft` s
257
+ * once under way and has no speed at 0, so a move laid over a camera that
258
+ * is still moving adds none of its own in its first instant.
259
+ * @param {number} tau @param {number} soft
260
+ */
261
+ const fromRest = (tau, soft) => (tau <= 0 ? 0 : soft > 0 ? tau - soft * (1 - Math.exp(-tau / soft)) : tau);
262
+
263
+ /**
264
+ * The camera a layer's pose amounts to (origin 0 0: a point p of the layer
265
+ * drawn at (x, y) + s·p), when that layer is already seen through the camera
266
+ * `f` (none: the layer at rest fills the frame).
267
+ * @param {number} x @param {number} y @param {number} s @param {View} view @param {Cam | null} [f] @returns {Cam}
268
+ */
269
+ function camOf(x, y, s, view, f) {
270
+ const S = s * /** @type {number} */ (f?.s ?? 1);
271
+ return {
272
+ x: /** @type {number} */ (f?.x ?? view.width / 2) + (view.width / 2 - x - (s * view.width) / 2) / S,
273
+ y: /** @type {number} */ (f?.y ?? view.height / 2) + (view.height / 2 - y - (s * view.height) / 2) / S,
274
+ s: S,
275
+ };
276
+ }
277
+
278
+ /**
279
+ * A camera { x, y, s } (anim.js cam2d's: the world point at the frame's
280
+ * centre, and the scale) as the pose of the world's layer, origin 0 0 — what
281
+ * `cam2d(cam).css` writes, for `apply` and for the moves here that give a
282
+ * camera back.
283
+ * `apply(world, camPose(stations(t, list)))`
284
+ * @param {Cam} cam @param {View} [view] @returns {Pose}
285
+ */
286
+ export function camPose(cam, view = FRAME) {
287
+ const s = /** @type {number} */ (cam.s);
288
+ return pose({ x: view.width / 2 - /** @type {number} */ (cam.x) * s, y: view.height / 2 - /** @type {number} */ (cam.y) * s, s }, "0 0");
289
+ }
290
+
291
+ // --- a window hop ---------------------------------------------------------------
292
+
293
+ // Flying-machine film, 31.50–32.20 s (30 fps, 1276 wide), pulling out of a
294
+ // window that filled the frame onto the desk it sits on: the window's width
295
+ // 1276 → 1185 → 680 → 515 px in 0.7 s, slow to start, three frames fastest,
296
+ // ten frames settling. As [s after the start, the view's scale], read back
297
+ // to log progress below.
298
+ const HOP_PULL = [[0, 2.47], [0.233, 2.3], [0.333, 1.357], [0.367, 1.253], [0.4, 1.174], [0.433, 1.095], [0.467, 1.076], [0.5, 1.057], [0.567, 1.035], [0.633, 1.011], [0.7, 1]];
299
+ // …then (flying-machine film, 32.53–33.23 s) the next window lifting toward
300
+ // the lens: 430 → 470 → 660 → 780 → 1135 px → the whole frame in 0.67 s,
301
+ // fastest late (one step ×1.45), while the desk scaled 0.99–1.04 and only
302
+ // slid, about −50 px, carried out at ~40 px a frame in the last 5 frames.
303
+ const HOP_LIFT = [[0, 1], [0.07, 1.093], [0.27, 1.535], [0.403, 1.814], [0.47, 2.64], [0.67, 3.06]];
304
+ const hopPull = measured(/** @type {[number, number][]} */ (HOP_PULL.map(([t, s]) => [/** @type {number} */ (t) / 0.7, 1 - Math.log(/** @type {number} */ (s)) / Math.log(2.47)])));
305
+ const hopLift = measured(/** @type {[number, number][]} */ (HOP_LIFT.map(([t, s]) => [/** @type {number} */ (t) / 0.67, Math.log(/** @type {number} */ (s)) / Math.log(3.06)])));
306
+
307
+ /**
308
+ * Out of one window and into the next across a desk, as layers: the camera
309
+ * pulls back from `from` (filling the frame) until the desk is at rest
310
+ * (`pull` s), holds `hold` s, then `to` lifts toward the lens until it fills
311
+ * the frame (`lift` s) while the desk scales at most `deskScale` and slides
312
+ * `pan` px toward where `to` was, carried a further `out` px in the last
313
+ * frames. Measured on the flying-machine film, 31.50–33.23 s: pull 0.7 s,
314
+ * hold 0.33 s, lift 0.67 s; the desk 0.99–1.04 while the window grew 3×. A
315
+ * zoom of the whole desk instead scaled it 1.8×, and read as a zoom, not a
316
+ * window coming forward.
317
+ * `from` is the window the pull starts in, filling the frame — or, when the
318
+ * take was not framed on one, the camera it is on: { x, y, s } over the
319
+ * desk's layout, or a function of t for one still moving (`(t) =>
320
+ * stations(t, list)`). The pull then starts where that camera is and at its
321
+ * speed: it is read at every t, what is left of its move carries on under
322
+ * the pull, and the pull itself starts from rest over `soft` s (so it ends
323
+ * that much into the hold; keep `hold` longer than `soft`). Before t0 `desk`
324
+ * is that camera's own pose, so one `apply(desk, h.desk)` serves the whole
325
+ * take. A window's rect can match a moving camera's place at t0 but not its
326
+ * speed: the picture stops dead for a frame, then starts again.
327
+ * The desk is an element at 0, 0 the size of the view (the frame), its
328
+ * transform-origin 0 0; lay the windows out inside it at their places at
329
+ * rest, `to` above the others, and give `from` and `to` as those places
330
+ * (the desk's own layout, which is frame px while the desk is unmoved).
331
+ * `desk` is for the desk, `to` for the lifting window (its own centre), the
332
+ * others ride the desk. The lift, from `lifts` to `end`, is a picture jump
333
+ * to the render report: declare it, `tl.segment(h.lifts, h.end, { handoff:
334
+ * "lift" })`. Once it has lifted (`end`), the next scene can take over from
335
+ * the window filling the frame.
336
+ * `const h = windowHop(t, 2, editorBox, simBox); apply(desk, h.desk); apply(sim, h.to);`
337
+ * `const h = windowHop(t, T.hop, (t) => stations(t, tour, { from: cam0 }), simBox); apply(desk, h.desk); apply(sim, h.to);`
338
+ * @param {number} t @param {number} t0 the pull starts
339
+ * @param {Rect | CamFrom} from @param {Rect} to in the desk's layout, frame px
340
+ * @param {{ view?: View, pull?: number, hold?: number, lift?: number, fill?: number, grow?: number,
341
+ * deskScale?: number, pan?: number, out?: number, outDur?: number, soft?: number }} [o]
342
+ * fill: the view's scale at the start (default: `from` as wide as the frame; a camera's own s); grow:
343
+ * `to`'s scale at the end (default: filling the frame); soft: how long the pull takes to get under
344
+ * way over a camera still moving (default 2 frames of 24: 0.083 s; a camera at rest, or a window: 0)
345
+ * @returns {{ desk: Pose, to: Pose, phase: "before" | "pull" | "hold" | "lift" | "done", p: number, lifts: number, end: number }}
346
+ */
347
+ export function windowHop(t, t0, from, to, o = {}) {
348
+ const view = o.view ?? FRAME;
349
+ const moving = typeof from === "function";
350
+ // a window has a width; a camera has a scale
351
+ const cam = moving || !("w" in from) ? camAt(/** @type {CamFrom} */ (from), t, "windowHop") : null;
352
+ if (!cam) sized("windowHop", "from", /** @type {Rect} */ (from));
353
+ sized("windowHop", "to", to);
354
+ const { pull = 0.7, hold = 0.33, lift = 0.67, deskScale = 1.04, pan = 75, out = 300, outDur = 5 / 30 } = o;
355
+ const soft = moving ? (o.soft ?? 2 / 24) : 0;
356
+ const fill = cam ? /** @type {number} */ (cam.s) : (o.fill ?? view.width / /** @type {Rect} */ (from).w);
357
+ const grow = o.grow ?? Math.max(view.width / to.w, view.height / to.h);
358
+ const vc = [view.width / 2, view.height / 2];
359
+ const fc = cam ? [cam.x, cam.y] : mid(/** @type {Rect} */ (from)), tc = mid(to);
360
+ const b = t0 + pull, c = b + hold, d = c + lift;
361
+ const phase = t < t0 ? "before" : t < b ? "pull" : t < c ? "hold" : t < d ? "lift" : "done";
362
+ const still = pose({}, "50% 50%");
363
+ if (t < c) {
364
+ const e = hopPull(pull > 0 ? clamp(fromRest(t - t0, soft) / pull) : t >= t0 ? 1 : 0);
365
+ const S = fill ** (1 - e);
366
+ const cx = lerp(/** @type {number} */ (vc[0]), /** @type {number} */ (fc[0]), e);
367
+ const cy = lerp(/** @type {number} */ (vc[1]), /** @type {number} */ (fc[1]), e);
368
+ return {
369
+ desk: pose({ x: cx - /** @type {number} */ (fc[0]) * S, y: cy - /** @type {number} */ (fc[1]) * S, s: S }, "0 0"),
370
+ to: still,
371
+ phase,
372
+ p: e,
373
+ lifts: c,
374
+ end: d,
375
+ };
376
+ }
377
+ const q = hopLift(prog(t, c, d));
378
+ const ds = 1 + (deskScale - 1) * q;
379
+ const dx = /** @type {number} */ (vc[0]) - /** @type {number} */ (tc[0]), dy = /** @type {number} */ (vc[1]) - /** @type {number} */ (tc[1]);
380
+ const len = Math.hypot(dx, dy);
381
+ const [ux, uy] = len > 1e-6 ? [dx / len, dy / len] : [0, 0];
382
+ const slide = pan * q + out * prog(t, d - outDur, d);
383
+ const X = /** @type {number} */ (vc[0]) * (1 - ds) + ux * slide;
384
+ const Y = /** @type {number} */ (vc[1]) * (1 - ds) + uy * slide;
385
+ // the window: its centre to the frame's, its size `grow` on screen — written
386
+ // inside the desk, so the desk's own move is taken out
387
+ const Tx = lerp(/** @type {number} */ (tc[0]), /** @type {number} */ (vc[0]), q);
388
+ const Ty = lerp(/** @type {number} */ (tc[1]), /** @type {number} */ (vc[1]), q);
389
+ const sT = grow ** q;
390
+ return {
391
+ desk: pose({ x: X, y: Y, s: ds }, "0 0"),
392
+ to: pose({ x: (Tx - X) / ds - /** @type {number} */ (tc[0]), y: (Ty - Y) / ds - /** @type {number} */ (tc[1]), s: sT / ds }, "50% 50%"),
393
+ phase,
394
+ p: q,
395
+ lifts: c,
396
+ end: d,
397
+ };
398
+ }
399
+
400
+ // --- pulling back into space, and stations --------------------------------------
401
+
402
+ // Game film, 46.167–46.75 s (24 fps): the plane's width, share of the
403
+ // frame's, frame by frame from the full frame — nearly even on screen, the
404
+ // camera's distance speeding up.
405
+ const REVEAL = [1, 0.95, 0.892, 0.845, 0.797, 0.761, 0.722, 0.678, 0.642, 0.619, 0.578, 0.547, 0.527, 0.495, 0.472];
406
+ const reveal = measured(/** @type {[number, number][]} */ (REVEAL.map((w, i) => [i / 14, (1 - w) / (1 - 0.472)])));
407
+
408
+ /**
409
+ * The whole frame pulls back into a plane in space: its width shrinking at
410
+ * a nearly even rate on screen (the camera's distance speeding up), its
411
+ * centre sliding to `at`, then drifting on, slower and slower. Measured on
412
+ * the game film, 46.167–47.2 s (24 fps): 1.0 → 0.47 of the frame's width in
413
+ * 14 frames, about 0.037 a frame, replayed here frame by frame; the centre
414
+ * 0.50 → 0.68 W; then about 0.017 W a frame. A pull at an even distance
415
+ * instead runs ahead early (0.08 W off in six frames). The drift starts at
416
+ * `drift` and fades over `tau` as a share of the width left, so the plane
417
+ * shrinks toward `rest` (about 0.21 W by default) and never through
418
+ * nothing. `yaw` turns the plane by up to that many degrees on the way (the
419
+ * parent needs no perspective of its own: `css` carries it).
420
+ * Returns the pose of a frame-sized layer (origin its centre), `cam` — the
421
+ * same as a camera for anim.js cam2d over a world whose plane fills the
422
+ * frame (for stations' `from`) — and `rest`, where the drift ends.
423
+ * `from`: the camera the take is on when the pull starts — { x, y, s } over
424
+ * the world, or a function of t for one still moving (`(t) => stations(t,
425
+ * list)`). `cam` and `rest` are then cameras over that world, the pull laid
426
+ * over what the camera was doing: write `cam` onto the world's one element
427
+ * (`apply(world, camPose(r.cam))`) and leave the pose be. Over a moving
428
+ * camera the pull starts from rest over `soft` s, and so runs that much
429
+ * behind the measured frames; what is left of the camera's own move carries
430
+ * on under it.
431
+ * `const r = pullbackReveal(t, 4); apply(screen, r);`
432
+ * `const r = pullbackReveal(t, T.back, { from: (t) => stations(t, tour) }); apply(world, camPose(r.cam));`
433
+ * @param {number} t @param {number} t0
434
+ * @param {{ view?: View, dur?: number, to?: number, at?: [number, number], drift?: number, tau?: number, yaw?: number,
435
+ * from?: CamFrom, soft?: number }} [o]
436
+ * to: its width at the end, share of the frame's (above 0, below 1); at: its centre then, shares of the
437
+ * frame; drift: share of the frame's width a second, after; tau: how long the drift takes to fade (s);
438
+ * soft: how long the pull takes to get under way over a camera still moving (default 2 frames of 24)
439
+ * @returns {Pose & { cam: Cam, rest: Cam, p: number }}
440
+ */
441
+ export function pullbackReveal(t, t0, o = {}) {
442
+ const view = o.view ?? FRAME;
443
+ const { dur = 14 / 24, to = 0.47, at = [0.68, 0.5], drift = 0.42, tau = 0.9, yaw = 0 } = o;
444
+ if (!(to > 0 && to < 1))
445
+ throw new Error(`moves: pullbackReveal's \`to\` is the plane's width at the end, a share of the frame's above 0 and below 1 (got ${to})`);
446
+ const W = view.width, H = view.height;
447
+ const f = o.from ? camAt(o.from, t, "pullbackReveal") : null;
448
+ const tau0 = typeof o.from === "function" && t > t0 ? fromRest(t - t0, o.soft ?? 2 / 24) : t - t0;
449
+ // after the pull, the width falls at `drift` a second at first, the fall
450
+ // fading over `tau` and taken out of what is left: it never reaches 0
451
+ const left = (/** @type {number} */ x) => (tau > 0 ? to * Math.exp(-(drift / to) * tau * (1 - Math.exp(-x / tau))) : to);
452
+ const sAt = (/** @type {number} */ x) => (x <= dur ? 1 - (1 - to) * reveal(clamp(x / dur)) : left(x - dur));
453
+ const place = (/** @type {number} */ s) => {
454
+ const k = (1 - s) / (1 - to);
455
+ const cx = (0.5 + (at[0] - 0.5) * k) * W, cy = (0.5 + (at[1] - 0.5) * k) * H;
456
+ // the plane drawn at its centre (cx, cy), scaled s about it: as a layer's pose, and the camera it amounts to
457
+ return { cx, cy, k, cam: camOf(cx - (s * W) / 2, cy - (s * H) / 2, s, view, f) };
458
+ };
459
+ const s = sAt(Math.max(0, tau0));
460
+ const { cx, cy, k, cam } = place(s);
461
+ const rest = place(left(Infinity)).cam;
462
+ return {
463
+ ...pose({ x: cx - W / 2, y: cy - H / 2, s, ry: yaw * Math.min(1, k) }, "50% 50%"),
464
+ cam,
465
+ rest,
466
+ p: clamp(tau0 / dur),
467
+ };
468
+ }
469
+
470
+ /**
471
+ * The camera that frames `rect` the way the game film's stations did
472
+ * (50.54, 52.63, 55.0 s): centred, the rect `share` of the frame's width
473
+ * (three panels landed at 0.635 W, 810, 814 and 809 px of 1276). A camera
474
+ * for anim.js cam2d: { x, y, s }.
475
+ * `stations(t, [{ t: 6, at: station(panelA) }, { t: 7.2, at: station(panelB) }], { from: cam0 })`
476
+ * @param {Rect} rect @param {{ share?: number, view?: View }} [o] @returns {Cam}
477
+ */
478
+ export function station(rect, { share = 0.635, view = FRAME } = {}) {
479
+ const [x, y] = mid(rect);
480
+ return { x: /** @type {number} */ (x), y: /** @type {number} */ (y), s: (share * view.width) / rect.w };
481
+ }
482
+
483
+ // Fly film, the tilted map, 39.25–44.25 s (24 fps, five stations): a leg
484
+ // speeds up for 5–6 frames, slows for 10–12 at about ×0.73 a frame from a
485
+ // peak of 110–187 px a frame, then the station is held 3–8 frames at 0.1–0.5
486
+ // px a frame and left; stations 0.75–1.08 s apart. Slowing by ×0.73 a frame
487
+ // for ever does not land in that time: from 150 px a frame it is still at
488
+ // 4.7 after 11 frames and reaches 0.5 only after 18, later than the next
489
+ // station leaves. So the slowing here ends: ×0.73 a frame at first, done in
490
+ // SETTLE, and CREEP of the leg is kept back for a slow drift on (losing
491
+ // CREEP_KEEP of its speed a frame), which from that peak is 0.4 px a frame
492
+ // as the leg lands and 0.15 eight frames on.
493
+ const ACCEL = 5.5 / 24;
494
+ const DECAY = 0.73;
495
+ const SETTLE = 11 / 24;
496
+ const CREEP = 0.02;
497
+ const CREEP_KEEP = 0.885;
498
+
499
+ /** progress of a move τ s after it leaves: speed rising over `ta` s, then falling at rate `lam` /s to nothing
500
+ * `td` s later (Infinity: for ever)
501
+ * @param {number} tau @param {number} ta @param {number} lam @param {number} td */
502
+ function legTo(tau, ta, lam, td) {
503
+ if (tau <= 0) return 0;
504
+ const ends = Number.isFinite(td);
505
+ const floor = ends ? Math.exp(-lam * td) : 0;
506
+ // ∫ of the fall, its speed 1 at 0 and 0 at td
507
+ const fall = (/** @type {number} */ x) => (floor < 1 ? ((1 - Math.exp(-lam * x)) / lam - floor * x) / (1 - floor) : 0);
508
+ const total = ta / 2 + (ends ? fall(td) : 1 / lam);
509
+ if (!(total > 0)) return 1;
510
+ if (tau < ta) return (tau / 2 - (ta / (2 * Math.PI)) * Math.sin((Math.PI * tau) / ta)) / total;
511
+ return (ta / 2 + fall(Math.min(tau - ta, td))) / total;
512
+ }
513
+
514
+ /** progress of one leg τ s after it leaves: the move, and the share of it kept back to creep on
515
+ * @param {number} tau @param {number} ta @param {number} lam @param {number} td @param {number} creep */
516
+ const leg = (tau, ta, lam, td, creep) =>
517
+ (1 - creep) * legTo(tau, ta, lam, td) + (creep > 0 ? creep * legTo(tau, ta, -Math.log(CREEP_KEEP) * 24, Infinity) : 0);
518
+
519
+ /**
520
+ * A camera from station to station: list = [{ t, at }], each leaving for
521
+ * `at` (a camera: anim.js cam2d's { x, y, s }, or any flat object of
522
+ * numbers; `s` mixes in log space) at its t. Each leg speeds up over
523
+ * `accel` s, slows by `decay` of its speed every 1/24 s at first and is
524
+ * down to a creep `settle` s after its fastest frame, then drifts on, slower
525
+ * and slower, until the next leaves: short to leave, longer to arrive, never
526
+ * quite still, and what is left of one leg is still moving when the next
527
+ * leaves. Measured on the fly film's tilted map, 39.25–44.25 s, five
528
+ * stations: speeding up 5–6 frames, slowing 10–12 frames at about ×0.73 a
529
+ * frame, a station held 3–8 frames at 0.1–0.5 px a frame, then off again;
530
+ * stations 0.75–1.08 s apart. So a leg takes about 0.69 s (16.5 frames) and
531
+ * a station list written 0.8–1.0 s apart moves for most of its time; one
532
+ * written 1.5 s apart sits at a creep for half of it (`stationTimes` gives
533
+ * each leg's landing and how long its station is held). `decay` is the share
534
+ * of its speed a leg keeps every 1/24 s, above 0 and below 1: nearer 1 it
535
+ * slows more evenly over the same `settle`. `creep` is the share of the leg
536
+ * left to the drift (0: it stops dead when it lands); `settle: Infinity`
537
+ * with `creep: 0` slows by `decay` for ever. `from`: where the camera is
538
+ * before the first leg — a camera, or a function of t (pullbackReveal's or
539
+ * rampJump's `cam`, still moving), which the first leg leaves from without a
540
+ * jolt. The camera it returns is what windowHop's and pullbackReveal's
541
+ * `from` take, as `(t) => stations(t, list, o)`, to leave the tour on.
542
+ * `const cam = cam2d(stations(t, [{ t: 6, at: station(a) }, { t: 6.9, at: station(b) }], { from: (t) => pullbackReveal(t, 5).cam }))`
543
+ * @param {number} t
544
+ * @param {{ t: number, at: Cam, accel?: number, decay?: number, settle?: number, creep?: number }[]} list in time order
545
+ * @param {{ from?: CamFrom, accel?: number, decay?: number, settle?: number, creep?: number }} [o]
546
+ * @returns {Cam & { leg: number }} leg: the last one to leave (−1 before the first)
547
+ */
548
+ export function stations(t, list, o = {}) {
549
+ const { accel = ACCEL, decay = DECAY, settle = SETTLE, creep = CREEP } = o;
550
+ const from = o.from ?? /** @type {{ at: Cam }} */ (list[0]).at;
551
+ const base = typeof from === "function" ? from(t) : from;
552
+ /** @type {Record<string, number>} */
553
+ const cam = { ...base };
554
+ /** @type {Cam} */
555
+ let prev = base;
556
+ let last = -1;
557
+ for (let i = 0; i < list.length; i++) {
558
+ const st = /** @type {{ t: number, at: Cam, accel?: number, decay?: number, settle?: number, creep?: number }} */ (list[i]);
559
+ const keep = st.decay ?? decay;
560
+ if (!(keep > 0 && keep < 1))
561
+ throw new Error(`moves: stations' decay is the share of its speed a leg keeps every 1/24 s, above 0 and below 1 (got ${keep})`);
562
+ const lam = -Math.log(keep) * 24;
563
+ const k = leg(t - st.t, st.accel ?? accel, lam, Math.max(0, st.settle ?? settle), clamp(st.creep ?? creep));
564
+ if (t >= st.t) last = i;
565
+ for (const key of Object.keys(st.at)) {
566
+ // the first leg mixes from where the camera is now (a moving start is
567
+ // left smoothly); each later one adds its own step on top of the last
568
+ const a = /** @type {number} */ (prev[key] ?? st.at[key]), b = /** @type {number} */ (st.at[key]);
569
+ const c = i === 0 ? a : (cam[key] ?? a);
570
+ if (key === "s" && a > 0 && b > 0) cam[key] = c * (b / a) ** k;
571
+ else cam[key] = c + (b - a) * k;
572
+ }
573
+ prev = st.at;
574
+ }
575
+ return { ...cam, leg: last };
576
+ }
577
+
578
+ /**
579
+ * When each leg of a station list is fastest and when it has landed (down
580
+ * to its creep), and how long its station is then held before the next
581
+ * leaves — the measured tour held each 3–8 frames of 24 (0.125–0.33 s).
582
+ * A hold below 0: the next leg leaves before this one has landed.
583
+ * `stationTimes(tour).map((s) => s.held)`
584
+ * @param {{ t: number, accel?: number, settle?: number }[]} list
585
+ * @param {{ accel?: number, settle?: number }} [o]
586
+ * @returns {{ t: number, peak: number, lands: number, held: number }[]} held: Infinity for the last
587
+ */
588
+ export function stationTimes(list, o = {}) {
589
+ const { accel = ACCEL, settle = SETTLE } = o;
590
+ return list.map((st, i) => {
591
+ const peak = st.t + (st.accel ?? accel);
592
+ const lands = peak + (st.settle ?? settle);
593
+ const next = list[i + 1];
594
+ return { t: st.t, peak, lands, held: next ? next.t - lands : Infinity };
595
+ });
596
+ }
597
+
598
+ // --- cuts in motion --------------------------------------------------------------
599
+
600
+ /**
601
+ * Leave faster every frame and cut on the fastest; the next shot carries on
602
+ * the same way from behind its place and slows into it. Measured on the
603
+ * flying-machine film, 3.033–3.567 s (30 fps, 718 px tall): the title card
604
+ * left 85 px up in 8 frames (cubic-bezier(0.775, 0, 0.975, 1), ease.leave),
605
+ * cut on its fastest frame at 3.300; the next began 57 px below its place
606
+ * and slowed into it in 8 frames (cubic-bezier(0.275, 0.8, 0.675, 1),
607
+ * ease.resume), −17.7 → −0.5 px a frame. Here 128 and 86 px of a 1080
608
+ * frame; the way out reaches `out` on the last frame drawn before the cut,
609
+ * so its largest step is seen, and runs on at that step's speed until the
610
+ * cut, so that frame's shutter smears all of it; the next shot runs at its
611
+ * first step's speed from the cut to its first frame. `a` is the shot
612
+ * leaving, `b` the next, each at its place at rest; each is visible on its
613
+ * side of the cut.
614
+ * A whole scene carried 128 px off its place uncovers a strip that wide at
615
+ * the edge it leaves (the reel's card moved over a ground that did not).
616
+ * `cover` says what fills it, and `apply` does it: "ground" (the default) —
617
+ * a scene that covers the frame and paints one flat colour has that colour
618
+ * painted past its edge, as far as it has moved (`ground`: the colour, when
619
+ * the scene's own is not the one to use, or it paints a gradient whose edge
620
+ * colour you name); a scene that is or is backed by a picture, a gradient
621
+ * or a canvas is drawn larger about its middle by just what the move
622
+ * uncovers (1.24× at the cut for 128 px of 1080, back to 1 as it lands);
623
+ * anything smaller than the frame — a card, a title — is left as it is.
624
+ * "scale" draws every scene larger that way, and the pose's `s` and `css`
625
+ * say so; false leaves the edge to you (a scene laid out larger than the
626
+ * frame, or a ground behind both that does not move). The painted ground is
627
+ * a box-shadow on the scene's element: a clip-path or `contain: paint` on
628
+ * that element cuts it off. It is written by `apply` and taken off by
629
+ * `apply` — when the scene is hidden, when it has landed, or by any later
630
+ * pose — so keep applying the cut's poses until `b` is back on its place
631
+ * (`inDur`, 0.27 s); a film that stops part way leaves the last of it
632
+ * painted, and a frame then depends on the ones drawn before it.
633
+ * `const m = momentumCut(t, 3.3, { dir: "up" }); apply(title, m.a); apply(list, m.b); tl.event(m.cutAt, "cut");`
634
+ * @param {number} t @param {number} at the cut
635
+ * @param {{ dir?: "up" | "down" | "left" | "right", out?: number, outDur?: number, in?: number, inDur?: number,
636
+ * leave?: Ease | string, resume?: Ease | string, fps?: number, cover?: "ground" | "scale" | false,
637
+ * ground?: string | [string, string], view?: View }} [o]
638
+ * ground: a CSS colour for both scenes, or [a's, b's]
639
+ * @returns {{ a: Pose, b: Pose, cutAt: number, p: number }}
640
+ */
641
+ export function momentumCut(t, at, o = {}) {
642
+ const { dir = "up", out = 128, outDur = 8 / 30, inDur = 8 / 30, fps = filmFps() } = o;
643
+ const inn = o.in ?? 86;
644
+ const [ux, uy] = unit(dir);
645
+ const after = crossed(t, at, fps);
646
+ const cutAt = frameOf(at, fps) / fps;
647
+ // the way out ends on the last frame drawn before the cut: its fastest step
648
+ // is seen; through the half frame to the cut it carries on at that speed
649
+ const lastA = cutAt - 1 / fps;
650
+ const half = 0.5 / fps;
651
+ const ua = outDur > 0 ? clamp((t - lastA + outDur) / outDur, 0, 1 + half / outDur) : t >= lastA ? 1 : 0;
652
+ const ub = inDur > 0 ? clamp((t - cutAt) / inDur, -half / inDur, 1) : t >= cutAt ? 1 : 0;
653
+ const ea = carried(named(o.leave ?? "leave"), ua, 1 / (fps * outDur));
654
+ const eb = carried(named(o.resume ?? "resume"), ub, 1 / (fps * inDur));
655
+ const view = o.view ?? FRAME;
656
+ const cover = o.cover ?? "ground";
657
+ const grounds = Array.isArray(o.ground) ? o.ground : [o.ground, o.ground];
658
+ /** one side, `d` px along the move from its place @param {number} d @param {boolean} visible @param {string | undefined} colour */
659
+ const sideOf = (d, visible, colour) => {
660
+ const far = Math.abs(d);
661
+ // drawn larger about its middle: what a move of `far` px uncovers at one edge
662
+ const s = cover === "scale" ? 1 + (2 * far) / (ux ? view.width : view.height) : 1;
663
+ const p = pose({ x: ux * d, y: uy * d, s, visible });
664
+ // 2 px over, for the half pixel the browser may round the scene's edge to
665
+ // (a side that is hidden has none: nothing is left painted on the scene the cut has left)
666
+ if (cover === "ground") p.cover = { px: visible && far > 0 ? far + 2 : 0, view, ...(colour ? { ground: colour } : {}) };
667
+ return p;
668
+ };
669
+ return {
670
+ a: sideOf(out * ea, !after, grounds[0]),
671
+ b: sideOf(-inn * (1 - eb), after, grounds[1]),
672
+ cutAt,
673
+ p: after ? clamp(eb) : clamp(ea),
674
+ };
675
+ }
676
+
677
+ // Fly film, the map at 33.5–34.33 s, the jump at 34.083 (24 fps): the view's
678
+ // scale frame by frame, one frame of 1.45× between the 14th and 15th, then
679
+ // settling — 2.07× in all in 0.83 s; the same push as one smooth move needs
680
+ // 1.106× a frame at its peak.
681
+ const RAMP = [1.0, 1.0014, 1.0018, 1.0026, 1.0032, 1.0034, 1.0071, 1.0145, 1.0289, 1.047, 1.0794, 1.1226, 1.1885, 1.244, 1.7978, 1.9644, 2.0184, 2.0539, 2.071, 2.0776, 2.0751];
682
+ const RAMP_LOG = RAMP.map((s) => Math.log(s) / Math.log(/** @type {number} */ (RAMP[RAMP.length - 1])));
683
+ const rampPre = measured(/** @type {[number, number][]} */ (RAMP_LOG.slice(0, 14).map((v, i) => [i / 13, v / /** @type {number} */ (RAMP_LOG[13])])));
684
+ const rampPost = measured(/** @type {[number, number][]} */ (RAMP_LOG.slice(14).map((v, i) => [i / 6, v])));
685
+
686
+ /**
687
+ * A push that speeds up, jumps in one frame, and settles: the cut that
688
+ * hides inside a move. Speeding up for 14 reel frames (24 fps; 1.0004× →
689
+ * 1.059× a frame), one frame of about 1.4×, then 6 frames settling (1.075×,
690
+ * 1.026×, 1.016×, 1.008×, 1.003×) — 2.07× in all in 0.83 s, measured on the
691
+ * fly film's map, the jump at 34.083 s. `by` scales the whole push (in log
692
+ * space); it zooms about `focus` (frame px), which stays put. `shift` is
693
+ * [x, y] in px of the frame, as seen on screen (not px of the layer, which
694
+ * the push has made larger): how far the picture — the focus with it — has
695
+ * slid by the time the push has settled — a third of it by the frame before
696
+ * the jump, half of it in the jump, as the scale goes (the fly film's other
697
+ * ramp, 30.875 s, jumped 1.5× and travelled about 300 px in that frame). A
698
+ * pose for the layer (origin 0 0). The jump falls between two frames of the film: declare
699
+ * `cutAt` as a cut hidden in the move, `tl.event(j.cutAt, "hidden-cut")`.
700
+ * `cam` is the same push as a camera over the layer and `rest` the camera
701
+ * it settles on, for a move that carries on in the same picture: the layer
702
+ * stays one element and the next move starts where this one is —
703
+ * `apply(map, camPose(stations(t, [{ t: 9.4, at: station(rows) }], { from:
704
+ * (t) => rampJump(t, 8.125, o).cam })))`. `from`: the camera the layer is
705
+ * already seen through when the push begins ({ x, y, s }, or a function of
706
+ * t); the pose, `cam` and `rest` are then the push laid over it, and `focus`
707
+ * and `shift` stay px of the frame.
708
+ * `const j = rampJump(t, 8.125, { focus: [700, 400], by: 2 }); apply(map, j); tl.event(j.cutAt, "hidden-cut");`
709
+ * @param {number} t @param {number} at the jump
710
+ * @param {{ by?: number, focus?: [number, number], shift?: [number, number], view?: View, fps?: number, from?: CamFrom }} [o]
711
+ * @returns {Pose & { cutAt: number, p: number, cam: Cam, rest: Cam }}
712
+ */
713
+ export function rampJump(t, at, o = {}) {
714
+ const view = o.view ?? FRAME;
715
+ const { by = 2.0751, focus = [view.width / 2, view.height / 2], shift = [0, 0], fps = filmFps() } = o;
716
+ const after = crossed(t, at, fps);
717
+ const cutAt = frameOf(at, fps) / fps;
718
+ const phi = (t - cutAt) * 24 + 14; // in reel frames; the jump at 14
719
+ const L13 = /** @type {number} */ (RAMP_LOG[13]), L12 = /** @type {number} */ (RAMP_LOG[12]);
720
+ let L;
721
+ if (after) L = rampPost(clamp((phi - 14) / 6));
722
+ else if (phi <= 13) L = rampPre(clamp(phi / 13)) * L13;
723
+ else L = L13 + (phi - 13) * (L13 - L12); // the last frame before the jump, still speeding up
724
+ const s = Math.exp(L * Math.log(by));
725
+ const [fx, fy] = focus;
726
+ const f = o.from ? camAt(o.from, t, "rampJump") : null;
727
+ const cam = camOf(fx * (1 - s) + shift[0] * L, fy * (1 - s) + shift[1] * L, s, view, f);
728
+ const rest = camOf(fx * (1 - by) + shift[0], fy * (1 - by) + shift[1], by, view, f);
729
+ const own = f ? camPose(cam, view) : pose({ x: fx * (1 - s) + shift[0] * L, y: fy * (1 - s) + shift[1] * L, s }, "0 0");
730
+ return { ...own, cutAt, p: L, cam, rest };
731
+ }
732
+
733
+ /**
734
+ * A hold that never stops: from t0 it drifts at `v0` px/s along `dir`, and
735
+ * over the last `kick` s before t1 speeds up to `v1` px/s, so the cut at t1
736
+ * comes on a move. Measured on the truck film, 20.08–21.5 s (24 fps, 1080
737
+ * tall): lines of text slowing in, near still at 16–56 px/s, then 176, 328,
738
+ * 560 px/s in the last three eighths of a second into a hard cut; nine of
739
+ * its shots (3, 5, 6, 13, 14, 15, 17, 19, 20) drift 10–60 px/s and reach
740
+ * 250–560 px/s 0.1–0.25 s before their cut. `grow` changes the scale that
741
+ * much a second meanwhile (the game film's title card at 37.92 s shrinking
742
+ * 5 % a second: −0.05). `kick` 0 jumps to `v1` at once.
743
+ * `const d = exitDrift(t, 9.2, 10.67); apply(lines, d);`
744
+ * @param {number} t @param {number} t0 @param {number} t1 the cut
745
+ * @param {{ dir?: "up" | "down" | "left" | "right", v0?: number, v1?: number, kick?: number, grow?: number }} [o]
746
+ * @returns {Pose & { speed: number }}
747
+ */
748
+ export function exitDrift(t, t0, t1, o = {}) {
749
+ const { dir = "up", v0 = 40, v1 = 560, kick = 0.375, grow = 0 } = o;
750
+ const [ux, uy] = unit(dir);
751
+ const tau = Math.max(0, t - t0);
752
+ const k0 = Math.max(0, t1 - t0 - kick);
753
+ const kk = Math.max(0, tau - k0);
754
+ // speed v0 until k0, then rising evenly to v1 over `kick`, then v1
755
+ const ramp = Math.min(kk, kick);
756
+ const d = v0 * tau + (kick > 0 ? ((v1 - v0) * ramp * ramp) / (2 * kick) : 0) + (v1 - v0) * Math.max(0, kk - kick);
757
+ const speed = kick > 0 ? v0 + (v1 - v0) * clamp(kk / kick) : kk > 0 ? v1 : v0;
758
+ return { ...pose({ x: ux * d, y: uy * d, s: 1 + grow * tau }), speed };
759
+ }
760
+
761
+ /**
762
+ * The page kicked sideways when something lands on it, gone in 3–4 frames:
763
+ * a damped swing, amp·e^(−τ/decay)·sin(2πfτ). The manga film's page shook
764
+ * with every new panel (26.33 and 27.12 s), 3–4 frames of sideways blur
765
+ * (the frames were looked at, the distance not measured: amp 60 moves it
766
+ * 30 px, then −30, −7, +7 at 24 fps). A softer, longer one (a motion
767
+ * component library's impact shake): amp 15, ampY 11, freq 5, decay 0.2,
768
+ * rot 1.1. `lag` delays it, for a layer behind that follows 0.03–0.06 s
769
+ * late.
770
+ * `const k = arrivalShake(t, T.panel3); apply(page, k);`
771
+ * @param {number} t @param {number} t0
772
+ * @param {{ amp?: number, ampY?: number, rot?: number, freq?: number, decay?: number, lag?: number }} [o]
773
+ * @returns {Pose}
774
+ */
775
+ export function arrivalShake(t, t0, o = {}) {
776
+ const { amp = 60, ampY = 0, rot = 0, freq = 6, decay = 0.06, lag = 0 } = o;
777
+ const tau = t - t0 - lag;
778
+ if (tau <= 0) return pose({});
779
+ const e = Math.exp(-tau / decay);
780
+ const w = 2 * Math.PI * freq * tau;
781
+ return pose({ x: amp * e * Math.sin(w), y: ampY * e * Math.sin(1.3 * w), r: rot * e * Math.sin(1.1 * w) });
782
+ }
783
+
784
+ /**
785
+ * Out of focus, cut, back into focus: the blur itself is what crosses. The
786
+ * shot leaving blurs over `out` s (ease-in), deepest on the last frame drawn
787
+ * before the cut; the next starts as blurred on its first frame and sharpens
788
+ * over `in` s (ease-out). Measured: the game film defocused 4 frames at
789
+ * 64.71–64.875 s (24 fps; sharpness 141 → 16); the fly film 4 frames, cut
790
+ * at 36.625 s, 9 frames back; a catalogue film wrapped all 10 of its cuts
791
+ * in 3 frames out, 4–6 in. Here 4 frames out, 6 in; `blur` px at the
792
+ * deepest (a 1080 frame). Write `a.blur` and `b.blur` as a CSS blur (apply
793
+ * does).
794
+ * `const f = blurBridge(t, 12.4); apply(shotA, f.a); apply(shotB, f.b); tl.event(f.cutAt, "cut");`
795
+ * @param {number} t @param {number} at
796
+ * @param {{ out?: number, in?: number, blur?: number, fps?: number }} [o]
797
+ * @returns {{ a: Pose, b: Pose, cutAt: number }}
798
+ */
799
+ export function blurBridge(t, at, o = {}) {
800
+ const { out = 4 / 24, blur = 24, fps = filmFps() } = o;
801
+ const inn = o.in ?? 6 / 24;
802
+ const after = crossed(t, at, fps);
803
+ const cutAt = frameOf(at, fps) / fps;
804
+ // deepest on the last frame drawn: the frame at cutAt is already the next shot
805
+ const lastA = cutAt - 1 / fps;
806
+ return {
807
+ a: pose({ blur: blur * ease.in2(prog(t, lastA - out, lastA)), visible: !after }),
808
+ b: pose({ blur: after ? blur * (1 - ease.out2(prog(t, cutAt, cutAt + inn))) : blur, visible: after }),
809
+ cutAt,
810
+ };
811
+ }
812
+
813
+ // --- carrying something across ---------------------------------------------------
814
+
815
+ /**
816
+ * Fly into `rect` faster every frame and cut on the fastest frame, into what
817
+ * it was: the scale grows exponentially in log space (k 3), so each frame's
818
+ * step is larger than the last — measured on the app film, 2.20–2.50 s:
819
+ * 1.02× a frame rising to 1.39× over 9 frames (3.05× in 0.3 s); and on the
820
+ * flying-machine film, 57.43–58.53 s: 8 frames of +14, 18, 25, 36, 48, 64,
821
+ * 88, 131 px (1.55×). It ends with `rect` covering the view, `through`
822
+ * times more, on the last frame drawn before the cut, and keeps speeding up
823
+ * through the half frame to the cut; then the next shot (`b`, at rest at
824
+ * the whole frame) starts `land` large and settles on ease-out over
825
+ * `settle` s, the push carrying on. `rect` is in the layout of the element
826
+ * `a` is for (frame px when it sits at 0, 0 the size of the frame), not
827
+ * where another move has put it on screen. (kit/motion.js zoomThrough grows
828
+ * one box into another on a smooth ease; this is the camera's fly-in to a
829
+ * cut.)
830
+ * `const z = zoomThrough(t, 7.4, 7.75, panelBox); apply(world, z.a); apply(next, z.b); tl.event(z.cutAt, "cut");`
831
+ * @param {number} t @param {number} start @param {number} end the cut
832
+ * @param {Rect} rect in the layout of `a`'s element
833
+ * @param {{ view?: View, through?: number, k?: number, land?: number, settle?: number, fps?: number }} [o]
834
+ * @returns {{ a: Pose, b: Pose, cutAt: number, p: number }}
835
+ */
836
+ export function zoomThrough(t, start, end, rect, o = {}) {
837
+ const view = o.view ?? FRAME;
838
+ sized("zoomThrough", "rect", rect);
839
+ const { through = 1.25, k = 3, land = 1.2, settle = 0.3, fps = filmFps() } = o;
840
+ const S = Math.max(view.width / rect.w, view.height / rect.h) * through;
841
+ const [cx, cy] = mid(rect);
842
+ // the point that stays put; with no zoom at all (S 1) any point does
843
+ const still = Math.abs(S - 1) < 1e-9;
844
+ const fx = still ? view.width / 2 : (S * /** @type {number} */ (cx) - view.width / 2) / (S - 1);
845
+ const fy = still ? view.height / 2 : (S * /** @type {number} */ (cy) - view.height / 2) / (S - 1);
846
+ const after = crossed(t, end, fps);
847
+ const cutAt = frameOf(end, fps) / fps;
848
+ // all the way in on the last frame drawn before the cut, and on, faster
849
+ // still, through the half frame of its shutter up to the cut
850
+ const lastA = cutAt - 1 / fps;
851
+ const half = 0.5 / fps;
852
+ const u = lastA > start ? clamp((t - start) / (lastA - start), 0, 1 + half / (lastA - start)) : t >= lastA ? 1 : 0;
853
+ const e = k ? (Math.exp(k * u) - 1) / (Math.exp(k) - 1) : u;
854
+ const s = S ** e;
855
+ // the next shot from the cut, its first speed carried back over the half frame before its first frame
856
+ const ub = settle > 0 ? clamp((t - cutAt) / settle, -half / settle, 1) : t >= cutAt ? 1 : 0;
857
+ const eb = 1 - (1 - ub) ** 3;
858
+ return {
859
+ a: pose({ x: fx * (1 - s), y: fy * (1 - s), s, visible: !after }, "0 0"),
860
+ b: pose({ s: land ** (1 - eb), visible: after }, "50% 50%"),
861
+ cutAt,
862
+ p: after ? clamp(eb) : clamp(e),
863
+ };
864
+ }
865
+
866
+ /**
867
+ * A flash, and the whole picture shrinks into its thumbnail in the next
868
+ * scene: the thing carried across is the picture itself. Measured on the
869
+ * truck film, 5.33–5.67 s (24 fps, frames 128–136): 3 frames of overexposed
870
+ * white, then the photo shrank into the chat card's thumbnail in 6 frames
871
+ * (0.25 s), blurred by its speed. The
872
+ * picture is laid out at `from` (usually the whole frame); its size changes
873
+ * in log space, its height following its width. `flash` is the white
874
+ * layer's opacity over everything.
875
+ * `const th = toThumbnail(t, 5.4, frameBox, thumbBox); apply(photo, th.photo); white.style.opacity = th.flash;`
876
+ * @param {number} t @param {number} start the shrink starts (the flash is before it)
877
+ * @param {Rect} from @param {Rect} to
878
+ * @param {{ dur?: number, flash?: number, peak?: number, ease?: Ease | string }} [o]
879
+ * @returns {{ photo: Pose, flash: number, rect: Rect, p: number }}
880
+ */
881
+ export function toThumbnail(t, start, from, to, o = {}) {
882
+ const { dur = 6 / 24, flash = 3 / 24, peak = 0.85 } = o;
883
+ const e = named(o.ease ?? "out3")(prog(t, start, start + dur));
884
+ const w = from.w * (to.w / from.w) ** e;
885
+ const k = w / from.w;
886
+ const [ax, ay] = mid(from), [bx, by] = mid(to);
887
+ const cx = lerp(/** @type {number} */ (ax), /** @type {number} */ (bx), e), cy = lerp(/** @type {number} */ (ay), /** @type {number} */ (by), e);
888
+ const h = from.h * k;
889
+ const fl = t < start ? prog(t, start - flash, start) : 1 - prog(t, start, start + 2 / 24);
890
+ return {
891
+ photo: pose({ x: cx - w / 2 - from.x, y: cy - h / 2 - from.y, s: k }, "0 0"),
892
+ flash: peak * ease.in2(fl),
893
+ rect: { x: cx - w / 2, y: cy - h / 2, w, h },
894
+ p: e,
895
+ };
896
+ }
897
+
898
+ /**
899
+ * A crowd collapses into one point, and the point becomes one thing: items
900
+ * (their centres, frame px) rush to `to`'s centre, faster and faster,
901
+ * shrinking and blurring, and are gone at `dur`; then the thing laid out at
902
+ * `to` grows from that point over `grow` s. Measured on the app film,
903
+ * 44.133 s: about 30 figures collapsing in 0.3 s, radial blur → a ball → a
904
+ * point, the point becoming the next section's avatar. The grow is not
905
+ * measured there (it
906
+ * lands across a cut): 0.25 s, ease-out. Each item's pose is against its own
907
+ * place; `blur` is for the crowd's layer.
908
+ * `const im = implodeTo(t, 10.1, dots.map(centre), avatarBox); dots.forEach((d, i) => apply(d, im.items[i])); apply(avatar, im.into);`
909
+ * @param {number} t @param {number} start
910
+ * @param {{ x: number, y: number }[]} items @param {Rect} to
911
+ * @param {{ dur?: number, grow?: number, blur?: number, shrink?: number }} [o] shrink: the items' size at the point
912
+ * @returns {{ items: Pose[], into: Pose, blur: number, p: number }}
913
+ */
914
+ export function implodeTo(t, start, items, to, o = {}) {
915
+ const { dur = 0.3, grow = 0.25, blur = 18, shrink = 0.12 } = o;
916
+ const u = prog(t, start, start + dur);
917
+ const e = ease.in3(u);
918
+ const gone = t >= start + dur;
919
+ const [tx, ty] = mid(to);
920
+ const g = ease.out3(prog(t, start + dur, start + dur + grow));
921
+ return {
922
+ items: items.map((it) =>
923
+ pose({ x: (/** @type {number} */ (tx) - it.x) * e, y: (/** @type {number} */ (ty) - it.y) * e, s: lerp(1, shrink, e), visible: !gone }),
924
+ ),
925
+ into: pose({ s: lerp(0.02, 1, g), visible: gone }),
926
+ blur: gone ? 0 : blur * clamp(e * 2),
927
+ p: u,
928
+ };
929
+ }
930
+
931
+ /** "#rgb" or "#rrggbb" → [r, g, b] 0..1 @param {string} hex @returns {[number, number, number]} */
932
+ function rgb(hex) {
933
+ const h = hex.replace("#", "");
934
+ const f = h.length === 3 ? h.split("").map((c) => c + c).join("") : h;
935
+ const n = parseInt(f, 16);
936
+ if (!/^[0-9a-f]{6}$/i.test(f)) throw new Error(`moves: develop's colours are "#rgb" or "#rrggbb" (got ${JSON.stringify(hex)})`);
937
+ return [((n >> 16) & 255) / 255, ((n >> 8) & 255) / 255, (n & 255) / 255];
938
+ }
939
+ /** the colour matrix mapping a pixel's luminance from `dark` to `light` @param {string} dark @param {string} light */
940
+ function duotone(dark, light) {
941
+ const d = rgb(dark), l = rgb(light);
942
+ const Y = [0.2126, 0.7152, 0.0722];
943
+ /** @type {number[]} */
944
+ const m = [];
945
+ for (let c = 0; c < 3; c++) {
946
+ const span = /** @type {number} */ (l[c]) - /** @type {number} */ (d[c]);
947
+ m.push(span * /** @type {number} */ (Y[0]), span * /** @type {number} */ (Y[1]), span * /** @type {number} */ (Y[2]), 0, /** @type {number} */ (d[c]));
948
+ }
949
+ m.push(0, 0, 0, 1, 0);
950
+ return m;
951
+ }
952
+ const IDENTITY = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0];
953
+
954
+ /**
955
+ * A picture arriving in the colours of something still being made, then
956
+ * finished: a first duotone, a second, then the picture as it is. Measured
957
+ * on the manga film, 26.33–26.75 s (24 fps): a new comic panel magenta from
958
+ * its arrival (deepest 0.09–0.13 s in), lime at 0.25–0.38 s, finished from
959
+ * 0.42 s — 10 frames.
960
+ * `values` is for an SVG feColorMatrix (type "matrix") the picture is
961
+ * filtered through; mixing matrices mixes the pictures. Put the filter in
962
+ * the page once, with color-interpolation-filters="sRGB":
963
+ * <svg width="0" height="0"><filter id="dev" color-interpolation-filters="sRGB"><feColorMatrix id="devm" type="matrix"/></filter></svg>
964
+ * img.style.filter = "url(#dev)"
965
+ * `devm.setAttribute("values", develop(t, T.panel).values)` (and the filter off once `p` is 1).
966
+ * @param {number} t @param {number} start
967
+ * @param {{ dur?: number, first?: [string, string], second?: [string, string] }} [o] each [dark, light]
968
+ * @returns {{ values: string, stage: "first" | "second" | "done", p: number }}
969
+ */
970
+ export function develop(t, start, o = {}) {
971
+ const { dur = 0.42, first = ["#2b0030", "#ff4fd8"], second = ["#0d2600", "#c5fb27"] } = o;
972
+ const A = duotone(...first), B = duotone(...second);
973
+ const u = prog(t, start, start + dur);
974
+ // [share of dur, matrix]: the first held to 31 %, the second from 60 to 90 %, done at 100 %
975
+ /** @type {[number, number[]][]} */
976
+ const ks = [[0, A], [0.31, A], [0.6, B], [0.9, B], [1, IDENTITY]];
977
+ let m = IDENTITY;
978
+ for (let i = 1; i < ks.length; i++) {
979
+ const [u0, m0] = /** @type {[number, number[]]} */ (ks[i - 1]);
980
+ const [u1, m1] = /** @type {[number, number[]]} */ (ks[i]);
981
+ if (u <= u1) {
982
+ const q = ease.inOut2(prog(u, u0, u1));
983
+ m = m0.map((v, j) => lerp(v, /** @type {number} */ (m1[j]), q));
984
+ break;
985
+ }
986
+ }
987
+ return {
988
+ values: m.map((v) => +v.toFixed(4)).join(" "),
989
+ stage: u < 0.45 ? "first" : u < 1 ? "second" : "done",
990
+ p: u,
991
+ };
992
+ }
993
+
994
+ // --- time ------------------------------------------------------------------------
995
+
996
+ // ∫ from 0 to u of an ease, as a running sum over one fixed grid of 0 → 1
997
+ // read between its steps: an ease that is never below 0 gives a sum that
998
+ // never falls, however steep it is (a rule refitted to each u can).
999
+ const STEPS = 1024;
1000
+ /** @type {WeakMap<Function, Float64Array>} */
1001
+ const sumsOfFns = new WeakMap();
1002
+ /** @type {Map<string, Float64Array>} */
1003
+ const sumsOfNames = new Map();
1004
+ /** @param {Ease | string} e @returns {Float64Array} */
1005
+ function sums(e) {
1006
+ const known = typeof e === "function" ? sumsOfFns.get(e) : sumsOfNames.get(e);
1007
+ if (known) return known;
1008
+ const f = named(e);
1009
+ const tab = new Float64Array(STEPS + 1);
1010
+ let prev = f(0);
1011
+ for (let i = 1; i <= STEPS; i++) {
1012
+ const v = f(i / STEPS);
1013
+ tab[i] = /** @type {number} */ (tab[i - 1]) + (prev + v) / (2 * STEPS);
1014
+ prev = v;
1015
+ }
1016
+ if (typeof e === "function") sumsOfFns.set(e, tab);
1017
+ else sumsOfNames.set(e, tab);
1018
+ return tab;
1019
+ }
1020
+ /** ∫ from 0 to x of the ease e (x in 0..1) @param {Ease | string} e @param {number} x */
1021
+ function integral(e, x) {
1022
+ if (x <= 0) return 0;
1023
+ const tab = sums(e);
1024
+ const q = Math.min(1, x) * STEPS;
1025
+ const i = Math.min(STEPS - 1, Math.floor(q));
1026
+ const a = /** @type {number} */ (tab[i]), b = /** @type {number} */ (tab[i + 1]);
1027
+ return a + (b - a) * (q - i);
1028
+ }
1029
+
1030
+ /**
1031
+ * Film time → the time a stretch of the film is drawn at, from speed keys
1032
+ * [[t, speed, ease?], …] in film time (ascending): the speed changes from
1033
+ * one key's to the next's on that key's ease (default inOut2), and the drawn
1034
+ * time is its integral — so a ramp, a freeze (speed 0) or slow motion is
1035
+ * one function wrapped round the page's own: `__render = (t) =>
1036
+ * draw(remap(t, keys))`. Before the first key the drawn time is film time
1037
+ * (at the first speed); after the last, it runs on at the last speed. The
1038
+ * master's shutter samples film time, so a slowed move is drawn with less
1039
+ * blur on its own. `twos`: the drawn time held for that many frames at a
1040
+ * time at `fps` (2: on twos), as the game film's animated shots were
1041
+ * (78.67–79.83 s: on twos, then threes). The drawn time never runs back
1042
+ * while every speed is 0 or more.
1043
+ * `draw(remap(t, freeze(6.2)))`; `draw(remap(t, [[2, 1], [2.2, 0.2], [3.45, 0.2], [3.8, 1]]))`
1044
+ * @param {number} t
1045
+ * @param {[number, number, (Ease | string)?][]} keys
1046
+ * @param {{ twos?: number, fps?: number }} [o]
1047
+ */
1048
+ export function remap(t, keys, { twos = 0, fps = 24 } = {}) {
1049
+ let tau = t;
1050
+ if (keys.length) {
1051
+ const [k0, v0] = /** @type {[number, number]} */ (keys[0]);
1052
+ if (t <= k0) tau = k0 + v0 * (t - k0);
1053
+ else {
1054
+ tau = k0;
1055
+ let done = false;
1056
+ for (let i = 1; i < keys.length && !done; i++) {
1057
+ const [ta, va] = /** @type {[number, number]} */ (keys[i - 1]);
1058
+ const [tb, vb, e] = /** @type {[number, number, (Ease | string)?]} */ (keys[i]);
1059
+ const span = tb - ta;
1060
+ const x = Math.min(t, tb) - ta;
1061
+ tau += span > 0 ? va * x + (vb - va) * span * integral(e ?? "inOut2", x / span) : 0;
1062
+ if (t <= tb) done = true;
1063
+ }
1064
+ if (!done) {
1065
+ const [tl, vl] = /** @type {[number, number]} */ (keys[keys.length - 1]);
1066
+ tau += vl * (t - tl);
1067
+ }
1068
+ }
1069
+ }
1070
+ return twos > 0 ? onTwos(tau, twos, fps) : tau;
1071
+ }
1072
+
1073
+ /**
1074
+ * The speed keys of a freeze, for remap: slowing to `speed` over `slow` s
1075
+ * before `at`, held `hold` s, back to full speed over `back` s. Measured on
1076
+ * the game film, 43.29–44.58 s (24 fps): 9 frames slowing, 14 frozen
1077
+ * (0.58 s), 9 speeding up. What
1078
+ * is drawn then runs behind film time by about hold + (slow + back) / 2.
1079
+ * `draw(remap(t, freeze(43.3)))`
1080
+ * @param {number} at the freeze begins
1081
+ * @param {{ slow?: number, hold?: number, back?: number, speed?: number }} [o]
1082
+ * @returns {[number, number][]}
1083
+ */
1084
+ export function freeze(at, { slow = 9 / 24, hold = 14 / 24, back = 9 / 24, speed = 0 } = {}) {
1085
+ return [[at - slow, 1], [at, speed], [at + hold, speed], [at + hold + back, 1]];
1086
+ }
1087
+
1088
+ /**
1089
+ * Time held for `n` frames at a time at `fps`: drawn on twos (n 2) or threes.
1090
+ * `draw(onTwos(t))`
1091
+ * @param {number} t @param {number} [n] @param {number} [fps]
1092
+ */
1093
+ export function onTwos(t, n = 2, fps = 24) {
1094
+ return (Math.floor((t * fps) / n + 1e-6) * n) / fps;
1095
+ }