@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/stage.js
ADDED
|
@@ -0,0 +1,923 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Depth for a film page — open-take's film kit. Parts of the product as flat
|
|
3
|
+
// slabs in 3D: a screen tilted into space while what is on it keeps working,
|
|
4
|
+
// a screen coming apart into its parts and back together, cards lowered onto
|
|
5
|
+
// the stage like prints or onto a pile, a card turning over to show the next
|
|
6
|
+
// scene, the whole layout turning into a table, the lens travelling past one
|
|
7
|
+
// slab into what lies behind it. A slab is one element — a part of a saved
|
|
8
|
+
// screen shown through a window its size (an iframe of state.html cropped to
|
|
9
|
+
// the part: live DOM), a part's own file (parts/), a crop of a picture, a
|
|
10
|
+
// <video>, any node — with its own pose over time; the stage turns the poses
|
|
11
|
+
// into one CSS transform per slab.
|
|
12
|
+
//
|
|
13
|
+
// Sharp by construction. Chrome draws a layer under a perspective at no more
|
|
14
|
+
// than about the frame's area and stretches it (`skill film render`: a whole
|
|
15
|
+
// saved page tilted and pushed to 2.3× went soft; a tilted box no bigger than
|
|
16
|
+
// the part it showed stayed sharp). So here:
|
|
17
|
+
// - each slab is laid out at its part's own size, with its own perspective
|
|
18
|
+
// — no perspective on a parent, no layer bigger than the part it shows;
|
|
19
|
+
// - a slab square on to the lens (no tilt left) is written as a plain 2D
|
|
20
|
+
// transform, no perspective at all, so a push into it — or the lens
|
|
21
|
+
// travelling up to it — is drawn at its final scale;
|
|
22
|
+
// - warnings() names a tilted slab drawn bigger than the frame (it would be
|
|
23
|
+
// stretched) and when, and at(t) says it per slab (`soft`).
|
|
24
|
+
//
|
|
25
|
+
// Nothing is on until you ask: a film that never calls stage() stays flat, a
|
|
26
|
+
// slab never moved stays where its part sat, and no move has a default angle.
|
|
27
|
+
// The few defaults below each say where they come from (`skill film craft`).
|
|
28
|
+
//
|
|
29
|
+
// import { stage, explode, together, drop, flip } from "./kit/stage.js";
|
|
30
|
+
// const st = stage({ el: document.querySelector("#stage"), camera: cam });
|
|
31
|
+
// const card = st.slab(frameOf("states/home/state.html"), { crop: { x: 607, y: 136, width: 706, height: 203 } });
|
|
32
|
+
// card.to({ rx: 20, ry: -28 }, { start: 2, dur: 0.9 }); // tilts into depth, content still live
|
|
33
|
+
// card.to({ rx: 0, ry: 0 }, { arrive: 5 }); // and square on again
|
|
34
|
+
// st.turn({ rx: 40 }, { start: 6, dur: 1.2 }); // the whole layout becomes a table
|
|
35
|
+
// explode([bg, header, card], { start: 7.5, gap: 140 }); // its parts lift apart
|
|
36
|
+
// window.__render = (t) => st.apply(t);
|
|
37
|
+
//
|
|
38
|
+
// Or a picture, a video or a part the page already has, where it is — not
|
|
39
|
+
// moved, not wrapped, untouched until it is asked to move (`st.adopt`):
|
|
40
|
+
//
|
|
41
|
+
// const st = stage();
|
|
42
|
+
// const shot = st.adopt(document.querySelector("#nycShot"));
|
|
43
|
+
// shot.to({ rx: 7, ry: -9 }, { start: 3.9, dur: 0.7 }); // tilted into depth, then
|
|
44
|
+
// shot.to({ rx: 0, ry: 0 }, { arrive: 6 }); // square on: as it was
|
|
45
|
+
// window.__render = (t) => { sc.show(t); st.apply(t); }; // after scenes, if any
|
|
46
|
+
|
|
47
|
+
/** @typedef {{ x: number, y: number, w?: number, h?: number, width?: number, height?: number }} BoxLike */
|
|
48
|
+
/** @typedef {{ x: number, y: number, w: number, h: number }} Box */
|
|
49
|
+
/**
|
|
50
|
+
* @typedef {object} Pose where a slab is, from where its part sat
|
|
51
|
+
* @property {number} x px across, from its place (default 0)
|
|
52
|
+
* @property {number} y px down
|
|
53
|
+
* @property {number} z px toward the lens (+) or away (−)
|
|
54
|
+
* @property {number} rx degrees about its horizontal axis — positive tips its top away
|
|
55
|
+
* @property {number} ry degrees about its vertical axis — positive turns its right side away
|
|
56
|
+
* @property {number} rz degrees in its own plane, clockwise
|
|
57
|
+
* @property {number} scale its size, 1 as it sat
|
|
58
|
+
* @property {number} opacity 0..1
|
|
59
|
+
*/
|
|
60
|
+
/**
|
|
61
|
+
* @typedef {object} When when a move happens — one of `arrive` or `start`
|
|
62
|
+
* @property {number} [start] the move leaves here (s)
|
|
63
|
+
* @property {number} [arrive] the move lands here (s)
|
|
64
|
+
* @property {number} [dur] how long it takes (s, default 0.73 — the camera's push-in)
|
|
65
|
+
* @property {(p: number) => number} [ease] progress 0..1 over `dur`; default: the camera's settle (96 % in `dur`, the rest into the hold)
|
|
66
|
+
* @property {{ freq?: number, damping?: number, overshoot?: number }} [spring] a spring instead of `ease`:
|
|
67
|
+
* it runs until it settles (its `dur` is that time); freq Hz (default 1.6), damping ratio or overshoot share
|
|
68
|
+
*/
|
|
69
|
+
/** @typedef {{ cx: number, cy: number, w: number, scale: number }} View */
|
|
70
|
+
/** @typedef {{ at: (t: number) => View, jitter?: (t: number) => { x: number, y: number, rot: number }, view?: { width: number, height: number }, content?: { width: number, height: number } }} CameraLike a kit camera (kit/camera.js) */
|
|
71
|
+
/** @typedef {number[]} Mat a 4×4 matrix, column-major (as CSS matrix3d lists it) */
|
|
72
|
+
|
|
73
|
+
const FIELDS = /** @type {const} */ (["x", "y", "z", "rx", "ry", "rz", "scale", "opacity"]);
|
|
74
|
+
/** @type {Pose} */
|
|
75
|
+
const REST = Object.freeze({ x: 0, y: 0, z: 0, rx: 0, ry: 0, rz: 0, scale: 1, opacity: 1 });
|
|
76
|
+
// a lens 2000 px from the stage: the middle of the 1600–2800 px measured on
|
|
77
|
+
// the films that tilted a screen into space (`skill film craft`, Depth)
|
|
78
|
+
const DEFAULT_PERSPECTIVE = 2000;
|
|
79
|
+
// the camera's push-in: 0.73 s, 96 % of the way in its time, the rest
|
|
80
|
+
// settling into the hold (kit/camera.js)
|
|
81
|
+
const DEFAULT_DUR = 0.73;
|
|
82
|
+
const SETTLE = 0.04;
|
|
83
|
+
|
|
84
|
+
// --- small helpers ----------------------------------------------------------
|
|
85
|
+
|
|
86
|
+
/** @param {number} x */
|
|
87
|
+
const clamp01 = (x) => Math.max(0, Math.min(1, x));
|
|
88
|
+
/** @param {number} a @param {number} b @param {number} p */
|
|
89
|
+
const lerp = (a, b, p) => a + (b - a) * p;
|
|
90
|
+
const RAD = Math.PI / 180;
|
|
91
|
+
/** @param {BoxLike} b @returns {Box} */
|
|
92
|
+
const boxOf = (b) => ({ x: b.x, y: b.y, w: b.w ?? b.width ?? 0, h: b.h ?? b.height ?? 0 });
|
|
93
|
+
/** @param {number} v */
|
|
94
|
+
const f6 = (v) => (Math.abs(v) < 1e-12 ? 0 : +v.toPrecision(10));
|
|
95
|
+
|
|
96
|
+
/** what is left of a move at progress u: an overdamped spring's step (ζ 1.2)
|
|
97
|
+
* whose residual at u = 1 is `frac` — the camera's settleDecay (kit/camera.js) */
|
|
98
|
+
/** @param {number} frac */
|
|
99
|
+
function settleDecay(frac) {
|
|
100
|
+
const zeta = 1.2;
|
|
101
|
+
const s = Math.sqrt(zeta * zeta - 1);
|
|
102
|
+
const l1 = zeta + s;
|
|
103
|
+
const l2 = zeta - s;
|
|
104
|
+
/** @param {number} x */
|
|
105
|
+
const resid = (x) => (l1 * Math.exp(-l2 * x) - l2 * Math.exp(-l1 * x)) / (l1 - l2);
|
|
106
|
+
let lo = 0.1;
|
|
107
|
+
let hi = 60;
|
|
108
|
+
for (let i = 0; i < 60; i++) {
|
|
109
|
+
const mid = (lo + hi) / 2;
|
|
110
|
+
if (resid(mid) > frac) lo = mid;
|
|
111
|
+
else hi = mid;
|
|
112
|
+
}
|
|
113
|
+
const w0T = (lo + hi) / 2;
|
|
114
|
+
/** @param {number} u */
|
|
115
|
+
return (u) => (u <= 0 ? 1 : resid(w0T * u));
|
|
116
|
+
}
|
|
117
|
+
const decay = settleDecay(SETTLE);
|
|
118
|
+
|
|
119
|
+
/** a unit step of a damped spring, from 0 toward 1, τ s after release (the
|
|
120
|
+
* closed forms of kit/motion.js's spring) */
|
|
121
|
+
/** @param {number} tau @param {number} w0 @param {number} zeta */
|
|
122
|
+
function springStep(tau, w0, zeta) {
|
|
123
|
+
if (tau <= 0) return 0;
|
|
124
|
+
if (Math.abs(zeta - 1) < 1e-6) return 1 - Math.exp(-w0 * tau) * (1 + w0 * tau);
|
|
125
|
+
if (zeta < 1) {
|
|
126
|
+
const wd = w0 * Math.sqrt(1 - zeta * zeta);
|
|
127
|
+
const a = zeta * w0;
|
|
128
|
+
return 1 - Math.exp(-a * tau) * (Math.cos(wd * tau) + (a / wd) * Math.sin(wd * tau));
|
|
129
|
+
}
|
|
130
|
+
const q = Math.sqrt(zeta * zeta - 1);
|
|
131
|
+
const r1 = -w0 * (zeta - q);
|
|
132
|
+
const r2 = -w0 * (zeta + q);
|
|
133
|
+
const c2 = r1 / (r1 - r2);
|
|
134
|
+
const c1 = -1 - c2;
|
|
135
|
+
return 1 + c1 * Math.exp(r1 * tau) + c2 * Math.exp(r2 * tau);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** a spring's ω0 and ζ: 1.6 Hz and ζ 0.7 unless asked (kit/motion.js's defaults) */
|
|
139
|
+
/** @param {{ freq?: number, damping?: number, overshoot?: number }} o */
|
|
140
|
+
function springOf(o) {
|
|
141
|
+
const w0 = 2 * Math.PI * (o.freq ?? 1.6);
|
|
142
|
+
let zeta = o.damping ?? 0.7;
|
|
143
|
+
if (o.overshoot != null) {
|
|
144
|
+
const l = Math.log(Math.min(Math.max(o.overshoot, 1e-6), 0.999));
|
|
145
|
+
zeta = o.overshoot > 0 ? -l / Math.sqrt(Math.PI * Math.PI + l * l) : 1;
|
|
146
|
+
}
|
|
147
|
+
if (!(w0 > 0)) throw new Error("stage: a spring's freq must be above 0");
|
|
148
|
+
if (!(zeta > 0)) throw new Error("stage: a spring's damping must be above 0");
|
|
149
|
+
// until it stays within 1 % of its travel: when the next thing can be planned
|
|
150
|
+
const step = 1 / 240;
|
|
151
|
+
let last = 0;
|
|
152
|
+
for (let tau = 0; tau < 30; tau += step) {
|
|
153
|
+
if (Math.abs(springStep(tau, w0, zeta) - 1) > 0.01) last = tau;
|
|
154
|
+
else if (tau - last > 4 / w0) break;
|
|
155
|
+
}
|
|
156
|
+
return { w0, zeta, settle: last + step };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// --- 4×4 matrices, as CSS matrix3d lists them (column-major) ------------------
|
|
160
|
+
|
|
161
|
+
/** @returns {Mat} */
|
|
162
|
+
const identity = () => [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
163
|
+
/** a · b: b applied first, as CSS reads a transform list right to left */
|
|
164
|
+
/** @param {Mat} a @param {Mat} b @returns {Mat} */
|
|
165
|
+
function mul(a, b) {
|
|
166
|
+
const o = new Array(16).fill(0);
|
|
167
|
+
for (let c = 0; c < 4; c++)
|
|
168
|
+
for (let r = 0; r < 4; r++) {
|
|
169
|
+
let s = 0;
|
|
170
|
+
for (let k = 0; k < 4; k++)
|
|
171
|
+
s += /** @type {number} */ (a[k * 4 + r]) * /** @type {number} */ (b[c * 4 + k]);
|
|
172
|
+
o[c * 4 + r] = s;
|
|
173
|
+
}
|
|
174
|
+
return o;
|
|
175
|
+
}
|
|
176
|
+
/** @param {number} x @param {number} y @param {number} [z] @returns {Mat} */
|
|
177
|
+
const translate = (x, y, z = 0) => [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, z, 1];
|
|
178
|
+
/** @param {number} sx @param {number} [sy] @returns {Mat} */
|
|
179
|
+
const scale = (sx, sy = sx) => [sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
180
|
+
// CSS's rotations (y points down, z toward the viewer)
|
|
181
|
+
/** @param {number} deg @returns {Mat} */
|
|
182
|
+
const rotateX = (deg) => {
|
|
183
|
+
const c = Math.cos(deg * RAD);
|
|
184
|
+
const s = Math.sin(deg * RAD);
|
|
185
|
+
return [1, 0, 0, 0, 0, c, s, 0, 0, -s, c, 0, 0, 0, 0, 1];
|
|
186
|
+
};
|
|
187
|
+
/** @param {number} deg @returns {Mat} */
|
|
188
|
+
const rotateY = (deg) => {
|
|
189
|
+
const c = Math.cos(deg * RAD);
|
|
190
|
+
const s = Math.sin(deg * RAD);
|
|
191
|
+
return [c, 0, -s, 0, 0, 1, 0, 0, s, 0, c, 0, 0, 0, 0, 1];
|
|
192
|
+
};
|
|
193
|
+
/** @param {number} deg @returns {Mat} */
|
|
194
|
+
const rotateZ = (deg) => {
|
|
195
|
+
const c = Math.cos(deg * RAD);
|
|
196
|
+
const s = Math.sin(deg * RAD);
|
|
197
|
+
return [c, s, 0, 0, -s, c, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
198
|
+
};
|
|
199
|
+
/** CSS perspective(d): a point at z is seen d / (d − z) times its size */
|
|
200
|
+
/** @param {number} d @returns {Mat} */
|
|
201
|
+
const perspective = (d) => [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, -1 / d, 0, 0, 0, 1];
|
|
202
|
+
/** @param {Mat} m @param {number} x @param {number} y @param {number} [z] */
|
|
203
|
+
function apply(m, x, y, z = 0) {
|
|
204
|
+
/** @param {number} i */
|
|
205
|
+
const g = (i) => /** @type {number} */ (m[i]);
|
|
206
|
+
const w = g(3) * x + g(7) * y + g(11) * z + g(15);
|
|
207
|
+
return {
|
|
208
|
+
x: (g(0) * x + g(4) * y + g(8) * z + g(12)) / w,
|
|
209
|
+
y: (g(1) * x + g(5) * y + g(9) * z + g(13)) / w,
|
|
210
|
+
z: (g(2) * x + g(6) * y + g(10) * z + g(14)) / w,
|
|
211
|
+
w,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// --- moves over time -----------------------------------------------------------
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* @typedef {object} Track one field's moves, in the order asked
|
|
219
|
+
* @property {{ t0: number, dur: number, to: number, curve: ((tau: number) => number) | null }[]} moves
|
|
220
|
+
*/
|
|
221
|
+
|
|
222
|
+
/** a When resolved to its start, its length and its progress curve (null: a cut) */
|
|
223
|
+
/** @param {When} w @param {string} label */
|
|
224
|
+
function timing(w, label) {
|
|
225
|
+
const at = w.arrive ?? w.start;
|
|
226
|
+
if (at == null || !Number.isFinite(at))
|
|
227
|
+
throw new Error(`stage: ${label} needs { arrive } or { start }`);
|
|
228
|
+
if (w.arrive != null && w.start != null)
|
|
229
|
+
throw new Error(`stage: ${label} takes { arrive } or { start }, not both`);
|
|
230
|
+
/** @type {(tau: number) => number} */
|
|
231
|
+
let curve;
|
|
232
|
+
/** @type {number} */
|
|
233
|
+
let dur;
|
|
234
|
+
if (w.spring) {
|
|
235
|
+
const s = springOf(w.spring);
|
|
236
|
+
dur = w.dur ?? s.settle;
|
|
237
|
+
curve = (tau) => springStep(tau, s.w0, s.zeta);
|
|
238
|
+
} else {
|
|
239
|
+
dur = w.dur ?? DEFAULT_DUR;
|
|
240
|
+
if (!(dur > 0)) throw new Error(`stage: ${label}: dur must be above 0`);
|
|
241
|
+
const ease = w.ease;
|
|
242
|
+
curve = ease ? (tau) => ease(clamp01(tau / dur)) : (tau) => 1 - decay(tau / dur);
|
|
243
|
+
}
|
|
244
|
+
const t0 = w.arrive != null ? w.arrive - dur : at;
|
|
245
|
+
return { t0, dur, curve };
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** a field at t: each move starts from wherever the field is when it begins
|
|
249
|
+
* and runs until the next one does — the camera's rule (kit/camera.js) */
|
|
250
|
+
/** @param {Track} track @param {number} rest @param {number} t */
|
|
251
|
+
function fieldAt(track, rest, t) {
|
|
252
|
+
let v = rest;
|
|
253
|
+
const ms = track.moves;
|
|
254
|
+
for (let i = 0; i < ms.length; i++) {
|
|
255
|
+
const m = /** @type {Track["moves"][number]} */ (ms[i]);
|
|
256
|
+
if (t < m.t0) break;
|
|
257
|
+
const next = ms[i + 1];
|
|
258
|
+
const until = next ? Math.min(t, next.t0) : t;
|
|
259
|
+
v = m.curve ? lerp(v, m.to, m.curve(until - m.t0)) : m.to;
|
|
260
|
+
if (!next || t < next.t0) break;
|
|
261
|
+
}
|
|
262
|
+
return v;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** the moves of a pose, one track per field */
|
|
266
|
+
function poseTracks() {
|
|
267
|
+
/** @type {Record<keyof Pose, Track>} */
|
|
268
|
+
const tracks = /** @type {any} */ ({});
|
|
269
|
+
for (const f of FIELDS) tracks[f] = { moves: [] };
|
|
270
|
+
return tracks;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** @param {Record<keyof Pose, Track>} tracks @param {Partial<Pose>} to @param {When | null} w @param {number} at @param {string} label */
|
|
274
|
+
function ask(tracks, to, w, at, label) {
|
|
275
|
+
const tm = w ? timing(w, label) : { t0: at, dur: 0, curve: null };
|
|
276
|
+
for (const [k, v] of Object.entries(to)) {
|
|
277
|
+
if (!FIELDS.includes(/** @type {any} */ (k)))
|
|
278
|
+
throw new Error(`stage: ${label}: no pose field "${k}" (${FIELDS.join(", ")})`);
|
|
279
|
+
if (v == null) continue;
|
|
280
|
+
if (!Number.isFinite(v)) throw new Error(`stage: ${label}: ${k} must be a number`);
|
|
281
|
+
const track = tracks[/** @type {keyof Pose} */ (k)];
|
|
282
|
+
track.moves.push({ t0: tm.t0, dur: tm.dur, to: v, curve: tm.curve });
|
|
283
|
+
// in time order; at one instant, in the order asked
|
|
284
|
+
track.moves.sort((a, b) => (a.t0 < b.t0 ? -1 : a.t0 > b.t0 ? 1 : 0));
|
|
285
|
+
}
|
|
286
|
+
return tm;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/** @param {Record<keyof Pose, Track>} tracks @param {Pose} rest @param {number} t @returns {Pose} */
|
|
290
|
+
function poseOf(tracks, rest, t) {
|
|
291
|
+
/** @type {any} */
|
|
292
|
+
const p = {};
|
|
293
|
+
for (const f of FIELDS) p[f] = fieldAt(tracks[f], rest[f], t);
|
|
294
|
+
return p;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// --- the stage -------------------------------------------------------------------
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* @typedef {object} SlabOpts
|
|
301
|
+
* @property {BoxLike} [box] where the slab sits on the stage (px); default its crop's box, else the node's own box
|
|
302
|
+
* @property {BoxLike} [crop] show this region of the node (a saved screen's iframe, a picture, a video at the stage's size): the window is the region's size, the slab sits where it was
|
|
303
|
+
* @property {string} [name] what warnings call it
|
|
304
|
+
* @property {[number, number]} [origin] the point it turns about, as shares of its box (default [0.5, 0.5]: its centre)
|
|
305
|
+
* @property {"hidden" | "visible"} [backface] its back when turned away (default hidden: a card's other side is another slab)
|
|
306
|
+
* @property {number} [blur] px of blur per 1000 px it is in front of or behind the focus (default 0: off) — the ones nearer the lens softer
|
|
307
|
+
* @property {number} [sheen] 0..1: a band of light that crosses it as it turns (default 0: off)
|
|
308
|
+
* @property {number} [shadow] 0..1: a shadow under it, wide and soft when lifted, close and sharp when down (default 0: off)
|
|
309
|
+
* @property {Partial<Pose>} [rest] its pose before any move (default where its part sat)
|
|
310
|
+
* @property {boolean} [inPlace] (internal) the node is adopted where it is — `st.adopt`
|
|
311
|
+
*/
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* @typedef {object} Slab a slab on the stage
|
|
315
|
+
* @property {string} name
|
|
316
|
+
* @property {Box} box where it sits (px)
|
|
317
|
+
* @property {HTMLElement | null} el its element (null on a stage without `el`): put what it shows in it
|
|
318
|
+
* @property {[number, number]} origin
|
|
319
|
+
* @property {"hidden" | "visible"} backface
|
|
320
|
+
* @property {number} blur
|
|
321
|
+
* @property {number} sheen
|
|
322
|
+
* @property {number} shadow
|
|
323
|
+
* @property {HTMLElement | null} light its light band's layer, when it has a sheen
|
|
324
|
+
* @property {boolean} inPlace an element adopted where it was (`st.adopt`)
|
|
325
|
+
* @property {(to: Partial<Pose>, when: When) => Slab} to move to a pose — only the fields given; the rest keep moving as they were
|
|
326
|
+
* @property {(to: Partial<Pose>, at: number) => Slab} set a cut: from `at` on (-Infinity: from the start), these fields are this, with no move
|
|
327
|
+
* @property {(t: number) => Pose} pose its own pose at t
|
|
328
|
+
*/
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* @typedef {object} SlabState a slab at t, ready for CSS
|
|
332
|
+
* @property {string} name
|
|
333
|
+
* @property {Pose} pose its own pose (the stage's turn and lens not in it)
|
|
334
|
+
* @property {{ transform: string, opacity: string, visibility: string, zIndex: string, filter: string, boxShadow: string }} style
|
|
335
|
+
* @property {{ background: string, opacity: number } | null} sheen the light band's layer (null: no sheen asked)
|
|
336
|
+
* @property {boolean} flat square on to the lens: drawn with a 2D transform, no perspective
|
|
337
|
+
* @property {boolean} facing its front toward the lens
|
|
338
|
+
* @property {{ x: number, y: number }[]} quad its corners in the picture (px), top-left first, clockwise
|
|
339
|
+
* @property {number} area px² it covers in the picture
|
|
340
|
+
* @property {number} depth its centre's z after the turn and the lens (px, + nearer)
|
|
341
|
+
* @property {boolean} soft tilted and drawn bigger than the frame: Chrome stretches such a layer
|
|
342
|
+
*/
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* A stage of slabs: the picture's size, a lens, and optionally the film's
|
|
346
|
+
* camera, whose view frames it (slabs are placed in its content px, and the
|
|
347
|
+
* vanishing point is the middle of what it shows — a zoom is a longer lens,
|
|
348
|
+
* the depth unchanged).
|
|
349
|
+
* @param {object} [opts]
|
|
350
|
+
* @param {HTMLElement} [opts.el] the element slabs are put in: at the picture's top-left, not transformed (default: slabs are numbers only — at(t))
|
|
351
|
+
* @param {number} [opts.width] the picture (px, default the camera's view, else 1920)
|
|
352
|
+
* @param {number} [opts.height] (default the camera's view, else 1080)
|
|
353
|
+
* @param {number} [opts.perspective] how far the lens is from the stage (px, default 2000)
|
|
354
|
+
* @param {CameraLike} [opts.camera] a kit camera: its view at t frames the stage
|
|
355
|
+
* @param {[number, number]} [opts.pivot] what the stage turns about (px, default the middle of the content)
|
|
356
|
+
* @param {number} [opts.focus] the depth in focus, for slabs that blur (px, default 0)
|
|
357
|
+
*/
|
|
358
|
+
export function stage(opts = {}) {
|
|
359
|
+
const cam = opts.camera ?? null;
|
|
360
|
+
const W = opts.width ?? cam?.view?.width ?? 1920;
|
|
361
|
+
const H = opts.height ?? cam?.view?.height ?? 1080;
|
|
362
|
+
const content = cam?.content ?? { width: W, height: H };
|
|
363
|
+
const d = opts.perspective ?? DEFAULT_PERSPECTIVE;
|
|
364
|
+
if (!(d > 0)) throw new Error("stage: perspective must be a distance above 0 px");
|
|
365
|
+
const pivot = opts.pivot ?? [content.width / 2, content.height / 2];
|
|
366
|
+
const focus = opts.focus ?? 0;
|
|
367
|
+
const host = opts.el ?? null;
|
|
368
|
+
/** @type {Slab[]} */
|
|
369
|
+
const slabs = [];
|
|
370
|
+
// the stage's own turn (rx, ry, rz about the pivot), the lens's travel (z)
|
|
371
|
+
const world = poseTracks();
|
|
372
|
+
/** every move asked, as [start, end] (s): where warnings() looks */
|
|
373
|
+
/** @type {[number, number][]} */
|
|
374
|
+
const spans = [];
|
|
375
|
+
/** @param {{ t0: number, dur: number }} tm */
|
|
376
|
+
const note = (tm) => {
|
|
377
|
+
if (Number.isFinite(tm.t0)) spans.push([tm.t0, tm.t0 + tm.dur]);
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
/** the camera's view as a 2D map, content → picture (kit/camera.js's css()) */
|
|
381
|
+
/** @param {number} t */
|
|
382
|
+
const viewAt = (t) => {
|
|
383
|
+
if (!cam) return { m: identity(), cx: content.width / 2, cy: content.height / 2 };
|
|
384
|
+
const v = cam.at(t);
|
|
385
|
+
const s = v.scale ?? W / v.w;
|
|
386
|
+
let m = mul(translate(W / 2 - v.cx * s, H / 2 - v.cy * s), scale(s));
|
|
387
|
+
const j = cam.jitter?.(t);
|
|
388
|
+
if (j && (j.x || j.y || j.rot))
|
|
389
|
+
m = mul(
|
|
390
|
+
mul(translate(W / 2 + j.x, H / 2 + j.y), rotateZ(j.rot)),
|
|
391
|
+
mul(translate(-W / 2, -H / 2), m),
|
|
392
|
+
);
|
|
393
|
+
return { m, cx: v.cx, cy: v.cy };
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
/** @param {Slab} sl @param {number} t @returns {SlabState} */
|
|
397
|
+
const state = (sl, t) => {
|
|
398
|
+
const p = sl.pose(t);
|
|
399
|
+
const w = poseOf(world, REST, t);
|
|
400
|
+
const b = sl.box;
|
|
401
|
+
const ox = b.w * sl.origin[0];
|
|
402
|
+
const oy = b.h * sl.origin[1];
|
|
403
|
+
// the slab: turned and sized about its origin, moved from where it sat
|
|
404
|
+
const own = mul(
|
|
405
|
+
mul(
|
|
406
|
+
translate(b.x + ox + p.x, b.y + oy + p.y, p.z),
|
|
407
|
+
mul(mul(rotateX(p.rx), rotateY(p.ry)), rotateZ(p.rz)),
|
|
408
|
+
),
|
|
409
|
+
mul(scale(p.scale), translate(-ox, -oy)),
|
|
410
|
+
);
|
|
411
|
+
// the stage turned about its pivot, then the lens's travel
|
|
412
|
+
const turned = mul(
|
|
413
|
+
mul(
|
|
414
|
+
translate(pivot[0], pivot[1], w.z),
|
|
415
|
+
mul(mul(rotateX(w.rx), rotateY(w.ry)), rotateZ(w.rz)),
|
|
416
|
+
),
|
|
417
|
+
translate(-pivot[0], -pivot[1]),
|
|
418
|
+
);
|
|
419
|
+
const placed = mul(turned, own);
|
|
420
|
+
const view = viewAt(t);
|
|
421
|
+
const lens = mul(
|
|
422
|
+
mul(translate(view.cx, view.cy), perspective(d)),
|
|
423
|
+
translate(-view.cx, -view.cy),
|
|
424
|
+
);
|
|
425
|
+
// an adopted element is drawn from where it already sits: its transform
|
|
426
|
+
// is the move away from that place, not the whole way from the corner
|
|
427
|
+
const full = sl.inPlace
|
|
428
|
+
? mul(translate(-b.x, -b.y), mul(view.m, mul(lens, placed)))
|
|
429
|
+
: mul(view.m, mul(lens, placed));
|
|
430
|
+
// which way it faces, and how deep its centre is, before the lens
|
|
431
|
+
const n = {
|
|
432
|
+
x: /** @type {number} */ (placed[8]),
|
|
433
|
+
y: /** @type {number} */ (placed[9]),
|
|
434
|
+
z: /** @type {number} */ (placed[10]),
|
|
435
|
+
};
|
|
436
|
+
const len = Math.hypot(n.x, n.y, n.z) || 1;
|
|
437
|
+
const facing = n.z / len > 0;
|
|
438
|
+
const c = apply(placed, b.w / 2, b.h / 2);
|
|
439
|
+
const corners = [
|
|
440
|
+
[0, 0],
|
|
441
|
+
[b.w, 0],
|
|
442
|
+
[b.w, b.h],
|
|
443
|
+
[0, b.h],
|
|
444
|
+
].map(([x, y]) =>
|
|
445
|
+
apply(
|
|
446
|
+
sl.inPlace ? mul(translate(b.x, b.y), full) : full,
|
|
447
|
+
/** @type {number} */ (x),
|
|
448
|
+
/** @type {number} */ (y),
|
|
449
|
+
),
|
|
450
|
+
);
|
|
451
|
+
const behind = corners.some((q) => !(q.w > 1e-6));
|
|
452
|
+
const quad = corners.map((q) => ({ x: q.x, y: q.y }));
|
|
453
|
+
let area = 0;
|
|
454
|
+
for (let i = 0; i < 4; i++) {
|
|
455
|
+
const a = /** @type {{x:number,y:number}} */ (quad[i]);
|
|
456
|
+
const e = /** @type {{x:number,y:number}} */ (quad[(i + 1) % 4]);
|
|
457
|
+
area += a.x * e.y - e.x * a.y;
|
|
458
|
+
}
|
|
459
|
+
area = behind ? Number.POSITIVE_INFINITY : Math.abs(area) / 2;
|
|
460
|
+
// square on: every point of it at one depth, so the lens only scales it —
|
|
461
|
+
// a 2D transform, drawn by Chrome at its final scale
|
|
462
|
+
const flat = Math.abs(Math.abs(n.z) / len - 1) < 1e-7;
|
|
463
|
+
let transform;
|
|
464
|
+
if (flat && !behind) {
|
|
465
|
+
const o = apply(full, 0, 0);
|
|
466
|
+
const ex = apply(full, 1, 0);
|
|
467
|
+
const ey = apply(full, 0, 1);
|
|
468
|
+
transform = `matrix(${[ex.x - o.x, ex.y - o.y, ey.x - o.x, ey.y - o.y, o.x, o.y].map(f6).join(", ")})`;
|
|
469
|
+
} else transform = `matrix3d(${full.map(f6).join(", ")})`;
|
|
470
|
+
// close to the lens it fades: the last quarter of the way it is gone
|
|
471
|
+
const ahead = d - c.z;
|
|
472
|
+
const nearFade = clamp01((ahead - 0.02 * d) / (0.23 * d));
|
|
473
|
+
const opacity = clamp01(p.opacity) * nearFade;
|
|
474
|
+
const hidden = behind || opacity <= 0 || (!facing && sl.backface === "hidden");
|
|
475
|
+
const lifted = Math.max(0, p.z);
|
|
476
|
+
const blur = sl.blur > 0 ? (sl.blur * Math.abs(c.z - focus)) / 1000 : 0;
|
|
477
|
+
const shadow =
|
|
478
|
+
sl.shadow > 0
|
|
479
|
+
? `0 ${f6(4 + 0.08 * lifted)}px ${f6(8 + 0.15 * lifted)}px rgba(0, 0, 0, ${f6(sl.shadow * 0.35 * (1 - 0.5 * clamp01(lifted / (0.3 * d))))})`
|
|
480
|
+
: "none";
|
|
481
|
+
/** @type {SlabState["sheen"]} */
|
|
482
|
+
let sheen = null;
|
|
483
|
+
if (sl.sheen > 0) {
|
|
484
|
+
// a light up and to the left of the lens: turning the slab moves the
|
|
485
|
+
// band across it, square on it is gone
|
|
486
|
+
const turn = p.ry + w.ry + 0.5 * (p.rx + w.rx);
|
|
487
|
+
const at = 50 - turn * 2.2;
|
|
488
|
+
const k = clamp01(Math.abs(turn) / 25);
|
|
489
|
+
sheen = {
|
|
490
|
+
background: `linear-gradient(105deg, rgba(255,255,255,0) ${f6(at - 18)}%, rgba(255,255,255,${f6(0.55 * sl.sheen)}) ${f6(at)}%, rgba(255,255,255,0) ${f6(at + 18)}%)`,
|
|
491
|
+
opacity: f6(k),
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
return {
|
|
495
|
+
name: sl.name,
|
|
496
|
+
pose: p,
|
|
497
|
+
style: {
|
|
498
|
+
transform,
|
|
499
|
+
opacity: String(f6(opacity)),
|
|
500
|
+
visibility: hidden ? "hidden" : "visible",
|
|
501
|
+
zIndex: "0", // set by at(t), nearest on top
|
|
502
|
+
filter: blur > 0.05 ? `blur(${f6(blur)}px)` : "none",
|
|
503
|
+
boxShadow: shadow,
|
|
504
|
+
},
|
|
505
|
+
sheen,
|
|
506
|
+
flat,
|
|
507
|
+
facing,
|
|
508
|
+
quad,
|
|
509
|
+
area,
|
|
510
|
+
depth: c.z,
|
|
511
|
+
soft: !flat && !hidden && area > W * H,
|
|
512
|
+
};
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
/** every slab at t, the nearest drawn on top */
|
|
516
|
+
/** @param {number} t @returns {SlabState[]} */
|
|
517
|
+
const at = (t) => {
|
|
518
|
+
const all = slabs.map((s) => state(s, t));
|
|
519
|
+
const order = all.map((s, i) => ({ s, i })).sort((a, b) => a.s.depth - b.s.depth || a.i - b.i);
|
|
520
|
+
order.forEach(({ s }, k) => {
|
|
521
|
+
s.style.zIndex = String(k + 1);
|
|
522
|
+
});
|
|
523
|
+
return all;
|
|
524
|
+
};
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* A slab: a node shown flat in space. With `crop`, the node is a whole
|
|
528
|
+
* screen, picture or video at the stage's size and the slab a window onto
|
|
529
|
+
* that region (an iframe of a saved screen cropped to one part: live DOM,
|
|
530
|
+
* sharp at any size); without, the node itself at its own size.
|
|
531
|
+
* @param {HTMLElement | string | null} node an element, a saved screen's state.html or a picture's URL (put in an iframe or an img at the stage's size), or null: an empty slab of `box` to draw into (`slab.el`)
|
|
532
|
+
* @param {SlabOpts} [o]
|
|
533
|
+
*/
|
|
534
|
+
const slab = (node, o = {}) => {
|
|
535
|
+
const name = o.name ?? `slab ${slabs.length + 1}`;
|
|
536
|
+
const crop = o.crop ? boxOf(o.crop) : null;
|
|
537
|
+
/** @type {Box | null} */
|
|
538
|
+
let box = o.box ? boxOf(o.box) : crop;
|
|
539
|
+
/** @type {HTMLElement | null} */
|
|
540
|
+
let el = null;
|
|
541
|
+
const inPlace = !!o.inPlace;
|
|
542
|
+
if (inPlace) {
|
|
543
|
+
if (!node || typeof node !== "object")
|
|
544
|
+
throw new Error(`stage: ${name}: adopt takes an element the page already has`);
|
|
545
|
+
el = node;
|
|
546
|
+
box ??= placeOf(node);
|
|
547
|
+
if (!box) throw new Error(`stage: ${name} has no size where it sits (give it a box)`);
|
|
548
|
+
// turning about its own corner, as the stage's matrices are written;
|
|
549
|
+
// nothing shows of it until a transform is written
|
|
550
|
+
el.style.transformOrigin = "0 0";
|
|
551
|
+
if (o.backface) el.style.backfaceVisibility = o.backface;
|
|
552
|
+
} else if (host) {
|
|
553
|
+
el = document.createElement("div");
|
|
554
|
+
el.dataset.otSlab = name;
|
|
555
|
+
/** @type {HTMLElement | null} */
|
|
556
|
+
let inner = null;
|
|
557
|
+
if (typeof node === "string") {
|
|
558
|
+
inner = document.createElement(/\.html?(\?|#|$)/.test(node) ? "iframe" : "img");
|
|
559
|
+
inner.setAttribute("src", node);
|
|
560
|
+
inner.setAttribute("aria-hidden", "true");
|
|
561
|
+
Object.assign(inner.style, {
|
|
562
|
+
border: "0",
|
|
563
|
+
width: `${content.width}px`,
|
|
564
|
+
height: `${content.height}px`,
|
|
565
|
+
maxWidth: "none",
|
|
566
|
+
});
|
|
567
|
+
} else if (node) inner = node;
|
|
568
|
+
if (inner && !box) {
|
|
569
|
+
const r = {
|
|
570
|
+
x: inner.offsetLeft,
|
|
571
|
+
y: inner.offsetTop,
|
|
572
|
+
w: inner.offsetWidth,
|
|
573
|
+
h: inner.offsetHeight,
|
|
574
|
+
};
|
|
575
|
+
box = r.w && r.h ? r : null;
|
|
576
|
+
}
|
|
577
|
+
if (!box) throw new Error(`stage: ${name} needs a box (or a crop, or a node with a size)`);
|
|
578
|
+
Object.assign(el.style, {
|
|
579
|
+
position: "absolute",
|
|
580
|
+
left: "0px",
|
|
581
|
+
top: "0px",
|
|
582
|
+
width: `${box.w}px`,
|
|
583
|
+
height: `${box.h}px`,
|
|
584
|
+
overflow: "hidden",
|
|
585
|
+
transformOrigin: "0 0",
|
|
586
|
+
backfaceVisibility: o.backface ?? "hidden",
|
|
587
|
+
});
|
|
588
|
+
if (inner) {
|
|
589
|
+
Object.assign(inner.style, {
|
|
590
|
+
position: "absolute",
|
|
591
|
+
left: `${-(crop?.x ?? 0)}px`,
|
|
592
|
+
top: `${-(crop?.y ?? 0)}px`,
|
|
593
|
+
});
|
|
594
|
+
el.appendChild(inner);
|
|
595
|
+
}
|
|
596
|
+
host.appendChild(el);
|
|
597
|
+
}
|
|
598
|
+
if (!box) throw new Error(`stage: ${name} needs a box (or a crop)`);
|
|
599
|
+
/** @type {HTMLElement | null} */
|
|
600
|
+
let light = null;
|
|
601
|
+
if (el && !inPlace && (o.sheen ?? 0) > 0) {
|
|
602
|
+
light = document.createElement("div");
|
|
603
|
+
Object.assign(light.style, {
|
|
604
|
+
position: "absolute",
|
|
605
|
+
inset: "0",
|
|
606
|
+
pointerEvents: "none",
|
|
607
|
+
zIndex: "1",
|
|
608
|
+
});
|
|
609
|
+
el.appendChild(light);
|
|
610
|
+
}
|
|
611
|
+
const tracks = poseTracks();
|
|
612
|
+
const rest = { ...REST, ...(o.rest ?? {}) };
|
|
613
|
+
const handle = {
|
|
614
|
+
name,
|
|
615
|
+
box,
|
|
616
|
+
/** the slab's element (null on a stage without `el`): put what it shows in it */
|
|
617
|
+
el,
|
|
618
|
+
origin: o.origin ?? /** @type {[number, number]} */ ([0.5, 0.5]),
|
|
619
|
+
backface: o.backface ?? "hidden",
|
|
620
|
+
blur: o.blur ?? 0,
|
|
621
|
+
sheen: o.sheen ?? 0,
|
|
622
|
+
shadow: o.shadow ?? 0,
|
|
623
|
+
/** @internal */
|
|
624
|
+
light,
|
|
625
|
+
inPlace,
|
|
626
|
+
/** move to a pose — only the fields given; the rest keep moving as they were
|
|
627
|
+
* @param {Partial<Pose>} to @param {When} when */
|
|
628
|
+
to(to, when) {
|
|
629
|
+
note(ask(tracks, to, when, 0, `${name} to`));
|
|
630
|
+
return handle;
|
|
631
|
+
},
|
|
632
|
+
/** a cut: from `at` on (-Infinity: from the start), these fields are this, with no move
|
|
633
|
+
* @param {Partial<Pose>} to @param {number} at */
|
|
634
|
+
set(to, at) {
|
|
635
|
+
if (!(Number.isFinite(at) || at === Number.NEGATIVE_INFINITY))
|
|
636
|
+
throw new Error(`stage: ${name} set needs a time (s, or -Infinity: from the start)`);
|
|
637
|
+
note(ask(tracks, to, null, at, `${name} set`));
|
|
638
|
+
return handle;
|
|
639
|
+
},
|
|
640
|
+
/** its own pose at t */
|
|
641
|
+
/** @param {number} t @returns {Pose} */
|
|
642
|
+
pose: (t) => poseOf(tracks, rest, t),
|
|
643
|
+
};
|
|
644
|
+
slabs.push(handle);
|
|
645
|
+
return handle;
|
|
646
|
+
};
|
|
647
|
+
|
|
648
|
+
return {
|
|
649
|
+
width: W,
|
|
650
|
+
height: H,
|
|
651
|
+
perspective: d,
|
|
652
|
+
slab,
|
|
653
|
+
/**
|
|
654
|
+
* A slab made of an element where it already is — a picture, a video, a
|
|
655
|
+
* player of frames, a part of the page: not moved into the stage, not
|
|
656
|
+
* wrapped, its layout and its children untouched. Until it is asked to
|
|
657
|
+
* move it is left exactly as it was; moved, it gets a transform (and an
|
|
658
|
+
* opacity, a blur, a shadow when those are asked), nothing else — the
|
|
659
|
+
* page's own visibility (`scenes`) still decides whether it shows.
|
|
660
|
+
* Its place is where its layout puts it on the page (`box` to say
|
|
661
|
+
* otherwise). A sheen is not drawn on an adopted element.
|
|
662
|
+
* @param {HTMLElement} el
|
|
663
|
+
* @param {Omit<SlabOpts, "crop" | "sheen">} [o]
|
|
664
|
+
*/
|
|
665
|
+
adopt: (el, o = {}) => slab(el, { ...o, inPlace: true }),
|
|
666
|
+
/** the whole stage turns about its pivot — a flat layout becoming a table
|
|
667
|
+
* @param {{ rx?: number, ry?: number, rz?: number }} to @param {When} when */
|
|
668
|
+
turn(to, when) {
|
|
669
|
+
const { rx, ry, rz } = to;
|
|
670
|
+
note(ask(world, { rx, ry, rz }, when, 0, "turn"));
|
|
671
|
+
},
|
|
672
|
+
/** the lens travels into the stage (px, + toward and past what is in
|
|
673
|
+
* front): a slab it nears grows, fades over the last quarter of the way
|
|
674
|
+
* and is gone; what was behind it comes up
|
|
675
|
+
* @param {number} z @param {When} when */
|
|
676
|
+
dolly(z, when) {
|
|
677
|
+
note(ask(world, { z }, when, 0, "dolly"));
|
|
678
|
+
},
|
|
679
|
+
/** the stage's own turn and the lens's travel at t ({ rx, ry, rz, z }) */
|
|
680
|
+
/** @param {number} t */
|
|
681
|
+
world: (t) => {
|
|
682
|
+
const w = poseOf(world, REST, t);
|
|
683
|
+
return { rx: w.rx, ry: w.ry, rz: w.rz, z: w.z };
|
|
684
|
+
},
|
|
685
|
+
at,
|
|
686
|
+
/** write every slab's state at t onto its element */
|
|
687
|
+
/** @param {number} t */
|
|
688
|
+
apply(t) {
|
|
689
|
+
const all = at(t);
|
|
690
|
+
all.forEach((s, i) => {
|
|
691
|
+
const sl = /** @type {Slab} */ (slabs[i]);
|
|
692
|
+
if (!sl.el) return;
|
|
693
|
+
if (sl.inPlace) {
|
|
694
|
+
// only what the stage changed: at rest and square on, the element's
|
|
695
|
+
// own styles — its visibility (scenes'), its stacking — stay its own
|
|
696
|
+
const st = sl.el.style;
|
|
697
|
+
// a move settling into the hold ends a hair off: within 0.01 px
|
|
698
|
+
// and 1e-5 of scale, it is back where it was
|
|
699
|
+
const m = /^matrix\(([^)]*)\)$/.exec(s.style.transform);
|
|
700
|
+
const still =
|
|
701
|
+
!!m &&
|
|
702
|
+
(m[1] ?? "")
|
|
703
|
+
.split(",")
|
|
704
|
+
.map(Number)
|
|
705
|
+
.every((v, i) => Math.abs(v - (i === 0 || i === 3 ? 1 : 0)) < (i < 4 ? 1e-5 : 0.01));
|
|
706
|
+
st.transform = still ? "" : s.style.transform;
|
|
707
|
+
const gone = s.style.visibility === "hidden";
|
|
708
|
+
st.opacity = gone ? "0" : s.style.opacity === "1" ? "" : s.style.opacity;
|
|
709
|
+
st.filter = s.style.filter === "none" ? "" : s.style.filter;
|
|
710
|
+
if (sl.shadow > 0) st.boxShadow = s.style.boxShadow === "none" ? "" : s.style.boxShadow;
|
|
711
|
+
return;
|
|
712
|
+
}
|
|
713
|
+
Object.assign(sl.el.style, s.style);
|
|
714
|
+
if (sl.light && s.sheen) {
|
|
715
|
+
sl.light.style.background = s.sheen.background;
|
|
716
|
+
sl.light.style.opacity = String(s.sheen.opacity);
|
|
717
|
+
}
|
|
718
|
+
});
|
|
719
|
+
return all;
|
|
720
|
+
},
|
|
721
|
+
/**
|
|
722
|
+
* What the stage would draw soft: a tilted slab bigger in the picture than
|
|
723
|
+
* the frame, which Chrome draws at about the frame's area and stretches —
|
|
724
|
+
* checked every 1/30 s from `from` to `to` (default: the span of every
|
|
725
|
+
* move asked, plus a second).
|
|
726
|
+
* @param {number} [from] @param {number} [to]
|
|
727
|
+
*/
|
|
728
|
+
warnings(from, to) {
|
|
729
|
+
const lo = Math.min(...spans.map((s) => s[0]));
|
|
730
|
+
const hi = Math.max(...spans.map((s) => s[1]));
|
|
731
|
+
const t0 = from ?? (Number.isFinite(lo) ? lo : 0);
|
|
732
|
+
const t1 = to ?? (Number.isFinite(hi) ? hi + 1 : t0);
|
|
733
|
+
/** @type {Map<string, [number, number]>} */
|
|
734
|
+
const soft = new Map();
|
|
735
|
+
/** @type {string[]} */
|
|
736
|
+
const out = [];
|
|
737
|
+
const flush = (/** @type {string} */ n) => {
|
|
738
|
+
const r = soft.get(n);
|
|
739
|
+
if (!r) return;
|
|
740
|
+
out.push(
|
|
741
|
+
`${n}: tilted and bigger than the frame ${r[0].toFixed(2)}–${r[1].toFixed(2)} s — Chrome draws it at about the frame's area and stretches it (soft); smaller, or square on before it grows`,
|
|
742
|
+
);
|
|
743
|
+
soft.delete(n);
|
|
744
|
+
};
|
|
745
|
+
for (let t = t0; t <= t1 + 1e-9; t += 1 / 30) {
|
|
746
|
+
const all = at(t);
|
|
747
|
+
for (const s of all) {
|
|
748
|
+
const r = soft.get(s.name);
|
|
749
|
+
if (s.soft) soft.set(s.name, r ? [r[0], t] : [t, t]);
|
|
750
|
+
else flush(s.name);
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
for (const n of [...soft.keys()]) flush(n);
|
|
754
|
+
return out;
|
|
755
|
+
},
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
/**
|
|
760
|
+
* Where an element's layout puts it on the page, with no transform of any
|
|
761
|
+
* ancestor's counted: its offsets summed up to the page, its own size.
|
|
762
|
+
* @param {HTMLElement} el
|
|
763
|
+
* @returns {Box | null}
|
|
764
|
+
*/
|
|
765
|
+
function placeOf(el) {
|
|
766
|
+
const w = el.offsetWidth;
|
|
767
|
+
const h = el.offsetHeight;
|
|
768
|
+
if (!(w > 0 && h > 0)) return null;
|
|
769
|
+
let x = 0;
|
|
770
|
+
let y = 0;
|
|
771
|
+
/** @type {HTMLElement | null} */
|
|
772
|
+
let e = el;
|
|
773
|
+
while (e) {
|
|
774
|
+
x += e.offsetLeft || 0;
|
|
775
|
+
y += e.offsetTop || 0;
|
|
776
|
+
e = /** @type {HTMLElement | null} */ (e.offsetParent);
|
|
777
|
+
}
|
|
778
|
+
return { x, y, w, h };
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
// --- moves made of moves ---------------------------------------------------------
|
|
782
|
+
|
|
783
|
+
/**
|
|
784
|
+
* Slabs lift apart in depth — a screen coming apart into its parts — each
|
|
785
|
+
* `gap` px nearer the lens than the one before (the first stays where it is),
|
|
786
|
+
* `spread` pushing them out from their middle as they rise (a share of each
|
|
787
|
+
* one's distance from it). Seen square on it reads as a slight swell; under a
|
|
788
|
+
* stage `turn` or a tilt it reads as layers.
|
|
789
|
+
* @param {Slab[]} list in order, back to front
|
|
790
|
+
* @param {When & { gap?: number, spread?: number, every?: number }} when gap: px between layers
|
|
791
|
+
* (default 120: about a sixteenth of the lens's distance); spread: default 0; every: s between one
|
|
792
|
+
* slab leaving and the next (default 0)
|
|
793
|
+
*/
|
|
794
|
+
export function explode(list, when) {
|
|
795
|
+
const { gap = 120, spread = 0, every = 0, ...w } = when;
|
|
796
|
+
const mx = list.reduce((s, sl) => s + sl.box.x + sl.box.w / 2, 0) / Math.max(1, list.length);
|
|
797
|
+
const my = list.reduce((s, sl) => s + sl.box.y + sl.box.h / 2, 0) / Math.max(1, list.length);
|
|
798
|
+
list.forEach((sl, i) => {
|
|
799
|
+
const cx = sl.box.x + sl.box.w / 2;
|
|
800
|
+
const cy = sl.box.y + sl.box.h / 2;
|
|
801
|
+
sl.to(
|
|
802
|
+
{ z: i * gap, ...(spread ? { x: (cx - mx) * spread, y: (cy - my) * spread } : {}) },
|
|
803
|
+
shift(w, i * every),
|
|
804
|
+
);
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
/** Slabs back where their parts sat, square on (explode's undoing) */
|
|
809
|
+
/** @param {Slab[]} list @param {When & { every?: number }} when */
|
|
810
|
+
export function together(list, when) {
|
|
811
|
+
const { every = 0, ...w } = when;
|
|
812
|
+
list.forEach((sl, i) => {
|
|
813
|
+
sl.to({ x: 0, y: 0, z: 0, rx: 0, ry: 0, rz: 0, scale: 1 }, shift(w, i * every));
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* Lowered onto the stage like a print: it starts nearer the lens — 1.25× its
|
|
819
|
+
* size — and settles down with a 3 % bounce, its shadow (if it has one)
|
|
820
|
+
* tightening from wide and soft to close and sharp (`skill film craft`,
|
|
821
|
+
* Arrivals with weight). It is not seen until it drops. `tilt` given: it
|
|
822
|
+
* falls from that angle and lands square.
|
|
823
|
+
* @param {Slab} sl
|
|
824
|
+
* @param {When & { from?: number, z?: number, tilt?: { rx?: number, ry?: number, rz?: number } }} when
|
|
825
|
+
* from: how far above its rest it starts (px; default 400, which reads as 1.25× under the default
|
|
826
|
+
* lens of 2000 px); z: where it comes to rest (default 0); default a spring of 2 Hz swinging 12 %
|
|
827
|
+
* of its fall past its rest (a 3 % bounce of its size)
|
|
828
|
+
*/
|
|
829
|
+
export function drop(sl, when) {
|
|
830
|
+
const { from, z = 0, tilt, ...w } = when;
|
|
831
|
+
const h = from ?? 0.2 * DEFAULT_PERSPECTIVE;
|
|
832
|
+
/** @type {When} */
|
|
833
|
+
const motion = w.ease || w.spring ? w : { spring: { freq: 2, overshoot: 0.12 }, ...w };
|
|
834
|
+
const tm = timing(motion, `${sl.name} drop`);
|
|
835
|
+
// unseen until it drops
|
|
836
|
+
sl.set({ opacity: 0 }, Number.NEGATIVE_INFINITY);
|
|
837
|
+
sl.set({ z: z + h, opacity: 0, ...(tilt ?? {}) }, tm.t0);
|
|
838
|
+
sl.to({ opacity: 1 }, { start: tm.t0, dur: Math.min(0.12, tm.dur), ease: (p) => p });
|
|
839
|
+
/** @type {Partial<Pose>} */
|
|
840
|
+
const square = {};
|
|
841
|
+
for (const k of /** @type {const} */ (["rx", "ry", "rz"])) if (tilt?.[k] != null) square[k] = 0;
|
|
842
|
+
sl.to({ z, ...square }, { ...motion, start: tm.t0, arrive: undefined });
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
/**
|
|
846
|
+
* A pile: slabs dropped one after another onto the same place, each resting
|
|
847
|
+
* `gap` px above the last — panels landing on a stack. Under a stage `turn`
|
|
848
|
+
* the pile has thickness.
|
|
849
|
+
* @param {Slab[]} list first dropped first
|
|
850
|
+
* @param {When & { every?: number, gap?: number, from?: number, rz?: number[] }} when every: s between
|
|
851
|
+
* drops (default 0.16 — labels in those films stacked one every ≈0.16 s); gap: px each rests above
|
|
852
|
+
* the last (default 6); rz: the angle each lies at (default none)
|
|
853
|
+
*/
|
|
854
|
+
export function stack(list, when) {
|
|
855
|
+
const { every = 0.16, gap = 6, rz, ...w } = when;
|
|
856
|
+
list.forEach((sl, i) => {
|
|
857
|
+
const wi = shift(w, i * every);
|
|
858
|
+
drop(sl, { ...wi, z: i * gap });
|
|
859
|
+
const r = rz?.[i];
|
|
860
|
+
if (r != null)
|
|
861
|
+
sl.set(
|
|
862
|
+
{ rz: r },
|
|
863
|
+
timing(
|
|
864
|
+
wi.ease || wi.spring ? wi : { spring: { freq: 2, overshoot: 0.12 }, ...wi },
|
|
865
|
+
`${sl.name} stack`,
|
|
866
|
+
).t0,
|
|
867
|
+
);
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
/**
|
|
872
|
+
* A card turns over: `front` turns away about its vertical (or horizontal)
|
|
873
|
+
* axis while `back` — the next scene, the other side — turns in from behind,
|
|
874
|
+
* each hidden while it faces away. `lift` px toward the lens at the middle of
|
|
875
|
+
* the turn (default 0).
|
|
876
|
+
* @param {Slab} front
|
|
877
|
+
* @param {Slab} back
|
|
878
|
+
* @param {When & { axis?: "x" | "y", dir?: 1 | -1, lift?: number }} when
|
|
879
|
+
*/
|
|
880
|
+
export function flip(front, back, when) {
|
|
881
|
+
const { axis = "y", dir = 1, lift = 0, ...w } = when;
|
|
882
|
+
const k = axis === "y" ? "ry" : "rx";
|
|
883
|
+
const tm = timing(w, `${front.name} flip`);
|
|
884
|
+
back.set({ [k]: -180 * dir }, tm.t0);
|
|
885
|
+
front.to({ [k]: 180 * dir }, w);
|
|
886
|
+
back.to({ [k]: 0 }, w);
|
|
887
|
+
if (lift) {
|
|
888
|
+
// up over the first half of the turn, down over the second
|
|
889
|
+
const half = {
|
|
890
|
+
dur: tm.dur / 2,
|
|
891
|
+
ease: (/** @type {number} */ p) => Math.sin((p * Math.PI) / 2),
|
|
892
|
+
};
|
|
893
|
+
const down = {
|
|
894
|
+
dur: tm.dur / 2,
|
|
895
|
+
ease: (/** @type {number} */ p) => 1 - Math.cos((p * Math.PI) / 2),
|
|
896
|
+
};
|
|
897
|
+
for (const sl of [front, back]) {
|
|
898
|
+
sl.to({ z: lift }, { ...half, start: tm.t0 });
|
|
899
|
+
sl.to({ z: 0 }, { ...down, start: tm.t0 + tm.dur / 2 });
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
/** a When moved later by s */
|
|
905
|
+
/** @param {When} w @param {number} s @returns {When} */
|
|
906
|
+
function shift(w, s) {
|
|
907
|
+
if (!s) return w;
|
|
908
|
+
return w.arrive != null ? { ...w, arrive: w.arrive + s } : { ...w, start: (w.start ?? 0) + s };
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
/** the stage's matrices (CSS's, column-major), for kit/world.js: the same
|
|
912
|
+
* poses drawn in WebGL */
|
|
913
|
+
export const matrices = {
|
|
914
|
+
identity,
|
|
915
|
+
mul,
|
|
916
|
+
translate,
|
|
917
|
+
scale,
|
|
918
|
+
rotateX,
|
|
919
|
+
rotateY,
|
|
920
|
+
rotateZ,
|
|
921
|
+
perspective,
|
|
922
|
+
apply,
|
|
923
|
+
};
|