canvas-recorder-lib 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BREAKING-CHANGES.md +18 -0
- package/README.md +112 -20
- package/dev/audio-builder.ts +4 -2
- package/dev/canvas-recorder.css +59 -0
- package/dev/canvas-recorder.ts +679 -51
- package/dev/delay-files.ts +1 -1
- package/dev/font-utils.ts +8 -1
- package/dev/format-editor.ts +734 -0
- package/dev/format-string.ts +110 -0
- package/dev/local-file-row.ts +107 -0
- package/dev/multi-text-dialog.ts +360 -0
- package/dev/multi-text-panel.ts +11 -0
- package/dev/player-body.ts +86 -6
- package/dev/rect-snap.ts +9 -9
- package/dev/slide-panel.ts +1 -1
- package/dev/split-dialog.ts +13 -2
- package/dev/static-image-panel.ts +35 -5
- package/dev/timeline-display.ts +50 -5
- package/dev/transcripts.ts +5 -3
- package/dev/video-clip-panel.ts +201 -15
- package/dist/dev/audio-builder.d.ts +1 -1
- package/dist/dev/audio-builder.d.ts.map +1 -1
- package/dist/dev/audio-builder.js +3 -2
- package/dist/dev/audio-builder.js.map +1 -1
- package/dist/dev/canvas-recorder.css +59 -0
- package/dist/dev/canvas-recorder.js +612 -50
- package/dist/dev/canvas-recorder.js.map +1 -1
- package/dist/dev/delay-files.js +1 -1
- package/dist/dev/delay-files.js.map +1 -1
- package/dist/dev/font-utils.d.ts.map +1 -1
- package/dist/dev/font-utils.js +9 -1
- package/dist/dev/font-utils.js.map +1 -1
- package/dist/dev/format-editor.d.ts +75 -0
- package/dist/dev/format-editor.d.ts.map +1 -0
- package/dist/dev/format-editor.js +642 -0
- package/dist/dev/format-editor.js.map +1 -0
- package/dist/dev/format-string.d.ts +62 -0
- package/dist/dev/format-string.d.ts.map +1 -0
- package/dist/dev/format-string.js +86 -0
- package/dist/dev/format-string.js.map +1 -0
- package/dist/dev/local-file-row.d.ts +22 -0
- package/dist/dev/local-file-row.d.ts.map +1 -0
- package/dist/dev/local-file-row.js +84 -0
- package/dist/dev/local-file-row.js.map +1 -0
- package/dist/dev/multi-text-dialog.d.ts +30 -0
- package/dist/dev/multi-text-dialog.d.ts.map +1 -0
- package/dist/dev/multi-text-dialog.js +297 -0
- package/dist/dev/multi-text-dialog.js.map +1 -0
- package/dist/dev/multi-text-panel.d.ts +2 -0
- package/dist/dev/multi-text-panel.d.ts.map +1 -1
- package/dist/dev/multi-text-panel.js +4 -0
- package/dist/dev/multi-text-panel.js.map +1 -1
- package/dist/dev/player-body.d.ts +1 -1
- package/dist/dev/player-body.d.ts.map +1 -1
- package/dist/dev/player-body.js +86 -6
- package/dist/dev/player-body.js.map +1 -1
- package/dist/dev/rect-snap.d.ts +1 -1
- package/dist/dev/rect-snap.js +7 -7
- package/dist/dev/rect-snap.js.map +1 -1
- package/dist/dev/slide-panel.d.ts +1 -1
- package/dist/dev/slide-panel.d.ts.map +1 -1
- package/dist/dev/slide-panel.js +1 -1
- package/dist/dev/slide-panel.js.map +1 -1
- package/dist/dev/split-dialog.d.ts.map +1 -1
- package/dist/dev/split-dialog.js +14 -2
- package/dist/dev/split-dialog.js.map +1 -1
- package/dist/dev/static-image-panel.d.ts +2 -0
- package/dist/dev/static-image-panel.d.ts.map +1 -1
- package/dist/dev/static-image-panel.js +29 -5
- package/dist/dev/static-image-panel.js.map +1 -1
- package/dist/dev/timeline-display.d.ts +23 -2
- package/dist/dev/timeline-display.d.ts.map +1 -1
- package/dist/dev/timeline-display.js +47 -5
- package/dist/dev/timeline-display.js.map +1 -1
- package/dist/dev/transcripts.d.ts.map +1 -1
- package/dist/dev/transcripts.js +5 -3
- package/dist/dev/transcripts.js.map +1 -1
- package/dist/dev/video-clip-panel.d.ts +8 -0
- package/dist/dev/video-clip-panel.d.ts.map +1 -1
- package/dist/dev/video-clip-panel.js +175 -9
- package/dist/dev/video-clip-panel.js.map +1 -1
- package/dist/lib/index.d.ts +3 -0
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +3 -0
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/main-control.d.ts +50 -4
- package/dist/lib/main-control.d.ts.map +1 -1
- package/dist/lib/main-control.js +94 -12
- package/dist/lib/main-control.js.map +1 -1
- package/dist/src/binary-search.js +1 -1
- package/dist/src/binary-search.js.map +1 -1
- package/dist/src/corner-rounder.d.ts +17 -0
- package/dist/src/corner-rounder.d.ts.map +1 -0
- package/dist/src/corner-rounder.js +89 -0
- package/dist/src/corner-rounder.js.map +1 -0
- package/dist/src/cross-fade.d.ts +1 -1
- package/dist/src/cross-fade.d.ts.map +1 -1
- package/dist/src/cross-fade.js +3 -3
- package/dist/src/cross-fade.js.map +1 -1
- package/dist/src/fancy-text.d.ts +116 -0
- package/dist/src/fancy-text.d.ts.map +1 -0
- package/dist/src/fancy-text.js +211 -0
- package/dist/src/fancy-text.js.map +1 -0
- package/dist/src/glib/letters-base.d.ts +1 -1
- package/dist/src/glib/letters-base.d.ts.map +1 -1
- package/dist/src/glib/letters-base.js +4 -3
- package/dist/src/glib/letters-base.js.map +1 -1
- package/dist/src/glib/line-font.d.ts +2 -2
- package/dist/src/glib/line-font.d.ts.map +1 -1
- package/dist/src/glib/line-font.js +2 -2
- package/dist/src/glib/line-font.js.map +1 -1
- package/dist/src/glib/paragraph-layout.d.ts +2 -2
- package/dist/src/glib/paragraph-layout.d.ts.map +1 -1
- package/dist/src/glib/paragraph-layout.js +1 -1
- package/dist/src/glib/paragraph-layout.js.map +1 -1
- package/dist/src/glib/path-shape-splitter.d.ts +1 -1
- package/dist/src/glib/path-shape-splitter.d.ts.map +1 -1
- package/dist/src/glib/path-shape-splitter.js +1 -1
- package/dist/src/glib/path-shape-splitter.js.map +1 -1
- package/dist/src/glib/path-shape.js +2 -2
- package/dist/src/glib/path-shape.js.map +1 -1
- package/dist/src/interpolate.d.ts +2 -2
- package/dist/src/interpolate.d.ts.map +1 -1
- package/dist/src/interpolate.js +1 -1
- package/dist/src/interpolate.js.map +1 -1
- package/dist/src/lattice.d.ts +1 -1
- package/dist/src/lattice.d.ts.map +1 -1
- package/dist/src/local-files.d.ts +129 -0
- package/dist/src/local-files.d.ts.map +1 -0
- package/dist/src/local-files.js +327 -0
- package/dist/src/local-files.js.map +1 -0
- package/dist/src/morph-animation.d.ts +1 -1
- package/dist/src/morph-animation.d.ts.map +1 -1
- package/dist/src/morph-animation.js +2 -2
- package/dist/src/morph-animation.js.map +1 -1
- package/dist/src/peano-fourier/fourier-shared.d.ts +1 -1
- package/dist/src/peano-fourier/fourier-shared.d.ts.map +1 -1
- package/dist/src/peano-fourier/fourier-shared.js +17 -4
- package/dist/src/peano-fourier/fourier-shared.js.map +1 -1
- package/dist/src/schedule-helper.d.ts +4 -4
- package/dist/src/schedule-helper.d.ts.map +1 -1
- package/dist/src/schedule-helper.js +2 -2
- package/dist/src/schedule-helper.js.map +1 -1
- package/dist/src/showable.d.ts +36 -4
- package/dist/src/showable.d.ts.map +1 -1
- package/dist/src/showable.js +37 -1
- package/dist/src/showable.js.map +1 -1
- package/dist/src/slide-components/arrow.d.ts +4 -4
- package/dist/src/slide-components/arrow.d.ts.map +1 -1
- package/dist/src/slide-components/arrow.js +2 -2
- package/dist/src/slide-components/arrow.js.map +1 -1
- package/dist/src/slide-components/cross-fade-transition.d.ts +3 -3
- package/dist/src/slide-components/cross-fade-transition.d.ts.map +1 -1
- package/dist/src/slide-components/cross-fade-transition.js +3 -3
- package/dist/src/slide-components/cross-fade-transition.js.map +1 -1
- package/dist/src/slide-components/duration-agnostic.d.ts +3 -3
- package/dist/src/slide-components/duration-agnostic.d.ts.map +1 -1
- package/dist/src/slide-components/duration-agnostic.js +1 -1
- package/dist/src/slide-components/duration-agnostic.js.map +1 -1
- package/dist/src/slide-components/fixed-duration.d.ts +1 -1
- package/dist/src/slide-components/fixed-duration.d.ts.map +1 -1
- package/dist/src/slide-components/fixed-duration.js +1 -1
- package/dist/src/slide-components/fixed-duration.js.map +1 -1
- package/dist/src/slide-components/fourier.d.ts +6 -6
- package/dist/src/slide-components/fourier.d.ts.map +1 -1
- package/dist/src/slide-components/fourier.js +6 -6
- package/dist/src/slide-components/fourier.js.map +1 -1
- package/dist/src/slide-components/frame-counter.d.ts +2 -2
- package/dist/src/slide-components/frame-counter.d.ts.map +1 -1
- package/dist/src/slide-components/frame-counter.js +1 -1
- package/dist/src/slide-components/frame-counter.js.map +1 -1
- package/dist/src/slide-components/function-graph.d.ts +2 -2
- package/dist/src/slide-components/function-graph.d.ts.map +1 -1
- package/dist/src/slide-components/function-graph.js +3 -3
- package/dist/src/slide-components/function-graph.js.map +1 -1
- package/dist/src/slide-components/halftone-shadow.d.ts +4 -4
- package/dist/src/slide-components/halftone-shadow.d.ts.map +1 -1
- package/dist/src/slide-components/halftone-shadow.js +2 -2
- package/dist/src/slide-components/halftone-shadow.js.map +1 -1
- package/dist/src/slide-components/handwriting-effect.d.ts +5 -5
- package/dist/src/slide-components/handwriting-effect.d.ts.map +1 -1
- package/dist/src/slide-components/handwriting-effect.js +5 -5
- package/dist/src/slide-components/handwriting-effect.js.map +1 -1
- package/dist/src/slide-components/hold.d.ts +3 -3
- package/dist/src/slide-components/hold.d.ts.map +1 -1
- package/dist/src/slide-components/hold.js +3 -3
- package/dist/src/slide-components/hold.js.map +1 -1
- package/dist/src/slide-components/image.d.ts +3 -3
- package/dist/src/slide-components/image.d.ts.map +1 -1
- package/dist/src/slide-components/image.js +3 -3
- package/dist/src/slide-components/image.js.map +1 -1
- package/dist/src/slide-components/in-parallel.d.ts +3 -3
- package/dist/src/slide-components/in-parallel.d.ts.map +1 -1
- package/dist/src/slide-components/in-parallel.js +2 -2
- package/dist/src/slide-components/in-parallel.js.map +1 -1
- package/dist/src/slide-components/in-series.d.ts +4 -4
- package/dist/src/slide-components/in-series.d.ts.map +1 -1
- package/dist/src/slide-components/in-series.js +5 -1
- package/dist/src/slide-components/in-series.js.map +1 -1
- package/dist/src/slide-components/live-duration.d.ts +1 -1
- package/dist/src/slide-components/live-duration.d.ts.map +1 -1
- package/dist/src/slide-components/live-duration.js +1 -1
- package/dist/src/slide-components/live-duration.js.map +1 -1
- package/dist/src/slide-components/multi-text.d.ts +76 -15
- package/dist/src/slide-components/multi-text.d.ts.map +1 -1
- package/dist/src/slide-components/multi-text.js +170 -25
- package/dist/src/slide-components/multi-text.js.map +1 -1
- package/dist/src/slide-components/rectangle.d.ts +3 -3
- package/dist/src/slide-components/rectangle.d.ts.map +1 -1
- package/dist/src/slide-components/rectangle.js +1 -1
- package/dist/src/slide-components/rectangle.js.map +1 -1
- package/dist/src/slide-components/registry.d.ts +1 -1
- package/dist/src/slide-components/registry.d.ts.map +1 -1
- package/dist/src/slide-components/registry.js +18 -18
- package/dist/src/slide-components/registry.js.map +1 -1
- package/dist/src/slide-components/serialize.d.ts +1 -1
- package/dist/src/slide-components/serialize.d.ts.map +1 -1
- package/dist/src/slide-components/serialize.js +2 -2
- package/dist/src/slide-components/serialize.js.map +1 -1
- package/dist/src/slide-components/show-error.js +2 -2
- package/dist/src/slide-components/show-error.js.map +1 -1
- package/dist/src/slide-components/simple-text.d.ts +4 -4
- package/dist/src/slide-components/simple-text.d.ts.map +1 -1
- package/dist/src/slide-components/simple-text.js +4 -4
- package/dist/src/slide-components/simple-text.js.map +1 -1
- package/dist/src/slide-components/slide-component.d.ts +5 -5
- package/dist/src/slide-components/slide-component.d.ts.map +1 -1
- package/dist/src/slide-components/slide-component.js +4 -4
- package/dist/src/slide-components/slide-component.js.map +1 -1
- package/dist/src/slide-components/slide-left.d.ts +3 -3
- package/dist/src/slide-components/slide-left.d.ts.map +1 -1
- package/dist/src/slide-components/slide-left.js +3 -3
- package/dist/src/slide-components/slide-left.js.map +1 -1
- package/dist/src/slide-components/split-video-clip.d.ts +2 -2
- package/dist/src/slide-components/split-video-clip.d.ts.map +1 -1
- package/dist/src/slide-components/split-video-clip.js +3 -3
- package/dist/src/slide-components/split-video-clip.js.map +1 -1
- package/dist/src/slide-components/text-effect.d.ts +2 -2
- package/dist/src/slide-components/text-effect.d.ts.map +1 -1
- package/dist/src/slide-components/traditional-text.d.ts +4 -4
- package/dist/src/slide-components/traditional-text.d.ts.map +1 -1
- package/dist/src/slide-components/traditional-text.js +3 -3
- package/dist/src/slide-components/traditional-text.js.map +1 -1
- package/dist/src/slide-components/video-clip.d.ts +17 -5
- package/dist/src/slide-components/video-clip.d.ts.map +1 -1
- package/dist/src/slide-components/video-clip.js +52 -11
- package/dist/src/slide-components/video-clip.js.map +1 -1
- package/dist/src/slide-components/video-info.d.ts +11 -11
- package/dist/src/slide-components/video-info.d.ts.map +1 -1
- package/dist/src/slide-components/video-info.js +32 -21
- package/dist/src/slide-components/video-info.js.map +1 -1
- package/dist/src/slow-image-sources.d.ts +7 -1
- package/dist/src/slow-image-sources.d.ts.map +1 -1
- package/dist/src/slow-image-sources.js +36 -5
- package/dist/src/slow-image-sources.js.map +1 -1
- package/dist/src/snapshot.d.ts +2 -2
- package/dist/src/snapshot.d.ts.map +1 -1
- package/dist/src/snapshot.js +4 -4
- package/dist/src/snapshot.js.map +1 -1
- package/dist/src/stroke-colors.d.ts +1 -1
- package/dist/src/stroke-colors.d.ts.map +1 -1
- package/dist/src/stroke-colors.js +4 -4
- package/dist/src/stroke-colors.js.map +1 -1
- package/dist/src/utility.d.ts +3 -4
- package/dist/src/utility.d.ts.map +1 -1
- package/dist/src/utility.js +4 -4
- package/dist/src/utility.js.map +1 -1
- package/lib/index.ts +3 -0
- package/lib/main-control.ts +119 -12
- package/package.json +7 -5
- package/src/binary-search.ts +2 -2
- package/src/corner-rounder.ts +128 -0
- package/src/cross-fade.ts +3 -3
- package/src/fancy-text.ts +255 -0
- package/src/glib/letters-base.ts +4 -3
- package/src/glib/line-font.ts +2 -2
- package/src/glib/paragraph-layout.ts +2 -2
- package/src/glib/path-shape-splitter.ts +1 -1
- package/src/glib/path-shape.ts +2 -2
- package/src/interpolate.ts +3 -3
- package/src/lattice.ts +1 -1
- package/src/local-files.ts +389 -0
- package/src/morph-animation.ts +2 -2
- package/src/peano-fourier/fourier-shared.ts +17 -4
- package/src/schedule-helper.ts +4 -4
- package/src/showable.ts +54 -4
- package/src/slide-components/arrow.ts +4 -4
- package/src/slide-components/cross-fade-transition.ts +4 -4
- package/src/slide-components/duration-agnostic.ts +3 -3
- package/src/slide-components/fixed-duration.ts +1 -1
- package/src/slide-components/fourier.ts +9 -9
- package/src/slide-components/frame-counter.ts +2 -2
- package/src/slide-components/function-graph.ts +4 -4
- package/src/slide-components/halftone-shadow.ts +4 -4
- package/src/slide-components/handwriting-effect.ts +7 -7
- package/src/slide-components/hold.ts +4 -4
- package/src/slide-components/image.ts +5 -5
- package/src/slide-components/in-parallel.ts +4 -4
- package/src/slide-components/in-series.ts +7 -4
- package/src/slide-components/live-duration.ts +1 -1
- package/src/slide-components/multi-text.ts +195 -30
- package/src/slide-components/rectangle.ts +3 -3
- package/src/slide-components/registry.ts +19 -19
- package/src/slide-components/serialize.ts +2 -2
- package/src/slide-components/show-error.ts +2 -2
- package/src/slide-components/simple-text.ts +7 -7
- package/src/slide-components/slide-component.ts +7 -7
- package/src/slide-components/slide-left.ts +4 -4
- package/src/slide-components/split-video-clip.ts +4 -4
- package/src/slide-components/text-effect.ts +2 -2
- package/src/slide-components/traditional-text.ts +5 -5
- package/src/slide-components/video-clip.ts +64 -13
- package/src/slide-components/video-info.ts +33 -21
- package/src/slow-image-sources.ts +38 -6
- package/src/snapshot.ts +4 -4
- package/src/stroke-colors.ts +4 -4
- package/src/utility.ts +5 -5
|
@@ -16,6 +16,7 @@ import { buildTraditionalTextPanel, openFontPickerDialog, } from "./font-widgets
|
|
|
16
16
|
import { buildSlideComponentPanel } from "./slide-panel.js";
|
|
17
17
|
import { buildVideoClipPanel } from "./video-clip-panel.js";
|
|
18
18
|
import { buildTextFramePanel } from "./multi-text-panel.js";
|
|
19
|
+
import { openMultiTextDialog } from "./multi-text-dialog.js";
|
|
19
20
|
import { ownerOf, parseSoundClips, rehomeSoundClip, soundOwners, startWithin, tidyMs, } from "./sound-clips.js";
|
|
20
21
|
import { askHowToSplit, askHowToSplitSound } from "./split-dialog.js";
|
|
21
22
|
import { SyncedFile } from "./synced-file.js";
|
|
@@ -25,6 +26,7 @@ import { transcriptFileName, transcriptJson } from "./transcript-export.js";
|
|
|
25
26
|
import { wordFlag } from "./transcript-align.js";
|
|
26
27
|
import { canvasRecorder } from "../lib/main-control.js";
|
|
27
28
|
import { watchServiceWorkerReady } from "./delay-files.js";
|
|
29
|
+
import { checkLocalFiles, localFilesNeedingPermission, localFileUrlsIn, onLocalFilesChange, requestLocalFileAccess, } from "../src/local-files.js";
|
|
28
30
|
import { DurationAgnosticComponent } from "../src/slide-components/duration-agnostic.js";
|
|
29
31
|
import { componentChoices, componentRegistry, } from "../src/slide-components/registry.js";
|
|
30
32
|
import { pickComponent } from "./component-picker.js";
|
|
@@ -189,6 +191,159 @@ viewport.addEventListener("wheel", (e) => {
|
|
|
189
191
|
return;
|
|
190
192
|
applyZoom(currentZoomFactor, panX - e.deltaX, panY - e.deltaY);
|
|
191
193
|
}, { passive: false });
|
|
194
|
+
// MARK: Video size
|
|
195
|
+
/**
|
|
196
|
+
* The four size fields: the saved file's pixels, and the drawing units.
|
|
197
|
+
* See development-plans/configurable-video-size.md.
|
|
198
|
+
*/
|
|
199
|
+
const videoSizeInputs = {
|
|
200
|
+
pixelWidth: getById("videoPixelWidth", HTMLInputElement),
|
|
201
|
+
pixelHeight: getById("videoPixelHeight", HTMLInputElement),
|
|
202
|
+
width: getById("videoUnitWidth", HTMLInputElement),
|
|
203
|
+
height: getById("videoUnitHeight", HTMLInputElement),
|
|
204
|
+
};
|
|
205
|
+
const videoSizeWarning = getById("videoSizeWarning", HTMLSpanElement);
|
|
206
|
+
/**
|
|
207
|
+
* Where the user's size is remembered. One entry per video, shared by every window
|
|
208
|
+
* and session on this origin. localStorage, not IndexedDB: it's synchronous, so a
|
|
209
|
+
* saved size is in place before the first frame, and its `storage` event tells the
|
|
210
|
+
* other windows about a change for free.
|
|
211
|
+
*/
|
|
212
|
+
const videoSizeStorageKey = `canvas-recorder-size|${startRequest.name}`;
|
|
213
|
+
/** The size this video's user saved, if any. */
|
|
214
|
+
function readSavedVideoSize() {
|
|
215
|
+
try {
|
|
216
|
+
const parsed = JSON.parse(localStorage.getItem(videoSizeStorageKey) ?? "null");
|
|
217
|
+
if (typeof parsed !== "object" || parsed === null)
|
|
218
|
+
return undefined;
|
|
219
|
+
const record = parsed;
|
|
220
|
+
const size = {
|
|
221
|
+
pixelWidth: record.pixelWidth,
|
|
222
|
+
pixelHeight: record.pixelHeight,
|
|
223
|
+
width: record.width,
|
|
224
|
+
height: record.height,
|
|
225
|
+
};
|
|
226
|
+
const valid = Object.values(size).every((value) => typeof value === "number" && Number.isFinite(value) && value > 0);
|
|
227
|
+
return valid ? size : undefined;
|
|
228
|
+
}
|
|
229
|
+
catch {
|
|
230
|
+
return undefined;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
/** Use the saved size, unless the program locked it. A bad saved size is ignored. */
|
|
234
|
+
function applySavedVideoSize() {
|
|
235
|
+
if (canvasRecorder.sizeLocked)
|
|
236
|
+
return;
|
|
237
|
+
const saved = readSavedVideoSize();
|
|
238
|
+
if (!saved)
|
|
239
|
+
return;
|
|
240
|
+
try {
|
|
241
|
+
canvasRecorder.size = saved;
|
|
242
|
+
}
|
|
243
|
+
catch (error) {
|
|
244
|
+
console.warn("Ignoring the saved video size.", saved, error);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
applySavedVideoSize();
|
|
248
|
+
/** Copy the size into the fields, except one the user is typing in. */
|
|
249
|
+
function showVideoSize(size) {
|
|
250
|
+
for (const [key, input] of Object.entries(videoSizeInputs)) {
|
|
251
|
+
input.readOnly = canvasRecorder.sizeLocked;
|
|
252
|
+
if (document.activeElement !== input) {
|
|
253
|
+
input.value = String(size[key]);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
const pixelAspect = size.pixelWidth / size.pixelHeight;
|
|
257
|
+
const unitAspect = size.width / size.height;
|
|
258
|
+
const stretched = Math.abs(pixelAspect / unitAspect - 1) > 0.001;
|
|
259
|
+
videoSizeWarning.textContent = stretched ? "⚠ stretched" : "";
|
|
260
|
+
videoSizeWarning.title = stretched
|
|
261
|
+
? `The pixels are ${pixelAspect.toFixed(3)} : 1 and the units are ${unitAspect.toFixed(3)} : 1, so the picture is stretched to fit.`
|
|
262
|
+
: "";
|
|
263
|
+
getById("videoSizeControls", HTMLSpanElement).title = canvasRecorder.sizeLocked
|
|
264
|
+
? "The size of the video. This program sets it, so it can't be changed here."
|
|
265
|
+
: "The size of the video. Pixels: the saved file. Units: the coordinates everything is drawn in. Remembered for this video.";
|
|
266
|
+
}
|
|
267
|
+
showVideoSize(canvasRecorder.size);
|
|
268
|
+
/**
|
|
269
|
+
* The user asked for this size, in the size fields or with a button like the Video File
|
|
270
|
+
* panel's "Make video this size". Use it, and remember it for this video.
|
|
271
|
+
* @returns False if the size is locked, or `size` isn't usable. Nothing changes then.
|
|
272
|
+
*/
|
|
273
|
+
function setVideoSizeFromGui(size) {
|
|
274
|
+
if (canvasRecorder.sizeLocked)
|
|
275
|
+
return false;
|
|
276
|
+
try {
|
|
277
|
+
canvasRecorder.size = size;
|
|
278
|
+
}
|
|
279
|
+
catch {
|
|
280
|
+
// E.g. 0.4 pixels, which rounds to 0. Normal while typing.
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
try {
|
|
284
|
+
localStorage.setItem(videoSizeStorageKey, JSON.stringify(canvasRecorder.size));
|
|
285
|
+
}
|
|
286
|
+
catch {
|
|
287
|
+
// Private browsing, or storage is full. The size still works until the page reloads.
|
|
288
|
+
}
|
|
289
|
+
return true;
|
|
290
|
+
}
|
|
291
|
+
for (const [key, input] of Object.entries(videoSizeInputs)) {
|
|
292
|
+
input.addEventListener("input", () => {
|
|
293
|
+
const value = input.valueAsNumber;
|
|
294
|
+
// Empty, 0 or negative is normal while typing. Wait for a usable number.
|
|
295
|
+
if (!(Number.isFinite(value) && value > 0))
|
|
296
|
+
return;
|
|
297
|
+
setVideoSizeFromGui({ ...canvasRecorder.size, [key]: value });
|
|
298
|
+
});
|
|
299
|
+
// Show the value as stored, e.g. rounded to whole pixels, once the user is done typing.
|
|
300
|
+
input.addEventListener("blur", () => showVideoSize(canvasRecorder.size));
|
|
301
|
+
}
|
|
302
|
+
canvasRecorder.onSizeChange((size) => {
|
|
303
|
+
showVideoSize(size);
|
|
304
|
+
if (isRecording)
|
|
305
|
+
return;
|
|
306
|
+
if (zoomSelect.value === "fit") {
|
|
307
|
+
zoomToFit();
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
applyZoom(currentZoomFactor);
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
// Another window changed this video's size.
|
|
314
|
+
addEventListener("storage", (event) => {
|
|
315
|
+
if (event.key === videoSizeStorageKey)
|
|
316
|
+
applySavedVideoSize();
|
|
317
|
+
});
|
|
318
|
+
// MARK: Local files
|
|
319
|
+
/**
|
|
320
|
+
* 🔓: shown when some of the video's files are on this computer, and the browser
|
|
321
|
+
* needs a click before it will read them. See src/local-files.ts.
|
|
322
|
+
*/
|
|
323
|
+
const localFilesBtn = getById("localFilesBtn", HTMLButtonElement);
|
|
324
|
+
function updateLocalFilesButton() {
|
|
325
|
+
const names = localFilesNeedingPermission();
|
|
326
|
+
localFilesBtn.hidden = names.length === 0;
|
|
327
|
+
localFilesBtn.textContent =
|
|
328
|
+
names.length === 1 ? "🔓 Allow local file" : `🔓 Allow ${names.length} local files`;
|
|
329
|
+
localFilesBtn.title =
|
|
330
|
+
"The browser needs your OK before it reads these files again:\n" + names.join("\n");
|
|
331
|
+
}
|
|
332
|
+
onLocalFilesChange(updateLocalFilesButton);
|
|
333
|
+
/** Ask about every file that needs it. Then the sounds can load. */
|
|
334
|
+
async function allowLocalFiles() {
|
|
335
|
+
await requestLocalFileAccess();
|
|
336
|
+
// The images and video clips try again by themselves. The sounds are loaded all at once.
|
|
337
|
+
void initAudio();
|
|
338
|
+
}
|
|
339
|
+
localFilesBtn.addEventListener("click", () => void allowLocalFiles());
|
|
340
|
+
/**
|
|
341
|
+
* Find out, without asking the user anything, whether the video's local files can be read.
|
|
342
|
+
* Any that can't put the 🔓 button on screen.
|
|
343
|
+
*/
|
|
344
|
+
function checkVideosLocalFiles() {
|
|
345
|
+
void checkLocalFiles(localFileUrlsIn(toShow));
|
|
346
|
+
}
|
|
192
347
|
/**
|
|
193
348
|
* @param timeInMs Draw the animation at this time.
|
|
194
349
|
* @param live True for interactive display (schedule markers drawn on top).
|
|
@@ -476,6 +631,8 @@ function setPlaybackRate(rate) {
|
|
|
476
631
|
let audioBuilder = new AudioBuilder(toShow.duration);
|
|
477
632
|
let reloadGeneration = 0;
|
|
478
633
|
async function initAudio() {
|
|
634
|
+
// The sound clips are being re-read, so this is a good time to look for files needing 🔓.
|
|
635
|
+
checkVideosLocalFiles();
|
|
479
636
|
const myGen = ++reloadGeneration;
|
|
480
637
|
audioReady = false;
|
|
481
638
|
stopAudio();
|
|
@@ -594,11 +751,16 @@ playPositionSeconds.addEventListener("input", () => {
|
|
|
594
751
|
loadPlayPositionRange();
|
|
595
752
|
});
|
|
596
753
|
// Cmd+Z / Ctrl+Z opens the history (undo) dialog when no text field is focused.
|
|
754
|
+
// A contenteditable, like the Multi Text editor, is a text field with its own undo,
|
|
755
|
+
// and an editor that handled the key itself has said so with preventDefault().
|
|
597
756
|
addEventListener("keydown", (event) => {
|
|
598
757
|
if (!(event.metaKey || event.ctrlKey) || event.key !== "z")
|
|
599
758
|
return;
|
|
759
|
+
if (event.defaultPrevented)
|
|
760
|
+
return;
|
|
600
761
|
if (event.target instanceof HTMLInputElement ||
|
|
601
|
-
event.target instanceof HTMLTextAreaElement
|
|
762
|
+
event.target instanceof HTMLTextAreaElement ||
|
|
763
|
+
(event.target instanceof HTMLElement && event.target.isContentEditable))
|
|
602
764
|
return;
|
|
603
765
|
event.preventDefault();
|
|
604
766
|
if (historyDialog.open)
|
|
@@ -645,6 +807,70 @@ getById("back5s", HTMLButtonElement).addEventListener("click", () => {
|
|
|
645
807
|
* for the live/realtime display. Than can vary significantly.
|
|
646
808
|
*/
|
|
647
809
|
const FPS = canvasRecorder.fps;
|
|
810
|
+
// MARK: Frames
|
|
811
|
+
/**
|
|
812
|
+
* Frame *n* covers the times from n / FPS (inclusive) to (n + 1) / FPS (exclusive), and is
|
|
813
|
+
* always drawn at its center, (n + ½) / FPS. That's true for the whole video and for any part
|
|
814
|
+
* of it, so separately saved pieces line up exactly.
|
|
815
|
+
*
|
|
816
|
+
* These measure in frames from the start of the whole video, with the centers at whole numbers.
|
|
817
|
+
* The play position is stored to 0.1 ms (see {@link loadPlayPositionSeconds}), so a time that
|
|
818
|
+
* was meant to be a center is allowed to miss by a little.
|
|
819
|
+
*/
|
|
820
|
+
const FRAME_TOLERANCE = 0.01;
|
|
821
|
+
/** `ms` in frames, shifted so the frame centers are whole numbers. */
|
|
822
|
+
function framePosition(ms) {
|
|
823
|
+
return (ms * FPS) / 1000 - 0.5;
|
|
824
|
+
}
|
|
825
|
+
/** Where frame `n` is drawn, in ms from the start of the whole video. */
|
|
826
|
+
function frameCenterMs(n) {
|
|
827
|
+
return ((n + 0.5) * 1000) / FPS;
|
|
828
|
+
}
|
|
829
|
+
/** The first frame drawn at or after `ms`. */
|
|
830
|
+
function firstFrameAtOrAfter(ms) {
|
|
831
|
+
return Math.ceil(framePosition(ms) - FRAME_TOLERANCE);
|
|
832
|
+
}
|
|
833
|
+
/** How many frames are drawn from `startMs` (inclusive) to `endMs` (exclusive). */
|
|
834
|
+
function framesBetween(startMs, endMs) {
|
|
835
|
+
return Math.max(0, firstFrameAtOrAfter(endMs) - firstFrameAtOrAfter(startMs));
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* Move one frame forward (+1) or back (-1), pausing playback.
|
|
839
|
+
*
|
|
840
|
+
* From a frame's center, that's exactly one frame. From anywhere else, it's the nearest
|
|
841
|
+
* center in that direction, so the playhead always ends up on a time that's really rendered.
|
|
842
|
+
* It stays inside the play limits.
|
|
843
|
+
*/
|
|
844
|
+
function stepOneFrame(direction) {
|
|
845
|
+
const position = framePosition(playPositionSeconds.valueAsNumber * 1000);
|
|
846
|
+
let frame = direction > 0
|
|
847
|
+
? Math.floor(position + FRAME_TOLERANCE) + 1
|
|
848
|
+
: Math.ceil(position - FRAME_TOLERANCE) - 1;
|
|
849
|
+
const first = firstFrameAtOrAfter(sectionStartTime);
|
|
850
|
+
const last = firstFrameAtOrAfter(sectionEndTime) - 1;
|
|
851
|
+
frame = Math.max(first, Math.min(last, frame));
|
|
852
|
+
playCheckBox.checked = false;
|
|
853
|
+
stopAudio();
|
|
854
|
+
loadPlayPositionSeconds(frameCenterMs(frame));
|
|
855
|
+
loadPlayPositionRange();
|
|
856
|
+
}
|
|
857
|
+
// Option-← and Option-→: one frame back or forward. Like the other hot keys, these use Option.
|
|
858
|
+
// They work even in a text field, where they would otherwise move the cursor one word.
|
|
859
|
+
// Arrow keys never cause a keypress event, so this has to be keydown.
|
|
860
|
+
addEventListener("keydown", (event) => {
|
|
861
|
+
if (!event.altKey || event.shiftKey || event.metaKey || event.ctrlKey)
|
|
862
|
+
return;
|
|
863
|
+
if (suspendLiveAnimationLoop)
|
|
864
|
+
return; // Recording.
|
|
865
|
+
if (event.code === "ArrowRight") {
|
|
866
|
+
stepOneFrame(1);
|
|
867
|
+
event.preventDefault();
|
|
868
|
+
}
|
|
869
|
+
else if (event.code === "ArrowLeft") {
|
|
870
|
+
stepOneFrame(-1);
|
|
871
|
+
event.preventDefault();
|
|
872
|
+
}
|
|
873
|
+
});
|
|
648
874
|
/**
|
|
649
875
|
* This is the status of the save. It has no purpose during live / realtime operation
|
|
650
876
|
* so it initialize it to blank.
|
|
@@ -675,20 +901,29 @@ function escapeHtml(text) {
|
|
|
675
901
|
.replace(/</g, "<")
|
|
676
902
|
.replace(/>/g, ">");
|
|
677
903
|
}
|
|
678
|
-
|
|
904
|
+
/**
|
|
905
|
+
* Record the video and save it to a file the user picks.
|
|
906
|
+
* @param saveStartMs Where to start, in the video's time.
|
|
907
|
+
* @param saveEndMs Where to stop.
|
|
908
|
+
* @param pixelWidth The saved file's width. Usually {@link canvasRecorder.pixelWidth}, but the
|
|
909
|
+
* Save dialog can change it, just for this file. Nothing else sees the change: the picture
|
|
910
|
+
* is still drawn in canvasRecorder's units, and simply stretched to this size.
|
|
911
|
+
* @param pixelHeight The saved file's height. See `pixelWidth`.
|
|
912
|
+
*/
|
|
913
|
+
async function startRecording(saveStartMs = 0, saveEndMs = toShow.duration, pixelWidth = canvasRecorder.pixelWidth, pixelHeight = canvasRecorder.pixelHeight) {
|
|
679
914
|
stopAudio();
|
|
680
915
|
startRecordingButton.disabled = true;
|
|
681
916
|
liveControls.disabled = true;
|
|
682
917
|
cancelRecordingButton.disabled = false;
|
|
683
918
|
canceled = false;
|
|
684
919
|
suspendLiveAnimationLoop = true;
|
|
685
|
-
// Lock canvas at
|
|
920
|
+
// Lock the canvas at the output size for the duration of recording.
|
|
686
921
|
// Disable all size-changing code paths so the encoder sees a constant frame size.
|
|
687
922
|
isRecording = true;
|
|
688
923
|
viewportResizeObserver.disconnect();
|
|
689
924
|
zoomControls.inert = true;
|
|
690
|
-
canvas.width =
|
|
691
|
-
canvas.height =
|
|
925
|
+
canvas.width = pixelWidth;
|
|
926
|
+
canvas.height = pixelHeight;
|
|
692
927
|
canvas.style.width = "";
|
|
693
928
|
canvas.style.height = "";
|
|
694
929
|
canvas.style.maxWidth = "100%";
|
|
@@ -710,7 +945,7 @@ async function startRecording(saveStartMs = 0, saveEndMs = toShow.duration) {
|
|
|
710
945
|
suggestedName: "canvas-recording.mp4",
|
|
711
946
|
types: [
|
|
712
947
|
{
|
|
713
|
-
description: "
|
|
948
|
+
description: "MP4 Video",
|
|
714
949
|
accept: { "video/mp4": [".mp4"] },
|
|
715
950
|
},
|
|
716
951
|
],
|
|
@@ -721,20 +956,26 @@ async function startRecording(saveStartMs = 0, saveEndMs = toShow.duration) {
|
|
|
721
956
|
format: new Mp4OutputFormat(),
|
|
722
957
|
target: new StreamTarget(writableStream, { chunked: true }), // Batch writes for speed
|
|
723
958
|
});
|
|
724
|
-
//
|
|
959
|
+
// HEVC (H.265): Macs encode it in hardware, fast and well.
|
|
725
960
|
const videoSource = new CanvasSource(canvas, {
|
|
726
961
|
codec: "hevc",
|
|
727
|
-
|
|
962
|
+
// 16 Mbps. This file is the master that YouTube re-encodes, so a higher rate costs only
|
|
963
|
+
// file size. See "Export bit rate" in development-plans/review-2026-11.md.
|
|
964
|
+
bitrate: 16_000_000,
|
|
728
965
|
});
|
|
729
966
|
output.addVideoTrack(videoSource, { frameRate: FPS });
|
|
967
|
+
// Frames come from the whole video's grid, even for part of it. See firstFrameAtOrAfter().
|
|
968
|
+
const firstFrame = firstFrameAtOrAfter(saveStartMs);
|
|
969
|
+
// The file starts where its first frame starts, so the sound starts there too.
|
|
970
|
+
const audioStartMs = (firstFrame * 1000) / FPS;
|
|
730
971
|
const fullAudioBuffer = audioBuilder.getAudioBuffer();
|
|
731
972
|
let audioBuffer;
|
|
732
|
-
if (
|
|
973
|
+
if (firstFrame === 0 && saveEndMs >= toShow.duration) {
|
|
733
974
|
audioBuffer = fullAudioBuffer;
|
|
734
975
|
}
|
|
735
976
|
else {
|
|
736
977
|
const sr = fullAudioBuffer.sampleRate;
|
|
737
|
-
const s0 = Math.round((
|
|
978
|
+
const s0 = Math.round((audioStartMs / 1000) * sr);
|
|
738
979
|
const s1 = Math.min(Math.round((saveEndMs / 1000) * sr), fullAudioBuffer.length);
|
|
739
980
|
const len = Math.max(0, s1 - s0);
|
|
740
981
|
audioBuffer = new AudioBuffer({
|
|
@@ -759,7 +1000,7 @@ async function startRecording(saveStartMs = 0, saveEndMs = toShow.duration) {
|
|
|
759
1000
|
let frameNumber = 0;
|
|
760
1001
|
let warnedNoFramePromises = false;
|
|
761
1002
|
while (!canceled) {
|
|
762
|
-
const timeInMs =
|
|
1003
|
+
const timeInMs = frameCenterMs(firstFrame + frameNumber);
|
|
763
1004
|
if (timeInMs >= saveEndMs) {
|
|
764
1005
|
break;
|
|
765
1006
|
}
|
|
@@ -883,6 +1124,83 @@ const saveInfoStart = getById("saveInfoStart", HTMLTableCellElement);
|
|
|
883
1124
|
const saveInfoEnd = getById("saveInfoEnd", HTMLTableCellElement);
|
|
884
1125
|
const saveInfoDuration = getById("saveInfoDuration", HTMLTableCellElement);
|
|
885
1126
|
const saveInfoFrames = getById("saveInfoFrames", HTMLTableCellElement);
|
|
1127
|
+
const saveWidthInput = getById("saveWidth", HTMLInputElement);
|
|
1128
|
+
const saveHeightInput = getById("saveHeight", HTMLInputElement);
|
|
1129
|
+
const saveKeepAspectCheckbox = getById("saveKeepAspect", HTMLInputElement);
|
|
1130
|
+
const saveSizeNote = getById("saveSizeNote", HTMLDivElement);
|
|
1131
|
+
const saveOkBtn = getById("saveOkBtn", HTMLButtonElement);
|
|
1132
|
+
// MARK: Save size
|
|
1133
|
+
/**
|
|
1134
|
+
* Why the Save dialog's size can't be used, or undefined if it can.
|
|
1135
|
+
*
|
|
1136
|
+
* HEVC stores color at half resolution (4:2:0), so both numbers must be even.
|
|
1137
|
+
*/
|
|
1138
|
+
function saveSizeProblem(width, height) {
|
|
1139
|
+
if (!(Number.isInteger(width) && width > 0 && Number.isInteger(height) && height > 0)) {
|
|
1140
|
+
return "The size must be two whole numbers of pixels.";
|
|
1141
|
+
}
|
|
1142
|
+
if (width % 2 || height % 2) {
|
|
1143
|
+
return "Both numbers must be even.";
|
|
1144
|
+
}
|
|
1145
|
+
return undefined;
|
|
1146
|
+
}
|
|
1147
|
+
/** Explain the Save dialog's size, and enable OK only when everything is usable. */
|
|
1148
|
+
function updateSaveSizeNote() {
|
|
1149
|
+
const width = saveWidthInput.valueAsNumber;
|
|
1150
|
+
const height = saveHeightInput.valueAsNumber;
|
|
1151
|
+
const { pixelWidth, pixelHeight } = canvasRecorder;
|
|
1152
|
+
const problem = saveSizeProblem(width, height);
|
|
1153
|
+
if (problem) {
|
|
1154
|
+
saveSizeNote.textContent = problem;
|
|
1155
|
+
saveSizeNote.style.color = "red";
|
|
1156
|
+
}
|
|
1157
|
+
else if (width === pixelWidth && height === pixelHeight) {
|
|
1158
|
+
saveSizeNote.textContent = "The video's own size.";
|
|
1159
|
+
saveSizeNote.style.color = "#555";
|
|
1160
|
+
}
|
|
1161
|
+
else {
|
|
1162
|
+
const stretched = Math.abs((width / height) / (pixelWidth / pixelHeight) - 1) > 0.001;
|
|
1163
|
+
saveSizeNote.textContent = stretched
|
|
1164
|
+
? `Stretched: the video is ${pixelWidth} × ${pixelHeight}.`
|
|
1165
|
+
: `${Math.round((width / pixelWidth) * 100)}% of the video's ${pixelWidth} × ${pixelHeight}.`;
|
|
1166
|
+
saveSizeNote.style.color = stretched ? "#a06000" : "#555";
|
|
1167
|
+
}
|
|
1168
|
+
const startMs = (saveStartSecondsInput.valueAsNumber || 0) * 1000;
|
|
1169
|
+
const endMs = (saveEndSecondsInput.valueAsNumber || 0) * 1000;
|
|
1170
|
+
saveOkBtn.disabled = problem !== undefined || endMs <= startMs;
|
|
1171
|
+
}
|
|
1172
|
+
/** Set the Save dialog's size to the video's own. */
|
|
1173
|
+
function resetSaveSize() {
|
|
1174
|
+
saveWidthInput.value = String(canvasRecorder.pixelWidth);
|
|
1175
|
+
saveHeightInput.value = String(canvasRecorder.pixelHeight);
|
|
1176
|
+
updateSaveSizeNote();
|
|
1177
|
+
}
|
|
1178
|
+
/**
|
|
1179
|
+
* With Keep aspect ratio checked, typing one number sets the other.
|
|
1180
|
+
* The shape always comes from the video's own size, not the last pair typed, so it can't drift.
|
|
1181
|
+
* The other number is rounded to an even number of pixels.
|
|
1182
|
+
*/
|
|
1183
|
+
function matchSaveAspect(changed) {
|
|
1184
|
+
if (saveKeepAspectCheckbox.checked) {
|
|
1185
|
+
const aspect = canvasRecorder.pixelWidth / canvasRecorder.pixelHeight;
|
|
1186
|
+
const even = (n) => Math.max(2, Math.round(n / 2) * 2);
|
|
1187
|
+
if (changed === "width") {
|
|
1188
|
+
const width = saveWidthInput.valueAsNumber;
|
|
1189
|
+
if (width > 0)
|
|
1190
|
+
saveHeightInput.value = String(even(width / aspect));
|
|
1191
|
+
}
|
|
1192
|
+
else {
|
|
1193
|
+
const height = saveHeightInput.valueAsNumber;
|
|
1194
|
+
if (height > 0)
|
|
1195
|
+
saveWidthInput.value = String(even(height * aspect));
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
updateSaveSizeNote();
|
|
1199
|
+
}
|
|
1200
|
+
saveWidthInput.addEventListener("input", () => matchSaveAspect("width"));
|
|
1201
|
+
saveHeightInput.addEventListener("input", () => matchSaveAspect("height"));
|
|
1202
|
+
saveKeepAspectCheckbox.addEventListener("input", () => matchSaveAspect("width"));
|
|
1203
|
+
getById("saveVideoSizeBtn", HTMLButtonElement).addEventListener("click", resetSaveSize);
|
|
886
1204
|
function formatTimecode(ms) {
|
|
887
1205
|
const totalFrames = Math.round((ms * FPS) / 1000);
|
|
888
1206
|
const frames = totalFrames % FPS;
|
|
@@ -901,8 +1219,9 @@ function updateSaveDialogInfo() {
|
|
|
901
1219
|
saveInfoEnd.textContent = formatTimecode(endMs);
|
|
902
1220
|
saveInfoDuration.textContent = formatTimecode(durationMs);
|
|
903
1221
|
saveInfoDuration.style.color = invalid ? "red" : "";
|
|
904
|
-
saveInfoFrames.textContent =
|
|
1222
|
+
saveInfoFrames.textContent = framesBetween(startMs, endMs).toLocaleString();
|
|
905
1223
|
saveInfoFrames.style.color = invalid ? "red" : "";
|
|
1224
|
+
updateSaveSizeNote();
|
|
906
1225
|
}
|
|
907
1226
|
function setSaveRange(startMs, endMs) {
|
|
908
1227
|
saveStartSecondsInput.value = (startMs / 1000).toString();
|
|
@@ -951,16 +1270,47 @@ saveEndSecondsInput.addEventListener("input", () => {
|
|
|
951
1270
|
updateSaveDialogInfo();
|
|
952
1271
|
});
|
|
953
1272
|
getById("saveDialogCancelBtn", HTMLButtonElement).addEventListener("click", () => saveDialog.close());
|
|
954
|
-
getById("
|
|
1273
|
+
const saveLocalFilesRow = getById("saveLocalFilesRow", HTMLDivElement);
|
|
1274
|
+
const saveLocalFilesNote = getById("saveLocalFilesNote", HTMLSpanElement);
|
|
1275
|
+
const saveLocalFilesBtn = getById("saveLocalFilesBtn", HTMLButtonElement);
|
|
1276
|
+
/**
|
|
1277
|
+
* Check every local file the video uses, before a long recording starts, so it can't stop
|
|
1278
|
+
* halfway to wait for a permission nobody is there to give.
|
|
1279
|
+
* @returns True if they're all ready. Otherwise the Save dialog says what's wrong.
|
|
1280
|
+
*/
|
|
1281
|
+
async function saveDialogLocalFilesReady() {
|
|
1282
|
+
const problems = await checkLocalFiles(localFileUrlsIn(toShow));
|
|
1283
|
+
saveLocalFilesRow.hidden = problems.length === 0;
|
|
1284
|
+
const needPermission = problems.some((problem) => problem.reason === "permission");
|
|
1285
|
+
saveLocalFilesBtn.hidden = !needPermission;
|
|
1286
|
+
saveLocalFilesNote.textContent = problems.map((problem) => problem.message).join(" ");
|
|
1287
|
+
return problems.length === 0;
|
|
1288
|
+
}
|
|
1289
|
+
saveLocalFilesBtn.addEventListener("click", async () => {
|
|
1290
|
+
await allowLocalFiles();
|
|
1291
|
+
await saveDialogLocalFilesReady();
|
|
1292
|
+
});
|
|
1293
|
+
saveOkBtn.addEventListener("click", async () => {
|
|
955
1294
|
const startMs = (saveStartSecondsInput.valueAsNumber || 0) * 1000;
|
|
956
1295
|
const endMs = (saveEndSecondsInput.valueAsNumber || 0) * 1000;
|
|
1296
|
+
const width = saveWidthInput.valueAsNumber;
|
|
1297
|
+
const height = saveHeightInput.valueAsNumber;
|
|
1298
|
+
if (saveSizeProblem(width, height))
|
|
1299
|
+
return;
|
|
1300
|
+
// Quick: no prompts, just IndexedDB. The click still counts for the file picker afterward.
|
|
1301
|
+
if (!(await saveDialogLocalFilesReady()))
|
|
1302
|
+
return;
|
|
957
1303
|
saveDialog.close();
|
|
958
|
-
startRecording(startMs, endMs);
|
|
1304
|
+
startRecording(startMs, endMs, width, height);
|
|
959
1305
|
});
|
|
960
1306
|
startRecordingButton.addEventListener("click", () => {
|
|
961
1307
|
populateSaveChapterSelect();
|
|
1308
|
+
// Always start from the video's own size, not whatever was used last time.
|
|
1309
|
+
resetSaveSize();
|
|
962
1310
|
setSaveRange(0, toShow.duration);
|
|
1311
|
+
saveLocalFilesRow.hidden = true;
|
|
963
1312
|
saveDialog.showModal();
|
|
1313
|
+
void saveDialogLocalFilesReady();
|
|
964
1314
|
});
|
|
965
1315
|
/**
|
|
966
1316
|
* The flat list of every selectable section in the video, in timeline order.
|
|
@@ -1252,10 +1602,7 @@ const veRootParent = {
|
|
|
1252
1602
|
clearTimeout(_durationAudioTimer);
|
|
1253
1603
|
_durationAudioTimer = setTimeout(() => void initAudio(), 300);
|
|
1254
1604
|
// Redraw the timeline so block positions/sizes update during drags.
|
|
1255
|
-
|
|
1256
|
-
timelineDisplay.setChapterDuration(_veRootSelectable.duration);
|
|
1257
|
-
timelineDisplay.setBlocks(_buildTimelineBlocks(_veRootSelectable));
|
|
1258
|
-
}
|
|
1605
|
+
refreshTimeline();
|
|
1259
1606
|
scheduleChapterRefresh();
|
|
1260
1607
|
},
|
|
1261
1608
|
};
|
|
@@ -1278,10 +1625,7 @@ const toShowParent = {
|
|
|
1278
1625
|
markDirty();
|
|
1279
1626
|
clearTimeout(_durationAudioTimer);
|
|
1280
1627
|
_durationAudioTimer = setTimeout(() => void initAudio(), 300);
|
|
1281
|
-
|
|
1282
|
-
timelineDisplay.setChapterDuration(_veRootSelectable.duration);
|
|
1283
|
-
timelineDisplay.setBlocks(_buildTimelineBlocks(_veRootSelectable));
|
|
1284
|
-
}
|
|
1628
|
+
refreshTimeline();
|
|
1285
1629
|
scheduleChapterRefresh();
|
|
1286
1630
|
},
|
|
1287
1631
|
};
|
|
@@ -1492,8 +1836,7 @@ transcriptView = new TranscriptView({
|
|
|
1492
1836
|
_durationAudioTimer = setTimeout(() => void initAudio(), 300);
|
|
1493
1837
|
// Show the owner's Sound Clips, with the remaining piece highlighted.
|
|
1494
1838
|
selectInChapter(owner);
|
|
1495
|
-
|
|
1496
|
-
_updateTimeline(_veRootSelectable);
|
|
1839
|
+
refreshTimeline();
|
|
1497
1840
|
},
|
|
1498
1841
|
});
|
|
1499
1842
|
getById("timelineCanvas", HTMLCanvasElement).after(transcriptView.element);
|
|
@@ -1816,8 +2159,19 @@ function _buildTimelineBlocks(selectable) {
|
|
|
1816
2159
|
}
|
|
1817
2160
|
return blocks;
|
|
1818
2161
|
}
|
|
2162
|
+
/**
|
|
2163
|
+
* Redraw the timeline after an edit. It always shows the chapter, the root picked in the
|
|
2164
|
+
* `<select>`. Not {@link _veRootSelectable}: that's whatever the component editor shows, which
|
|
2165
|
+
* can be a child of the chapter. Passing both, one after the other, looked like a new chapter
|
|
2166
|
+
* every time, and reset the timeline's zoom and pan.
|
|
2167
|
+
*/
|
|
2168
|
+
function refreshTimeline() {
|
|
2169
|
+
const chapter = currentRoot();
|
|
2170
|
+
if (chapter)
|
|
2171
|
+
_updateTimeline(chapter);
|
|
2172
|
+
}
|
|
1819
2173
|
function _updateTimeline(selectable) {
|
|
1820
|
-
timelineDisplay.
|
|
2174
|
+
timelineDisplay.setChapter(selectable, selectable.duration);
|
|
1821
2175
|
timelineDisplay.setBlocks(_buildTimelineBlocks(selectable));
|
|
1822
2176
|
timelineDisplay.setSelectedId(selectedSlideChild ?? undefined);
|
|
1823
2177
|
}
|
|
@@ -2189,10 +2543,6 @@ function buildDiffText() {
|
|
|
2189
2543
|
? JSON.stringify(s.keyframes)
|
|
2190
2544
|
: JSON.stringify(s.value);
|
|
2191
2545
|
}
|
|
2192
|
-
/**
|
|
2193
|
-
* Generate TypeScript constructor + .set() lines for a removable component,
|
|
2194
|
-
* omitting any property whose value matches the class default.
|
|
2195
|
-
*/
|
|
2196
2546
|
/** Variable names already used in this diff, so generated code never declares one twice. */
|
|
2197
2547
|
const usedVarNames = new Set();
|
|
2198
2548
|
function uniqueVarName(base) {
|
|
@@ -2204,11 +2554,12 @@ function buildDiffText() {
|
|
|
2204
2554
|
}
|
|
2205
2555
|
/**
|
|
2206
2556
|
* TypeScript that recreates `comp`, a component added in the Visual Editor, and adds it to
|
|
2207
|
-
* `parentExpr
|
|
2557
|
+
* `parentExpr`'s replaceable children, so the Visual Editor can still edit or delete it.
|
|
2558
|
+
* Covers everything the save file stores for such a component: schedules
|
|
2208
2559
|
* and scalars that differ from the class's defaults, the user's name for it, its own
|
|
2209
2560
|
* replaceable children (recursively), its duration, and its sound clips.
|
|
2210
2561
|
*/
|
|
2211
|
-
function generateComponentCode(comp, indent, parentExpr
|
|
2562
|
+
function generateComponentCode(comp, indent, parentExpr) {
|
|
2212
2563
|
const out = [];
|
|
2213
2564
|
const rk = comp.registryKey ?? "unknown";
|
|
2214
2565
|
const regEntry = componentRegistry.get(rk);
|
|
@@ -2279,10 +2630,33 @@ function buildDiffText() {
|
|
|
2279
2630
|
JSON.stringify(comp.soundClips ?? []) !== JSON.stringify(def.soundClips ?? [])) {
|
|
2280
2631
|
out.push(`${indent}${varName}.soundClips = ${JSON.stringify(comp.soundClips ?? [])};`);
|
|
2281
2632
|
}
|
|
2282
|
-
out.push(`${indent}${parentExpr}.
|
|
2633
|
+
out.push(`${indent}${parentExpr}.replaceableComponents!.push(${varName});`);
|
|
2283
2634
|
return out;
|
|
2284
2635
|
}
|
|
2285
|
-
|
|
2636
|
+
/** A component's name in the diff: the user's name for it, or its own. */
|
|
2637
|
+
function displayName(comp) {
|
|
2638
|
+
return comp.userEditableDescription ?? comp.description;
|
|
2639
|
+
}
|
|
2640
|
+
/** `names`, with " #1", " #2"… added to any name used more than once. */
|
|
2641
|
+
function numberedNames(names) {
|
|
2642
|
+
const total = new Map();
|
|
2643
|
+
for (const name of names)
|
|
2644
|
+
total.set(name, (total.get(name) ?? 0) + 1);
|
|
2645
|
+
const seen = new Map();
|
|
2646
|
+
return names.map((name) => {
|
|
2647
|
+
if (total.get(name) < 2)
|
|
2648
|
+
return name;
|
|
2649
|
+
const n = (seen.get(name) ?? 0) + 1;
|
|
2650
|
+
seen.set(name, n);
|
|
2651
|
+
return `${name} #${n}`;
|
|
2652
|
+
});
|
|
2653
|
+
}
|
|
2654
|
+
/**
|
|
2655
|
+
* The differences in one component's own properties. The same for a fixed child, whose
|
|
2656
|
+
* default is its TypeScript, and for a replaceable child, whose default is its counterpart
|
|
2657
|
+
* in the TypeScript's list.
|
|
2658
|
+
*/
|
|
2659
|
+
function diffProperties(defaultEntry, sel, path) {
|
|
2286
2660
|
const defSchedules = defaultEntry.schedules ?? [];
|
|
2287
2661
|
const curSchedules = sel.schedules?.length
|
|
2288
2662
|
? serializeSchedules(sel.schedules)
|
|
@@ -2339,13 +2713,66 @@ function buildDiffText() {
|
|
|
2339
2713
|
lines.push(`TypeScript: ${JSON.stringify(defClips)}`);
|
|
2340
2714
|
lines.push(`Current: ${JSON.stringify(curClips)}`);
|
|
2341
2715
|
}
|
|
2342
|
-
|
|
2343
|
-
|
|
2716
|
+
}
|
|
2717
|
+
/**
|
|
2718
|
+
* The differences between a component's replaceable children and the TypeScript's.
|
|
2719
|
+
*
|
|
2720
|
+
* Children pair up by kind and name, in order, the way fixed children pair up by description.
|
|
2721
|
+
* Then any left over pair up by kind alone, so a child renamed in the Visual Editor is one
|
|
2722
|
+
* child with a new name, not one deleted and one added.
|
|
2723
|
+
*
|
|
2724
|
+
* A pair prints its property changes, the same way a fixed child does. A child with no
|
|
2725
|
+
* counterpart in the TypeScript prints as the TypeScript that makes it. A deleted child, or
|
|
2726
|
+
* an order that deleting and adding wouldn't give, gets one line. No changes, no lines.
|
|
2727
|
+
*/
|
|
2728
|
+
function diffReplaceable(defaults, sel, path) {
|
|
2729
|
+
// Only components with a registry key are saved, so only they can differ.
|
|
2730
|
+
const live = (sel.replaceableComponents?.get() ?? []).filter((comp) => comp.registryKey !== undefined);
|
|
2731
|
+
const key = (registryKey, name) => `${registryKey}\0${name ?? ""}`;
|
|
2732
|
+
const liveFor = counterparts(defaults.map((d) => ({
|
|
2733
|
+
description: key(d.registryKey, d.userEditableDescription),
|
|
2734
|
+
})), live.map((comp) => ({
|
|
2735
|
+
description: key(comp.registryKey, comp.userEditableDescription),
|
|
2736
|
+
comp,
|
|
2737
|
+
}))).map((match) => match?.comp);
|
|
2738
|
+
for (const [index, d] of defaults.entries()) {
|
|
2739
|
+
liveFor[index] ??= live.find((comp) => comp.registryKey === d.registryKey && !liveFor.includes(comp));
|
|
2740
|
+
}
|
|
2741
|
+
const added = live.filter((comp) => !liveFor.includes(comp));
|
|
2742
|
+
const names = new Map(numberedNames(live.map(displayName)).map((name, index) => [
|
|
2743
|
+
live[index],
|
|
2744
|
+
name,
|
|
2745
|
+
]));
|
|
2746
|
+
const expectedOrder = [
|
|
2747
|
+
...liveFor.filter((comp) => comp !== undefined),
|
|
2748
|
+
...added,
|
|
2749
|
+
];
|
|
2750
|
+
if (expectedOrder.some((comp, index) => comp !== live[index])) {
|
|
2344
2751
|
printPathIfNeeded(path);
|
|
2345
|
-
|
|
2346
|
-
|
|
2752
|
+
lines.push(` [new order: ${live.map((comp) => names.get(comp)).join(", ")}]`);
|
|
2753
|
+
}
|
|
2754
|
+
for (const [index, d] of defaults.entries()) {
|
|
2755
|
+
const comp = liveFor[index];
|
|
2756
|
+
if (comp) {
|
|
2757
|
+
const childPath = [...path, names.get(comp)];
|
|
2758
|
+
diffProperties(d, comp, childPath);
|
|
2759
|
+
diffReplaceable(d.components ?? [], comp, childPath);
|
|
2760
|
+
}
|
|
2761
|
+
else {
|
|
2762
|
+
printPathIfNeeded([...path, d.userEditableDescription ?? d.registryKey]);
|
|
2763
|
+
lines.push(` [deleted]`);
|
|
2347
2764
|
}
|
|
2348
2765
|
}
|
|
2766
|
+
const parentExpr = toVarName(path.at(-1) ?? "") || "parent";
|
|
2767
|
+
for (const comp of added) {
|
|
2768
|
+
printPathIfNeeded([...path, names.get(comp)]);
|
|
2769
|
+
lines.push(` [added]`);
|
|
2770
|
+
lines.push(...generateComponentCode(comp, " ", parentExpr));
|
|
2771
|
+
}
|
|
2772
|
+
}
|
|
2773
|
+
function diffNode(defaultEntry, sel, path) {
|
|
2774
|
+
diffProperties(defaultEntry, sel, path);
|
|
2775
|
+
diffReplaceable(defaultEntry.components ?? [], sel, path);
|
|
2349
2776
|
const liveFixed = getFixedComponents(sel);
|
|
2350
2777
|
const defaultFixed = defaultEntry.fixedComponents ?? [];
|
|
2351
2778
|
const liveFor = counterparts(defaultFixed, liveFixed);
|
|
@@ -2369,10 +2796,12 @@ function buildDiffText() {
|
|
|
2369
2796
|
if (tsDefaultsTree) {
|
|
2370
2797
|
diffNode(tsDefaultsTree, toShow, [toShow.description]);
|
|
2371
2798
|
}
|
|
2372
|
-
if (lines.length ===
|
|
2799
|
+
if (lines.length === 0)
|
|
2373
2800
|
lines.push("(no differences found)");
|
|
2374
2801
|
return lines.join("\n");
|
|
2375
2802
|
}
|
|
2803
|
+
/** The diff file's text, from the console, with or without syncing the file. */
|
|
2804
|
+
philDebug.diffText = () => console.log(buildDiffText());
|
|
2376
2805
|
// MARK: Load-source helpers
|
|
2377
2806
|
/** Logs abandoned or deleted items; replace console.info with persistent storage if needed. */
|
|
2378
2807
|
function sendToRecycleBin(...args) {
|
|
@@ -3104,9 +3533,18 @@ function buildScheduleSection(info, selectable) {
|
|
|
3104
3533
|
function currentTimeMs() {
|
|
3105
3534
|
return playPositionSeconds.valueAsNumber * 1000;
|
|
3106
3535
|
}
|
|
3107
|
-
/**
|
|
3536
|
+
/**
|
|
3537
|
+
* Where the component that owns this schedule starts, measured from the start of the Visual
|
|
3538
|
+
* Editor's root. 0 for anything in a parallel container at the top, which is why measuring
|
|
3539
|
+
* from the root used to look right. A clip in an In Series starts later.
|
|
3540
|
+
*/
|
|
3541
|
+
function ownerStartMs() {
|
|
3542
|
+
const root = currentRoot();
|
|
3543
|
+
return root ? (startWithin(root, selectable) ?? 0) : 0;
|
|
3544
|
+
}
|
|
3545
|
+
/** Time relative to the start of the component that owns this schedule — what keyframe.time values use. */
|
|
3108
3546
|
function localTimeMs() {
|
|
3109
|
-
return currentTimeMs() - rootStartMs;
|
|
3547
|
+
return currentTimeMs() - rootStartMs - ownerStartMs();
|
|
3110
3548
|
}
|
|
3111
3549
|
function addKeyframeAtCurrentTime() {
|
|
3112
3550
|
const t = localTimeMs();
|
|
@@ -3867,7 +4305,7 @@ function buildScheduleSection(info, selectable) {
|
|
|
3867
4305
|
updateGoTo();
|
|
3868
4306
|
goToButtonUpdaters.push(updateGoTo);
|
|
3869
4307
|
goToBtn.addEventListener("click", () => {
|
|
3870
|
-
const globalMs = Math.max(sectionStartTime, Math.min(sectionEndTime, kf.time + rootStartMs));
|
|
4308
|
+
const globalMs = Math.max(sectionStartTime, Math.min(sectionEndTime, kf.time + rootStartMs + ownerStartMs()));
|
|
3871
4309
|
stopAudio();
|
|
3872
4310
|
loadPlayPositionSeconds(globalMs);
|
|
3873
4311
|
loadPlayPositionRange();
|
|
@@ -3993,10 +4431,13 @@ function updateComponentEditor(selectable) {
|
|
|
3993
4431
|
}
|
|
3994
4432
|
if (replaceable && replaceables) {
|
|
3995
4433
|
const moveChild = (fromIdx, toIdx) => {
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4434
|
+
// In a series, the playhead follows the picture it was showing.
|
|
4435
|
+
keepingScene(selectable, () => {
|
|
4436
|
+
const arr = replaceables.get();
|
|
4437
|
+
const [item] = arr.splice(fromIdx, 1);
|
|
4438
|
+
arr.splice(toIdx, 0, item);
|
|
4439
|
+
replaceables.replace(arr);
|
|
4440
|
+
});
|
|
4000
4441
|
activeRootComponentEditor?.resetAll();
|
|
4001
4442
|
updateComponentEditor(selectable);
|
|
4002
4443
|
};
|
|
@@ -4027,12 +4468,21 @@ function updateComponentEditor(selectable) {
|
|
|
4027
4468
|
const deleteBtn = document.createElement("button");
|
|
4028
4469
|
deleteBtn.type = "button";
|
|
4029
4470
|
deleteBtn.textContent = "🗑";
|
|
4471
|
+
deleteBtn.title = "Delete component";
|
|
4030
4472
|
deleteBtn.addEventListener("click", () => {
|
|
4473
|
+
// In a series, everything after this child moves earlier, and the playhead goes with it.
|
|
4474
|
+
const root = currentRoot();
|
|
4475
|
+
const childStart = root ? startWithin(root, child) : undefined;
|
|
4476
|
+
const childDuration = child.duration;
|
|
4477
|
+
const chainEndMs = seriesChainEndMs(selectable);
|
|
4031
4478
|
const arr = replaceables.get();
|
|
4032
4479
|
const i = arr.indexOf(child);
|
|
4033
4480
|
if (i !== -1)
|
|
4034
4481
|
arr.splice(i, 1);
|
|
4035
4482
|
replaceables.replace(arr);
|
|
4483
|
+
if (childStart !== undefined) {
|
|
4484
|
+
playheadAfterRemoving(childStart, childStart + childDuration, chainEndMs);
|
|
4485
|
+
}
|
|
4036
4486
|
if (selectedSlideChild === child) {
|
|
4037
4487
|
selectedSlideChild = null;
|
|
4038
4488
|
updateScheduleEditor(selectable);
|
|
@@ -4149,6 +4599,16 @@ function updateComponentEditor(selectable) {
|
|
|
4149
4599
|
if (!entry)
|
|
4150
4600
|
return;
|
|
4151
4601
|
const newChild = entry.create();
|
|
4602
|
+
if (newChild instanceof VideoClipComponent) {
|
|
4603
|
+
// The class default is 16 × 9, and saved files rely on defaults never changing.
|
|
4604
|
+
// So fill the canvas here, as a value of its own, whatever size the canvas is.
|
|
4605
|
+
newChild.destinationRectSchedule.set({
|
|
4606
|
+
x: 0,
|
|
4607
|
+
y: 0,
|
|
4608
|
+
width: canvasRecorder.width,
|
|
4609
|
+
height: canvasRecorder.height,
|
|
4610
|
+
});
|
|
4611
|
+
}
|
|
4152
4612
|
addTarget.replaceableComponents.push(newChild);
|
|
4153
4613
|
afterStructureEdit(newChild);
|
|
4154
4614
|
});
|
|
@@ -4227,8 +4687,7 @@ function buildSoundClipSection(selectable) {
|
|
|
4227
4687
|
clearTimeout(_durationAudioTimer);
|
|
4228
4688
|
_durationAudioTimer = setTimeout(() => void initAudio(), 300);
|
|
4229
4689
|
updateScheduleEditor(selectable);
|
|
4230
|
-
|
|
4231
|
-
_updateTimeline(_veRootSelectable);
|
|
4690
|
+
refreshTimeline();
|
|
4232
4691
|
}
|
|
4233
4692
|
/** Every place a sound can live in this video, and when each starts. */
|
|
4234
4693
|
const owners = soundOwners(toShow);
|
|
@@ -4333,7 +4792,7 @@ function buildSoundClipSection(selectable) {
|
|
|
4333
4792
|
});
|
|
4334
4793
|
const delBtn = document.createElement("button");
|
|
4335
4794
|
delBtn.type = "button";
|
|
4336
|
-
delBtn.textContent = "
|
|
4795
|
+
delBtn.textContent = "🗑";
|
|
4337
4796
|
delBtn.title = "Delete clip";
|
|
4338
4797
|
delBtn.addEventListener("click", () => {
|
|
4339
4798
|
clips.splice(i, 1);
|
|
@@ -4523,8 +4982,7 @@ function buildSoundClipSection(selectable) {
|
|
|
4523
4982
|
// The new owner is in another chapter. Stay here; the clip is gone from this list.
|
|
4524
4983
|
updateScheduleEditor(selectable);
|
|
4525
4984
|
}
|
|
4526
|
-
|
|
4527
|
-
_updateTimeline(_veRootSelectable);
|
|
4985
|
+
refreshTimeline();
|
|
4528
4986
|
});
|
|
4529
4987
|
ownerLabel.append(ownerSelect);
|
|
4530
4988
|
const playsAt = document.createElement("span");
|
|
@@ -4573,6 +5031,9 @@ function buildNameSection(selectable) {
|
|
|
4573
5031
|
const root = currentSaveTarget();
|
|
4574
5032
|
if (root)
|
|
4575
5033
|
updateComponentEditor(root);
|
|
5034
|
+
// The timeline's blocks and the Edit menu show the name, too.
|
|
5035
|
+
refreshTimeline();
|
|
5036
|
+
scheduleChapterRefresh();
|
|
4576
5037
|
}
|
|
4577
5038
|
input.addEventListener("input", () => syncName(input.value));
|
|
4578
5039
|
resetBtn.addEventListener("click", () => {
|
|
@@ -4642,6 +5103,13 @@ function updateScheduleEditor(selectable) {
|
|
|
4642
5103
|
}
|
|
4643
5104
|
const videoPanel = videoClip
|
|
4644
5105
|
? buildVideoClipPanel(videoClip, {
|
|
5106
|
+
setVideoSize: setVideoSizeFromGui,
|
|
5107
|
+
urlChanged() {
|
|
5108
|
+
activeRootComponentEditor?.update(videoClip, videoClip.urlScalar);
|
|
5109
|
+
markDirty();
|
|
5110
|
+
// Rebuild so the URL field shows the new value.
|
|
5111
|
+
updateScheduleEditor(videoClip);
|
|
5112
|
+
},
|
|
4645
5113
|
scalarsChanged() {
|
|
4646
5114
|
activeRootComponentEditor?.update(videoClip, videoClip.startMsIntoClipScalar);
|
|
4647
5115
|
activeRootComponentEditor?.update(videoClip, videoClip.endMsIntoClipScalar);
|
|
@@ -4678,6 +5146,12 @@ function updateScheduleEditor(selectable) {
|
|
|
4678
5146
|
if (selectable instanceof SingleImageComponent) {
|
|
4679
5147
|
const image = selectable;
|
|
4680
5148
|
const imagePanel = buildStaticImagePanel(image, {
|
|
5149
|
+
urlChanged() {
|
|
5150
|
+
activeRootComponentEditor?.update(image, image.urlSchedule);
|
|
5151
|
+
markDirty();
|
|
5152
|
+
// Rebuild so the URL field shows the new value.
|
|
5153
|
+
updateScheduleEditor(image);
|
|
5154
|
+
},
|
|
4681
5155
|
rectKeyframeChanged(kf) {
|
|
4682
5156
|
// The same sync a drag on the canvas uses, so ✎ edit mode survives.
|
|
4683
5157
|
markerSyncCallbacks.get(kf)?.(kf.value);
|
|
@@ -4785,6 +5259,68 @@ function splitTarget(clip) {
|
|
|
4785
5259
|
}
|
|
4786
5260
|
return parent;
|
|
4787
5261
|
}
|
|
5262
|
+
// MARK: Keep the scene
|
|
5263
|
+
/** Move the playhead to this time, measured from the start of the Visual Editor's root. */
|
|
5264
|
+
function seekInRoot(ms) {
|
|
5265
|
+
stopAudio();
|
|
5266
|
+
loadPlayPositionSeconds(rootStartMs + ms);
|
|
5267
|
+
loadPlayPositionRange();
|
|
5268
|
+
// An edit moved the playhead. Keep it on the timeline's screen if it was there.
|
|
5269
|
+
timelineDisplay.movePlayMs(ms);
|
|
5270
|
+
}
|
|
5271
|
+
/**
|
|
5272
|
+
* Before an edit removes time from `series`: where its chain of series ends, measured from the
|
|
5273
|
+
* start of the root. Removing time moves everything up to there earlier, and nothing after it.
|
|
5274
|
+
* Undefined if `series` isn't an In Series in the current root, so nothing moves.
|
|
5275
|
+
*/
|
|
5276
|
+
function seriesChainEndMs(series) {
|
|
5277
|
+
const root = currentRoot();
|
|
5278
|
+
if (!root || !(series instanceof InSeriesComponent))
|
|
5279
|
+
return undefined;
|
|
5280
|
+
let top = series;
|
|
5281
|
+
while (top !== root && top.parent instanceof InSeriesComponent) {
|
|
5282
|
+
top = top.parent;
|
|
5283
|
+
}
|
|
5284
|
+
const start = startWithin(root, top);
|
|
5285
|
+
return start === undefined ? undefined : start + top.duration;
|
|
5286
|
+
}
|
|
5287
|
+
/**
|
|
5288
|
+
* A series just lost the time from `fromMs` to `toMs` (measured from the start of the root), and
|
|
5289
|
+
* everything after it moved earlier to fill the gap. Move the playhead with it, so the preview
|
|
5290
|
+
* keeps showing the same picture. A playhead inside what's gone goes to where the gap was.
|
|
5291
|
+
* @param chainEndMs {@link seriesChainEndMs}, from before the edit.
|
|
5292
|
+
*/
|
|
5293
|
+
function playheadAfterRemoving(fromMs, toMs, chainEndMs) {
|
|
5294
|
+
if (chainEndMs === undefined)
|
|
5295
|
+
return;
|
|
5296
|
+
const at = playheadInRootMs();
|
|
5297
|
+
if (at < fromMs || at >= chainEndMs)
|
|
5298
|
+
return;
|
|
5299
|
+
seekInRoot(at >= toMs ? at - (toMs - fromMs) : fromMs);
|
|
5300
|
+
}
|
|
5301
|
+
/**
|
|
5302
|
+
* Run `edit`, which reorders the children of `series`, then put the playhead on the same moment
|
|
5303
|
+
* of the same child, wherever that child is now.
|
|
5304
|
+
*/
|
|
5305
|
+
function keepingScene(series, edit) {
|
|
5306
|
+
const root = currentRoot();
|
|
5307
|
+
const seriesStart = root && series instanceof InSeriesComponent
|
|
5308
|
+
? startWithin(root, series)
|
|
5309
|
+
: undefined;
|
|
5310
|
+
let anchor;
|
|
5311
|
+
if (seriesStart !== undefined) {
|
|
5312
|
+
const local = playheadInRootMs() - seriesStart;
|
|
5313
|
+
const found = series.children?.find(({ start, child }) => local >= start && local < start + child.duration);
|
|
5314
|
+
if (found)
|
|
5315
|
+
anchor = { child: found.child, offsetMs: local - found.start };
|
|
5316
|
+
}
|
|
5317
|
+
edit();
|
|
5318
|
+
if (!root || !anchor)
|
|
5319
|
+
return;
|
|
5320
|
+
const newStart = startWithin(root, anchor.child);
|
|
5321
|
+
if (newStart !== undefined)
|
|
5322
|
+
seekInRoot(newStart + anchor.offsetMs);
|
|
5323
|
+
}
|
|
4788
5324
|
/** How long a sound plays, for splitting: a clip whose file isn't decoded yet is taken to play forever. */
|
|
4789
5325
|
function soundLengthForSplit(sound) {
|
|
4790
5326
|
return soundClipLengthMs(sound) ?? Infinity;
|
|
@@ -4815,8 +5351,17 @@ async function splitAtPlayhead(clip) {
|
|
|
4815
5351
|
: [second];
|
|
4816
5352
|
const siblings = parent.replaceableComponents.get();
|
|
4817
5353
|
siblings.splice(siblings.indexOf(clip), 1, ...kept);
|
|
5354
|
+
const chainEndMs = seriesChainEndMs(parent);
|
|
4818
5355
|
// Saves, rebuilds the audio, and redraws the timeline and the chapter list.
|
|
4819
5356
|
parent.replaceableComponents.replace(siblings);
|
|
5357
|
+
// Keep showing the same picture: a piece thrown away takes its time with it.
|
|
5358
|
+
const splitMs = clipStart + first.duration;
|
|
5359
|
+
if (choice.keep === "second") {
|
|
5360
|
+
playheadAfterRemoving(clipStart, splitMs, chainEndMs);
|
|
5361
|
+
}
|
|
5362
|
+
else if (choice.keep === "first") {
|
|
5363
|
+
playheadAfterRemoving(splitMs, splitMs + second.duration, chainEndMs);
|
|
5364
|
+
}
|
|
4820
5365
|
selectedSoundClip = undefined;
|
|
4821
5366
|
activeRootComponentEditor?.resetAll();
|
|
4822
5367
|
if (root !== clip) {
|
|
@@ -4898,6 +5443,21 @@ function buildMultiTextFrame(text) {
|
|
|
4898
5443
|
textFrameCanvasStates.set(text, newState);
|
|
4899
5444
|
applyCanvasState();
|
|
4900
5445
|
},
|
|
5446
|
+
editText() {
|
|
5447
|
+
void openMultiTextDialog(text, {
|
|
5448
|
+
saveNow: _flushDirtyToDb,
|
|
5449
|
+
changed: markDirty,
|
|
5450
|
+
copyComponent: (component) => buildComponents(serializeComponents([component]))[0],
|
|
5451
|
+
closed() {
|
|
5452
|
+
// The dialog covered the component list and this panel, so neither was kept up to date.
|
|
5453
|
+
activeRootComponentEditor?.resetAll();
|
|
5454
|
+
const root = currentSaveTarget();
|
|
5455
|
+
if (root)
|
|
5456
|
+
updateComponentEditor(root);
|
|
5457
|
+
updateScheduleEditor(text);
|
|
5458
|
+
},
|
|
5459
|
+
});
|
|
5460
|
+
},
|
|
4901
5461
|
});
|
|
4902
5462
|
// Adding a keyframe to Position, say, means there's no longer one frame.
|
|
4903
5463
|
scheduleEditorRefreshers.push(applyCanvasState, panel.refresh);
|
|
@@ -6099,6 +6659,8 @@ function refreshEditorsAfterLoad() {
|
|
|
6099
6659
|
activeRootComponentEditor?.resetAll();
|
|
6100
6660
|
updateComponentEditor(current);
|
|
6101
6661
|
updateScheduleEditor(current);
|
|
6662
|
+
// The loaded state may use local files that need 🔓.
|
|
6663
|
+
checkVideosLocalFiles();
|
|
6102
6664
|
}
|
|
6103
6665
|
/**
|
|
6104
6666
|
* Apply a parsed JSON snapshot to all matching selectables in `chapterList`,
|