@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.
- package/dist/cdp-CzT5BKNY.js +3 -0
- package/dist/cdp-QXbQfXna.js +373 -0
- package/dist/cdp-QXbQfXna.js.map +1 -0
- package/dist/index.d.ts +4327 -195
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26282 -160
- package/dist/index.js.map +1 -1
- package/dist/server-841PMF2H.js +163 -0
- package/dist/server-841PMF2H.js.map +1 -0
- package/dist/server-C2aVv4-t.js +3 -0
- package/kit/audio.mjs +2366 -0
- package/kit/camera.js +587 -0
- package/kit/cursor.js +264 -0
- package/kit/cut.js +427 -0
- package/kit/draw.js +346 -0
- package/kit/look.js +589 -0
- package/kit/map.js +170 -0
- package/kit/media.js +3568 -0
- package/kit/motion.js +1115 -0
- package/kit/seams.js +1006 -0
- package/kit/stage.js +923 -0
- package/kit/time.js +812 -0
- package/kit/world.js +1072 -0
- package/package.json +7 -3
- package/src/ffmpeg.ts +63 -0
- package/src/film/beats.ts +1285 -0
- package/src/film/carry.ts +221 -0
- package/src/film/changes.ts +330 -0
- package/src/film/check.ts +996 -0
- package/src/film/clock.ts +2530 -0
- package/src/film/components-probe.ts +809 -0
- package/src/film/components.ts +1566 -0
- package/src/film/frames.ts +389 -0
- package/src/film/gallery.ts +3276 -0
- package/src/film/kit.ts +515 -0
- package/src/film/layout.ts +701 -0
- package/src/film/listen.ts +1979 -0
- package/src/film/look.ts +3829 -0
- package/src/film/materials.ts +976 -0
- package/src/film/moving.ts +248 -0
- package/src/film/part-files.ts +729 -0
- package/src/film/picture.ts +74 -0
- package/src/film/probe-text.ts +843 -0
- package/src/film/probe.ts +3456 -0
- package/src/film/provenance.ts +596 -0
- package/src/film/render.ts +2447 -0
- package/src/film/report.ts +1631 -0
- package/src/film/sheet.ts +156 -0
- package/src/film/study-declared.ts +123 -0
- package/src/film/study-picture.ts +791 -0
- package/src/film/study-sound.ts +416 -0
- package/src/film/study.ts +864 -0
- package/src/film/tuning.ts +155 -0
- package/src/film/viewer.ts +174 -0
- package/src/html/cdp.ts +575 -0
- package/src/html/server.ts +208 -0
- package/src/index.ts +202 -0
- package/src/launch-render.ts +3 -2
- package/src/math.ts +3 -3
- package/src/mjpeg-matroska.ts +228 -0
- package/src/render.ts +6 -4
- package/src/state-diff.ts +215 -0
- package/src/state-index.ts +99 -0
- package/src/types.ts +59 -1
- package/starter/PLAN.md +84 -0
- package/starter/START.md +460 -0
- package/starter/lib/anim.js +760 -0
- package/starter/lib/devices.js +1402 -0
- package/starter/lib/handoff.js +421 -0
- package/starter/lib/hud.js +1879 -0
- package/starter/lib/measure.mjs +154 -0
- package/starter/lib/moves.js +1095 -0
- package/starter/lib/palette.mjs +803 -0
- package/starter/lib/physics-seeds.mjs +198 -0
- package/starter/lib/physics.js +738 -0
- package/starter/lib/sampler.mjs +242 -0
- package/starter/lib/solid.js +727 -0
- package/starter/lib/space.js +1227 -0
- package/starter/lib/swarm.js +1398 -0
- package/starter/reference/motion.md +276 -0
- package/starter/reference/structure.md +466 -0
- package/starter/reference/travel/motion.md +433 -0
- package/starter/reference/travel/sound.md +241 -0
- package/starter/reference/travel/structure.md +518 -0
- package/starter/samples/NOTICE.txt +55 -0
- package/starter/samples/celli/celli_24_1.opus +0 -0
- package/starter/samples/celli/celli_24_3.opus +0 -0
- package/starter/samples/celli/celli_28_1.opus +0 -0
- package/starter/samples/celli/celli_28_3.opus +0 -0
- package/starter/samples/celli/celli_31_1.opus +0 -0
- package/starter/samples/celli/celli_31_3.opus +0 -0
- package/starter/samples/celli/celli_35_1.opus +0 -0
- package/starter/samples/celli/celli_35_3.opus +0 -0
- package/starter/samples/celli/celli_38_1.opus +0 -0
- package/starter/samples/celli/celli_38_3.opus +0 -0
- package/starter/samples/celli/celli_41_1.opus +0 -0
- package/starter/samples/celli/celli_41_3.opus +0 -0
- package/starter/samples/celli/celli_45_1.opus +0 -0
- package/starter/samples/celli/celli_45_3.opus +0 -0
- package/starter/samples/celli/celli_48_1.opus +0 -0
- package/starter/samples/celli/celli_48_3.opus +0 -0
- package/starter/samples/celli/celli_52_1.opus +0 -0
- package/starter/samples/celli/celli_52_3.opus +0 -0
- package/starter/samples/celli/celli_55_1.opus +0 -0
- package/starter/samples/celli/celli_55_3.opus +0 -0
- package/starter/samples/celli/celli_59_1.opus +0 -0
- package/starter/samples/celli/celli_59_3.opus +0 -0
- package/starter/samples/celli/celli_62_1.opus +0 -0
- package/starter/samples/celli/celli_62_3.opus +0 -0
- package/starter/samples/celli/celli_65_1.opus +0 -0
- package/starter/samples/celli/celli_65_3.opus +0 -0
- package/starter/samples/crash/crash_f_1.flac +0 -0
- package/starter/samples/crash/crash_fff_1.flac +0 -0
- package/starter/samples/ebass/ebass_0_x.flac +0 -0
- package/starter/samples/ebass/ebass_10_x.flac +0 -0
- package/starter/samples/ebass/ebass_11_x.flac +0 -0
- package/starter/samples/ebass/ebass_1_x.flac +0 -0
- package/starter/samples/ebass/ebass_2_x.flac +0 -0
- package/starter/samples/ebass/ebass_3_x.flac +0 -0
- package/starter/samples/ebass/ebass_4_x.flac +0 -0
- package/starter/samples/ebass/ebass_5_x.flac +0 -0
- package/starter/samples/ebass/ebass_6_x.flac +0 -0
- package/starter/samples/ebass/ebass_7_x.flac +0 -0
- package/starter/samples/ebass/ebass_8_x.flac +0 -0
- package/starter/samples/ebass/ebass_9_x.flac +0 -0
- package/starter/samples/ek_clap/ek_clap_1_1.flac +0 -0
- package/starter/samples/ek_hat/ek_hat_1_1.flac +0 -0
- package/starter/samples/ek_hat/ek_hat_1_2.flac +0 -0
- package/starter/samples/ek_kick/ek_kick_1_1.flac +0 -0
- package/starter/samples/ek_kick/ek_kick_1_2.flac +0 -0
- package/starter/samples/glock/glock_67_x.flac +0 -0
- package/starter/samples/glock/glock_72_x.flac +0 -0
- package/starter/samples/glock/glock_79_x.flac +0 -0
- package/starter/samples/glock/glock_84_x.flac +0 -0
- package/starter/samples/glock/glock_91_x.flac +0 -0
- package/starter/samples/glock/glock_96_x.flac +0 -0
- package/starter/samples/harp/harp_101_f.opus +0 -0
- package/starter/samples/harp/harp_28_f.opus +0 -0
- package/starter/samples/harp/harp_31_mp.opus +0 -0
- package/starter/samples/harp/harp_35_mf.opus +0 -0
- package/starter/samples/harp/harp_38_mf.opus +0 -0
- package/starter/samples/harp/harp_41_mf.opus +0 -0
- package/starter/samples/harp/harp_45_mf.opus +0 -0
- package/starter/samples/harp/harp_48_mf.opus +0 -0
- package/starter/samples/harp/harp_52_mf.opus +0 -0
- package/starter/samples/harp/harp_55_mf.opus +0 -0
- package/starter/samples/harp/harp_59_mf.opus +0 -0
- package/starter/samples/harp/harp_62_mf.opus +0 -0
- package/starter/samples/harp/harp_65_mf.opus +0 -0
- package/starter/samples/harp/harp_69_mf.opus +0 -0
- package/starter/samples/harp/harp_72_mf.opus +0 -0
- package/starter/samples/harp/harp_76_mf.opus +0 -0
- package/starter/samples/harp/harp_79_mf.opus +0 -0
- package/starter/samples/harp/harp_83_mf.opus +0 -0
- package/starter/samples/harp/harp_86_mf.opus +0 -0
- package/starter/samples/harp/harp_89_mf.opus +0 -0
- package/starter/samples/harp/harp_93_mf.opus +0 -0
- package/starter/samples/harp/harp_95_mf.opus +0 -0
- package/starter/samples/harp/harp_98_f.opus +0 -0
- package/starter/samples/manifest.json +2951 -0
- package/starter/samples/marimba/marimba_29_x.flac +0 -0
- package/starter/samples/marimba/marimba_36_x.flac +0 -0
- package/starter/samples/marimba/marimba_43_x.flac +0 -0
- package/starter/samples/marimba/marimba_47_x.flac +0 -0
- package/starter/samples/marimba/marimba_53_x.flac +0 -0
- package/starter/samples/marimba/marimba_60_x.flac +0 -0
- package/starter/samples/marimba/marimba_67_x.flac +0 -0
- package/starter/samples/marimba/marimba_71_x.flac +0 -0
- package/starter/samples/marimba/marimba_77_x.flac +0 -0
- package/starter/samples/marimba/marimba_84_x.flac +0 -0
- package/starter/samples/piano/piano_102_12.opus +0 -0
- package/starter/samples/piano/piano_102_16.opus +0 -0
- package/starter/samples/piano/piano_102_4.opus +0 -0
- package/starter/samples/piano/piano_102_8.opus +0 -0
- package/starter/samples/piano/piano_105_12.opus +0 -0
- package/starter/samples/piano/piano_105_16.opus +0 -0
- package/starter/samples/piano/piano_105_4.opus +0 -0
- package/starter/samples/piano/piano_105_8.opus +0 -0
- package/starter/samples/piano/piano_108_12.opus +0 -0
- package/starter/samples/piano/piano_108_16.opus +0 -0
- package/starter/samples/piano/piano_108_4.opus +0 -0
- package/starter/samples/piano/piano_108_8.opus +0 -0
- package/starter/samples/piano/piano_21_12.opus +0 -0
- package/starter/samples/piano/piano_21_16.opus +0 -0
- package/starter/samples/piano/piano_21_4.opus +0 -0
- package/starter/samples/piano/piano_21_8.opus +0 -0
- package/starter/samples/piano/piano_24_12.opus +0 -0
- package/starter/samples/piano/piano_24_16.opus +0 -0
- package/starter/samples/piano/piano_24_4.opus +0 -0
- package/starter/samples/piano/piano_24_8.opus +0 -0
- package/starter/samples/piano/piano_27_12.opus +0 -0
- package/starter/samples/piano/piano_27_16.opus +0 -0
- package/starter/samples/piano/piano_27_4.opus +0 -0
- package/starter/samples/piano/piano_27_8.opus +0 -0
- package/starter/samples/piano/piano_30_12.opus +0 -0
- package/starter/samples/piano/piano_30_16.opus +0 -0
- package/starter/samples/piano/piano_30_4.opus +0 -0
- package/starter/samples/piano/piano_30_8.opus +0 -0
- package/starter/samples/piano/piano_33_12.opus +0 -0
- package/starter/samples/piano/piano_33_16.opus +0 -0
- package/starter/samples/piano/piano_33_4.opus +0 -0
- package/starter/samples/piano/piano_33_8.opus +0 -0
- package/starter/samples/piano/piano_36_12.opus +0 -0
- package/starter/samples/piano/piano_36_16.opus +0 -0
- package/starter/samples/piano/piano_36_4.opus +0 -0
- package/starter/samples/piano/piano_36_8.opus +0 -0
- package/starter/samples/piano/piano_39_12.opus +0 -0
- package/starter/samples/piano/piano_39_16.opus +0 -0
- package/starter/samples/piano/piano_39_4.opus +0 -0
- package/starter/samples/piano/piano_39_8.opus +0 -0
- package/starter/samples/piano/piano_42_12.opus +0 -0
- package/starter/samples/piano/piano_42_16.opus +0 -0
- package/starter/samples/piano/piano_42_4.opus +0 -0
- package/starter/samples/piano/piano_42_8.opus +0 -0
- package/starter/samples/piano/piano_45_12.opus +0 -0
- package/starter/samples/piano/piano_45_16.opus +0 -0
- package/starter/samples/piano/piano_45_4.opus +0 -0
- package/starter/samples/piano/piano_45_8.opus +0 -0
- package/starter/samples/piano/piano_48_12.opus +0 -0
- package/starter/samples/piano/piano_48_16.opus +0 -0
- package/starter/samples/piano/piano_48_4.opus +0 -0
- package/starter/samples/piano/piano_48_8.opus +0 -0
- package/starter/samples/piano/piano_51_12.opus +0 -0
- package/starter/samples/piano/piano_51_16.opus +0 -0
- package/starter/samples/piano/piano_51_4.opus +0 -0
- package/starter/samples/piano/piano_51_8.opus +0 -0
- package/starter/samples/piano/piano_54_12.opus +0 -0
- package/starter/samples/piano/piano_54_16.opus +0 -0
- package/starter/samples/piano/piano_54_4.opus +0 -0
- package/starter/samples/piano/piano_54_8.opus +0 -0
- package/starter/samples/piano/piano_57_12.opus +0 -0
- package/starter/samples/piano/piano_57_16.opus +0 -0
- package/starter/samples/piano/piano_57_4.opus +0 -0
- package/starter/samples/piano/piano_57_8.opus +0 -0
- package/starter/samples/piano/piano_60_12.opus +0 -0
- package/starter/samples/piano/piano_60_16.opus +0 -0
- package/starter/samples/piano/piano_60_4.opus +0 -0
- package/starter/samples/piano/piano_60_8.opus +0 -0
- package/starter/samples/piano/piano_63_12.opus +0 -0
- package/starter/samples/piano/piano_63_16.opus +0 -0
- package/starter/samples/piano/piano_63_4.opus +0 -0
- package/starter/samples/piano/piano_63_8.opus +0 -0
- package/starter/samples/piano/piano_66_12.opus +0 -0
- package/starter/samples/piano/piano_66_16.opus +0 -0
- package/starter/samples/piano/piano_66_4.opus +0 -0
- package/starter/samples/piano/piano_66_8.opus +0 -0
- package/starter/samples/piano/piano_69_12.opus +0 -0
- package/starter/samples/piano/piano_69_16.opus +0 -0
- package/starter/samples/piano/piano_69_4.opus +0 -0
- package/starter/samples/piano/piano_69_8.opus +0 -0
- package/starter/samples/piano/piano_72_12.opus +0 -0
- package/starter/samples/piano/piano_72_16.opus +0 -0
- package/starter/samples/piano/piano_72_4.opus +0 -0
- package/starter/samples/piano/piano_72_8.opus +0 -0
- package/starter/samples/piano/piano_75_12.opus +0 -0
- package/starter/samples/piano/piano_75_16.opus +0 -0
- package/starter/samples/piano/piano_75_4.opus +0 -0
- package/starter/samples/piano/piano_75_8.opus +0 -0
- package/starter/samples/piano/piano_78_12.opus +0 -0
- package/starter/samples/piano/piano_78_16.opus +0 -0
- package/starter/samples/piano/piano_78_4.opus +0 -0
- package/starter/samples/piano/piano_78_8.opus +0 -0
- package/starter/samples/piano/piano_81_12.opus +0 -0
- package/starter/samples/piano/piano_81_16.opus +0 -0
- package/starter/samples/piano/piano_81_4.opus +0 -0
- package/starter/samples/piano/piano_81_8.opus +0 -0
- package/starter/samples/piano/piano_84_12.opus +0 -0
- package/starter/samples/piano/piano_84_16.opus +0 -0
- package/starter/samples/piano/piano_84_4.opus +0 -0
- package/starter/samples/piano/piano_84_8.opus +0 -0
- package/starter/samples/piano/piano_87_12.opus +0 -0
- package/starter/samples/piano/piano_87_16.opus +0 -0
- package/starter/samples/piano/piano_87_4.opus +0 -0
- package/starter/samples/piano/piano_87_8.opus +0 -0
- package/starter/samples/piano/piano_90_12.opus +0 -0
- package/starter/samples/piano/piano_90_16.opus +0 -0
- package/starter/samples/piano/piano_90_4.opus +0 -0
- package/starter/samples/piano/piano_90_8.opus +0 -0
- package/starter/samples/piano/piano_93_12.opus +0 -0
- package/starter/samples/piano/piano_93_16.opus +0 -0
- package/starter/samples/piano/piano_93_4.opus +0 -0
- package/starter/samples/piano/piano_93_8.opus +0 -0
- package/starter/samples/piano/piano_96_12.opus +0 -0
- package/starter/samples/piano/piano_96_16.opus +0 -0
- package/starter/samples/piano/piano_96_4.opus +0 -0
- package/starter/samples/piano/piano_96_8.opus +0 -0
- package/starter/samples/piano/piano_99_12.opus +0 -0
- package/starter/samples/piano/piano_99_16.opus +0 -0
- package/starter/samples/piano/piano_99_4.opus +0 -0
- package/starter/samples/piano/piano_99_8.opus +0 -0
- package/starter/samples/piano/piano_rel_102_x.opus +0 -0
- package/starter/samples/piano/piano_rel_105_x.opus +0 -0
- package/starter/samples/piano/piano_rel_108_x.opus +0 -0
- package/starter/samples/piano/piano_rel_21_x.opus +0 -0
- package/starter/samples/piano/piano_rel_24_x.opus +0 -0
- package/starter/samples/piano/piano_rel_27_x.opus +0 -0
- package/starter/samples/piano/piano_rel_30_x.opus +0 -0
- package/starter/samples/piano/piano_rel_33_x.opus +0 -0
- package/starter/samples/piano/piano_rel_36_x.opus +0 -0
- package/starter/samples/piano/piano_rel_39_x.opus +0 -0
- package/starter/samples/piano/piano_rel_42_x.opus +0 -0
- package/starter/samples/piano/piano_rel_45_x.opus +0 -0
- package/starter/samples/piano/piano_rel_48_x.opus +0 -0
- package/starter/samples/piano/piano_rel_51_x.opus +0 -0
- package/starter/samples/piano/piano_rel_54_x.opus +0 -0
- package/starter/samples/piano/piano_rel_57_x.opus +0 -0
- package/starter/samples/piano/piano_rel_60_x.opus +0 -0
- package/starter/samples/piano/piano_rel_63_x.opus +0 -0
- package/starter/samples/piano/piano_rel_66_x.opus +0 -0
- package/starter/samples/piano/piano_rel_69_x.opus +0 -0
- package/starter/samples/piano/piano_rel_72_x.opus +0 -0
- package/starter/samples/piano/piano_rel_75_x.opus +0 -0
- package/starter/samples/piano/piano_rel_78_x.opus +0 -0
- package/starter/samples/piano/piano_rel_81_x.opus +0 -0
- package/starter/samples/piano/piano_rel_84_x.opus +0 -0
- package/starter/samples/piano/piano_rel_87_x.opus +0 -0
- package/starter/samples/piano/piano_rel_90_x.opus +0 -0
- package/starter/samples/piano/piano_rel_93_x.opus +0 -0
- package/starter/samples/piano/piano_rel_96_x.opus +0 -0
- package/starter/samples/piano/piano_rel_99_x.opus +0 -0
- package/starter/samples/pizz/pizz_24_2.flac +0 -0
- package/starter/samples/pizz/pizz_28_2.flac +0 -0
- package/starter/samples/pizz/pizz_31_2.flac +0 -0
- package/starter/samples/pizz/pizz_35_2.flac +0 -0
- package/starter/samples/pizz/pizz_38_2.flac +0 -0
- package/starter/samples/pizz/pizz_41_2.flac +0 -0
- package/starter/samples/pizz/pizz_45_2.flac +0 -0
- package/starter/samples/pizz/pizz_48_2.flac +0 -0
- package/starter/samples/pizz/pizz_52_2.flac +0 -0
- package/starter/samples/pizz/pizz_57_2.flac +0 -0
- package/starter/samples/pizz/pizz_60_2.flac +0 -0
- package/starter/samples/pizz/pizz_64_2.flac +0 -0
- package/starter/samples/pizz/pizz_67_2.flac +0 -0
- package/starter/samples/pizz/pizz_71_2.flac +0 -0
- package/starter/samples/pizz/pizz_74_2.flac +0 -0
- package/starter/samples/pk_hat/pk_hat_2_1.flac +0 -0
- package/starter/samples/pk_hat/pk_hat_2_2.flac +0 -0
- package/starter/samples/pk_hat/pk_hat_6_1.flac +0 -0
- package/starter/samples/pk_hat/pk_hat_6_2.flac +0 -0
- package/starter/samples/pk_kick/pk_kick_3_1.flac +0 -0
- package/starter/samples/pk_kick/pk_kick_3_2.flac +0 -0
- package/starter/samples/pk_kick/pk_kick_7_1.flac +0 -0
- package/starter/samples/pk_kick/pk_kick_7_2.flac +0 -0
- package/starter/samples/pk_ohat/pk_ohat_3_1.flac +0 -0
- package/starter/samples/pk_ohat/pk_ohat_3_2.flac +0 -0
- package/starter/samples/pk_ohat/pk_ohat_6_1.flac +0 -0
- package/starter/samples/pk_ohat/pk_ohat_6_2.flac +0 -0
- package/starter/samples/pk_rim/pk_rim_2_1.flac +0 -0
- package/starter/samples/pk_rim/pk_rim_2_2.flac +0 -0
- package/starter/samples/pk_rim/pk_rim_5_1.flac +0 -0
- package/starter/samples/pk_rim/pk_rim_5_2.flac +0 -0
- package/starter/samples/pk_snare/pk_snare_3_1.flac +0 -0
- package/starter/samples/pk_snare/pk_snare_3_2.flac +0 -0
- package/starter/samples/pk_snare/pk_snare_7_1.flac +0 -0
- package/starter/samples/pk_snare/pk_snare_7_2.flac +0 -0
- package/starter/samples/shaker/shaker_1_1.flac +0 -0
- package/starter/samples/shaker/shaker_2_1.flac +0 -0
- package/starter/samples/snap/snap_r_1.flac +0 -0
- package/starter/samples/snap/snap_r_2.flac +0 -0
- package/starter/samples/snap/snap_r_3.flac +0 -0
- package/starter/samples/snap/snap_r_4.flac +0 -0
- package/starter/samples/snap/snap_r_5.flac +0 -0
- package/starter/samples/snap/snap_r_6.flac +0 -0
- package/starter/samples/tom/tom_3_1.flac +0 -0
- package/starter/samples/tom/tom_3_2.flac +0 -0
- package/starter/samples/tom/tom_4_1.flac +0 -0
- package/starter/samples/tom/tom_4_2.flac +0 -0
- package/starter/samples/vibes/vibes_41_1.opus +0 -0
- package/starter/samples/vibes/vibes_41_2.opus +0 -0
- package/starter/samples/vibes/vibes_45_1.opus +0 -0
- package/starter/samples/vibes/vibes_45_2.opus +0 -0
- package/starter/samples/vibes/vibes_48_1.opus +0 -0
- package/starter/samples/vibes/vibes_48_2.opus +0 -0
- package/starter/samples/vibes/vibes_52_1.opus +0 -0
- package/starter/samples/vibes/vibes_52_2.opus +0 -0
- package/starter/samples/vibes/vibes_55_1.opus +0 -0
- package/starter/samples/vibes/vibes_55_2.opus +0 -0
- package/starter/samples/vibes/vibes_59_1.opus +0 -0
- package/starter/samples/vibes/vibes_59_2.opus +0 -0
- package/starter/samples/vibes/vibes_62_1.opus +0 -0
- package/starter/samples/vibes/vibes_62_2.opus +0 -0
- package/starter/samples/vibes/vibes_65_1.opus +0 -0
- package/starter/samples/vibes/vibes_65_2.opus +0 -0
- package/starter/samples/vibes/vibes_69_1.opus +0 -0
- package/starter/samples/vibes/vibes_69_2.opus +0 -0
- package/starter/samples/vibes/vibes_72_1.opus +0 -0
- package/starter/samples/vibes/vibes_72_2.opus +0 -0
- package/starter/samples/vibes/vibes_76_1.opus +0 -0
- package/starter/samples/vibes/vibes_76_2.opus +0 -0
- package/starter/samples/violas/violas_36_1.opus +0 -0
- package/starter/samples/violas/violas_36_2.opus +0 -0
- package/starter/samples/violas/violas_38_1.opus +0 -0
- package/starter/samples/violas/violas_38_2.opus +0 -0
- package/starter/samples/violas/violas_40_1.opus +0 -0
- package/starter/samples/violas/violas_40_2.opus +0 -0
- package/starter/samples/violas/violas_43_1.opus +0 -0
- package/starter/samples/violas/violas_43_2.opus +0 -0
- package/starter/samples/violas/violas_47_1.opus +0 -0
- package/starter/samples/violas/violas_47_2.opus +0 -0
- package/starter/samples/violas/violas_50_1.opus +0 -0
- package/starter/samples/violas/violas_50_2.opus +0 -0
- package/starter/samples/violas/violas_53_1.opus +0 -0
- package/starter/samples/violas/violas_53_2.opus +0 -0
- package/starter/samples/violas/violas_57_1.opus +0 -0
- package/starter/samples/violas/violas_57_2.opus +0 -0
- package/starter/samples/violas/violas_60_1.opus +0 -0
- package/starter/samples/violas/violas_60_2.opus +0 -0
- package/starter/samples/violas/violas_64_1.opus +0 -0
- package/starter/samples/violas/violas_64_2.opus +0 -0
- package/starter/samples/violas/violas_67_1.opus +0 -0
- package/starter/samples/violas/violas_67_2.opus +0 -0
- package/starter/samples/violas/violas_71_1.opus +0 -0
- package/starter/samples/violas/violas_71_2.opus +0 -0
- package/starter/samples/violas/violas_74_1.opus +0 -0
- package/starter/samples/violas/violas_74_2.opus +0 -0
- package/starter/samples/violins/violins_43_1.opus +0 -0
- package/starter/samples/violins/violins_43_2.opus +0 -0
- package/starter/samples/violins/violins_45_1.opus +0 -0
- package/starter/samples/violins/violins_45_2.opus +0 -0
- package/starter/samples/violins/violins_47_1.opus +0 -0
- package/starter/samples/violins/violins_47_2.opus +0 -0
- package/starter/samples/violins/violins_50_1.opus +0 -0
- package/starter/samples/violins/violins_50_2.opus +0 -0
- package/starter/samples/violins/violins_54_1.opus +0 -0
- package/starter/samples/violins/violins_54_2.opus +0 -0
- package/starter/samples/violins/violins_57_1.opus +0 -0
- package/starter/samples/violins/violins_57_2.opus +0 -0
- package/starter/samples/violins/violins_60_1.opus +0 -0
- package/starter/samples/violins/violins_60_2.opus +0 -0
- package/starter/samples/violins/violins_64_1.opus +0 -0
- package/starter/samples/violins/violins_64_2.opus +0 -0
- package/starter/samples/violins/violins_67_1.opus +0 -0
- package/starter/samples/violins/violins_67_2.opus +0 -0
- package/starter/samples/violins/violins_71_1.opus +0 -0
- package/starter/samples/violins/violins_71_2.opus +0 -0
- package/starter/samples/violins/violins_74_1.opus +0 -0
- package/starter/samples/violins/violins_74_2.opus +0 -0
- package/starter/samples/woodblock/woodblock_f_1.flac +0 -0
- package/starter/samples/woodblock/woodblock_f_2.flac +0 -0
package/kit/camera.js
ADDED
|
@@ -0,0 +1,587 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// A camera for a film page — open-take's film kit. You say when to see what;
|
|
3
|
+
// the camera works out how to get there. The motion is open-take's take
|
|
4
|
+
// camera, the one tuned by eye on recordings:
|
|
5
|
+
//
|
|
6
|
+
// - the VIEW moves (its centre and its width together), so whatever is
|
|
7
|
+
// framed heads for its place in a straight line and never swings the
|
|
8
|
+
// wrong way first — moving the centre and the zoom separately does;
|
|
9
|
+
// - a view is kept inside the content once, when you ask for it, never
|
|
10
|
+
// mid-move (a clamp applied every frame bends the path: the camera stops
|
|
11
|
+
// short, then lurches back);
|
|
12
|
+
// - a move covers 96 % of the way in its time and settles the rest into the
|
|
13
|
+
// hold, and the next move starts from wherever the camera really is — no
|
|
14
|
+
// stop, no jolt.
|
|
15
|
+
//
|
|
16
|
+
// The defaults are measured (in 0.73 s, out 1.34 s; what is framed fills 60 %
|
|
17
|
+
// of the picture). Every move can set its own duration and curve — a fast
|
|
18
|
+
// push, a whip, a slow drift are yours to choose. One flat layer, seen through
|
|
19
|
+
// a 2D camera: for 3D, kit/stage.js takes this camera (its view frames the
|
|
20
|
+
// stage), or read at(t) and project it yourself.
|
|
21
|
+
//
|
|
22
|
+
// More is there when you ask for it, all of it off until you do: a camera
|
|
23
|
+
// that gets there early (`lead`), a hand holding it (`handheld`), a jolt on
|
|
24
|
+
// an impact (`shake`), layers that move at their own rate (`depth`), a zoom
|
|
25
|
+
// that runs at an even pace over big scale changes (`zoom: "log"`), and a view
|
|
26
|
+
// left free to go past the content (`keepInside: false`).
|
|
27
|
+
//
|
|
28
|
+
// const cam = camera({ content: { width: 1920, height: 1080 } });
|
|
29
|
+
// cam.frame(box, { arrive: 12 }); // framed by 12 s
|
|
30
|
+
// cam.frame(other, { start: 15, dur: 0.3, ease: (p) => p * p });
|
|
31
|
+
// cam.cut(third, 20); // a cut: no move
|
|
32
|
+
// layer.style.transformOrigin = "0 0";
|
|
33
|
+
// layer.style.transform = cam.transform(t); // in __render(t)
|
|
34
|
+
|
|
35
|
+
/** @typedef {{ x: number, y: number, width: number, height: number }} Box a region of the content, in its CSS px */
|
|
36
|
+
/** @typedef {{ cx: number, cy: number, w: number }} View what the picture shows: its centre and width, in content px */
|
|
37
|
+
/** @typedef {{ boxAt: (t: number) => Box, name?: string, used?: (use: string, t: number) => unknown }} PartLike a part of the product (kit/media.js product()): framed where it is when the move lands */
|
|
38
|
+
/**
|
|
39
|
+
* @typedef {object} When when a move happens — one of `arrive` or `start`
|
|
40
|
+
* @property {number} [arrive] the move lands here (s)
|
|
41
|
+
* @property {number} [start] the move leaves here (s)
|
|
42
|
+
* @property {number} [dur] how long it takes (s); default 0.73 in, 1.34 out
|
|
43
|
+
* @property {(p: number) => number} [ease] progress 0..1 over the move; default: settle into the hold
|
|
44
|
+
* @property {number} [fill] the share of the picture a framed box fills (default 0.6)
|
|
45
|
+
* @property {"contain" | "width"} [fit] fit the box whole (default), or its width only — a tall box is then framed from its top
|
|
46
|
+
* @property {number} [lead] this move leaves and lands this much earlier (s); default: the camera's `lead`
|
|
47
|
+
* @property {boolean} [keepInside] keep this view inside the content; default: the camera's `keepInside`
|
|
48
|
+
* @property {"linear" | "log"} [zoom] how this move's width changes; default: the camera's `zoom`
|
|
49
|
+
*/
|
|
50
|
+
/**
|
|
51
|
+
* @typedef {object} Handheld a hand on the camera: a slow, smooth wander that never repeats
|
|
52
|
+
* @property {number} [amp] how far it wanders, in picture px (default 3)
|
|
53
|
+
* @property {number} [rot] how far it tilts, in degrees (default 0)
|
|
54
|
+
* @property {number} [period] about how long between turns (s, default 2.5)
|
|
55
|
+
* @property {number} [seed] another seed, another hand (default 1)
|
|
56
|
+
*/
|
|
57
|
+
/**
|
|
58
|
+
* @typedef {object} Shake a jolt that dies away
|
|
59
|
+
* @property {number} [amp] how far it throws the picture at first, in px (default 10)
|
|
60
|
+
* @property {number} [rot] how far it tilts at first, in degrees (default 0)
|
|
61
|
+
* @property {number} [dur] how long until it is still (s, default 0.45)
|
|
62
|
+
* @property {number} [freq] how fast it rattles (about this many turns a second, default 16)
|
|
63
|
+
* @property {number} [seed] another seed, another jolt (default: one per shake)
|
|
64
|
+
*/
|
|
65
|
+
/** @typedef {{ x: number, y: number, rot: number }} Jitter what the hand and the shakes add at t: picture px, degrees */
|
|
66
|
+
/**
|
|
67
|
+
* @typedef {object} Move
|
|
68
|
+
* @property {"move" | "cut"} kind
|
|
69
|
+
* @property {number} t0
|
|
70
|
+
* @property {number} t1
|
|
71
|
+
* @property {View} to
|
|
72
|
+
* @property {((p: number) => number) | null} ease
|
|
73
|
+
* @property {string} label
|
|
74
|
+
* @property {true} [free] left free to go past the content
|
|
75
|
+
* @property {true} [log] its width changes at an even pace in log space
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
/** what is left of a move at progress u (0 at its start, 0.04 at its end, still
|
|
79
|
+
* decaying after): the step response of an overdamped spring (ζ 1.2), the
|
|
80
|
+
* shape frame-tracked off a reference recording's camera; ω0 is solved so the
|
|
81
|
+
* residual at u = 1 equals `frac`. Same function as the take camera's. */
|
|
82
|
+
export function settleDecay(frac = 0.04) {
|
|
83
|
+
const zeta = 1.2;
|
|
84
|
+
const s = Math.sqrt(zeta * zeta - 1);
|
|
85
|
+
const l1 = zeta + s;
|
|
86
|
+
const l2 = zeta - s;
|
|
87
|
+
/** @param {number} x */
|
|
88
|
+
const resid = (x) => (l1 * Math.exp(-l2 * x) - l2 * Math.exp(-l1 * x)) / (l1 - l2);
|
|
89
|
+
let lo = 0.1;
|
|
90
|
+
let hi = 60;
|
|
91
|
+
for (let i = 0; i < 60; i++) {
|
|
92
|
+
const mid = (lo + hi) / 2;
|
|
93
|
+
if (resid(mid) > frac) lo = mid;
|
|
94
|
+
else hi = mid;
|
|
95
|
+
}
|
|
96
|
+
const w0T = (lo + hi) / 2;
|
|
97
|
+
/** @param {number} u */
|
|
98
|
+
return (u) => (u <= 0 ? 1 : resid(w0T * u));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** smootherstep, 6p⁵ − 15p⁴ + 10p³: a symmetric ease for moves that should end exactly on time */
|
|
102
|
+
/** @param {number} p */
|
|
103
|
+
export const smooth = (p) => {
|
|
104
|
+
const x = Math.max(0, Math.min(1, p));
|
|
105
|
+
return x * x * x * (x * (x * 6 - 15) + 10);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/** @param {number} p */
|
|
109
|
+
export const linear = (p) => Math.max(0, Math.min(1, p));
|
|
110
|
+
|
|
111
|
+
/** a seeded number in -1..1 for each whole i — the same i and seed, the same number */
|
|
112
|
+
/** @param {number} i @param {number} seed */
|
|
113
|
+
const lattice = (i, seed) => {
|
|
114
|
+
let h = Math.imul(i | 0, 0x27d4eb2d) ^ Math.imul(seed | 0, 0x165667b1);
|
|
115
|
+
h = Math.imul(h ^ (h >>> 15), 0x85ebca6b);
|
|
116
|
+
h = Math.imul(h ^ (h >>> 13), 0xc2b2ae35);
|
|
117
|
+
h ^= h >>> 16;
|
|
118
|
+
return (h >>> 0) / 0x7fffffff - 1;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/** smooth seeded noise along one axis, about -1..1: zero on every whole x,
|
|
122
|
+
* with a seeded slope there, eased between (gradient noise). It starts from
|
|
123
|
+
* rest at x = 0, so a jolt never jumps on its first frame. */
|
|
124
|
+
/** @param {number} x @param {number} seed */
|
|
125
|
+
export const noise = (x, seed = 1) => {
|
|
126
|
+
const i = Math.floor(x);
|
|
127
|
+
const f = x - i;
|
|
128
|
+
const u = f * f * f * (f * (f * 6 - 15) + 10);
|
|
129
|
+
const a = lattice(i, seed) * f;
|
|
130
|
+
const b = lattice(i + 1, seed) * (f - 1);
|
|
131
|
+
return 2 * (a + (b - a) * u);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @param {object} opts
|
|
136
|
+
* @param {{ width: number, height: number }} opts.content the layer the camera looks at, in CSS px
|
|
137
|
+
* @param {{ width: number, height: number }} [opts.view] the film's picture (default: the content's size)
|
|
138
|
+
* @param {number} [opts.zoomIn] default duration of a move that closes in (s)
|
|
139
|
+
* @param {number} [opts.zoomOut] default duration of a move that pulls out (s)
|
|
140
|
+
* @param {number} [opts.settle] the share of a move left to settle into the hold
|
|
141
|
+
* @param {number} [opts.lead] every move leaves and lands this much earlier (s, default 0): the camera is there before what it waits for
|
|
142
|
+
* @param {boolean} [opts.keepInside] keep each view inside the content (default true); false lets the camera look past its edge
|
|
143
|
+
* @param {"linear" | "log"} [opts.zoom] how a move's width changes: evenly in px (default), or at an even pace in log space, which reads better when the scale changes a lot
|
|
144
|
+
* @param {Handheld} [opts.handheld] a hand on the camera (default: none)
|
|
145
|
+
*/
|
|
146
|
+
export function camera({
|
|
147
|
+
content,
|
|
148
|
+
view = content,
|
|
149
|
+
zoomIn = 0.73,
|
|
150
|
+
zoomOut = 1.34,
|
|
151
|
+
settle = 0.04,
|
|
152
|
+
lead = 0,
|
|
153
|
+
keepInside = true,
|
|
154
|
+
zoom = "linear",
|
|
155
|
+
handheld,
|
|
156
|
+
}) {
|
|
157
|
+
const aspect = view.width / view.height;
|
|
158
|
+
const decay = settleDecay(settle);
|
|
159
|
+
if (!Number.isFinite(lead)) throw new Error("camera: lead must be a number of seconds");
|
|
160
|
+
if (zoom !== "linear" && zoom !== "log")
|
|
161
|
+
throw new Error(`camera: zoom is "linear" or "log", not ${JSON.stringify(zoom)}`);
|
|
162
|
+
if (handheld && !((handheld.period ?? 2.5) > 0))
|
|
163
|
+
throw new Error("camera: handheld period must be above 0 s");
|
|
164
|
+
/** @type {{ kind: "move" | "cut", at: number, anchor: "arrive" | "start", target: View, dur?: number, ease?: (p: number) => number, label: string, lead: number, free: boolean, log: boolean }[]} */
|
|
165
|
+
const asked = [];
|
|
166
|
+
/** @type {{ at: number, amp: number, rot: number, dur: number, freq: number, seed: number }[]} */
|
|
167
|
+
const shakes = [];
|
|
168
|
+
/** @type {Move[] | null} */
|
|
169
|
+
let moves = null;
|
|
170
|
+
/** @type {string[]} */
|
|
171
|
+
const warnings = []; // from asking: views that had to be kept inside
|
|
172
|
+
/** @type {string[]} */
|
|
173
|
+
let overshoots = []; // from planning: curves that leave the content
|
|
174
|
+
|
|
175
|
+
/** the whole content, centred */
|
|
176
|
+
const all = () =>
|
|
177
|
+
/** @type {View} */ ({
|
|
178
|
+
cx: content.width / 2,
|
|
179
|
+
cy: content.height / 2,
|
|
180
|
+
w: Math.max(content.width, content.height * aspect),
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
/** a view kept inside the content: on an axis the view covers, its centre
|
|
184
|
+
* stops at the content's edge; on one it does not, it is centred — the
|
|
185
|
+
* take camera's clampCenter */
|
|
186
|
+
/** @param {View} v */
|
|
187
|
+
const inside = (v) => {
|
|
188
|
+
const h = v.w / aspect;
|
|
189
|
+
return {
|
|
190
|
+
cx:
|
|
191
|
+
v.w <= content.width
|
|
192
|
+
? Math.min(Math.max(v.cx, v.w / 2), content.width - v.w / 2)
|
|
193
|
+
: content.width / 2,
|
|
194
|
+
cy:
|
|
195
|
+
h <= content.height
|
|
196
|
+
? Math.min(Math.max(v.cy, h / 2), content.height - h / 2)
|
|
197
|
+
: content.height / 2,
|
|
198
|
+
w: v.w,
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
/** @param {Box | View} b @param {When} [o] */
|
|
203
|
+
const viewOf = (b, o = {}) => {
|
|
204
|
+
if ("w" in b) return b;
|
|
205
|
+
const fill = o.fill ?? 0.6;
|
|
206
|
+
if (o.fit === "width") {
|
|
207
|
+
const w = b.width / fill;
|
|
208
|
+
const tall = b.height > w / aspect;
|
|
209
|
+
const pad = (w - b.width) / 2;
|
|
210
|
+
return {
|
|
211
|
+
cx: b.x + b.width / 2,
|
|
212
|
+
cy: tall ? b.y - pad + w / aspect / 2 : b.y + b.height / 2,
|
|
213
|
+
w,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
return {
|
|
217
|
+
cx: b.x + b.width / 2,
|
|
218
|
+
cy: b.y + b.height / 2,
|
|
219
|
+
w: Math.max(b.width, b.height * aspect) / fill,
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
/** @param {"move" | "cut"} kind @param {Box | View} target @param {When} o @param {string} label */
|
|
224
|
+
const ask = (kind, target, o, label) => {
|
|
225
|
+
const at = o.arrive ?? o.start;
|
|
226
|
+
if (at == null || !Number.isFinite(at))
|
|
227
|
+
throw new Error(`camera: ${label} needs { arrive } or { start }`);
|
|
228
|
+
if (o.arrive != null && o.start != null)
|
|
229
|
+
throw new Error(`camera: ${label} takes { arrive } or { start }, not both`);
|
|
230
|
+
const moveLead = o.lead ?? lead;
|
|
231
|
+
if (!Number.isFinite(moveLead))
|
|
232
|
+
throw new Error(`camera: ${label} at ${at}s: lead must be a number`);
|
|
233
|
+
const moveZoom = o.zoom ?? zoom;
|
|
234
|
+
if (moveZoom !== "linear" && moveZoom !== "log")
|
|
235
|
+
throw new Error(`camera: ${label} at ${at}s: zoom is "linear" or "log"`);
|
|
236
|
+
const free = !(o.keepInside ?? keepInside);
|
|
237
|
+
const wanted = viewOf(target, o);
|
|
238
|
+
const kept = free ? wanted : inside(wanted);
|
|
239
|
+
const off = Math.hypot(kept.cx - wanted.cx, kept.cy - wanted.cy);
|
|
240
|
+
if (off > 1)
|
|
241
|
+
warnings.push(
|
|
242
|
+
`${label} at ${at}s: the content ends there — the view stops ${Math.round(off)} px short of centring it`,
|
|
243
|
+
);
|
|
244
|
+
asked.push({
|
|
245
|
+
kind,
|
|
246
|
+
at,
|
|
247
|
+
anchor: o.arrive != null ? "arrive" : "start",
|
|
248
|
+
target: kept,
|
|
249
|
+
dur: o.dur,
|
|
250
|
+
ease: o.ease,
|
|
251
|
+
label: `${label} at ${at}s`,
|
|
252
|
+
lead: moveLead,
|
|
253
|
+
free,
|
|
254
|
+
log: moveZoom === "log",
|
|
255
|
+
});
|
|
256
|
+
moves = null;
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
/** a part of the product is framed where it is when the move lands (a
|
|
260
|
+
* cut: where it is at the cut); a box or a view as it is
|
|
261
|
+
* @param {"move" | "cut"} kind @param {Box | View | PartLike} target @param {When} o @param {string} label */
|
|
262
|
+
const askFor = (kind, target, o, label) => {
|
|
263
|
+
if (!("boxAt" in target) || typeof target.boxAt !== "function")
|
|
264
|
+
return ask(kind, /** @type {Box | View} */ (target), o, label);
|
|
265
|
+
const named = `${label} ${target.name ?? "part"}`;
|
|
266
|
+
const part = target;
|
|
267
|
+
if (kind === "cut" || o.arrive != null || o.dur != null || o.start == null) {
|
|
268
|
+
const lands =
|
|
269
|
+
kind === "cut"
|
|
270
|
+
? (o.start ?? Number.NaN)
|
|
271
|
+
: (o.arrive ?? (o.start ?? Number.NaN) + (o.dur ?? zoomIn)) - (o.lead ?? lead);
|
|
272
|
+
if (!Number.isFinite(lands)) return ask(kind, { cx: 0, cy: 0, w: 1 }, o, named);
|
|
273
|
+
part.used?.(kind === "cut" ? "cut" : label, lands);
|
|
274
|
+
return ask(kind, part.boxAt(lands), o, named);
|
|
275
|
+
}
|
|
276
|
+
// a move given by its start alone lasts as plan() times it — longer when
|
|
277
|
+
// it pulls out wider than the view asked for before it — so the part is
|
|
278
|
+
// read where that lands, and the move keeps that duration
|
|
279
|
+
const start = o.start;
|
|
280
|
+
const moveLead = o.lead ?? lead;
|
|
281
|
+
let leaving = all();
|
|
282
|
+
let latest = Number.NEGATIVE_INFINITY;
|
|
283
|
+
for (const a of asked)
|
|
284
|
+
if (a.at <= start && a.at >= latest) {
|
|
285
|
+
latest = a.at;
|
|
286
|
+
leaving = a.target;
|
|
287
|
+
}
|
|
288
|
+
let dur = zoomIn;
|
|
289
|
+
if (viewOf(part.boxAt(start + zoomIn - moveLead), o).w > leaving.w + 1e-9) dur = zoomOut;
|
|
290
|
+
part.used?.(label, start + dur - moveLead);
|
|
291
|
+
return ask(kind, part.boxAt(start + dur - moveLead), { ...o, dur }, named);
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
/** the moves in time order, each with its start and end resolved */
|
|
295
|
+
const plan = () => {
|
|
296
|
+
if (moves) return moves;
|
|
297
|
+
const order = [...asked].sort((a, b) => a.at - b.at);
|
|
298
|
+
/** @type {Move[]} */
|
|
299
|
+
const out = [];
|
|
300
|
+
let leaving = all(); // the view the camera was last asked for
|
|
301
|
+
for (const a of order) {
|
|
302
|
+
/** @type {Move} */
|
|
303
|
+
let m;
|
|
304
|
+
if (a.kind === "cut") {
|
|
305
|
+
// a cut is where you put it: a lead moves only the moves
|
|
306
|
+
m = { kind: "cut", t0: a.at, t1: a.at, to: a.target, ease: null, label: a.label };
|
|
307
|
+
} else {
|
|
308
|
+
const dur = a.dur ?? (a.target.w > leaving.w + 1e-9 ? zoomOut : zoomIn);
|
|
309
|
+
let t0 = a.anchor === "arrive" ? a.at - dur : a.at;
|
|
310
|
+
if (a.lead) t0 -= a.lead;
|
|
311
|
+
m = {
|
|
312
|
+
kind: "move",
|
|
313
|
+
t0,
|
|
314
|
+
t1: t0 + Math.max(dur, 1e-6),
|
|
315
|
+
to: a.target,
|
|
316
|
+
ease: a.ease ?? null,
|
|
317
|
+
label: a.label,
|
|
318
|
+
};
|
|
319
|
+
if (a.log) m.log = true;
|
|
320
|
+
}
|
|
321
|
+
if (a.free) m.free = true;
|
|
322
|
+
out.push(m);
|
|
323
|
+
leaving = a.target;
|
|
324
|
+
}
|
|
325
|
+
// at one instant a cut comes first and a move leaves from it; two cuts or
|
|
326
|
+
// two moves at one instant would be a guess, so they are refused
|
|
327
|
+
out.sort((a, b) => a.t0 - b.t0 || (a.kind === b.kind ? 0 : a.kind === "cut" ? -1 : 1));
|
|
328
|
+
for (let i = 1; i < out.length; i++) {
|
|
329
|
+
const a = out[i - 1];
|
|
330
|
+
const b = out[i];
|
|
331
|
+
if (a && b && Math.abs(a.t0 - b.t0) < 1e-9 && a.kind === b.kind)
|
|
332
|
+
throw new Error(
|
|
333
|
+
`camera: ${a.label} and ${b.label} begin at the same instant — which one wins is not yours to guess`,
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
moves = out;
|
|
337
|
+
overshoots = [];
|
|
338
|
+
overshoot(out);
|
|
339
|
+
return out;
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
/** where the camera is at t: each move starts from wherever the camera is
|
|
343
|
+
* when it begins, and runs (settling) until the next one does */
|
|
344
|
+
/** @param {number} t */
|
|
345
|
+
const at = (t) => {
|
|
346
|
+
const ms = plan();
|
|
347
|
+
let from = all();
|
|
348
|
+
for (let i = 0; i < ms.length; i++) {
|
|
349
|
+
const m = /** @type {Move} */ (ms[i]);
|
|
350
|
+
if (t < m.t0) break;
|
|
351
|
+
const next = ms[i + 1];
|
|
352
|
+
const until = next ? Math.min(t, next.t0) : t;
|
|
353
|
+
if (m.kind === "cut") from = m.to;
|
|
354
|
+
else {
|
|
355
|
+
const u = (until - m.t0) / (m.t1 - m.t0);
|
|
356
|
+
const left = m.ease ? 1 - m.ease(Math.min(1, u)) : decay(u);
|
|
357
|
+
if (m.log) {
|
|
358
|
+
// the width at an even pace in log space; the centre keeps the
|
|
359
|
+
// point that stays put on screen where it is, so everything still
|
|
360
|
+
// heads for its place in a straight line
|
|
361
|
+
const r = from.w / m.to.w;
|
|
362
|
+
const w = m.to.w * r ** left;
|
|
363
|
+
const k = Math.abs(Math.log(r)) < 1e-9 ? left : (w - m.to.w) / (from.w - m.to.w);
|
|
364
|
+
from = {
|
|
365
|
+
cx: m.to.cx + (from.cx - m.to.cx) * k,
|
|
366
|
+
cy: m.to.cy + (from.cy - m.to.cy) * k,
|
|
367
|
+
w,
|
|
368
|
+
};
|
|
369
|
+
} else
|
|
370
|
+
from = {
|
|
371
|
+
cx: m.to.cx + (from.cx - m.to.cx) * left,
|
|
372
|
+
cy: m.to.cy + (from.cy - m.to.cy) * left,
|
|
373
|
+
w: Math.max(m.to.w + (from.w - m.to.w) * left, Math.min(from.w, m.to.w) * 0.5),
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
if (!next || t < next.t0) break;
|
|
377
|
+
}
|
|
378
|
+
return { ...from, scale: view.width / from.w };
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
/** how far a view passes the content's edge on an axis it fits (0: inside) */
|
|
382
|
+
/** @param {View} v */
|
|
383
|
+
const past = (v) => {
|
|
384
|
+
const h = v.w / aspect;
|
|
385
|
+
return Math.max(
|
|
386
|
+
0,
|
|
387
|
+
v.w <= content.width ? Math.max(v.w / 2 - v.cx, v.cx + v.w / 2 - content.width) : 0,
|
|
388
|
+
h <= content.height ? Math.max(h / 2 - v.cy, v.cy + h / 2 - content.height) : 0,
|
|
389
|
+
);
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
/** a curve of your own may overshoot: say where the view then leaves the content */
|
|
393
|
+
/** @param {Move[]} ms */
|
|
394
|
+
const overshoot = (ms) => {
|
|
395
|
+
const anyFree = ms.some((m) => m.free);
|
|
396
|
+
for (const m of ms) {
|
|
397
|
+
if (m.kind !== "move" || !m.ease || m.free) continue;
|
|
398
|
+
// a move that leaves from a view left past the edge is past it at first:
|
|
399
|
+
// that is not the curve's doing, only going further out is
|
|
400
|
+
const from = anyFree ? past(at(m.t0)) : 0;
|
|
401
|
+
for (let k = 0; k <= 60; k++) {
|
|
402
|
+
const v = at(m.t0 + ((m.t1 - m.t0) * k) / 60);
|
|
403
|
+
const h = v.w / aspect;
|
|
404
|
+
const out = anyFree
|
|
405
|
+
? past(v) > from + 0.5
|
|
406
|
+
: (v.w <= content.width &&
|
|
407
|
+
(v.cx - v.w / 2 < -0.5 || v.cx + v.w / 2 > content.width + 0.5)) ||
|
|
408
|
+
(h <= content.height && (v.cy - h / 2 < -0.5 || v.cy + h / 2 > content.height + 0.5));
|
|
409
|
+
if (out) {
|
|
410
|
+
overshoots.push(
|
|
411
|
+
`${m.label}: its curve overshoots — the view passes the content's edge mid-move`,
|
|
412
|
+
);
|
|
413
|
+
break;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
|
|
419
|
+
/** what the hand and the shakes add at t, in picture px and degrees */
|
|
420
|
+
/** @param {number} t @returns {Jitter} */
|
|
421
|
+
const jitter = (t) => {
|
|
422
|
+
let x = 0;
|
|
423
|
+
let y = 0;
|
|
424
|
+
let rot = 0;
|
|
425
|
+
if (handheld) {
|
|
426
|
+
const { amp = 3, rot: tilt = 0, period = 2.5, seed = 1 } = handheld;
|
|
427
|
+
const p = t / period;
|
|
428
|
+
// two octaves, the second faint: a hand drifts and corrects; each axis
|
|
429
|
+
// is shifted off the others so they never rest at one instant together
|
|
430
|
+
/** @param {number} k */
|
|
431
|
+
const wander = (k) =>
|
|
432
|
+
(noise(p + 0.37 * k, seed * 7 + k) + 0.35 * noise(p * 2.13 + 17.5, seed * 7 + k + 3)) /
|
|
433
|
+
1.35;
|
|
434
|
+
x += amp * wander(0);
|
|
435
|
+
y += amp * wander(1);
|
|
436
|
+
rot += tilt * wander(2);
|
|
437
|
+
}
|
|
438
|
+
for (const s of shakes) {
|
|
439
|
+
const tau = t - s.at;
|
|
440
|
+
if (tau <= 0 || tau >= s.dur) continue;
|
|
441
|
+
// a rattle that starts from rest and reaches about `amp` on its first
|
|
442
|
+
// swing, then dies away to nothing at `dur`; each axis swings at its
|
|
443
|
+
// own seeded rate and drifts off a clean sine, so no two read alike
|
|
444
|
+
const env = (1 - tau / s.dur) ** 2;
|
|
445
|
+
const p = tau * s.freq;
|
|
446
|
+
/** @param {number} k @param {number} rate */
|
|
447
|
+
const swing = (k, rate) =>
|
|
448
|
+
Math.sin(
|
|
449
|
+
2 * Math.PI * p * rate * (1 + 0.12 * lattice(k, s.seed)) +
|
|
450
|
+
1.2 * noise(p * 0.5, s.seed * 5 + k),
|
|
451
|
+
);
|
|
452
|
+
x += s.amp * env * swing(0, 1);
|
|
453
|
+
y += s.amp * env * (0.6 + 0.3 * lattice(9, s.seed)) * swing(1, 1.31);
|
|
454
|
+
rot += s.rot * env * swing(2, 0.83);
|
|
455
|
+
}
|
|
456
|
+
return { x, y, rot };
|
|
457
|
+
};
|
|
458
|
+
const jitters = () => !!handheld || shakes.length > 0;
|
|
459
|
+
|
|
460
|
+
/** where the layer goes at t; `k` is its depth factor (1: the content's own plane) */
|
|
461
|
+
/** @param {number} t @param {number} [k] */
|
|
462
|
+
const place = (t, k = 1) => {
|
|
463
|
+
const v = at(t);
|
|
464
|
+
let p;
|
|
465
|
+
if (k === 1)
|
|
466
|
+
p = {
|
|
467
|
+
s: v.scale,
|
|
468
|
+
tx: view.width / 2 - v.cx * v.scale,
|
|
469
|
+
ty: view.height / 2 - v.cy * v.scale,
|
|
470
|
+
r: 0,
|
|
471
|
+
};
|
|
472
|
+
else {
|
|
473
|
+
// a layer at factor k sees the move k times over from the whole
|
|
474
|
+
// content: its centre goes k of the way, its scale k of the way in log
|
|
475
|
+
const r0 = all();
|
|
476
|
+
const cx = r0.cx + (v.cx - r0.cx) * k;
|
|
477
|
+
const cy = r0.cy + (v.cy - r0.cy) * k;
|
|
478
|
+
const s = (view.width / r0.w) * (r0.w / v.w) ** k;
|
|
479
|
+
p = { s, tx: view.width / 2 - cx * s, ty: view.height / 2 - cy * s, r: 0 };
|
|
480
|
+
}
|
|
481
|
+
if (jitters()) {
|
|
482
|
+
const j = jitter(t);
|
|
483
|
+
p.tx += j.x * k;
|
|
484
|
+
p.ty += j.y * k;
|
|
485
|
+
p.r = j.rot * k;
|
|
486
|
+
}
|
|
487
|
+
return p;
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
/** the transform's own point mapping: content → picture, and back */
|
|
491
|
+
/** @param {{ s: number, tx: number, ty: number, r: number }} p */
|
|
492
|
+
const css = (p) => {
|
|
493
|
+
if (!p.r) return `translate(${p.tx}px, ${p.ty}px) scale(${p.s})`;
|
|
494
|
+
const hx = view.width / 2;
|
|
495
|
+
const hy = view.height / 2;
|
|
496
|
+
return `translate(${hx}px, ${hy}px) rotate(${p.r}deg) translate(${p.tx - hx}px, ${p.ty - hy}px) scale(${p.s})`;
|
|
497
|
+
};
|
|
498
|
+
/** @param {{ s: number, tx: number, ty: number, r: number }} p @param {number} x @param {number} y */
|
|
499
|
+
const project = (p, x, y) => {
|
|
500
|
+
const qx = p.tx + x * p.s;
|
|
501
|
+
const qy = p.ty + y * p.s;
|
|
502
|
+
if (!p.r) return [qx, qy];
|
|
503
|
+
const a = (p.r * Math.PI) / 180;
|
|
504
|
+
const hx = view.width / 2;
|
|
505
|
+
const hy = view.height / 2;
|
|
506
|
+
const c = Math.cos(a);
|
|
507
|
+
const n = Math.sin(a);
|
|
508
|
+
return [hx + (qx - hx) * c - (qy - hy) * n, hy + (qx - hx) * n + (qy - hy) * c];
|
|
509
|
+
};
|
|
510
|
+
/** @param {{ s: number, tx: number, ty: number, r: number }} p @param {number} x @param {number} y */
|
|
511
|
+
const unproject = (p, x, y) => {
|
|
512
|
+
let qx = x;
|
|
513
|
+
let qy = y;
|
|
514
|
+
if (p.r) {
|
|
515
|
+
const a = (-p.r * Math.PI) / 180;
|
|
516
|
+
const hx = view.width / 2;
|
|
517
|
+
const hy = view.height / 2;
|
|
518
|
+
const c = Math.cos(a);
|
|
519
|
+
const n = Math.sin(a);
|
|
520
|
+
qx = hx + (x - hx) * c - (y - hy) * n;
|
|
521
|
+
qy = hy + (x - hx) * n + (y - hy) * c;
|
|
522
|
+
}
|
|
523
|
+
return [(qx - p.tx) / p.s, (qy - p.ty) / p.s];
|
|
524
|
+
};
|
|
525
|
+
|
|
526
|
+
return {
|
|
527
|
+
/** the layer's size and the picture's, as given */
|
|
528
|
+
content,
|
|
529
|
+
view,
|
|
530
|
+
/** frame a box, a view or a part of the product (where it is when the
|
|
531
|
+
* move lands) — `{ arrive }` or `{ start }`, optionally `dur`, `ease`, `fill`, `fit` */
|
|
532
|
+
/** @param {Box | View | PartLike} target @param {When} when */
|
|
533
|
+
frame: (target, when) => askFor("move", target, when, "frame"),
|
|
534
|
+
/** pull out to the whole content */
|
|
535
|
+
/** @param {When} when */
|
|
536
|
+
rest: (when) => ask("move", all(), when, "rest"),
|
|
537
|
+
/** a cut: from `at` on the camera shows `target`, with no move */
|
|
538
|
+
/** @param {Box | View | PartLike} target @param {number} at @param {When} [o] */
|
|
539
|
+
cut: (target, at, o = {}) => askFor("cut", target, { ...o, start: at }, "cut"),
|
|
540
|
+
/** a jolt from `at` on, dying away over `dur` — an impact, a slam, a beat
|
|
541
|
+
* that lands; shakes that overlap add up */
|
|
542
|
+
/** @param {number} at @param {Shake} [o] */
|
|
543
|
+
shake: (at, o = {}) => {
|
|
544
|
+
if (!Number.isFinite(at)) throw new Error("camera: shake needs a time (s)");
|
|
545
|
+
const { amp = 10, rot = 0, dur = 0.45, freq = 16, seed = shakes.length + 1 } = o;
|
|
546
|
+
if (!(dur > 0)) throw new Error(`camera: shake at ${at}s: dur must be above 0`);
|
|
547
|
+
shakes.push({ at, amp, rot, dur, freq, seed });
|
|
548
|
+
},
|
|
549
|
+
/** the view at t ({ cx, cy, w, scale }) — for a camera of your own; the
|
|
550
|
+
* hand and the shakes are not in it, they are in jitter(t) */
|
|
551
|
+
at,
|
|
552
|
+
/** what the hand and the shakes add at t ({ x, y, rot }: picture px, degrees about its centre) */
|
|
553
|
+
jitter,
|
|
554
|
+
/** the CSS transform for the layer at t (give the layer transform-origin 0 0) */
|
|
555
|
+
/** @param {number} t */
|
|
556
|
+
transform: (t) => css(place(t)),
|
|
557
|
+
/** a point of the content → where it is in the picture at t */
|
|
558
|
+
/** @param {number} x @param {number} y @param {number} t */
|
|
559
|
+
toView: (x, y, t) => project(place(t), x, y),
|
|
560
|
+
/** a point of the picture → the content under it at t */
|
|
561
|
+
/** @param {number} x @param {number} y @param {number} t */
|
|
562
|
+
toContent: (x, y, t) => unproject(place(t), x, y),
|
|
563
|
+
/** a layer the size of the content at depth factor k: 1 moves with the
|
|
564
|
+
* content, 0 holds still, 0.3 is far behind, 1.5 passes in front — its
|
|
565
|
+
* centre goes k of the way of each move and its zoom k of the way (in
|
|
566
|
+
* log), the hand and shakes k times as far */
|
|
567
|
+
/** @param {number} k */
|
|
568
|
+
depth: (k) => {
|
|
569
|
+
if (!Number.isFinite(k)) throw new Error("camera: depth needs a factor");
|
|
570
|
+
return {
|
|
571
|
+
/** @param {number} t */
|
|
572
|
+
transform: (t) => css(place(t, k)),
|
|
573
|
+
/** @param {number} x @param {number} y @param {number} t */
|
|
574
|
+
toView: (x, y, t) => project(place(t, k), x, y),
|
|
575
|
+
/** @param {number} x @param {number} y @param {number} t */
|
|
576
|
+
toContent: (x, y, t) => unproject(place(t, k), x, y),
|
|
577
|
+
};
|
|
578
|
+
},
|
|
579
|
+
/** the moves as planned (times resolved) */
|
|
580
|
+
moves: () => plan(),
|
|
581
|
+
/** what the camera could not do as asked, and why */
|
|
582
|
+
warnings: () => {
|
|
583
|
+
plan();
|
|
584
|
+
return [...warnings, ...overshoots];
|
|
585
|
+
},
|
|
586
|
+
};
|
|
587
|
+
}
|