@open-take/compositor 0.5.3 → 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,760 @@
1
+ // anim.js — motion helpers for a film page. Plain functions of film time t (s):
2
+ // no state, no clock, nothing here knows any film. Gathered from what three
3
+ // films wrote for themselves in place of the kit's camera, cursor and motion
4
+ // files; the curves are the ones measured on the reference (reference/motion.md
5
+ // §3.1–3.3). Import what you use:
6
+ //
7
+ // import { keys, ease, stamp, pointer } from "./lib/anim.js";
8
+ //
9
+ // clamp(x, a, b) x held inside [a, b]
10
+ // lerp(a, b, u) a → b at u
11
+ // prog(t, a, b) 0 → 1 as t goes from a to b
12
+ // rng(seed) seeded numbers in [0, 1), the same every render
13
+ // bezier(x1, y1, x2, y2) a CSS cubic-bezier as an ease
14
+ // ease.* linear, in2 … inOut4, out5, inOutSine, outExpo,
15
+ // and the measured ones: push, count, pull, fling
16
+ // keys(t, ks) a value through keyframes, each stretch with its own ease
17
+ // track(ks) keys as a function of t
18
+ // keyed(t, start, moves) a value through moves that start at t and last dur (holds between)
19
+ // stamp(t, t0, o) → { scale, opacity } — an object landing: 1.19× → 1 in one 24 fps frame, no bounce
20
+ // spring(t, t0, o) a damped spring 0 → 1
21
+ // swing(t, t0, o) a damped swing amp → 0 (a dragged thing's tilt)
22
+ // fling(t, t0, from, to, tau) flung in: fastest at once, exponential arrival — a value;
23
+ // its ease, for keys or your own progress, is ease.fling(u, tau)
24
+ // rise(t, t0, o) a line rising into place
25
+ // exit(t, t0, o) leaving by accelerating until gone
26
+ // typeOn(t, t0, text, cps) the part of a text typed so far
27
+ // count(t, t0, dur, a, b, o) a number counting a → b on the measured count curve
28
+ // fmt(n, digits) 1234.5 → "1,234.5"
29
+ // pointer(t, marks, o) a cursor going from target to target, in a slight arc
30
+ // press(t, t0) a click's squash: 1 → 0.86 → 1 around t0
31
+ // cam2d(c, w, h) a 2D camera { x, y, s } → its CSS transform and toScreen
32
+ //
33
+ // Named for what they do, and the GSAP names the reels' eases were measured in:
34
+ //
35
+ // ease.arrive, leave, resume, step, pop, settle, drift eases by purpose (below)
36
+ // named(e) an ease, by its name or a GSAP name ("power2.out", "back.out(1.5)",
37
+ // "elastic.out(1, 0.4)"); an unknown name is an error. Every ease
38
+ // option here takes the same names.
39
+ // gsapEase(name) a GSAP ease name as GSAP 3 computes it, or null
40
+ // staggerGrid(i, cols, rows, o) when cell i of a grid starts, by its distance from a cell or the centre
41
+ // accelStagger(i, n, o) when item i of n starts, the gaps shrinking: a run that speeds up
42
+ // split(el, o) a line of text split into chars, words or lines (with a mask), to move each
43
+ // springs(t, changes, o) a value retargeted again and again, each change a spring on top of the last
44
+ // anticipate(t, t0, o) a move that winds up first: back, squashed, then launched and stretched
45
+ // follow(drive, o) a tag's swing, pushed by what it hangs from: a function of t, built once
46
+
47
+ /** @typedef {(u: number) => number} Ease progress 0..1, eased */
48
+ /** @typedef {any} Value a number, an array of numbers, or a flat object of numbers */
49
+ /** @typedef {[number, Value, (Ease | string)?]} Key [t, value, the ease of the stretch that ends on it] */
50
+
51
+ /** x held inside [a, b]. `clamp(1.3)` → 1 @param {number} x @param {number} [a] @param {number} [b] */
52
+ export const clamp = (x, a = 0, b = 1) => Math.min(b, Math.max(a, x));
53
+
54
+ /** a → b at u (0..1, not clamped). `lerp(0, 100, 0.25)` → 25 @param {number} a @param {number} b @param {number} u */
55
+ export const lerp = (a, b, u) => a + (b - a) * u;
56
+
57
+ /** progress 0..1 of t through [a, b] (a time, not a duration). `prog(t, 2, 2.6)` @param {number} t @param {number} a @param {number} b */
58
+ export const prog = (t, a, b) => (b <= a ? (t >= b ? 1 : 0) : clamp((t - a) / (b - a)));
59
+
60
+ /**
61
+ * Numbers that look random but are the same every render (mulberry32, as
62
+ * kit/audio.mjs's rng for the score): a page built on Math.random() changes
63
+ * each time it is drawn. `const r = rng(7); r()` → a number in [0, 1)
64
+ * @param {number} seed @returns {() => number}
65
+ */
66
+ export function rng(seed) {
67
+ let a = seed | 0;
68
+ return () => {
69
+ a = (a + 0x6d2b79f5) | 0;
70
+ let t = Math.imul(a ^ (a >>> 15), a | 1);
71
+ t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
72
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
73
+ };
74
+ }
75
+
76
+ /**
77
+ * CSS cubic-bezier(x1, y1, x2, y2) as an ease of progress 0..1 (Newton steps,
78
+ * bisection when they stall). `const e = bezier(0.48, 0.08, 0.07, 1.02); e(0.3)`
79
+ * @param {number} x1 @param {number} y1 @param {number} x2 @param {number} y2
80
+ * @returns {Ease}
81
+ */
82
+ export function bezier(x1, y1, x2, y2) {
83
+ const cx = 3 * x1, bx = 3 * (x2 - x1) - cx, ax = 1 - cx - bx;
84
+ const cy = 3 * y1, by = 3 * (y2 - y1) - cy, ay = 1 - cy - by;
85
+ const X = (/** @type {number} */ s) => ((ax * s + bx) * s + cx) * s;
86
+ const dX = (/** @type {number} */ s) => (3 * ax * s + 2 * bx) * s + cx;
87
+ const Y = (/** @type {number} */ s) => ((ay * s + by) * s + cy) * s;
88
+ return (x) => {
89
+ if (x <= 0) return 0;
90
+ if (x >= 1) return 1;
91
+ let s = x;
92
+ for (let i = 0; i < 8; i++) {
93
+ const e = X(s) - x, d = dX(s);
94
+ if (Math.abs(e) < 1e-6 || Math.abs(d) < 1e-6) break;
95
+ s -= e / d;
96
+ }
97
+ let lo = 0, hi = 1;
98
+ for (let i = 0; i < 20 && Math.abs(X(s) - x) > 1e-6; i++) {
99
+ if (X(s) < x) lo = s; else hi = s;
100
+ s = (lo + hi) / 2;
101
+ }
102
+ return Y(s);
103
+ };
104
+ }
105
+
106
+ /**
107
+ * Eases of progress 0..1. The last four were measured on the reference
108
+ * (reference/motion.md §3.3), which used three families: speed peaking near
109
+ * 30 % with a long settle (push, count), pure acceleration until gone (in3,
110
+ * in4: exits), fastest at once with an exponential settle (fling).
111
+ * Anywhere an ease is taken, its name works too. `keys(t, [[0, 0], [1, 1, "push"]])`
112
+ * @satisfies {Record<string, (u: number, tau?: number) => number>}
113
+ */
114
+ export const ease = {
115
+ linear: (u) => u,
116
+ in2: (u) => u * u,
117
+ out2: (u) => 1 - (1 - u) ** 2,
118
+ inOut2: (u) => (u < 0.5 ? 2 * u * u : 1 - (-2 * u + 2) ** 2 / 2),
119
+ in3: (u) => u ** 3, // an exit: accelerates until it is gone (reference: 0.8–1.0 s, no fade)
120
+ out3: (u) => 1 - (1 - u) ** 3,
121
+ inOut3: (u) => (u < 0.5 ? 4 * u ** 3 : 1 - (-2 * u + 2) ** 3 / 2),
122
+ in4: (u) => u ** 4,
123
+ out4: (u) => 1 - (1 - u) ** 4,
124
+ inOut4: (u) => (u < 0.5 ? 8 * u ** 4 : 1 - (-2 * u + 2) ** 4 / 2),
125
+ out5: (u) => 1 - (1 - u) ** 5,
126
+ inOutSine: (u) => -(Math.cos(Math.PI * u) - 1) / 2,
127
+ outExpo: (u) => (u >= 1 ? 1 : 1 - 2 ** (-10 * u)),
128
+ // a camera push-in: gentle start, speed peaks at ~30 %, long settle (1.25–1.33 s)
129
+ push: bezier(0.48, 0.08, 0.07, 1.02),
130
+ // a number counting up (0.875 s, peak at 30 %, the last 0.25 s climbs 1 %)
131
+ count: bezier(0.32, 0.15, 0.39, 1.06),
132
+ // a pull-back (2.7 s, close to out3)
133
+ pull: bezier(0.25, 0.06, 0.1, 0.91),
134
+ // flung in: fastest at once, exponential settle; tau as a share of the stretch
135
+ // (the reference's cursor: tau 0.14 s over 0.625 s ≈ 0.22). `(u) => ease.fling(u, 0.18)`.
136
+ // A progress, not a value: to move a value from one place to another over
137
+ // film time, fling(t, t0, from, to, tau) below (tau in seconds there)
138
+ fling: (u, tau = 0.22) => (1 - Math.exp(-u / tau)) / (1 - Math.exp(-1 / tau)),
139
+ // By purpose, each measured on a launch film (the GSAP name it is closest to after it):
140
+ // something arriving, all its force in the first frame: a panel dropping
141
+ // 195 px in 0.47 s, 65 px of it in the first frame (flying-machine film, 5.533 s; circ.out)
142
+ arrive: bezier(0.1, 1, 0.95, 1),
143
+ // leaving, faster every frame, cut on the fastest: a card sliding 85 px in 8 frames
144
+ // (flying-machine film, 3.033–3.3 s; power3.in)
145
+ leave: bezier(0.775, 0, 0.975, 1),
146
+ // the next shot carrying on the same way and slowing: 57 px in 8 frames, −17.7 → −0.5 px a frame
147
+ // (flying-machine film, 3.3–3.567 s)
148
+ resume: bezier(0.275, 0.8, 0.675, 1),
149
+ // one step of a list or wheel: 155 px in 10 frames (flying-machine film, 3.667–4.9 s; power2.inOut)
150
+ step: bezier(0.425, 0, 0.2, 1),
151
+ // a block snapping to a new size in two frames, a touch past (truck film, 28.46 s; back.out(1.5))
152
+ pop: (u) => 1 + 2.5 * (u - 1) ** 3 + 1.5 * (u - 1) ** 2,
153
+ // a number or a pill settling: a 1.07 s count (flying-machine film, 38.758 s), a pill 164 px
154
+ // in 0.375 s (game film, 16.2 s) (power2.out)
155
+ settle: (u) => 1 - (1 - u) ** 3,
156
+ // a drift: the same speed throughout (a hold that never stops, a scroll)
157
+ drift: (u) => u,
158
+ };
159
+ /** an ease of `ease` by its own name (not one every object inherits, such as "toString") @param {string} e */
160
+ const own = (e) => (Object.hasOwn(ease, e) ? /** @type {Record<string, Ease>} */ (ease)[e] : undefined);
161
+
162
+ /** an ease, or one by its name or a GSAP name (a bare GSAP family, "sine", is
163
+ * its .out, as in GSAP); a name that is neither is inOut3
164
+ * @param {Ease | string | undefined} e @returns {Ease} */
165
+ const easeOf = (e) => (typeof e === "function" ? e : (own(e ?? "inOut3") ?? gsapEase(e ?? "")) ?? ease.inOut3);
166
+
167
+ /**
168
+ * An ease, or one by its name in `ease` or a GSAP name; a name that is
169
+ * neither is an error, saying which names there are.
170
+ * `named("power2.out")(0.5)` → 0.875
171
+ * @param {Ease | string} e @returns {Ease}
172
+ */
173
+ export function named(e) {
174
+ if (typeof e === "function") return e;
175
+ const f = (typeof e === "string" ? own(e) : undefined) ?? gsapEase(e);
176
+ if (!f)
177
+ throw new Error(
178
+ `anim: no ease named "${e}" — one of ${Object.keys(ease).join(", ")}, or a GSAP name such as "power2.out", "sine.inOut", "back.out(1.7)"`,
179
+ );
180
+ return f;
181
+ }
182
+
183
+ /** GSAP's power families: the power of their ease-in */
184
+ /** @type {Record<string, number>} */
185
+ const POWER = { linear: 1, none: 1, power0: 1, power1: 2, quad: 2, power2: 3, cubic: 3, power3: 4, quart: 4, power4: 5, quint: 5, strong: 5 };
186
+
187
+ /**
188
+ * A GSAP 3 ease name as GSAP computes it: power0–4 (quad … quint), sine,
189
+ * expo (GSAP's blended form, 0.9766 at 0.5 where ease.outExpo is 0.9688),
190
+ * circ, back (overshoot, default 1.70158), elastic (amplitude, period),
191
+ * bounce, none/linear; ".in", ".out" or ".inOut", a bare family being
192
+ * ".out" as in GSAP. Names differ between libraries for the same curve:
193
+ * GSAP's power2.out is ease.out3 here (and anime's outCubic). Null for a
194
+ * name it does not know.
195
+ * `gsapEase("power2.out")(0.5)` → 0.875; `gsapEase("back.out(1.5)")`
196
+ * @param {string} name @returns {Ease | null}
197
+ */
198
+ export function gsapEase(name) {
199
+ const m = /^\s*([a-z][a-z0-9]*)(?:\.(in|out|inout))?\s*(?:\(([^)]*)\))?\s*$/i.exec(String(name));
200
+ if (!m) return null;
201
+ const fam = /** @type {string} */ (m[1]).toLowerCase();
202
+ const kind = (m[2] ?? "out").toLowerCase();
203
+ const args = m[3] ? m[3].split(",").map((s) => Number(s.trim())) : [];
204
+ /** in → out → inOut, as GSAP derives them from the ease-in @param {Ease} f */
205
+ const from_in = (f) =>
206
+ kind === "in" ? f : kind === "out" ? (/** @type {Ease} */ (u) => 1 - f(1 - u)) : (/** @type {Ease} */ (u) => (u < 0.5 ? f(u * 2) / 2 : 1 - f((1 - u) * 2) / 2));
207
+ /** …and from the ease-out, for back and elastic @param {Ease} f */
208
+ const from_out = (f) =>
209
+ kind === "out" ? f : kind === "in" ? (/** @type {Ease} */ (u) => 1 - f(1 - u)) : (/** @type {Ease} */ (u) => (u < 0.5 ? (1 - f(1 - u * 2)) / 2 : 0.5 + f((u - 0.5) * 2) / 2));
210
+ const n = Object.hasOwn(POWER, fam) ? POWER[fam] : undefined;
211
+ if (n != null) return n === 1 ? (u) => u : from_in((u) => u ** n);
212
+ if (fam === "sine") return from_in((u) => (u === 1 ? 1 : 1 - Math.cos((u * Math.PI) / 2)));
213
+ if (fam === "expo") return from_in((u) => 2 ** (10 * (u - 1)) * u + u ** 6 * (1 - u));
214
+ if (fam === "circ") return from_in((u) => 1 - Math.sqrt(1 - u * u));
215
+ if (fam === "back") {
216
+ const o = Number.isFinite(args[0]) ? /** @type {number} */ (args[0]) : 1.70158;
217
+ return from_out((u) => {
218
+ if (!u) return 0;
219
+ const q = u - 1;
220
+ return q * q * ((o + 1) * q + o) + 1;
221
+ });
222
+ }
223
+ if (fam === "elastic") {
224
+ const amp = Number.isFinite(args[0]) ? /** @type {number} */ (args[0]) : 1;
225
+ // a period of 0 is the default, as GSAP's `period ||` reads it
226
+ const per = Number.isFinite(args[1]) && args[1] !== 0 ? /** @type {number} */ (args[1]) : kind === "inout" ? 0.45 : 0.3;
227
+ const p1 = amp >= 1 ? amp : 1;
228
+ const p2 = per / (amp < 1 ? amp : 1);
229
+ const p3 = (p2 / (2 * Math.PI)) * (Math.asin(1 / p1) || 0);
230
+ const w = (2 * Math.PI) / p2;
231
+ return from_out((u) => (u === 1 ? 1 : p1 * 2 ** (-10 * u) * Math.sin((u - p3) * w) + 1));
232
+ }
233
+ if (fam === "bounce") {
234
+ const k = 7.5625, c = 2.75;
235
+ /** @type {Ease} */
236
+ const out = (u) =>
237
+ u < 1 / c ? k * u * u : u < 2 / c ? k * (u - 1.5 / c) ** 2 + 0.75 : u < 2.5 / c ? k * (u - 2.25 / c) ** 2 + 0.9375 : k * (u - 2.625 / c) ** 2 + 0.984375;
238
+ return from_in((u) => 1 - out(1 - u));
239
+ }
240
+ return null;
241
+ }
242
+
243
+ /** a mix of two values: numbers, arrays of numbers, or flat objects of numbers (a key `s` mixes in log space)
244
+ * @param {Value} a @param {Value} b @param {number} u @returns {Value} */
245
+ function mixv(a, b, u) {
246
+ if (a == null || b == null)
247
+ throw new Error(
248
+ `anim: a value to move is missing (from ${JSON.stringify(a)} to ${JSON.stringify(b)}) — a number, an array of numbers or a flat object of numbers`,
249
+ );
250
+ if (typeof a === "number") return lerp(a, b, u);
251
+ if (Array.isArray(a)) return a.map((v, i) => lerp(v, b[i], u));
252
+ /** @type {Record<string, number>} */
253
+ const o = {};
254
+ for (const k of Object.keys(a)) {
255
+ if (k === "s" && a.s > 0 && b.s > 0) o.s = a.s * (b.s / a.s) ** u;
256
+ else o[k] = lerp(a[k], b[k] ?? a[k], u);
257
+ }
258
+ return o;
259
+ }
260
+
261
+ /**
262
+ * A value through keyframes ks = [[t, value, ease?], …], times ascending. The
263
+ * ease of key i shapes the stretch that ends on it (default inOut3). Values
264
+ * are numbers, arrays, or flat objects; a key named `s` is mixed in log space,
265
+ * so a zoom changes at an even rate of scale. Holds the first value before the
266
+ * first key and the last after the last.
267
+ * `const cam = keys(t, [[0, { x: 960, y: 540, s: 1 }], [2, { x: 700, y: 400, s: 1.4 }, "push"]])`
268
+ * @param {number} t
269
+ * @param {Key[]} ks
270
+ * @returns {Value}
271
+ */
272
+ export function keys(t, ks) {
273
+ const first = /** @type {Key} */ (ks[0]);
274
+ if (t <= first[0]) return first[1];
275
+ for (let i = 1; i < ks.length; i++) {
276
+ const [t1, v1, e] = /** @type {Key} */ (ks[i]);
277
+ if (t <= t1) {
278
+ const [t0, v0] = /** @type {Key} */ (ks[i - 1]);
279
+ return mixv(v0, v1, easeOf(e)(prog(t, t0, t1)));
280
+ }
281
+ }
282
+ return /** @type {Key} */ (ks[ks.length - 1])[1];
283
+ }
284
+
285
+ /** keys(t, ks) as a function of t, to define once and read every frame. `const x = track([[0, 0], [1, 300, "out3"]]); x(t)`
286
+ * @param {Key[]} ks @returns {(t: number) => Value} */
287
+ export const track = (ks) => (t) => keys(t, ks);
288
+
289
+ /**
290
+ * A value through moves, each starting at its own t and lasting dur: moves =
291
+ * [{ t, dur, v, ease? }], in time order. Between moves the value holds, so the
292
+ * holds are written by leaving gaps. Default ease inOut3.
293
+ * `keyed(t, [0, 0], [{ t: 1, dur: 0.6, v: [400, 200], ease: "push" }, { t: 3, dur: 0.8, v: [-900, 200], ease: "in3" }])`
294
+ * @param {number} t
295
+ * @param {Value} start
296
+ * @param {{ t: number, dur: number, v: Value, ease?: Ease | string }[]} moves
297
+ * @returns {Value}
298
+ */
299
+ export function keyed(t, start, moves) {
300
+ let v = start;
301
+ for (const m of moves) {
302
+ if (t < m.t) break;
303
+ const u = easeOf(m.ease)(prog(t, m.t, m.t + m.dur));
304
+ if (t < m.t + m.dur) return mixv(v, m.v, u);
305
+ v = m.v;
306
+ }
307
+ return v;
308
+ }
309
+
310
+ /**
311
+ * An object stamped down where it lands: scale `from` → 1 over `dur`, then
312
+ * still; no bounce. The reference: 1.19× → 1.0 in one 24 fps frame (42 ms).
313
+ * Before t0: { scale: from, opacity: 0 }.
314
+ * `const st = stamp(t, T.result); el.style.transform = `scale(${st.scale})`; el.style.opacity = st.opacity;`
315
+ * @param {number} t @param {number} t0
316
+ * @param {{ from?: number, dur?: number, ease?: Ease | string }} [o]
317
+ */
318
+ export function stamp(t, t0, { from = 1.19, dur = 1 / 24, ease: e = "linear" } = {}) {
319
+ if (t < t0) return { scale: from, opacity: 0 };
320
+ return { scale: lerp(from, 1, easeOf(e)(prog(t, t0, t0 + dur))), opacity: 1 };
321
+ }
322
+
323
+ /**
324
+ * A damped spring from 0 toward 1, released at t0. freq in Hz; zeta the
325
+ * damping ratio (below 1 it overshoots, 1 and above it does not).
326
+ * `const k = spring(t, T.mark, { freq: 2.6, zeta: 0.42 }); el.style.transform = `scale(${k})`;`
327
+ * @param {number} t @param {number} t0 @param {{ freq?: number, zeta?: number }} [o]
328
+ */
329
+ export function spring(t, t0, { freq = 2.2, zeta = 0.45 } = {}) {
330
+ const x = t - t0;
331
+ if (x <= 0) return 0;
332
+ const w = 2 * Math.PI * freq;
333
+ if (zeta >= 1) return 1 - (1 + w * x) * Math.exp(-w * x);
334
+ const wd = w * Math.sqrt(1 - zeta * zeta);
335
+ return 1 - Math.exp(-zeta * w * x) * (Math.cos(wd * x) + ((zeta * w) / wd) * Math.sin(wd * x));
336
+ }
337
+
338
+ /**
339
+ * A damped swing about 0 from `amp` at t0: a tilt that overshoots and settles.
340
+ * The reference's dragged boxes: 21° → past 0 by ~24 % → upright, ζ ≈ 0.4.
341
+ * Holds `amp` before t0.
342
+ * `el.style.rotate = `${swing(t, T.drag, { amp: 18, freq: 0.9, zeta: 0.42 })}deg``
343
+ * @param {number} t @param {number} t0 @param {{ amp?: number, freq?: number, zeta?: number }} [o]
344
+ */
345
+ export function swing(t, t0, { amp = 10, freq = 1.1, zeta = 0.35 } = {}) {
346
+ if (t < t0) return amp;
347
+ const w = 2 * Math.PI * freq;
348
+ const x = t - t0;
349
+ return amp * Math.exp(-zeta * w * x) * Math.cos(w * Math.sqrt(1 - zeta * zeta) * x);
350
+ }
351
+
352
+ /**
353
+ * Flung in: from → to, fastest at t0, closing on its mark exponentially with
354
+ * time constant tau (s). The reference's cursor: 8600 px/s at first, tau ≈
355
+ * 0.14 s, settled in ~0.63 s. Numbers, arrays or flat objects.
356
+ * `const [x, y] = fling(t, T.cursorIn, [2100, 300], [960, 540], 0.14)`
357
+ * @param {number} t @param {number} t0 @param {Value} from @param {Value} to @param {number} [tau]
358
+ * @returns {Value}
359
+ */
360
+ export function fling(t, t0, from, to, tau = 0.14) {
361
+ if (from == null || to == null)
362
+ throw new Error(
363
+ "anim: fling(t, t0, from, to, tau) moves a value from `from` to `to` — given no from or to. " +
364
+ "The ease of the same shape, a progress 0..1 → 0..1 for keys or your own lerp, is ease.fling(u, tau)",
365
+ );
366
+ if (t <= t0) return from;
367
+ return mixv(from, to, 1 - Math.exp(-(t - t0) / tau));
368
+ }
369
+
370
+ /**
371
+ * A line rising into place: y offset dy → 0 on out5, opacity following the
372
+ * travel. The reference's section titles: up 35 px over ~14 frames, a second
373
+ * line 3 frames later. Returns { y, opacity, p }.
374
+ * `const r = rise(t, T.title + i * 0.125); line.style.transform = `translateY(${r.y}px)`; line.style.opacity = r.opacity;`
375
+ * @param {number} t @param {number} t0 @param {{ dy?: number, dur?: number }} [o]
376
+ */
377
+ export function rise(t, t0, { dy = 36, dur = 0.55 } = {}) {
378
+ const p = ease.out5(prog(t, t0, t0 + dur));
379
+ return { y: (1 - p) * dy, opacity: clamp(p * 1.6), p };
380
+ }
381
+
382
+ /**
383
+ * Leaving by accelerating (in3) along dx, dy until gone. The reference's
384
+ * outgoing scenes never fade (0.8–1.0 s, last frame ~6000 px/s); fade: true
385
+ * fades over the last 60 %. Returns { x, y, opacity, p }.
386
+ * `const e = exit(t, T.out, { dx: -2200, dur: 0.9 }); win.style.transform = `translateX(${e.x}px)`;`
387
+ * @param {number} t @param {number} t0
388
+ * @param {{ dx?: number, dy?: number, dur?: number, fade?: boolean, ease?: Ease | string }} [o]
389
+ */
390
+ export function exit(t, t0, { dx = 0, dy = 0, dur = 0.8, fade = false, ease: e = "in3" } = {}) {
391
+ const p = easeOf(e)(prog(t, t0, t0 + dur));
392
+ return { x: dx * p, y: dy * p, opacity: fade ? 1 - clamp((p - 0.4) / 0.6) : 1, p };
393
+ }
394
+
395
+ /**
396
+ * The part of `text` typed by t, from t0 at `cps` characters a second. The
397
+ * reference: a title word ~15–17 cps, a long prompt ~45–55 cps.
398
+ * `field.textContent = typeOn(t, T.type, "Red pandas, up close", 30)`
399
+ * @param {number} t @param {number} t0 @param {string} text @param {number} [cps]
400
+ */
401
+ export function typeOn(t, t0, text, cps = 20) {
402
+ const n = Math.floor(Math.max(0, t - t0) * cps);
403
+ return text.slice(0, Math.min(text.length, n));
404
+ }
405
+
406
+ /**
407
+ * A number counting a → b over dur from t0, on the measured count curve
408
+ * (never passing b), rounded to `digits` places.
409
+ * `kpi.textContent = fmt(count(t, T.result, 0.875, 0, 58500))`
410
+ * @param {number} t @param {number} t0 @param {number} dur @param {number} a @param {number} b
411
+ * @param {{ ease?: Ease | string, digits?: number }} [o]
412
+ */
413
+ export function count(t, t0, dur, a, b, { ease: e = "count", digits = 0 } = {}) {
414
+ const v = lerp(a, b, clamp(easeOf(e)(prog(t, t0, t0 + dur))));
415
+ const k = 10 ** digits;
416
+ return Math.round(v * k) / k;
417
+ }
418
+
419
+ /** a number with thousands separators. `fmt(2576)` → "2,576"; `fmt(3.14159, 1)` → "3.1" @param {number} n @param {number} [digits] */
420
+ export const fmt = (n, digits) =>
421
+ n.toLocaleString("en-US", digits == null ? undefined : { minimumFractionDigits: digits, maximumFractionDigits: digits });
422
+
423
+ /**
424
+ * A cursor going from target to target: marks = [{ t, at, travel?, ease?, bow? }],
425
+ * `at` an [x, y] or a function giving one (read every frame, so it follows a
426
+ * target that moves). It arrives on each mark at its t, travelling over the
427
+ * `travel` s before (default 0.5, ease inOut3), and bows sideways a little as
428
+ * a hand does (bow 0.08 of the distance). ease: "fling" for a flung cursor.
429
+ * `const [x, y] = pointer(t, [{ t: 0, at: [1500, 900] }, { t: 1.2, at: () => [knob.x, knob.y] }, { t: 2.4, at: [880, 610], ease: "fling", travel: 0.6 }])`
430
+ * To ride a moving target for a whole stretch (a drag), give that mark `ease: () => 1`.
431
+ * @typedef {{ t: number, at: [number, number] | (() => [number, number]), travel?: number, ease?: Ease | string, bow?: number }} Mark
432
+ * @param {number} t @param {Mark[]} marks
433
+ * @param {{ travel?: number, ease?: Ease | string, bow?: number }} [o]
434
+ * @returns {[number, number]}
435
+ */
436
+ export function pointer(t, marks, { travel = 0.5, ease: e = "inOut3", bow = 0.08 } = {}) {
437
+ const at = (/** @type {Mark} */ m) => (typeof m.at === "function" ? m.at() : m.at);
438
+ const first = /** @type {Mark} */ (marks[0]);
439
+ if (t <= first.t) return at(first);
440
+ for (let i = 1; i < marks.length; i++) {
441
+ const m = /** @type {Mark} */ (marks[i]);
442
+ if (t <= m.t) {
443
+ const prev = /** @type {Mark} */ (marks[i - 1]);
444
+ const start = Math.max(prev.t, m.t - (m.travel ?? travel));
445
+ const u = easeOf(m.ease ?? e)(prog(t, start, m.t));
446
+ const a = at(prev);
447
+ const b = at(m);
448
+ const dx = b[0] - a[0];
449
+ const dy = b[1] - a[1];
450
+ const k = (m.bow ?? bow) * Math.sin(Math.PI * u);
451
+ return [lerp(a[0], b[0], u) - dy * k, lerp(a[1], b[1], u) + dx * k];
452
+ }
453
+ }
454
+ return at(/** @type {Mark} */ (marks[marks.length - 1]));
455
+ }
456
+
457
+ /** a click's squash on the pressed thing (or the cursor): 1 → 0.86 → 1 in 0.2 s around t0. `btn.style.transform = `scale(${press(t, T.click)})`` @param {number} t @param {number} t0 */
458
+ export function press(t, t0) {
459
+ const d = t - t0;
460
+ if (d < -0.06 || d > 0.14) return 1;
461
+ return d < 0 ? 1 - (0.14 * (d + 0.06)) / 0.06 : 0.86 + (0.14 * d) / 0.14;
462
+ }
463
+
464
+ /**
465
+ * A 2D camera c = { x, y, s }: the world point (x, y) at the frame's centre,
466
+ * scaled s. Returns c with `css` (the transform for the world's element, with
467
+ * transform-origin 0 0) and `toScreen(x, y)` (where a world point is in the
468
+ * frame). Move it with keys: an `s` key mixes in log space.
469
+ * `const cam = cam2d(keys(t, camKeys)); world.style.transform = cam.css;`
470
+ * @param {{ x: number, y: number, s: number }} c @param {number} [w] @param {number} [h]
471
+ */
472
+ export function cam2d(c, w = 1920, h = 1080) {
473
+ return {
474
+ ...c,
475
+ css: `translate(${w / 2}px, ${h / 2}px) scale(${c.s}) translate(${-c.x}px, ${-c.y}px)`,
476
+ toScreen: (/** @type {number} */ px, /** @type {number} */ py) => [(px - c.x) * c.s + w / 2, (py - c.y) * c.s + h / 2],
477
+ };
478
+ }
479
+
480
+ // --- many things at once, and moves with a body ---------------------------------
481
+
482
+ /**
483
+ * When cell i of a grid (row by row, `cols` wide) starts, in s after the
484
+ * first: its distance from `from`, in cells, times `each`. `from` is
485
+ * "center", "start" (the first cell), "end" (the last), "edges" (outer cells
486
+ * first, the middle last), a cell's index, or [col, row]. `amount` instead of
487
+ * `each`: the whole spread, first to last, whatever the grid's size.
488
+ * Libraries mean different things by these: GSAP's grid `each` is the spread
489
+ * over the longest side, anime's is per cell; here `each` is per cell of
490
+ * distance and `amount` the total. `ease` bends the spread (default linear).
491
+ * The default `each` is the fly film's layer list growing a row every 2
492
+ * frames (11.5–13.25 s); a grid falls into place from the middle out.
493
+ * `const d = staggerGrid(i, 6, 4, { from: "center", each: 0.06 }); const r = rise(t, T.grid + d);`
494
+ * @param {number} i @param {number} cols @param {number} rows
495
+ * @param {{ from?: "center" | "start" | "end" | "edges" | number | [number, number], each?: number, amount?: number, ease?: Ease | string }} [o]
496
+ */
497
+ export function staggerGrid(i, cols, rows, { from = "center", each = 2 / 24, amount, ease: e = "linear" } = {}) {
498
+ const c = i % cols, r = Math.floor(i / cols);
499
+ const at = (/** @type {number} */ k) => [k % cols, Math.floor(k / cols)];
500
+ const corners = [[0, 0], [cols - 1, 0], [0, rows - 1], [cols - 1, rows - 1]];
501
+ /** distance of cell (x, y) from `from` @param {number} x @param {number} y */
502
+ const dist = (x, y) => {
503
+ if (from === "edges") return Math.min(x, y, cols - 1 - x, rows - 1 - y);
504
+ const [fx, fy] =
505
+ from === "center" ? [(cols - 1) / 2, (rows - 1) / 2]
506
+ : from === "start" ? [0, 0]
507
+ : from === "end" ? [cols - 1, rows - 1]
508
+ : typeof from === "number" ? at(from)
509
+ : from;
510
+ return Math.hypot(x - /** @type {number} */ (fx), y - /** @type {number} */ (fy));
511
+ };
512
+ let max = 0;
513
+ if (from === "edges") max = Math.floor((Math.min(cols, rows) - 1) / 2);
514
+ else for (const [x, y] of corners) max = Math.max(max, dist(/** @type {number} */ (x), /** @type {number} */ (y)));
515
+ const d = dist(c, r);
516
+ const span = amount ?? each * max;
517
+ return max > 0 ? span * easeOf(e)(d / max) : 0;
518
+ }
519
+
520
+ /**
521
+ * When item i of n starts, in s after the first, the gaps shrinking evenly
522
+ * (in ratio) from `first` to `last`: a run that speeds up as it goes. The
523
+ * fly film's packshot (47.6 s): 13 layers popping in at gaps of 8 frames
524
+ * down to 1; the app film's worker list: rows 0.5–0.65 s apart, then three
525
+ * in 0.3 s (14.6–14.9 s). A gap of 0 has no ratio: then the gaps change
526
+ * evenly from `first` to `last`.
527
+ * `layers.forEach((el, i) => { el.style.opacity = t >= T.pack + accelStagger(i, layers.length) ? 1 : 0; })`
528
+ * @param {number} i @param {number} n @param {{ first?: number, last?: number }} [o] gaps in s (default 8 and 1 frames at 24 fps)
529
+ */
530
+ export function accelStagger(i, n, { first = 8 / 24, last = 1 / 24 } = {}) {
531
+ let s = 0;
532
+ const k = Math.max(0, Math.min(i, n - 1));
533
+ const ratio = first > 0 && last > 0;
534
+ for (let j = 0; j < k; j++) {
535
+ const u = n <= 2 ? 0 : j / (n - 2);
536
+ s += ratio ? first * (last / first) ** u : lerp(first, last, u);
537
+ }
538
+ return s;
539
+ }
540
+
541
+ /**
542
+ * Split an element's text into pieces to move one by one: "chars", "words"
543
+ * or "lines" (lines as the text wraps now, so call it once its fonts are in).
544
+ * Returns the pieces, in order; spaces stay as text between them. With
545
+ * `mask`, each piece sits in a clip of its own height, so a piece moved down
546
+ * by its height is hidden and rises into view (`rise`). Calling it again
547
+ * splits the original text again. Build-time, not per frame: split once,
548
+ * then move the pieces in __render.
549
+ * `const words = split(title, { by: "lines", mask: true }); words.forEach((w, i) => { const r = rise(t, T.title + i * 0.1, { dy: 90 }); w.style.transform = `translateY(${r.y}px)`; });`
550
+ * @param {HTMLElement} el @param {{ by?: "chars" | "words" | "lines", mask?: boolean }} [o]
551
+ * @returns {HTMLElement[]}
552
+ */
553
+ export function split(el, { by = "words", mask = false } = {}) {
554
+ const doc = el.ownerDocument;
555
+ const text = el.dataset.splitText ?? el.textContent ?? "";
556
+ el.dataset.splitText = text;
557
+ el.textContent = "";
558
+ /** @param {string} cls @param {string} display */
559
+ const span = (cls, display) => {
560
+ const s = doc.createElement("span");
561
+ s.className = cls;
562
+ s.style.display = display;
563
+ return s;
564
+ };
565
+ /** a piece, in its mask if asked; returns the piece @param {HTMLElement} parent @param {string} txt @param {string} cls @param {string} display */
566
+ const piece = (parent, txt, cls, display) => {
567
+ const p = span(cls, display);
568
+ p.textContent = txt;
569
+ if (!mask) {
570
+ parent.appendChild(p);
571
+ return p;
572
+ }
573
+ const m = span(`${cls}-mask`, display);
574
+ m.style.overflow = "hidden";
575
+ m.style.verticalAlign = "top";
576
+ m.appendChild(p);
577
+ parent.appendChild(m);
578
+ return p;
579
+ };
580
+ const words = text.split(/(\s+)/);
581
+ if (by === "lines") {
582
+ // lay the words out, read where each line starts, then rebuild one block per line
583
+ /** @type {HTMLElement[]} */
584
+ const probes = [];
585
+ for (const w of words) {
586
+ if (/^\s+$/.test(w)) el.appendChild(doc.createTextNode(" "));
587
+ else if (w) {
588
+ const s = span("word", "inline");
589
+ s.textContent = w;
590
+ el.appendChild(s);
591
+ probes.push(s);
592
+ }
593
+ }
594
+ /** @type {string[][]} */
595
+ const lines = [];
596
+ let top = -Infinity;
597
+ for (const s of probes) {
598
+ if (s.offsetTop > top + 1) {
599
+ lines.push([]);
600
+ top = s.offsetTop;
601
+ }
602
+ /** @type {string[]} */ (lines[lines.length - 1]).push(s.textContent ?? "");
603
+ }
604
+ el.textContent = "";
605
+ return lines.map((ws) => piece(el, ws.join(" "), "line", "block"));
606
+ }
607
+ /** @type {HTMLElement[]} */
608
+ const out = [];
609
+ for (const w of words) {
610
+ if (!w) continue;
611
+ if (/^\s+$/.test(w)) {
612
+ el.appendChild(doc.createTextNode(" "));
613
+ continue;
614
+ }
615
+ if (by === "words") out.push(piece(el, w, "word", "inline-block"));
616
+ else {
617
+ // chars inside a word that does not break apart
618
+ const word = span("word", "inline-block");
619
+ el.appendChild(word);
620
+ for (const ch of Array.from(w)) out.push(piece(word, ch, "char", "inline-block"));
621
+ }
622
+ }
623
+ return out;
624
+ }
625
+
626
+ /**
627
+ * A value retargeted again and again: each change starts a spring from where
628
+ * the value is going to where it goes next, on top of the ones still
629
+ * settling, so a change mid-move bends the path instead of stopping it dead
630
+ * (a tween restarted from the current value drops its speed to 0 there).
631
+ * changes = [[t, value], …], times ascending; before the first, its value.
632
+ * Numbers, arrays or flat objects. Default freq 3.2 Hz, zeta 0.78: about 2 %
633
+ * past the mark. A tab indicator whose leading edge rides a faster spring
634
+ * than its trailing one stretches as it moves: two calls, freq 4.6 and 2.4.
635
+ * `const x = springs(t, [[0, 0], [1.0, 240], [1.22, 0], [1.6, 480]])`
636
+ * @param {number} t @param {[number, Value][]} changes @param {{ freq?: number, zeta?: number }} [o]
637
+ * @returns {Value}
638
+ */
639
+ export function springs(t, changes, { freq = 3.2, zeta = 0.78 } = {}) {
640
+ if (!changes.length) throw new Error("anim: springs(t, changes) needs at least one change, [[t, value], …]");
641
+ const first = /** @type {[number, Value]} */ (changes[0]);
642
+ let v = first[1];
643
+ for (let i = 1; i < changes.length; i++) {
644
+ const [ti, vi] = /** @type {[number, Value]} */ (changes[i]);
645
+ if (t <= ti) break;
646
+ const [, prev] = /** @type {[number, Value]} */ (changes[i - 1]);
647
+ const k = spring(t, ti, { freq, zeta });
648
+ v = addv(v, prev, vi, k);
649
+ }
650
+ return v;
651
+ }
652
+
653
+ /** v + (b − a)·k, for numbers, arrays or flat objects @param {Value} v @param {Value} a @param {Value} b @param {number} k @returns {Value} */
654
+ function addv(v, a, b, k) {
655
+ if (typeof v === "number") return v + (b - a) * k;
656
+ if (Array.isArray(v)) return v.map((x, i) => x + (b[i] - a[i]) * k);
657
+ /** @type {Record<string, number>} */
658
+ const o = {};
659
+ for (const key of Object.keys(v)) o[key] = v[key] + ((b[key] ?? a[key]) - a[key]) * k;
660
+ return o;
661
+ }
662
+
663
+ /**
664
+ * A move with a body: it winds up for `prep` s before t0 — back by `back` px,
665
+ * squashed, leaning away — then launches at t0, overshooting a little
666
+ * (back.out, `overshoot`) and stretched along the way, and lands with a
667
+ * small wobble. from, to: numbers (along x) or [x, y]. Every part is
668
+ * continuous through the launch (a frame from the wind-up and the next one
669
+ * from the launch never jump). Amounts are a card's, scaled down from a
670
+ * character's: back 30 px, squash 1.06 × 0.94, lean 2.5°, prep 0.4 s, launch
671
+ * 0.45 s, stretch 1.10 × 0.93, wobble 0.04. Kept small, it reads as weight;
672
+ * larger, as a cartoon. Returns { x, y, sx, sy, r (deg), p }.
673
+ * `const a = anticipate(t, T.send, { from: 230, to: 1290 }); card.style.transform = `translate(${a.x}px, ${a.y}px) rotate(${a.r}deg) scale(${a.sx}, ${a.sy})`;`
674
+ * @param {number} t @param {number} t0 the launch
675
+ * @param {{ from?: number | [number, number], to?: number | [number, number], back?: number, prep?: number, dur?: number,
676
+ * squash?: [number, number], stretch?: [number, number], lean?: number, overshoot?: number, wobble?: number }} [o]
677
+ */
678
+ export function anticipate(t, t0, o = {}) {
679
+ const {
680
+ from = 0, to = 0, back = 30, prep = 0.4, dur = 0.45, squash = [1.06, 0.94], stretch = [1.1, 0.93],
681
+ lean = 2.5, overshoot = 1.1, wobble = 0.04,
682
+ } = o;
683
+ /** @type {[number, number]} */
684
+ const A = typeof from === "number" ? [from, 0] : from;
685
+ /** @type {[number, number]} */
686
+ const B = typeof to === "number" ? [to, 0] : to;
687
+ const dx = B[0] - A[0], dy = B[1] - A[1];
688
+ const len = Math.hypot(dx, dy) || 1;
689
+ const ux = dx / len, uy = dy / len;
690
+ const side = ux < 0 ? -1 : 1; // leans away from where it goes
691
+ const w = ease.inOut2(prog(t, t0 - prep, t0)); // the wind-up
692
+ if (t < t0) {
693
+ return {
694
+ x: A[0] - ux * back * w, y: A[1] - uy * back * w,
695
+ sx: lerp(1, squash[0], w), sy: lerp(1, squash[1], w), r: -side * lean * w, p: 0,
696
+ };
697
+ }
698
+ const q = prog(t, t0, t0 + dur);
699
+ const g = /** @type {Ease} */ (gsapEase(`back.out(${overshoot})`));
700
+ const d = lerp(-back, len, g(q));
701
+ // squash → stretch over the first 30 %, stretch → 1 by 70 %; the lean eases out over the first 35 %
702
+ const s1 = ease.out2(prog(q, 0, 0.3)), s2 = ease.inOut2(prog(q, 0.3, 0.7));
703
+ let sx = q < 0.3 ? lerp(squash[0], stretch[0], s1) : lerp(stretch[0], 1, s2);
704
+ let sy = q < 0.3 ? lerp(squash[1], stretch[1], s1) : lerp(stretch[1], 1, s2);
705
+ const r = -side * lean * (1 - ease.out3(prog(q, 0, 0.35)));
706
+ if (t > t0 + dur) {
707
+ const k = t - t0 - dur;
708
+ const wob = wobble * Math.exp(-7 * k) * Math.sin(17 * k);
709
+ sx = 1 + wob;
710
+ sy = 1 - wob;
711
+ }
712
+ return { x: A[0] + ux * d, y: A[1] + uy * d, sx, sy, r, p: q };
713
+ }
714
+
715
+ /**
716
+ * A thing hanging from a moving one — a tag, a flag, a cable — swinging
717
+ * from the mover's acceleration: angle'' = −ω²·angle − c·angle' − gain·acc
718
+ * (ω 11 rad/s, c 5.5: it swings past twice and settles in about 2 s). The
719
+ * swing has a past, so it is integrated once, here, over [from, to] in
720
+ * 1/600 s steps into a table; the function it returns reads the table, so a
721
+ * frame drawn twice or out of order is the same. drive(t) is the mover's
722
+ * position (px, a number or [x, y]: the x is used, or `axis: "y"`). Returns
723
+ * the angle in degrees (gain in rad per px/s²: 0.001 swings a tag about 26°
724
+ * either way when a card crosses 1060 px in 0.45 s).
725
+ * `const tag = follow((t) => anticipate(t, T.send, { from: 230, to: 1290 }).x, { from: 0, to: 4 }); el.style.rotate = `${tag(t)}deg``
726
+ * @param {(t: number) => number | number[]} drive
727
+ * @param {{ from?: number, to?: number, omega?: number, damping?: number, gain?: number, axis?: "x" | "y", max?: number }} [o]
728
+ * max: the swing held inside ± this many degrees (default 63)
729
+ * @returns {(t: number) => number}
730
+ */
731
+ export function follow(drive, { from = 0, to = 10, omega = 11, damping = 5.5, gain = 0.001, axis = "x", max = 63 } = {}) {
732
+ if (!(to >= from))
733
+ throw new Error(`anim: follow's table runs from \`from\` to \`to\`, so \`to\` is not before \`from\` (got from ${from}, to ${to})`);
734
+ const dt = 1 / 600;
735
+ const n = Math.max(2, Math.ceil((to - from) / dt) + 1);
736
+ const tab = new Float64Array(n);
737
+ const pos = (/** @type {number} */ i) => {
738
+ const v = drive(from + i * dt);
739
+ return typeof v === "number" ? v : /** @type {number} */ (v[axis === "y" ? 1 : 0]);
740
+ };
741
+ let a = 0, v = 0;
742
+ let p0 = pos(-1), p1 = pos(0);
743
+ for (let i = 0; i < n; i++) {
744
+ const p2 = pos(i + 1);
745
+ const acc = (p2 - 2 * p1 + p0) / (dt * dt);
746
+ v += (-omega * omega * a - damping * v - gain * acc) * dt;
747
+ a += v * dt;
748
+ tab[i] = a;
749
+ p0 = p1;
750
+ p1 = p2;
751
+ }
752
+ const lim = (max * Math.PI) / 180;
753
+ return (t) => {
754
+ const x = (Math.min(Math.max(t, from), to) - from) / dt;
755
+ const i = Math.min(n - 2, Math.floor(x));
756
+ const u = x - i;
757
+ const rad = lerp(/** @type {number} */ (tab[i]), /** @type {number} */ (tab[i + 1]), u);
758
+ return (clamp(rad, -lim, lim) * 180) / Math.PI;
759
+ };
760
+ }