@sixb/core 0.2.6 → 0.2.8
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/actions/index.js +53 -50
- package/dist/actions/index.js.map +1 -1
- package/dist/actions/request.d.ts.map +1 -1
- package/dist/actions/run/context.d.ts.map +1 -1
- package/dist/actions/run/execute.d.ts +3 -0
- package/dist/actions/run/execute.d.ts.map +1 -1
- package/dist/actions/run/executor.d.ts +3 -0
- package/dist/actions/run/executor.d.ts.map +1 -1
- package/dist/actions/run/normalize.d.ts.map +1 -1
- package/dist/actions/run/types.d.ts +6 -0
- package/dist/actions/run/types.d.ts.map +1 -1
- package/dist/actions/types/context.d.ts +7 -0
- package/dist/actions/types/context.d.ts.map +1 -1
- package/dist/agents/context/entries.d.ts +17 -0
- package/dist/agents/context/entries.d.ts.map +1 -1
- package/dist/agents/context/index.js +3 -2
- package/dist/agents/context/index.js.map +1 -1
- package/dist/agents/context-model.d.ts.map +1 -1
- package/dist/agents/context-resolution.d.ts.map +1 -1
- package/dist/agents/execution.d.ts +7 -0
- package/dist/agents/execution.d.ts.map +1 -1
- package/dist/agents/index.d.ts +1 -1
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +62 -57
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/model-call-retry.d.ts +28 -0
- package/dist/agents/model-call-retry.d.ts.map +1 -0
- package/dist/agents/model-loop.d.ts +4 -2
- package/dist/agents/model-loop.d.ts.map +1 -1
- package/dist/agents/model-routing.d.ts +15 -4
- package/dist/agents/model-routing.d.ts.map +1 -1
- package/dist/agents/request.d.ts.map +1 -1
- package/dist/agents/run-artifacts.d.ts +2 -0
- package/dist/agents/run-artifacts.d.ts.map +1 -1
- package/dist/agents/run-plan.d.ts +1 -1
- package/dist/agents/run-plan.d.ts.map +1 -1
- package/dist/agents/run-session-http.d.ts.map +1 -1
- package/dist/agents/run-session-serve.d.ts.map +1 -1
- package/dist/agents/run-session-wire.d.ts +6 -0
- package/dist/agents/run-session-wire.d.ts.map +1 -1
- package/dist/agents/run-token.d.ts +6 -0
- package/dist/agents/run-token.d.ts.map +1 -1
- package/dist/agents/streams/index.js +1 -1
- package/dist/agents/streams/internal.js +2 -2
- package/dist/agents/thread-access.d.ts +13 -0
- package/dist/agents/thread-access.d.ts.map +1 -1
- package/dist/agents/tool-files.d.ts.map +1 -1
- package/dist/artifacts/caller.d.ts +10 -0
- package/dist/artifacts/caller.d.ts.map +1 -0
- package/dist/artifacts/comment-place.d.ts +26 -0
- package/dist/artifacts/comment-place.d.ts.map +1 -0
- package/dist/artifacts/comment-text.d.ts +12 -4
- package/dist/artifacts/comment-text.d.ts.map +1 -1
- package/dist/artifacts/comments.d.ts +8 -2
- package/dist/artifacts/comments.d.ts.map +1 -1
- package/dist/artifacts/errors.d.ts +1 -1
- package/dist/artifacts/errors.d.ts.map +1 -1
- package/dist/artifacts/execution.d.ts +73 -5
- package/dist/artifacts/execution.d.ts.map +1 -1
- package/dist/artifacts/frames/assets.d.ts +27 -7
- package/dist/artifacts/frames/assets.d.ts.map +1 -1
- package/dist/artifacts/frames/entries.d.ts +5 -4
- package/dist/artifacts/frames/entries.d.ts.map +1 -1
- package/dist/artifacts/frames/hyperframes.d.ts +12 -0
- package/dist/artifacts/frames/hyperframes.d.ts.map +1 -0
- package/dist/artifacts/frames/index.d.ts +3 -1
- package/dist/artifacts/frames/index.d.ts.map +1 -1
- package/dist/artifacts/frames/index.js +20 -6
- package/dist/artifacts/frames/index.js.map +3 -3
- package/dist/artifacts/frames/kit.d.ts.map +1 -1
- package/dist/artifacts/frames/protocol.d.ts +33 -0
- package/dist/artifacts/frames/protocol.d.ts.map +1 -1
- package/dist/artifacts/frames/video-runtime.d.ts +21 -0
- package/dist/artifacts/frames/video-runtime.d.ts.map +1 -0
- package/dist/artifacts/html.d.ts +23 -0
- package/dist/artifacts/html.d.ts.map +1 -1
- package/dist/artifacts/index.d.ts +5 -3
- package/dist/artifacts/index.d.ts.map +1 -1
- package/dist/artifacts/index.js +71 -10
- package/dist/artifacts/index.js.map +4 -4
- package/dist/artifacts/kinds.d.ts +1 -1
- package/dist/artifacts/kinds.d.ts.map +1 -1
- package/dist/artifacts/limits.d.ts +37 -0
- package/dist/artifacts/limits.d.ts.map +1 -1
- package/dist/artifacts/live/document.d.ts.map +1 -1
- package/dist/artifacts/live/index.d.ts +6 -2
- package/dist/artifacts/live/index.d.ts.map +1 -1
- package/dist/artifacts/live/index.js +3432 -13
- package/dist/artifacts/live/index.js.map +6 -3
- package/dist/artifacts/live/presence.d.ts +7 -5
- package/dist/artifacts/live/presence.d.ts.map +1 -1
- package/dist/artifacts/live/protocol.d.ts +4 -2
- package/dist/artifacts/live/protocol.d.ts.map +1 -1
- package/dist/artifacts/live/server.d.ts +1 -1
- package/dist/artifacts/live/server.d.ts.map +1 -1
- package/dist/artifacts/live/server.js +36 -31
- package/dist/artifacts/live/server.js.map +1 -1
- package/dist/artifacts/live/state.d.ts +2 -2
- package/dist/artifacts/media/media.d.ts +96 -0
- package/dist/artifacts/media/media.d.ts.map +1 -0
- package/dist/artifacts/media/transcriber.d.ts +29 -0
- package/dist/artifacts/media/transcriber.d.ts.map +1 -0
- package/dist/artifacts/outline.d.ts +26 -1
- package/dist/artifacts/outline.d.ts.map +1 -1
- package/dist/artifacts/publish/files.d.ts +5 -2
- package/dist/artifacts/publish/files.d.ts.map +1 -1
- package/dist/artifacts/publish/index.d.ts +11 -2
- package/dist/artifacts/publish/index.d.ts.map +1 -1
- package/dist/artifacts/publish/index.js +110 -33
- package/dist/artifacts/publish/index.js.map +1 -1
- package/dist/artifacts/publish/pdf.d.ts.map +1 -1
- package/dist/artifacts/publish/previews.d.ts +7 -2
- package/dist/artifacts/publish/previews.d.ts.map +1 -1
- package/dist/artifacts/publish/publish.d.ts.map +1 -1
- package/dist/artifacts/publish/validate/html.d.ts +5 -4
- package/dist/artifacts/publish/validate/html.d.ts.map +1 -1
- package/dist/artifacts/publish/validate/video.d.ts +36 -0
- package/dist/artifacts/publish/validate/video.d.ts.map +1 -0
- package/dist/artifacts/publish/video.d.ts +79 -0
- package/dist/artifacts/publish/video.d.ts.map +1 -0
- package/dist/artifacts/resolve.d.ts +9 -0
- package/dist/artifacts/resolve.d.ts.map +1 -1
- package/dist/artifacts/video/composition.d.ts +183 -0
- package/dist/artifacts/video/composition.d.ts.map +1 -0
- package/dist/artifacts/video/edit.d.ts +298 -0
- package/dist/artifacts/video/edit.d.ts.map +1 -0
- package/dist/artifacts/video/export.d.ts +142 -0
- package/dist/artifacts/video/export.d.ts.map +1 -0
- package/dist/artifacts/video/looks.d.ts +133 -0
- package/dist/artifacts/video/looks.d.ts.map +1 -0
- package/dist/artifacts/video/project.d.ts +74 -0
- package/dist/artifacts/video/project.d.ts.map +1 -0
- package/dist/artifacts/video/stills.d.ts +65 -0
- package/dist/artifacts/video/stills.d.ts.map +1 -0
- package/dist/artifacts/video/timeline.d.ts +153 -0
- package/dist/artifacts/video/timeline.d.ts.map +1 -0
- package/dist/auth/index.js +9 -8
- package/dist/auth/index.js.map +1 -1
- package/dist/authorization/index.js +5 -4
- package/dist/authorization/index.js.map +1 -1
- package/dist/blob-storage/browser.d.ts +1 -1
- package/dist/blob-storage/browser.d.ts.map +1 -1
- package/dist/blob-storage/browser.js +8 -4
- package/dist/blob-storage/browser.js.map +1 -1
- package/dist/blob-storage/constants.d.ts +8 -3
- package/dist/blob-storage/constants.d.ts.map +1 -1
- package/dist/blob-storage/download-urls.d.ts +2 -2
- package/dist/blob-storage/download-urls.d.ts.map +1 -1
- package/dist/blob-storage/index.d.ts +1 -1
- package/dist/blob-storage/index.d.ts.map +1 -1
- package/dist/blob-storage/index.js +9 -5
- package/dist/blob-storage/index.js.map +1 -1
- package/dist/blob-storage/internal.d.ts +2 -2
- package/dist/blob-storage/internal.d.ts.map +1 -1
- package/dist/blob-storage/internal.js +10 -4
- package/dist/blob-storage/internal.js.map +1 -1
- package/dist/blob-storage/media-type.d.ts +12 -3
- package/dist/blob-storage/media-type.d.ts.map +1 -1
- package/dist/bootstrap/discovery.d.ts +6 -0
- package/dist/bootstrap/discovery.d.ts.map +1 -1
- package/dist/bootstrap/index.js +63 -60
- package/dist/bootstrap/index.js.map +2 -2
- package/dist/{chunk-az95tsh3.js → chunk-0fjryajn.js} +3 -2
- package/dist/chunk-0fjryajn.js.map +11 -0
- package/dist/{chunk-9tpmfh3n.js → chunk-0mk8qqp9.js} +3 -3
- package/dist/{chunk-9tpmfh3n.js.map → chunk-0mk8qqp9.js.map} +3 -3
- package/dist/{chunk-88xeh6zx.js → chunk-1g4me5f2.js} +182 -7
- package/dist/{chunk-88xeh6zx.js.map → chunk-1g4me5f2.js.map} +3 -3
- package/dist/{chunk-7mhbs9yy.js → chunk-1z8ccj53.js} +1 -1
- package/dist/{chunk-wkv3h3q7.js → chunk-2138b0ng.js} +115 -8
- package/dist/chunk-2138b0ng.js.map +12 -0
- package/dist/chunk-23eaayw4.js +3757 -0
- package/dist/chunk-23eaayw4.js.map +22 -0
- package/dist/{chunk-s8xxef60.js → chunk-2mxq1yd9.js} +48 -41
- package/dist/{chunk-s8xxef60.js.map → chunk-2mxq1yd9.js.map} +6 -6
- package/dist/{chunk-dmnd9ea6.js → chunk-30a0ftnm.js} +2 -2
- package/dist/{chunk-nxysqbt0.js → chunk-389ybvw9.js} +6 -2
- package/dist/chunk-389ybvw9.js.map +10 -0
- package/dist/{chunk-qbd282aa.js → chunk-39q9ybav.js} +2 -2
- package/dist/{chunk-9c9yknwt.js → chunk-3d9w8t4n.js} +111 -23
- package/dist/{chunk-9c9yknwt.js.map → chunk-3d9w8t4n.js.map} +5 -5
- package/dist/chunk-3dvcdn9w.js +8 -0
- package/dist/chunk-3dvcdn9w.js.map +10 -0
- package/dist/{chunk-bcz9dxtf.js → chunk-3x902cja.js} +3 -3
- package/dist/{chunk-c4nrycdy.js → chunk-4q4a5a96.js} +1 -1
- package/dist/{chunk-7r9mqpva.js → chunk-4tdm3fsj.js} +100 -36
- package/dist/{chunk-7r9mqpva.js.map → chunk-4tdm3fsj.js.map} +10 -10
- package/dist/{chunk-ykchk644.js → chunk-4w8qzy9w.js} +6 -6
- package/dist/{chunk-c29729me.js → chunk-4z9xtxke.js} +8 -7
- package/dist/chunk-4z9xtxke.js.map +12 -0
- package/dist/chunk-5278qwax.js +270 -0
- package/dist/chunk-5278qwax.js.map +11 -0
- package/dist/{chunk-kft7mp7z.js → chunk-5xkqasvn.js} +1 -1
- package/dist/{chunk-k1g14kk3.js → chunk-6a4hp405.js} +4 -5
- package/dist/{chunk-k1g14kk3.js.map → chunk-6a4hp405.js.map} +3 -3
- package/dist/{chunk-xavet0qs.js → chunk-6whr25gw.js} +2 -2
- package/dist/{chunk-mbwsgjn7.js → chunk-7zygtcqq.js} +14 -2
- package/dist/chunk-7zygtcqq.js.map +11 -0
- package/dist/chunk-88s9z5pf.js +3 -0
- package/dist/{chunk-de5sfbc3.js.map → chunk-88s9z5pf.js.map} +1 -1
- package/dist/{chunk-ygvay56w.js → chunk-896te58g.js} +2 -2
- package/dist/{chunk-pqj8vff9.js → chunk-8eqqqc1h.js} +3 -3
- package/dist/{chunk-425ydk65.js → chunk-8tefbhdx.js} +14 -14
- package/dist/{chunk-425ydk65.js.map → chunk-8tefbhdx.js.map} +1 -1
- package/dist/{chunk-jka26v8c.js → chunk-8x1bsp68.js} +1 -1
- package/dist/{chunk-wzcjhv54.js → chunk-93e4w7te.js} +113 -1
- package/dist/chunk-93e4w7te.js.map +11 -0
- package/dist/{chunk-ym1bqd98.js → chunk-990a5bkc.js} +424 -76
- package/dist/chunk-990a5bkc.js.map +21 -0
- package/dist/{chunk-fmgf9h5e.js → chunk-9az7kjv4.js} +6 -6
- package/dist/{chunk-eg6xqef7.js → chunk-9e5t53z0.js} +3 -3
- package/dist/{chunk-eg6xqef7.js.map → chunk-9e5t53z0.js.map} +3 -3
- package/dist/{chunk-bs1sd0e0.js → chunk-9p7kyeqz.js} +4 -4
- package/dist/chunk-a68zz4r0.js +537 -0
- package/dist/chunk-a68zz4r0.js.map +11 -0
- package/dist/{chunk-d7vyc7k6.js → chunk-a700gjc8.js} +10 -2
- package/dist/chunk-a700gjc8.js.map +10 -0
- package/dist/{chunk-gfdh9kqa.js → chunk-a9qzjaz2.js} +2 -5
- package/dist/chunk-a9qzjaz2.js.map +10 -0
- package/dist/{chunk-ats8y3d9.js → chunk-as94vcty.js} +688 -504
- package/dist/{chunk-ats8y3d9.js.map → chunk-as94vcty.js.map} +21 -21
- package/dist/{chunk-brybqw5k.js → chunk-bkxm2dzx.js} +1 -1
- package/dist/{chunk-ppxf7gw2.js → chunk-d7t9jnym.js} +3 -3
- package/dist/{chunk-tapdssb5.js → chunk-e3b1r4d2.js} +8 -7
- package/dist/{chunk-tapdssb5.js.map → chunk-e3b1r4d2.js.map} +4 -4
- package/dist/{chunk-cg7cygfj.js → chunk-fdmvaz7x.js} +1 -1
- package/dist/{chunk-191jz8a6.js → chunk-ff0qdk7z.js} +1 -1
- package/dist/{chunk-9vsc919v.js → chunk-fgxvrxx4.js} +22 -2
- package/dist/chunk-fgxvrxx4.js.map +10 -0
- package/dist/{chunk-wx7smkn2.js → chunk-fq8drkp0.js} +1 -1
- package/dist/{chunk-60662fyv.js → chunk-fqms1a8c.js} +132 -4
- package/dist/{chunk-60662fyv.js.map → chunk-fqms1a8c.js.map} +8 -6
- package/dist/{chunk-v8a1qjzp.js → chunk-hpswfrjj.js} +1 -1
- package/dist/{chunk-qttqe1ah.js → chunk-jbg905hn.js} +80 -13
- package/dist/chunk-jbg905hn.js.map +25 -0
- package/dist/{chunk-bz5bnjjt.js → chunk-jjte0h4p.js} +1 -1
- package/dist/{chunk-jt012fxq.js → chunk-jwjwvzj1.js} +797 -51
- package/dist/chunk-jwjwvzj1.js.map +38 -0
- package/dist/{chunk-f05994as.js → chunk-k3vd2vyz.js} +6 -2
- package/dist/chunk-k3vd2vyz.js.map +10 -0
- package/dist/chunk-kcqpk9w1.js.map +2 -2
- package/dist/chunk-mvz89age.js.map +2 -2
- package/dist/{chunk-xrmbhap8.js → chunk-mwg0nwkb.js} +1 -1
- package/dist/{chunk-a3faa34j.js → chunk-nfjt8k8j.js} +1 -1
- package/dist/{chunk-394zjzjs.js → chunk-nhgqz3g3.js} +3 -3
- package/dist/{chunk-bqr703h4.js → chunk-p0c5kkhn.js} +23 -6
- package/dist/{chunk-bqr703h4.js.map → chunk-p0c5kkhn.js.map} +3 -3
- package/dist/{chunk-92wrka15.js → chunk-q150fnj9.js} +1 -1
- package/dist/{chunk-w3t94hm6.js → chunk-qk3zq25v.js} +1 -1
- package/dist/{chunk-6hfbz4d0.js → chunk-r588h4ev.js} +1 -1
- package/dist/chunk-rtkqczbr.js.map +2 -2
- package/dist/{chunk-3qtk0070.js → chunk-ssqbrts1.js} +86 -9
- package/dist/chunk-ssqbrts1.js.map +14 -0
- package/dist/{chunk-5qqmndhm.js → chunk-szzhrn3e.js} +1 -1
- package/dist/{chunk-n1hbwc6y.js → chunk-t6pfch4e.js} +1 -1
- package/dist/{chunk-xtztwpkh.js → chunk-v6h4tc2v.js} +86 -5
- package/dist/chunk-v6h4tc2v.js.map +12 -0
- package/dist/{chunk-brhp9d97.js → chunk-vmqjndb3.js} +2 -2
- package/dist/chunk-vtjzwymr.js.map +2 -2
- package/dist/{chunk-t19wjmnc.js → chunk-wpba6hhd.js} +54 -20
- package/dist/{chunk-t19wjmnc.js.map → chunk-wpba6hhd.js.map} +3 -3
- package/dist/{chunk-htdzx40w.js → chunk-wrb1x1ss.js} +12 -4
- package/dist/{chunk-htdzx40w.js.map → chunk-wrb1x1ss.js.map} +3 -3
- package/dist/{chunk-5sswe5ej.js → chunk-wsv23wvr.js} +2 -2
- package/dist/{chunk-90nqenq8.js → chunk-x0hqc54n.js} +4 -4
- package/dist/{chunk-sgx82nnt.js → chunk-xg31er4p.js} +43 -4
- package/dist/chunk-xg31er4p.js.map +10 -0
- package/dist/{chunk-3neam1y5.js → chunk-y3qb965a.js} +2 -2
- package/dist/{chunk-gaj8djsw.js → chunk-y57eawng.js} +10 -5
- package/dist/{chunk-gaj8djsw.js.map → chunk-y57eawng.js.map} +3 -3
- package/dist/{chunk-8ncg20rd.js → chunk-yah25st6.js} +5 -5
- package/dist/chunk-yah25st6.js.map +10 -0
- package/dist/{chunk-grt2j5vp.js → chunk-ywvxcmqj.js} +106 -13
- package/dist/{chunk-grt2j5vp.js.map → chunk-ywvxcmqj.js.map} +8 -7
- package/dist/{chunk-xf76csps.js → chunk-zmq9xc9s.js} +70 -31
- package/dist/{chunk-xf76csps.js.map → chunk-zmq9xc9s.js.map} +4 -3
- package/dist/datasets/write.js +8 -7
- package/dist/datasets/write.js.map +1 -1
- package/dist/deploy/index.d.ts +1 -1
- package/dist/deploy/index.d.ts.map +1 -1
- package/dist/deploy/internal.js +2 -2
- package/dist/deploy/internal.js.map +2 -2
- package/dist/deploy/types.d.ts +8 -58
- package/dist/deploy/types.d.ts.map +1 -1
- package/dist/env/index.d.ts +10 -3
- package/dist/env/index.d.ts.map +1 -1
- package/dist/env/index.js.map +2 -2
- package/dist/errors/catalog.d.ts.map +1 -1
- package/dist/execution/agent.js +53 -50
- package/dist/execution/agent.js.map +1 -1
- package/dist/execution/kernel-operation.d.ts +1 -0
- package/dist/execution/kernel-operation.d.ts.map +1 -1
- package/dist/execution/primitive.js +53 -50
- package/dist/execution/primitive.js.map +1 -1
- package/dist/execution/request.js +54 -51
- package/dist/execution/request.js.map +2 -2
- package/dist/execution/types.d.ts +5 -0
- package/dist/execution/types.d.ts.map +1 -1
- package/dist/http/api-routes.d.ts.map +1 -1
- package/dist/http/index.js +1 -1
- package/dist/index.d.ts +7 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +73 -67
- package/dist/index.js.map +1 -1
- package/dist/lake-storage/index.js +9 -8
- package/dist/lake-storage/index.js.map +1 -1
- package/dist/maintenance/index.js +9 -8
- package/dist/maintenance/index.js.map +2 -2
- package/dist/materializer/index.js +26 -24
- package/dist/materializer/index.js.map +1 -1
- package/dist/models/audio/runtime.d.ts +3 -1
- package/dist/models/audio/runtime.d.ts.map +1 -1
- package/dist/models/audio/speech.d.ts +2 -2
- package/dist/models/audio/speech.d.ts.map +1 -1
- package/dist/models/audio/types.d.ts +23 -3
- package/dist/models/audio/types.d.ts.map +1 -1
- package/dist/models/calls.d.ts +7 -0
- package/dist/models/calls.d.ts.map +1 -1
- package/dist/models/catalog.d.ts +5 -0
- package/dist/models/catalog.d.ts.map +1 -1
- package/dist/models/definitions.d.ts +3 -2
- package/dist/models/definitions.d.ts.map +1 -1
- package/dist/models/errors.d.ts +5 -3
- package/dist/models/errors.d.ts.map +1 -1
- package/dist/models/events.d.ts +2 -0
- package/dist/models/events.d.ts.map +1 -1
- package/dist/models/execution/index.d.ts +1 -0
- package/dist/models/execution/index.d.ts.map +1 -1
- package/dist/models/execution/index.js +33 -28
- package/dist/models/execution/index.js.map +1 -1
- package/dist/models/execution/model-call-limits.d.ts.map +1 -1
- package/dist/models/execution/model-call-recorder.d.ts +8 -0
- package/dist/models/execution/model-call-recorder.d.ts.map +1 -1
- package/dist/models/execution/session.d.ts +12 -0
- package/dist/models/execution/session.d.ts.map +1 -1
- package/dist/models/execution/usage.d.ts.map +1 -1
- package/dist/models/execution.d.ts +1 -1
- package/dist/models/execution.d.ts.map +1 -1
- package/dist/models/generation-types.d.ts +2 -0
- package/dist/models/generation-types.d.ts.map +1 -1
- package/dist/models/index.d.ts +4 -2
- package/dist/models/index.d.ts.map +1 -1
- package/dist/models/index.js +2 -2
- package/dist/models/input-file.d.ts.map +1 -1
- package/dist/models/pricing.d.ts +2 -1
- package/dist/models/pricing.d.ts.map +1 -1
- package/dist/models/rate-card.d.ts +6 -0
- package/dist/models/rate-card.d.ts.map +1 -1
- package/dist/models/tools.d.ts +5 -0
- package/dist/models/tools.d.ts.map +1 -1
- package/dist/models/video/catalog.d.ts +13 -0
- package/dist/models/video/catalog.d.ts.map +1 -0
- package/dist/models/video/check.d.ts +76 -0
- package/dist/models/video/check.d.ts.map +1 -0
- package/dist/models/video/runtime.d.ts +21 -0
- package/dist/models/video/runtime.d.ts.map +1 -0
- package/dist/models/video/types.d.ts +188 -0
- package/dist/models/video/types.d.ts.map +1 -0
- package/dist/objects/execution.d.ts.map +1 -1
- package/dist/objects/index.js +53 -50
- package/dist/objects/index.js.map +1 -1
- package/dist/objects/query/index.js +25 -23
- package/dist/objects/query/index.js.map +1 -1
- package/dist/objects/sdk/object-set.d.ts.map +1 -1
- package/dist/ontology/index.js +4 -4
- package/dist/ontology/internal.js +4 -4
- package/dist/pipelines/index.js +28 -26
- package/dist/pipelines/index.js.map +1 -1
- package/dist/projections/internal.js +26 -24
- package/dist/projections/internal.js.map +1 -1
- package/dist/queues/index.d.ts +1 -1
- package/dist/queues/index.d.ts.map +1 -1
- package/dist/queues/types.d.ts +103 -6
- package/dist/queues/types.d.ts.map +1 -1
- package/dist/runtime/create.d.ts.map +1 -1
- package/dist/runtime/definitions.d.ts +14 -0
- package/dist/runtime/definitions.d.ts.map +1 -1
- package/dist/runtime/host.d.ts +3 -1
- package/dist/runtime/host.d.ts.map +1 -1
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/internal.d.ts +3 -1
- package/dist/runtime/internal.d.ts.map +1 -1
- package/dist/runtime/internal.js +49 -43
- package/dist/runtime/internal.js.map +2 -2
- package/dist/runtime/resolve-definitions.d.ts +2 -1
- package/dist/runtime/resolve-definitions.d.ts.map +1 -1
- package/dist/runtime/sixb.d.ts.map +1 -1
- package/dist/sandboxes/errors.d.ts +19 -0
- package/dist/sandboxes/errors.d.ts.map +1 -1
- package/dist/sandboxes/exec.d.ts +2 -0
- package/dist/sandboxes/exec.d.ts.map +1 -1
- package/dist/sandboxes/index.d.ts +1 -1
- package/dist/sandboxes/index.d.ts.map +1 -1
- package/dist/sandboxes/index.js +14 -8
- package/dist/sandboxes/index.js.map +1 -1
- package/dist/sandboxes/sandbox.d.ts +15 -1
- package/dist/sandboxes/sandbox.d.ts.map +1 -1
- package/dist/security/public.d.ts +6 -4
- package/dist/security/public.d.ts.map +1 -1
- package/dist/security/public.js +5 -3
- package/dist/security/public.js.map +1 -1
- package/dist/shares/internal.js +25 -23
- package/dist/shares/internal.js.map +2 -2
- package/dist/storage/agents/in-memory.d.ts +2 -1
- package/dist/storage/agents/in-memory.d.ts.map +1 -1
- package/dist/storage/agents/index.d.ts +1 -1
- package/dist/storage/agents/index.d.ts.map +1 -1
- package/dist/storage/agents/provider.d.ts.map +1 -1
- package/dist/storage/agents/provider.js +5 -5
- package/dist/storage/agents/types.d.ts +27 -1
- package/dist/storage/agents/types.d.ts.map +1 -1
- package/dist/storage/ai-cost/analytics.d.ts +1 -0
- package/dist/storage/ai-cost/analytics.d.ts.map +1 -1
- package/dist/storage/ai-cost/groups.d.ts +2 -0
- package/dist/storage/ai-cost/groups.d.ts.map +1 -1
- package/dist/storage/ai-cost/provider.js +5 -5
- package/dist/storage/ai-cost/types.d.ts +2 -1
- package/dist/storage/ai-cost/types.d.ts.map +1 -1
- package/dist/storage/ai-cost/validation.d.ts.map +1 -1
- package/dist/storage/ai-limits/enforcement.js +3 -3
- package/dist/storage/ai-limits/provider.js +2 -2
- package/dist/storage/ai-usage/in-memory.d.ts +8 -1
- package/dist/storage/ai-usage/in-memory.d.ts.map +1 -1
- package/dist/storage/ai-usage/index.d.ts +2 -2
- package/dist/storage/ai-usage/index.d.ts.map +1 -1
- package/dist/storage/ai-usage/record.d.ts +11 -1
- package/dist/storage/ai-usage/record.d.ts.map +1 -1
- package/dist/storage/ai-usage/types.d.ts +80 -1
- package/dist/storage/ai-usage/types.d.ts.map +1 -1
- package/dist/storage/ai-usage/usage.d.ts +1 -1
- package/dist/storage/ai-usage/usage.d.ts.map +1 -1
- package/dist/storage/artifacts/in-memory.d.ts +25 -2
- package/dist/storage/artifacts/in-memory.d.ts.map +1 -1
- package/dist/storage/artifacts/index.d.ts +1 -1
- package/dist/storage/artifacts/index.d.ts.map +1 -1
- package/dist/storage/artifacts/record.d.ts +12 -1
- package/dist/storage/artifacts/record.d.ts.map +1 -1
- package/dist/storage/artifacts/types.d.ts +198 -6
- package/dist/storage/artifacts/types.d.ts.map +1 -1
- package/dist/storage/executions/provider.js +3 -2
- package/dist/storage/executions/provider.js.map +1 -1
- package/dist/storage/file-upload-sessions/provider.js +10 -9
- package/dist/storage/file-upload-sessions/provider.js.map +1 -1
- package/dist/storage/in-memory/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +4 -4
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +25 -23
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/internal.d.ts +2 -2
- package/dist/storage/internal.d.ts.map +1 -1
- package/dist/storage/internal.js +34 -14
- package/dist/storage/internal.js.map +2 -2
- package/dist/storage/workflow-runs/provider.js +10 -9
- package/dist/storage/workflow-runs/provider.js.map +1 -1
- package/dist/syncs/index.js +29 -27
- package/dist/syncs/index.js.map +1 -1
- package/dist/testing/agent-storage-contract.d.ts.map +1 -1
- package/dist/testing/ai-cost-storage-contract.d.ts.map +1 -1
- package/dist/testing/ai-usage-storage-contract.d.ts.map +1 -1
- package/dist/testing/artifact-storage-contract.d.ts +3 -0
- package/dist/testing/artifact-storage-contract.d.ts.map +1 -1
- package/dist/testing/execution-storage-contract.d.ts.map +1 -1
- package/dist/testing/index.js +686 -75
- package/dist/testing/index.js.map +10 -10
- package/dist/testing/lake-storage-contract.d.ts.map +1 -1
- package/dist/testing/queues-contract.d.ts.map +1 -1
- package/dist/testing/sandboxes-contract.d.ts.map +1 -1
- package/dist/webhooks/internal.js +26 -24
- package/dist/webhooks/internal.js.map +2 -2
- package/dist/workers/index.js +5 -5
- package/dist/workers/index.js.map +1 -1
- package/dist/workflows/index.js +60 -57
- package/dist/workflows/index.js.map +1 -1
- package/package.json +3 -1
- package/src/actions/request.ts +2 -0
- package/src/actions/run/context.ts +1 -0
- package/src/actions/run/execute.ts +5 -1
- package/src/actions/run/executor.ts +4 -0
- package/src/actions/run/normalize.ts +4 -0
- package/src/actions/run/types.ts +6 -0
- package/src/actions/types/context.ts +7 -0
- package/src/agents/README.md +3 -1
- package/src/agents/context/entries.ts +63 -9
- package/src/agents/context-model.ts +9 -0
- package/src/agents/context-resolution.ts +7 -0
- package/src/agents/execution.ts +39 -0
- package/src/agents/index.ts +1 -0
- package/src/agents/model-call-retry.ts +69 -0
- package/src/agents/model-loop.ts +86 -12
- package/src/agents/model-routing.ts +104 -38
- package/src/agents/request.ts +27 -1
- package/src/agents/run-artifacts.ts +10 -5
- package/src/agents/run-plan.ts +2 -1
- package/src/agents/run-session-http.ts +1 -0
- package/src/agents/run-session-serve.ts +23 -2
- package/src/agents/run-session-wire.ts +45 -0
- package/src/agents/run-token.ts +7 -0
- package/src/agents/thread-access.ts +34 -1
- package/src/agents/tool-files.ts +23 -7
- package/src/artifacts/caller.ts +42 -0
- package/src/artifacts/comment-place.ts +51 -0
- package/src/artifacts/comment-text.ts +50 -7
- package/src/artifacts/comments.ts +132 -34
- package/src/artifacts/errors.ts +1 -0
- package/src/artifacts/execution.ts +249 -5
- package/src/artifacts/frames/assets.ts +93 -15
- package/src/artifacts/frames/entries.ts +7 -4
- package/src/artifacts/frames/generated/hyperframes-notices.txt +290 -0
- package/src/artifacts/frames/generated/hyperframes.txt +1145 -0
- package/src/artifacts/frames/generated.d.ts +5 -0
- package/src/artifacts/frames/hyperframes.ts +14 -0
- package/src/artifacts/frames/index.ts +5 -0
- package/src/artifacts/frames/kit.ts +7 -3
- package/src/artifacts/frames/protocol.ts +56 -0
- package/src/artifacts/frames/video-runtime.ts +165 -0
- package/src/artifacts/html.ts +13 -0
- package/src/artifacts/index.ts +7 -0
- package/src/artifacts/kinds.ts +9 -1
- package/src/artifacts/limits.ts +43 -0
- package/src/artifacts/live/document.ts +27 -3
- package/src/artifacts/live/index.ts +58 -2
- package/src/artifacts/live/presence.ts +17 -5
- package/src/artifacts/live/protocol.ts +4 -2
- package/src/artifacts/live/server.ts +1 -1
- package/src/artifacts/live/state.ts +3 -3
- package/src/artifacts/media/README.md +75 -0
- package/src/artifacts/media/media.ts +316 -0
- package/src/artifacts/media/transcriber.ts +84 -0
- package/src/artifacts/outline.ts +28 -0
- package/src/artifacts/publish/files.ts +19 -6
- package/src/artifacts/publish/index.ts +49 -2
- package/src/artifacts/publish/pdf.ts +3 -1
- package/src/artifacts/publish/previews.ts +22 -8
- package/src/artifacts/publish/publish.ts +4 -1
- package/src/artifacts/publish/validate/html.ts +23 -18
- package/src/artifacts/publish/validate/video.ts +309 -0
- package/src/artifacts/publish/video.ts +235 -0
- package/src/artifacts/resolve.ts +45 -0
- package/src/artifacts/video/README.md +402 -0
- package/src/artifacts/video/composition.ts +898 -0
- package/src/artifacts/video/edit.ts +3967 -0
- package/src/artifacts/video/export.ts +352 -0
- package/src/artifacts/video/looks.ts +694 -0
- package/src/artifacts/video/project.ts +198 -0
- package/src/artifacts/video/stills.ts +168 -0
- package/src/artifacts/video/timeline.ts +658 -0
- package/src/blob-storage/browser.ts +1 -1
- package/src/blob-storage/constants.ts +9 -3
- package/src/blob-storage/download-urls.ts +5 -3
- package/src/blob-storage/index.ts +1 -0
- package/src/blob-storage/internal.ts +13 -2
- package/src/blob-storage/media-type.ts +149 -8
- package/src/bootstrap/discovery.ts +61 -11
- package/src/deploy/index.ts +0 -5
- package/src/deploy/types.ts +8 -63
- package/src/deploy/validation.ts +1 -1
- package/src/env/index.ts +10 -4
- package/src/errors/catalog.ts +2 -1
- package/src/execution/authorization.ts +2 -2
- package/src/execution/kernel-operation.ts +14 -0
- package/src/execution/types.ts +2 -0
- package/src/http/api-routes.ts +117 -0
- package/src/index.ts +21 -1
- package/src/lake-storage/definition-updates.ts +3 -9
- package/src/models/audio/runtime.ts +48 -3
- package/src/models/audio/speech.ts +2 -2
- package/src/models/audio/types.ts +24 -3
- package/src/models/calls.ts +35 -18
- package/src/models/catalog.ts +9 -2
- package/src/models/definitions.ts +4 -2
- package/src/models/errors.ts +5 -3
- package/src/models/events.ts +2 -0
- package/src/models/execution/README.md +68 -2
- package/src/models/execution/index.ts +1 -0
- package/src/models/execution/model-call-limits.ts +11 -5
- package/src/models/execution/model-call-recorder.ts +14 -0
- package/src/models/execution/session.ts +52 -23
- package/src/models/execution/usage.ts +1 -0
- package/src/models/execution.ts +13 -2
- package/src/models/generation-types.ts +2 -0
- package/src/models/index.ts +20 -1
- package/src/models/input-file.ts +7 -2
- package/src/models/pricing.ts +19 -1
- package/src/models/rate-card.ts +15 -3
- package/src/models/tools.ts +5 -0
- package/src/models/video/catalog.ts +101 -0
- package/src/models/video/check.ts +441 -0
- package/src/models/video/runtime.ts +550 -0
- package/src/models/video/types.ts +194 -0
- package/src/objects/execution.ts +2 -0
- package/src/objects/sdk/object-set.ts +2 -0
- package/src/queues/index.ts +5 -0
- package/src/queues/types.ts +126 -5
- package/src/runtime/create.ts +1 -0
- package/src/runtime/definitions.ts +25 -0
- package/src/runtime/host.ts +6 -1
- package/src/runtime/index.ts +6 -1
- package/src/runtime/internal.ts +3 -1
- package/src/runtime/resolve-definitions.ts +7 -1
- package/src/runtime/sixb.ts +12 -4
- package/src/sandboxes/README.md +12 -2
- package/src/sandboxes/errors.ts +27 -0
- package/src/sandboxes/exec.ts +3 -1
- package/src/sandboxes/index.ts +3 -0
- package/src/sandboxes/sandbox.ts +15 -1
- package/src/security/public.ts +6 -4
- package/src/storage/agents/in-memory.ts +39 -0
- package/src/storage/agents/index.ts +1 -0
- package/src/storage/agents/provider.ts +8 -0
- package/src/storage/agents/types.ts +32 -1
- package/src/storage/ai-cost/analytics.ts +2 -0
- package/src/storage/ai-cost/codec.ts +1 -0
- package/src/storage/ai-cost/groups.ts +7 -0
- package/src/storage/ai-cost/types.ts +2 -0
- package/src/storage/ai-cost/validation.ts +2 -0
- package/src/storage/ai-usage/in-memory.ts +93 -0
- package/src/storage/ai-usage/index.ts +10 -0
- package/src/storage/ai-usage/record.ts +106 -0
- package/src/storage/ai-usage/types.ts +102 -1
- package/src/storage/ai-usage/usage.ts +2 -0
- package/src/storage/artifacts/in-memory.ts +108 -11
- package/src/storage/artifacts/index.ts +14 -0
- package/src/storage/artifacts/record.ts +203 -1
- package/src/storage/artifacts/types.ts +199 -6
- package/src/storage/executions/validation.ts +2 -2
- package/src/storage/in-memory/index.ts +1 -1
- package/src/storage/index.ts +22 -1
- package/src/storage/internal.ts +9 -0
- package/src/testing/agent-storage-contract.ts +135 -0
- package/src/testing/ai-cost-storage-contract.ts +1 -0
- package/src/testing/ai-usage-storage-contract.ts +145 -1
- package/src/testing/artifact-storage-contract.ts +330 -0
- package/src/testing/execution-storage-contract.ts +10 -2
- package/src/testing/lake-storage-contract.ts +27 -0
- package/src/testing/queues-contract.ts +71 -0
- package/src/testing/sandboxes-contract.ts +50 -0
- package/dist/chunk-3723kgba.js +0 -29
- package/dist/chunk-3723kgba.js.map +0 -10
- package/dist/chunk-3qtk0070.js.map +0 -14
- package/dist/chunk-8ncg20rd.js.map +0 -10
- package/dist/chunk-9vsc919v.js.map +0 -10
- package/dist/chunk-az95tsh3.js.map +0 -11
- package/dist/chunk-c29729me.js.map +0 -12
- package/dist/chunk-d7vyc7k6.js.map +0 -10
- package/dist/chunk-de5sfbc3.js +0 -3
- package/dist/chunk-f05994as.js.map +0 -10
- package/dist/chunk-gfdh9kqa.js.map +0 -11
- package/dist/chunk-jt012fxq.js.map +0 -34
- package/dist/chunk-mbwsgjn7.js.map +0 -11
- package/dist/chunk-nxysqbt0.js.map +0 -10
- package/dist/chunk-qttqe1ah.js.map +0 -24
- package/dist/chunk-sgx82nnt.js.map +0 -10
- package/dist/chunk-vs2s3p8n.js +0 -2274
- package/dist/chunk-vs2s3p8n.js.map +0 -20
- package/dist/chunk-wkv3h3q7.js.map +0 -12
- package/dist/chunk-wzcjhv54.js.map +0 -11
- package/dist/chunk-xtztwpkh.js.map +0 -12
- package/dist/chunk-ym1bqd98.js.map +0 -19
- /package/dist/{chunk-7mhbs9yy.js.map → chunk-1z8ccj53.js.map} +0 -0
- /package/dist/{chunk-dmnd9ea6.js.map → chunk-30a0ftnm.js.map} +0 -0
- /package/dist/{chunk-qbd282aa.js.map → chunk-39q9ybav.js.map} +0 -0
- /package/dist/{chunk-bcz9dxtf.js.map → chunk-3x902cja.js.map} +0 -0
- /package/dist/{chunk-c4nrycdy.js.map → chunk-4q4a5a96.js.map} +0 -0
- /package/dist/{chunk-ykchk644.js.map → chunk-4w8qzy9w.js.map} +0 -0
- /package/dist/{chunk-kft7mp7z.js.map → chunk-5xkqasvn.js.map} +0 -0
- /package/dist/{chunk-xavet0qs.js.map → chunk-6whr25gw.js.map} +0 -0
- /package/dist/{chunk-ygvay56w.js.map → chunk-896te58g.js.map} +0 -0
- /package/dist/{chunk-pqj8vff9.js.map → chunk-8eqqqc1h.js.map} +0 -0
- /package/dist/{chunk-jka26v8c.js.map → chunk-8x1bsp68.js.map} +0 -0
- /package/dist/{chunk-fmgf9h5e.js.map → chunk-9az7kjv4.js.map} +0 -0
- /package/dist/{chunk-bs1sd0e0.js.map → chunk-9p7kyeqz.js.map} +0 -0
- /package/dist/{chunk-brybqw5k.js.map → chunk-bkxm2dzx.js.map} +0 -0
- /package/dist/{chunk-ppxf7gw2.js.map → chunk-d7t9jnym.js.map} +0 -0
- /package/dist/{chunk-cg7cygfj.js.map → chunk-fdmvaz7x.js.map} +0 -0
- /package/dist/{chunk-191jz8a6.js.map → chunk-ff0qdk7z.js.map} +0 -0
- /package/dist/{chunk-wx7smkn2.js.map → chunk-fq8drkp0.js.map} +0 -0
- /package/dist/{chunk-v8a1qjzp.js.map → chunk-hpswfrjj.js.map} +0 -0
- /package/dist/{chunk-bz5bnjjt.js.map → chunk-jjte0h4p.js.map} +0 -0
- /package/dist/{chunk-xrmbhap8.js.map → chunk-mwg0nwkb.js.map} +0 -0
- /package/dist/{chunk-a3faa34j.js.map → chunk-nfjt8k8j.js.map} +0 -0
- /package/dist/{chunk-394zjzjs.js.map → chunk-nhgqz3g3.js.map} +0 -0
- /package/dist/{chunk-92wrka15.js.map → chunk-q150fnj9.js.map} +0 -0
- /package/dist/{chunk-w3t94hm6.js.map → chunk-qk3zq25v.js.map} +0 -0
- /package/dist/{chunk-6hfbz4d0.js.map → chunk-r588h4ev.js.map} +0 -0
- /package/dist/{chunk-5qqmndhm.js.map → chunk-szzhrn3e.js.map} +0 -0
- /package/dist/{chunk-n1hbwc6y.js.map → chunk-t6pfch4e.js.map} +0 -0
- /package/dist/{chunk-brhp9d97.js.map → chunk-vmqjndb3.js.map} +0 -0
- /package/dist/{chunk-5sswe5ej.js.map → chunk-wsv23wvr.js.map} +0 -0
- /package/dist/{chunk-90nqenq8.js.map → chunk-x0hqc54n.js.map} +0 -0
- /package/dist/{chunk-3neam1y5.js.map → chunk-y3qb965a.js.map} +0 -0
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
|
+
VIDEO_ENTRY2,
|
|
4
|
+
readVideoComposition2,
|
|
5
|
+
parseVideoRoot,
|
|
6
|
+
videoFilePath
|
|
7
|
+
} from "../../chunk-a68zz4r0.js";
|
|
8
|
+
import"../../chunk-3dvcdn9w.js";
|
|
9
|
+
import {
|
|
10
|
+
ARTIFACT_LIMITS2
|
|
11
|
+
} from "../../chunk-fgxvrxx4.js";
|
|
12
|
+
import {
|
|
13
|
+
diffSequences,
|
|
14
|
+
textLines,
|
|
15
|
+
diffText,
|
|
3
16
|
mergeText,
|
|
4
17
|
markdownToBlocks2,
|
|
5
18
|
blocksToMarkdown2,
|
|
@@ -14,10 +27,9 @@ import {
|
|
|
14
27
|
canvasItemMap2,
|
|
15
28
|
canvasItemObject2,
|
|
16
29
|
mergeCanvasItem2
|
|
17
|
-
} from "../../chunk-
|
|
30
|
+
} from "../../chunk-p0c5kkhn.js";
|
|
18
31
|
import"../../chunk-kr6dx38r.js";
|
|
19
|
-
import"../../chunk-
|
|
20
|
-
import"../../chunk-bz5bnjjt.js";
|
|
32
|
+
import"../../chunk-jjte0h4p.js";
|
|
21
33
|
import {
|
|
22
34
|
ARTIFACT_LIVE_ROUTE2,
|
|
23
35
|
USER_AWARENESS_FIELD2,
|
|
@@ -26,8 +38,3387 @@ import {
|
|
|
26
38
|
encodeLiveData2,
|
|
27
39
|
decodeLiveData2
|
|
28
40
|
} from "../../chunk-vtjzwymr.js";
|
|
41
|
+
// src/artifacts/video/looks.ts
|
|
42
|
+
function cssBlocks(css) {
|
|
43
|
+
const text = css.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
44
|
+
const blocks = [];
|
|
45
|
+
let at = 0;
|
|
46
|
+
while (at < text.length) {
|
|
47
|
+
const open = text.indexOf("{", at);
|
|
48
|
+
if (open < 0)
|
|
49
|
+
break;
|
|
50
|
+
const prelude = (text.slice(at, open).split(";").at(-1) ?? "").trim();
|
|
51
|
+
let depth = 0;
|
|
52
|
+
let quote = "";
|
|
53
|
+
let close = open;
|
|
54
|
+
for (;close < text.length; close += 1) {
|
|
55
|
+
const char = text[close];
|
|
56
|
+
if (quote) {
|
|
57
|
+
if (char === "\\")
|
|
58
|
+
close += 1;
|
|
59
|
+
else if (char === quote)
|
|
60
|
+
quote = "";
|
|
61
|
+
} else if (char === '"' || char === "'")
|
|
62
|
+
quote = char;
|
|
63
|
+
else if (char === "{")
|
|
64
|
+
depth += 1;
|
|
65
|
+
else if (char === "}" && --depth === 0)
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
blocks.push({ prelude, body: text.slice(open + 1, close) });
|
|
69
|
+
at = close + 1;
|
|
70
|
+
}
|
|
71
|
+
return blocks;
|
|
72
|
+
}
|
|
73
|
+
function keyframesOf(blocks) {
|
|
74
|
+
const found = new Map;
|
|
75
|
+
for (const block of blocks) {
|
|
76
|
+
const name = KEYFRAMES.exec(block.prelude)?.[1];
|
|
77
|
+
if (name && !found.has(name))
|
|
78
|
+
found.set(name, block.body);
|
|
79
|
+
}
|
|
80
|
+
return found;
|
|
81
|
+
}
|
|
82
|
+
function lookOf(element, scene, sheets) {
|
|
83
|
+
const rules = [];
|
|
84
|
+
const keyframes = new Map;
|
|
85
|
+
const defined = new Map;
|
|
86
|
+
const unsure = [];
|
|
87
|
+
for (const sheet of sheets) {
|
|
88
|
+
for (const [name, body] of keyframesOf(sheet.blocks)) {
|
|
89
|
+
if (!defined.has(name))
|
|
90
|
+
defined.set(name, body);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const visit = (blocks, sheet, within) => {
|
|
94
|
+
for (const block of blocks) {
|
|
95
|
+
if (GROUPING.test(block.prelude)) {
|
|
96
|
+
visit(cssBlocks(block.body), sheet, [...within, block.prelude]);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (block.prelude.startsWith("@"))
|
|
100
|
+
continue;
|
|
101
|
+
for (const selector of selectorsOf(block.prelude)) {
|
|
102
|
+
const styled = stylesItself(selector, element, scene, sheet);
|
|
103
|
+
if (styled === "uncertain")
|
|
104
|
+
unsure.push({ selector, body: block.body, sheet });
|
|
105
|
+
if (styled === undefined || styled === "uncertain")
|
|
106
|
+
continue;
|
|
107
|
+
const rule = { ...styled, body: block.body, within };
|
|
108
|
+
const same = (other) => cssKey(JSON.stringify(other)) === cssKey(JSON.stringify(rule));
|
|
109
|
+
if (!rules.some(same))
|
|
110
|
+
rules.push(rule);
|
|
111
|
+
for (const [name, frames] of defined) {
|
|
112
|
+
if (animatesBy(block.body, name))
|
|
113
|
+
keyframes.set(name, frames);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
for (const sheet of sheets)
|
|
119
|
+
visit(sheet.blocks, sheet, []);
|
|
120
|
+
return {
|
|
121
|
+
rules,
|
|
122
|
+
keyframes,
|
|
123
|
+
uncertain: unsure.length > 0,
|
|
124
|
+
...unsure.length > 0 ? { unsure } : {}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function lookDiffers(look, element, context) {
|
|
128
|
+
if (!look.uncertain)
|
|
129
|
+
return false;
|
|
130
|
+
if (!context)
|
|
131
|
+
return true;
|
|
132
|
+
const both = [];
|
|
133
|
+
for (const { selector, body, sheet } of look.unsure ?? []) {
|
|
134
|
+
if (sheet.carried || sheet.byId)
|
|
135
|
+
return true;
|
|
136
|
+
const from = matchesIn(selector, element, context.from);
|
|
137
|
+
if (from === "uncertain")
|
|
138
|
+
return true;
|
|
139
|
+
if (!sheet.shared) {
|
|
140
|
+
if (from)
|
|
141
|
+
return true;
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const to = matchesIn(selector, element, context.to);
|
|
145
|
+
if (to === "uncertain" || to !== from)
|
|
146
|
+
return true;
|
|
147
|
+
if (from)
|
|
148
|
+
both.push(body);
|
|
149
|
+
}
|
|
150
|
+
return both.some((body) => look.rules.some((rule) => sharesProperty(body, rule.body)));
|
|
151
|
+
}
|
|
152
|
+
function matchesIn(selector, element, ancestors) {
|
|
153
|
+
const compounds = compoundsOf(selector).map((each) => ({
|
|
154
|
+
combinator: each.combinator,
|
|
155
|
+
parts: subjectParts(each.compound)
|
|
156
|
+
}));
|
|
157
|
+
if (compounds.length === 0)
|
|
158
|
+
return false;
|
|
159
|
+
if (compounds.some((each) => !each.parts))
|
|
160
|
+
return "uncertain";
|
|
161
|
+
if (compounds.slice(1).some((each) => each.combinator !== " " && each.combinator !== ">")) {
|
|
162
|
+
return "uncertain";
|
|
163
|
+
}
|
|
164
|
+
let uncertain = false;
|
|
165
|
+
const holds = (at, candidate, held) => {
|
|
166
|
+
const matched = matchCompound(compounds[at]?.parts ?? [], candidate, held);
|
|
167
|
+
if (matched === "uncertain")
|
|
168
|
+
uncertain = true;
|
|
169
|
+
return matched !== false;
|
|
170
|
+
};
|
|
171
|
+
const within = (at, from) => {
|
|
172
|
+
if (at < 0)
|
|
173
|
+
return true;
|
|
174
|
+
if (compounds[at + 1]?.combinator === ">") {
|
|
175
|
+
const parent = ancestors[from];
|
|
176
|
+
return parent !== undefined && holds(at, parent, true) && within(at - 1, from - 1);
|
|
177
|
+
}
|
|
178
|
+
for (let outer = from;outer >= 0; outer -= 1) {
|
|
179
|
+
const candidate = ancestors[outer];
|
|
180
|
+
if (candidate && holds(at, candidate, true) && within(at - 1, outer - 1))
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
return false;
|
|
184
|
+
};
|
|
185
|
+
const last = compounds.length - 1;
|
|
186
|
+
const matched = holds(last, element, false) && within(last - 1, ancestors.length - 1);
|
|
187
|
+
return uncertain ? "uncertain" : matched;
|
|
188
|
+
}
|
|
189
|
+
function sharesProperty(one, other) {
|
|
190
|
+
const names = (body) => body.split(";").map((declaration) => declaration.split(":")[0]?.trim().toLowerCase() ?? "").filter(Boolean);
|
|
191
|
+
const theirs = names(other);
|
|
192
|
+
return names(one).some((name) => theirs.some((each) => each === name || each.startsWith(`${name}-`) || name.startsWith(`${each}-`)));
|
|
193
|
+
}
|
|
194
|
+
function writtenLook(look, scene, key, seen) {
|
|
195
|
+
const renamed = new Map;
|
|
196
|
+
const frames = [];
|
|
197
|
+
for (const [name, body] of look.keyframes) {
|
|
198
|
+
const same = (other) => other !== undefined && cssKey(other) === cssKey(body);
|
|
199
|
+
const free = (candidate) => {
|
|
200
|
+
const own = seen.own.get(candidate);
|
|
201
|
+
const carried = seen.carried.get(candidate) ?? [];
|
|
202
|
+
return (own === undefined || same(own)) && carried.every((each) => same(each));
|
|
203
|
+
};
|
|
204
|
+
let chosen = name;
|
|
205
|
+
for (let n = 2;!free(chosen); n += 1)
|
|
206
|
+
chosen = `${name}-${n}`;
|
|
207
|
+
if (chosen !== name)
|
|
208
|
+
renamed.set(name, chosen);
|
|
209
|
+
if (!same(seen.own.get(chosen)))
|
|
210
|
+
frames.push(cssRule(`@keyframes ${chosen}`, body));
|
|
211
|
+
}
|
|
212
|
+
const rules = look.rules.map((rule) => {
|
|
213
|
+
let body = rule.body;
|
|
214
|
+
for (const [from, to] of renamed)
|
|
215
|
+
body = renameAnimation(body, from, to);
|
|
216
|
+
const scope = rule.scoped ? `[data-composition-id="${scene}"] ` : "";
|
|
217
|
+
const reach = `:is([data-look="${key}"], #${LOOK_ID})`.repeat(rule.ids);
|
|
218
|
+
const selector = `${scope}${rule.tag}${reach}${rule.rest}${rule.tail}`;
|
|
219
|
+
return rule.within.reduceRight((inner, prelude) => wrapped(prelude, inner), cssRule(selector, body));
|
|
220
|
+
});
|
|
221
|
+
return [...rules, ...frames];
|
|
222
|
+
}
|
|
223
|
+
function wrapped(prelude, inner) {
|
|
224
|
+
if (!inner.includes(`
|
|
225
|
+
`))
|
|
226
|
+
return `${prelude} { ${inner} }`;
|
|
227
|
+
return [`${prelude} {`, ...inner.split(`
|
|
228
|
+
`).map((line) => ` ${line}`), "}"].join(`
|
|
229
|
+
`);
|
|
230
|
+
}
|
|
231
|
+
function scriptNames(scripts, element) {
|
|
232
|
+
if (scripts.trim() === "")
|
|
233
|
+
return false;
|
|
234
|
+
const byId = element.id !== undefined && (inSelector(scripts, `#${element.id}`) || new RegExp(`getElementById\\(\\s*["'\`]${escapeRegExp(element.id)}["'\`]`).test(scripts));
|
|
235
|
+
return byId || element.classes.some((name) => inSelector(scripts, `.${name}`));
|
|
236
|
+
}
|
|
237
|
+
function scriptReaches(scripts, element) {
|
|
238
|
+
if (scripts.trim() === "")
|
|
239
|
+
return false;
|
|
240
|
+
const byTag = new RegExp(`[\\]}]\\s+${escapeRegExp(element.tag)}(?=["'\`\\s,.:\\[>)])`, "i");
|
|
241
|
+
return byTag.test(scripts) || element.classes.some((name) => inSelector(scripts, `.${name}`));
|
|
242
|
+
}
|
|
243
|
+
function scriptReachesIn(scripts, element, context) {
|
|
244
|
+
if (scripts.trim() === "")
|
|
245
|
+
return false;
|
|
246
|
+
const strings = [...scripts.matchAll(/(["'`])((?:\\.|(?!\1)[^\\\n])*)\1/g)];
|
|
247
|
+
const declared = new Map;
|
|
248
|
+
for (const match of scripts.matchAll(/\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*(["'])((?:\\.|(?!\2)[^\\\n])*)\2/g)) {
|
|
249
|
+
if (match[1])
|
|
250
|
+
declared.set(match[1], match[3] ?? "");
|
|
251
|
+
}
|
|
252
|
+
let built = false;
|
|
253
|
+
const selectors = strings.flatMap((match) => {
|
|
254
|
+
const text = (match[2] ?? "").replace(/\$\{\s*([A-Za-z_$][\w$]*)\s*\}/g, (whole, name) => match[1] === "`" && declared.has(name) ? declared.get(name) ?? "" : whole);
|
|
255
|
+
if (text.includes("${"))
|
|
256
|
+
built = true;
|
|
257
|
+
const selector = text.trim();
|
|
258
|
+
return selector && /^[\w\s\-.#[\]="':(),>+~*|^$]+$/.test(selector) && /[.#[]/.test(selector) ? [selector] : [];
|
|
259
|
+
});
|
|
260
|
+
if (built || selectors.length === 0)
|
|
261
|
+
return scriptReaches(scripts, element);
|
|
262
|
+
return selectors.some((text) => selectorsOf(text).some((selector) => matchesIn(selector, element, context) !== false));
|
|
263
|
+
}
|
|
264
|
+
function cssRule(prelude, body) {
|
|
265
|
+
const lines = body.split(`
|
|
266
|
+
`).map((line) => line.trim()).filter(Boolean);
|
|
267
|
+
if (lines.length <= 1)
|
|
268
|
+
return `${prelude} { ${lines[0] ?? ""} }`;
|
|
269
|
+
return [`${prelude} {`, ...lines.map((line) => ` ${line}`), "}"].join(`
|
|
270
|
+
`);
|
|
271
|
+
}
|
|
272
|
+
var KEYFRAMES = /^@(?:-webkit-)?keyframes\s+([\w-]+)/i;
|
|
273
|
+
var SCOPE = /^\[\s*data-composition-id\s*=\s*(["']?)([^"'\]\s]+)\1\s*\]$/;
|
|
274
|
+
var LOOK_ID = "sixb-look";
|
|
275
|
+
var REACH = new RegExp(`^:is\\(\\[data-look="[^"]*"\\], #${LOOK_ID}\\)$`);
|
|
276
|
+
function lookKey(home, look) {
|
|
277
|
+
const names = [...look.keyframes.keys()];
|
|
278
|
+
const rules = look.rules.map((rule) => ({
|
|
279
|
+
...rule,
|
|
280
|
+
within: rule.within.map(cssKey),
|
|
281
|
+
body: cssKey(names.reduce((body, name, at) => renameAnimation(body, name, `\x00${at}`), rule.body))
|
|
282
|
+
}));
|
|
283
|
+
const frames = [...look.keyframes.values()].map(cssKey);
|
|
284
|
+
const text = `${home}
|
|
285
|
+
${JSON.stringify(rules)}
|
|
286
|
+
${JSON.stringify(frames)}`;
|
|
287
|
+
let low = 2166136261;
|
|
288
|
+
let high = 16777619;
|
|
289
|
+
for (let at = 0;at < text.length; at += 1) {
|
|
290
|
+
const code = text.charCodeAt(at);
|
|
291
|
+
low = Math.imul(low ^ code, 16777619);
|
|
292
|
+
high = Math.imul(high ^ code, 2166136261) ^ low >>> 15;
|
|
293
|
+
}
|
|
294
|
+
return [high >>> 0, low >>> 0, text.length].map((each) => each.toString(36)).join("");
|
|
295
|
+
}
|
|
296
|
+
var GROUPING = /^@(?:media|supports|container|layer)\b/i;
|
|
297
|
+
var STATES = new Set([
|
|
298
|
+
"hover",
|
|
299
|
+
"focus",
|
|
300
|
+
"focus-visible",
|
|
301
|
+
"focus-within",
|
|
302
|
+
"active",
|
|
303
|
+
"visited",
|
|
304
|
+
"link",
|
|
305
|
+
"any-link",
|
|
306
|
+
"checked",
|
|
307
|
+
"disabled",
|
|
308
|
+
"enabled"
|
|
309
|
+
]);
|
|
310
|
+
function stylesItself(selector, element, scene, sheet) {
|
|
311
|
+
const compounds = compoundsOf(selector);
|
|
312
|
+
if (compounds.length === 0)
|
|
313
|
+
return;
|
|
314
|
+
let first = 0;
|
|
315
|
+
while (first < compounds.length - 1 && SCOPE.exec(compounds[first]?.compound ?? ""))
|
|
316
|
+
first += 1;
|
|
317
|
+
const scopes = compounds.slice(0, first).map((each) => SCOPE.exec(each.compound)?.[2]);
|
|
318
|
+
if (scopes.some((each) => each !== scene))
|
|
319
|
+
return;
|
|
320
|
+
const anchor = compounds[first];
|
|
321
|
+
const after = compounds.slice(first + 1);
|
|
322
|
+
if (!anchor)
|
|
323
|
+
return;
|
|
324
|
+
const parts = subjectParts(anchor.compound);
|
|
325
|
+
const matched = parts ? matchCompound(parts, element) : "uncertain";
|
|
326
|
+
if (matched === false || !parts) {
|
|
327
|
+
const last = compounds.at(-1);
|
|
328
|
+
const lastParts = last && after.length > 0 ? subjectParts(last.compound) : undefined;
|
|
329
|
+
if (!parts)
|
|
330
|
+
return "uncertain";
|
|
331
|
+
return lastParts && matchCompound(lastParts, element) !== false ? "uncertain" : undefined;
|
|
332
|
+
}
|
|
333
|
+
if (matched === "uncertain")
|
|
334
|
+
return "uncertain";
|
|
335
|
+
if (after.some((each) => each.combinator !== " " && each.combinator !== ">"))
|
|
336
|
+
return "uncertain";
|
|
337
|
+
let names = false;
|
|
338
|
+
let ids = 0;
|
|
339
|
+
let tag = "";
|
|
340
|
+
let rest = "";
|
|
341
|
+
for (const part of parts) {
|
|
342
|
+
if (sheet.carried && REACH.test(part)) {
|
|
343
|
+
ids += 1;
|
|
344
|
+
names = true;
|
|
345
|
+
} else if (part.startsWith("#")) {
|
|
346
|
+
ids += 1;
|
|
347
|
+
names = true;
|
|
348
|
+
} else if (part.startsWith(".")) {
|
|
349
|
+
if (sheet.byId)
|
|
350
|
+
return;
|
|
351
|
+
names = true;
|
|
352
|
+
rest += part;
|
|
353
|
+
} else if (/^[a-zA-Z]/.test(part)) {
|
|
354
|
+
if (sheet.byId)
|
|
355
|
+
return;
|
|
356
|
+
names = true;
|
|
357
|
+
tag = part;
|
|
358
|
+
} else if (part !== "*") {
|
|
359
|
+
if (/^:(?:is|where)\(/i.test(part))
|
|
360
|
+
names = true;
|
|
361
|
+
rest += part;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
if (!names)
|
|
365
|
+
return;
|
|
366
|
+
if (sheet.byId && ids === 0)
|
|
367
|
+
return;
|
|
368
|
+
const tail = after.map((each) => `${each.combinator === " " ? " " : ` ${each.combinator} `}${each.compound}`).join("");
|
|
369
|
+
return { scoped: first > 0, tag, rest, tail, ids: sheet.carried ? ids : ids + 1 };
|
|
370
|
+
}
|
|
371
|
+
function subjectParts(compound) {
|
|
372
|
+
const parts = compound.match(/::?[\w-]+(?:\((?:[^()]|\([^()]*\))*\))?|\[[^\]]*\]|[#.](?:[\w-]|\\.)+|\*|[a-zA-Z][\w-]*/g) ?? [];
|
|
373
|
+
return parts.join("") === compound ? parts : undefined;
|
|
374
|
+
}
|
|
375
|
+
function matchCompound(parts, element, held = false) {
|
|
376
|
+
let uncertain = false;
|
|
377
|
+
for (const part of parts) {
|
|
378
|
+
if (part.startsWith("::"))
|
|
379
|
+
continue;
|
|
380
|
+
if (part.startsWith(":")) {
|
|
381
|
+
const name = /^:([\w-]+)/.exec(part)?.[1]?.toLowerCase() ?? "";
|
|
382
|
+
const args = /\((.*)\)$/.exec(part)?.[1];
|
|
383
|
+
if (STATES.has(name))
|
|
384
|
+
continue;
|
|
385
|
+
if ((name === "is" || name === "where" || name === "not") && args !== undefined) {
|
|
386
|
+
const each = selectorsOf(args).map((arg) => {
|
|
387
|
+
const inner = compoundsOf(arg).length === 1 ? subjectParts(arg.trim()) : undefined;
|
|
388
|
+
return inner ? matchCompound(inner, element, held) : "uncertain";
|
|
389
|
+
});
|
|
390
|
+
const any = each.includes(true);
|
|
391
|
+
if (name === "not" ? any : !any && !each.includes("uncertain"))
|
|
392
|
+
return false;
|
|
393
|
+
if (each.includes("uncertain") && !(name !== "not" && any))
|
|
394
|
+
uncertain = true;
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
uncertain = true;
|
|
398
|
+
} else if (part.startsWith("#")) {
|
|
399
|
+
if (unescaped(part.slice(1)) !== element.id)
|
|
400
|
+
return false;
|
|
401
|
+
} else if (part.startsWith(".")) {
|
|
402
|
+
if (!element.classes.includes(unescaped(part.slice(1))))
|
|
403
|
+
return false;
|
|
404
|
+
} else if (part.startsWith("[")) {
|
|
405
|
+
const attribute = /^\[\s*([\w-]+)\s*(?:([~^$*|]?=)\s*(["']?)([^"'\]]*)\3\s*)?\]$/.exec(part);
|
|
406
|
+
const name = attribute?.[1]?.toLowerCase();
|
|
407
|
+
if (!attribute || !name) {
|
|
408
|
+
uncertain = true;
|
|
409
|
+
continue;
|
|
410
|
+
}
|
|
411
|
+
const value = element.attributes.get(name);
|
|
412
|
+
if (name === "data-composition-id" && !held || value === undefined)
|
|
413
|
+
return false;
|
|
414
|
+
if (attribute[2] && !attributeMatches(value, attribute[2], attribute[4] ?? ""))
|
|
415
|
+
return false;
|
|
416
|
+
} else if (part !== "*" && part.toLowerCase() !== element.tag) {
|
|
417
|
+
return false;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
return uncertain ? "uncertain" : true;
|
|
421
|
+
}
|
|
422
|
+
function compoundsOf(selector) {
|
|
423
|
+
const compounds = [];
|
|
424
|
+
let depth = 0;
|
|
425
|
+
let current = "";
|
|
426
|
+
let combinator = "";
|
|
427
|
+
const text = selector.trim();
|
|
428
|
+
for (let at = 0;at < text.length; at += 1) {
|
|
429
|
+
const char = text[at] ?? "";
|
|
430
|
+
if (char === "\\") {
|
|
431
|
+
current += text.slice(at, at + 2);
|
|
432
|
+
at += 1;
|
|
433
|
+
continue;
|
|
434
|
+
}
|
|
435
|
+
if (char === "[" || char === "(")
|
|
436
|
+
depth += 1;
|
|
437
|
+
if (char === "]" || char === ")")
|
|
438
|
+
depth -= 1;
|
|
439
|
+
if (depth === 0 && /[\s>+~]/.test(char)) {
|
|
440
|
+
if (current)
|
|
441
|
+
compounds.push({
|
|
442
|
+
combinator: compounds.length === 0 ? "" : combinator || " ",
|
|
443
|
+
compound: current
|
|
444
|
+
});
|
|
445
|
+
if (current)
|
|
446
|
+
combinator = "";
|
|
447
|
+
current = "";
|
|
448
|
+
if (char !== " " && !/\s/.test(char))
|
|
449
|
+
combinator = char;
|
|
450
|
+
continue;
|
|
451
|
+
}
|
|
452
|
+
current += char;
|
|
453
|
+
}
|
|
454
|
+
if (current)
|
|
455
|
+
compounds.push({
|
|
456
|
+
combinator: compounds.length === 0 ? "" : combinator || " ",
|
|
457
|
+
compound: current
|
|
458
|
+
});
|
|
459
|
+
return compounds;
|
|
460
|
+
}
|
|
461
|
+
function selectorsOf(prelude) {
|
|
462
|
+
const selectors = [];
|
|
463
|
+
let depth = 0;
|
|
464
|
+
let quote = "";
|
|
465
|
+
let start = 0;
|
|
466
|
+
for (let at = 0;at < prelude.length; at += 1) {
|
|
467
|
+
const char = prelude[at];
|
|
468
|
+
if (quote) {
|
|
469
|
+
if (char === quote)
|
|
470
|
+
quote = "";
|
|
471
|
+
} else if (char === '"' || char === "'")
|
|
472
|
+
quote = char;
|
|
473
|
+
else if (char === "(" || char === "[")
|
|
474
|
+
depth += 1;
|
|
475
|
+
else if (char === ")" || char === "]")
|
|
476
|
+
depth -= 1;
|
|
477
|
+
else if (char === "," && depth === 0) {
|
|
478
|
+
selectors.push(prelude.slice(start, at).trim());
|
|
479
|
+
start = at + 1;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
selectors.push(prelude.slice(start).trim());
|
|
483
|
+
return selectors.filter(Boolean);
|
|
484
|
+
}
|
|
485
|
+
function attributeMatches(value, op, wanted) {
|
|
486
|
+
switch (op) {
|
|
487
|
+
case "~=":
|
|
488
|
+
return value.split(/\s+/).includes(wanted);
|
|
489
|
+
case "^=":
|
|
490
|
+
return wanted !== "" && value.startsWith(wanted);
|
|
491
|
+
case "$=":
|
|
492
|
+
return wanted !== "" && value.endsWith(wanted);
|
|
493
|
+
case "*=":
|
|
494
|
+
return wanted !== "" && value.includes(wanted);
|
|
495
|
+
case "|=":
|
|
496
|
+
return value === wanted || value.startsWith(`${wanted}-`);
|
|
497
|
+
default:
|
|
498
|
+
return value === wanted;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
function unescaped(identifier) {
|
|
502
|
+
return identifier.replace(/\\([0-9a-fA-F]{1,6}\s?|.)/g, (_, escaped) => /^[0-9a-fA-F]/.test(escaped) && escaped.trim().length > 1 ? String.fromCodePoint(Number.parseInt(escaped.trim(), 16)) : escaped.trim() || escaped);
|
|
503
|
+
}
|
|
504
|
+
function animatesBy(body, name) {
|
|
505
|
+
return new RegExp(`animation(?:-name)?\\s*:[^;}]*(?<![\\w-])${escapeRegExp(name)}(?![\\w-])`).test(body);
|
|
506
|
+
}
|
|
507
|
+
function renameAnimation(body, from, to) {
|
|
508
|
+
return body.replace(/(animation(?:-name)?\s*:)([^;}]*)/g, (_, property, value) => {
|
|
509
|
+
const pattern = new RegExp(`(?<![\\w-])${escapeRegExp(from)}(?![\\w-])`, "g");
|
|
510
|
+
return `${property}${value.replace(pattern, to)}`;
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
function inSelector(scripts, token) {
|
|
514
|
+
return new RegExp(`(?<![\\w$)\\]])${escapeRegExp(token)}(?![\\w-])`).test(scripts);
|
|
515
|
+
}
|
|
516
|
+
function cssKey(css) {
|
|
517
|
+
return css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\s+/g, " ").replace(/\s*([{};:,>])\s*/g, "$1").replace(/;}/g, "}").replace(/;$/, "").trim();
|
|
518
|
+
}
|
|
519
|
+
function escapeRegExp(value) {
|
|
520
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
// src/artifacts/video/timeline.ts
|
|
524
|
+
import { parse, parseFragment } from "parse5";
|
|
525
|
+
var TEXT_TAGS = new Set([
|
|
526
|
+
"h1",
|
|
527
|
+
"h2",
|
|
528
|
+
"h3",
|
|
529
|
+
"h4",
|
|
530
|
+
"h5",
|
|
531
|
+
"h6",
|
|
532
|
+
"p",
|
|
533
|
+
"span",
|
|
534
|
+
"div",
|
|
535
|
+
"li",
|
|
536
|
+
"strong",
|
|
537
|
+
"em",
|
|
538
|
+
"small",
|
|
539
|
+
"blockquote",
|
|
540
|
+
"figcaption",
|
|
541
|
+
"label",
|
|
542
|
+
"a",
|
|
543
|
+
"button"
|
|
544
|
+
]);
|
|
545
|
+
var LINE_BREAKS = new Set(["br", "wbr"]);
|
|
546
|
+
var INLINE_STYLES = new Set([
|
|
547
|
+
"span",
|
|
548
|
+
"b",
|
|
549
|
+
"strong",
|
|
550
|
+
"i",
|
|
551
|
+
"em",
|
|
552
|
+
"u",
|
|
553
|
+
"s",
|
|
554
|
+
"mark",
|
|
555
|
+
"small",
|
|
556
|
+
"sub",
|
|
557
|
+
"sup"
|
|
558
|
+
]);
|
|
559
|
+
function readSceneTimeline(html) {
|
|
560
|
+
const fragment = parseFragment(html, { sourceCodeLocationInfo: true });
|
|
561
|
+
const template = fragment.childNodes.find((node) => ("tagName" in node) && node.tagName === "template");
|
|
562
|
+
if (!template)
|
|
563
|
+
return null;
|
|
564
|
+
const composition = elements(contentOf(template)).find((element) => has(element, "data-composition-id"));
|
|
565
|
+
return composition ? timelineOf(composition) : null;
|
|
566
|
+
}
|
|
567
|
+
function readRootTimeline(html) {
|
|
568
|
+
const document = parse(html, { sourceCodeLocationInfo: true });
|
|
569
|
+
const compositions = elements(document.childNodes).filter((element) => has(element, "data-composition-id"));
|
|
570
|
+
const root = compositions.find((element) => attribute(element, "data-root") === "true") ?? compositions[0];
|
|
571
|
+
return root ? timelineOf(root) : null;
|
|
572
|
+
}
|
|
573
|
+
function readRootLayers(html) {
|
|
574
|
+
const document = parse(html, { sourceCodeLocationInfo: true });
|
|
575
|
+
const compositions = elements(document.childNodes).filter((element) => has(element, "data-composition-id"));
|
|
576
|
+
const root = compositions.find((element) => attribute(element, "data-root") === "true") ?? compositions[0];
|
|
577
|
+
const children = root?.childNodes.filter((node) => ("tagName" in node)) ?? [];
|
|
578
|
+
const first = children.findIndex((element) => has(element, "data-composition-src"));
|
|
579
|
+
if (first < 0)
|
|
580
|
+
return [];
|
|
581
|
+
return children.slice(first + 1).filter((element) => !has(element, "data-composition-src") && !UNSEEN_TAGS.has(element.tagName)).map(sourceOf);
|
|
582
|
+
}
|
|
583
|
+
var UNSEEN_TAGS = new Set(["audio", "script", "style", "template", "link", "meta", "noscript"]);
|
|
584
|
+
function timelineOf(composition) {
|
|
585
|
+
const own = elements(composition.childNodes, { stop: nests }).filter((element) => !nests(element));
|
|
586
|
+
const timed = own.filter((element) => isClip(element));
|
|
587
|
+
const ids = new Map;
|
|
588
|
+
for (const element of timed) {
|
|
589
|
+
const id = attribute(element, "id");
|
|
590
|
+
if (id && !ids.has(id))
|
|
591
|
+
ids.set(id, element);
|
|
592
|
+
}
|
|
593
|
+
const clips = [];
|
|
594
|
+
const resolved = new Map;
|
|
595
|
+
const startOf = (element, seen) => {
|
|
596
|
+
const known = resolved.get(element);
|
|
597
|
+
if (known)
|
|
598
|
+
return known.startMs;
|
|
599
|
+
const written = attribute(element, "data-start")?.trim() ?? "";
|
|
600
|
+
return clipStart(written, (name) => {
|
|
601
|
+
const other = ids.get(name);
|
|
602
|
+
if (!other || seen.has(other))
|
|
603
|
+
return;
|
|
604
|
+
seen.add(other);
|
|
605
|
+
const start = startOf(other, seen);
|
|
606
|
+
const duration = readMs(attribute(other, "data-duration"));
|
|
607
|
+
return duration === undefined ? undefined : start + duration;
|
|
608
|
+
});
|
|
609
|
+
};
|
|
610
|
+
timed.forEach((element, index) => {
|
|
611
|
+
const id = attribute(element, "id")?.trim() || undefined;
|
|
612
|
+
const kind = clipKind(element);
|
|
613
|
+
const className = attribute(element, "class") ?? "";
|
|
614
|
+
const durationMs = readMs(attribute(element, "data-duration"));
|
|
615
|
+
const volume = readNumber(attribute(element, "data-volume"));
|
|
616
|
+
const fadeInMs = readMs(attribute(element, "data-fade-in"));
|
|
617
|
+
const fadeOutMs = readMs(attribute(element, "data-fade-out"));
|
|
618
|
+
const src = attribute(element, "src")?.trim();
|
|
619
|
+
const text = kind === "text" ? styledWordsOf(element) : undefined;
|
|
620
|
+
const continues = attribute(element, "data-continues")?.trim();
|
|
621
|
+
const clip = {
|
|
622
|
+
ref: id ?? `#${index}`,
|
|
623
|
+
...id ? { id } : {},
|
|
624
|
+
tag: element.tagName,
|
|
625
|
+
kind,
|
|
626
|
+
track: kind === "audio" ? "sound" : kind === "text" ? "text" : "picture",
|
|
627
|
+
caption: /\bcaptions?\b/.test(className),
|
|
628
|
+
startMs: startOf(element, new Set([element])),
|
|
629
|
+
...durationMs === undefined ? {} : { durationMs },
|
|
630
|
+
mediaStartMs: readMs(attribute(element, "data-media-start")) ?? 0,
|
|
631
|
+
...src ? { src } : {},
|
|
632
|
+
...volume === undefined ? {} : { volume },
|
|
633
|
+
...fadeInMs === undefined ? {} : { fadeInMs },
|
|
634
|
+
...fadeOutMs === undefined ? {} : { fadeOutMs },
|
|
635
|
+
silent: kind === "audio" && has(element, "muted") || kind === "video" && (has(element, "muted") || has(element, "data-has-audio") && !hasAudio(element)),
|
|
636
|
+
...text === undefined ? {} : { text },
|
|
637
|
+
...continues ? { continues } : {},
|
|
638
|
+
source: sourceOf(element)
|
|
639
|
+
};
|
|
640
|
+
resolved.set(element, clip);
|
|
641
|
+
clips.push(clip);
|
|
642
|
+
});
|
|
643
|
+
const counts = new Map;
|
|
644
|
+
const texts = own.flatMap((element) => {
|
|
645
|
+
const text = TEXT_TAGS.has(element.tagName) ? wordsOf(element) : undefined;
|
|
646
|
+
if (text === undefined)
|
|
647
|
+
return [];
|
|
648
|
+
const place = counts.get(element.tagName) ?? 0;
|
|
649
|
+
counts.set(element.tagName, place + 1);
|
|
650
|
+
const id = attribute(element, "id")?.trim();
|
|
651
|
+
const className = attribute(element, "class")?.trim();
|
|
652
|
+
return [
|
|
653
|
+
{
|
|
654
|
+
ref: id || `${element.tagName}:${place}`,
|
|
655
|
+
tag: element.tagName,
|
|
656
|
+
text,
|
|
657
|
+
...className ? { className } : {},
|
|
658
|
+
timed: has(element, "data-start"),
|
|
659
|
+
source: sourceOf(element)
|
|
660
|
+
}
|
|
661
|
+
];
|
|
662
|
+
});
|
|
663
|
+
const children = composition.childNodes.filter((node) => ("tagName" in node)).map((element) => ({ tag: element.tagName, source: sourceOf(element) }));
|
|
664
|
+
return { clips, texts, composition: sourceOf(composition), children };
|
|
665
|
+
}
|
|
666
|
+
var SAME_MS = 15;
|
|
667
|
+
var FRAME_MS = 42;
|
|
668
|
+
function videoChains(scenes, timelineOf) {
|
|
669
|
+
const files = new Map;
|
|
670
|
+
for (const scene of scenes)
|
|
671
|
+
if (!files.has(scene.src))
|
|
672
|
+
files.set(scene.src, scene);
|
|
673
|
+
const parts = [];
|
|
674
|
+
const written = new Map;
|
|
675
|
+
for (const [file, scene] of files) {
|
|
676
|
+
for (const clip of timelineOf(file)?.clips ?? []) {
|
|
677
|
+
if (clip.id)
|
|
678
|
+
written.set(clip.id, (written.get(clip.id) ?? 0) + 1);
|
|
679
|
+
if (clip.durationMs === undefined)
|
|
680
|
+
continue;
|
|
681
|
+
const startMs = scene.startMs + clip.startMs;
|
|
682
|
+
parts.push({ file, clip, startMs, endMs: startMs + clip.durationMs });
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
const byId = new Map(parts.flatMap((part) => part.clip.id && written.get(part.clip.id) === 1 ? [[part.clip.id, part]] : []));
|
|
686
|
+
const sceneOf = (part) => files.get(part.file);
|
|
687
|
+
const chains = [];
|
|
688
|
+
const following = new Map;
|
|
689
|
+
for (const part of parts) {
|
|
690
|
+
if (!part.clip.continues)
|
|
691
|
+
continue;
|
|
692
|
+
following.set(part.clip.continues, [...following.get(part.clip.continues) ?? [], part]);
|
|
693
|
+
}
|
|
694
|
+
for (const [id, after] of following) {
|
|
695
|
+
const left = after.sort((a, b) => a.startMs - b.startMs);
|
|
696
|
+
const head = byId.get(id);
|
|
697
|
+
let start = head ?? left.shift();
|
|
698
|
+
while (start) {
|
|
699
|
+
const chain = [start];
|
|
700
|
+
for (;; ) {
|
|
701
|
+
const last = chain[chain.length - 1];
|
|
702
|
+
const next = left.filter((part) => goesOn(scenes, last, part, sceneOf));
|
|
703
|
+
const found = next.find((part) => playsOn(last, part)) ?? next.find((part) => part.file === last.file) ?? next[0];
|
|
704
|
+
if (!found)
|
|
705
|
+
break;
|
|
706
|
+
chain.push(...left.splice(left.indexOf(found), 1));
|
|
707
|
+
}
|
|
708
|
+
if (chain.length > 1)
|
|
709
|
+
chains.push({ parts: chain });
|
|
710
|
+
start = left.shift();
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
return chains.sort((a, b) => (a.parts[0]?.startMs ?? 0) - (b.parts[0]?.startMs ?? 0));
|
|
714
|
+
}
|
|
715
|
+
function sceneAfter(scenes, scene) {
|
|
716
|
+
const chapters = videoChapters(scenes);
|
|
717
|
+
const end = scene.startMs + scene.durationMs;
|
|
718
|
+
const onTop = chapters.filter((each) => each !== scene && each.startMs <= end && end < each.startMs + each.durationMs).at(-1);
|
|
719
|
+
return onTop ?? chapters.find((each) => each !== scene && each.startMs >= end);
|
|
720
|
+
}
|
|
721
|
+
function videoChapters(scenes) {
|
|
722
|
+
const end = (scene) => scene.startMs + scene.durationMs;
|
|
723
|
+
const holds = (outer, inner) => outer.startMs <= inner.startMs && end(inner) <= end(outer);
|
|
724
|
+
const within = (outer, inner, outerAt, innerAt) => holds(outer, inner) && (!holds(inner, outer) || innerAt < outerAt);
|
|
725
|
+
return scenes.filter((scene, at) => {
|
|
726
|
+
const others = scenes.filter((other) => other !== scene);
|
|
727
|
+
if (others.length === 0)
|
|
728
|
+
return true;
|
|
729
|
+
const held = others.filter((other) => within(scene, other, at, scenes.indexOf(other)));
|
|
730
|
+
if (held.length >= 2)
|
|
731
|
+
return false;
|
|
732
|
+
const first = Math.min(...others.map((other) => other.startMs));
|
|
733
|
+
const last = Math.max(...others.map(end));
|
|
734
|
+
const spans = scene.startMs <= first && last <= end(scene);
|
|
735
|
+
return !(others.length >= 2 && spans && held.length === others.length);
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
function goesOn(scenes, previous, next, sceneOf) {
|
|
739
|
+
const [a, b] = [previous.clip, next.clip];
|
|
740
|
+
if (a.tag !== b.tag || a.src !== b.src || a.text !== b.text)
|
|
741
|
+
return false;
|
|
742
|
+
const recording = b.kind === "video" || b.kind === "audio";
|
|
743
|
+
if (previous.file === next.file) {
|
|
744
|
+
return recording && Math.abs(next.startMs - previous.endMs) <= FRAME_MS;
|
|
745
|
+
}
|
|
746
|
+
const before = sceneOf(previous);
|
|
747
|
+
const after = sceneOf(next);
|
|
748
|
+
if (!before || !after || sceneAfter(scenes, before) !== after)
|
|
749
|
+
return false;
|
|
750
|
+
const sceneEnd = before.startMs + before.durationMs;
|
|
751
|
+
const from = Math.max(Math.min(previous.endMs, sceneEnd), after.startMs);
|
|
752
|
+
if (recording) {
|
|
753
|
+
const reaches = previous.endMs >= sceneEnd - FRAME_MS;
|
|
754
|
+
return (reaches || playsOn(previous, next)) && next.startMs <= Math.max(sceneEnd, after.startMs) + FRAME_MS;
|
|
755
|
+
}
|
|
756
|
+
if (previous.endMs < sceneEnd - SAME_MS)
|
|
757
|
+
return false;
|
|
758
|
+
return Math.abs(next.startMs - from) <= SAME_MS;
|
|
759
|
+
}
|
|
760
|
+
function goesOnFrom(scenes, previous, next) {
|
|
761
|
+
const sceneOf = (part) => scenes.find((scene) => scene.src === part.file);
|
|
762
|
+
return goesOn(scenes, previous, next, sceneOf);
|
|
763
|
+
}
|
|
764
|
+
function playsOn(previous, next) {
|
|
765
|
+
const stops = previous.clip.mediaStartMs + (previous.clip.durationMs ?? 0);
|
|
766
|
+
return Math.abs(next.clip.mediaStartMs - stops) <= SAME_MS;
|
|
767
|
+
}
|
|
768
|
+
function nests(element) {
|
|
769
|
+
return has(element, "data-composition-id") || has(element, "data-composition-src");
|
|
770
|
+
}
|
|
771
|
+
function isClip(element) {
|
|
772
|
+
if (has(element, "data-composition-src"))
|
|
773
|
+
return false;
|
|
774
|
+
return has(element, "data-start") || element.tagName === "video" || element.tagName === "audio";
|
|
775
|
+
}
|
|
776
|
+
function clipKind(element) {
|
|
777
|
+
switch (element.tagName) {
|
|
778
|
+
case "video":
|
|
779
|
+
return "video";
|
|
780
|
+
case "audio":
|
|
781
|
+
return "audio";
|
|
782
|
+
case "img":
|
|
783
|
+
case "picture":
|
|
784
|
+
case "svg":
|
|
785
|
+
return "image";
|
|
786
|
+
default:
|
|
787
|
+
return styledWordsOf(element) === undefined ? "element" : "text";
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
function clipStart(written, endOf) {
|
|
791
|
+
if (written === "")
|
|
792
|
+
return 0;
|
|
793
|
+
const seconds = Number(written);
|
|
794
|
+
if (Number.isFinite(seconds))
|
|
795
|
+
return Math.max(0, Math.round(seconds * 1000));
|
|
796
|
+
const offset = /^(.*?)\s*([+-])\s*((?:\d*\.)?\d+)$/.exec(written);
|
|
797
|
+
const name = offset ? offset[1] ?? "" : written;
|
|
798
|
+
const shift = offset ? (offset[2] === "-" ? -1 : 1) * Number(offset[3]) * 1000 : 0;
|
|
799
|
+
const end = endOf(name);
|
|
800
|
+
return end === undefined ? 0 : Math.max(0, Math.round(end + shift));
|
|
801
|
+
}
|
|
802
|
+
function hasAudio(element) {
|
|
803
|
+
return attribute(element, "data-has-audio")?.trim() === "true";
|
|
804
|
+
}
|
|
805
|
+
function styledWordsOf(element) {
|
|
806
|
+
const collect = (node) => {
|
|
807
|
+
let words = "";
|
|
808
|
+
for (const child of node.childNodes) {
|
|
809
|
+
if ("tagName" in child) {
|
|
810
|
+
if (LINE_BREAKS.has(child.tagName)) {
|
|
811
|
+
words += " ";
|
|
812
|
+
continue;
|
|
813
|
+
}
|
|
814
|
+
if (!INLINE_STYLES.has(child.tagName))
|
|
815
|
+
return;
|
|
816
|
+
const inner = collect(child);
|
|
817
|
+
if (inner === undefined)
|
|
818
|
+
return;
|
|
819
|
+
words += inner;
|
|
820
|
+
} else if (child.nodeName === "#text" && "value" in child) {
|
|
821
|
+
words += child.value;
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
return words;
|
|
825
|
+
};
|
|
826
|
+
const text = collect(element)?.replace(/\s+/g, " ").trim();
|
|
827
|
+
return text === undefined || text === "" ? undefined : text;
|
|
828
|
+
}
|
|
829
|
+
function wordsOf(element) {
|
|
830
|
+
let words = "";
|
|
831
|
+
for (const node of element.childNodes) {
|
|
832
|
+
if ("tagName" in node) {
|
|
833
|
+
if (!LINE_BREAKS.has(node.tagName))
|
|
834
|
+
return;
|
|
835
|
+
words += " ";
|
|
836
|
+
} else if (node.nodeName === "#text" && "value" in node) {
|
|
837
|
+
words += node.value;
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
const text = words.replace(/\s+/g, " ").trim();
|
|
841
|
+
return text === "" ? undefined : text;
|
|
842
|
+
}
|
|
843
|
+
function sourceOf(element) {
|
|
844
|
+
const location = element.sourceCodeLocation;
|
|
845
|
+
const span = (at) => ({
|
|
846
|
+
start: at?.startOffset ?? 0,
|
|
847
|
+
end: at?.endOffset ?? 0
|
|
848
|
+
});
|
|
849
|
+
const tag = span(location?.startTag);
|
|
850
|
+
const end = location?.endTag;
|
|
851
|
+
return {
|
|
852
|
+
element: span(location ?? undefined),
|
|
853
|
+
tag,
|
|
854
|
+
attributes: Object.fromEntries(Object.entries(location?.attrs ?? {}).map(([name, at]) => [name, span(at)])),
|
|
855
|
+
...end && end.startOffset >= tag.end ? { content: { start: tag.end, end: end.startOffset } } : {}
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
function readMs(written) {
|
|
859
|
+
const seconds = readNumber(written);
|
|
860
|
+
return seconds === undefined || seconds < 0 ? undefined : Math.round(seconds * 1000);
|
|
861
|
+
}
|
|
862
|
+
function readNumber(written) {
|
|
863
|
+
const trimmed = written?.trim() ?? "";
|
|
864
|
+
if (trimmed === "")
|
|
865
|
+
return;
|
|
866
|
+
const value = Number(trimmed);
|
|
867
|
+
return Number.isFinite(value) ? value : undefined;
|
|
868
|
+
}
|
|
869
|
+
function elements(nodes, options = {}) {
|
|
870
|
+
const found = [];
|
|
871
|
+
const visit = (children) => {
|
|
872
|
+
for (const node of children) {
|
|
873
|
+
if (!("tagName" in node))
|
|
874
|
+
continue;
|
|
875
|
+
found.push(node);
|
|
876
|
+
if (options.stop?.(node))
|
|
877
|
+
continue;
|
|
878
|
+
visit(node.childNodes);
|
|
879
|
+
if (node.tagName === "template")
|
|
880
|
+
visit(contentOf(node));
|
|
881
|
+
}
|
|
882
|
+
};
|
|
883
|
+
visit(nodes);
|
|
884
|
+
return found;
|
|
885
|
+
}
|
|
886
|
+
function contentOf(element) {
|
|
887
|
+
return "content" in element ? element.content.childNodes : [];
|
|
888
|
+
}
|
|
889
|
+
function attribute(element, name) {
|
|
890
|
+
return element.attrs.find((each) => each.name === name)?.value;
|
|
891
|
+
}
|
|
892
|
+
function has(element, name) {
|
|
893
|
+
return element.attrs.some((each) => each.name === name);
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
// src/artifacts/video/edit.ts
|
|
897
|
+
var MAX_VOLUME = 4;
|
|
898
|
+
var MIN_CLIP_MS = 100;
|
|
899
|
+
var SAME_MS2 = 15;
|
|
900
|
+
function videoTarget(element) {
|
|
901
|
+
if ("id" in element && element.id)
|
|
902
|
+
return element.ref;
|
|
903
|
+
return {
|
|
904
|
+
ref: element.ref,
|
|
905
|
+
tag: element.tag,
|
|
906
|
+
...element.text === undefined ? {} : { words: element.text },
|
|
907
|
+
..."src" in element && element.src ? { src: element.src } : {}
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
function setSceneLength(sources, scene, ms) {
|
|
911
|
+
return run(sources, (work) => {
|
|
912
|
+
if (!(ms >= MIN_CLIP_MS))
|
|
913
|
+
throw new EditError(`A scene lasts at least ${MIN_CLIP_MS} ms.`);
|
|
914
|
+
lengthenScene(work, scene, videoSceneLength(ms, rootOf(work).fps));
|
|
915
|
+
});
|
|
916
|
+
}
|
|
917
|
+
function videoSceneLength(ms, fps) {
|
|
918
|
+
const step = frameStepMs(fps);
|
|
919
|
+
return Math.max(Math.ceil(MIN_CLIP_MS / step), Math.round(ms / step)) * step;
|
|
920
|
+
}
|
|
921
|
+
function setSceneLabel(sources, scene, label) {
|
|
922
|
+
return run(sources, (work) => {
|
|
923
|
+
const named = label.replace(/\s+/g, " ").trim().slice(0, ARTIFACT_LIMITS2.maxTitleLength);
|
|
924
|
+
const host = hostOf(work, scene);
|
|
925
|
+
setAttributes(work, VIDEO_ENTRY2, host.host, { "data-label": named === "" ? null : named });
|
|
926
|
+
});
|
|
927
|
+
}
|
|
928
|
+
function moveScene(sources, scene, to) {
|
|
929
|
+
return run(sources, (work) => {
|
|
930
|
+
const before = openRoot(work);
|
|
931
|
+
const chapters = videoChapters(before.scenes);
|
|
932
|
+
const moving = before.scenes.find((each) => each.id === scene);
|
|
933
|
+
if (!moving)
|
|
934
|
+
throw new EditError(noScene(scene));
|
|
935
|
+
if (!chapters.includes(moving)) {
|
|
936
|
+
throw new EditError(`'${scene}' is laid over the other scenes: it plays in no order of theirs.`);
|
|
937
|
+
}
|
|
938
|
+
const order = [...before.scenes];
|
|
939
|
+
const from = order.indexOf(moving);
|
|
940
|
+
const target = Math.min(Math.max(Math.round(to), 0), order.length - 1);
|
|
941
|
+
if (target === from)
|
|
942
|
+
return;
|
|
943
|
+
order.splice(from, 1);
|
|
944
|
+
order.splice(target, 0, moving);
|
|
945
|
+
for (const scene of before.scenes) {
|
|
946
|
+
if (chapters.includes(scene) || scene.start.type !== "after")
|
|
947
|
+
continue;
|
|
948
|
+
setAttributes(work, VIDEO_ENTRY2, hostOf(work, scene.id).host, {
|
|
949
|
+
"data-start": seconds(scene.startMs)
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
const played = order.filter((each) => chapters.includes(each));
|
|
953
|
+
const was = new Map(chapters.map((each, index) => [each.id, chapters[index - 1]?.id]));
|
|
954
|
+
const changed = played.findIndex((each, index) => was.get(each.id) !== played[index - 1]?.id);
|
|
955
|
+
if (changed < 0)
|
|
956
|
+
return;
|
|
957
|
+
played.forEach((each, index) => {
|
|
958
|
+
const after = played[index - 1];
|
|
959
|
+
const kept = was.get(each.id) === after?.id;
|
|
960
|
+
if (kept && (index < changed || each.start.type === "after"))
|
|
961
|
+
return;
|
|
962
|
+
const start = after ? chainedStart(after.id, gapBefore(chapters, each)) : "0";
|
|
963
|
+
setAttributes(work, VIDEO_ENTRY2, hostOf(work, each.id).host, { "data-start": start });
|
|
964
|
+
});
|
|
965
|
+
restack(work);
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
function duplicateScene(sources, scene) {
|
|
969
|
+
let copy;
|
|
970
|
+
const result = run(sources, (work) => {
|
|
971
|
+
const chains = chainsOf(work);
|
|
972
|
+
const before = openRoot(work);
|
|
973
|
+
const original = hostOf(work, scene);
|
|
974
|
+
const taken = takenNames(work);
|
|
975
|
+
const id = uniqueName(scene, taken);
|
|
976
|
+
copy = id;
|
|
977
|
+
taken.add(id);
|
|
978
|
+
const folder = original.src.includes("/") ? original.src.slice(0, original.src.lastIndexOf("/") + 1) : "";
|
|
979
|
+
const src = uniquePath(work, `${folder}${id}`, ".html");
|
|
980
|
+
work.create(src, copySceneFile(work.text(original.src), scene, id, taken));
|
|
981
|
+
const index = work.text(VIDEO_ENTRY2);
|
|
982
|
+
const block = lineBlock(index, original.host.element);
|
|
983
|
+
const host = withAttributes(index.slice(original.host.element.start, original.host.element.end), {
|
|
984
|
+
"data-composition-id": id,
|
|
985
|
+
"data-composition-src": src,
|
|
986
|
+
"data-start": scene,
|
|
987
|
+
...original.host.attributes.id ? { id } : {}
|
|
988
|
+
});
|
|
989
|
+
const indent = index.slice(block.start, original.host.element.start);
|
|
990
|
+
work.replace(VIDEO_ENTRY2, block.end, block.end, `${indent}${host}${lineEnd(index, block)}`);
|
|
991
|
+
const place = before.scenes.findIndex((each) => each.id === scene);
|
|
992
|
+
const length = before.scenes[place]?.durationMs ?? 0;
|
|
993
|
+
before.scenes.forEach((each, index) => {
|
|
994
|
+
if (index <= place)
|
|
995
|
+
return;
|
|
996
|
+
if (startsAfter(each.start, original)) {
|
|
997
|
+
const offset = each.start.type === "after" ? each.start.offset : 0;
|
|
998
|
+
setAttributes(work, VIDEO_ENTRY2, hostOf(work, each.id).host, {
|
|
999
|
+
"data-start": chainedStart(id, offset)
|
|
1000
|
+
});
|
|
1001
|
+
} else if (each.start.type === "at") {
|
|
1002
|
+
setAttributes(work, VIDEO_ENTRY2, hostOf(work, each.id).host, {
|
|
1003
|
+
"data-start": seconds(each.startMs + length)
|
|
1004
|
+
});
|
|
1005
|
+
}
|
|
1006
|
+
});
|
|
1007
|
+
strandedParts(work, chains);
|
|
1008
|
+
});
|
|
1009
|
+
return "edit" in result && copy ? { ...result, scene: copy } : result;
|
|
1010
|
+
}
|
|
1011
|
+
function removeScene(sources, scene) {
|
|
1012
|
+
return run(sources, (work) => {
|
|
1013
|
+
const chains = chainsOf(work);
|
|
1014
|
+
openRoot(work);
|
|
1015
|
+
dropScene(work, scene);
|
|
1016
|
+
strandedParts(work, chains);
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
1019
|
+
function strandedParts(work, before) {
|
|
1020
|
+
const after = new Set([...chainsOf(work).keys()]);
|
|
1021
|
+
for (const [key, chain] of before) {
|
|
1022
|
+
const [file] = key.split(`
|
|
1023
|
+
`);
|
|
1024
|
+
const part = chain.parts.find((each) => `${each.file}
|
|
1025
|
+
${each.clip.ref}` === key);
|
|
1026
|
+
if (!file || !part || part === chain.parts[0] || after.has(key))
|
|
1027
|
+
continue;
|
|
1028
|
+
if (work.textOf(file) === undefined || !part.clip.id)
|
|
1029
|
+
continue;
|
|
1030
|
+
const now = readTimeline(work, file)?.clips.find((clip) => clip.id === part.clip.id);
|
|
1031
|
+
if (now?.continues)
|
|
1032
|
+
setAttributes(work, file, now.source, { "data-continues": null });
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
function setClipTiming(sources, file, clip, timing) {
|
|
1036
|
+
return run(sources, (work) => {
|
|
1037
|
+
const found = clipOf(work, file, clip);
|
|
1038
|
+
const { startMs, durationMs, mediaStartMs } = timing;
|
|
1039
|
+
if (startMs !== undefined && !(startMs >= 0))
|
|
1040
|
+
throw new EditError("A clip starts at 0 or later.");
|
|
1041
|
+
if (durationMs !== undefined && !(durationMs >= MIN_CLIP_MS)) {
|
|
1042
|
+
throw new EditError(`A clip lasts at least ${MIN_CLIP_MS} ms.`);
|
|
1043
|
+
}
|
|
1044
|
+
if (mediaStartMs !== undefined && !(mediaStartMs >= 0)) {
|
|
1045
|
+
throw new EditError("A clip plays its file from 0 or later.");
|
|
1046
|
+
}
|
|
1047
|
+
const chain = chainsOf(work).get(`${file}
|
|
1048
|
+
${found.ref}`);
|
|
1049
|
+
if (mediaStartMs !== undefined && playsFile(found) && chain) {
|
|
1050
|
+
const by = mediaStartMs - found.mediaStartMs;
|
|
1051
|
+
if (chain.parts.some((part) => part.clip.mediaStartMs + by < 0)) {
|
|
1052
|
+
throw new EditError("A clip plays its file from 0 or later.");
|
|
1053
|
+
}
|
|
1054
|
+
for (const part of chain.parts) {
|
|
1055
|
+
if (part.file === file)
|
|
1056
|
+
continue;
|
|
1057
|
+
setAttributes(work, part.file, clipOf(work, part.file, part.clip.ref).source, {
|
|
1058
|
+
"data-media-start": seconds(part.clip.mediaStartMs + by)
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
setAttributes(work, file, clipOf(work, file, found.ref).source, {
|
|
1063
|
+
...startMs === undefined ? {} : { "data-start": seconds(startMs) },
|
|
1064
|
+
...durationMs === undefined ? {} : { "data-duration": seconds(durationMs) },
|
|
1065
|
+
...mediaStartMs === undefined || !playsFile(found) ? {} : { "data-media-start": seconds(mediaStartMs) }
|
|
1066
|
+
});
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
function trimClip(sources, file, clip, edge, toMs, options = {}) {
|
|
1070
|
+
return placing(sources, (work) => {
|
|
1071
|
+
const found = clipOf(work, file, clip);
|
|
1072
|
+
const end = clipEnd(found, options.endMs);
|
|
1073
|
+
const offsetMs = videoStartOf(work, file, found) - found.startMs;
|
|
1074
|
+
const chains = file === VIDEO_ENTRY2 ? new Map : chainsOf(work);
|
|
1075
|
+
const logical = logicalClip(work, chains, { file, clip: found });
|
|
1076
|
+
if (edge === "end") {
|
|
1077
|
+
if (options.ripple || file === VIDEO_ENTRY2) {
|
|
1078
|
+
const length = Math.round(toMs) - found.startMs;
|
|
1079
|
+
if (length < MIN_CLIP_MS)
|
|
1080
|
+
throw new EditError(`A clip lasts at least ${MIN_CLIP_MS} ms.`);
|
|
1081
|
+
if (length === found.durationMs)
|
|
1082
|
+
return;
|
|
1083
|
+
setAttributes(work, file, found.source, { "data-duration": seconds(length) });
|
|
1084
|
+
if (options.ripple)
|
|
1085
|
+
ripple(work, file, end, found.startMs + length - end, new Set([found.ref]));
|
|
1086
|
+
return;
|
|
1087
|
+
}
|
|
1088
|
+
const length = offsetMs + Math.round(toMs) - logical.startMs;
|
|
1089
|
+
if (length < MIN_CLIP_MS)
|
|
1090
|
+
throw new EditError(`A clip lasts at least ${MIN_CLIP_MS} ms.`);
|
|
1091
|
+
if (length === logical.durationMs)
|
|
1092
|
+
return;
|
|
1093
|
+
return placeFound(work, [{ ...logical, durationMs: length }]);
|
|
1094
|
+
}
|
|
1095
|
+
if ((logical.others?.length ?? 0) > 0 && !options.ripple) {
|
|
1096
|
+
const head = sceneOf(work, logical.file);
|
|
1097
|
+
const into = logical.clip.mediaStartMs;
|
|
1098
|
+
const floor = Math.max(head?.startMs ?? 0, playsFile(logical.clip) ? logical.startMs - into : head?.startMs ?? 0);
|
|
1099
|
+
const startMs = Math.max(offsetMs + Math.round(toMs), floor);
|
|
1100
|
+
const endMs = logical.startMs + (logical.durationMs ?? 0);
|
|
1101
|
+
if (endMs - startMs < MIN_CLIP_MS) {
|
|
1102
|
+
throw new EditError(`A clip lasts at least ${MIN_CLIP_MS} ms.`);
|
|
1103
|
+
}
|
|
1104
|
+
if (startMs === logical.startMs)
|
|
1105
|
+
return;
|
|
1106
|
+
return placeFound(work, [
|
|
1107
|
+
{
|
|
1108
|
+
...logical,
|
|
1109
|
+
startMs,
|
|
1110
|
+
durationMs: endMs - startMs,
|
|
1111
|
+
...jumpsFrom(into, logical.jumps, startMs - logical.startMs)
|
|
1112
|
+
}
|
|
1113
|
+
]);
|
|
1114
|
+
}
|
|
1115
|
+
const floors = [playsFile(found) ? -found.mediaStartMs : -found.startMs];
|
|
1116
|
+
if (!options.ripple)
|
|
1117
|
+
floors.push(-found.startMs);
|
|
1118
|
+
const moved = Math.max(Math.round(toMs) - found.startMs, ...floors);
|
|
1119
|
+
if (end - (found.startMs + moved) < MIN_CLIP_MS) {
|
|
1120
|
+
throw new EditError(`A clip lasts at least ${MIN_CLIP_MS} ms.`);
|
|
1121
|
+
}
|
|
1122
|
+
setAttributes(work, file, found.source, {
|
|
1123
|
+
...options.ripple ? {} : { "data-start": seconds(found.startMs + moved) },
|
|
1124
|
+
"data-duration": seconds(end - found.startMs - moved),
|
|
1125
|
+
...playsFile(found) ? { "data-media-start": seconds(found.mediaStartMs + moved) } : {}
|
|
1126
|
+
});
|
|
1127
|
+
if (options.ripple)
|
|
1128
|
+
ripple(work, file, end, -moved, new Set([found.ref]));
|
|
1129
|
+
return;
|
|
1130
|
+
});
|
|
1131
|
+
}
|
|
1132
|
+
function moveClip(sources, file, clip, startMs) {
|
|
1133
|
+
return placing(sources, (work) => {
|
|
1134
|
+
const found = clipOf(work, file, clip);
|
|
1135
|
+
return moveFound(work, [{ file, clip: found }], Math.round(startMs) - found.startMs);
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
function setClipSound(sources, file, clip, sound) {
|
|
1139
|
+
return run(sources, (work) => {
|
|
1140
|
+
const found = clipOf(work, file, clip);
|
|
1141
|
+
if (found.kind !== "video" && found.kind !== "audio") {
|
|
1142
|
+
throw new EditError(`'${found.ref}' plays no sound.`);
|
|
1143
|
+
}
|
|
1144
|
+
if (sound.muted !== undefined && found.kind !== "video") {
|
|
1145
|
+
throw new EditError(`'${found.ref}' is a sound: turn its volume down instead.`);
|
|
1146
|
+
}
|
|
1147
|
+
const { volume, fadeInMs, fadeOutMs } = sound;
|
|
1148
|
+
const loudest = Math.max(MAX_VOLUME, found.volume ?? 1);
|
|
1149
|
+
if (volume !== undefined && !(volume >= 0 && volume <= loudest)) {
|
|
1150
|
+
throw new EditError(`A clip's volume is from 0 to ${loudest}.`);
|
|
1151
|
+
}
|
|
1152
|
+
for (const fade of [fadeInMs, fadeOutMs]) {
|
|
1153
|
+
if (fade !== undefined && !(fade >= 0))
|
|
1154
|
+
throw new EditError("A fade lasts 0 s or more.");
|
|
1155
|
+
}
|
|
1156
|
+
const parts = chainsOf(work).get(`${file}
|
|
1157
|
+
${found.ref}`)?.parts ?? [
|
|
1158
|
+
{ file, clip: found, startMs: 0, endMs: 0 }
|
|
1159
|
+
];
|
|
1160
|
+
parts.forEach((part, index) => {
|
|
1161
|
+
setAttributes(work, part.file, clipOf(work, part.file, part.clip.ref).source, {
|
|
1162
|
+
...volume === undefined ? {} : { "data-volume": String(Math.round(volume * 100) / 100) },
|
|
1163
|
+
...fadeInMs === undefined || index > 0 ? {} : { "data-fade-in": fadeInMs === 0 ? null : seconds(fadeInMs) },
|
|
1164
|
+
...fadeOutMs === undefined || index < parts.length - 1 ? {} : { "data-fade-out": fadeOutMs === 0 ? null : seconds(fadeOutMs) },
|
|
1165
|
+
...sound.muted === undefined ? {} : sound.muted ? { muted: "", "data-has-audio": null } : { muted: null, "data-has-audio": "true" }
|
|
1166
|
+
});
|
|
1167
|
+
});
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
1170
|
+
function setVideoText(sources, file, ref, text) {
|
|
1171
|
+
return run(sources, (work) => {
|
|
1172
|
+
const found = resolveTarget(timelineOf2(work, file).texts, ref, file, "text");
|
|
1173
|
+
if (!found.source.content)
|
|
1174
|
+
throw new EditError(`${file} shows no text '${found.ref}'.`);
|
|
1175
|
+
const words = text.trim();
|
|
1176
|
+
if (words === "")
|
|
1177
|
+
throw new EditError("A text says something: remove it instead.");
|
|
1178
|
+
const html = words.split(/\r?\n/).map((line) => escapeText(line.trim())).join("<br>");
|
|
1179
|
+
const clip = timelineOf2(work, file).clips.find((each) => each.source.element.start === found.source.element.start);
|
|
1180
|
+
const chain = clip ? chainsOf(work).get(`${file}
|
|
1181
|
+
${clip.ref}`) : undefined;
|
|
1182
|
+
for (const part of chain?.parts ?? []) {
|
|
1183
|
+
if (part.file === file)
|
|
1184
|
+
continue;
|
|
1185
|
+
const text = timelineOf2(work, part.file).texts.find((each) => each.source.element.start === part.clip.source.element.start);
|
|
1186
|
+
if (text?.source.content) {
|
|
1187
|
+
work.replace(part.file, text.source.content.start, text.source.content.end, html);
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
work.replace(file, found.source.content.start, found.source.content.end, html);
|
|
1191
|
+
});
|
|
1192
|
+
}
|
|
1193
|
+
function splitClip(sources, file, clip, atMs, options = {}) {
|
|
1194
|
+
let second;
|
|
1195
|
+
const result = run(sources, (work) => {
|
|
1196
|
+
const chains = chainsOf(work);
|
|
1197
|
+
second = splitChained(work, chains, file, clipOf(work, file, clip), atMs, options.endMs);
|
|
1198
|
+
});
|
|
1199
|
+
return "edit" in result && second ? { ...result, clip: second } : result;
|
|
1200
|
+
}
|
|
1201
|
+
function removeClip(sources, file, clip, options = {}) {
|
|
1202
|
+
return run(sources, (work) => {
|
|
1203
|
+
const found = clipOf(work, file, clip);
|
|
1204
|
+
const chain = file === VIDEO_ENTRY2 ? undefined : chainsOf(work).get(`${file}
|
|
1205
|
+
${found.ref}`);
|
|
1206
|
+
if (chain) {
|
|
1207
|
+
removeFound(work, chain.parts, options.ripple === true);
|
|
1208
|
+
return;
|
|
1209
|
+
}
|
|
1210
|
+
const end = clipEnd(found, options.endMs);
|
|
1211
|
+
if (found.id)
|
|
1212
|
+
freezeFollowers(work, file, (each) => each.id === found.id);
|
|
1213
|
+
const removed = clipOf(work, file, clip);
|
|
1214
|
+
const block = lineBlock(work.text(file), removed.source.element);
|
|
1215
|
+
work.replace(file, block.start, block.end, "");
|
|
1216
|
+
pruneLooks(work, file);
|
|
1217
|
+
if (options.ripple)
|
|
1218
|
+
rippleRemove(work, file, [{ startMs: found.startMs, endMs: end }]);
|
|
1219
|
+
});
|
|
1220
|
+
}
|
|
1221
|
+
function moveClips(sources, clips, deltaMs) {
|
|
1222
|
+
return placing(sources, (work) => moveFound(work, clipsOf(work, clips), deltaMs));
|
|
1223
|
+
}
|
|
1224
|
+
function removeClips(sources, clips, options = {}) {
|
|
1225
|
+
return run(sources, (work) => {
|
|
1226
|
+
const chains = chainsOf(work);
|
|
1227
|
+
const found = new Map;
|
|
1228
|
+
for (const each of clipsOf(work, clips)) {
|
|
1229
|
+
const endMs = clips[each.index]?.endMs;
|
|
1230
|
+
const parts = chains.get(`${each.file}
|
|
1231
|
+
${each.clip.ref}`)?.parts ?? [each];
|
|
1232
|
+
for (const part of parts) {
|
|
1233
|
+
found.set(`${part.file}
|
|
1234
|
+
${part.clip.ref}`, {
|
|
1235
|
+
file: part.file,
|
|
1236
|
+
clip: part.clip,
|
|
1237
|
+
...endMs === undefined ? {} : { endMs }
|
|
1238
|
+
});
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
removeFound(work, [...found.values()], options.ripple === true);
|
|
1242
|
+
});
|
|
1243
|
+
}
|
|
1244
|
+
function removeFound(work, found, ripple) {
|
|
1245
|
+
for (const [file, each] of byFile(found)) {
|
|
1246
|
+
const stretches = each.map(({ clip, endMs }) => ({
|
|
1247
|
+
startMs: clip.startMs,
|
|
1248
|
+
endMs: clipEnd(clip, endMs)
|
|
1249
|
+
}));
|
|
1250
|
+
const ids = new Set(each.flatMap(({ clip }) => clip.id ? [clip.id] : []));
|
|
1251
|
+
freezeFollowers(work, file, (clip) => clip.id !== undefined && ids.has(clip.id));
|
|
1252
|
+
rewriteClips(work, file, new Map(each.map(({ clip }) => [clip.ref, "remove"])));
|
|
1253
|
+
pruneLooks(work, file);
|
|
1254
|
+
if (ripple)
|
|
1255
|
+
rippleRemove(work, file, stretches);
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1258
|
+
function splitClips(sources, splits) {
|
|
1259
|
+
const parts = [];
|
|
1260
|
+
const result = run(sources, (work) => {
|
|
1261
|
+
const found = clipsOf(work, splits);
|
|
1262
|
+
const chains = chainsOf(work);
|
|
1263
|
+
for (const [file, each] of byFile(found)) {
|
|
1264
|
+
const lastFirst = [...each].sort((a, b) => b.clip.source.element.start - a.clip.source.element.start);
|
|
1265
|
+
for (const { clip, index } of lastFirst) {
|
|
1266
|
+
const split = splits[index];
|
|
1267
|
+
if (!split)
|
|
1268
|
+
continue;
|
|
1269
|
+
const now = clipOf(work, file, clip.ref);
|
|
1270
|
+
const second = splitChained(work, chains, file, now, split.atMs, split.endMs);
|
|
1271
|
+
if (second)
|
|
1272
|
+
parts[index] = { file, clip: second };
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
});
|
|
1276
|
+
return "edit" in result ? { ...result, clips: parts.filter((part) => part !== undefined) } : result;
|
|
1277
|
+
}
|
|
1278
|
+
function removeMediaRanges(sources, file, src, ranges, options = {}) {
|
|
1279
|
+
return run(sources, (work) => {
|
|
1280
|
+
const removed = mergeCuts(ranges);
|
|
1281
|
+
const exists = (path) => work.has(path);
|
|
1282
|
+
const recording = videoFilePath(file, src, exists) ?? src;
|
|
1283
|
+
const played = timelineOf2(work, file).clips.filter((clip) => clip.src !== undefined && (videoFilePath(file, clip.src, exists) ?? clip.src) === recording && playsFile(clip));
|
|
1284
|
+
const parts = chainParts(work, file, played);
|
|
1285
|
+
const endOf = (part) => clipEnd(part.clip, part.file === file ? options.endMs : undefined);
|
|
1286
|
+
const cuts = new Map;
|
|
1287
|
+
for (const part of parts) {
|
|
1288
|
+
const { clip } = part;
|
|
1289
|
+
const from = clip.mediaStartMs;
|
|
1290
|
+
const to = from + endOf(part) - clip.startMs;
|
|
1291
|
+
const at = (ms) => clip.startMs + Math.min(to, Math.max(from, ms)) - from;
|
|
1292
|
+
const cut = cuts.get(part.file) ?? [];
|
|
1293
|
+
cuts.set(part.file, cut);
|
|
1294
|
+
for (const range of removed) {
|
|
1295
|
+
const startMs = at(range.startMs);
|
|
1296
|
+
const endMs = at(range.endMs);
|
|
1297
|
+
if (endMs <= startMs)
|
|
1298
|
+
continue;
|
|
1299
|
+
const room = range.room ?? range;
|
|
1300
|
+
cut.push({ startMs, endMs, room: { startMs: at(room.startMs), endMs: at(room.endMs) } });
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
if ([...cuts.values()].every((cut) => cut.length === 0))
|
|
1304
|
+
return;
|
|
1305
|
+
const left = parts.some((part) => subtractRanges({ startMs: part.clip.startMs, endMs: endOf(part) }, mergeRanges(cuts.get(part.file) ?? [])).some((piece) => piece.endMs - piece.startMs >= MIN_CLIP_MS));
|
|
1306
|
+
if (!left)
|
|
1307
|
+
throw new EditError("Nothing of the recording would be left: remove it instead.");
|
|
1308
|
+
for (const [each, cut] of cuts)
|
|
1309
|
+
if (cut.length > 0)
|
|
1310
|
+
rippleRemove(work, each, cut);
|
|
1311
|
+
});
|
|
1312
|
+
}
|
|
1313
|
+
function chainParts(work, file, clips) {
|
|
1314
|
+
const chains = clips.length > 0 && file !== VIDEO_ENTRY2 ? chainsOf(work) : new Map;
|
|
1315
|
+
const parts = new Map;
|
|
1316
|
+
for (const clip of clips) {
|
|
1317
|
+
const chain = chains.get(`${file}
|
|
1318
|
+
${clip.ref}`);
|
|
1319
|
+
for (const part of chain?.parts ?? [{ file, clip }]) {
|
|
1320
|
+
parts.set(`${part.file}
|
|
1321
|
+
${part.clip.ref}`, { file: part.file, clip: part.clip });
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
return [...parts.values()];
|
|
1325
|
+
}
|
|
1326
|
+
function cutRange(sources, range) {
|
|
1327
|
+
return run(sources, (work) => {
|
|
1328
|
+
const startMs = Math.max(0, Math.round(range.startMs));
|
|
1329
|
+
const endMs = Math.round(range.endMs);
|
|
1330
|
+
if (endMs - startMs < MIN_CLIP_MS) {
|
|
1331
|
+
throw new EditError(`A cut lasts at least ${MIN_CLIP_MS} ms.`);
|
|
1332
|
+
}
|
|
1333
|
+
const scenes = [...openRoot(work).scenes].sort((a, b) => a.startMs - b.startMs);
|
|
1334
|
+
const shares = scenes.map((scene, index) => {
|
|
1335
|
+
const until = Math.min(scene.startMs + scene.durationMs, scenes[index + 1]?.startMs ?? Number.POSITIVE_INFINITY);
|
|
1336
|
+
return {
|
|
1337
|
+
scene,
|
|
1338
|
+
from: Math.max(startMs, scene.startMs),
|
|
1339
|
+
to: Math.min(endMs, until),
|
|
1340
|
+
whole: startMs <= scene.startMs + SAME_MS2 && endMs >= until - SAME_MS2
|
|
1341
|
+
};
|
|
1342
|
+
});
|
|
1343
|
+
for (const { scene, from, to, whole } of shares.reverse()) {
|
|
1344
|
+
if (to - from < SAME_MS2)
|
|
1345
|
+
continue;
|
|
1346
|
+
if (whole)
|
|
1347
|
+
dropScene(work, scene.id);
|
|
1348
|
+
else {
|
|
1349
|
+
rippleRemove(work, scene.src, [
|
|
1350
|
+
{ startMs: from - scene.startMs, endMs: to - scene.startMs }
|
|
1351
|
+
]);
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
});
|
|
1355
|
+
}
|
|
1356
|
+
function insertClip(sources, file, clip) {
|
|
1357
|
+
let added;
|
|
1358
|
+
let muted = false;
|
|
1359
|
+
const result = run(sources, (work) => {
|
|
1360
|
+
if (!sources.has(clip.src))
|
|
1361
|
+
throw new EditError(`'${clip.src}' is not one of the video's files.`);
|
|
1362
|
+
if (!(clip.durationMs >= MIN_CLIP_MS)) {
|
|
1363
|
+
throw new EditError(`A clip lasts at least ${MIN_CLIP_MS} ms.`);
|
|
1364
|
+
}
|
|
1365
|
+
const timeline = timelineOf2(work, file);
|
|
1366
|
+
const stem = clip.src.replace(/^.*\//, "").replace(/\.[^.]*$/, "");
|
|
1367
|
+
const id = uniqueName(slug(stem) || clip.kind, takenNames(work));
|
|
1368
|
+
added = id;
|
|
1369
|
+
const startMs = (sceneOf(work, file)?.startMs ?? 0) + Math.max(0, clip.startMs);
|
|
1370
|
+
muted = clip.kind === "video" && heardDuring(work, startMs, startMs + clip.durationMs);
|
|
1371
|
+
const html = clipHtml(clip.kind, {
|
|
1372
|
+
id,
|
|
1373
|
+
src: clip.src,
|
|
1374
|
+
start: seconds(Math.max(0, clip.startMs)),
|
|
1375
|
+
duration: seconds(clip.durationMs),
|
|
1376
|
+
mediaStart: seconds(clip.mediaStartMs ?? 0),
|
|
1377
|
+
muted
|
|
1378
|
+
});
|
|
1379
|
+
const track = clip.kind === "audio" ? "sound" : "picture";
|
|
1380
|
+
insertInComposition(work, file, timeline, [html], track);
|
|
1381
|
+
const found = clipOf(work, file, id);
|
|
1382
|
+
placeFound(work, [
|
|
1383
|
+
{ file, clip: found, startMs: videoStartOf(work, file, found), durationMs: clip.durationMs }
|
|
1384
|
+
]);
|
|
1385
|
+
});
|
|
1386
|
+
if (!("edit" in result) || !added)
|
|
1387
|
+
return result;
|
|
1388
|
+
return { ...result, clip: added, ...muted ? { muted: true } : {} };
|
|
1389
|
+
}
|
|
1390
|
+
function heardDuring(work, fromMs, toMs) {
|
|
1391
|
+
const heard = (clip) => (clip.kind === "audio" || clip.kind === "video") && !clip.silent && clip.volume !== 0;
|
|
1392
|
+
const during = (from, to) => from < toMs && fromMs < to;
|
|
1393
|
+
const root = rootOf(work);
|
|
1394
|
+
const chapters = { ...root, scenes: videoChapters(root.scenes) };
|
|
1395
|
+
const voiceOver = (readTimeline(work, VIDEO_ENTRY2)?.clips ?? []).some((clip) => heard(clip) && clip.durationMs !== undefined && numericStart(work, VIDEO_ENTRY2, clip) && sceneOfClip(chapters, clip) !== undefined && during(clip.startMs, clip.startMs + clip.durationMs));
|
|
1396
|
+
if (voiceOver)
|
|
1397
|
+
return true;
|
|
1398
|
+
return root.scenes.some((scene) => {
|
|
1399
|
+
if (work.textOf(scene.src) === undefined)
|
|
1400
|
+
return false;
|
|
1401
|
+
const endMs = scene.startMs + scene.durationMs;
|
|
1402
|
+
return (readTimeline(work, scene.src)?.clips ?? []).some((clip) => {
|
|
1403
|
+
if (!heard(clip))
|
|
1404
|
+
return false;
|
|
1405
|
+
const from = scene.startMs + clip.startMs;
|
|
1406
|
+
return during(from, Math.min(endMs, clip.durationMs === undefined ? endMs : from + clip.durationMs));
|
|
1407
|
+
});
|
|
1408
|
+
});
|
|
1409
|
+
}
|
|
1410
|
+
function replaceClipMedia(sources, file, clip, src) {
|
|
1411
|
+
return run(sources, (work) => {
|
|
1412
|
+
const found = clipOf(work, file, clip);
|
|
1413
|
+
const kind = found.kind;
|
|
1414
|
+
if (!found.src || kind !== "video" && kind !== "audio" && kind !== "image") {
|
|
1415
|
+
throw new EditError(`'${found.ref}' plays no file to replace.`);
|
|
1416
|
+
}
|
|
1417
|
+
const path = videoFilePath(file, src, (each) => work.has(each)) ?? src;
|
|
1418
|
+
if (sources.get(path) !== null) {
|
|
1419
|
+
throw new EditError(`'${src}' is not one of the video's recordings or pictures.`);
|
|
1420
|
+
}
|
|
1421
|
+
const replacing = mediaKind(path);
|
|
1422
|
+
if (replacing !== undefined && replacing !== kind) {
|
|
1423
|
+
throw new EditError(`'${src}' is no ${kind === "image" ? "picture" : kind}: choose one that is.`);
|
|
1424
|
+
}
|
|
1425
|
+
const parts = file === VIDEO_ENTRY2 ? [{ file, clip: found }] : chainsOf(work).get(`${file}
|
|
1426
|
+
${found.ref}`)?.parts ?? [{ file, clip: found }];
|
|
1427
|
+
let intoMs = 0;
|
|
1428
|
+
for (const part of parts) {
|
|
1429
|
+
const now = clipOf(work, part.file, part.clip.ref);
|
|
1430
|
+
setAttributes(work, part.file, now.source, {
|
|
1431
|
+
src: writtenPath(work, part.file, path, now.src?.startsWith("../") ?? false),
|
|
1432
|
+
...playsFile(now) ? { "data-media-start": seconds(intoMs) } : {}
|
|
1433
|
+
});
|
|
1434
|
+
intoMs += now.durationMs ?? 0;
|
|
1435
|
+
}
|
|
1436
|
+
});
|
|
1437
|
+
}
|
|
1438
|
+
function mediaKind(path) {
|
|
1439
|
+
const extension = /\.([^./]+)$/.exec(path)?.[1]?.toLowerCase() ?? "";
|
|
1440
|
+
if (["mp4", "mov", "m4v", "webm"].includes(extension))
|
|
1441
|
+
return "video";
|
|
1442
|
+
if (["mp3", "m4a", "wav", "aac", "ogg", "oga", "flac"].includes(extension))
|
|
1443
|
+
return "audio";
|
|
1444
|
+
if (["png", "jpg", "jpeg", "webp", "gif", "avif"].includes(extension))
|
|
1445
|
+
return "image";
|
|
1446
|
+
return;
|
|
1447
|
+
}
|
|
1448
|
+
function writtenPath(work, file, path, beside = false) {
|
|
1449
|
+
const exists = (each) => work.has(each);
|
|
1450
|
+
const up = `${"../".repeat(file.split("/").length - 1)}${path}`;
|
|
1451
|
+
const spellings = beside ? [up, path] : [path, up];
|
|
1452
|
+
return spellings.find((each) => videoFilePath(file, each, exists) === path) ?? path;
|
|
1453
|
+
}
|
|
1454
|
+
function readVideoFileTimeline(file, html) {
|
|
1455
|
+
return file === VIDEO_ENTRY2 ? readRootTimeline(html) : readSceneTimeline(html);
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1458
|
+
class EditError extends Error {
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
class Working {
|
|
1462
|
+
sources;
|
|
1463
|
+
files;
|
|
1464
|
+
opened;
|
|
1465
|
+
marking;
|
|
1466
|
+
whole = new Map;
|
|
1467
|
+
timelines = new Map;
|
|
1468
|
+
constructor(sources) {
|
|
1469
|
+
this.sources = sources;
|
|
1470
|
+
this.files = new Map(sources);
|
|
1471
|
+
}
|
|
1472
|
+
text(path) {
|
|
1473
|
+
const text = this.files.get(path);
|
|
1474
|
+
if (typeof text !== "string") {
|
|
1475
|
+
throw new EditError(`'${path}' is not one of the video's HTML files.`);
|
|
1476
|
+
}
|
|
1477
|
+
return text;
|
|
1478
|
+
}
|
|
1479
|
+
has(path) {
|
|
1480
|
+
return this.files.has(path);
|
|
1481
|
+
}
|
|
1482
|
+
textOf(path) {
|
|
1483
|
+
const text = this.files.get(path);
|
|
1484
|
+
return typeof text === "string" ? text : undefined;
|
|
1485
|
+
}
|
|
1486
|
+
paths() {
|
|
1487
|
+
return [...this.files.keys()];
|
|
1488
|
+
}
|
|
1489
|
+
replace(path, start, end, insert) {
|
|
1490
|
+
const text = this.text(path);
|
|
1491
|
+
this.files.set(path, text.slice(0, start) + insert + text.slice(end));
|
|
1492
|
+
}
|
|
1493
|
+
create(path, text) {
|
|
1494
|
+
this.files.set(path, text);
|
|
1495
|
+
}
|
|
1496
|
+
remove(path) {
|
|
1497
|
+
this.files.delete(path);
|
|
1498
|
+
}
|
|
1499
|
+
changed() {
|
|
1500
|
+
return [...this.files].flatMap(([path, text]) => typeof text === "string" && this.sources.get(path) !== text ? [path] : []);
|
|
1501
|
+
}
|
|
1502
|
+
writeWhole(path, text) {
|
|
1503
|
+
this.whole.set(path, (this.whole.get(path) ?? new Set).add(text));
|
|
1504
|
+
}
|
|
1505
|
+
result() {
|
|
1506
|
+
const edit = [];
|
|
1507
|
+
for (const [path, text] of this.files) {
|
|
1508
|
+
const before = this.sources.get(path);
|
|
1509
|
+
if (text === null || before === text)
|
|
1510
|
+
continue;
|
|
1511
|
+
if (typeof before !== "string") {
|
|
1512
|
+
edit.push({ path, create: text });
|
|
1513
|
+
continue;
|
|
1514
|
+
}
|
|
1515
|
+
edit.push({
|
|
1516
|
+
path,
|
|
1517
|
+
changes: wholeAgain(before, text, textChanges(before, text), this.whole.get(path))
|
|
1518
|
+
});
|
|
1519
|
+
}
|
|
1520
|
+
for (const path of this.sources.keys()) {
|
|
1521
|
+
if (!this.files.has(path))
|
|
1522
|
+
edit.push({ path, remove: true });
|
|
1523
|
+
}
|
|
1524
|
+
return { edit, files: this.files };
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
function wholeAgain(before, after, changes, whole) {
|
|
1528
|
+
const result = [...changes];
|
|
1529
|
+
for (const text of whole ?? []) {
|
|
1530
|
+
const start = before.indexOf(text);
|
|
1531
|
+
const end = start + text.length;
|
|
1532
|
+
if (start < 0 || !after.includes(text))
|
|
1533
|
+
continue;
|
|
1534
|
+
const inside = result.some((change) => change.remove > 0 ? change.index < end && change.index + change.remove > start : change.index > start && change.index < end);
|
|
1535
|
+
if (inside)
|
|
1536
|
+
continue;
|
|
1537
|
+
const at = result.findIndex((change) => change.remove === 0 && change.index === start);
|
|
1538
|
+
const ahead = result[at];
|
|
1539
|
+
if (ahead)
|
|
1540
|
+
result[at] = { index: start, remove: text.length, insert: ahead.insert + text };
|
|
1541
|
+
else
|
|
1542
|
+
result.push({ index: start, remove: text.length, insert: text });
|
|
1543
|
+
}
|
|
1544
|
+
return result.sort((a, b) => a.index - b.index);
|
|
1545
|
+
}
|
|
1546
|
+
function textChanges(before, after) {
|
|
1547
|
+
return diffText(before, after).flatMap((edit) => {
|
|
1548
|
+
const start = before.lastIndexOf(`
|
|
1549
|
+
`, edit.start - 1) + 1;
|
|
1550
|
+
const lineEnd = before.indexOf(`
|
|
1551
|
+
`, edit.end);
|
|
1552
|
+
const end = lineEnd < 0 ? before.length : lineEnd;
|
|
1553
|
+
const insert = before.slice(start, edit.start) + edit.insert + before.slice(edit.end, end);
|
|
1554
|
+
const removed = textLines(before.slice(start, end));
|
|
1555
|
+
const added = textLines(insert);
|
|
1556
|
+
if (removed.length !== added.length || removed.length === 0) {
|
|
1557
|
+
return [{ index: edit.start, remove: edit.end - edit.start, insert: edit.insert }];
|
|
1558
|
+
}
|
|
1559
|
+
const changes = [];
|
|
1560
|
+
let at = start;
|
|
1561
|
+
removed.forEach((line, index) => {
|
|
1562
|
+
const next = added[index] ?? "";
|
|
1563
|
+
if (!alike(line, next)) {
|
|
1564
|
+
changes.push({ index: at, remove: line.length, insert: next });
|
|
1565
|
+
at += line.length;
|
|
1566
|
+
return;
|
|
1567
|
+
}
|
|
1568
|
+
const from = tokens(line);
|
|
1569
|
+
const to = tokens(next);
|
|
1570
|
+
const fromAt = offsets(from);
|
|
1571
|
+
const toAt = offsets(to);
|
|
1572
|
+
for (const hunk of diffSequences(from, to)) {
|
|
1573
|
+
const index = fromAt[hunk.aStart] ?? 0;
|
|
1574
|
+
changes.push({
|
|
1575
|
+
index: at + index,
|
|
1576
|
+
remove: (fromAt[hunk.aEnd] ?? line.length) - index,
|
|
1577
|
+
insert: next.slice(toAt[hunk.bStart] ?? 0, toAt[hunk.bEnd] ?? next.length)
|
|
1578
|
+
});
|
|
1579
|
+
}
|
|
1580
|
+
at += line.length;
|
|
1581
|
+
});
|
|
1582
|
+
return changes;
|
|
1583
|
+
});
|
|
1584
|
+
}
|
|
1585
|
+
function tokens(line) {
|
|
1586
|
+
return line.match(/\s+[^\s"'<>/=]+=(?:"[^"]*"|'[^']*')|\s+|[A-Za-z0-9_.:+-]+|[^\sA-Za-z0-9_.:+-]/g) ?? [];
|
|
1587
|
+
}
|
|
1588
|
+
function offsets(parts) {
|
|
1589
|
+
const at = [0];
|
|
1590
|
+
for (const part of parts)
|
|
1591
|
+
at.push((at.at(-1) ?? 0) + part.length);
|
|
1592
|
+
return at;
|
|
1593
|
+
}
|
|
1594
|
+
function alike(left, right) {
|
|
1595
|
+
let head = 0;
|
|
1596
|
+
while (head < left.length && head < right.length && left[head] === right[head])
|
|
1597
|
+
head += 1;
|
|
1598
|
+
let tail = 0;
|
|
1599
|
+
while (tail < left.length - head && tail < right.length - head && left[left.length - 1 - tail] === right[right.length - 1 - tail]) {
|
|
1600
|
+
tail += 1;
|
|
1601
|
+
}
|
|
1602
|
+
return (head + tail) * 2 >= Math.max(left.length, right.length);
|
|
1603
|
+
}
|
|
1604
|
+
function run(sources, operation) {
|
|
1605
|
+
const work = new Working(sources);
|
|
1606
|
+
try {
|
|
1607
|
+
operation(work);
|
|
1608
|
+
markCutChains(work);
|
|
1609
|
+
if (work.opened || work.changed().some((path) => holdsParts(work, path)))
|
|
1610
|
+
settleChains(work);
|
|
1611
|
+
if (work.opened)
|
|
1612
|
+
fitRoot(work, work.opened);
|
|
1613
|
+
} catch (error) {
|
|
1614
|
+
if (error instanceof EditError)
|
|
1615
|
+
return { error: error.message };
|
|
1616
|
+
throw error;
|
|
1617
|
+
}
|
|
1618
|
+
const { edit, files } = work.result();
|
|
1619
|
+
const index = files.get(VIDEO_ENTRY2);
|
|
1620
|
+
if (typeof index !== "string")
|
|
1621
|
+
return { error: `A video needs '${VIDEO_ENTRY2}'.` };
|
|
1622
|
+
const read = readVideoComposition2(index, (path) => {
|
|
1623
|
+
const text = files.get(path);
|
|
1624
|
+
return typeof text === "string" ? text : undefined;
|
|
1625
|
+
});
|
|
1626
|
+
if ("error" in read)
|
|
1627
|
+
return { error: read.error };
|
|
1628
|
+
for (const scene of read.composition.scenes) {
|
|
1629
|
+
if (!readSceneTimeline(files.get(scene.src))) {
|
|
1630
|
+
return { error: `${scene.src}: a scene file is one <template> holding its composition.` };
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
const limit = ARTIFACT_LIMITS2.maxSceneBytes;
|
|
1634
|
+
for (const change of edit) {
|
|
1635
|
+
if (!/\.html?$/i.test(change.path) || "remove" in change)
|
|
1636
|
+
continue;
|
|
1637
|
+
const after = new TextEncoder().encode(files.get(change.path) ?? "").length;
|
|
1638
|
+
const before = new TextEncoder().encode(sources.get(change.path) ?? "").length;
|
|
1639
|
+
if (after > limit && after > before) {
|
|
1640
|
+
return {
|
|
1641
|
+
error: `'${change.path}' would be ${after} bytes: each of a video's HTML files holds at most ${limit}.`,
|
|
1642
|
+
refusal: "too_large"
|
|
1643
|
+
};
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
return { edit: [...edit, ...unplayed(sources, files, edit)] };
|
|
1647
|
+
}
|
|
1648
|
+
function unplayed(sources, files, edit) {
|
|
1649
|
+
const named = (path, text) => new Set([...(text ?? "").matchAll(/\ssrc\s*=\s*(["'])([^"']+)\1/gi)].flatMap((match) => {
|
|
1650
|
+
const found = videoFilePath(path, match[2] ?? "", (each) => sources.has(each));
|
|
1651
|
+
return found === undefined ? [] : [found];
|
|
1652
|
+
}));
|
|
1653
|
+
const gone = new Set;
|
|
1654
|
+
for (const change of edit) {
|
|
1655
|
+
if (!/\.html?$/i.test(change.path))
|
|
1656
|
+
continue;
|
|
1657
|
+
const now = named(change.path, files.get(change.path));
|
|
1658
|
+
for (const path of named(change.path, sources.get(change.path))) {
|
|
1659
|
+
if (!now.has(path) && sources.get(path) === null && files.has(path))
|
|
1660
|
+
gone.add(path);
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
if (gone.size === 0)
|
|
1664
|
+
return [];
|
|
1665
|
+
const texts = [...files.values()].filter((text) => typeof text === "string");
|
|
1666
|
+
return [...gone].filter((path) => {
|
|
1667
|
+
const name = path.slice(path.lastIndexOf("/") + 1);
|
|
1668
|
+
const spellings = new Set([name, encodeURIComponent(name), encodeURI(name)].flatMap((each) => [
|
|
1669
|
+
each,
|
|
1670
|
+
each.replace(/[&<>"']/g, (char) => HTML_ENTITIES[char] ?? char),
|
|
1671
|
+
each.replace(/[^\w.-]/g, (char) => `\\${char}`)
|
|
1672
|
+
]));
|
|
1673
|
+
return !texts.some((text) => [...spellings].some((spelling) => text.includes(spelling)));
|
|
1674
|
+
}).map((path) => ({ path, remove: true }));
|
|
1675
|
+
}
|
|
1676
|
+
var HTML_ENTITIES = {
|
|
1677
|
+
"&": "&",
|
|
1678
|
+
"<": "<",
|
|
1679
|
+
">": ">",
|
|
1680
|
+
'"': """,
|
|
1681
|
+
"'": "'"
|
|
1682
|
+
};
|
|
1683
|
+
function placing(sources, operation) {
|
|
1684
|
+
let placement;
|
|
1685
|
+
const result = run(sources, (work) => {
|
|
1686
|
+
placement = operation(work);
|
|
1687
|
+
});
|
|
1688
|
+
return "edit" in result && placement ? { ...result, ...placement } : result;
|
|
1689
|
+
}
|
|
1690
|
+
function rootOf(work) {
|
|
1691
|
+
const read = parseVideoRoot(work.text(VIDEO_ENTRY2));
|
|
1692
|
+
if (!("error" in read))
|
|
1693
|
+
return read.root;
|
|
1694
|
+
if (work.opened && read.error.includes("after the root composition's data-duration")) {
|
|
1695
|
+
throw new EditError(`A video lasts at most ${ARTIFACT_LIMITS2.maxVideoSeconds} s.`);
|
|
1696
|
+
}
|
|
1697
|
+
throw new EditError(read.error);
|
|
1698
|
+
}
|
|
1699
|
+
function openRoot(work) {
|
|
1700
|
+
if (work.opened)
|
|
1701
|
+
return work.opened;
|
|
1702
|
+
const before = rootOf(work);
|
|
1703
|
+
work.opened = before;
|
|
1704
|
+
if (before.root.attributes["data-duration"]) {
|
|
1705
|
+
setAttributes(work, VIDEO_ENTRY2, before.root, {
|
|
1706
|
+
"data-duration": String(ARTIFACT_LIMITS2.maxVideoSeconds)
|
|
1707
|
+
});
|
|
1708
|
+
}
|
|
1709
|
+
return before;
|
|
1710
|
+
}
|
|
1711
|
+
function hostOf(work, scene) {
|
|
1712
|
+
const found = rootOf(work).scenes.find((each) => each.id === scene);
|
|
1713
|
+
if (!found)
|
|
1714
|
+
throw new EditError(noScene(scene));
|
|
1715
|
+
return found;
|
|
1716
|
+
}
|
|
1717
|
+
function sceneOf(work, file) {
|
|
1718
|
+
if (file === VIDEO_ENTRY2)
|
|
1719
|
+
return;
|
|
1720
|
+
return rootOf(work).scenes.find((each) => each.src === file);
|
|
1721
|
+
}
|
|
1722
|
+
function noScene(scene) {
|
|
1723
|
+
return `The video has no scene '${scene}'.`;
|
|
1724
|
+
}
|
|
1725
|
+
function lengthenScene(work, scene, ms) {
|
|
1726
|
+
openRoot(work);
|
|
1727
|
+
const now = rootOf(work);
|
|
1728
|
+
const host = now.scenes.find((each) => each.id === scene);
|
|
1729
|
+
if (!host)
|
|
1730
|
+
throw new EditError(noScene(scene));
|
|
1731
|
+
const delta = ms - host.durationMs;
|
|
1732
|
+
if (delta === 0)
|
|
1733
|
+
return;
|
|
1734
|
+
const end = host.startMs + host.durationMs;
|
|
1735
|
+
setAttributes(work, VIDEO_ENTRY2, host.host, { "data-duration": seconds(ms) });
|
|
1736
|
+
for (const each of now.scenes) {
|
|
1737
|
+
if (each.id === scene || each.start.type !== "at" || each.startMs < end - SAME_MS2)
|
|
1738
|
+
continue;
|
|
1739
|
+
setAttributes(work, VIDEO_ENTRY2, hostOf(work, each.id).host, {
|
|
1740
|
+
"data-start": seconds(Math.max(0, each.startMs + delta))
|
|
1741
|
+
});
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
function dropScene(work, scene) {
|
|
1745
|
+
const now = rootOf(work);
|
|
1746
|
+
const removed = now.scenes.find((each) => each.id === scene);
|
|
1747
|
+
if (!removed)
|
|
1748
|
+
throw new EditError(noScene(scene));
|
|
1749
|
+
if (now.scenes.length === 1)
|
|
1750
|
+
throw new EditError("A video keeps at least one scene.");
|
|
1751
|
+
const end = removed.startMs + removed.durationMs;
|
|
1752
|
+
for (const each of now.scenes) {
|
|
1753
|
+
if (each.id === scene)
|
|
1754
|
+
continue;
|
|
1755
|
+
if (startsAfter(each.start, removed)) {
|
|
1756
|
+
const offset = each.start.type === "after" ? each.start.offset : 0;
|
|
1757
|
+
const start = removed.start.type === "at" ? seconds(Math.max(0, removed.startMs + offset * 1000)) : chainedStart(removed.start.scene, removed.start.offset + offset);
|
|
1758
|
+
setAttributes(work, VIDEO_ENTRY2, hostOf(work, each.id).host, { "data-start": start });
|
|
1759
|
+
} else if (each.start.type === "at" && each.startMs >= end - SAME_MS2) {
|
|
1760
|
+
setAttributes(work, VIDEO_ENTRY2, hostOf(work, each.id).host, {
|
|
1761
|
+
"data-start": seconds(each.startMs - removed.durationMs)
|
|
1762
|
+
});
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
const block = lineBlock(work.text(VIDEO_ENTRY2), hostOf(work, scene).host.element);
|
|
1766
|
+
work.replace(VIDEO_ENTRY2, block.start, block.end, "");
|
|
1767
|
+
if (!now.scenes.some((each) => each.id !== scene && each.src === removed.src)) {
|
|
1768
|
+
work.remove(removed.src);
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
function startsAfter(start, scene) {
|
|
1772
|
+
return start.type === "after" && (start.scene === scene.id || start.scene === scene.hostId);
|
|
1773
|
+
}
|
|
1774
|
+
function gapBefore(scenes, scene) {
|
|
1775
|
+
if (scene.start.type === "after")
|
|
1776
|
+
return scene.start.offset;
|
|
1777
|
+
const previous = scenes[scenes.findIndex((each) => each.id === scene.id) - 1];
|
|
1778
|
+
if (!previous)
|
|
1779
|
+
return 0;
|
|
1780
|
+
return (scene.startMs - previous.startMs - previous.durationMs) / 1000;
|
|
1781
|
+
}
|
|
1782
|
+
function chainedStart(after, offset) {
|
|
1783
|
+
const amount = Math.round(Math.abs(offset) * 1000) / 1000;
|
|
1784
|
+
if (amount === 0)
|
|
1785
|
+
return after;
|
|
1786
|
+
return `${after} ${offset < 0 ? "-" : "+"} ${amount}`;
|
|
1787
|
+
}
|
|
1788
|
+
function restack(work) {
|
|
1789
|
+
const text = work.text(VIDEO_ENTRY2);
|
|
1790
|
+
const play = rootOf(work).scenes;
|
|
1791
|
+
const line = new Map([...play].sort((a, b) => a.host.element.start - b.host.element.start).map((scene, index) => [scene.id, index]));
|
|
1792
|
+
const wanted = new Map;
|
|
1793
|
+
play.forEach((each, index) => {
|
|
1794
|
+
let least = 0;
|
|
1795
|
+
for (const below of play.slice(0, index)) {
|
|
1796
|
+
if (!together(below, each))
|
|
1797
|
+
continue;
|
|
1798
|
+
const under = wanted.get(below.id) ?? 0;
|
|
1799
|
+
const later = (line.get(each.id) ?? 0) > (line.get(below.id) ?? 0);
|
|
1800
|
+
least = Math.max(least, later ? under : under + 1);
|
|
1801
|
+
}
|
|
1802
|
+
wanted.set(each.id, least);
|
|
1803
|
+
});
|
|
1804
|
+
const writes = [];
|
|
1805
|
+
for (const scene of play) {
|
|
1806
|
+
const layer = wanted.get(scene.id) ?? 0;
|
|
1807
|
+
if (layer !== layerOf(text, scene.host))
|
|
1808
|
+
writes.push({ source: scene.host, layer });
|
|
1809
|
+
}
|
|
1810
|
+
const was = Math.max(0, ...play.map((scene) => layerOf(text, scene.host)));
|
|
1811
|
+
const top = Math.max(0, ...wanted.values());
|
|
1812
|
+
for (const source of readRootLayers(text)) {
|
|
1813
|
+
const layer = layerOf(text, source);
|
|
1814
|
+
const own = was > 0 && layer === was + 1;
|
|
1815
|
+
if (top === 0 && own)
|
|
1816
|
+
writes.push({ source, layer: 0 });
|
|
1817
|
+
else if (top > 0 && layer !== top + 1 && (own || layer <= top)) {
|
|
1818
|
+
writes.push({ source, layer: top + 1 });
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
for (const { source, layer } of writes.sort((a, b) => b.source.tag.start - a.source.tag.start)) {
|
|
1822
|
+
const style = source.attributes.style;
|
|
1823
|
+
setAttributes(work, VIDEO_ENTRY2, source, {
|
|
1824
|
+
style: withLayer(style ? attributeValue(text, style) : undefined, layer)
|
|
1825
|
+
});
|
|
1826
|
+
}
|
|
1827
|
+
}
|
|
1828
|
+
function together(a, b) {
|
|
1829
|
+
return a.startMs < b.startMs + b.durationMs - SAME_MS2 && b.startMs < a.startMs + a.durationMs - SAME_MS2;
|
|
1830
|
+
}
|
|
1831
|
+
function layerOf(text, source) {
|
|
1832
|
+
const at = source.attributes.style;
|
|
1833
|
+
const style = at ? attributeValue(text, at) : undefined;
|
|
1834
|
+
const written = style && /(?:^|;)\s*z-index\s*:\s*(-?\d+)\s*(?:;|$)/i.exec(style);
|
|
1835
|
+
return written ? Number(written[1]) : 0;
|
|
1836
|
+
}
|
|
1837
|
+
function withLayer(style, layer) {
|
|
1838
|
+
const rest = (style ?? "").split(";").map((each) => each.trim()).filter((each) => each !== "" && !/^z-index\s*:/i.test(each));
|
|
1839
|
+
if (layer > 0)
|
|
1840
|
+
rest.push(`z-index: ${layer}`);
|
|
1841
|
+
return rest.length > 0 ? rest.join("; ") : null;
|
|
1842
|
+
}
|
|
1843
|
+
function fitRoot(work, before) {
|
|
1844
|
+
const now = rootOf(work);
|
|
1845
|
+
const end = (root) => Math.max(...root.scenes.map((scene) => scene.startMs + scene.durationMs));
|
|
1846
|
+
const tail = Math.max(0, before.durationMs - end(before));
|
|
1847
|
+
const duration = end(now) + tail;
|
|
1848
|
+
const moved = (scene) => scene && now.scenes.find((each) => each.id === scene.id);
|
|
1849
|
+
const owners = new Map;
|
|
1850
|
+
for (const clip of readRootTimeline(work.text(VIDEO_ENTRY2))?.clips ?? []) {
|
|
1851
|
+
const owner = numericStart(work, VIDEO_ENTRY2, clip) ? sceneOfClip(before, clip) : undefined;
|
|
1852
|
+
if (owner)
|
|
1853
|
+
owners.set(clip.ref, owner);
|
|
1854
|
+
}
|
|
1855
|
+
freezeFollowers(work, VIDEO_ENTRY2, (clip) => {
|
|
1856
|
+
const owner = owners.get(clip.ref);
|
|
1857
|
+
return owner !== undefined && !moved(owner);
|
|
1858
|
+
});
|
|
1859
|
+
const plan = new Map;
|
|
1860
|
+
for (const clip of readRootTimeline(work.text(VIDEO_ENTRY2))?.clips ?? []) {
|
|
1861
|
+
const owner = owners.get(clip.ref);
|
|
1862
|
+
const scene = moved(owner);
|
|
1863
|
+
if (owner && !scene) {
|
|
1864
|
+
plan.set(clip.ref, "remove");
|
|
1865
|
+
continue;
|
|
1866
|
+
}
|
|
1867
|
+
const start = scene && owner ? clip.startMs + scene.startMs - owner.startMs : clip.startMs;
|
|
1868
|
+
const change = {};
|
|
1869
|
+
if (start !== clip.startMs)
|
|
1870
|
+
change["data-start"] = seconds(start);
|
|
1871
|
+
if (duration !== before.durationMs && clip.durationMs !== undefined && Math.abs(clip.startMs + clip.durationMs - before.durationMs) <= SAME_MS2 && duration - start >= MIN_CLIP_MS) {
|
|
1872
|
+
change["data-duration"] = seconds(duration - start);
|
|
1873
|
+
}
|
|
1874
|
+
if (Object.keys(change).length > 0)
|
|
1875
|
+
plan.set(clip.ref, change);
|
|
1876
|
+
}
|
|
1877
|
+
rewriteClips(work, VIDEO_ENTRY2, plan);
|
|
1878
|
+
pruneLooks(work, VIDEO_ENTRY2);
|
|
1879
|
+
const poster = posterAfter(before, now, duration);
|
|
1880
|
+
setAttributes(work, VIDEO_ENTRY2, rootOf(work).root, {
|
|
1881
|
+
...before.root.attributes["data-duration"] ? { "data-duration": seconds(duration) } : {},
|
|
1882
|
+
...poster === undefined || poster === before.posterMs ? {} : { "data-poster": seconds(poster) }
|
|
1883
|
+
});
|
|
1884
|
+
}
|
|
1885
|
+
function sceneOfClip(root, clip) {
|
|
1886
|
+
if (clip.durationMs === undefined)
|
|
1887
|
+
return;
|
|
1888
|
+
const clipEnd = clip.startMs + clip.durationMs;
|
|
1889
|
+
let owner;
|
|
1890
|
+
let most = 0;
|
|
1891
|
+
for (const scene of root.scenes) {
|
|
1892
|
+
const during = Math.min(clipEnd, scene.startMs + scene.durationMs) - Math.max(clip.startMs, scene.startMs);
|
|
1893
|
+
if (during > 0 && during >= most) {
|
|
1894
|
+
owner = scene;
|
|
1895
|
+
most = during;
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
return owner && clip.durationMs <= owner.durationMs + SAME_MS2 ? owner : undefined;
|
|
1899
|
+
}
|
|
1900
|
+
function posterAfter(before, now, duration) {
|
|
1901
|
+
const posterMs = before.posterMs;
|
|
1902
|
+
if (posterMs === undefined)
|
|
1903
|
+
return;
|
|
1904
|
+
const frame = Math.ceil(1000 / before.fps);
|
|
1905
|
+
const owner = before.scenes.filter((scene) => scene.startMs <= posterMs && posterMs < scene.startMs + scene.durationMs).at(-1);
|
|
1906
|
+
const scene = owner && now.scenes.find((each) => each.id === owner.id);
|
|
1907
|
+
const at = owner && scene ? scene.startMs + Math.min(posterMs - owner.startMs, Math.max(0, scene.durationMs - frame)) : posterMs;
|
|
1908
|
+
return at >= duration ? Math.max(0, duration - frame) : at;
|
|
1909
|
+
}
|
|
1910
|
+
function copySceneFile(text, from, to, taken) {
|
|
1911
|
+
const quoted = (name) => name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1912
|
+
let copy = text.replace(new RegExp(`(data-composition-id\\s*=\\s*)(["'])${quoted(from)}\\2`, "g"), (_, name, quote) => `${name}${quote}${to}${quote}`).replace(new RegExp(`(__timelines\\s*\\[\\s*)(["'])${quoted(from)}\\2(\\s*\\])`, "g"), (_, open, quote, close) => `${open}${quote}${to}${quote}${close}`);
|
|
1913
|
+
copy = copy.replace(/\s+data-continues\s*=\s*(["'])[^"']*\1/g, "");
|
|
1914
|
+
const renamed = new Map;
|
|
1915
|
+
for (const match of copy.matchAll(/\sid\s*=\s*(["'])([^"']+)\1/g)) {
|
|
1916
|
+
const id = match[2];
|
|
1917
|
+
if (!id || renamed.has(id))
|
|
1918
|
+
continue;
|
|
1919
|
+
const fresh = uniqueName(id, taken);
|
|
1920
|
+
taken.add(fresh);
|
|
1921
|
+
renamed.set(id, fresh);
|
|
1922
|
+
}
|
|
1923
|
+
if (renamed.size === 0)
|
|
1924
|
+
return copy;
|
|
1925
|
+
const name = (id) => renamed.get(id) ?? id;
|
|
1926
|
+
return copy.replace(/(\sid\s*=\s*)(["'])([^"']+)\2/g, (_, attribute, quote, id) => `${attribute}${quote}${name(id)}${quote}`).replace(/(\sdata-start\s*=\s*(["'])\s*)([A-Za-z][\w.:-]*)(?=\s+[+-]\s|\s*\2)/g, (_, start, _quote, id) => `${start}${name(id)}`).replace(/(<style\b[^>]*>)([\s\S]*?)(<\/style>)/gi, (_, open, css, close) => `${open}${renameInCss(css, name)}${close}`).replace(/(<script\b[^>]*>)([\s\S]*?)(<\/script>)/gi, (_, open, script, close) => `${open}${renameInScript(script, name)}${close}`);
|
|
1927
|
+
}
|
|
1928
|
+
function renameInSelector(selector, to) {
|
|
1929
|
+
return selector.replace(/#([A-Za-z_][\w-]*)/g, (_, id) => `#${to(id)}`).replace(/(\[\s*id\s*=\s*)(["']?)([^"'\]\s]+)\2(\s*\])/g, (_, open, quote, id, close) => `${open}${quote}${to(id)}${quote}${close}`);
|
|
1930
|
+
}
|
|
1931
|
+
function renameInCss(css, to) {
|
|
1932
|
+
let out = "";
|
|
1933
|
+
let segment = "";
|
|
1934
|
+
for (let at = 0;at < css.length; at += 1) {
|
|
1935
|
+
const char = css[at] ?? "";
|
|
1936
|
+
if (char === "/" && css[at + 1] === "*") {
|
|
1937
|
+
const end = css.indexOf("*/", at + 2);
|
|
1938
|
+
const stop = end < 0 ? css.length : end + 2;
|
|
1939
|
+
segment += css.slice(at, stop);
|
|
1940
|
+
at = stop - 1;
|
|
1941
|
+
continue;
|
|
1942
|
+
}
|
|
1943
|
+
if (char === '"' || char === "'") {
|
|
1944
|
+
let end = at + 1;
|
|
1945
|
+
while (end < css.length && css[end] !== char)
|
|
1946
|
+
end += css[end] === "\\" ? 2 : 1;
|
|
1947
|
+
segment += css.slice(at, end + 1);
|
|
1948
|
+
at = end;
|
|
1949
|
+
continue;
|
|
1950
|
+
}
|
|
1951
|
+
if (char === "{") {
|
|
1952
|
+
out += segment.trimStart().startsWith("@") ? segment : renameInSelector(segment, to);
|
|
1953
|
+
out += char;
|
|
1954
|
+
segment = "";
|
|
1955
|
+
continue;
|
|
1956
|
+
}
|
|
1957
|
+
if (char === ";" || char === "}") {
|
|
1958
|
+
out += segment + char;
|
|
1959
|
+
segment = "";
|
|
1960
|
+
continue;
|
|
1961
|
+
}
|
|
1962
|
+
segment += char;
|
|
1963
|
+
}
|
|
1964
|
+
return out + segment;
|
|
1965
|
+
}
|
|
1966
|
+
function renameInScript(script, to) {
|
|
1967
|
+
return script.replace(/(["'`])((?:\\.|(?!\1)[^\\])*)\1/g, (whole, quote, inner, offset) => {
|
|
1968
|
+
const before = script.slice(Math.max(0, offset - 40), offset);
|
|
1969
|
+
if (/:\s*$/.test(before))
|
|
1970
|
+
return whole;
|
|
1971
|
+
if (/getElementById\(\s*$/.test(before))
|
|
1972
|
+
return `${quote}${to(inner)}${quote}`;
|
|
1973
|
+
return `${quote}${renameInSelector(inner, to)}${quote}`;
|
|
1974
|
+
});
|
|
1975
|
+
}
|
|
1976
|
+
function takenNames(work) {
|
|
1977
|
+
return new Set(nameCounts(work).keys());
|
|
1978
|
+
}
|
|
1979
|
+
function nameCounts(work) {
|
|
1980
|
+
const counts = new Map;
|
|
1981
|
+
for (const path of work.paths()) {
|
|
1982
|
+
if (!/\.html?$/i.test(path))
|
|
1983
|
+
continue;
|
|
1984
|
+
const text = work.text(path);
|
|
1985
|
+
for (const match of text.matchAll(/\s(?:id|data-composition-id)\s*=\s*(["'])([^"']*)\1/g)) {
|
|
1986
|
+
if (match[2])
|
|
1987
|
+
counts.set(match[2], (counts.get(match[2]) ?? 0) + 1);
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
return counts;
|
|
1991
|
+
}
|
|
1992
|
+
function uniqueName(base, taken) {
|
|
1993
|
+
const stem = /^[A-Za-z]/.test(base) ? base : `x-${base}`;
|
|
1994
|
+
const plain = stem.replace(/-\d+$/, "");
|
|
1995
|
+
const free = (name) => !taken.has(name) && name !== LOOK_ID;
|
|
1996
|
+
if (free(stem))
|
|
1997
|
+
return stem;
|
|
1998
|
+
for (let n = 2;; n += 1) {
|
|
1999
|
+
const name = `${plain}-${n}`;
|
|
2000
|
+
if (free(name))
|
|
2001
|
+
return name;
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
function uniquePath(work, stem, extension) {
|
|
2005
|
+
if (!work.has(`${stem}${extension}`))
|
|
2006
|
+
return `${stem}${extension}`;
|
|
2007
|
+
for (let n = 2;; n += 1) {
|
|
2008
|
+
if (!work.has(`${stem}-${n}${extension}`))
|
|
2009
|
+
return `${stem}-${n}${extension}`;
|
|
2010
|
+
}
|
|
2011
|
+
}
|
|
2012
|
+
function slug(name) {
|
|
2013
|
+
return name.normalize("NFKD").replace(/[\u0300-\u036F]/g, "").replace(/[^A-Za-z0-9_-]+/g, "-").replace(/^[^A-Za-z]+/, "").replace(/-+$/, "").slice(0, 40);
|
|
2014
|
+
}
|
|
2015
|
+
function timelineOf2(work, file) {
|
|
2016
|
+
const timeline = readTimeline(work, file);
|
|
2017
|
+
if (!timeline)
|
|
2018
|
+
throw new EditError(`${file} holds no composition.`);
|
|
2019
|
+
return timeline;
|
|
2020
|
+
}
|
|
2021
|
+
function readTimeline(work, file) {
|
|
2022
|
+
const text = work.text(file);
|
|
2023
|
+
const read = work.timelines.get(file);
|
|
2024
|
+
if (read?.text === text)
|
|
2025
|
+
return read.timeline;
|
|
2026
|
+
const timeline = readVideoFileTimeline(file, text);
|
|
2027
|
+
work.timelines.set(file, { text, timeline });
|
|
2028
|
+
return timeline;
|
|
2029
|
+
}
|
|
2030
|
+
function clipOf(work, file, target) {
|
|
2031
|
+
return resolveTarget(timelineOf2(work, file).clips, target, file, "clip");
|
|
2032
|
+
}
|
|
2033
|
+
function clipsOf(work, clips) {
|
|
2034
|
+
if (clips.length === 0)
|
|
2035
|
+
throw new EditError("Choose the clips first.");
|
|
2036
|
+
const seen = new Set;
|
|
2037
|
+
return clips.flatMap(({ file, clip }, index) => {
|
|
2038
|
+
const found = clipOf(work, file, clip);
|
|
2039
|
+
const key = `${file}
|
|
2040
|
+
${found.ref}`;
|
|
2041
|
+
if (seen.has(key))
|
|
2042
|
+
return [];
|
|
2043
|
+
seen.add(key);
|
|
2044
|
+
return [{ file, clip: found, index }];
|
|
2045
|
+
});
|
|
2046
|
+
}
|
|
2047
|
+
function byFile(found) {
|
|
2048
|
+
const files = new Map;
|
|
2049
|
+
const ordered = [...found].sort((a, b) => Number(b.file === VIDEO_ENTRY2) - Number(a.file === VIDEO_ENTRY2));
|
|
2050
|
+
for (const each of ordered)
|
|
2051
|
+
files.set(each.file, [...files.get(each.file) ?? [], each]);
|
|
2052
|
+
return files;
|
|
2053
|
+
}
|
|
2054
|
+
function splitFound(work, file, found, atMs, endMs) {
|
|
2055
|
+
const at = Math.round(atMs);
|
|
2056
|
+
const end = clipEnd(found, endMs);
|
|
2057
|
+
if (at - found.startMs < MIN_CLIP_MS || end - at < MIN_CLIP_MS) {
|
|
2058
|
+
throw new EditError(`Each part of a split clip lasts at least ${MIN_CLIP_MS} ms.`);
|
|
2059
|
+
}
|
|
2060
|
+
const parts = clipParts(work, file, found, [
|
|
2061
|
+
{ startMs: found.startMs, mediaStartMs: found.mediaStartMs, durationMs: at - found.startMs },
|
|
2062
|
+
{
|
|
2063
|
+
startMs: at,
|
|
2064
|
+
mediaStartMs: found.mediaStartMs + (at - found.startMs),
|
|
2065
|
+
durationMs: end - at
|
|
2066
|
+
}
|
|
2067
|
+
]);
|
|
2068
|
+
const second = parts.refs[1];
|
|
2069
|
+
replaceClip(work, file, found, parts.html);
|
|
2070
|
+
if (found.id && second)
|
|
2071
|
+
followInstead(work, file, found.id, second);
|
|
2072
|
+
return second;
|
|
2073
|
+
}
|
|
2074
|
+
function splitChained(work, chains, file, found, atMs, endMs) {
|
|
2075
|
+
const chain = chains.get(`${file}
|
|
2076
|
+
${found.ref}`);
|
|
2077
|
+
const at = videoStartOf(work, file, found) - found.startMs + Math.round(atMs);
|
|
2078
|
+
const second = splitFound(work, file, found, atMs, endMs);
|
|
2079
|
+
if (!chain || !second)
|
|
2080
|
+
return second;
|
|
2081
|
+
for (const part of chain.parts) {
|
|
2082
|
+
if (part.file === file && part.clip.ref === found.ref || part.startMs < at)
|
|
2083
|
+
continue;
|
|
2084
|
+
const now = clipOf(work, part.file, videoTarget(part.clip));
|
|
2085
|
+
setAttributes(work, part.file, now.source, { "data-continues": second });
|
|
2086
|
+
}
|
|
2087
|
+
return second;
|
|
2088
|
+
}
|
|
2089
|
+
function resolveTarget(items, target, file, what) {
|
|
2090
|
+
const found = findVideoTarget(items, target);
|
|
2091
|
+
if (!Array.isArray(found))
|
|
2092
|
+
return found;
|
|
2093
|
+
const ref = typeof target === "string" ? target : target.ref;
|
|
2094
|
+
if (typeof target === "string" || isIdRef(ref)) {
|
|
2095
|
+
throw new EditError(`${file} has no ${what} '${ref}'.`);
|
|
2096
|
+
}
|
|
2097
|
+
throw new EditError(found.length === 0 ? `The ${what} you chose in ${file} changed or was removed meanwhile: choose it again.` : `${file} now has ${found.length} ${what}s like the one you chose: choose it again.`);
|
|
2098
|
+
}
|
|
2099
|
+
function findVideoTarget(items, target) {
|
|
2100
|
+
const ref = typeof target === "string" ? target : target.ref;
|
|
2101
|
+
const placed = items.find((item) => item.ref === ref);
|
|
2102
|
+
if (typeof target === "string" || isIdRef(ref))
|
|
2103
|
+
return placed ?? [];
|
|
2104
|
+
if (placed && matches(placed, target))
|
|
2105
|
+
return placed;
|
|
2106
|
+
const alike = items.filter((item) => !isIdRef(item.ref) && matches(item, target));
|
|
2107
|
+
const [only] = alike;
|
|
2108
|
+
return only && alike.length === 1 ? only : alike;
|
|
2109
|
+
}
|
|
2110
|
+
function matches(item, target) {
|
|
2111
|
+
return item.tag === target.tag && (target.words === undefined || item.text === target.words) && (target.src === undefined || item.src === target.src);
|
|
2112
|
+
}
|
|
2113
|
+
function isIdRef(ref) {
|
|
2114
|
+
return !/^#\d+$|^[a-z][\w-]*:\d+$/.test(ref);
|
|
2115
|
+
}
|
|
2116
|
+
function playsFile(clip) {
|
|
2117
|
+
return clip.kind === "video" || clip.kind === "audio";
|
|
2118
|
+
}
|
|
2119
|
+
function clipEnd(clip, endMs) {
|
|
2120
|
+
if (clip.durationMs !== undefined)
|
|
2121
|
+
return clip.startMs + clip.durationMs;
|
|
2122
|
+
if (endMs !== undefined && endMs > clip.startMs)
|
|
2123
|
+
return Math.round(endMs);
|
|
2124
|
+
throw new EditError(`'${clip.ref}' writes no length: give it data-duration first.`);
|
|
2125
|
+
}
|
|
2126
|
+
function ripple(work, file, fromMs, deltaMs, except) {
|
|
2127
|
+
if (deltaMs === 0)
|
|
2128
|
+
return;
|
|
2129
|
+
const after = timelineOf2(work, file).clips.filter((clip) => !except.has(clip.ref) && clip.startMs >= fromMs - SAME_MS2 && numericStart(work, file, clip));
|
|
2130
|
+
rewriteClips(work, file, new Map(after.map((clip) => [
|
|
2131
|
+
clip.ref,
|
|
2132
|
+
{ "data-start": seconds(Math.max(0, clip.startMs + deltaMs)) }
|
|
2133
|
+
])));
|
|
2134
|
+
const scene = sceneOf(work, file);
|
|
2135
|
+
if (scene && scene.durationMs >= fromMs - SAME_MS2) {
|
|
2136
|
+
lengthenScene(work, scene.id, Math.max(MIN_CLIP_MS, scene.durationMs + deltaMs));
|
|
2137
|
+
}
|
|
2138
|
+
}
|
|
2139
|
+
function rippleRemove(work, file, cut) {
|
|
2140
|
+
work.marking ??= { chains: chainsOf(work), pieces: new Map };
|
|
2141
|
+
const chains = work.marking;
|
|
2142
|
+
const shown = sceneOf(work, file);
|
|
2143
|
+
const spans = shown ? inFrameSteps(cut, shown.durationMs, frameStepMs(rootOf(work).fps)) : mergeRanges(cut);
|
|
2144
|
+
const map = (t) => t - spans.reduce((sum, span) => sum + Math.max(0, Math.min(t, span.endMs) - span.startMs), 0);
|
|
2145
|
+
const from = spans[0]?.startMs ?? Number.POSITIVE_INFINITY;
|
|
2146
|
+
freezeFollowers(work, file, (each) => each.durationMs === undefined || each.startMs + each.durationMs > from);
|
|
2147
|
+
const taken = takenNames(work);
|
|
2148
|
+
const plan = new Map;
|
|
2149
|
+
const chained = (clip) => clip.id !== undefined && chains.chains.has(`${file}
|
|
2150
|
+
${clip.ref}`);
|
|
2151
|
+
for (const clip of timelineOf2(work, file).clips) {
|
|
2152
|
+
if (!numericStart(work, file, clip))
|
|
2153
|
+
continue;
|
|
2154
|
+
const start = map(clip.startMs);
|
|
2155
|
+
if (clip.durationMs === undefined) {
|
|
2156
|
+
if (start !== clip.startMs)
|
|
2157
|
+
plan.set(clip.ref, { "data-start": seconds(start) });
|
|
2158
|
+
continue;
|
|
2159
|
+
}
|
|
2160
|
+
const kept = subtractRanges({ startMs: clip.startMs, endMs: clip.startMs + clip.durationMs }, spans).filter((piece) => piece.endMs - piece.startMs >= MIN_CLIP_MS);
|
|
2161
|
+
const first = kept[0];
|
|
2162
|
+
if (!first) {
|
|
2163
|
+
plan.set(clip.ref, "remove");
|
|
2164
|
+
if (chained(clip))
|
|
2165
|
+
chains.pieces.set(`${file}
|
|
2166
|
+
${clip.ref}`, []);
|
|
2167
|
+
continue;
|
|
2168
|
+
}
|
|
2169
|
+
if (playsFile(clip) && kept.length > 1) {
|
|
2170
|
+
const parts = clipParts(work, file, clip, kept.map((piece) => ({
|
|
2171
|
+
startMs: map(piece.startMs),
|
|
2172
|
+
mediaStartMs: clip.mediaStartMs + piece.startMs - clip.startMs,
|
|
2173
|
+
durationMs: piece.endMs - piece.startMs
|
|
2174
|
+
})), taken);
|
|
2175
|
+
plan.set(clip.ref, { html: parts.html });
|
|
2176
|
+
if (chained(clip))
|
|
2177
|
+
chains.pieces.set(`${file}
|
|
2178
|
+
${clip.ref}`, parts.refs);
|
|
2179
|
+
continue;
|
|
2180
|
+
}
|
|
2181
|
+
const length = map(clip.startMs + clip.durationMs) - start;
|
|
2182
|
+
if (start === clip.startMs && length === clip.durationMs)
|
|
2183
|
+
continue;
|
|
2184
|
+
const into = first.startMs - clip.startMs;
|
|
2185
|
+
plan.set(clip.ref, {
|
|
2186
|
+
"data-start": seconds(start),
|
|
2187
|
+
"data-duration": seconds(length),
|
|
2188
|
+
...into > 0 && playsFile(clip) ? { "data-media-start": seconds(clip.mediaStartMs + into) } : {}
|
|
2189
|
+
});
|
|
2190
|
+
}
|
|
2191
|
+
rewriteClips(work, file, plan);
|
|
2192
|
+
pruneLooks(work, file);
|
|
2193
|
+
const scene = sceneOf(work, file);
|
|
2194
|
+
if (scene)
|
|
2195
|
+
lengthenScene(work, scene.id, Math.max(MIN_CLIP_MS, map(scene.durationMs)));
|
|
2196
|
+
}
|
|
2197
|
+
function settleChains(work) {
|
|
2198
|
+
joinStrays(work);
|
|
2199
|
+
for (let placed = 0;; placed += 1) {
|
|
2200
|
+
const scenes = rootOf(work).scenes;
|
|
2201
|
+
const chains = chainsOf(work);
|
|
2202
|
+
if (placed > chains.size)
|
|
2203
|
+
return;
|
|
2204
|
+
const overlapping = [...new Set(chains.values())].find((chain) => {
|
|
2205
|
+
const seen = chain.parts.map((part) => {
|
|
2206
|
+
const scene = scenes.find((each) => each.src === part.file);
|
|
2207
|
+
return Math.min(part.endMs, scene ? scene.startMs + scene.durationMs : part.endMs);
|
|
2208
|
+
});
|
|
2209
|
+
return chain.parts.slice(1).some((part, at) => part.startMs < (seen[at] ?? part.startMs) - SAME_MS2);
|
|
2210
|
+
});
|
|
2211
|
+
const head = overlapping?.parts[0];
|
|
2212
|
+
if (!head)
|
|
2213
|
+
return;
|
|
2214
|
+
placeFound(work, [logicalClip(work, chains, head)]);
|
|
2215
|
+
}
|
|
2216
|
+
}
|
|
2217
|
+
function joinStrays(work) {
|
|
2218
|
+
for (let joined = 0;joined <= MAX_STRAYS; joined += 1) {
|
|
2219
|
+
const scenes = rootOf(work).scenes;
|
|
2220
|
+
const chains = [...new Set(chainsOf(work).values())];
|
|
2221
|
+
const linked = new Set(chains.flatMap((chain) => chain.parts.map((part) => keyOf(part))));
|
|
2222
|
+
const strays = chains.filter((chain) => chain.parts[0]?.clip.continues).map((chain) => [...chain.parts]);
|
|
2223
|
+
for (const scene of scenes) {
|
|
2224
|
+
if (work.textOf(scene.src) === undefined)
|
|
2225
|
+
continue;
|
|
2226
|
+
for (const clip of readTimeline(work, scene.src)?.clips ?? []) {
|
|
2227
|
+
const part = { file: scene.src, clip };
|
|
2228
|
+
if (!clip.continues || clip.durationMs === undefined || linked.has(keyOf(part)))
|
|
2229
|
+
continue;
|
|
2230
|
+
const startMs = scene.startMs + clip.startMs;
|
|
2231
|
+
strays.push([{ ...part, startMs, endMs: startMs + clip.durationMs }]);
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
const heads = chains.filter((chain) => chain.parts[0]?.clip.id && !chain.parts[0].clip.continues);
|
|
2235
|
+
const found = strays.map((stray) => ({
|
|
2236
|
+
stray,
|
|
2237
|
+
chain: heads.find((chain) => {
|
|
2238
|
+
const last = chain.parts.at(-1);
|
|
2239
|
+
return last && stray[0] && goesOnFrom(scenes, last, stray[0]);
|
|
2240
|
+
})
|
|
2241
|
+
})).find((each) => each.chain);
|
|
2242
|
+
const head = found?.chain?.parts[0]?.clip.id;
|
|
2243
|
+
if (!found || !head)
|
|
2244
|
+
return;
|
|
2245
|
+
for (const part of found.stray) {
|
|
2246
|
+
const now = clipOf(work, part.file, videoTarget(part.clip));
|
|
2247
|
+
setAttributes(work, part.file, now.source, { "data-continues": head });
|
|
2248
|
+
}
|
|
2249
|
+
}
|
|
2250
|
+
}
|
|
2251
|
+
function holdsParts(work, path) {
|
|
2252
|
+
const text = work.textOf(path);
|
|
2253
|
+
if (path === VIDEO_ENTRY2 || text === undefined || !/\.html?$/i.test(path))
|
|
2254
|
+
return false;
|
|
2255
|
+
if (text.includes("data-continues"))
|
|
2256
|
+
return true;
|
|
2257
|
+
const heads = new Set;
|
|
2258
|
+
for (const file of work.paths()) {
|
|
2259
|
+
for (const match of (work.textOf(file) ?? "").matchAll(/\sdata-continues\s*=\s*"([^"]+)"/g)) {
|
|
2260
|
+
if (match[1])
|
|
2261
|
+
heads.add(match[1]);
|
|
2262
|
+
}
|
|
2263
|
+
}
|
|
2264
|
+
return [...heads].some((id) => text.includes(` id="${id}"`));
|
|
2265
|
+
}
|
|
2266
|
+
var MAX_STRAYS = 20;
|
|
2267
|
+
function keyOf(part) {
|
|
2268
|
+
return `${part.file}
|
|
2269
|
+
${part.clip.ref}`;
|
|
2270
|
+
}
|
|
2271
|
+
function markCutChains(work) {
|
|
2272
|
+
const marking = work.marking;
|
|
2273
|
+
if (!marking || marking.pieces.size === 0)
|
|
2274
|
+
return;
|
|
2275
|
+
for (const chain of new Set(marking.chains.values())) {
|
|
2276
|
+
const keys = chain.parts.map((part) => `${part.file}
|
|
2277
|
+
${part.clip.ref}`);
|
|
2278
|
+
if (!keys.some((key) => marking.pieces.has(key)))
|
|
2279
|
+
continue;
|
|
2280
|
+
const left = chain.parts.flatMap((part, at) => {
|
|
2281
|
+
const ids = marking.pieces.get(keys[at]) ?? (part.clip.id ? [part.clip.id] : []);
|
|
2282
|
+
const clips = work.textOf(part.file) === undefined ? [] : timelineOf2(work, part.file).clips;
|
|
2283
|
+
return ids.flatMap((id) => {
|
|
2284
|
+
const clip = clips.find((each) => each.id === id);
|
|
2285
|
+
return clip ? [{ file: part.file, clip }] : [];
|
|
2286
|
+
});
|
|
2287
|
+
});
|
|
2288
|
+
const [head, ...rest] = left;
|
|
2289
|
+
if (!head?.clip.id)
|
|
2290
|
+
continue;
|
|
2291
|
+
if (head.clip.continues) {
|
|
2292
|
+
setAttributes(work, head.file, head.clip.source, { "data-continues": null });
|
|
2293
|
+
}
|
|
2294
|
+
for (const part of rest) {
|
|
2295
|
+
if (part.clip.continues === head.clip.id)
|
|
2296
|
+
continue;
|
|
2297
|
+
const now = clipOf(work, part.file, videoTarget(part.clip));
|
|
2298
|
+
setAttributes(work, part.file, now.source, { "data-continues": head.clip.id });
|
|
2299
|
+
}
|
|
2300
|
+
}
|
|
2301
|
+
}
|
|
2302
|
+
function frameStepMs(fps) {
|
|
2303
|
+
let [a, b] = [fps, 1000];
|
|
2304
|
+
while (b > 0)
|
|
2305
|
+
[a, b] = [b, a % b];
|
|
2306
|
+
return 1000 / a;
|
|
2307
|
+
}
|
|
2308
|
+
function inFrameSteps(cut, lengthMs, step) {
|
|
2309
|
+
const scene = (ms) => Math.min(lengthMs, Math.max(0, ms));
|
|
2310
|
+
let spans = mergeCuts(cut.map((each) => {
|
|
2311
|
+
const room = each.room ?? each;
|
|
2312
|
+
return {
|
|
2313
|
+
startMs: scene(Math.floor(each.startMs)),
|
|
2314
|
+
endMs: scene(Math.ceil(each.endMs)),
|
|
2315
|
+
room: { startMs: scene(Math.ceil(room.startMs)), endMs: scene(Math.floor(room.endMs)) }
|
|
2316
|
+
};
|
|
2317
|
+
}));
|
|
2318
|
+
for (;; ) {
|
|
2319
|
+
const grown = mergeCuts(spans.map((span) => growToSteps(span, step, lengthMs)));
|
|
2320
|
+
if (grown.length === spans.length)
|
|
2321
|
+
return grown;
|
|
2322
|
+
spans = grown;
|
|
2323
|
+
}
|
|
2324
|
+
}
|
|
2325
|
+
function growToSteps(cut, step, lengthMs) {
|
|
2326
|
+
const length = cut.endMs - cut.startMs;
|
|
2327
|
+
const extra = Math.ceil(length / step) * step - length;
|
|
2328
|
+
const room = cut.room ?? cut;
|
|
2329
|
+
const roomBefore = Math.max(0, cut.startMs - room.startMs);
|
|
2330
|
+
const roomAfter = Math.max(0, room.endMs - cut.endMs);
|
|
2331
|
+
let before = Math.min(roomBefore, Math.floor(extra / 2));
|
|
2332
|
+
const after = Math.min(roomAfter, extra - before);
|
|
2333
|
+
before = Math.min(roomBefore, extra - after);
|
|
2334
|
+
const beyond = extra - before - after;
|
|
2335
|
+
let startMs = cut.startMs - before - Math.floor(beyond / 2);
|
|
2336
|
+
let endMs = cut.endMs + after + Math.ceil(beyond / 2);
|
|
2337
|
+
if (startMs < 0)
|
|
2338
|
+
[startMs, endMs] = [0, endMs - startMs];
|
|
2339
|
+
if (endMs > lengthMs)
|
|
2340
|
+
[startMs, endMs] = [Math.max(0, startMs - (endMs - lengthMs)), lengthMs];
|
|
2341
|
+
return {
|
|
2342
|
+
startMs,
|
|
2343
|
+
endMs,
|
|
2344
|
+
room: { startMs: Math.min(room.startMs, startMs), endMs: Math.max(room.endMs, endMs) }
|
|
2345
|
+
};
|
|
2346
|
+
}
|
|
2347
|
+
function mergeCuts(cuts) {
|
|
2348
|
+
const sorted = cuts.filter((cut) => cut.endMs > cut.startMs).sort((a, b) => a.startMs - b.startMs);
|
|
2349
|
+
const merged = [];
|
|
2350
|
+
for (const cut of sorted) {
|
|
2351
|
+
const room = cut.room ?? cut;
|
|
2352
|
+
const last = merged.at(-1);
|
|
2353
|
+
if (last && cut.startMs <= last.endMs) {
|
|
2354
|
+
const lastRoom = last.room ?? last;
|
|
2355
|
+
merged[merged.length - 1] = {
|
|
2356
|
+
startMs: last.startMs,
|
|
2357
|
+
endMs: Math.max(last.endMs, cut.endMs),
|
|
2358
|
+
room: {
|
|
2359
|
+
startMs: Math.min(lastRoom.startMs, room.startMs),
|
|
2360
|
+
endMs: Math.max(lastRoom.endMs, room.endMs)
|
|
2361
|
+
}
|
|
2362
|
+
};
|
|
2363
|
+
} else {
|
|
2364
|
+
merged.push({ startMs: cut.startMs, endMs: cut.endMs, room });
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
return merged;
|
|
2368
|
+
}
|
|
2369
|
+
function subtractRanges(range, spans) {
|
|
2370
|
+
const pieces = [];
|
|
2371
|
+
let cursor = range.startMs;
|
|
2372
|
+
for (const span of spans) {
|
|
2373
|
+
if (span.endMs <= cursor || span.startMs >= range.endMs)
|
|
2374
|
+
continue;
|
|
2375
|
+
if (span.startMs > cursor)
|
|
2376
|
+
pieces.push({ startMs: cursor, endMs: span.startMs });
|
|
2377
|
+
cursor = Math.max(cursor, span.endMs);
|
|
2378
|
+
}
|
|
2379
|
+
if (cursor < range.endMs)
|
|
2380
|
+
pieces.push({ startMs: cursor, endMs: range.endMs });
|
|
2381
|
+
return pieces;
|
|
2382
|
+
}
|
|
2383
|
+
function numericStart(work, file, clip) {
|
|
2384
|
+
const at = clip.source.attributes["data-start"];
|
|
2385
|
+
if (!at)
|
|
2386
|
+
return true;
|
|
2387
|
+
return Number.isFinite(Number(attributeValue(work.text(file), at) ?? Number.NaN));
|
|
2388
|
+
}
|
|
2389
|
+
function followed(written) {
|
|
2390
|
+
if (written.trim() === "" || Number.isFinite(Number(written)))
|
|
2391
|
+
return;
|
|
2392
|
+
const match = /^\s*(.*?)(\s*[+-]\s*(?:\d*\.)?\d+)?\s*$/.exec(written);
|
|
2393
|
+
return match?.[1] ? { name: match[1], offset: match[2] ?? "" } : undefined;
|
|
2394
|
+
}
|
|
2395
|
+
function freezeFollowers(work, file, moves) {
|
|
2396
|
+
for (;; ) {
|
|
2397
|
+
const clips = timelineOf2(work, file).clips;
|
|
2398
|
+
const moving = new Set(clips.flatMap((clip) => clip.id && moves(clip) ? [clip.id] : []));
|
|
2399
|
+
const follower = clips.find((clip) => {
|
|
2400
|
+
const at = clip.source.attributes["data-start"];
|
|
2401
|
+
const name = at ? followed(attributeValue(work.text(file), at) ?? "")?.name : undefined;
|
|
2402
|
+
return name !== undefined && moving.has(name);
|
|
2403
|
+
});
|
|
2404
|
+
if (!follower)
|
|
2405
|
+
return;
|
|
2406
|
+
setAttributes(work, file, follower.source, { "data-start": seconds(follower.startMs) });
|
|
2407
|
+
}
|
|
2408
|
+
}
|
|
2409
|
+
function followInstead(work, file, name, instead) {
|
|
2410
|
+
for (;; ) {
|
|
2411
|
+
const follower = timelineOf2(work, file).clips.find((clip) => {
|
|
2412
|
+
const at = clip.source.attributes["data-start"];
|
|
2413
|
+
return at && followed(attributeValue(work.text(file), at) ?? "")?.name === name;
|
|
2414
|
+
});
|
|
2415
|
+
const at = follower?.source.attributes["data-start"];
|
|
2416
|
+
if (!follower || !at)
|
|
2417
|
+
return;
|
|
2418
|
+
const written = followed(attributeValue(work.text(file), at) ?? "");
|
|
2419
|
+
setAttributes(work, file, follower.source, {
|
|
2420
|
+
"data-start": `${instead}${written?.offset ?? ""}`
|
|
2421
|
+
});
|
|
2422
|
+
}
|
|
2423
|
+
}
|
|
2424
|
+
function rewriteClips(work, file, plan) {
|
|
2425
|
+
if (plan.size === 0)
|
|
2426
|
+
return;
|
|
2427
|
+
const clips = timelineOf2(work, file).clips.filter((clip) => plan.has(clip.ref)).sort((a, b) => b.source.element.start - a.source.element.start);
|
|
2428
|
+
for (const clip of clips) {
|
|
2429
|
+
const change = plan.get(clip.ref);
|
|
2430
|
+
if (change === "remove") {
|
|
2431
|
+
const block = lineBlock(work.text(file), clip.source.element);
|
|
2432
|
+
work.replace(file, block.start, block.end, "");
|
|
2433
|
+
} else if (change && "html" in change && typeof change.html === "string") {
|
|
2434
|
+
work.replace(file, clip.source.element.start, clip.source.element.end, change.html);
|
|
2435
|
+
} else if (change) {
|
|
2436
|
+
setAttributes(work, file, clip.source, change);
|
|
2437
|
+
}
|
|
2438
|
+
}
|
|
2439
|
+
}
|
|
2440
|
+
function clipParts(work, file, clip, parts, taken = takenNames(work)) {
|
|
2441
|
+
const text = work.text(file);
|
|
2442
|
+
const element = text.slice(clip.source.element.start, clip.source.element.end);
|
|
2443
|
+
const indent = lineIndent(text, clip.source.element.start);
|
|
2444
|
+
const base = clip.id ?? slug(clip.src?.replace(/^.*\//, "").replace(/\.[^.]*$/, "") ?? "");
|
|
2445
|
+
const refs = [];
|
|
2446
|
+
const html = parts.map((part, index) => {
|
|
2447
|
+
const id = index === 0 && clip.id ? clip.id : uniqueName(base || clip.kind, taken);
|
|
2448
|
+
taken.add(id);
|
|
2449
|
+
refs.push(id);
|
|
2450
|
+
return withAttributes(element, {
|
|
2451
|
+
id,
|
|
2452
|
+
"data-start": seconds(part.startMs),
|
|
2453
|
+
"data-duration": seconds(part.durationMs),
|
|
2454
|
+
...playsFile(clip) ? { "data-media-start": seconds(part.mediaStartMs) } : {},
|
|
2455
|
+
...index === 0 ? {} : { "data-continues": null }
|
|
2456
|
+
});
|
|
2457
|
+
});
|
|
2458
|
+
return { html: html.join(`
|
|
2459
|
+
${indent}`), refs };
|
|
2460
|
+
}
|
|
2461
|
+
function replaceClip(work, file, clip, html) {
|
|
2462
|
+
work.replace(file, clip.source.element.start, clip.source.element.end, html);
|
|
2463
|
+
}
|
|
2464
|
+
function clipHtml(kind, values) {
|
|
2465
|
+
const { id, src, start, duration, mediaStart } = values;
|
|
2466
|
+
const fill = 'style="position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover"';
|
|
2467
|
+
const timing = `data-start="${start}" data-duration="${duration}"`;
|
|
2468
|
+
const sound = values.muted ? "muted" : 'data-has-audio="true"';
|
|
2469
|
+
switch (kind) {
|
|
2470
|
+
case "video":
|
|
2471
|
+
return `<video id="${id}" src="${escapeAttribute(src)}" ${timing} data-media-start="${mediaStart}" ${sound} playsinline ${fill}></video>`;
|
|
2472
|
+
case "audio":
|
|
2473
|
+
return `<audio id="${id}" src="${escapeAttribute(src)}" ${timing} data-media-start="${mediaStart}" data-volume="1"></audio>`;
|
|
2474
|
+
case "image":
|
|
2475
|
+
return `<img id="${id}" src="${escapeAttribute(src)}" alt="" ${timing} ${fill}>`;
|
|
2476
|
+
}
|
|
2477
|
+
}
|
|
2478
|
+
function insertInComposition(work, file, timeline, elements, track) {
|
|
2479
|
+
const text = work.text(file);
|
|
2480
|
+
const children = timeline.children;
|
|
2481
|
+
const holds = (child, tracks) => {
|
|
2482
|
+
const { start, end } = child.source.element;
|
|
2483
|
+
const inside = (span) => span.start >= start && span.end <= end;
|
|
2484
|
+
return timeline.clips.some((clip) => tracks.includes(clip.track) && inside(clip.source.element)) || tracks.includes("text") && timeline.texts.some((each) => inside(each.source.element));
|
|
2485
|
+
};
|
|
2486
|
+
const lastHolding = (tracks) => children.filter((child) => holds(child, tracks)).at(-1);
|
|
2487
|
+
const firstWords = children.findIndex((child) => holds(child, ["text"]));
|
|
2488
|
+
const lastPicture = children.reduce((last, child, index) => holds(child, ["picture"]) ? index : last, -1);
|
|
2489
|
+
const underWords = track === "picture" && firstWords >= 0 && (lastPicture < 0 || firstWords <= lastPicture);
|
|
2490
|
+
const after = underWords ? undefined : lastHolding([track]) ?? (track === "picture" ? undefined : lastHolding(["picture"]));
|
|
2491
|
+
const before = underWords ? children[firstWords] : undefined;
|
|
2492
|
+
let closing = children.length;
|
|
2493
|
+
while (closing > 0 && ["style", "script"].includes(children[closing - 1]?.tag ?? ""))
|
|
2494
|
+
closing -= 1;
|
|
2495
|
+
const next = before ?? (after ? undefined : children[closing]);
|
|
2496
|
+
const previous = after ?? (next ? undefined : children[closing - 1]);
|
|
2497
|
+
if (previous) {
|
|
2498
|
+
const block = lineBlock(text, previous.source.element);
|
|
2499
|
+
const indent = lineIndent(text, previous.source.element.start);
|
|
2500
|
+
const html = elements.join(`
|
|
2501
|
+
${indent}`);
|
|
2502
|
+
work.replace(file, block.end, block.end, `${indent}${html}${lineEnd(text, block)}`);
|
|
2503
|
+
return;
|
|
2504
|
+
}
|
|
2505
|
+
if (next) {
|
|
2506
|
+
const block = lineBlock(text, next.source.element);
|
|
2507
|
+
const indent = lineIndent(text, next.source.element.start);
|
|
2508
|
+
const html = elements.join(`
|
|
2509
|
+
${indent}`);
|
|
2510
|
+
if (block.start < next.source.element.start || aloneOnLine(text, next.source.element.start)) {
|
|
2511
|
+
work.replace(file, block.start, block.start, `${indent}${html}
|
|
2512
|
+
`);
|
|
2513
|
+
} else {
|
|
2514
|
+
work.replace(file, next.source.element.start, next.source.element.start, `${html} `);
|
|
2515
|
+
}
|
|
2516
|
+
return;
|
|
2517
|
+
}
|
|
2518
|
+
const content = timeline.composition.content;
|
|
2519
|
+
if (!content)
|
|
2520
|
+
throw new EditError(`${file}: its composition holds nothing a clip can join.`);
|
|
2521
|
+
const indent = `${lineIndent(text, timeline.composition.element.start)} `;
|
|
2522
|
+
work.replace(file, content.start, content.start, `
|
|
2523
|
+
${indent}${elements.join(`
|
|
2524
|
+
${indent}`)}`);
|
|
2525
|
+
}
|
|
2526
|
+
var PLACING = "data-sixb-placing";
|
|
2527
|
+
function videoStartOf(work, file, clip) {
|
|
2528
|
+
return (sceneOf(work, file)?.startMs ?? 0) + clip.startMs;
|
|
2529
|
+
}
|
|
2530
|
+
function moveFound(work, found, deltaMs) {
|
|
2531
|
+
const chains = chainsOf(work);
|
|
2532
|
+
const logical = [
|
|
2533
|
+
...new Map(found.map((each) => {
|
|
2534
|
+
const clip = logicalClip(work, chains, each);
|
|
2535
|
+
return [`${clip.file}
|
|
2536
|
+
${clip.clip.ref}`, clip];
|
|
2537
|
+
})).values()
|
|
2538
|
+
];
|
|
2539
|
+
const delta = Math.max(Math.round(deltaMs), ...logical.map((clip) => -clip.startMs));
|
|
2540
|
+
if (delta === 0) {
|
|
2541
|
+
return {
|
|
2542
|
+
clips: logical.map(({ file, clip }) => ({ file, clip: videoTarget(clip) })),
|
|
2543
|
+
animationsLeft: [],
|
|
2544
|
+
animationsJoined: []
|
|
2545
|
+
};
|
|
2546
|
+
}
|
|
2547
|
+
return placeFound(work, logical.map((clip) => ({ ...clip, startMs: clip.startMs + delta })));
|
|
2548
|
+
}
|
|
2549
|
+
function chainsOf(work) {
|
|
2550
|
+
const scenes = rootOf(work).scenes;
|
|
2551
|
+
const chains = videoChains(scenes, (file) => work.textOf(file) === undefined ? undefined : readTimeline(work, file) ?? undefined);
|
|
2552
|
+
const byPart = new Map;
|
|
2553
|
+
for (const chain of chains) {
|
|
2554
|
+
for (const part of chain.parts)
|
|
2555
|
+
byPart.set(`${part.file}
|
|
2556
|
+
${part.clip.ref}`, chain);
|
|
2557
|
+
}
|
|
2558
|
+
return byPart;
|
|
2559
|
+
}
|
|
2560
|
+
function logicalClip(work, chains, found) {
|
|
2561
|
+
const chain = chains.get(`${found.file}
|
|
2562
|
+
${found.clip.ref}`);
|
|
2563
|
+
const [head, ...others] = chain?.parts ?? [
|
|
2564
|
+
{ ...found, startMs: videoStartOf(work, found.file, found.clip), endMs: 0 }
|
|
2565
|
+
];
|
|
2566
|
+
if (!head)
|
|
2567
|
+
throw new EditError(`'${found.clip.ref}' is not one of the video's clips.`);
|
|
2568
|
+
const shown = (part) => {
|
|
2569
|
+
if (part.clip.durationMs === undefined)
|
|
2570
|
+
return;
|
|
2571
|
+
const scene = sceneOf(work, part.file);
|
|
2572
|
+
if (!scene || part.clip.startMs >= scene.durationMs)
|
|
2573
|
+
return part.clip.durationMs;
|
|
2574
|
+
return Math.min(part.clip.durationMs, scene.durationMs - part.clip.startMs);
|
|
2575
|
+
};
|
|
2576
|
+
const lengths = [head, ...others].map(shown);
|
|
2577
|
+
const durationMs = lengths.some((length) => length === undefined) ? undefined : lengths.reduce((sum, length) => sum + (length ?? 0), 0);
|
|
2578
|
+
const jumps = [];
|
|
2579
|
+
if (playsFile(head.clip)) {
|
|
2580
|
+
let intoMs = 0;
|
|
2581
|
+
others.forEach((part, at) => {
|
|
2582
|
+
const before = [head, ...others][at];
|
|
2583
|
+
intoMs += lengths[at] ?? 0;
|
|
2584
|
+
const stops = before.clip.mediaStartMs + (before.clip.durationMs ?? 0);
|
|
2585
|
+
if (Math.abs(part.clip.mediaStartMs - stops) > SAME_MS2) {
|
|
2586
|
+
jumps.push({ intoMs, mediaMs: part.clip.mediaStartMs });
|
|
2587
|
+
}
|
|
2588
|
+
});
|
|
2589
|
+
}
|
|
2590
|
+
return {
|
|
2591
|
+
file: head.file,
|
|
2592
|
+
clip: head.clip,
|
|
2593
|
+
startMs: head.startMs,
|
|
2594
|
+
durationMs,
|
|
2595
|
+
...jumps.length > 0 ? { jumps } : {},
|
|
2596
|
+
others: others.map(({ file, clip }) => ({ file, clip }))
|
|
2597
|
+
};
|
|
2598
|
+
}
|
|
2599
|
+
function mediaAt(mediaStartMs, jumps, intoMs) {
|
|
2600
|
+
const jump = jumps?.filter((each) => each.intoMs <= intoMs).at(-1);
|
|
2601
|
+
return jump ? jump.mediaMs + intoMs - jump.intoMs : mediaStartMs + intoMs;
|
|
2602
|
+
}
|
|
2603
|
+
function jumpsFrom(mediaStartMs, jumps, byMs) {
|
|
2604
|
+
if (!jumps)
|
|
2605
|
+
return { mediaStartMs: mediaStartMs + byMs };
|
|
2606
|
+
const ahead = jumps.filter((jump) => jump.intoMs > byMs).map((jump) => ({ intoMs: jump.intoMs - byMs, mediaMs: jump.mediaMs }));
|
|
2607
|
+
return {
|
|
2608
|
+
mediaStartMs: byMs < 0 ? mediaStartMs + byMs : mediaAt(mediaStartMs, jumps, byMs),
|
|
2609
|
+
...ahead.length > 0 ? { jumps: ahead } : {}
|
|
2610
|
+
};
|
|
2611
|
+
}
|
|
2612
|
+
function placeFound(work, placing) {
|
|
2613
|
+
const root = rootOf(work);
|
|
2614
|
+
const scenes = root.scenes;
|
|
2615
|
+
const frameMs = 1000 / root.fps;
|
|
2616
|
+
const plans = placing.map((each, index) => {
|
|
2617
|
+
const own = each.file === VIDEO_ENTRY2 ? undefined : scenes.find((scene) => scene.src === each.file);
|
|
2618
|
+
const parts = own ? atJumps(partsOf(scenes, own, each.startMs, each.durationMs), each, frameMs) : [];
|
|
2619
|
+
return { ...each, index, own, parts };
|
|
2620
|
+
});
|
|
2621
|
+
const read = new Map;
|
|
2622
|
+
const clipsIn = (file) => {
|
|
2623
|
+
const known = read.get(file);
|
|
2624
|
+
if (known)
|
|
2625
|
+
return known;
|
|
2626
|
+
const clips = timelineOf2(work, file).clips;
|
|
2627
|
+
read.set(file, clips);
|
|
2628
|
+
return clips;
|
|
2629
|
+
};
|
|
2630
|
+
for (const { file, clip, own, parts } of plans) {
|
|
2631
|
+
if (!own || parts.every((part) => part.scene.id === own.id))
|
|
2632
|
+
continue;
|
|
2633
|
+
for (const src of new Set([file, ...parts.map((part) => part.scene.src)])) {
|
|
2634
|
+
if (scenes.filter((scene) => scene.src === src).length > 1) {
|
|
2635
|
+
throw new EditError(`More than one scene plays ${src}: a clip can't leave or join it.`);
|
|
2636
|
+
}
|
|
2637
|
+
}
|
|
2638
|
+
const { start, end } = clip.source.element;
|
|
2639
|
+
const holds = clipsIn(file).some((other) => other.source.element.start > start && other.source.element.end <= end);
|
|
2640
|
+
if (holds)
|
|
2641
|
+
throw new EditError(`'${clip.ref}' holds other clips: it moves within its scene.`);
|
|
2642
|
+
}
|
|
2643
|
+
for (const [file, each] of byFile(plans)) {
|
|
2644
|
+
const marks = new Map(each.map((plan) => [plan.clip.ref, String(plan.index)]));
|
|
2645
|
+
const clips = timelineOf2(work, file).clips.filter((clip) => marks.has(clip.ref)).sort((a, b) => b.source.element.start - a.source.element.start);
|
|
2646
|
+
for (const clip of clips) {
|
|
2647
|
+
setAttributes(work, file, clip.source, { [PLACING]: marks.get(clip.ref) ?? null });
|
|
2648
|
+
}
|
|
2649
|
+
}
|
|
2650
|
+
const cut = new Map;
|
|
2651
|
+
const cuts = (file, id) => {
|
|
2652
|
+
if (!id)
|
|
2653
|
+
return;
|
|
2654
|
+
cut.set(file, (cut.get(file) ?? new Set).add(id));
|
|
2655
|
+
};
|
|
2656
|
+
for (const { file, clip, own, parts, durationMs, others } of plans) {
|
|
2657
|
+
const [first] = parts;
|
|
2658
|
+
const whole = parts.length === 1 && first?.scene.id === own?.id && first?.durationMs === durationMs;
|
|
2659
|
+
if (own && !whole)
|
|
2660
|
+
cuts(file, clip.id);
|
|
2661
|
+
for (const other of others ?? [])
|
|
2662
|
+
cuts(other.file, other.clip.id);
|
|
2663
|
+
}
|
|
2664
|
+
for (const [file, ids] of cut) {
|
|
2665
|
+
freezeFollowers(work, file, (clip) => clip.id !== undefined && ids.has(clip.id));
|
|
2666
|
+
}
|
|
2667
|
+
const counts = nameCounts(work);
|
|
2668
|
+
const taken = new Set(counts.keys());
|
|
2669
|
+
const carried = [];
|
|
2670
|
+
const left = [];
|
|
2671
|
+
const joined = [];
|
|
2672
|
+
const uncertain = new Set;
|
|
2673
|
+
const changes = new Map;
|
|
2674
|
+
const change = (file, ref, what) => {
|
|
2675
|
+
const plan = changes.get(file) ?? new Map;
|
|
2676
|
+
changes.set(file, plan);
|
|
2677
|
+
plan.set(ref, what);
|
|
2678
|
+
};
|
|
2679
|
+
const touched = new Set;
|
|
2680
|
+
const linked = linkedBlocks(work);
|
|
2681
|
+
const blocksOf = new Map;
|
|
2682
|
+
const parsed = (css) => {
|
|
2683
|
+
const known = blocksOf.get(css);
|
|
2684
|
+
if (known)
|
|
2685
|
+
return known;
|
|
2686
|
+
const blocks = cssBlocks(css);
|
|
2687
|
+
blocksOf.set(css, blocks);
|
|
2688
|
+
return blocks;
|
|
2689
|
+
};
|
|
2690
|
+
const looksOf = new Map;
|
|
2691
|
+
const contexts = new Map;
|
|
2692
|
+
const landing = (id) => {
|
|
2693
|
+
const known = contexts.get(id);
|
|
2694
|
+
if (known)
|
|
2695
|
+
return known;
|
|
2696
|
+
const scene = rootOf(work).scenes.find((each) => each.id === id);
|
|
2697
|
+
const context = scene ? sceneContext(work, scene) : undefined;
|
|
2698
|
+
if (context)
|
|
2699
|
+
contexts.set(id, context);
|
|
2700
|
+
return context;
|
|
2701
|
+
};
|
|
2702
|
+
const wrote = new Map;
|
|
2703
|
+
for (const [file, each] of byFile(plans)) {
|
|
2704
|
+
const text = work.text(file);
|
|
2705
|
+
const clips = timelineOf2(work, file).clips;
|
|
2706
|
+
const scripts = file === VIDEO_ENTRY2 ? "" : scriptsOf(text);
|
|
2707
|
+
const read = attributesRead([...linked, ...stylesIn(text).map((style) => parsed(style.css))]);
|
|
2708
|
+
for (const plan of each) {
|
|
2709
|
+
const { clip: was, own, parts, startMs, durationMs, index } = plan;
|
|
2710
|
+
const clip = markedClip(text, clips, index);
|
|
2711
|
+
if (!own) {
|
|
2712
|
+
change(file, clip.ref, {
|
|
2713
|
+
...startMs === was.startMs ? {} : { "data-start": seconds(startMs) },
|
|
2714
|
+
...durationMs === undefined || durationMs === was.durationMs ? {} : { "data-duration": seconds(durationMs) }
|
|
2715
|
+
});
|
|
2716
|
+
continue;
|
|
2717
|
+
}
|
|
2718
|
+
const element = text.slice(clip.source.element.start, clip.source.element.end);
|
|
2719
|
+
const facts = lookElement(element, was.id);
|
|
2720
|
+
const stays = parts[0]?.scene.id === own.id;
|
|
2721
|
+
const mediaStartMs = plan.mediaStartMs ?? was.mediaStartMs;
|
|
2722
|
+
const carriedKey = facts.attributes.get("data-look");
|
|
2723
|
+
const known = parts.some((part) => part.scene.id !== own.id) ? (() => {
|
|
2724
|
+
const signature = `${file}
|
|
2725
|
+
${carriedKey ?? ""}
|
|
2726
|
+
${lookSignature(facts, read)}`;
|
|
2727
|
+
const cached = looksOf.get(signature);
|
|
2728
|
+
if (cached)
|
|
2729
|
+
return cached;
|
|
2730
|
+
const styled = lookSheets(stylesIn(text), carriedKey, linked, parsed);
|
|
2731
|
+
const found = {
|
|
2732
|
+
look: lookOf(facts, own.id, styled.sheets),
|
|
2733
|
+
home: styled.home ?? own.id
|
|
2734
|
+
};
|
|
2735
|
+
looksOf.set(signature, found);
|
|
2736
|
+
return found;
|
|
2737
|
+
})() : undefined;
|
|
2738
|
+
const look = known?.look;
|
|
2739
|
+
const home = known?.home ?? own.id;
|
|
2740
|
+
const key = look && look.rules.length > 0 ? lookKey(home, look) : undefined;
|
|
2741
|
+
if (look?.uncertain) {
|
|
2742
|
+
const from = clipContext(work, own, text, clip);
|
|
2743
|
+
const elsewhere = new Set(parts.map((part) => part.scene).filter((scene) => scene.id !== home));
|
|
2744
|
+
const differs = [...elsewhere].some((scene) => lookDiffers(look, facts, { from, to: landing(scene.id) ?? [] }));
|
|
2745
|
+
if (differs)
|
|
2746
|
+
uncertain.add(index);
|
|
2747
|
+
}
|
|
2748
|
+
const base = was.id ?? slug(was.src?.replace(/^.*\//, "").replace(/\.[^.]*$/, "") ?? "");
|
|
2749
|
+
const fresh = () => {
|
|
2750
|
+
const id = uniqueName(base || was.kind, taken);
|
|
2751
|
+
taken.add(id);
|
|
2752
|
+
return id;
|
|
2753
|
+
};
|
|
2754
|
+
const others = [...plan.others ?? []];
|
|
2755
|
+
const reuse = (src) => {
|
|
2756
|
+
const at = others.findIndex((other) => other.file === src);
|
|
2757
|
+
return at < 0 ? undefined : others.splice(at, 1)[0];
|
|
2758
|
+
};
|
|
2759
|
+
const keepsId = was.id !== undefined && (stays || (counts.get(was.id) ?? 0) <= 1);
|
|
2760
|
+
const headId = keepsId ? was.id : was.id || parts.length > 1 ? fresh() : undefined;
|
|
2761
|
+
if (headId && headId === was.id)
|
|
2762
|
+
taken.add(headId);
|
|
2763
|
+
const written = new Set;
|
|
2764
|
+
for (const id of [headId, was.id])
|
|
2765
|
+
if (id)
|
|
2766
|
+
wrote.set(id, written);
|
|
2767
|
+
const lastOther = plan.others?.at(-1);
|
|
2768
|
+
const fadeOutMs = lastOther ? lastOther.clip.fadeOutMs : was.fadeOutMs;
|
|
2769
|
+
const fades = (n, now) => ({
|
|
2770
|
+
...n > 0 && now.fadeInMs !== undefined ? { "data-fade-in": null } : {},
|
|
2771
|
+
...n < parts.length - 1 ? now.fadeOutMs === undefined ? {} : { "data-fade-out": null } : now.fadeOutMs === fadeOutMs ? {} : { "data-fade-out": fadeOutMs === undefined ? null : seconds(fadeOutMs) }
|
|
2772
|
+
});
|
|
2773
|
+
parts.forEach((part, n) => {
|
|
2774
|
+
const media = mediaAt(mediaStartMs, plan.jumps, part.intoMs);
|
|
2775
|
+
const timing = {
|
|
2776
|
+
start: seconds(part.startMs - part.scene.startMs),
|
|
2777
|
+
duration: part.durationMs === undefined ? undefined : seconds(part.durationMs),
|
|
2778
|
+
media: playsFile(was) ? seconds(media) : undefined
|
|
2779
|
+
};
|
|
2780
|
+
if (n === 0 && stays) {
|
|
2781
|
+
change(file, clip.ref, {
|
|
2782
|
+
...part.startMs === own.startMs + was.startMs ? {} : { "data-start": timing.start },
|
|
2783
|
+
...timing.duration === undefined || part.durationMs === was.durationMs ? {} : { "data-duration": timing.duration },
|
|
2784
|
+
...timing.media === undefined || mediaStartMs === was.mediaStartMs ? {} : { "data-media-start": timing.media },
|
|
2785
|
+
...headId && headId !== was.id ? { id: headId } : {},
|
|
2786
|
+
...was.continues ? { "data-continues": null } : {},
|
|
2787
|
+
...fades(n, was)
|
|
2788
|
+
});
|
|
2789
|
+
return;
|
|
2790
|
+
}
|
|
2791
|
+
const kept = n > 0 ? reuse(part.scene.src) : undefined;
|
|
2792
|
+
if (kept) {
|
|
2793
|
+
const old = kept.clip;
|
|
2794
|
+
written.add(`${kept.file}
|
|
2795
|
+
${old.id ?? old.ref}`);
|
|
2796
|
+
change(kept.file, old.ref, {
|
|
2797
|
+
...part.startMs - part.scene.startMs === old.startMs ? {} : { "data-start": timing.start },
|
|
2798
|
+
...part.durationMs === old.durationMs || timing.duration === undefined ? {} : { "data-duration": timing.duration },
|
|
2799
|
+
...timing.media === undefined || media === old.mediaStartMs ? {} : { "data-media-start": timing.media },
|
|
2800
|
+
...old.continues === headId ? {} : { "data-continues": headId ?? null },
|
|
2801
|
+
...fades(n, old)
|
|
2802
|
+
});
|
|
2803
|
+
return;
|
|
2804
|
+
}
|
|
2805
|
+
const id = n === 0 ? headId : fresh();
|
|
2806
|
+
if (n > 0 && id)
|
|
2807
|
+
written.add(`${part.scene.src}
|
|
2808
|
+
${id}`);
|
|
2809
|
+
const styled = key !== undefined && part.scene.id !== home;
|
|
2810
|
+
const src = attributeOf(text, clip, "src");
|
|
2811
|
+
const moved = src === undefined ? undefined : rebased(work, file, part.scene.src, src);
|
|
2812
|
+
const html = withAttributes(element, {
|
|
2813
|
+
...id ? { id } : {},
|
|
2814
|
+
"data-start": timing.start,
|
|
2815
|
+
...timing.duration === undefined ? {} : { "data-duration": timing.duration },
|
|
2816
|
+
...timing.media === undefined || media === was.mediaStartMs ? {} : { "data-media-start": timing.media },
|
|
2817
|
+
...moved === undefined ? {} : { src: moved },
|
|
2818
|
+
"data-continues": n === 0 ? null : headId ?? null,
|
|
2819
|
+
"data-look": styled ? key : null,
|
|
2820
|
+
...fades(n, was),
|
|
2821
|
+
...n === 0 ? {} : { [PLACING]: null }
|
|
2822
|
+
});
|
|
2823
|
+
carried.push({
|
|
2824
|
+
file: part.scene.src,
|
|
2825
|
+
scene: part.scene.id,
|
|
2826
|
+
track: was.track,
|
|
2827
|
+
html,
|
|
2828
|
+
index,
|
|
2829
|
+
element: { ...facts, ...id ? { id } : {} },
|
|
2830
|
+
...look && key && styled ? { look, key, home } : {}
|
|
2831
|
+
});
|
|
2832
|
+
});
|
|
2833
|
+
if (!stays) {
|
|
2834
|
+
change(file, clip.ref, "remove");
|
|
2835
|
+
touched.add(file);
|
|
2836
|
+
if (scriptNames(scripts, facts))
|
|
2837
|
+
left.push({ index, scene: own.id });
|
|
2838
|
+
}
|
|
2839
|
+
for (const other of others) {
|
|
2840
|
+
change(other.file, other.clip.ref, "remove");
|
|
2841
|
+
touched.add(other.file);
|
|
2842
|
+
}
|
|
2843
|
+
}
|
|
2844
|
+
}
|
|
2845
|
+
for (const [file, plan] of changes)
|
|
2846
|
+
rewriteClips(work, file, plan);
|
|
2847
|
+
for (const [file, each] of groupBy(carried, (one) => one.file)) {
|
|
2848
|
+
for (const track of ["picture", "text", "sound"]) {
|
|
2849
|
+
const batch = each.filter((one) => one.track === track);
|
|
2850
|
+
if (batch.length === 0)
|
|
2851
|
+
continue;
|
|
2852
|
+
insertInComposition(work, file, timelineOf2(work, file), batch.map((one) => one.html), track);
|
|
2853
|
+
}
|
|
2854
|
+
const scripts = scriptsOf(work.text(file));
|
|
2855
|
+
const seen = sceneKeyframes(work, file, linked);
|
|
2856
|
+
const carriedIn = new Map(seen.carried);
|
|
2857
|
+
const text = work.text(file);
|
|
2858
|
+
const present = lookBlocks(text);
|
|
2859
|
+
const written = new Set(present.map((block) => block.key));
|
|
2860
|
+
const looks = [];
|
|
2861
|
+
for (const one of each) {
|
|
2862
|
+
const there = one.key ? present.find((block) => block.key === one.key) : undefined;
|
|
2863
|
+
if (there)
|
|
2864
|
+
work.writeWhole(file, text.slice(...spanOf(lineBlock(text, there))));
|
|
2865
|
+
if (one.look && one.key && one.home && !written.has(one.key)) {
|
|
2866
|
+
written.add(one.key);
|
|
2867
|
+
const rules = writtenLook(one.look, one.scene, one.key, {
|
|
2868
|
+
own: seen.own,
|
|
2869
|
+
carried: carriedIn
|
|
2870
|
+
});
|
|
2871
|
+
if (rules.length > 0)
|
|
2872
|
+
looks.push({ key: one.key, home: one.home, rules });
|
|
2873
|
+
for (const [name, body] of keyframesOf(cssBlocks(rules.join(`
|
|
2874
|
+
`)))) {
|
|
2875
|
+
carriedIn.set(name, [...carriedIn.get(name) ?? [], body]);
|
|
2876
|
+
}
|
|
2877
|
+
}
|
|
2878
|
+
const context = landing(one.scene);
|
|
2879
|
+
const reaches = context ? scriptReachesIn(scripts, one.element, context) : scriptReaches(scripts, one.element);
|
|
2880
|
+
if (reaches && !joined.some((each) => each.index === one.index)) {
|
|
2881
|
+
joined.push({ index: one.index, scene: one.scene });
|
|
2882
|
+
}
|
|
2883
|
+
}
|
|
2884
|
+
writeLooks(work, file, looks);
|
|
2885
|
+
}
|
|
2886
|
+
for (const file of touched)
|
|
2887
|
+
pruneLooks(work, file);
|
|
2888
|
+
if (wrote.size > 0) {
|
|
2889
|
+
for (const scene of rootOf(work).scenes) {
|
|
2890
|
+
const text = work.textOf(scene.src);
|
|
2891
|
+
if (text === undefined || !text.includes("data-continues"))
|
|
2892
|
+
continue;
|
|
2893
|
+
for (;; ) {
|
|
2894
|
+
const stale = readTimeline(work, scene.src)?.clips.find((clip) => {
|
|
2895
|
+
const parts = clip.continues ? wrote.get(clip.continues) : undefined;
|
|
2896
|
+
return parts !== undefined && !parts.has(`${scene.src}
|
|
2897
|
+
${clip.id ?? clip.ref}`);
|
|
2898
|
+
});
|
|
2899
|
+
if (!stale)
|
|
2900
|
+
break;
|
|
2901
|
+
setAttributes(work, scene.src, stale.source, { "data-continues": null });
|
|
2902
|
+
}
|
|
2903
|
+
}
|
|
2904
|
+
}
|
|
2905
|
+
const needed = new Map;
|
|
2906
|
+
for (const { parts } of plans) {
|
|
2907
|
+
for (const part of parts) {
|
|
2908
|
+
if (part.durationMs === undefined)
|
|
2909
|
+
continue;
|
|
2910
|
+
const end = part.startMs + part.durationMs - part.scene.startMs;
|
|
2911
|
+
needed.set(part.scene.id, Math.max(needed.get(part.scene.id) ?? 0, end));
|
|
2912
|
+
}
|
|
2913
|
+
}
|
|
2914
|
+
const step = frameStepMs(rootOf(work).fps);
|
|
2915
|
+
for (const [id, end] of needed) {
|
|
2916
|
+
const scene = scenes.find((each) => each.id === id);
|
|
2917
|
+
if (scene && end > scene.durationMs + SAME_MS2) {
|
|
2918
|
+
lengthenScene(work, id, Math.ceil(end / step) * step);
|
|
2919
|
+
}
|
|
2920
|
+
}
|
|
2921
|
+
const found = new Map;
|
|
2922
|
+
for (const file of new Set([
|
|
2923
|
+
...plans.map((plan) => plan.file),
|
|
2924
|
+
...carried.map((one) => one.file)
|
|
2925
|
+
])) {
|
|
2926
|
+
const text = work.text(file);
|
|
2927
|
+
const marked = timelineOf2(work, file).clips.filter((clip) => clip.source.attributes[PLACING]).sort((a, b) => b.source.element.start - a.source.element.start);
|
|
2928
|
+
for (const clip of marked) {
|
|
2929
|
+
const at = clip.source.attributes[PLACING];
|
|
2930
|
+
found.set(Number(at ? attributeValue(text, at) : Number.NaN), {
|
|
2931
|
+
file,
|
|
2932
|
+
clip: videoTarget(clip)
|
|
2933
|
+
});
|
|
2934
|
+
setAttributes(work, file, clip.source, { [PLACING]: null });
|
|
2935
|
+
}
|
|
2936
|
+
}
|
|
2937
|
+
return {
|
|
2938
|
+
clips: plans.flatMap((plan) => {
|
|
2939
|
+
const at = found.get(plan.index);
|
|
2940
|
+
return at ? [at] : [];
|
|
2941
|
+
}),
|
|
2942
|
+
animationsLeft: left.flatMap(({ index, scene }) => {
|
|
2943
|
+
const clip = found.get(index);
|
|
2944
|
+
return clip ? [{ clip, scene }] : [];
|
|
2945
|
+
}),
|
|
2946
|
+
animationsJoined: joined.flatMap(({ index, scene }) => {
|
|
2947
|
+
const clip = found.get(index);
|
|
2948
|
+
return clip ? [{ clip, scene }] : [];
|
|
2949
|
+
}),
|
|
2950
|
+
looksMayDiffer: [...uncertain].flatMap((index) => {
|
|
2951
|
+
const clip = found.get(index);
|
|
2952
|
+
return clip ? [clip] : [];
|
|
2953
|
+
})
|
|
2954
|
+
};
|
|
2955
|
+
}
|
|
2956
|
+
function partsOf(every, own, startMs, durationMs) {
|
|
2957
|
+
const scenes = videoChapters(every);
|
|
2958
|
+
if (!scenes.includes(own)) {
|
|
2959
|
+
return [{ scene: own, startMs: Math.max(startMs, own.startMs), durationMs, intoMs: 0 }];
|
|
2960
|
+
}
|
|
2961
|
+
const end = (scene) => scene.startMs + scene.durationMs;
|
|
2962
|
+
const holds = (scene, ms) => scene.startMs <= ms && ms < end(scene);
|
|
2963
|
+
const onTop = (ms, except) => scenes.filter((scene) => scene !== except && holds(scene, ms)).at(-1);
|
|
2964
|
+
const from = (ms, except) => scenes.find((scene) => scene !== except && scene.startMs >= ms);
|
|
2965
|
+
const last = scenes.reduce((latest, scene) => end(scene) >= end(latest) ? scene : latest, own);
|
|
2966
|
+
const next = (scene) => sceneAfter(scenes, scene);
|
|
2967
|
+
let scene = (holds(own, startMs) ? own : undefined) ?? onTop(startMs) ?? from(startMs) ?? last;
|
|
2968
|
+
const first = Math.max(startMs, scene.startMs);
|
|
2969
|
+
if (durationMs === undefined)
|
|
2970
|
+
return [{ scene, startMs: first, durationMs, intoMs: 0 }];
|
|
2971
|
+
const clipEnd = first + durationMs;
|
|
2972
|
+
const pieces = [];
|
|
2973
|
+
let at = first;
|
|
2974
|
+
for (;; ) {
|
|
2975
|
+
const after = clipEnd > end(scene) + SAME_MS2 ? next(scene) : undefined;
|
|
2976
|
+
const until = after ? end(scene) : clipEnd;
|
|
2977
|
+
pieces.push({ scene, startMs: at, durationMs: until - at, intoMs: at - first });
|
|
2978
|
+
if (!after)
|
|
2979
|
+
break;
|
|
2980
|
+
at = Math.max(end(scene), after.startMs);
|
|
2981
|
+
if (at >= clipEnd)
|
|
2982
|
+
break;
|
|
2983
|
+
scene = after;
|
|
2984
|
+
}
|
|
2985
|
+
const kept = pieces.filter((piece) => (piece.durationMs ?? 0) >= MIN_CLIP_MS);
|
|
2986
|
+
if (kept.length > 0)
|
|
2987
|
+
return kept;
|
|
2988
|
+
const longest = pieces.reduce((a, b) => (b.durationMs ?? 0) > (a.durationMs ?? 0) ? b : a);
|
|
2989
|
+
return [longest];
|
|
2990
|
+
}
|
|
2991
|
+
function atJumps(parts, placing, frameMs) {
|
|
2992
|
+
const jumps = placing.jumps ?? [];
|
|
2993
|
+
if (jumps.length === 0)
|
|
2994
|
+
return [...parts];
|
|
2995
|
+
return parts.flatMap((part) => {
|
|
2996
|
+
if (part.durationMs === undefined)
|
|
2997
|
+
return [part];
|
|
2998
|
+
const end = part.intoMs + part.durationMs;
|
|
2999
|
+
const cuts = jumps.map((jump) => jump.intoMs).filter((at) => at > part.intoMs && at < end);
|
|
3000
|
+
const edges = [part.intoMs, ...cuts, end];
|
|
3001
|
+
const pieces = edges.slice(1).map((to, at) => {
|
|
3002
|
+
const from = edges[at];
|
|
3003
|
+
return {
|
|
3004
|
+
...part,
|
|
3005
|
+
startMs: part.startMs + from - part.intoMs,
|
|
3006
|
+
durationMs: to - from,
|
|
3007
|
+
intoMs: from
|
|
3008
|
+
};
|
|
3009
|
+
});
|
|
3010
|
+
const whole = pieces.filter((piece) => piece.durationMs >= frameMs);
|
|
3011
|
+
return whole.length > 0 ? whole : pieces;
|
|
3012
|
+
});
|
|
3013
|
+
}
|
|
3014
|
+
function sceneContext(work, scene) {
|
|
3015
|
+
const index = work.text(VIDEO_ENTRY2);
|
|
3016
|
+
const composition = work.textOf(scene.src) === undefined ? undefined : readTimeline(work, scene.src);
|
|
3017
|
+
return [
|
|
3018
|
+
startTagOf(index, rootOf(work).root),
|
|
3019
|
+
startTagOf(index, scene.host),
|
|
3020
|
+
...composition ? [startTagOf(work.text(scene.src), composition.composition)] : []
|
|
3021
|
+
];
|
|
3022
|
+
}
|
|
3023
|
+
function clipContext(work, scene, text, clip) {
|
|
3024
|
+
const timeline = readTimeline(work, scene.src);
|
|
3025
|
+
const content = timeline?.composition.content;
|
|
3026
|
+
const wrappers = content ? wrappersOf(text, content.start, clip.source.element.start) : [];
|
|
3027
|
+
return [...sceneContext(work, scene), ...wrappers];
|
|
3028
|
+
}
|
|
3029
|
+
function startTagOf(text, source) {
|
|
3030
|
+
const html = text.slice(source.tag.start, source.tag.end);
|
|
3031
|
+
const element = lookElement(html, undefined);
|
|
3032
|
+
const id = element.attributes.get("id");
|
|
3033
|
+
return id ? { ...element, id } : element;
|
|
3034
|
+
}
|
|
3035
|
+
function wrappersOf(text, from, to) {
|
|
3036
|
+
const open = [];
|
|
3037
|
+
const tags = /<!--[\s\S]*?-->|<(\/?)([a-zA-Z][\w-]*)\b[^>]*>/g;
|
|
3038
|
+
tags.lastIndex = from;
|
|
3039
|
+
for (let match = tags.exec(text);match && match.index < to; match = tags.exec(text)) {
|
|
3040
|
+
const [html, closing, name] = match;
|
|
3041
|
+
if (!name)
|
|
3042
|
+
continue;
|
|
3043
|
+
const tag = name.toLowerCase();
|
|
3044
|
+
if (closing) {
|
|
3045
|
+
const at = open.map((each) => each.tag).lastIndexOf(tag);
|
|
3046
|
+
if (at >= 0)
|
|
3047
|
+
open.length = at;
|
|
3048
|
+
continue;
|
|
3049
|
+
}
|
|
3050
|
+
if (VOID_TAGS.has(tag) || html.endsWith("/>"))
|
|
3051
|
+
continue;
|
|
3052
|
+
if (tag === "script" || tag === "style") {
|
|
3053
|
+
const end = text.indexOf(`</${tag}`, tags.lastIndex);
|
|
3054
|
+
tags.lastIndex = end < 0 ? text.length : end;
|
|
3055
|
+
continue;
|
|
3056
|
+
}
|
|
3057
|
+
open.push({ tag, html });
|
|
3058
|
+
}
|
|
3059
|
+
return open.map(({ html }) => {
|
|
3060
|
+
const element = lookElement(html, undefined);
|
|
3061
|
+
const id = element.attributes.get("id");
|
|
3062
|
+
return id ? { ...element, id } : element;
|
|
3063
|
+
});
|
|
3064
|
+
}
|
|
3065
|
+
var VOID_TAGS = new Set([
|
|
3066
|
+
"area",
|
|
3067
|
+
"base",
|
|
3068
|
+
"br",
|
|
3069
|
+
"col",
|
|
3070
|
+
"embed",
|
|
3071
|
+
"hr",
|
|
3072
|
+
"img",
|
|
3073
|
+
"input",
|
|
3074
|
+
"link",
|
|
3075
|
+
"meta",
|
|
3076
|
+
"source",
|
|
3077
|
+
"track",
|
|
3078
|
+
"wbr"
|
|
3079
|
+
]);
|
|
3080
|
+
function lookElement(html, id) {
|
|
3081
|
+
const source = readElement(html);
|
|
3082
|
+
const attributes = new Map;
|
|
3083
|
+
for (const [name, at] of Object.entries(source.attributes)) {
|
|
3084
|
+
attributes.set(name, attributeValue(html, at) ?? "");
|
|
3085
|
+
}
|
|
3086
|
+
return {
|
|
3087
|
+
tag: (/^<([a-zA-Z][\w-]*)/.exec(html)?.[1] ?? "").toLowerCase(),
|
|
3088
|
+
...id ? { id } : {},
|
|
3089
|
+
classes: (attributes.get("class") ?? "").split(/\s+/).filter(Boolean),
|
|
3090
|
+
attributes
|
|
3091
|
+
};
|
|
3092
|
+
}
|
|
3093
|
+
function lookSignature(element, read) {
|
|
3094
|
+
const attributes = [...element.attributes].filter(([name]) => read.has(name.toLowerCase()));
|
|
3095
|
+
return JSON.stringify([element.tag, element.id, element.classes, attributes]);
|
|
3096
|
+
}
|
|
3097
|
+
function attributesRead(sheets) {
|
|
3098
|
+
const read = new Set;
|
|
3099
|
+
for (const blocks of sheets) {
|
|
3100
|
+
for (const { prelude, body } of blocks) {
|
|
3101
|
+
for (const match of `${prelude}{${body}`.matchAll(/\[\s*([\w-]+)/g)) {
|
|
3102
|
+
read.add((match[1] ?? "").toLowerCase());
|
|
3103
|
+
}
|
|
3104
|
+
}
|
|
3105
|
+
}
|
|
3106
|
+
return read;
|
|
3107
|
+
}
|
|
3108
|
+
function stylesIn(text) {
|
|
3109
|
+
return [...text.matchAll(/<style\b([^>]*)>([\s\S]*?)<\/style>/gi)].map((match) => {
|
|
3110
|
+
const attributes = match[1] ?? "";
|
|
3111
|
+
const look = /\sdata-look\s*=\s*"([^"]*)"/.exec(attributes)?.[1];
|
|
3112
|
+
const from = /\sdata-from\s*=\s*"([^"]*)"/.exec(attributes)?.[1];
|
|
3113
|
+
return { css: match[2] ?? "", ...look ? { look } : {}, ...from ? { from } : {} };
|
|
3114
|
+
});
|
|
3115
|
+
}
|
|
3116
|
+
function linkedBlocks(work) {
|
|
3117
|
+
const exists = (path) => work.has(path);
|
|
3118
|
+
return rootOf(work).links.stylesheets.flatMap((link) => {
|
|
3119
|
+
const path = videoFilePath(VIDEO_ENTRY2, link.value, exists);
|
|
3120
|
+
const css = path === undefined ? undefined : work.textOf(path);
|
|
3121
|
+
return css === undefined ? [] : [cssBlocks(css)];
|
|
3122
|
+
});
|
|
3123
|
+
}
|
|
3124
|
+
function lookSheets(styles, key, linked, parsed) {
|
|
3125
|
+
const own = key ? styles.find((style) => style.look === key) : undefined;
|
|
3126
|
+
const byId = own !== undefined;
|
|
3127
|
+
const sheets = [
|
|
3128
|
+
...linked.map((blocks) => ({ blocks, byId, shared: true })),
|
|
3129
|
+
...styles.filter((style) => style.look === undefined).map((style) => ({ blocks: parsed(style.css), byId })),
|
|
3130
|
+
...own ? [{ blocks: parsed(own.css), carried: true }] : []
|
|
3131
|
+
];
|
|
3132
|
+
return { sheets, ...own?.from ? { home: own.from } : {} };
|
|
3133
|
+
}
|
|
3134
|
+
function sceneKeyframes(work, file, linked) {
|
|
3135
|
+
const own = new Map;
|
|
3136
|
+
const carried = new Map;
|
|
3137
|
+
const styles = stylesIn(work.text(file));
|
|
3138
|
+
for (const blocks of [
|
|
3139
|
+
...styles.filter((style) => !style.look).map((style) => cssBlocks(style.css)),
|
|
3140
|
+
...linked
|
|
3141
|
+
]) {
|
|
3142
|
+
for (const [name, body] of keyframesOf(blocks))
|
|
3143
|
+
if (!own.has(name))
|
|
3144
|
+
own.set(name, body);
|
|
3145
|
+
}
|
|
3146
|
+
for (const style of styles.filter((each) => each.look)) {
|
|
3147
|
+
for (const [name, body] of keyframesOf(cssBlocks(style.css))) {
|
|
3148
|
+
carried.set(name, [...carried.get(name) ?? [], body]);
|
|
3149
|
+
}
|
|
3150
|
+
}
|
|
3151
|
+
return { own, carried };
|
|
3152
|
+
}
|
|
3153
|
+
function looksIn(text) {
|
|
3154
|
+
return stylesIn(text).flatMap((style) => style.look ? [style.look] : []);
|
|
3155
|
+
}
|
|
3156
|
+
function lookBlocks(text) {
|
|
3157
|
+
return [...text.matchAll(/<style\b([^>]*)>[\s\S]*?<\/style>/gi)].flatMap((match) => {
|
|
3158
|
+
const key = /\sdata-look\s*=\s*"([^"]*)"/.exec(match[1] ?? "")?.[1];
|
|
3159
|
+
return key ? [{ key, start: match.index, end: match.index + match[0].length }] : [];
|
|
3160
|
+
});
|
|
3161
|
+
}
|
|
3162
|
+
function pruneLooks(work, file) {
|
|
3163
|
+
if (!work.textOf(file)?.includes("data-look"))
|
|
3164
|
+
return;
|
|
3165
|
+
for (const key of new Set(looksIn(work.text(file)))) {
|
|
3166
|
+
const name = key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3167
|
+
for (;; ) {
|
|
3168
|
+
const text = work.text(file);
|
|
3169
|
+
const blocks = lookBlocks(text).filter((block) => block.key === key);
|
|
3170
|
+
const named = text.match(new RegExp(`\\sdata-look\\s*=\\s*"${name}"`, "g"))?.length ?? 0;
|
|
3171
|
+
const extra = named > blocks.length ? blocks.slice(1) : blocks;
|
|
3172
|
+
const last = extra.at(-1);
|
|
3173
|
+
if (!last)
|
|
3174
|
+
break;
|
|
3175
|
+
work.replace(file, ...spanOf(lineBlock(text, last)), "");
|
|
3176
|
+
}
|
|
3177
|
+
}
|
|
3178
|
+
}
|
|
3179
|
+
function writeLooks(work, file, looks) {
|
|
3180
|
+
if (looks.length === 0)
|
|
3181
|
+
return;
|
|
3182
|
+
const text = work.text(file);
|
|
3183
|
+
const timeline = timelineOf2(work, file);
|
|
3184
|
+
const children = timeline.children;
|
|
3185
|
+
let closing = children.length;
|
|
3186
|
+
while (closing > 0 && children[closing - 1]?.tag === "script")
|
|
3187
|
+
closing -= 1;
|
|
3188
|
+
const next = children[closing];
|
|
3189
|
+
const previous = children[closing - 1];
|
|
3190
|
+
const indent = next ? lineIndent(text, next.source.element.start) : previous ? lineIndent(text, previous.source.element.start) : `${lineIndent(text, timeline.composition.element.start)} `;
|
|
3191
|
+
const styles = looks.map(({ key, home, rules }) => {
|
|
3192
|
+
const body = rules.map((rule) => `${indent} ${rule.replace(/\n/g, `
|
|
3193
|
+
${indent} `)}`);
|
|
3194
|
+
return `<style data-look="${escapeAttribute(key)}" data-from="${escapeAttribute(home)}">
|
|
3195
|
+
${body.join(`
|
|
3196
|
+
`)}
|
|
3197
|
+
${indent}</style>`;
|
|
3198
|
+
}).join(`
|
|
3199
|
+
${indent}`);
|
|
3200
|
+
if (next && aloneOnLine(text, next.source.element.start)) {
|
|
3201
|
+
const lineStart = text.lastIndexOf(`
|
|
3202
|
+
`, next.source.element.start - 1) + 1;
|
|
3203
|
+
work.replace(file, lineStart, lineStart, `${indent}${styles}
|
|
3204
|
+
`);
|
|
3205
|
+
} else if (previous) {
|
|
3206
|
+
const block = lineBlock(text, previous.source.element);
|
|
3207
|
+
work.replace(file, block.end, block.end, `${indent}${styles}${lineEnd(text, block)}`);
|
|
3208
|
+
} else {
|
|
3209
|
+
const content = timeline.composition.content;
|
|
3210
|
+
if (!content)
|
|
3211
|
+
throw new EditError(`${file}: its composition holds nothing a style can join.`);
|
|
3212
|
+
work.replace(file, content.start, content.start, `
|
|
3213
|
+
${indent}${styles}`);
|
|
3214
|
+
}
|
|
3215
|
+
}
|
|
3216
|
+
function aloneOnLine(text, at) {
|
|
3217
|
+
return text.slice(text.lastIndexOf(`
|
|
3218
|
+
`, at - 1) + 1, at).trim() === "";
|
|
3219
|
+
}
|
|
3220
|
+
function scriptsOf(text) {
|
|
3221
|
+
return [...text.matchAll(/<script\b[^>]*>([\s\S]*?)<\/script>/gi)].map((match) => match[1] ?? "").join(`
|
|
3222
|
+
`);
|
|
3223
|
+
}
|
|
3224
|
+
function spanOf(span) {
|
|
3225
|
+
return [span.start, span.end];
|
|
3226
|
+
}
|
|
3227
|
+
function rebased(work, from, to, written) {
|
|
3228
|
+
const exists = (path) => work.has(path);
|
|
3229
|
+
const path = videoFilePath(from, written, exists);
|
|
3230
|
+
if (path === undefined || videoFilePath(to, written, exists) === path)
|
|
3231
|
+
return;
|
|
3232
|
+
const up = "../".repeat(to.split("/").length - 1);
|
|
3233
|
+
return [path, `${up}${path}`].find((each) => videoFilePath(to, each, exists) === path);
|
|
3234
|
+
}
|
|
3235
|
+
function markedClip(text, clips, index) {
|
|
3236
|
+
const found = clips.find((clip) => {
|
|
3237
|
+
const at = clip.source.attributes[PLACING];
|
|
3238
|
+
return at !== undefined && attributeValue(text, at) === String(index);
|
|
3239
|
+
});
|
|
3240
|
+
if (!found)
|
|
3241
|
+
throw new EditError("A clip changed while it was placed: try again.");
|
|
3242
|
+
return found;
|
|
3243
|
+
}
|
|
3244
|
+
function attributeOf(text, clip, name) {
|
|
3245
|
+
const at = clip.source.attributes[name];
|
|
3246
|
+
return at ? attributeValue(text, at) : undefined;
|
|
3247
|
+
}
|
|
3248
|
+
function groupBy(items, key) {
|
|
3249
|
+
const groups = new Map;
|
|
3250
|
+
for (const item of items)
|
|
3251
|
+
groups.set(key(item), [...groups.get(key(item)) ?? [], item]);
|
|
3252
|
+
return groups;
|
|
3253
|
+
}
|
|
3254
|
+
function setAttributes(work, file, source, values) {
|
|
3255
|
+
const text = work.text(file);
|
|
3256
|
+
const steps = [];
|
|
3257
|
+
const added = [];
|
|
3258
|
+
for (const [name, value] of Object.entries(values)) {
|
|
3259
|
+
for (const copy of laterCopies(text, source, name)) {
|
|
3260
|
+
steps.push({ at: copy.start, run: () => work.replace(file, copy.start, copy.end, "") });
|
|
3261
|
+
}
|
|
3262
|
+
const at = source.attributes[name];
|
|
3263
|
+
if (!at) {
|
|
3264
|
+
if (value !== null)
|
|
3265
|
+
added.push(` ${name}="${escapeAttribute(value)}"`);
|
|
3266
|
+
continue;
|
|
3267
|
+
}
|
|
3268
|
+
if (value === null) {
|
|
3269
|
+
let start = at.start;
|
|
3270
|
+
while (start > 0 && /[ \t\n\r]/.test(text[start - 1] ?? ""))
|
|
3271
|
+
start -= 1;
|
|
3272
|
+
steps.push({ at: at.start, run: () => work.replace(file, start, at.end, "") });
|
|
3273
|
+
continue;
|
|
3274
|
+
}
|
|
3275
|
+
const span = valueSpan(text, at);
|
|
3276
|
+
if (!span) {
|
|
3277
|
+
steps.push({
|
|
3278
|
+
at: at.start,
|
|
3279
|
+
run: () => work.replace(file, at.start, at.end, `${name}="${escapeAttribute(value)}"`)
|
|
3280
|
+
});
|
|
3281
|
+
continue;
|
|
3282
|
+
}
|
|
3283
|
+
const written = span.quoted ? escapeAttribute(value) : `"${escapeAttribute(value)}"`;
|
|
3284
|
+
if (attributeValue(text, at) === value)
|
|
3285
|
+
continue;
|
|
3286
|
+
steps.push({ at: at.start, run: () => work.replace(file, span.start, span.end, written) });
|
|
3287
|
+
}
|
|
3288
|
+
if (added.length > 0) {
|
|
3289
|
+
const close = text.slice(source.tag.start, source.tag.end).endsWith("/>") ? 2 : 1;
|
|
3290
|
+
let at = source.tag.end - close;
|
|
3291
|
+
while (at > source.tag.start && /[ \t\n\r]/.test(text[at - 1] ?? ""))
|
|
3292
|
+
at -= 1;
|
|
3293
|
+
steps.push({ at, run: () => work.replace(file, at, at, added.join("")) });
|
|
3294
|
+
}
|
|
3295
|
+
for (const step of steps.sort((a, b) => b.at - a.at))
|
|
3296
|
+
step.run();
|
|
3297
|
+
}
|
|
3298
|
+
function laterCopies(text, source, name) {
|
|
3299
|
+
const first = source.attributes[name];
|
|
3300
|
+
if (!first)
|
|
3301
|
+
return [];
|
|
3302
|
+
const copies = [];
|
|
3303
|
+
const pattern = /\s+([^\s"'>/=]+)(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'=<>`]+))?/y;
|
|
3304
|
+
let at = first.end;
|
|
3305
|
+
for (;; ) {
|
|
3306
|
+
pattern.lastIndex = at;
|
|
3307
|
+
const match = pattern.exec(text);
|
|
3308
|
+
if (!match?.[1] || match.index + match[0].length > source.tag.end)
|
|
3309
|
+
break;
|
|
3310
|
+
if (match[1].toLowerCase() === name) {
|
|
3311
|
+
copies.push({ start: match.index, end: match.index + match[0].length });
|
|
3312
|
+
}
|
|
3313
|
+
at = match.index + match[0].length;
|
|
3314
|
+
}
|
|
3315
|
+
return copies;
|
|
3316
|
+
}
|
|
3317
|
+
function withAttributes(html, values) {
|
|
3318
|
+
const scratch = new Working(new Map([["element.html", html]]));
|
|
3319
|
+
const source = readElement(html);
|
|
3320
|
+
setAttributes(scratch, "element.html", source, values);
|
|
3321
|
+
return scratch.text("element.html");
|
|
3322
|
+
}
|
|
3323
|
+
function readElement(html) {
|
|
3324
|
+
const tag = /^<([a-zA-Z][\w-]*)/.exec(html);
|
|
3325
|
+
if (!tag)
|
|
3326
|
+
throw new EditError("An element was expected.");
|
|
3327
|
+
const attributes = {};
|
|
3328
|
+
const pattern = /\s+([^\s"'>/=]+)(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'=<>`]+))?/y;
|
|
3329
|
+
let at = tag[0].length;
|
|
3330
|
+
for (;; ) {
|
|
3331
|
+
pattern.lastIndex = at;
|
|
3332
|
+
const match = pattern.exec(html);
|
|
3333
|
+
if (!match?.[1])
|
|
3334
|
+
break;
|
|
3335
|
+
const name = match[1].toLowerCase();
|
|
3336
|
+
const start = match.index + match[0].length - match[0].trimStart().length;
|
|
3337
|
+
attributes[name] ??= { start, end: match.index + match[0].length };
|
|
3338
|
+
at = match.index + match[0].length;
|
|
3339
|
+
}
|
|
3340
|
+
const close = html.indexOf(">", at);
|
|
3341
|
+
if (close < 0)
|
|
3342
|
+
throw new EditError("An element's start tag was not closed.");
|
|
3343
|
+
return { element: { start: 0, end: html.length }, tag: { start: 0, end: close + 1 }, attributes };
|
|
3344
|
+
}
|
|
3345
|
+
function valueSpan(text, at) {
|
|
3346
|
+
const written = text.slice(at.start, at.end);
|
|
3347
|
+
const equals = written.indexOf("=");
|
|
3348
|
+
if (equals < 0)
|
|
3349
|
+
return;
|
|
3350
|
+
let start = at.start + equals + 1;
|
|
3351
|
+
while (/[ \t\n\r]/.test(text[start] ?? ""))
|
|
3352
|
+
start += 1;
|
|
3353
|
+
const quote = text[start];
|
|
3354
|
+
if (quote === '"' || quote === "'")
|
|
3355
|
+
return { start: start + 1, end: at.end - 1, quoted: true };
|
|
3356
|
+
return { start, end: at.end, quoted: false };
|
|
3357
|
+
}
|
|
3358
|
+
function attributeValue(text, at) {
|
|
3359
|
+
const span = valueSpan(text, at);
|
|
3360
|
+
if (!span)
|
|
3361
|
+
return;
|
|
3362
|
+
return decodeEntities(text.slice(span.start, span.end));
|
|
3363
|
+
}
|
|
3364
|
+
function decodeEntities(value) {
|
|
3365
|
+
return value.replace(/"/g, '"').replace(/'/g, "'").replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
|
|
3366
|
+
}
|
|
3367
|
+
function escapeAttribute(value) {
|
|
3368
|
+
return value.replace(/&/g, "&").replace(/"/g, """);
|
|
3369
|
+
}
|
|
3370
|
+
function escapeText(value) {
|
|
3371
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
3372
|
+
}
|
|
3373
|
+
function seconds(ms) {
|
|
3374
|
+
return String(Math.round(ms) / 1000);
|
|
3375
|
+
}
|
|
3376
|
+
function mergeRanges(ranges) {
|
|
3377
|
+
const sorted = ranges.filter((range) => range.endMs > range.startMs).sort((a, b) => a.startMs - b.startMs);
|
|
3378
|
+
const merged = [];
|
|
3379
|
+
for (const range of sorted) {
|
|
3380
|
+
const last = merged.at(-1);
|
|
3381
|
+
if (last && range.startMs <= last.endMs) {
|
|
3382
|
+
merged[merged.length - 1] = {
|
|
3383
|
+
startMs: last.startMs,
|
|
3384
|
+
endMs: Math.max(last.endMs, range.endMs)
|
|
3385
|
+
};
|
|
3386
|
+
} else {
|
|
3387
|
+
merged.push(range);
|
|
3388
|
+
}
|
|
3389
|
+
}
|
|
3390
|
+
return merged;
|
|
3391
|
+
}
|
|
3392
|
+
function lineBlock(text, span) {
|
|
3393
|
+
let start = span.start;
|
|
3394
|
+
while (start > 0 && (text[start - 1] === " " || text[start - 1] === "\t"))
|
|
3395
|
+
start -= 1;
|
|
3396
|
+
const alone = start === 0 || text[start - 1] === `
|
|
3397
|
+
`;
|
|
3398
|
+
if (!alone)
|
|
3399
|
+
return span;
|
|
3400
|
+
let end = span.end;
|
|
3401
|
+
while (end < text.length && (text[end] === " " || text[end] === "\t"))
|
|
3402
|
+
end += 1;
|
|
3403
|
+
if (text[end] === "\r")
|
|
3404
|
+
end += 1;
|
|
3405
|
+
if (text[end] === `
|
|
3406
|
+
`)
|
|
3407
|
+
return { start, end: end + 1 };
|
|
3408
|
+
return end === text.length ? { start, end } : span;
|
|
3409
|
+
}
|
|
3410
|
+
function lineEnd(text, block) {
|
|
3411
|
+
return text[block.end - 1] === `
|
|
3412
|
+
` ? `
|
|
3413
|
+
` : "";
|
|
3414
|
+
}
|
|
3415
|
+
function lineIndent(text, at) {
|
|
3416
|
+
const line = text.lastIndexOf(`
|
|
3417
|
+
`, at - 1) + 1;
|
|
3418
|
+
return /^[ \t]*/.exec(text.slice(line, at))?.[0] ?? "";
|
|
3419
|
+
}
|
|
29
3420
|
// src/artifacts/live/board.ts
|
|
30
|
-
import { parse } from "parse5";
|
|
3421
|
+
import { parse as parse2 } from "parse5";
|
|
31
3422
|
var BOARD_STYLE_PROPERTIES = [
|
|
32
3423
|
"color",
|
|
33
3424
|
"background",
|
|
@@ -141,7 +3532,7 @@ function annotated(source) {
|
|
|
141
3532
|
const index = startTagClose(source, each.node);
|
|
142
3533
|
if (index === null)
|
|
143
3534
|
continue;
|
|
144
|
-
const marks = Object.entries(marksOf(each)).map(([name, value]) => `${name}="${
|
|
3535
|
+
const marks = Object.entries(marksOf(each)).map(([name, value]) => `${name}="${escapeAttribute2(value)}"`);
|
|
145
3536
|
changes.push({ index, remove: 0, insert: ` ${marks.join(" ")}` });
|
|
146
3537
|
}
|
|
147
3538
|
const shifts = [];
|
|
@@ -182,7 +3573,7 @@ function setText(source, node, text) {
|
|
|
182
3573
|
}
|
|
183
3574
|
const from = prefix;
|
|
184
3575
|
const to = before.length - suffix;
|
|
185
|
-
const insert =
|
|
3576
|
+
const insert = escapeText2(text.slice(prefix, text.length - suffix));
|
|
186
3577
|
if (nodes.length === 0) {
|
|
187
3578
|
const index = startTagEnd(node);
|
|
188
3579
|
return index === null ? [] : [{ index, remove: 0, insert }];
|
|
@@ -212,7 +3603,7 @@ function setText(source, node, text) {
|
|
|
212
3603
|
continue;
|
|
213
3604
|
}
|
|
214
3605
|
const value = each.value.slice(0, (takes ? from : removeFrom) - start) + (takes ? text.slice(prefix, text.length - suffix) : "") + each.value.slice(removes ? removeTo - start : (takes ? from : removeFrom) - start);
|
|
215
|
-
changes.push({ index: each.start, remove: each.end - each.start, insert:
|
|
3606
|
+
changes.push({ index: each.start, remove: each.end - each.start, insert: escapeText2(value) });
|
|
216
3607
|
}
|
|
217
3608
|
return changes.filter((change) => change.remove > 0 || change.insert.length > 0);
|
|
218
3609
|
}
|
|
@@ -390,7 +3781,7 @@ function boardFilePath(board, file) {
|
|
|
390
3781
|
return path.split("/").map(encodeURIComponent).join("/");
|
|
391
3782
|
}
|
|
392
3783
|
function located(source) {
|
|
393
|
-
const document =
|
|
3784
|
+
const document = parse2(source, { sourceCodeLocationInfo: true });
|
|
394
3785
|
const html = document.childNodes.find(isElement);
|
|
395
3786
|
const body = html?.childNodes.find((child) => isElement(child) && child.tagName === "body");
|
|
396
3787
|
if (!body)
|
|
@@ -548,7 +3939,7 @@ function startTagClose(source, node) {
|
|
|
548
3939
|
return at;
|
|
549
3940
|
}
|
|
550
3941
|
function attributeChange(source, node, name, value) {
|
|
551
|
-
const written = `${name}="${
|
|
3942
|
+
const written = `${name}="${escapeAttribute2(value)}"`;
|
|
552
3943
|
const location = node.sourceCodeLocation?.attrs?.[name];
|
|
553
3944
|
if (location) {
|
|
554
3945
|
return {
|
|
@@ -649,10 +4040,10 @@ function checkImageSource(src) {
|
|
|
649
4040
|
throw new Error(`[Sixb] '${src}' is not a picture a board's image shows.`);
|
|
650
4041
|
}
|
|
651
4042
|
}
|
|
652
|
-
function
|
|
4043
|
+
function escapeText2(text) {
|
|
653
4044
|
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
654
4045
|
}
|
|
655
|
-
function
|
|
4046
|
+
function escapeAttribute2(value) {
|
|
656
4047
|
return value.replace(/&/g, "&").replace(/"/g, """);
|
|
657
4048
|
}
|
|
658
4049
|
function isElement(node) {
|
|
@@ -665,10 +4056,12 @@ export {
|
|
|
665
4056
|
AGENT_AWARENESS_FIELD2 as AGENT_AWARENESS_FIELD,
|
|
666
4057
|
ARTIFACT_LIVE_ROUTE2 as ARTIFACT_LIVE_ROUTE,
|
|
667
4058
|
LIVE_FILES2 as LIVE_FILES,
|
|
4059
|
+
MAX_VOLUME,
|
|
668
4060
|
PAGE_BODY2 as PAGE_BODY,
|
|
669
4061
|
PAGE_MARK_TAGS2 as PAGE_MARK_TAGS,
|
|
670
4062
|
PAGE_TEXT_TAGS2 as PAGE_TEXT_TAGS,
|
|
671
4063
|
USER_AWARENESS_FIELD2 as USER_AWARENESS_FIELD,
|
|
4064
|
+
VIDEO_ENTRY2 as VIDEO_ENTRY,
|
|
672
4065
|
annotateBoard,
|
|
673
4066
|
applyBoardEditToText,
|
|
674
4067
|
blocksToMarkdown2 as blocksToMarkdown,
|
|
@@ -679,19 +4072,45 @@ export {
|
|
|
679
4072
|
boardTextHash,
|
|
680
4073
|
canvasItemMap2 as canvasItemMap,
|
|
681
4074
|
canvasItemObject2 as canvasItemObject,
|
|
4075
|
+
cutRange,
|
|
682
4076
|
decodeLiveData2 as decodeLiveData,
|
|
683
4077
|
documentCanvas2 as documentCanvas,
|
|
684
4078
|
documentFiles2 as documentFiles,
|
|
4079
|
+
duplicateScene,
|
|
685
4080
|
encodeLiveData2 as encodeLiveData,
|
|
4081
|
+
findVideoTarget,
|
|
4082
|
+
insertClip,
|
|
686
4083
|
isPageEntry2 as isPageEntry,
|
|
687
4084
|
liveSync2 as liveSync,
|
|
688
4085
|
markdownToBlocks2 as markdownToBlocks,
|
|
689
4086
|
mergeBoardText,
|
|
690
4087
|
mergeCanvasItem2 as mergeCanvasItem,
|
|
4088
|
+
moveClip,
|
|
4089
|
+
moveClips,
|
|
4090
|
+
moveScene,
|
|
691
4091
|
pageEntryHtml2 as pageEntryHtml,
|
|
4092
|
+
readVideoComposition2 as readVideoComposition,
|
|
4093
|
+
readVideoFileTimeline,
|
|
4094
|
+
removeClip,
|
|
4095
|
+
removeClips,
|
|
4096
|
+
removeMediaRanges,
|
|
4097
|
+
removeScene,
|
|
4098
|
+
replaceClipMedia,
|
|
692
4099
|
setBoardImage,
|
|
693
4100
|
setBoardStyle,
|
|
694
|
-
setBoardText
|
|
4101
|
+
setBoardText,
|
|
4102
|
+
setClipSound,
|
|
4103
|
+
setClipTiming,
|
|
4104
|
+
setSceneLabel,
|
|
4105
|
+
setSceneLength,
|
|
4106
|
+
setVideoText,
|
|
4107
|
+
splitClip,
|
|
4108
|
+
splitClips,
|
|
4109
|
+
trimClip,
|
|
4110
|
+
videoChains,
|
|
4111
|
+
videoChapters,
|
|
4112
|
+
videoSceneLength,
|
|
4113
|
+
videoTarget
|
|
695
4114
|
};
|
|
696
4115
|
|
|
697
|
-
//# debugId=
|
|
4116
|
+
//# debugId=5A992201E4E917B664756E2164756E21
|