@open-take/compositor 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
|
@@ -0,0 +1,976 @@
|
|
|
1
|
+
// The page's material, the whole page: the product's own images (an <img> or
|
|
2
|
+
// <picture> with its largest source, an inline SVG drawing, a CSS background
|
|
3
|
+
// image, a video, a canvas the page draws) and the copy it writes (headings,
|
|
4
|
+
// taglines, short paragraphs) — from the top of the page to its bottom, not
|
|
5
|
+
// only the first screen, in page order. The component index (parts.json)
|
|
6
|
+
// measures what is on screen at a saved moment; this lists what the page
|
|
7
|
+
// holds, so an illustration two screens down or the tagline above the footer
|
|
8
|
+
// is named too.
|
|
9
|
+
//
|
|
10
|
+
// One page script (MATERIALS_PROBE_JS) reads it, read-only, in the live page
|
|
11
|
+
// as a shoot keeps its first saved screen of each page (the URLs and the
|
|
12
|
+
// srcset candidates are the network's there), or in a restored state.html
|
|
13
|
+
// for a screen saved before this existed (its files are the saved ones). The
|
|
14
|
+
// Node side here turns what it returns into `states/<id>/materials.json`:
|
|
15
|
+
// the largest source of each image, the copy, and the summary lines a shoot
|
|
16
|
+
// prints. Nothing is ranked or picked: every list is in page order, and what
|
|
17
|
+
// the probe leaves out is counted with its reason in `skipped`.
|
|
18
|
+
|
|
19
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
20
|
+
import { join } from "node:path";
|
|
21
|
+
import type { ComponentSource } from "./components";
|
|
22
|
+
|
|
23
|
+
type Box = [number, number, number, number];
|
|
24
|
+
|
|
25
|
+
export type MaterialKind = "img" | "svg" | "background" | "video" | "canvas";
|
|
26
|
+
|
|
27
|
+
/** One image of the page. */
|
|
28
|
+
export type MaterialImage = {
|
|
29
|
+
kind: MaterialKind;
|
|
30
|
+
/** PAGE CSS px — x, y from the top-left of the whole page (scroll 0), and
|
|
31
|
+
* the size it is drawn at */
|
|
32
|
+
box: Box;
|
|
33
|
+
/** an <img>'s alt as written ("" — the page marks it decorative) */
|
|
34
|
+
alt?: string;
|
|
35
|
+
/** its accessible name when there is no alt: aria-label, title, an svg's <title> */
|
|
36
|
+
name?: string;
|
|
37
|
+
/** the largest source the page offers (srcset / <picture> / image-set), a URL */
|
|
38
|
+
src?: string;
|
|
39
|
+
/** that source's width descriptor (srcset `1600w`) */
|
|
40
|
+
srcW?: number;
|
|
41
|
+
/** how many sources the page offers for it */
|
|
42
|
+
sources?: number;
|
|
43
|
+
/** the source the browser drew, when it is not `src` */
|
|
44
|
+
shown?: string;
|
|
45
|
+
/** the drawn source's own pixel size, when it had loaded */
|
|
46
|
+
natural?: [number, number];
|
|
47
|
+
/** a video's poster frame, a URL */
|
|
48
|
+
poster?: string;
|
|
49
|
+
/** the saved copy, relative to the state folder ("../assets/<sha1>.jpg");
|
|
50
|
+
* a video's is its poster frame */
|
|
51
|
+
file?: string;
|
|
52
|
+
/** the saved copy's pixel size (absent for a format whose header is not read) */
|
|
53
|
+
fileSize?: [number, number];
|
|
54
|
+
bytes?: number;
|
|
55
|
+
/** why no copy was saved */
|
|
56
|
+
notSaved?: string;
|
|
57
|
+
/** it starts within the first screen (scroll 0) */
|
|
58
|
+
firstScreen: boolean;
|
|
59
|
+
/** inside a position: fixed layer (its box is where the page was scrolled to) */
|
|
60
|
+
fixed?: true;
|
|
61
|
+
/** the landmark it sits in: nav, header, footer, aside, dialog */
|
|
62
|
+
in?: string;
|
|
63
|
+
/** why it is not seen as the page stands: "opacity 0" (a reveal not yet
|
|
64
|
+
* run), "visibility hidden", "outside the page width" (a carousel slide) */
|
|
65
|
+
hidden?: string;
|
|
66
|
+
/** a CSS path that finds it */
|
|
67
|
+
selector: string;
|
|
68
|
+
/** its element id in the saved screen (read from a state.html) */
|
|
69
|
+
el?: string;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/** One piece of the page's copy. */
|
|
73
|
+
export type MaterialText = {
|
|
74
|
+
/** the element's tag (h1–h6, p, li, blockquote, …; a div or span set larger than the body) */
|
|
75
|
+
tag: string;
|
|
76
|
+
/** a heading's level (h2 → 2, aria-level) */
|
|
77
|
+
level?: number;
|
|
78
|
+
/** the text, collapsed (cut at MATERIAL_TEXT_MAX chars, `chars` the whole length) */
|
|
79
|
+
text: string;
|
|
80
|
+
chars?: number;
|
|
81
|
+
box: Box;
|
|
82
|
+
fontPx: number;
|
|
83
|
+
weight: number;
|
|
84
|
+
firstScreen: boolean;
|
|
85
|
+
fixed?: true;
|
|
86
|
+
in?: string;
|
|
87
|
+
hidden?: string;
|
|
88
|
+
selector: string;
|
|
89
|
+
el?: string;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export type MaterialMeta = {
|
|
93
|
+
description?: string;
|
|
94
|
+
/** og:image / twitter:image, a URL — the page's share picture */
|
|
95
|
+
ogImage?: string;
|
|
96
|
+
ogImageFile?: string;
|
|
97
|
+
ogTitle?: string;
|
|
98
|
+
themeColor?: string;
|
|
99
|
+
icon?: string;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/** A link the page offers — to its About, docs, examples, repository, store
|
|
103
|
+
* page: other pages a film can read the product from. */
|
|
104
|
+
export type MaterialLink = {
|
|
105
|
+
/** what it says (its text, else its accessible name) */
|
|
106
|
+
text: string;
|
|
107
|
+
href: string;
|
|
108
|
+
/** on the page's own site (its host's last two labels) */
|
|
109
|
+
own: boolean;
|
|
110
|
+
/** the landmark it sits in: nav, header, footer, aside, dialog */
|
|
111
|
+
in?: string;
|
|
112
|
+
firstScreen: boolean;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/** The full-page picture: the page from top to bottom, small, cut into
|
|
116
|
+
* columns side by side (column k shows page y k·columnPx … (k+1)·columnPx). */
|
|
117
|
+
export type MaterialSheet = {
|
|
118
|
+
/** relative to the state folder */
|
|
119
|
+
file: string;
|
|
120
|
+
columns: number;
|
|
121
|
+
/** page CSS px per column */
|
|
122
|
+
columnPx: number;
|
|
123
|
+
/** image px per page CSS px */
|
|
124
|
+
scale: number;
|
|
125
|
+
/** page CSS px it shows from the top (the whole page unless it is very tall) */
|
|
126
|
+
coveredPx: number;
|
|
127
|
+
/** read from the saved screen: images the snapshot did not carry are blank */
|
|
128
|
+
from: "saved screen";
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/** `states/<id>/materials.json` — version 1. */
|
|
132
|
+
export type MaterialsFile = {
|
|
133
|
+
version: 1;
|
|
134
|
+
/** the saved screen it was read with */
|
|
135
|
+
state: string;
|
|
136
|
+
/** "live": in the product's page as it was shot; "saved screen": in its state.html */
|
|
137
|
+
read: "live" | "saved screen";
|
|
138
|
+
url: string;
|
|
139
|
+
title: string;
|
|
140
|
+
viewport: { w: number; h: number };
|
|
141
|
+
/** the whole page, CSS px */
|
|
142
|
+
page: { w: number; h: number };
|
|
143
|
+
medianTextPx: number;
|
|
144
|
+
meta: MaterialMeta;
|
|
145
|
+
/** in page order (top to bottom, then left to right) */
|
|
146
|
+
images: MaterialImage[];
|
|
147
|
+
/** in page order */
|
|
148
|
+
copy: MaterialText[];
|
|
149
|
+
/** the other pages it links to, one per address, in page order (absent in
|
|
150
|
+
* a file written before links were read) */
|
|
151
|
+
links?: MaterialLink[];
|
|
152
|
+
/** counted, not listed — each with its reason in `scope` */
|
|
153
|
+
skipped: MaterialSkipped;
|
|
154
|
+
sheet?: MaterialSheet;
|
|
155
|
+
/** what was read and what was not, in words */
|
|
156
|
+
scope: string;
|
|
157
|
+
ms: { read: number; files?: number; sheet?: number };
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
export type MaterialSkipped = {
|
|
161
|
+
/** drawn at no size (display: none, an empty box) */
|
|
162
|
+
hidden: number;
|
|
163
|
+
/** images and backgrounds drawn smaller than MATERIAL_MIN_IMAGE_PX square (icons, pixels) */
|
|
164
|
+
small: number;
|
|
165
|
+
/** inline svgs smaller than MATERIAL_MIN_SVG_AREA px² (icons) */
|
|
166
|
+
icons: number;
|
|
167
|
+
/** copy inside aria-hidden (a marquee's repeat) */
|
|
168
|
+
ariaHidden: number;
|
|
169
|
+
/** iframes (embeds, ads): not read */
|
|
170
|
+
frames: number;
|
|
171
|
+
/** past MATERIAL_MAX_IMAGES / MATERIAL_MAX_COPY entries */
|
|
172
|
+
more: number;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export const MATERIAL_TEXT_MAX = 400;
|
|
176
|
+
export const MATERIAL_MIN_IMAGE_PX = 24;
|
|
177
|
+
export const MATERIAL_MIN_SVG_AREA = 3000;
|
|
178
|
+
export const MATERIAL_MAX_IMAGES = 400;
|
|
179
|
+
export const MATERIAL_MAX_COPY = 600;
|
|
180
|
+
export const MATERIAL_MAX_LINKS = 120;
|
|
181
|
+
|
|
182
|
+
/** A source the page offers for an image. */
|
|
183
|
+
export type MaterialCandidate = {
|
|
184
|
+
url: string;
|
|
185
|
+
/** srcset width descriptor */
|
|
186
|
+
w?: number;
|
|
187
|
+
/** density descriptor (a plain src is 1x) */
|
|
188
|
+
x?: number;
|
|
189
|
+
/** a <source>'s type */
|
|
190
|
+
type?: string;
|
|
191
|
+
media?: string;
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
/** What the page script returns per image, before the Node side picks the
|
|
195
|
+
* largest source and saves files. */
|
|
196
|
+
export type MaterialProbeImage = Omit<
|
|
197
|
+
MaterialImage,
|
|
198
|
+
"src" | "srcW" | "sources" | "shown" | "file" | "fileSize" | "bytes" | "notSaved"
|
|
199
|
+
> & {
|
|
200
|
+
candidates: MaterialCandidate[];
|
|
201
|
+
/** the source drawn (currentSrc) */
|
|
202
|
+
current?: string;
|
|
203
|
+
/** an inline svg, standalone (xmlns added, drawn size and colour on a wrapper) */
|
|
204
|
+
markup?: string;
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
export type MaterialsProbeResult =
|
|
208
|
+
| {
|
|
209
|
+
url: string;
|
|
210
|
+
title: string;
|
|
211
|
+
viewport: { w: number; h: number };
|
|
212
|
+
page: { w: number; h: number };
|
|
213
|
+
medianTextPx: number;
|
|
214
|
+
meta: MaterialMeta;
|
|
215
|
+
images: MaterialProbeImage[];
|
|
216
|
+
copy: MaterialText[];
|
|
217
|
+
links?: MaterialLink[];
|
|
218
|
+
skipped: MaterialSkipped;
|
|
219
|
+
ms: number;
|
|
220
|
+
}
|
|
221
|
+
| { error: string };
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* A function expression: `(${MATERIALS_PROBE_JS})()` returns a JSON string
|
|
225
|
+
* (MaterialsProbeResult). Reads the page only — no node, attribute or style
|
|
226
|
+
* is touched and nothing scrolls; the page is being filmed.
|
|
227
|
+
*/
|
|
228
|
+
export const MATERIALS_PROBE_JS = String.raw`function () {
|
|
229
|
+
try {
|
|
230
|
+
var t0 = performance.now();
|
|
231
|
+
var vw = innerWidth, vh = innerHeight, sx = scrollX, sy = scrollY;
|
|
232
|
+
var de = document.documentElement, body = document.body || de;
|
|
233
|
+
var pageW = Math.max(de.scrollWidth, body.scrollWidth, vw);
|
|
234
|
+
var pageH = Math.max(de.scrollHeight, body.scrollHeight, vh);
|
|
235
|
+
var R = Math.round;
|
|
236
|
+
var MIN_PX = ${MATERIAL_MIN_IMAGE_PX}, MIN_SVG = ${MATERIAL_MIN_SVG_AREA};
|
|
237
|
+
var MAX_IMAGES = ${MATERIAL_MAX_IMAGES}, MAX_COPY = ${MATERIAL_MAX_COPY}, TEXT_MAX = ${MATERIAL_TEXT_MAX}, MAX_LINKS = ${MATERIAL_MAX_LINKS};
|
|
238
|
+
var collapse = function (s) { return (s || "").replace(/\s+/g, " ").trim(); };
|
|
239
|
+
var absUrl = function (u) {
|
|
240
|
+
if (!u) return null;
|
|
241
|
+
try { var h = new URL(u, document.baseURI).href; return /^(about|javascript):/i.test(h) ? null : h; } catch (e) { return null; }
|
|
242
|
+
};
|
|
243
|
+
var styleCache = new Map();
|
|
244
|
+
var cs = function (el) { var s = styleCache.get(el); if (!s) { s = getComputedStyle(el); styleCache.set(el, s); } return s; };
|
|
245
|
+
var skipped = { hidden: 0, small: 0, icons: 0, ariaHidden: 0, frames: 0, more: 0 };
|
|
246
|
+
|
|
247
|
+
// --- where it is -----------------------------------------------------------
|
|
248
|
+
var fixedCache = new Map();
|
|
249
|
+
var fixedOf = function (el) {
|
|
250
|
+
if (!el || el.nodeType !== 1) return false;
|
|
251
|
+
if (fixedCache.has(el)) return fixedCache.get(el);
|
|
252
|
+
var f = cs(el).position === "fixed" || fixedOf(el.parentElement);
|
|
253
|
+
fixedCache.set(el, f);
|
|
254
|
+
return f;
|
|
255
|
+
};
|
|
256
|
+
var pageBox = function (r, fixed) {
|
|
257
|
+
// a fixed layer is where it is on screen, wherever the page is scrolled
|
|
258
|
+
var ox = fixed ? 0 : sx, oy = fixed ? 0 : sy;
|
|
259
|
+
return [R(r.left + ox), R(r.top + oy), R(r.width), R(r.height)];
|
|
260
|
+
};
|
|
261
|
+
var LANDMARK = "nav,header,footer,aside,dialog,[role=navigation],[role=banner],[role=contentinfo],[role=complementary],[role=dialog]";
|
|
262
|
+
var ROLE_NAME = { navigation: "nav", banner: "header", contentinfo: "footer", complementary: "aside", dialog: "dialog" };
|
|
263
|
+
var landmarkOf = function (el) {
|
|
264
|
+
var l = el.closest(LANDMARK);
|
|
265
|
+
if (!l) return undefined;
|
|
266
|
+
var role = l.getAttribute("role");
|
|
267
|
+
return (role && ROLE_NAME[role]) || l.localName;
|
|
268
|
+
};
|
|
269
|
+
var opacityCache = new Map();
|
|
270
|
+
var faded = function (el) {
|
|
271
|
+
if (!el || el.nodeType !== 1) return null;
|
|
272
|
+
if (opacityCache.has(el)) return opacityCache.get(el);
|
|
273
|
+
var o = parseFloat(cs(el).opacity);
|
|
274
|
+
var res = o < 0.05 ? "opacity " + R(o * 100) / 100 : faded(el.parentElement);
|
|
275
|
+
opacityCache.set(el, res);
|
|
276
|
+
return res;
|
|
277
|
+
};
|
|
278
|
+
var hiddenWhy = function (el, box) {
|
|
279
|
+
var v = cs(el).visibility;
|
|
280
|
+
if (v === "hidden" || v === "collapse") return "visibility hidden";
|
|
281
|
+
var f = faded(el);
|
|
282
|
+
if (f) return f;
|
|
283
|
+
if (box[0] + box[2] <= 0 || box[0] >= pageW) return "outside the page width";
|
|
284
|
+
return null;
|
|
285
|
+
};
|
|
286
|
+
var cssIdent = /^-?[A-Za-z_][A-Za-z0-9_-]*$/;
|
|
287
|
+
var selectorOf = function (el) {
|
|
288
|
+
var steps = [], n = el;
|
|
289
|
+
while (n && n !== de) {
|
|
290
|
+
if (n.id && cssIdent.test(n.id) && document.querySelectorAll("#" + n.id).length === 1) { steps.unshift("#" + n.id); break; }
|
|
291
|
+
var tag = n.localName, par = n.parentElement, step = tag;
|
|
292
|
+
if (par) {
|
|
293
|
+
var same = Array.prototype.filter.call(par.children, function (c) { return c.localName === tag; });
|
|
294
|
+
if (same.length > 1) step += ":nth-of-type(" + (same.indexOf(n) + 1) + ")";
|
|
295
|
+
}
|
|
296
|
+
steps.unshift(step);
|
|
297
|
+
if (tag === "body") break;
|
|
298
|
+
n = par;
|
|
299
|
+
}
|
|
300
|
+
return steps.join(" > ");
|
|
301
|
+
};
|
|
302
|
+
var common = function (el, r) {
|
|
303
|
+
var fixed = fixedOf(el), box = pageBox(r, fixed);
|
|
304
|
+
var o = { box: box, firstScreen: !fixed && box[1] < vh || fixed && r.top < vh, selector: selectorOf(el) };
|
|
305
|
+
if (fixed) o.fixed = true;
|
|
306
|
+
var lm = landmarkOf(el); if (lm) o.in = lm;
|
|
307
|
+
var h = hiddenWhy(el, box); if (h) o.hidden = h;
|
|
308
|
+
var id = el.getAttribute("data-ot-id"); if (id) o.el = id;
|
|
309
|
+
return o;
|
|
310
|
+
};
|
|
311
|
+
var nameOf = function (el) {
|
|
312
|
+
var a = el.getAttribute("aria-label");
|
|
313
|
+
if (a && collapse(a)) return collapse(a);
|
|
314
|
+
var by = el.getAttribute("aria-labelledby");
|
|
315
|
+
if (by) {
|
|
316
|
+
var t = by.split(/\s+/).map(function (id) { var n = document.getElementById(id); return n ? collapse(n.textContent) : ""; }).join(" ").trim();
|
|
317
|
+
if (t) return t;
|
|
318
|
+
}
|
|
319
|
+
var ti = el.getAttribute("title");
|
|
320
|
+
if (ti && collapse(ti)) return collapse(ti);
|
|
321
|
+
return undefined;
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
// --- sources ------------------------------------------------------------------
|
|
325
|
+
var parseSrcset = function (value) {
|
|
326
|
+
var out = [], n = value.length, i = 0;
|
|
327
|
+
while (i < n) {
|
|
328
|
+
while (i < n && /[\s,]/.test(value[i])) i++;
|
|
329
|
+
if (i >= n) break;
|
|
330
|
+
var st = i;
|
|
331
|
+
while (i < n && !/\s/.test(value[i])) i++;
|
|
332
|
+
var url = value.slice(st, i), d = "";
|
|
333
|
+
if (/,$/.test(url)) url = url.replace(/,+$/, "");
|
|
334
|
+
else {
|
|
335
|
+
while (i < n && /\s/.test(value[i])) i++;
|
|
336
|
+
var ds = i;
|
|
337
|
+
while (i < n && value[i] !== ",") i++;
|
|
338
|
+
d = value.slice(ds, i).trim();
|
|
339
|
+
}
|
|
340
|
+
if (url) out.push({ url: url, d: d });
|
|
341
|
+
}
|
|
342
|
+
return out;
|
|
343
|
+
};
|
|
344
|
+
var candidate = function (url, d, from) {
|
|
345
|
+
var a = absUrl(url);
|
|
346
|
+
if (!a) return null;
|
|
347
|
+
var c = { url: a }, m;
|
|
348
|
+
if ((m = /^(\d+(?:\.\d+)?)w$/i.exec(d || ""))) c.w = +m[1];
|
|
349
|
+
else if ((m = /^(\d+(?:\.\d+)?)x$/i.exec(d || ""))) c.x = +m[1];
|
|
350
|
+
else c.x = 1;
|
|
351
|
+
if (from && from.getAttribute("type")) c.type = from.getAttribute("type");
|
|
352
|
+
if (from && from.getAttribute("media")) c.media = from.getAttribute("media");
|
|
353
|
+
return c;
|
|
354
|
+
};
|
|
355
|
+
var fromSrcset = function (value, from) {
|
|
356
|
+
return parseSrcset(value || "").map(function (s) { return candidate(s.url, s.d, from); }).filter(Boolean);
|
|
357
|
+
};
|
|
358
|
+
var cssUrls = function (value) {
|
|
359
|
+
var out = [], re = /url\(\s*(?:"((?:[^"\\]|\\.)*)"|'((?:[^'\\]|\\.)*)'|([^)\s]*))\s*\)\s*(\d+(?:\.\d+)?x)?/g, m;
|
|
360
|
+
while ((m = re.exec(value))) {
|
|
361
|
+
var c = candidate((m[1] != null ? m[1] : m[2] != null ? m[2] : m[3] || "").replace(/\\(.)/g, "$1"), m[4] || "");
|
|
362
|
+
if (c) out.push(c);
|
|
363
|
+
}
|
|
364
|
+
return out;
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
var images = [];
|
|
368
|
+
var pushImage = function (o) {
|
|
369
|
+
if (images.length >= MAX_IMAGES) { skipped.more++; return; }
|
|
370
|
+
images.push(o);
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
// --- <img> (and its <picture>) ---------------------------------------------------
|
|
374
|
+
Array.prototype.forEach.call(document.images, function (img) {
|
|
375
|
+
var r = img.getBoundingClientRect();
|
|
376
|
+
if (r.width < 1 || r.height < 1) { skipped.hidden++; return; }
|
|
377
|
+
var nw = img.complete ? img.naturalWidth : 0, nh = img.complete ? img.naturalHeight : 0;
|
|
378
|
+
if ((r.width < MIN_PX || r.height < MIN_PX) && (nw < MIN_PX * 2 || nh < MIN_PX * 2)) { skipped.small++; return; }
|
|
379
|
+
var cands = [];
|
|
380
|
+
var pic = img.parentElement && img.parentElement.localName === "picture" ? img.parentElement : null;
|
|
381
|
+
if (pic) Array.prototype.forEach.call(pic.querySelectorAll(":scope > source"), function (s) {
|
|
382
|
+
cands = cands.concat(fromSrcset(s.getAttribute("srcset"), s));
|
|
383
|
+
var one = s.getAttribute("src") && candidate(s.getAttribute("src"), "", s);
|
|
384
|
+
if (one) cands.push(one);
|
|
385
|
+
});
|
|
386
|
+
cands = cands.concat(fromSrcset(img.getAttribute("srcset"), null));
|
|
387
|
+
var src = img.getAttribute("src") && candidate(img.getAttribute("src"), "", null);
|
|
388
|
+
if (src) cands.push(src);
|
|
389
|
+
var o = common(img, r);
|
|
390
|
+
o.kind = "img";
|
|
391
|
+
var alt = img.getAttribute("alt");
|
|
392
|
+
if (alt != null) o.alt = collapse(alt);
|
|
393
|
+
var nm = nameOf(img); if (nm) o.name = nm;
|
|
394
|
+
o.candidates = cands;
|
|
395
|
+
if (img.currentSrc) o.current = img.currentSrc;
|
|
396
|
+
if (nw && nh) o.natural = [nw, nh];
|
|
397
|
+
pushImage(o);
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
// --- inline svg, video, canvas, iframes ------------------------------------------------
|
|
401
|
+
Array.prototype.forEach.call(document.querySelectorAll("svg"), function (svg) {
|
|
402
|
+
if (svg.parentElement && svg.parentElement.closest("svg")) return;
|
|
403
|
+
var r = svg.getBoundingClientRect();
|
|
404
|
+
if (r.width < 1 || r.height < 1) { skipped.hidden++; return; }
|
|
405
|
+
if (r.width * r.height < MIN_SVG) { skipped.icons++; return; }
|
|
406
|
+
var o = common(svg, r);
|
|
407
|
+
o.kind = "svg";
|
|
408
|
+
var t = svg.querySelector(":scope > title");
|
|
409
|
+
var nm = nameOf(svg) || (t && collapse(t.textContent)) || undefined;
|
|
410
|
+
if (nm) o.name = nm;
|
|
411
|
+
o.candidates = [];
|
|
412
|
+
var w = R(r.width), h = R(r.height), src = svg.outerHTML;
|
|
413
|
+
if (src.length <= 400000)
|
|
414
|
+
o.markup = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="' + w + '" height="' + h +
|
|
415
|
+
'" viewBox="0 0 ' + w + " " + h + '" style="color:' + cs(svg).color + '">' +
|
|
416
|
+
src.replace(/^<svg(?![^>]*\sxmlns=)/, '<svg xmlns="http://www.w3.org/2000/svg"') + "</svg>";
|
|
417
|
+
pushImage(o);
|
|
418
|
+
});
|
|
419
|
+
Array.prototype.forEach.call(document.querySelectorAll("video"), function (v) {
|
|
420
|
+
var r = v.getBoundingClientRect();
|
|
421
|
+
if (r.width < 1 || r.height < 1) { skipped.hidden++; return; }
|
|
422
|
+
var o = common(v, r);
|
|
423
|
+
o.kind = "video";
|
|
424
|
+
var nm = nameOf(v); if (nm) o.name = nm;
|
|
425
|
+
var cands = [];
|
|
426
|
+
var one = v.getAttribute("src") && candidate(v.getAttribute("src"), "", null);
|
|
427
|
+
if (one) cands.push(one);
|
|
428
|
+
Array.prototype.forEach.call(v.querySelectorAll("source"), function (s) {
|
|
429
|
+
var c = s.getAttribute("src") && candidate(s.getAttribute("src"), "", s);
|
|
430
|
+
if (c) cands.push(c);
|
|
431
|
+
});
|
|
432
|
+
o.candidates = cands;
|
|
433
|
+
if (v.currentSrc) o.current = v.currentSrc;
|
|
434
|
+
if (v.videoWidth && v.videoHeight) o.natural = [v.videoWidth, v.videoHeight];
|
|
435
|
+
var p = absUrl(v.getAttribute("poster")); if (p) o.poster = p;
|
|
436
|
+
pushImage(o);
|
|
437
|
+
});
|
|
438
|
+
Array.prototype.forEach.call(document.querySelectorAll("canvas"), function (c) {
|
|
439
|
+
var r = c.getBoundingClientRect();
|
|
440
|
+
if (r.width < 1 || r.height < 1) { skipped.hidden++; return; }
|
|
441
|
+
if (r.width < MIN_PX * 2 || r.height < MIN_PX * 2) { skipped.small++; return; }
|
|
442
|
+
var o = common(c, r);
|
|
443
|
+
o.kind = "canvas";
|
|
444
|
+
var nm = nameOf(c); if (nm) o.name = nm;
|
|
445
|
+
o.candidates = [];
|
|
446
|
+
pushImage(o);
|
|
447
|
+
});
|
|
448
|
+
skipped.frames = document.querySelectorAll("iframe, frame").length;
|
|
449
|
+
|
|
450
|
+
// --- one pass over the elements: background images and the copy -----------------
|
|
451
|
+
var all = body.querySelectorAll("*");
|
|
452
|
+
var SKIP = { script: 1, style: 1, noscript: 1, template: 1, head: 1, link: 1, meta: 1, title: 1, svg: 1, math: 1, iframe: 1, canvas: 1, video: 1, img: 1, picture: 1, source: 1, select: 1, option: 1, textarea: 1, input: 1 };
|
|
453
|
+
var ownText = function (el) { var s = ""; for (var i = 0; i < el.childNodes.length; i++) { var n = el.childNodes[i]; if (n.nodeType === 3) s += n.data; } return collapse(s); };
|
|
454
|
+
// the body size: the median font over the page's text, weighted by characters
|
|
455
|
+
var sizes = [];
|
|
456
|
+
for (var i = 0; i < all.length; i++) {
|
|
457
|
+
var e = all[i];
|
|
458
|
+
if (SKIP[e.localName] || e.closest("svg")) continue;
|
|
459
|
+
var t = ownText(e);
|
|
460
|
+
if (!t) continue;
|
|
461
|
+
var rr = e.getBoundingClientRect();
|
|
462
|
+
if (rr.width < 1 || rr.height < 1) continue;
|
|
463
|
+
sizes.push([parseFloat(cs(e).fontSize) || 16, t.length]);
|
|
464
|
+
}
|
|
465
|
+
sizes.sort(function (a, b) { return a[0] - b[0]; });
|
|
466
|
+
var total = sizes.reduce(function (s, x) { return s + x[1]; }, 0), acc = 0, median = 16;
|
|
467
|
+
for (var k = 0; k < sizes.length; k++) { acc += sizes[k][1]; if (acc >= total / 2) { median = sizes[k][0]; break; } }
|
|
468
|
+
|
|
469
|
+
var COPY = { p: 1, blockquote: 1, figcaption: 1, li: 1, dt: 1, dd: 1, caption: 1, h1: 1, h2: 1, h3: 1, h4: 1, h5: 1, h6: 1 };
|
|
470
|
+
var INTERACTIVE = "a[href],button,select,textarea,input,label,summary,[role=button],[role=link],[role=tab],[role=menuitem],[role=option],[role=switch],[role=checkbox]";
|
|
471
|
+
var copy = [], taken = new Set();
|
|
472
|
+
var underTaken = function (el) { for (var n = el.parentElement; n; n = n.parentElement) if (taken.has(n)) return true; return false; };
|
|
473
|
+
var linkText = function (el) {
|
|
474
|
+
var s = "";
|
|
475
|
+
Array.prototype.forEach.call(el.querySelectorAll(INTERACTIVE), function (a) { s += " " + (a.innerText || ""); });
|
|
476
|
+
return collapse(s);
|
|
477
|
+
};
|
|
478
|
+
for (var j = 0; j < all.length; j++) {
|
|
479
|
+
var el = all[j], tag = el.localName;
|
|
480
|
+
if (SKIP[tag] || el.closest("svg")) continue;
|
|
481
|
+
// background images
|
|
482
|
+
var bg = cs(el).backgroundImage;
|
|
483
|
+
if (bg && bg !== "none" && bg.indexOf("url(") >= 0) {
|
|
484
|
+
var cands = cssUrls(bg);
|
|
485
|
+
if (cands.length) {
|
|
486
|
+
var br = el.getBoundingClientRect();
|
|
487
|
+
if (br.width < 1 || br.height < 1) skipped.hidden++;
|
|
488
|
+
else if (br.width < MIN_PX * 2 || br.height < MIN_PX * 2) skipped.small++;
|
|
489
|
+
else {
|
|
490
|
+
var bo = common(el, br);
|
|
491
|
+
bo.kind = "background";
|
|
492
|
+
var bn = nameOf(el); if (bn) bo.name = bn;
|
|
493
|
+
bo.candidates = cands;
|
|
494
|
+
pushImage(bo);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
// copy
|
|
499
|
+
var role = el.getAttribute("role");
|
|
500
|
+
var heading = /^h[1-6]$/.test(tag) || role === "heading";
|
|
501
|
+
var own = ownText(el);
|
|
502
|
+
var fs = parseFloat(cs(el).fontSize) || 16;
|
|
503
|
+
var block = COPY[tag] || heading;
|
|
504
|
+
var large = own.length >= 2 && fs >= 1.25 * median;
|
|
505
|
+
var prose = own.length >= 24 && !el.querySelector("p,div,li,section,article,h1,h2,h3,h4,h5,h6");
|
|
506
|
+
if (!block && !large && !prose) continue;
|
|
507
|
+
if (!heading && el.closest(INTERACTIVE)) continue;
|
|
508
|
+
if (underTaken(el)) continue;
|
|
509
|
+
var tr = el.getBoundingClientRect();
|
|
510
|
+
if (tr.width < 1 || tr.height < 1) { skipped.hidden++; continue; }
|
|
511
|
+
if (el.closest("[aria-hidden=true]")) { skipped.ariaHidden++; continue; }
|
|
512
|
+
var text = collapse(el.innerText || el.textContent);
|
|
513
|
+
if (!text) continue;
|
|
514
|
+
if (!heading) {
|
|
515
|
+
var lt = linkText(el);
|
|
516
|
+
if (lt && lt.length >= text.length * 0.9) continue;
|
|
517
|
+
}
|
|
518
|
+
if (copy.length >= MAX_COPY) { skipped.more++; continue; }
|
|
519
|
+
taken.add(el);
|
|
520
|
+
var co = common(el, tr);
|
|
521
|
+
co.tag = tag;
|
|
522
|
+
if (heading) {
|
|
523
|
+
var lv = /^h([1-6])$/.exec(tag) ? +tag[1] : +(el.getAttribute("aria-level") || 2);
|
|
524
|
+
co.level = lv;
|
|
525
|
+
}
|
|
526
|
+
co.text = text.length > TEXT_MAX ? text.slice(0, TEXT_MAX - 1) + "…" : text;
|
|
527
|
+
if (text.length > TEXT_MAX) co.chars = text.length;
|
|
528
|
+
co.fontPx = R(fs * 10) / 10;
|
|
529
|
+
co.weight = parseInt(cs(el).fontWeight, 10) || 400;
|
|
530
|
+
copy.push(co);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
// --- the other pages it links to ---------------------------------------------------
|
|
534
|
+
var site = function (h) { return h.split(".").slice(-2).join("."); };
|
|
535
|
+
var here = location.href.split("#")[0], ownSite = site(location.hostname);
|
|
536
|
+
var links = [], seenHref = new Set();
|
|
537
|
+
Array.prototype.forEach.call(body.querySelectorAll("a[href]"), function (a) {
|
|
538
|
+
if (links.length >= MAX_LINKS) return;
|
|
539
|
+
var href = absUrl(a.getAttribute("href"));
|
|
540
|
+
if (!href || !/^https?:/i.test(href)) return;
|
|
541
|
+
var bare = href.split("#")[0];
|
|
542
|
+
if (bare === here || seenHref.has(bare)) return;
|
|
543
|
+
var lr = a.getBoundingClientRect();
|
|
544
|
+
if (lr.width < 1 || lr.height < 1) return;
|
|
545
|
+
var text = collapse(a.innerText || "") || nameOf(a) || "";
|
|
546
|
+
if (!text) { var im = a.querySelector("img[alt]"); if (im) text = collapse(im.getAttribute("alt")); }
|
|
547
|
+
if (!text) return;
|
|
548
|
+
seenHref.add(bare);
|
|
549
|
+
var lo = { text: text.length > 80 ? text.slice(0, 79) + "…" : text, href: href, own: site(new URL(href).hostname) === ownSite,
|
|
550
|
+
firstScreen: (fixedOf(a) ? lr.top : lr.top + sy) < vh, box: pageBox(lr, fixedOf(a)) };
|
|
551
|
+
var lm = landmarkOf(a); if (lm) lo.in = lm;
|
|
552
|
+
links.push(lo);
|
|
553
|
+
});
|
|
554
|
+
links.sort(function (a, b) { return a.box[1] - b.box[1] || a.box[0] - b.box[0]; });
|
|
555
|
+
links.forEach(function (l) { delete l.box; });
|
|
556
|
+
|
|
557
|
+
// --- the head: what the page says about itself ----------------------------------
|
|
558
|
+
var metaOf = function (sel) { var m = document.querySelector(sel); return m ? collapse(m.getAttribute("content")) : ""; };
|
|
559
|
+
var meta = {};
|
|
560
|
+
var d = metaOf('meta[name="description"]') || metaOf('meta[property="og:description"]'); if (d) meta.description = d;
|
|
561
|
+
var og = absUrl(metaOf('meta[property="og:image"]') || metaOf('meta[name="twitter:image"]')); if (og) meta.ogImage = og;
|
|
562
|
+
var ot = metaOf('meta[property="og:title"]'); if (ot) meta.ogTitle = ot;
|
|
563
|
+
var tc = metaOf('meta[name="theme-color"]'); if (tc) meta.themeColor = tc;
|
|
564
|
+
var ic = document.querySelector('link[rel~="icon"], link[rel="apple-touch-icon"]');
|
|
565
|
+
var icu = ic && absUrl(ic.getAttribute("href")); if (icu) meta.icon = icu;
|
|
566
|
+
|
|
567
|
+
var order = function (a, b) { return a.box[1] - b.box[1] || a.box[0] - b.box[0]; };
|
|
568
|
+
images.sort(order);
|
|
569
|
+
copy.sort(order);
|
|
570
|
+
return JSON.stringify({
|
|
571
|
+
url: location.href, title: document.title,
|
|
572
|
+
viewport: { w: vw, h: vh }, page: { w: pageW, h: pageH },
|
|
573
|
+
medianTextPx: median, meta: meta, images: images, copy: copy, links: links, skipped: skipped,
|
|
574
|
+
ms: R(performance.now() - t0)
|
|
575
|
+
});
|
|
576
|
+
} catch (e) {
|
|
577
|
+
return JSON.stringify({ error: String(e && e.stack || e) });
|
|
578
|
+
}
|
|
579
|
+
}`;
|
|
580
|
+
|
|
581
|
+
/** The expression to evaluate (returnByValue): a JSON string. */
|
|
582
|
+
export const materialsProbeExpression = (): string => `(${MATERIALS_PROBE_JS})()`;
|
|
583
|
+
|
|
584
|
+
// --- the Node side ---------------------------------------------------------------
|
|
585
|
+
|
|
586
|
+
/** Formats a browser draws everywhere, preferred over a newer one of the
|
|
587
|
+
* same size (a saved .avif is a file fewer tools open) */
|
|
588
|
+
const PLAIN_TYPE = /^image\/(jpeg|jpg|png|webp|gif|svg\+xml)$/i;
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* The largest source among what the page offers for one image: the widest
|
|
592
|
+
* `w` descriptor when there is one, else the highest density (a plain src
|
|
593
|
+
* is 1x). A data: URL counts only when nothing else is offered (a blurred
|
|
594
|
+
* placeholder in src, the picture in srcset). Ties go to a plain format,
|
|
595
|
+
* then to the first offered. Null when nothing can be fetched.
|
|
596
|
+
*/
|
|
597
|
+
export function largestSource(
|
|
598
|
+
cands: readonly MaterialCandidate[],
|
|
599
|
+
): { url: string; w?: number } | null {
|
|
600
|
+
const real = cands.filter((c) => !/^(data|blob):/i.test(c.url));
|
|
601
|
+
const pool = real.length ? real : cands.filter((c) => /^data:/i.test(c.url));
|
|
602
|
+
if (!pool.length) return null;
|
|
603
|
+
const widths = pool.filter((c) => c.w != null);
|
|
604
|
+
const by = widths.length ? widths : pool;
|
|
605
|
+
const size = (c: MaterialCandidate) => (widths.length ? c.w! : (c.x ?? 1));
|
|
606
|
+
const plain = (c: MaterialCandidate) => (!c.type || PLAIN_TYPE.test(c.type) ? 1 : 0);
|
|
607
|
+
let best = by[0]!;
|
|
608
|
+
for (const c of by.slice(1))
|
|
609
|
+
if (size(c) > size(best) || (size(c) === size(best) && plain(c) > plain(best))) best = c;
|
|
610
|
+
return { url: best.url, ...(best.w != null ? { w: best.w } : {}) };
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
/** Hosts that serve ads and tracking, not a product's own pictures: listed,
|
|
614
|
+
* never saved. */
|
|
615
|
+
const AD_HOST =
|
|
616
|
+
/(^|\.)(doubleclick\.net|googlesyndication\.com|googleadservices\.com|adservice\.google\.[a-z.]+|google-analytics\.com|googletagmanager\.com|facebook\.net|adnxs\.com|criteo\.(com|net)|taboola\.com|outbrain\.com|amazon-adsystem\.com|scorecardresearch\.com|quantserve\.com|bat\.bing\.com|ads\.linkedin\.com|ads-twitter\.com|analytics\.twitter\.com|adsrvr\.org|rubiconproject\.com|pubmatic\.com|moatads\.com|hotjar\.com)$/i;
|
|
617
|
+
|
|
618
|
+
/** An ad or tracking host (the image is listed, never saved). */
|
|
619
|
+
export function adHost(url: string): boolean {
|
|
620
|
+
try {
|
|
621
|
+
const u = new URL(url);
|
|
622
|
+
return (
|
|
623
|
+
AD_HOST.test(u.hostname) ||
|
|
624
|
+
(/(^|\.)facebook\.com$/i.test(u.hostname) && u.pathname.startsWith("/tr"))
|
|
625
|
+
);
|
|
626
|
+
} catch {
|
|
627
|
+
return false;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/** The pixel size an image file states in its header (PNG, GIF, JPEG, WebP,
|
|
632
|
+
* SVG's width/height or viewBox); null for a format it does not read. */
|
|
633
|
+
export function imageFileSize(buf: Buffer): [number, number] | null {
|
|
634
|
+
if (buf.length >= 24 && buf.readUInt32BE(0) === 0x89504e47)
|
|
635
|
+
return [buf.readUInt32BE(16), buf.readUInt32BE(20)];
|
|
636
|
+
if (buf.length >= 10 && buf.toString("latin1", 0, 3) === "GIF")
|
|
637
|
+
return [buf.readUInt16LE(6), buf.readUInt16LE(8)];
|
|
638
|
+
if (buf.length >= 4 && buf[0] === 0xff && buf[1] === 0xd8) {
|
|
639
|
+
let i = 2;
|
|
640
|
+
while (i + 9 < buf.length) {
|
|
641
|
+
if (buf[i] !== 0xff) {
|
|
642
|
+
i++;
|
|
643
|
+
continue;
|
|
644
|
+
}
|
|
645
|
+
const m = buf[i + 1]!;
|
|
646
|
+
// SOFn (not DHT c4, JPG c8, DAC cc) carries the frame size
|
|
647
|
+
if (m >= 0xc0 && m <= 0xcf && m !== 0xc4 && m !== 0xc8 && m !== 0xcc)
|
|
648
|
+
return [buf.readUInt16BE(i + 7), buf.readUInt16BE(i + 5)];
|
|
649
|
+
if (m === 0xd8 || m === 0x01 || (m >= 0xd0 && m <= 0xd7) || m === 0xff) {
|
|
650
|
+
i += m === 0xff ? 1 : 2;
|
|
651
|
+
continue;
|
|
652
|
+
}
|
|
653
|
+
i += 2 + buf.readUInt16BE(i + 2);
|
|
654
|
+
}
|
|
655
|
+
return null;
|
|
656
|
+
}
|
|
657
|
+
if (
|
|
658
|
+
buf.length >= 30 &&
|
|
659
|
+
buf.toString("latin1", 0, 4) === "RIFF" &&
|
|
660
|
+
buf.toString("latin1", 8, 12) === "WEBP"
|
|
661
|
+
) {
|
|
662
|
+
const chunk = buf.toString("latin1", 12, 16);
|
|
663
|
+
if (chunk === "VP8X") return [1 + buf.readUIntLE(24, 3), 1 + buf.readUIntLE(27, 3)];
|
|
664
|
+
if (chunk === "VP8 ") return [buf.readUInt16LE(26) & 0x3fff, buf.readUInt16LE(28) & 0x3fff];
|
|
665
|
+
if (chunk === "VP8L") {
|
|
666
|
+
const b = buf.readUInt32LE(21);
|
|
667
|
+
return [1 + (b & 0x3fff), 1 + ((b >> 14) & 0x3fff)];
|
|
668
|
+
}
|
|
669
|
+
return null;
|
|
670
|
+
}
|
|
671
|
+
const head = buf.toString("utf8", 0, Math.min(buf.length, 4096));
|
|
672
|
+
const svg = /<svg\b[^>]*>/i.exec(head)?.[0];
|
|
673
|
+
if (svg) {
|
|
674
|
+
const num = (name: string) => {
|
|
675
|
+
const m = new RegExp(`\\s${name}\\s*=\\s*["']\\s*([\\d.]+)(px)?\\s*["']`, "i").exec(svg);
|
|
676
|
+
return m ? Number(m[1]) : null;
|
|
677
|
+
};
|
|
678
|
+
const w = num("width");
|
|
679
|
+
const h = num("height");
|
|
680
|
+
if (w && h) return [Math.round(w), Math.round(h)];
|
|
681
|
+
const vb = /\sviewBox\s*=\s*["']\s*[-\d.]+[\s,]+[-\d.]+[\s,]+([\d.]+)[\s,]+([\d.]+)/i.exec(svg);
|
|
682
|
+
if (vb) return [Math.round(Number(vb[1])), Math.round(Number(vb[2]))];
|
|
683
|
+
}
|
|
684
|
+
return null;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
/** What the probe found, as the file lists it: each image's largest source
|
|
688
|
+
* chosen, the source list dropped (its count kept); what is to be saved is
|
|
689
|
+
* returned beside it, by index. */
|
|
690
|
+
export function materialsFromProbe(
|
|
691
|
+
res: Exclude<MaterialsProbeResult, { error: string }>,
|
|
692
|
+
o: { state: string; read: MaterialsFile["read"] },
|
|
693
|
+
): {
|
|
694
|
+
file: MaterialsFile;
|
|
695
|
+
/** per image (same index): a URL to fetch, an svg's markup, or a data: URL to decode */
|
|
696
|
+
save: ({ url: string } | { markup: string } | { data: string } | null)[];
|
|
697
|
+
} {
|
|
698
|
+
const save: ({ url: string } | { markup: string } | { data: string } | null)[] = [];
|
|
699
|
+
const images: MaterialImage[] = res.images.map((im) => {
|
|
700
|
+
const { candidates, current, markup, ...rest } = im;
|
|
701
|
+
const best = largestSource(candidates);
|
|
702
|
+
const out: MaterialImage = { ...rest };
|
|
703
|
+
if (best) {
|
|
704
|
+
if (/^data:/i.test(best.url)) {
|
|
705
|
+
// the file holds it; the list names only its type
|
|
706
|
+
out.src = /^data:[^;,]*/i.exec(best.url)![0];
|
|
707
|
+
save.push({ data: best.url });
|
|
708
|
+
} else {
|
|
709
|
+
out.src = best.url;
|
|
710
|
+
// a video is not fetched: its poster frame is
|
|
711
|
+
save.push(
|
|
712
|
+
im.kind === "video" ? (out.poster ? { url: out.poster } : null) : { url: best.url },
|
|
713
|
+
);
|
|
714
|
+
}
|
|
715
|
+
if (best.w != null) out.srcW = best.w;
|
|
716
|
+
if (candidates.length > 1) out.sources = candidates.length;
|
|
717
|
+
if (current && current !== best.url && !/^data:/i.test(current)) out.shown = current;
|
|
718
|
+
} else save.push(markup ? { markup } : out.poster ? { url: out.poster } : null);
|
|
719
|
+
// a blob: or the like that names nothing to fetch
|
|
720
|
+
if (!best && current && !/^(data|blob):/i.test(current)) out.shown = current;
|
|
721
|
+
return out;
|
|
722
|
+
});
|
|
723
|
+
const file: MaterialsFile = {
|
|
724
|
+
version: 1,
|
|
725
|
+
state: o.state,
|
|
726
|
+
read: o.read,
|
|
727
|
+
url: res.url,
|
|
728
|
+
title: res.title,
|
|
729
|
+
viewport: res.viewport,
|
|
730
|
+
page: res.page,
|
|
731
|
+
medianTextPx: res.medianTextPx,
|
|
732
|
+
meta: res.meta,
|
|
733
|
+
images,
|
|
734
|
+
copy: res.copy,
|
|
735
|
+
...(res.links ? { links: res.links } : {}),
|
|
736
|
+
skipped: res.skipped,
|
|
737
|
+
scope: materialsScope(o.read),
|
|
738
|
+
ms: { read: res.ms },
|
|
739
|
+
};
|
|
740
|
+
return { file, save };
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
export function materialsScope(read: MaterialsFile["read"]): string {
|
|
744
|
+
return (
|
|
745
|
+
`the whole page, top to bottom, ${read === "live" ? "read in the product's page as it was shot" : "read in its saved screen (state.html: sources are the saved files)"}: ` +
|
|
746
|
+
`<img>/<picture> (largest source), inline <svg> of ${MATERIAL_MIN_SVG_AREA} px² or more, CSS background images, <video>, <canvas>; ` +
|
|
747
|
+
`headings, paragraphs, list items, quotes, captions, and text set ≥ 1.25× the body size; ` +
|
|
748
|
+
`the other pages it links to (one per address, its own site or not); ` +
|
|
749
|
+
`not read: iframes, shadow roots, ::before/::after, text inside links and buttons (headings aside), aria-hidden copies. ` +
|
|
750
|
+
`Nothing is ranked: every list is in page order`
|
|
751
|
+
);
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
/** One page's materials.json, where a source's saved screens hold one. */
|
|
755
|
+
export type MaterialsPage = { id: string; dir: string; file: MaterialsFile; path: string };
|
|
756
|
+
|
|
757
|
+
/** The materials.json files of a source's saved screens (one per page the
|
|
758
|
+
* shoot visited — the first screen kept on each), in shooting order, and
|
|
759
|
+
* the screens of pages none of them covers (to read from their state.html). */
|
|
760
|
+
export function readMaterials(source: ComponentSource): {
|
|
761
|
+
pages: MaterialsPage[];
|
|
762
|
+
/** one screen per page URL that has no materials.json */
|
|
763
|
+
missing: { id: string; dir: string; url: string }[];
|
|
764
|
+
} {
|
|
765
|
+
const pages: MaterialsPage[] = [];
|
|
766
|
+
const missing: { id: string; dir: string; url: string }[] = [];
|
|
767
|
+
const covered = new Set<string>();
|
|
768
|
+
const urlOf = (dir: string): string => {
|
|
769
|
+
try {
|
|
770
|
+
const ix = JSON.parse(readFileSync(join(dir, "index.json"), "utf8")) as { url?: string };
|
|
771
|
+
return pageKey(ix.url ?? "");
|
|
772
|
+
} catch {
|
|
773
|
+
return "";
|
|
774
|
+
}
|
|
775
|
+
};
|
|
776
|
+
for (const s of source.states) {
|
|
777
|
+
const path = join(s.dir, "materials.json");
|
|
778
|
+
if (!existsSync(path)) continue;
|
|
779
|
+
try {
|
|
780
|
+
const file = JSON.parse(readFileSync(path, "utf8")) as MaterialsFile;
|
|
781
|
+
if (file.version !== 1 || !Array.isArray(file.images) || !Array.isArray(file.copy)) continue;
|
|
782
|
+
pages.push({ id: s.id, dir: s.dir, file, path });
|
|
783
|
+
covered.add(pageKey(file.url));
|
|
784
|
+
} catch {
|
|
785
|
+
/* unreadable: read again below */
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
for (const s of source.states) {
|
|
789
|
+
const url = urlOf(s.dir);
|
|
790
|
+
if (covered.has(url)) continue;
|
|
791
|
+
covered.add(url);
|
|
792
|
+
missing.push({ id: s.id, dir: s.dir, url });
|
|
793
|
+
}
|
|
794
|
+
return { pages, missing };
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
/** A page's identity: its URL without the fragment. */
|
|
798
|
+
export const pageKey = (url: string): string => url.replace(/#.*$/, "");
|
|
799
|
+
|
|
800
|
+
// --- printing ----------------------------------------------------------------------
|
|
801
|
+
|
|
802
|
+
const cut = (s: string, n: number) => (s.length > n ? `${s.slice(0, n - 1)}…` : s);
|
|
803
|
+
const q = (s: string) => JSON.stringify(s);
|
|
804
|
+
const screens = (f: MaterialsFile) => Math.round((f.page.h / Math.max(1, f.viewport.h)) * 10) / 10;
|
|
805
|
+
|
|
806
|
+
const sizeText = (im: MaterialImage): string => {
|
|
807
|
+
const px = im.fileSize ?? im.natural;
|
|
808
|
+
const drawn = `${im.box[2]}×${im.box[3]}`;
|
|
809
|
+
if (px)
|
|
810
|
+
return `${px[0]}×${px[1]}${px[0] !== im.box[2] || px[1] !== im.box[3] ? ` (drawn ${drawn})` : ""}`;
|
|
811
|
+
if (im.srcW) return `${im.srcW}w (drawn ${drawn})`;
|
|
812
|
+
return `drawn ${drawn}`;
|
|
813
|
+
};
|
|
814
|
+
|
|
815
|
+
const wordOf = (im: MaterialImage): string =>
|
|
816
|
+
im.alt
|
|
817
|
+
? q(cut(im.alt, 60))
|
|
818
|
+
: im.alt === ""
|
|
819
|
+
? "(alt empty)"
|
|
820
|
+
: im.name
|
|
821
|
+
? q(cut(im.name, 60))
|
|
822
|
+
: "(no alt)";
|
|
823
|
+
|
|
824
|
+
/** where it is: its saved copy, else its URL */
|
|
825
|
+
const whereOf = (im: MaterialImage, dir: string, show: (abs: string) => string): string =>
|
|
826
|
+
im.file
|
|
827
|
+
? show(join(dir, im.file))
|
|
828
|
+
: im.src && !/^data:/.test(im.src)
|
|
829
|
+
? cut(im.src, 90)
|
|
830
|
+
: (im.notSaved ?? "");
|
|
831
|
+
|
|
832
|
+
/** a copy line's note on how it stands on the page */
|
|
833
|
+
const standing = (x: { fixed?: true; in?: string; hidden?: string }): string =>
|
|
834
|
+
[x.in ? `in ${x.in}` : "", x.fixed ? "fixed" : "", x.hidden ?? ""].filter(Boolean).join(", ");
|
|
835
|
+
|
|
836
|
+
export function imageLine(im: MaterialImage, dir: string, show: (abs: string) => string): string {
|
|
837
|
+
const s = standing(im);
|
|
838
|
+
return `y ${String(im.box[1]).padStart(5)} ${im.kind.padEnd(10)} ${sizeText(im)} ${wordOf(im)} ${whereOf(im, dir, show)}${s ? ` (${s})` : ""}`;
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
export function copyLine(t: MaterialText, max = 120): string {
|
|
842
|
+
const s = standing(t);
|
|
843
|
+
return `y ${String(t.box[1]).padStart(5)} ${t.tag.padEnd(10)} ${t.fontPx}px ${q(cut(t.text, max))}${t.chars ? ` (${t.chars} chars)` : ""}${s ? ` (${s})` : ""}`;
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
/** headings and type set larger than the body: what the summary shows of the copy */
|
|
847
|
+
const display = (t: MaterialText, f: MaterialsFile) =>
|
|
848
|
+
t.level != null || t.fontPx >= 1.25 * f.medianTextPx;
|
|
849
|
+
|
|
850
|
+
/**
|
|
851
|
+
* The few lines a shoot and `film init --url` print: per page its size and
|
|
852
|
+
* counts, then — for the first page — its first images in the first screen
|
|
853
|
+
* and below it, and its first headings / large type below the first screen,
|
|
854
|
+
* each in page order, and where the whole list and the sheet are. Counts
|
|
855
|
+
* and positions only; nothing is ranked or recommended.
|
|
856
|
+
*/
|
|
857
|
+
export function materialsSummary(
|
|
858
|
+
pages: readonly MaterialsPage[],
|
|
859
|
+
o: { show: (abs: string) => string; cmd: string },
|
|
860
|
+
): string[] {
|
|
861
|
+
if (!pages.length) return [];
|
|
862
|
+
const lines: string[] = [];
|
|
863
|
+
const [first, ...rest] = pages;
|
|
864
|
+
const head = (p: MaterialsPage) => {
|
|
865
|
+
const f = p.file;
|
|
866
|
+
const below = f.images.filter((i) => !i.firstScreen).length;
|
|
867
|
+
const belowT = f.copy.filter((t) => !t.firstScreen).length;
|
|
868
|
+
const saved = f.images.filter((i) => i.file).length;
|
|
869
|
+
return (
|
|
870
|
+
`${p.id} (${cut(f.url, 60)}) — ${f.page.h} px tall, ${screens(f)} screens: ` +
|
|
871
|
+
`${f.images.length} image${f.images.length === 1 ? "" : "s"} (${below} below the first screen, ${saved} saved), ` +
|
|
872
|
+
`${f.copy.length} text${f.copy.length === 1 ? "" : "s"} (${belowT} below)`
|
|
873
|
+
);
|
|
874
|
+
};
|
|
875
|
+
lines.push(`material, whole page: ${head(first!)}`);
|
|
876
|
+
const f = first!.file;
|
|
877
|
+
const top = f.images.filter((i) => i.firstScreen).slice(0, 2);
|
|
878
|
+
const low = f.images.filter((i) => !i.firstScreen).slice(0, 5 - top.length);
|
|
879
|
+
for (const im of [...top, ...low]) lines.push(` ${imageLine(im, first!.dir, o.show)}`);
|
|
880
|
+
const texts = f.copy.filter((t) => !t.firstScreen && display(t, f)).slice(0, 3);
|
|
881
|
+
for (const t of texts) lines.push(` ${copyLine(t, 70)}`);
|
|
882
|
+
const links = linksLine(f);
|
|
883
|
+
if (links) lines.push(` ${links}`);
|
|
884
|
+
for (const p of rest.slice(0, 2)) lines.push(` + ${head(p)}`);
|
|
885
|
+
if (rest.length > 2)
|
|
886
|
+
lines.push(` + ${rest.length - 2} more page${rest.length - 2 === 1 ? "" : "s"}`);
|
|
887
|
+
const sheet = f.sheet
|
|
888
|
+
? `; the page as one picture: ${o.show(join(first!.dir, f.sheet.file))}`
|
|
889
|
+
: "";
|
|
890
|
+
lines.push(
|
|
891
|
+
` all of it in page order: ${o.cmd} (${o.show(first!.path)}${pages.length > 1 ? ", one per page" : ""})${sheet}`,
|
|
892
|
+
);
|
|
893
|
+
return lines;
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
/** The pages a film can read the product from, as the page's links name
|
|
897
|
+
* them: its navigation, header and footer first, its own site before
|
|
898
|
+
* others, a few words each. Null when it links nowhere. */
|
|
899
|
+
export function linksLine(f: MaterialsFile, max = 10): string | null {
|
|
900
|
+
const all = f.links ?? [];
|
|
901
|
+
if (!all.length) return null;
|
|
902
|
+
const rank = (l: MaterialLink) =>
|
|
903
|
+
(l.in === "nav" || l.in === "header" ? 0 : l.in === "footer" ? 1 : 2) + (l.own ? 0 : 0.5);
|
|
904
|
+
const seen = new Set<string>();
|
|
905
|
+
const distinct = [...all]
|
|
906
|
+
.sort((a, b) => rank(a) - rank(b))
|
|
907
|
+
.filter((l) => {
|
|
908
|
+
const k = l.text.toLowerCase();
|
|
909
|
+
if (seen.has(k)) return false;
|
|
910
|
+
seen.add(k);
|
|
911
|
+
return true;
|
|
912
|
+
});
|
|
913
|
+
const shown = distinct.slice(0, max).map((l) => `${cut(l.text, 28)}${l.own ? "" : " ↗"}`);
|
|
914
|
+
return `links (${all.length}, pages a film can read the product from): ${shown.join(" · ")}${distinct.length > shown.length ? " · …" : ""} — each with its address in materials.json (links[])`;
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
/** The whole list, as `open-take materials` prints it: per page, images
|
|
918
|
+
* and copy interleaved in page order. */
|
|
919
|
+
export function formatMaterials(
|
|
920
|
+
pages: readonly MaterialsPage[],
|
|
921
|
+
o: { show: (abs: string) => string },
|
|
922
|
+
): string {
|
|
923
|
+
const out: string[] = [];
|
|
924
|
+
for (const p of pages) {
|
|
925
|
+
const f = p.file;
|
|
926
|
+
out.push(
|
|
927
|
+
`${p.id}: ${f.url} — ${f.title ? `${q(f.title)}, ` : ""}page ${f.page.w}×${f.page.h} (${screens(f)} screens of ${f.viewport.w}×${f.viewport.h}); read ${f.read === "live" ? "live" : "from the saved screen"}`,
|
|
928
|
+
);
|
|
929
|
+
out.push(` list: ${o.show(p.path)}`);
|
|
930
|
+
if (f.sheet)
|
|
931
|
+
out.push(
|
|
932
|
+
` sheet: ${o.show(join(p.dir, f.sheet.file))} — ${f.sheet.columns} column${f.sheet.columns === 1 ? "" : "s"} of ${f.sheet.columnPx} page px, ${f.sheet.coveredPx < f.page.h ? `the first ${f.sheet.coveredPx} px` : "the whole page"}`,
|
|
933
|
+
);
|
|
934
|
+
const m = f.meta;
|
|
935
|
+
if (m.description) out.push(` description: ${q(m.description)}`);
|
|
936
|
+
if (m.ogTitle) out.push(` og:title: ${q(m.ogTitle)}`);
|
|
937
|
+
if (m.ogImage)
|
|
938
|
+
out.push(` og:image: ${m.ogImageFile ? o.show(join(p.dir, m.ogImageFile)) : m.ogImage}`);
|
|
939
|
+
const items: { y: number; x: number; line: string }[] = [
|
|
940
|
+
...f.images.map((im) => ({ y: im.box[1], x: im.box[0], line: imageLine(im, p.dir, o.show) })),
|
|
941
|
+
...f.copy.map((t) => ({ y: t.box[1], x: t.box[0], line: copyLine(t) })),
|
|
942
|
+
].sort((a, b) => a.y - b.y || a.x - b.x);
|
|
943
|
+
let fold = false;
|
|
944
|
+
for (const it of items) {
|
|
945
|
+
if (!fold && it.y >= f.viewport.h) {
|
|
946
|
+
out.push(` ── the first screen ends (y ${f.viewport.h}) ──`);
|
|
947
|
+
fold = true;
|
|
948
|
+
}
|
|
949
|
+
out.push(` ${it.line}`);
|
|
950
|
+
}
|
|
951
|
+
if (f.links?.length) {
|
|
952
|
+
out.push(` links, in page order (${f.links.length}):`);
|
|
953
|
+
for (const l of f.links)
|
|
954
|
+
out.push(
|
|
955
|
+
` ${q(cut(l.text, 60))} → ${l.href}${l.own ? "" : " (another site)"}${l.in ? ` [${l.in}]` : ""}`,
|
|
956
|
+
);
|
|
957
|
+
}
|
|
958
|
+
const sk = f.skipped;
|
|
959
|
+
const counted = (
|
|
960
|
+
[
|
|
961
|
+
[sk.hidden, "drawn at no size"],
|
|
962
|
+
[sk.small, `smaller than ${MATERIAL_MIN_IMAGE_PX} px`],
|
|
963
|
+
[sk.icons, "svg icons"],
|
|
964
|
+
[sk.ariaHidden, "aria-hidden copies"],
|
|
965
|
+
[sk.frames, "iframes (not read)"],
|
|
966
|
+
[sk.more, "past the list's length"],
|
|
967
|
+
] as const
|
|
968
|
+
)
|
|
969
|
+
.filter(([n]) => n > 0)
|
|
970
|
+
.map(([n, w]) => `${n} ${w}`);
|
|
971
|
+
if (counted.length) out.push(` not listed: ${counted.join(", ")}`);
|
|
972
|
+
out.push(` read: ${f.scope}`);
|
|
973
|
+
out.push("");
|
|
974
|
+
}
|
|
975
|
+
return out.join("\n").trimEnd();
|
|
976
|
+
}
|