@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/time.js
ADDED
|
@@ -0,0 +1,812 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// One timeline for the picture and the sound — open-take's film kit. Keep the
|
|
3
|
+
// film's moments in one plain module that the page and the score (a Node
|
|
4
|
+
// script) both import: when a moment moves, its sound moves with it, and
|
|
5
|
+
// nothing has to be copied by hand. It holds names and times only; how the
|
|
6
|
+
// film is built around them is yours.
|
|
7
|
+
//
|
|
8
|
+
// // timeline.js — yours
|
|
9
|
+
// import { timeline } from "./kit/time.js";
|
|
10
|
+
// export const tl = timeline({ at: { hook: 0, search: 2.5, result: 4 } });
|
|
11
|
+
//
|
|
12
|
+
// tl.t("search") // 2.5
|
|
13
|
+
// tl.local(t, "search", 0.6) // 0 → 1 through the 0.6 s after "search"
|
|
14
|
+
//
|
|
15
|
+
// A pulse is there if the film has one — its tempo is the film's to choose,
|
|
16
|
+
// from its music or from nothing at all; none is assumed:
|
|
17
|
+
//
|
|
18
|
+
// const tl = timeline({ bpm: /* the music's */, at: { … } });
|
|
19
|
+
// tl.beat(8) // when the 8th beat falls (s)
|
|
20
|
+
// tl.snap(3.1) // the nearest beat to 3.1 s
|
|
21
|
+
//
|
|
22
|
+
// What happens in the picture, and how fast it moves, can be said here too,
|
|
23
|
+
// for the score: `film render` writes them beside the film as
|
|
24
|
+
// <film>.events.json (kit/audio.mjs readEvents reads it), so a click's sound
|
|
25
|
+
// lands on the click, pans to where it is on the stage, and a whoosh can
|
|
26
|
+
// follow the camera's speed rather than a guess.
|
|
27
|
+
//
|
|
28
|
+
// tl.event("search", "click", { x: 640, y: 380, force: 0.6 });
|
|
29
|
+
// tl.event(tl.t("search") + 0.12, "key", { label: "s" });
|
|
30
|
+
// tl.curve("zoom", (t) => cam.at(t).scale); // any number of t
|
|
31
|
+
// tl.curve("camSpeed", speed((t) => cam.at(t))); // content px/s, by difference
|
|
32
|
+
// window.__film = { duration: tl.t("end"), audio: "score.wav", ...tl.hooks() };
|
|
33
|
+
//
|
|
34
|
+
// tl.events() // the moments (kind "mark") and the events, in time order
|
|
35
|
+
//
|
|
36
|
+
// A beat sheet, if you keep one: what each stretch of the film is meant to
|
|
37
|
+
// do, in free words. Every field is optional and nothing checks it is "right";
|
|
38
|
+
// `film render` writes the list into the events file and `film probe` sets it
|
|
39
|
+
// beside what the picture did — "this segment was written to hold; the picture
|
|
40
|
+
// still moves 4.2–4.9 s" — as information, for you to keep or change.
|
|
41
|
+
//
|
|
42
|
+
// tl.segment("hook", "search", { label: "the problem", hold: true, sound: "one low hit" });
|
|
43
|
+
// tl.segment("search", "result", {
|
|
44
|
+
// subject: "#search", // a CSS selector (or a subject's name in the curves)
|
|
45
|
+
// handoff: "whip", // how it hands over to the next, at "result"
|
|
46
|
+
// });
|
|
47
|
+
// tl.segment("result", "end", { handoff: { kind: "depth", outDur: 0.25 } }); // with its options
|
|
48
|
+
// tl.segments() // [{ from, to, label?, hold?, handoff?, seam?, carry?, subject?, sound? }], by from
|
|
49
|
+
//
|
|
50
|
+
// What crosses a boundary, if you say: `carry` names the one thing that lives
|
|
51
|
+
// through the cut at the segment's end — a CSS selector, or a function of t
|
|
52
|
+
// giving its box ({ x, y, width, height, opacity? }, frame px) for what is
|
|
53
|
+
// drawn on a canvas. `film render` then follows that thing frame by frame,
|
|
54
|
+
// from 1 s before the boundary to 0.4 s after, and says what it did:
|
|
55
|
+
// carried (it was still there 0.25 s past the boundary, or filled the frame,
|
|
56
|
+
// and moved or changed size on the way), anchored (it stayed, unchanged), or
|
|
57
|
+
// bare (gone, or fading out, by then) — facts, not a grade. Its box is what
|
|
58
|
+
// is drawn of it: a clip-path inset() or circle() counts.
|
|
59
|
+
//
|
|
60
|
+
// tl.segment(0, 7.05, { handoff: "the pressed button grows into the next scene's ground", carry: "#cta" });
|
|
61
|
+
// tl.segment(7.05, 9, { handoff: "cut" }); // a hard cut, on purpose
|
|
62
|
+
//
|
|
63
|
+
// A handoff is your own words, or a seam's kind from kit/seams.js — "curve",
|
|
64
|
+
// "whip", "depth", "inverse", "push", "dip", or "cut" for a hard cut on
|
|
65
|
+
// purpose (and the names they go by: "pushCut", "into the lens"). Given the
|
|
66
|
+
// seams module, `scenes(…, { tl, seams })` below performs a kind at the
|
|
67
|
+
// boundary between the two scenes that meet there; words stay words, for you
|
|
68
|
+
// to build.
|
|
69
|
+
// A boundary whose segment names no kind is left as it is: nothing is added
|
|
70
|
+
// that the film did not ask for.
|
|
71
|
+
// Two handoffs are declarations the page performs itself, so the render reads
|
|
72
|
+
// what it sees there as meant: "hidden-cut" says the picture is replaced at
|
|
73
|
+
// `to` under motion (a blur or a whip covers it; an event of kind
|
|
74
|
+
// "hidden-cut" says the same at its time), so no cut need show there; "lift"
|
|
75
|
+
// says one layer moves on its own over the whole segment, so a jump or a
|
|
76
|
+
// camera turning back inside it is the lift. Neither asks for a `carry`;
|
|
77
|
+
// `film render` and `film probe` do not list them as undeclared jumps.
|
|
78
|
+
//
|
|
79
|
+
// tl.event(5.4, "hidden-cut"); // replaced in the blur at 5.4 s
|
|
80
|
+
// tl.segment(1.53, 2.2, { handoff: "lift" }); // a card rises out of the desk
|
|
81
|
+
//
|
|
82
|
+
// What the film uses that someone else made — a track, a sound, a font, a
|
|
83
|
+
// photo — and on what terms, if you keep a record of it. Nothing checks it or
|
|
84
|
+
// acts on it: `film render` writes it into the events file as "credits" (an
|
|
85
|
+
// empty list when there is none), for whoever publishes the film.
|
|
86
|
+
//
|
|
87
|
+
// tl.credit({ what: "music: Night Drive", by: "A. Artist", licence: "CC BY 4.0",
|
|
88
|
+
// url: "https://…", text: "Night Drive by A. Artist (CC BY 4.0)" });
|
|
89
|
+
// tl.credits() // [{ what?, by?, licence?, url?, text? }], as given
|
|
90
|
+
// // or by hand: window.__film = { …, credits: [{ what: "font: Inter", licence: "OFL-1.1" }] }
|
|
91
|
+
//
|
|
92
|
+
// Where a value on screen comes from, if the film shows the product's data —
|
|
93
|
+
// a part of components.json (`ref`, `field`), the live page it shows on
|
|
94
|
+
// (`url`), or a note that it is not the product's: "demo" (made-up records a
|
|
95
|
+
// viewer can tell are made up), "illustrative" (a figure for the idea, not a
|
|
96
|
+
// reading). Nothing checks it or acts on it: `film render` writes the list
|
|
97
|
+
// into the events file as "sources", and `film probe` sets it beside the
|
|
98
|
+
// numbers and strings it reads in the film's own text, as information.
|
|
99
|
+
// `label` is what on screen it covers: the text as shown, or words for it;
|
|
100
|
+
// `text` the strings it covers when the label is words, `selector` the
|
|
101
|
+
// film's elements whose text it covers. kit/media.js `readValues(url, { tl })`
|
|
102
|
+
// declares every value it reads, so a component rebuilt from real values
|
|
103
|
+
// needs no line of its own. `film render` asks for the list once, when the
|
|
104
|
+
// page is ready: declare (and read values) before that, not in __render.
|
|
105
|
+
//
|
|
106
|
+
// tl.source("$3,376", { ref: "result:e149", field: "number" });
|
|
107
|
+
// tl.source("six sample rows", { note: "demo", selector: "#table" });
|
|
108
|
+
// tl.source("monthly price", { url: "https://…/pricing", text: "$16" });
|
|
109
|
+
// tl.sources() // [{ label, ref?, field?, file?, url?, note?, text?, selector? }], as given
|
|
110
|
+
//
|
|
111
|
+
// Scenes, if the film has them: which element shows when. Hidden by
|
|
112
|
+
// visibility, so what is in a hidden scene keeps its layout (a saved screen
|
|
113
|
+
// can still be measured and lifted from) and what was lifted out of it hides
|
|
114
|
+
// with it; each start is a cut on the timeline, for the score and the probe.
|
|
115
|
+
// A child that sets `visibility: visible` itself is not hidden with its
|
|
116
|
+
// scene and shows through: inside a scene write `inherit`, or nothing.
|
|
117
|
+
//
|
|
118
|
+
// const sc = scenes({ result: [7.2, 16.8], search: [21.6, 31.2] }, { tl }); // ids of elements
|
|
119
|
+
// sc.show(t); // in __render(t): "result" shown 7.2–16.8 s, hidden otherwise
|
|
120
|
+
//
|
|
121
|
+
// Given kit/seams.js, a boundary whose segment names a seam's kind is handed
|
|
122
|
+
// over that way — the scene ending there is one side, the one starting the
|
|
123
|
+
// other — and show(t) writes both sides while the seam is open:
|
|
124
|
+
//
|
|
125
|
+
// import * as seams from "./kit/seams.js";
|
|
126
|
+
// const sc = scenes({ rows: [0, 4], map: [4, 10.6], hex: [10.6, 15] }, { tl, seams });
|
|
127
|
+
// tl.segment(0, 4, { handoff: "depth" }); // 4.0 s: the rows into the lens, the map out of it
|
|
128
|
+
// tl.segment(4, 10.6, { handoff: "the panel slides away" }); // words: yours to build
|
|
129
|
+
// tl.segment(10.6, 15, { handoff: { kind: "whip", dir: "up" } });
|
|
130
|
+
// window.__render = (t) => { sc.show(t); /* the rest */ };
|
|
131
|
+
//
|
|
132
|
+
// A curve or a whip with no `dir` travels so the incoming scene arrives from
|
|
133
|
+
// the side its subject is on (the segment's `subject`), else to the left.
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* One thing that happens in the film, in seconds; where on the stage (CSS px)
|
|
137
|
+
* and how hard (0..1), if it says.
|
|
138
|
+
* @typedef {object} FilmEvent
|
|
139
|
+
* @property {number} t
|
|
140
|
+
* @property {string} kind "click", "key", "land", "cut", "hidden-cut", "mark", or any word of yours
|
|
141
|
+
* @property {number} [x]
|
|
142
|
+
* @property {number} [y]
|
|
143
|
+
* @property {number} [force]
|
|
144
|
+
* @property {string} [label]
|
|
145
|
+
* @property {string} [id] the moment's name, on the moments `events()` lists
|
|
146
|
+
*/
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* One stretch of the film as the author means it, in seconds of page time.
|
|
150
|
+
* `handoff` is how it hands over to what comes next, at `to`.
|
|
151
|
+
* @typedef {object} FilmSegment
|
|
152
|
+
* @property {number} from
|
|
153
|
+
* @property {number} to
|
|
154
|
+
* @property {string} [label]
|
|
155
|
+
* @property {boolean} [hold] the picture is meant to hold still here
|
|
156
|
+
* @property {string} [handoff] a seam's kind (kit/seams.js), "hidden-cut" or "lift", or your
|
|
157
|
+
* own words
|
|
158
|
+
* @property {Record<string, number | string>} [seam] the seam's options, when the handoff was
|
|
159
|
+
* given as { kind, …options }
|
|
160
|
+
* @property {string} [carry] what lives through the boundary at `to`: a CSS selector, or
|
|
161
|
+
* "(a function)" when it was given as one — `film render` follows it across
|
|
162
|
+
* @property {string} [subject] what the eye should be on: a CSS selector, or a name
|
|
163
|
+
* @property {string} [sound]
|
|
164
|
+
*/
|
|
165
|
+
|
|
166
|
+
/** how long before a boundary a carry is followed (s): a thing becoming the
|
|
167
|
+
* next scene mostly does it on the way in */
|
|
168
|
+
export const CARRY_BEFORE = 1;
|
|
169
|
+
/** …and after it */
|
|
170
|
+
export const CARRY_AFTER = 0.4;
|
|
171
|
+
|
|
172
|
+
/** the curves a carry is written as, in the events file: `carry@<boundary s>:<field>`
|
|
173
|
+
* @param {number} at @param {"x" | "y" | "w" | "h" | "o" | "fw" | "fh"} field */
|
|
174
|
+
export const carryCurve = (at, field) => `carry@${+at.toFixed(3)}:${field}`;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* The part of a box a clip-path inset() or circle() leaves drawn (px of the
|
|
178
|
+
* box as laid out, scaled to the box as drawn); the box as it is otherwise.
|
|
179
|
+
* @param {Element} el @param {DOMRect} r
|
|
180
|
+
*/
|
|
181
|
+
function clipped(el, r) {
|
|
182
|
+
const clip = getComputedStyle(el).clipPath;
|
|
183
|
+
const lw = /** @type {HTMLElement} */ (el).offsetWidth || r.width;
|
|
184
|
+
const lh = /** @type {HTMLElement} */ (el).offsetHeight || r.height;
|
|
185
|
+
const kx = lw ? r.width / lw : 1;
|
|
186
|
+
const ky = lh ? r.height / lh : 1;
|
|
187
|
+
/** @param {string} v @param {number} of */
|
|
188
|
+
const len = (v, of) =>
|
|
189
|
+
v.endsWith("%") ? (Number.parseFloat(v) / 100) * of : Number.parseFloat(v) || 0;
|
|
190
|
+
const inset = /^inset\(([^)]*?)(?:\s+round\b[^)]*)?\)/.exec(clip);
|
|
191
|
+
if (inset) {
|
|
192
|
+
const v = (inset[1] ?? "").trim().split(/\s+/);
|
|
193
|
+
const [t = "0", rt = t, b = t, l = rt] = v;
|
|
194
|
+
const T = len(t, lh),
|
|
195
|
+
R = len(rt, lw),
|
|
196
|
+
B = len(b, lh),
|
|
197
|
+
L = len(l, lw);
|
|
198
|
+
return {
|
|
199
|
+
left: r.left + L * kx,
|
|
200
|
+
top: r.top + T * ky,
|
|
201
|
+
width: Math.max(0, (lw - L - R) * kx),
|
|
202
|
+
height: Math.max(0, (lh - T - B) * ky),
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
const circle =
|
|
206
|
+
/^circle\(\s*([\d.]+(?:px|%))(?:\s+at\s+([\d.]+(?:px|%))\s+([\d.]+(?:px|%)))?/.exec(clip);
|
|
207
|
+
if (circle) {
|
|
208
|
+
const rad = len(circle[1] ?? "0", Math.hypot(lw, lh) / Math.SQRT2);
|
|
209
|
+
const cx = circle[2] ? len(circle[2], lw) : lw / 2;
|
|
210
|
+
const cy = circle[3] ? len(circle[3], lh) : lh / 2;
|
|
211
|
+
return {
|
|
212
|
+
left: r.left + (cx - rad) * kx,
|
|
213
|
+
top: r.top + (cy - rad) * ky,
|
|
214
|
+
width: 2 * rad * kx,
|
|
215
|
+
height: 2 * rad * ky,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
return r;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Where a carry is at this instant, in frame px, and how visible: its box
|
|
223
|
+
* (after every transform), the opacity it is drawn at (its own and every
|
|
224
|
+
* ancestor's multiplied; 0 when it or one of them is hidden or not shown),
|
|
225
|
+
* and the frame's size. Null outside a page.
|
|
226
|
+
* @param {string | ((t: number) => unknown)} what
|
|
227
|
+
* @param {number} t
|
|
228
|
+
*/
|
|
229
|
+
function carryBox(what, t) {
|
|
230
|
+
if (typeof document === "undefined" || typeof window === "undefined") return null;
|
|
231
|
+
const fw = window.innerWidth;
|
|
232
|
+
const fh = window.innerHeight;
|
|
233
|
+
if (typeof what === "function") {
|
|
234
|
+
const b =
|
|
235
|
+
/** @type {{ x?: number, y?: number, w?: number, h?: number, width?: number, height?: number, opacity?: number } | null} */ (
|
|
236
|
+
what(t)
|
|
237
|
+
);
|
|
238
|
+
if (!b || typeof b !== "object") return { x: 0, y: 0, w: 0, h: 0, o: 0, fw, fh };
|
|
239
|
+
const w = b.width ?? b.w ?? 0;
|
|
240
|
+
const h = b.height ?? b.h ?? 0;
|
|
241
|
+
return { x: b.x ?? 0, y: b.y ?? 0, w, h, o: b.opacity ?? 1, fw, fh };
|
|
242
|
+
}
|
|
243
|
+
const el = document.querySelector(what);
|
|
244
|
+
if (!el) return { x: 0, y: 0, w: 0, h: 0, o: 0, fw, fh };
|
|
245
|
+
const r = clipped(el, el.getBoundingClientRect());
|
|
246
|
+
let o = 1;
|
|
247
|
+
for (let n = /** @type {Element | null} */ (el); n && o > 0; n = n.parentElement) {
|
|
248
|
+
const cs = getComputedStyle(n);
|
|
249
|
+
if (cs.display === "none") o = 0;
|
|
250
|
+
else o *= Number.parseFloat(cs.opacity) || 0;
|
|
251
|
+
if (n === el && cs.visibility !== "visible") o = 0;
|
|
252
|
+
}
|
|
253
|
+
return { x: r.left, y: r.top, w: r.width, h: r.height, o, fw, fh };
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Something the film uses that someone else made, and on what terms — every
|
|
258
|
+
* field optional free words, for the record only.
|
|
259
|
+
* @typedef {object} FilmCredit
|
|
260
|
+
* @property {string} [what] e.g. "music: Night Drive", "font: Inter"
|
|
261
|
+
* @property {string} [by]
|
|
262
|
+
* @property {string} [licence] e.g. "CC0", "CC BY 4.0", "OFL-1.1", "bought, standard licence"
|
|
263
|
+
* @property {string} [url]
|
|
264
|
+
* @property {string} [text] the attribution line as it should appear, if one must
|
|
265
|
+
*/
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Where something on screen comes from — at least one of `ref`, `url` or
|
|
269
|
+
* `note`; for the record only.
|
|
270
|
+
* @typedef {object} FilmSource
|
|
271
|
+
* @property {string} label what on screen it covers: the text as shown, or words for it
|
|
272
|
+
* @property {string} [ref] a part of components.json, "<state>:<element id>"
|
|
273
|
+
* @property {string} [field] which of the part's values
|
|
274
|
+
* @property {string} [file] the components.json it was read from, as the page fetched it
|
|
275
|
+
* @property {string} [url] where the value shows in the live product
|
|
276
|
+
* @property {string} [note] "demo", "illustrative", or your own words
|
|
277
|
+
* @property {string[]} [text] the strings on screen it covers (beside the label)
|
|
278
|
+
* @property {string} [selector] the film's elements whose text it covers (CSS)
|
|
279
|
+
*/
|
|
280
|
+
|
|
281
|
+
/** a source's known fields as given; null when it names no ref, url or note
|
|
282
|
+
* @param {string} label @param {Record<string, unknown>} o @returns {FilmSource | null} */
|
|
283
|
+
const sourceOf = (label, o) => {
|
|
284
|
+
/** @type {FilmSource} */
|
|
285
|
+
const s = { label };
|
|
286
|
+
for (const k of /** @type {const} */ (["ref", "field", "file", "url", "note", "selector"])) {
|
|
287
|
+
const v = o[k];
|
|
288
|
+
if (v != null && v !== "") s[k] = String(v);
|
|
289
|
+
}
|
|
290
|
+
const text = o.text == null ? [] : Array.isArray(o.text) ? o.text : [o.text];
|
|
291
|
+
const strings = text.filter((x) => x != null && x !== "").map(String);
|
|
292
|
+
if (strings.length) s.text = strings;
|
|
293
|
+
return s.ref || s.url || s.note ? s : null;
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
/** a credit's known fields as strings; "license" is read as "licence"
|
|
297
|
+
* @param {Record<string, unknown>} o @returns {FilmCredit} */
|
|
298
|
+
const creditOf = (o) => {
|
|
299
|
+
/** @type {FilmCredit} */
|
|
300
|
+
const c = {};
|
|
301
|
+
/** @type {Record<string, unknown>} */
|
|
302
|
+
const src = { ...o, licence: o.licence ?? o.license };
|
|
303
|
+
for (const k of /** @type {const} */ (["what", "by", "licence", "url", "text"]))
|
|
304
|
+
if (src[k] != null && src[k] !== "") c[k] = String(src[k]);
|
|
305
|
+
return c;
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* @param {object} opts
|
|
310
|
+
* @param {Record<string, number>} [opts.at] named moments (s)
|
|
311
|
+
* @param {number} [opts.bpm] a pulse, if the film has one
|
|
312
|
+
* @param {number} [opts.offset] when beat 0 falls (s)
|
|
313
|
+
*/
|
|
314
|
+
export function timeline({ at = {}, bpm, offset = 0 } = {}) {
|
|
315
|
+
for (const [id, t] of Object.entries(at))
|
|
316
|
+
if (!Number.isFinite(t)) throw new Error(`timeline: "${id}" is not a time (${t})`);
|
|
317
|
+
if (bpm != null && !(bpm > 0 && Number.isFinite(bpm)))
|
|
318
|
+
throw new Error(`timeline: bpm is beats a minute, a number above 0 (got ${bpm})`);
|
|
319
|
+
const beatLen = bpm ? 60 / bpm : null;
|
|
320
|
+
/** @param {string} id */
|
|
321
|
+
const t = (id) => {
|
|
322
|
+
const v = at[id];
|
|
323
|
+
if (v == null) throw new Error(`timeline: no moment named "${id}"`);
|
|
324
|
+
return v;
|
|
325
|
+
};
|
|
326
|
+
/** a moment's name or a time in seconds, as a time @param {string | number} when */
|
|
327
|
+
const when = (when) => (typeof when === "string" ? t(when) : when);
|
|
328
|
+
const needBeat = () => {
|
|
329
|
+
if (beatLen == null) throw new Error("timeline: no bpm was given");
|
|
330
|
+
return beatLen;
|
|
331
|
+
};
|
|
332
|
+
/** @type {FilmEvent[]} */
|
|
333
|
+
const declared = [];
|
|
334
|
+
/** @type {Map<string, (t: number) => number>} */
|
|
335
|
+
const curves = new Map();
|
|
336
|
+
/** @type {FilmSegment[]} */
|
|
337
|
+
const sheet = [];
|
|
338
|
+
/** what each carry follows, at the boundary it crosses
|
|
339
|
+
* @type {{ at: number, what: string | ((t: number) => unknown) }[]} */
|
|
340
|
+
const carriers = [];
|
|
341
|
+
/** @type {FilmCredit[]} */
|
|
342
|
+
const credited = [];
|
|
343
|
+
const credits = () => credited.map((c) => ({ ...c }));
|
|
344
|
+
/** @type {FilmSource[]} */
|
|
345
|
+
const declaredSources = [];
|
|
346
|
+
const sources = () =>
|
|
347
|
+
declaredSources.map((x) => (x.text ? { ...x, text: [...x.text] } : { ...x }));
|
|
348
|
+
/** the beat sheet, by `from` (same from: as declared) */
|
|
349
|
+
const segments = () =>
|
|
350
|
+
sheet
|
|
351
|
+
.map((s, i) => /** @type {const} */ ([s, i]))
|
|
352
|
+
.sort((a, b) => a[0].from - b[0].from || a[1] - b[1])
|
|
353
|
+
.map(([s]) => (s.seam ? { ...s, seam: { ...s.seam } } : { ...s }));
|
|
354
|
+
|
|
355
|
+
/** events whose label is known only once the film is written — a cut
|
|
356
|
+
* `scenes` declared, labelled by the seam performed there */
|
|
357
|
+
/** @type {WeakMap<FilmEvent, () => string>} */
|
|
358
|
+
const lateLabels = new WeakMap();
|
|
359
|
+
/** @param {FilmEvent} e */
|
|
360
|
+
const labelled = (e) => {
|
|
361
|
+
const late = lateLabels.get(e);
|
|
362
|
+
return late ? { ...e, label: late() } : { ...e };
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
/** every named moment and declared event, in time order (same time: as declared) */
|
|
366
|
+
const events = () =>
|
|
367
|
+
/** @type {FilmEvent[]} */ ([
|
|
368
|
+
...Object.entries(at).map(([id, s]) => ({ t: s, kind: "mark", label: id, id })),
|
|
369
|
+
...declared.map(labelled),
|
|
370
|
+
])
|
|
371
|
+
.map((e, i) => /** @type {const} */ ([e, i]))
|
|
372
|
+
.sort((a, b) => a[0].t - b[0].t || a[1] - b[1])
|
|
373
|
+
.map(([e]) => e);
|
|
374
|
+
/** every curve at t; a curve that gives no finite number is left out @param {number} now */
|
|
375
|
+
const sample = (now) => {
|
|
376
|
+
/** @type {Record<string, number>} */
|
|
377
|
+
const out = {};
|
|
378
|
+
for (const [name, fn] of curves) {
|
|
379
|
+
const v = fn(now);
|
|
380
|
+
if (Number.isFinite(v)) out[name] = v;
|
|
381
|
+
}
|
|
382
|
+
for (const c of carriers) {
|
|
383
|
+
if (now < c.at - CARRY_BEFORE - 1e-6 || now > c.at + CARRY_AFTER + 1e-6) continue;
|
|
384
|
+
/** @type {ReturnType<typeof carryBox>} */
|
|
385
|
+
let b = null;
|
|
386
|
+
try {
|
|
387
|
+
b = carryBox(c.what, now);
|
|
388
|
+
} catch {
|
|
389
|
+
// a selector the page cannot read, or a box function that threw: this
|
|
390
|
+
// carry is left out here, the film's other curves are not
|
|
391
|
+
}
|
|
392
|
+
if (!b) continue;
|
|
393
|
+
for (const [k, v] of Object.entries(b))
|
|
394
|
+
if (Number.isFinite(v)) out[carryCurve(c.at, /** @type {"x"} */ (k))] = v;
|
|
395
|
+
}
|
|
396
|
+
return out;
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
return {
|
|
400
|
+
/** the time of a named moment (s) */
|
|
401
|
+
t,
|
|
402
|
+
/** 0 before the moment, 1 once `dur` has passed, linear between */
|
|
403
|
+
/** @param {number} now @param {string} id @param {number} dur */
|
|
404
|
+
local: (now, id, dur) => Math.max(0, Math.min(1, (now - t(id)) / dur)),
|
|
405
|
+
/** whether now lies in [from, to) — names or seconds */
|
|
406
|
+
/** @param {number} now @param {string | number} from @param {string | number} to */
|
|
407
|
+
between: (now, from, to) => now >= when(from) && now < when(to),
|
|
408
|
+
/** when beat n falls (s) */
|
|
409
|
+
/** @param {number} n */
|
|
410
|
+
beat: (n) => offset + n * needBeat(),
|
|
411
|
+
/** the nearest beat to a time (s) */
|
|
412
|
+
/** @param {number} s */
|
|
413
|
+
snap: (s) => {
|
|
414
|
+
const len = needBeat();
|
|
415
|
+
return offset + Math.round((s - offset) / len) * len;
|
|
416
|
+
},
|
|
417
|
+
/** the beat a time falls in, counting from 0 */
|
|
418
|
+
/** @param {number} s */
|
|
419
|
+
beatOf: (s) => Math.floor((s - offset) / needBeat() + 1e-9),
|
|
420
|
+
/**
|
|
421
|
+
* Say that something happens: at a moment's name or a time (s), of a kind
|
|
422
|
+
* you name. Returns its time, so a page can use it too.
|
|
423
|
+
* @param {string | number} at
|
|
424
|
+
* @param {string} kind
|
|
425
|
+
* @param {{ x?: number, y?: number, force?: number, label?: string, labelOf?: () => string }} [o]
|
|
426
|
+
* labelOf: the label, asked each time the events are read (a cut `scenes` declares,
|
|
427
|
+
* named after the seam performed there)
|
|
428
|
+
*/
|
|
429
|
+
event: (at, kind, o = {}) => {
|
|
430
|
+
const s = when(at);
|
|
431
|
+
if (!Number.isFinite(s))
|
|
432
|
+
throw new Error(`timeline: event "${kind}" is not at a time (${at})`);
|
|
433
|
+
if (typeof kind !== "string" || !kind) throw new Error("timeline: an event needs a kind");
|
|
434
|
+
/** @type {FilmEvent} */
|
|
435
|
+
const e = { t: s, kind };
|
|
436
|
+
for (const k of /** @type {const} */ (["x", "y", "force"])) {
|
|
437
|
+
const v = o[k];
|
|
438
|
+
if (v == null) continue;
|
|
439
|
+
if (!Number.isFinite(v))
|
|
440
|
+
throw new Error(`timeline: event "${kind}" at ${s}s: ${k} is ${v}`);
|
|
441
|
+
e[k] = k === "force" ? Math.max(0, Math.min(1, v)) : v;
|
|
442
|
+
}
|
|
443
|
+
if (o.label != null) e.label = String(o.label);
|
|
444
|
+
if (typeof o.labelOf === "function") lateLabels.set(e, o.labelOf);
|
|
445
|
+
declared.push(e);
|
|
446
|
+
return s;
|
|
447
|
+
},
|
|
448
|
+
/** every named moment (kind "mark", with its name as `id` and `label`) and
|
|
449
|
+
* every declared event, in time order */
|
|
450
|
+
events,
|
|
451
|
+
/**
|
|
452
|
+
* A number that changes over the film — a zoom, a speed, a level — for the
|
|
453
|
+
* score to follow. `film render` samples it once a frame. Named again, it
|
|
454
|
+
* is replaced.
|
|
455
|
+
* @param {string} name
|
|
456
|
+
* @param {(t: number) => number} fn
|
|
457
|
+
*/
|
|
458
|
+
curve: (name, fn) => {
|
|
459
|
+
if (typeof fn !== "function")
|
|
460
|
+
throw new Error(`timeline: curve "${name}" is not a function of t`);
|
|
461
|
+
curves.set(name, fn);
|
|
462
|
+
},
|
|
463
|
+
/** every curve at t, by name */
|
|
464
|
+
curves: sample,
|
|
465
|
+
/**
|
|
466
|
+
* Say what a stretch of the film is meant to do — a line of a beat sheet,
|
|
467
|
+
* every field optional free words (`hold` true or false). From and to are
|
|
468
|
+
* moments' names or seconds. Returns the segment.
|
|
469
|
+
* @param {string | number} from
|
|
470
|
+
* @param {string | number} to
|
|
471
|
+
* @param {{ label?: string, hold?: boolean, handoff?: string | { kind: string, [k: string]: unknown },
|
|
472
|
+
* carry?: string | ((t: number) => { x: number, y: number, width: number, height: number, opacity?: number } | null),
|
|
473
|
+
* subject?: string, sound?: string }} [o]
|
|
474
|
+
* carry: what lives through the boundary at `to` — a CSS selector, or a
|
|
475
|
+
* function of t giving its box in frame px (a canvas's own drawing);
|
|
476
|
+
* `film render` follows it 0.4 s each side and says what it did
|
|
477
|
+
*/
|
|
478
|
+
segment: (from, to, o = {}) => {
|
|
479
|
+
const a = when(from);
|
|
480
|
+
const b = when(to);
|
|
481
|
+
if (!Number.isFinite(a) || !Number.isFinite(b))
|
|
482
|
+
throw new Error(`timeline: segment ${from}–${to} is not between two times`);
|
|
483
|
+
if (!(b > a)) throw new Error(`timeline: segment ${from}–${to} ends before it starts`);
|
|
484
|
+
/** @type {FilmSegment} */
|
|
485
|
+
const seg = { from: a, to: b };
|
|
486
|
+
const h = o.handoff;
|
|
487
|
+
if (h != null && typeof h === "object") {
|
|
488
|
+
const { kind, ...opts } = /** @type {{ kind?: unknown, [k: string]: unknown }} */ (h);
|
|
489
|
+
if (typeof kind !== "string" || !kind)
|
|
490
|
+
throw new Error(
|
|
491
|
+
`timeline: segment ${from}–${to}: a handoff given as an object needs its kind`,
|
|
492
|
+
);
|
|
493
|
+
seg.handoff = kind;
|
|
494
|
+
/** @type {Record<string, number | string>} */
|
|
495
|
+
const seam = {};
|
|
496
|
+
for (const [k, v] of Object.entries(opts))
|
|
497
|
+
if ((typeof v === "number" && Number.isFinite(v)) || typeof v === "string") seam[k] = v;
|
|
498
|
+
if (Object.keys(seam).length) seg.seam = seam;
|
|
499
|
+
} else if (h != null) seg.handoff = String(h);
|
|
500
|
+
for (const k of /** @type {const} */ (["label", "subject", "sound"]))
|
|
501
|
+
if (o[k] != null) seg[k] = String(o[k]);
|
|
502
|
+
if (o.carry != null) {
|
|
503
|
+
if (typeof o.carry === "function") seg.carry = "(a function)";
|
|
504
|
+
else if (typeof o.carry === "string" && o.carry.trim()) seg.carry = o.carry.trim();
|
|
505
|
+
else
|
|
506
|
+
throw new Error(
|
|
507
|
+
`timeline: segment ${from}–${to}: carry is a CSS selector, or a function of t giving a box`,
|
|
508
|
+
);
|
|
509
|
+
// two segments ending together name one boundary: the first carry is the one followed
|
|
510
|
+
// (the report reads the same one), a second would only overwrite its curves
|
|
511
|
+
if (!carriers.some((c) => Math.abs(c.at - b) < 1e-6))
|
|
512
|
+
carriers.push({ at: b, what: typeof o.carry === "function" ? o.carry : seg.carry });
|
|
513
|
+
}
|
|
514
|
+
if (o.hold != null) seg.hold = !!o.hold;
|
|
515
|
+
sheet.push(seg);
|
|
516
|
+
return { ...seg };
|
|
517
|
+
},
|
|
518
|
+
/** the beat sheet, by `from` */
|
|
519
|
+
segments,
|
|
520
|
+
/**
|
|
521
|
+
* Keep a record of something the film uses that someone else made: what,
|
|
522
|
+
* by whom, under what licence, where from, and the attribution line —
|
|
523
|
+
* every field optional, nothing checked. Returns the credit.
|
|
524
|
+
* @param {{ what?: string, by?: string, licence?: string, license?: string, url?: string, text?: string }} o
|
|
525
|
+
*/
|
|
526
|
+
credit: (o) => {
|
|
527
|
+
if (!o || typeof o !== "object") throw new Error("timeline: a credit is an object");
|
|
528
|
+
const c = creditOf(/** @type {Record<string, unknown>} */ (o));
|
|
529
|
+
if (!Object.keys(c).length)
|
|
530
|
+
throw new Error("timeline: a credit says nothing (what, by, licence, url or text)");
|
|
531
|
+
credited.push(c);
|
|
532
|
+
return { ...c };
|
|
533
|
+
},
|
|
534
|
+
/** every credit, as given */
|
|
535
|
+
credits,
|
|
536
|
+
/**
|
|
537
|
+
* Say where something on screen comes from: a part of components.json
|
|
538
|
+
* (`ref`, and which of its values, `field`), the live page it shows on
|
|
539
|
+
* (`url`), or a `note` — "demo", "illustrative" or your words. `label` is
|
|
540
|
+
* what on screen it covers (the text as shown, or words for it); `text`
|
|
541
|
+
* the strings it covers, `selector` the film's elements whose text it
|
|
542
|
+
* covers. Nothing is checked; returns the source.
|
|
543
|
+
* @param {string} label
|
|
544
|
+
* @param {{ ref?: string, field?: string, file?: string, url?: string, note?: "demo" | "illustrative" | string,
|
|
545
|
+
* text?: string | string[], selector?: string }} o
|
|
546
|
+
*/
|
|
547
|
+
source: (label, o) => {
|
|
548
|
+
if (typeof label !== "string" || !label.trim())
|
|
549
|
+
throw new Error("timeline: a source needs a label — what on screen it covers");
|
|
550
|
+
if (!o || typeof o !== "object")
|
|
551
|
+
throw new Error(`timeline: source "${label}" needs { ref }, { url } or { note }`);
|
|
552
|
+
const s = sourceOf(label, /** @type {Record<string, unknown>} */ (o));
|
|
553
|
+
if (!s)
|
|
554
|
+
throw new Error(
|
|
555
|
+
`timeline: source "${label}" says nothing of where it comes from — a ref (a part of components.json), a url, or a note ("demo", "illustrative")`,
|
|
556
|
+
);
|
|
557
|
+
declaredSources.push(s);
|
|
558
|
+
return s.text ? { ...s, text: [...s.text] } : { ...s };
|
|
559
|
+
},
|
|
560
|
+
/** every source, as given */
|
|
561
|
+
sources,
|
|
562
|
+
/** window.__film's `events`, `curves`, `segments`, `credits` and `sources`, to spread into it */
|
|
563
|
+
hooks: () => ({ events, curves: sample, segments, credits, sources }),
|
|
564
|
+
bpm,
|
|
565
|
+
offset,
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* Cut times from a list of numbers, or of events (those of kind "cut"), or of
|
|
571
|
+
* a camera's moves (kit/camera.js `cam.moves()`: those of kind "cut", at
|
|
572
|
+
* their `t0`), or a function that gives any of these when asked — ascending,
|
|
573
|
+
* finite only.
|
|
574
|
+
* @param {CutList | (() => CutList) | undefined} cuts
|
|
575
|
+
* @returns {number[]}
|
|
576
|
+
* @typedef {readonly (number | { t?: number, t0?: number, kind?: string })[]} CutList
|
|
577
|
+
*/
|
|
578
|
+
export function cutTimes(cuts) {
|
|
579
|
+
const list = typeof cuts === "function" ? cuts() : cuts;
|
|
580
|
+
if (list == null) return [];
|
|
581
|
+
if (!Array.isArray(list)) throw new Error("cuts: a list of times (s) or of events");
|
|
582
|
+
/** @type {number[]} */
|
|
583
|
+
const out = [];
|
|
584
|
+
for (const c of list) {
|
|
585
|
+
const t = typeof c === "number" ? c : c && c.kind === "cut" ? (c.t ?? c.t0) : Number.NaN;
|
|
586
|
+
if (t != null && Number.isFinite(t)) out.push(t);
|
|
587
|
+
}
|
|
588
|
+
return out.sort((a, b) => a - b);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* How fast something moves at t (units a second): `fn` gives a number, an
|
|
593
|
+
* { x, y } point (a camera's view also counts its width, `w`), or [x, y];
|
|
594
|
+
* the speed is measured across `h` s either side.
|
|
595
|
+
*
|
|
596
|
+
* At a hard cut the picture does not travel from one framing to the next, it
|
|
597
|
+
* replaces it — so given `cuts` (times, or events of kind "cut", or a
|
|
598
|
+
* function that gives them: `tl.events` for the cuts declared on the
|
|
599
|
+
* timeline, `cam.moves` for a camera's own `cam.cut`s), each shot is measured on its
|
|
600
|
+
* own: within `h` of a cut the difference is taken one-sided, inside the
|
|
601
|
+
* shot t is in. The speed holds the shot's own value up to the cut, and the
|
|
602
|
+
* next shot starts from its own first frames; the jump between the two
|
|
603
|
+
* framings never shows up as a spike. A cut at time c belongs to the shot
|
|
604
|
+
* that starts at c. Without `cuts` it differences straight across.
|
|
605
|
+
*
|
|
606
|
+
* tl.curve("camSpeed", speed((t) => cam.at(t), 1 / 240, { cuts: cam.moves }));
|
|
607
|
+
* // cuts on the timeline too: { cuts: () => [...tl.events(), ...cam.moves()] }
|
|
608
|
+
*
|
|
609
|
+
* @param {(t: number) => number | number[] | { x?: number, y?: number, cx?: number, cy?: number, w?: number }} fn
|
|
610
|
+
* @param {number} [h]
|
|
611
|
+
* @param {{ cuts?: CutList | (() => CutList) }} [o]
|
|
612
|
+
* @returns {(t: number) => number}
|
|
613
|
+
*/
|
|
614
|
+
export function speed(fn, h = 1 / 240, { cuts } = {}) {
|
|
615
|
+
if (!(h > 0)) throw new Error(`speed: h is a time step above 0 (got ${h})`);
|
|
616
|
+
/** @param {ReturnType<typeof fn>} v @returns {number[]} */
|
|
617
|
+
const vec = (v) => {
|
|
618
|
+
if (typeof v === "number") return [v];
|
|
619
|
+
if (Array.isArray(v)) return v;
|
|
620
|
+
return [v.x ?? v.cx ?? 0, v.y ?? v.cy ?? 0, v.w ?? 0];
|
|
621
|
+
};
|
|
622
|
+
// a fixed list is read once; a function is asked each time (cuts declared later count)
|
|
623
|
+
const fixed = typeof cuts === "function" ? null : cutTimes(cuts);
|
|
624
|
+
/** how far before a cut the shot ends (s): the last instant of the old picture */
|
|
625
|
+
const edge = h * 1e-3;
|
|
626
|
+
return (t) => {
|
|
627
|
+
let lo = Math.max(0, t - h);
|
|
628
|
+
let hi = t + h;
|
|
629
|
+
const cs = fixed ?? cutTimes(cuts);
|
|
630
|
+
for (const c of cs) {
|
|
631
|
+
if (c <= t) lo = Math.max(lo, c);
|
|
632
|
+
else hi = Math.min(hi, c - edge);
|
|
633
|
+
}
|
|
634
|
+
const span = hi - lo;
|
|
635
|
+
if (!(span > 0)) return 0;
|
|
636
|
+
const a = vec(fn(lo));
|
|
637
|
+
const b = vec(fn(hi));
|
|
638
|
+
let d = 0;
|
|
639
|
+
for (let i = 0; i < a.length; i++) d += ((b[i] ?? 0) - (a[i] ?? 0)) ** 2;
|
|
640
|
+
return Math.sqrt(d) / span;
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* Scenes: which element shows when — each a name (an element's id, or a
|
|
646
|
+
* selector) and when it is on, [from, to) in s, or a list of such spans for
|
|
647
|
+
* a scene that comes back. `show(t)` sets each one's visibility: hidden off
|
|
648
|
+
* its spans, inherited on them (so a scene inside a hidden one stays hidden)
|
|
649
|
+
* — never display, so what is inside keeps its layout. Scenes may overlap.
|
|
650
|
+
* With `tl`, each start after 0 is declared a "cut" there (labelled with the
|
|
651
|
+
* scene's name). `el`: how a name finds its element (default by id, or by
|
|
652
|
+
* selector when it looks like one). `seams`, the kit/seams.js module (with a
|
|
653
|
+
* `tl` that keeps a beat sheet): each boundary whose segment ending there
|
|
654
|
+
* names a seam's kind (its `kindOf`) is performed by show(t), and its cut is
|
|
655
|
+
* labelled "seam: <kind>"; `view`, the picture's size for a whip (default
|
|
656
|
+
* 1920×1080).
|
|
657
|
+
* @param {Record<string, [number, number] | [number, number][]>} map
|
|
658
|
+
* @param {{ tl?: { event: (at: number, kind: string, o?: { label?: string, labelOf?: () => string }) => number,
|
|
659
|
+
* segments?: () => FilmSegment[] },
|
|
660
|
+
* el?: (name: string) => { style: { visibility: string } } | null,
|
|
661
|
+
* seams?: { seams: typeof import("./seams.js").seams, kindOf: (name: unknown) => string | null },
|
|
662
|
+
* view?: { width: number, height: number } }} [o]
|
|
663
|
+
*/
|
|
664
|
+
export function scenes(map, o = {}) {
|
|
665
|
+
/** @type {{ name: string, spans: [number, number][] }[]} */
|
|
666
|
+
const list = Object.entries(map).map(([name, v]) => {
|
|
667
|
+
if (!Array.isArray(v) || !v.length)
|
|
668
|
+
throw new Error(`scenes: "${name}" needs [from, to] (s), or a list of them`);
|
|
669
|
+
const spans = /** @type {[number, number][]} */ (
|
|
670
|
+
Array.isArray(v[0]) ? v : [/** @type {[number, number]} */ (v)]
|
|
671
|
+
);
|
|
672
|
+
for (const sp of spans) {
|
|
673
|
+
const [a, b] = sp;
|
|
674
|
+
if (!Number.isFinite(a) || !Number.isFinite(b))
|
|
675
|
+
throw new Error(`scenes: "${name}" is on between two times (got ${JSON.stringify(sp)})`);
|
|
676
|
+
if (!(b > a)) throw new Error(`scenes: "${name}" ends (${b}) before it starts (${a})`);
|
|
677
|
+
}
|
|
678
|
+
return { name, spans: spans.map(([a, b]) => /** @type {[number, number]} */ ([a, b])) };
|
|
679
|
+
});
|
|
680
|
+
const kit = o.seams ?? null;
|
|
681
|
+
if (kit && (typeof kit.seams !== "function" || typeof kit.kindOf !== "function"))
|
|
682
|
+
throw new Error(
|
|
683
|
+
'scenes: seams is the kit/seams.js module — import * as seams from "./kit/seams.js"',
|
|
684
|
+
);
|
|
685
|
+
const withSeams = !!kit && !!o.tl && typeof o.tl.segments === "function";
|
|
686
|
+
if (o.tl)
|
|
687
|
+
for (const sc of list)
|
|
688
|
+
for (const [a] of sc.spans)
|
|
689
|
+
if (a > 0)
|
|
690
|
+
o.tl.event(a, "cut", {
|
|
691
|
+
label: sc.name,
|
|
692
|
+
...(withSeams ? { labelOf: () => seamAt(a) ?? sc.name } : {}),
|
|
693
|
+
});
|
|
694
|
+
/** @type {Map<string, { style: { visibility: string } }>} */
|
|
695
|
+
const found = new Map();
|
|
696
|
+
/** @param {string} name */
|
|
697
|
+
const elOf = (name) => {
|
|
698
|
+
const had = found.get(name);
|
|
699
|
+
if (had) return had;
|
|
700
|
+
const el = o.el
|
|
701
|
+
? o.el(name)
|
|
702
|
+
: (document.getElementById(name) ??
|
|
703
|
+
(/^[#.[]|[\s>:]/.test(name) ? document.querySelector(name) : null));
|
|
704
|
+
if (!el) throw new Error(`scenes: no element for the scene "${name}" (an id, or a selector)`);
|
|
705
|
+
found.set(name, /** @type {{ style: { visibility: string } }} */ (el));
|
|
706
|
+
return /** @type {{ style: { visibility: string } }} */ (el);
|
|
707
|
+
};
|
|
708
|
+
/** the scenes on at t, by name @param {number} t */
|
|
709
|
+
const at = (t) =>
|
|
710
|
+
list.filter((sc) => sc.spans.some(([a, b]) => t >= a && t < b)).map((sc) => sc.name);
|
|
711
|
+
const view = o.view ?? { width: 1920, height: 1080 };
|
|
712
|
+
/** @type {ReturnType<typeof import("./seams.js").seams> | null} */
|
|
713
|
+
let performed = null;
|
|
714
|
+
/** how many segments the sheet held when the seams were built */
|
|
715
|
+
let builtFrom = -1;
|
|
716
|
+
/** the boundaries the beat sheet names a kind at, as seams() takes them —
|
|
717
|
+
* read when first needed and again whenever the sheet has grown since (it
|
|
718
|
+
* may be written after the scenes, or after a first show(t)) */
|
|
719
|
+
const boundaryList = () => {
|
|
720
|
+
if (!withSeams) return [];
|
|
721
|
+
const sheet = o.tl?.segments ? o.tl.segments() : [];
|
|
722
|
+
/** @type {{ at: number, from: string, to: string, kind: string, [k: string]: unknown }[]} */
|
|
723
|
+
const out = [];
|
|
724
|
+
for (const sc of list)
|
|
725
|
+
for (const [a] of sc.spans) {
|
|
726
|
+
if (!(a > 0)) continue;
|
|
727
|
+
const seg = sheet.find((x) => Math.abs(x.to - a) < 1e-6 && kit?.kindOf(x.handoff));
|
|
728
|
+
if (!seg) continue;
|
|
729
|
+
const from =
|
|
730
|
+
list.find((x) => x !== sc && x.spans.some(([, b]) => Math.abs(b - a) < 1e-6)) ??
|
|
731
|
+
list.find(
|
|
732
|
+
(x) =>
|
|
733
|
+
x !== sc &&
|
|
734
|
+
x.spans.some(([p, q]) => a - 1e-6 >= p && a - 1e-6 < q) &&
|
|
735
|
+
!x.spans.some(([p, q]) => a >= p && a < q),
|
|
736
|
+
);
|
|
737
|
+
if (!from) continue;
|
|
738
|
+
const kind = /** @type {string} */ (kit?.kindOf(seg.handoff));
|
|
739
|
+
const opts = { ...(seg.seam ?? {}) };
|
|
740
|
+
if (!("dir" in opts) && (kind === "curve" || kind === "whip")) {
|
|
741
|
+
const next = sheet.find((x) => Math.abs(x.from - a) < 1e-6 && x.subject);
|
|
742
|
+
const d = dirToward(next?.subject ?? seg.subject, view);
|
|
743
|
+
if (d) opts.dir = d;
|
|
744
|
+
}
|
|
745
|
+
out.push({ ...opts, at: a, from: from.name, to: sc.name, kind });
|
|
746
|
+
}
|
|
747
|
+
return out;
|
|
748
|
+
};
|
|
749
|
+
const seamsHere = () => {
|
|
750
|
+
const n = o.tl?.segments ? o.tl.segments().length : 0;
|
|
751
|
+
if (!performed || n !== builtFrom) {
|
|
752
|
+
performed = /** @type {NonNullable<typeof kit>} */ (kit).seams(null, boundaryList(), {
|
|
753
|
+
view,
|
|
754
|
+
// the same element show(t) finds for the scene
|
|
755
|
+
el: (name) => /** @type {Element} */ (/** @type {unknown} */ (elOf(String(name)))),
|
|
756
|
+
});
|
|
757
|
+
builtFrom = n;
|
|
758
|
+
}
|
|
759
|
+
return performed;
|
|
760
|
+
};
|
|
761
|
+
/** the label of the seam performed at a boundary, if one is @param {number} a */
|
|
762
|
+
const seamAt = (a) => {
|
|
763
|
+
const s = seamsHere()
|
|
764
|
+
.list()
|
|
765
|
+
.find((x) => Math.abs(x.at - a) < 1e-6);
|
|
766
|
+
return s ? `seam: ${s.kind}` : null;
|
|
767
|
+
};
|
|
768
|
+
return {
|
|
769
|
+
/** every scene and its spans, as given */
|
|
770
|
+
list: () => list.map((sc) => ({ name: sc.name, spans: sc.spans.map((sp) => [...sp]) })),
|
|
771
|
+
at,
|
|
772
|
+
/** the seams performed at the boundaries, given the seams module: [{ at, kind, from, to, span }] */
|
|
773
|
+
seams: () => (withSeams ? seamsHere().list() : []),
|
|
774
|
+
/** show the scenes on at t and hide the rest — and, given the seams module,
|
|
775
|
+
* write both sides of every seam open at t; returns the names shown
|
|
776
|
+
* @param {number} t */
|
|
777
|
+
show(t) {
|
|
778
|
+
const on = at(t);
|
|
779
|
+
for (const sc of list)
|
|
780
|
+
elOf(sc.name).style.visibility = on.includes(sc.name) ? "inherit" : "hidden";
|
|
781
|
+
if (withSeams) seamsHere().apply(t);
|
|
782
|
+
return on;
|
|
783
|
+
},
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
/**
|
|
788
|
+
* The way a cut on the curve or a whip travels so the incoming scene arrives
|
|
789
|
+
* from the side its subject is on — a subject right of the middle comes in
|
|
790
|
+
* from the right, so the strip travels left. Null when the subject is not
|
|
791
|
+
* found or sits in the middle.
|
|
792
|
+
* @param {string | undefined} subject a CSS selector
|
|
793
|
+
* @param {{ width: number, height: number }} view
|
|
794
|
+
* @returns {"left" | "right" | "up" | "down" | null}
|
|
795
|
+
*/
|
|
796
|
+
function dirToward(subject, view) {
|
|
797
|
+
if (!subject || typeof document === "undefined") return null;
|
|
798
|
+
let el = null;
|
|
799
|
+
try {
|
|
800
|
+
el = document.querySelector(subject);
|
|
801
|
+
} catch {
|
|
802
|
+
return null;
|
|
803
|
+
}
|
|
804
|
+
if (!el) return null;
|
|
805
|
+
const r = clipped(el, el.getBoundingClientRect());
|
|
806
|
+
if (!(r.width > 0 && r.height > 0)) return null;
|
|
807
|
+
const dx = (r.left + r.width / 2 - view.width / 2) / view.width;
|
|
808
|
+
const dy = (r.top + r.height / 2 - view.height / 2) / view.height;
|
|
809
|
+
if (Math.max(Math.abs(dx), Math.abs(dy)) < 0.08) return null;
|
|
810
|
+
if (Math.abs(dx) >= Math.abs(dy)) return dx > 0 ? "left" : "right";
|
|
811
|
+
return dy > 0 ? "up" : "down";
|
|
812
|
+
}
|