canvas-recorder-lib 0.7.1 → 0.7.3
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/README.md +51 -8
- package/dev/audio-builder.ts +5 -1
- package/dev/canvas-recorder.css +15 -4
- package/dev/canvas-recorder.ts +518 -131
- package/dev/delay-files.ts +1 -1
- package/dev/format-editor.ts +7 -2
- package/dev/fourier-panel.ts +11 -3
- package/dev/handwriting-panel.ts +14 -9
- package/dev/local-file-row.ts +12 -5
- package/dev/multi-text-dialog.ts +15 -6
- package/dev/multi-text-panel.ts +6 -2
- package/dev/player-body.ts +4 -0
- package/dev/schedule-helpers.ts +11 -4
- package/dev/sound-clips.ts +4 -1
- package/dev/soundtrack.ts +42 -11
- package/dev/split-dialog.ts +49 -19
- package/dev/static-image-panel.ts +17 -5
- package/dev/synced-file.ts +4 -5
- package/dev/timeline-display.ts +152 -50
- package/dev/transcribe-core.ts +48 -17
- package/dev/transcribe-worker.ts +20 -9
- package/dev/transcript-align.ts +95 -20
- package/dev/transcript-export.ts +18 -7
- package/dev/transcript-view.ts +78 -22
- package/dev/transcripts.ts +43 -23
- package/dev/video-clip-panel.ts +64 -18
- package/dev/voice/chirp.ts +21 -5
- package/dev/voice/folder.ts +22 -7
- package/dev/voice/voice-panel.ts +34 -10
- package/dev/voice/voice-recorder.ts +74 -18
- package/dist/dev/audio-builder.js.map +1 -1
- package/dist/dev/canvas-recorder.css +15 -4
- package/dist/dev/canvas-recorder.js +375 -85
- package/dist/dev/canvas-recorder.js.map +1 -1
- package/dist/dev/format-editor.d.ts.map +1 -1
- package/dist/dev/format-editor.js.map +1 -1
- package/dist/dev/fourier-panel.d.ts.map +1 -1
- package/dist/dev/fourier-panel.js.map +1 -1
- package/dist/dev/handwriting-panel.d.ts.map +1 -1
- package/dist/dev/handwriting-panel.js +10 -8
- package/dist/dev/handwriting-panel.js.map +1 -1
- package/dist/dev/local-file-row.d.ts.map +1 -1
- package/dist/dev/local-file-row.js +12 -4
- package/dist/dev/local-file-row.js.map +1 -1
- package/dist/dev/multi-text-dialog.d.ts.map +1 -1
- package/dist/dev/multi-text-dialog.js +4 -2
- package/dist/dev/multi-text-dialog.js.map +1 -1
- package/dist/dev/multi-text-panel.d.ts.map +1 -1
- package/dist/dev/multi-text-panel.js +2 -1
- 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 +4 -0
- package/dist/dev/player-body.js.map +1 -1
- package/dist/dev/schedule-helpers.d.ts.map +1 -1
- package/dist/dev/schedule-helpers.js +4 -1
- package/dist/dev/schedule-helpers.js.map +1 -1
- package/dist/dev/sound-clips.d.ts.map +1 -1
- package/dist/dev/sound-clips.js.map +1 -1
- package/dist/dev/soundtrack.d.ts +12 -0
- package/dist/dev/soundtrack.d.ts.map +1 -1
- package/dist/dev/soundtrack.js +33 -7
- package/dist/dev/soundtrack.js.map +1 -1
- package/dist/dev/split-dialog.d.ts.map +1 -1
- package/dist/dev/split-dialog.js +17 -10
- package/dist/dev/split-dialog.js.map +1 -1
- package/dist/dev/static-image-panel.d.ts.map +1 -1
- package/dist/dev/static-image-panel.js +7 -3
- package/dist/dev/static-image-panel.js.map +1 -1
- package/dist/dev/synced-file.d.ts.map +1 -1
- package/dist/dev/synced-file.js.map +1 -1
- package/dist/dev/timeline-display.d.ts.map +1 -1
- package/dist/dev/timeline-display.js +62 -17
- package/dist/dev/timeline-display.js.map +1 -1
- package/dist/dev/transcribe-core.d.ts.map +1 -1
- package/dist/dev/transcribe-core.js +13 -3
- package/dist/dev/transcribe-core.js.map +1 -1
- package/dist/dev/transcribe-worker.d.ts.map +1 -1
- package/dist/dev/transcribe-worker.js +9 -3
- package/dist/dev/transcribe-worker.js.map +1 -1
- package/dist/dev/transcript-align.d.ts.map +1 -1
- package/dist/dev/transcript-align.js +52 -9
- package/dist/dev/transcript-align.js.map +1 -1
- package/dist/dev/transcript-export.d.ts.map +1 -1
- package/dist/dev/transcript-export.js +10 -4
- package/dist/dev/transcript-export.js.map +1 -1
- package/dist/dev/transcript-view.d.ts +2 -0
- package/dist/dev/transcript-view.d.ts.map +1 -1
- package/dist/dev/transcript-view.js +32 -11
- package/dist/dev/transcript-view.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.map +1 -1
- package/dist/dev/video-clip-panel.js +25 -8
- package/dist/dev/video-clip-panel.js.map +1 -1
- package/dist/dev/voice/chirp.d.ts.map +1 -1
- package/dist/dev/voice/chirp.js +5 -1
- package/dist/dev/voice/chirp.js.map +1 -1
- package/dist/dev/voice/folder.d.ts.map +1 -1
- package/dist/dev/voice/folder.js +1 -1
- package/dist/dev/voice/folder.js.map +1 -1
- package/dist/dev/voice/voice-panel.d.ts.map +1 -1
- package/dist/dev/voice/voice-panel.js +15 -6
- package/dist/dev/voice/voice-panel.js.map +1 -1
- package/dist/dev/voice/voice-recorder.d.ts.map +1 -1
- package/dist/dev/voice/voice-recorder.js +34 -9
- package/dist/dev/voice/voice-recorder.js.map +1 -1
- package/dist/lib/main-control.d.ts +35 -1
- package/dist/lib/main-control.d.ts.map +1 -1
- package/dist/lib/main-control.js +76 -0
- package/dist/lib/main-control.js.map +1 -1
- package/dist/src/corner-rounder.d.ts.map +1 -1
- package/dist/src/corner-rounder.js +1 -1
- package/dist/src/corner-rounder.js.map +1 -1
- package/dist/src/local-files.d.ts.map +1 -1
- package/dist/src/local-files.js +5 -2
- package/dist/src/local-files.js.map +1 -1
- package/dist/src/peano-fourier/fourier-shared.d.ts +7 -0
- package/dist/src/peano-fourier/fourier-shared.d.ts.map +1 -1
- package/dist/src/peano-fourier/fourier-shared.js +8 -1
- package/dist/src/peano-fourier/fourier-shared.js.map +1 -1
- package/dist/src/showable.d.ts +74 -0
- package/dist/src/showable.d.ts.map +1 -1
- package/dist/src/showable.js.map +1 -1
- package/dist/src/slide-components/fourier.d.ts.map +1 -1
- package/dist/src/slide-components/fourier.js +12 -4
- package/dist/src/slide-components/fourier.js.map +1 -1
- package/dist/src/slide-components/image.d.ts.map +1 -1
- package/dist/src/slide-components/image.js +1 -1
- package/dist/src/slide-components/image.js.map +1 -1
- package/dist/src/slide-components/in-parallel.d.ts.map +1 -1
- package/dist/src/slide-components/in-parallel.js.map +1 -1
- package/dist/src/slide-components/multi-text.d.ts.map +1 -1
- package/dist/src/slide-components/multi-text.js +1 -1
- package/dist/src/slide-components/multi-text.js.map +1 -1
- 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.js.map +1 -1
- package/dist/src/slide-components/serialize.d.ts.map +1 -1
- package/dist/src/slide-components/serialize.js +2 -1
- package/dist/src/slide-components/serialize.js.map +1 -1
- package/dist/src/slide-components/split-video-clip.d.ts.map +1 -1
- package/dist/src/slide-components/split-video-clip.js +4 -1
- package/dist/src/slide-components/split-video-clip.js.map +1 -1
- package/dist/src/slide-components/video-clip.d.ts.map +1 -1
- package/dist/src/slide-components/video-clip.js +7 -4
- package/dist/src/slide-components/video-clip.js.map +1 -1
- package/dist/src/slide-components/video-info.d.ts.map +1 -1
- package/dist/src/slide-components/video-info.js.map +1 -1
- package/dist/src/slow-image-sources.d.ts.map +1 -1
- package/dist/src/slow-image-sources.js +1 -1
- package/dist/src/slow-image-sources.js.map +1 -1
- package/dist/src/snapshot.d.ts.map +1 -1
- package/dist/src/snapshot.js +1 -1
- package/dist/src/snapshot.js.map +1 -1
- package/dist/src/utility.d.ts.map +1 -1
- package/dist/src/utility.js +1 -3
- package/dist/src/utility.js.map +1 -1
- package/lib/main-control.ts +95 -2
- package/package.json +4 -1
- package/src/corner-rounder.ts +5 -12
- package/src/glib/letters-base.ts +1 -1
- package/src/local-files.ts +19 -6
- package/src/peano-fourier/fourier-shared.ts +8 -1
- package/src/showable.ts +79 -0
- package/src/slide-components/fourier.ts +32 -10
- package/src/slide-components/image.ts +4 -1
- package/src/slide-components/in-parallel.ts +1 -2
- package/src/slide-components/multi-text.ts +17 -4
- package/src/slide-components/rectangle.ts +4 -1
- package/src/slide-components/registry.ts +1 -1
- package/src/slide-components/serialize.ts +4 -1
- package/src/slide-components/split-video-clip.ts +4 -1
- package/src/slide-components/video-clip.ts +21 -8
- package/src/slide-components/video-info.ts +4 -1
- package/src/slow-image-sources.ts +5 -1
- package/src/snapshot.ts +13 -4
- package/src/utility.ts +70 -33
package/dev/canvas-recorder.ts
CHANGED
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
assertNonNullable,
|
|
5
5
|
FIGURE_SPACE,
|
|
6
6
|
parseFloatX,
|
|
7
|
-
parseIntX,
|
|
8
7
|
ReadOnlyRect,
|
|
9
8
|
} from "phil-lib/misc";
|
|
10
9
|
import {
|
|
@@ -22,6 +21,8 @@ import {
|
|
|
22
21
|
QUALITY_HIGH,
|
|
23
22
|
} from "mediabunny";
|
|
24
23
|
import {
|
|
24
|
+
EditorPanel,
|
|
25
|
+
EditorPanelAPI,
|
|
25
26
|
RootComponentEditor,
|
|
26
27
|
SerializedScalar,
|
|
27
28
|
SerializedSchedule,
|
|
@@ -262,7 +263,7 @@ function applyZoom(zoom: number, px = panX, py = panY) {
|
|
|
262
263
|
canvas.height = physH;
|
|
263
264
|
canvas.style.width = `${cssW}px`;
|
|
264
265
|
canvas.style.height = `${cssH}px`;
|
|
265
|
-
showFrame(
|
|
266
|
+
showFrame(playheadInVideoMs(), true);
|
|
266
267
|
}
|
|
267
268
|
[panX, panY] = clampPan(cssW, cssH, px, py);
|
|
268
269
|
canvas.style.left = `${panX}px`;
|
|
@@ -297,7 +298,7 @@ function zoomToFit() {
|
|
|
297
298
|
canvas.style.left = `${Math.round((vpW - cssW) / 2)}px`;
|
|
298
299
|
canvas.style.top = `${Math.round((vpH - cssH) / 2)}px`;
|
|
299
300
|
// Immediately redraw so the canvas clear doesn't show as a gray flash.
|
|
300
|
-
showFrame(
|
|
301
|
+
showFrame(playheadInVideoMs(), true);
|
|
301
302
|
}
|
|
302
303
|
|
|
303
304
|
zoomSelect.addEventListener("change", () => {
|
|
@@ -365,7 +366,8 @@ function readSavedVideoSize(): VideoSize | undefined {
|
|
|
365
366
|
height: record.height,
|
|
366
367
|
};
|
|
367
368
|
const valid = Object.values(size).every(
|
|
368
|
-
(value) =>
|
|
369
|
+
(value) =>
|
|
370
|
+
typeof value === "number" && Number.isFinite(value) && value > 0,
|
|
369
371
|
);
|
|
370
372
|
return valid ? (size as VideoSize) : undefined;
|
|
371
373
|
} catch {
|
|
@@ -401,9 +403,10 @@ function showVideoSize(size: VideoSize) {
|
|
|
401
403
|
videoSizeWarning.title = stretched
|
|
402
404
|
? `The pixels are ${pixelAspect.toFixed(3)} : 1 and the units are ${unitAspect.toFixed(3)} : 1, so the picture is stretched to fit.`
|
|
403
405
|
: "";
|
|
404
|
-
getById("videoSizeControls", HTMLSpanElement).title =
|
|
405
|
-
|
|
406
|
-
|
|
406
|
+
getById("videoSizeControls", HTMLSpanElement).title =
|
|
407
|
+
canvasRecorder.sizeLocked
|
|
408
|
+
? "The size of the video. This program sets it, so it can't be changed here."
|
|
409
|
+
: "The size of the video. Pixels: the saved file. Units: the coordinates everything is drawn in. Remembered for this video.";
|
|
407
410
|
}
|
|
408
411
|
showVideoSize(canvasRecorder.size);
|
|
409
412
|
|
|
@@ -421,7 +424,10 @@ function setVideoSizeFromGui(size: VideoSize): boolean {
|
|
|
421
424
|
return false;
|
|
422
425
|
}
|
|
423
426
|
try {
|
|
424
|
-
localStorage.setItem(
|
|
427
|
+
localStorage.setItem(
|
|
428
|
+
videoSizeStorageKey,
|
|
429
|
+
JSON.stringify(canvasRecorder.size),
|
|
430
|
+
);
|
|
425
431
|
} catch {
|
|
426
432
|
// Private browsing, or storage is full. The size still works until the page reloads.
|
|
427
433
|
}
|
|
@@ -466,9 +472,12 @@ function updateLocalFilesButton() {
|
|
|
466
472
|
const names = localFilesNeedingPermission();
|
|
467
473
|
localFilesBtn.hidden = names.length === 0;
|
|
468
474
|
localFilesBtn.textContent =
|
|
469
|
-
names.length === 1
|
|
475
|
+
names.length === 1
|
|
476
|
+
? "🔓 Allow local file"
|
|
477
|
+
: `🔓 Allow ${names.length} local files`;
|
|
470
478
|
localFilesBtn.title =
|
|
471
|
-
"The browser needs your OK before it reads these files again:\n" +
|
|
479
|
+
"The browser needs your OK before it reads these files again:\n" +
|
|
480
|
+
names.join("\n");
|
|
472
481
|
}
|
|
473
482
|
onLocalFilesChange(updateLocalFilesButton);
|
|
474
483
|
|
|
@@ -518,8 +527,10 @@ function showFrame(timeInMs: number, live: boolean) {
|
|
|
518
527
|
timeInMs - rootStartMs,
|
|
519
528
|
live && playCheckBox.checked,
|
|
520
529
|
);
|
|
521
|
-
if (live)
|
|
530
|
+
if (live)
|
|
531
|
+
transcriptView?.update(timeInMs - rootStartMs, playCheckBox.checked);
|
|
522
532
|
for (const update of goToButtonUpdaters) update();
|
|
533
|
+
editorPanelsTimeChanged();
|
|
523
534
|
context.reset();
|
|
524
535
|
context.setTransform(mainTransform());
|
|
525
536
|
if (live) {
|
|
@@ -615,8 +626,18 @@ const playPositionRange = getById("playPositionRange", HTMLInputElement);
|
|
|
615
626
|
* This can be a number outside of the normal range of the current section.
|
|
616
627
|
* This, like all user visible number, is measured in seconds. Internal
|
|
617
628
|
* things measure time in milliseconds.
|
|
629
|
+
*
|
|
630
|
+
* It's measured from the start of the Visual Editor's root when
|
|
631
|
+
* {@link playPositionLocal} is checked, otherwise from the start of the video.
|
|
632
|
+
* Read it with {@link playheadInVideoMs} and write it with
|
|
633
|
+
* {@link loadPlayPositionSeconds}, which take care of that.
|
|
618
634
|
*/
|
|
619
635
|
const playPositionSeconds = getById("playPositionSeconds", HTMLInputElement);
|
|
636
|
+
/**
|
|
637
|
+
* Checked: {@link playPositionSeconds} is measured from the start of the
|
|
638
|
+
* Visual Editor's root. Unchecked: from the start of the video.
|
|
639
|
+
*/
|
|
640
|
+
const playPositionLocal = getById("playPositionLocal", HTMLInputElement);
|
|
620
641
|
/**
|
|
621
642
|
* When we get to the end of the section, automatically jump back to the
|
|
622
643
|
* beginning of the section.
|
|
@@ -626,24 +647,54 @@ const repeatRadioButton = querySelector(
|
|
|
626
647
|
HTMLInputElement,
|
|
627
648
|
);
|
|
628
649
|
|
|
650
|
+
/**
|
|
651
|
+
* The playhead, measured from the start of the whole video.
|
|
652
|
+
* {@link playPositionSeconds} is the source of truth.
|
|
653
|
+
*/
|
|
654
|
+
function playheadInVideoMs(): number {
|
|
655
|
+
const shownMs = playPositionSeconds.valueAsNumber * 1000;
|
|
656
|
+
return playPositionLocal.checked ? shownMs + rootStartMs : shownMs;
|
|
657
|
+
}
|
|
658
|
+
|
|
629
659
|
/**
|
|
630
660
|
* The playhead, measured from the start of the Visual Editor's root: the
|
|
631
661
|
* time its keyframes use.
|
|
632
662
|
*/
|
|
633
663
|
function playheadInRootMs(): number {
|
|
634
|
-
return
|
|
664
|
+
return playheadInVideoMs() - rootStartMs;
|
|
635
665
|
}
|
|
636
666
|
|
|
637
667
|
/**
|
|
638
668
|
* Update the input that shows the time as a number.
|
|
639
|
-
* @param timeInMs The time to display in the number control
|
|
669
|
+
* @param timeInMs The time to display in the number control, measured from the start of the
|
|
670
|
+
* video. It's shown from the start of the root instead if {@link playPositionLocal} says so.
|
|
640
671
|
* This is *automatically* converted to seconds and rounded to the nearest ⅒ of a millisecond.
|
|
641
672
|
* We only use milliseconds, not seconds, inside the code.
|
|
642
673
|
*/
|
|
643
674
|
function loadPlayPositionSeconds(timeInMs: number) {
|
|
644
|
-
|
|
675
|
+
const shownMs = playPositionLocal.checked ? timeInMs - rootStartMs : timeInMs;
|
|
676
|
+
playPositionSeconds.value = (shownMs / 1000).toFixed(4);
|
|
645
677
|
}
|
|
646
678
|
|
|
679
|
+
/**
|
|
680
|
+
* Move the Visual Editor's root. The playhead stays where it is in the video, so a local
|
|
681
|
+
* {@link playPositionSeconds} changes to match.
|
|
682
|
+
*/
|
|
683
|
+
function setRootStartMs(ms: number): void {
|
|
684
|
+
if (ms === rootStartMs) return;
|
|
685
|
+
const playheadMs = playheadInVideoMs();
|
|
686
|
+
rootStartMs = ms;
|
|
687
|
+
loadPlayPositionSeconds(playheadMs);
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
playPositionLocal.addEventListener("input", () => {
|
|
691
|
+
// The same time, shown the other way. The number still means what the checkbox used to say.
|
|
692
|
+
const shownMs = playPositionSeconds.valueAsNumber * 1000;
|
|
693
|
+
loadPlayPositionSeconds(
|
|
694
|
+
playPositionLocal.checked ? shownMs : shownMs + rootStartMs,
|
|
695
|
+
);
|
|
696
|
+
});
|
|
697
|
+
|
|
647
698
|
/**
|
|
648
699
|
* Update the range input to show the same time as the number input.
|
|
649
700
|
*
|
|
@@ -653,7 +704,7 @@ function loadPlayPositionSeconds(timeInMs: number) {
|
|
|
653
704
|
* If the user changes the range input, and the value is immediately copied to the number input for use in the program.
|
|
654
705
|
*/
|
|
655
706
|
function loadPlayPositionRange() {
|
|
656
|
-
playPositionRange.valueAsNumber =
|
|
707
|
+
playPositionRange.valueAsNumber = playheadInVideoMs();
|
|
657
708
|
}
|
|
658
709
|
|
|
659
710
|
// The same rate as the decoded files and the voice recorder, whatever the hardware uses.
|
|
@@ -672,7 +723,9 @@ const soundtrack = new Soundtrack({
|
|
|
672
723
|
root: () => toShow,
|
|
673
724
|
// Sound clips on the timeline can now show their waveforms, and the ones
|
|
674
725
|
// that play to the end of their file now know how long that is.
|
|
675
|
-
onDecoded:
|
|
726
|
+
onDecoded: soundFileLoaded,
|
|
727
|
+
// Marked ⚠, on the timeline and on its card. See soundFileProblem().
|
|
728
|
+
onFailed: soundFileLoaded,
|
|
676
729
|
// The new file may be a local one that needs 🔓.
|
|
677
730
|
onNewSource: () => checkVideosLocalFiles(),
|
|
678
731
|
});
|
|
@@ -866,7 +919,7 @@ const animationLoop = new AnimationLoop((_rAFTimeInMs: number) => {
|
|
|
866
919
|
// Pausing is how a voice recording stops, once the video has started.
|
|
867
920
|
if (voiceRecording && !voiceChirping) stopVoiceRecording();
|
|
868
921
|
playPositionSeconds.disabled = false;
|
|
869
|
-
showFrame(
|
|
922
|
+
showFrame(playheadInVideoMs(), true);
|
|
870
923
|
return;
|
|
871
924
|
}
|
|
872
925
|
|
|
@@ -876,7 +929,7 @@ const animationLoop = new AnimationLoop((_rAFTimeInMs: number) => {
|
|
|
876
929
|
if (!audioPlaying && !rafFallbackPlaying) {
|
|
877
930
|
// Not running: first play, after pause/seek, or after repeat.
|
|
878
931
|
// Clips whose file isn't decoded yet join in when it is, so nothing waits for them.
|
|
879
|
-
let startMs =
|
|
932
|
+
let startMs = playheadInVideoMs();
|
|
880
933
|
if (startMs >= sectionEndTime - 0.05) {
|
|
881
934
|
// At the end — jump to the beginning.
|
|
882
935
|
startMs = sectionStartTime;
|
|
@@ -978,10 +1031,7 @@ addEventListener("keypress", (event) => {
|
|
|
978
1031
|
});
|
|
979
1032
|
|
|
980
1033
|
getById("back5s", HTMLButtonElement).addEventListener("click", () => {
|
|
981
|
-
const backMs = Math.max(
|
|
982
|
-
sectionStartTime,
|
|
983
|
-
playPositionSeconds.valueAsNumber * 1000 - 5000,
|
|
984
|
-
);
|
|
1034
|
+
const backMs = Math.max(sectionStartTime, playheadInVideoMs() - 5000);
|
|
985
1035
|
loadPlayPositionSeconds(backMs);
|
|
986
1036
|
loadPlayPositionRange();
|
|
987
1037
|
stopAudio();
|
|
@@ -1037,7 +1087,7 @@ function framesBetween(startMs: number, endMs: number): number {
|
|
|
1037
1087
|
* It stays inside the play limits.
|
|
1038
1088
|
*/
|
|
1039
1089
|
function stepOneFrame(direction: 1 | -1): void {
|
|
1040
|
-
const position = framePosition(
|
|
1090
|
+
const position = framePosition(playheadInVideoMs());
|
|
1041
1091
|
let frame =
|
|
1042
1092
|
direction > 0
|
|
1043
1093
|
? Math.floor(position + FRAME_TOLERANCE) + 1
|
|
@@ -1100,7 +1150,8 @@ const sectionEndRadios = document.querySelectorAll<HTMLInputElement>(
|
|
|
1100
1150
|
);
|
|
1101
1151
|
|
|
1102
1152
|
/** Where the clip being recorded will go. For its block on the timeline. */
|
|
1103
|
-
let liveVoiceClip:
|
|
1153
|
+
let liveVoiceClip:
|
|
1154
|
+
{ readonly owner: Showable; readonly startInOwnerMs: number } | undefined;
|
|
1104
1155
|
|
|
1105
1156
|
recordModeButton.addEventListener("click", async () => {
|
|
1106
1157
|
if (voicePanel) {
|
|
@@ -1221,7 +1272,11 @@ function endVoiceClip(): void {
|
|
|
1221
1272
|
}
|
|
1222
1273
|
|
|
1223
1274
|
/** A clip's file is finished. Put it on the timeline. */
|
|
1224
|
-
function addVoiceClip(
|
|
1275
|
+
function addVoiceClip(
|
|
1276
|
+
owner: Showable,
|
|
1277
|
+
startInOwnerMs: number,
|
|
1278
|
+
recorded: RecordedClip,
|
|
1279
|
+
): void {
|
|
1225
1280
|
// The samples are in memory already. Don't read the file back.
|
|
1226
1281
|
soundtrack.provide(recorded.url, recorded.buffer);
|
|
1227
1282
|
(owner.soundClips ??= []).push({
|
|
@@ -1233,7 +1288,8 @@ function addVoiceClip(owner: Showable, startInOwnerMs: number, recorded: Recorde
|
|
|
1233
1288
|
markDirty();
|
|
1234
1289
|
soundtrack.request();
|
|
1235
1290
|
refreshTimeline();
|
|
1236
|
-
if ((selectedSlideChild ?? currentRoot()) === owner)
|
|
1291
|
+
if ((selectedSlideChild ?? currentRoot()) === owner)
|
|
1292
|
+
updateScheduleEditor(owner);
|
|
1237
1293
|
}
|
|
1238
1294
|
|
|
1239
1295
|
/**
|
|
@@ -1312,6 +1368,13 @@ async function startRecording(
|
|
|
1312
1368
|
],
|
|
1313
1369
|
});
|
|
1314
1370
|
|
|
1371
|
+
// The newest soundtrack, with every file in it decoded. Right after a reload or an
|
|
1372
|
+
// edit, that can take a moment. (After the file picker, which needs the click.)
|
|
1373
|
+
// Before anything is written: a sound that can't be read stops the save here.
|
|
1374
|
+
infoDiv.innerHTML = "Waiting for the sound…";
|
|
1375
|
+
await soundtrack.ready();
|
|
1376
|
+
assertSoundFilesLoaded();
|
|
1377
|
+
|
|
1315
1378
|
const writableStream = await fileHandle.createWritable();
|
|
1316
1379
|
|
|
1317
1380
|
// Set up Mediabunny output (streaming to file)
|
|
@@ -1335,10 +1398,6 @@ async function startRecording(
|
|
|
1335
1398
|
// The file starts where its first frame starts, so the sound starts there too.
|
|
1336
1399
|
const audioStartMs = (firstFrame * 1000) / FPS;
|
|
1337
1400
|
|
|
1338
|
-
// The newest soundtrack, with every file in it decoded. Right after a reload or an
|
|
1339
|
-
// edit, that can take a moment. (After the file picker, which needs the click.)
|
|
1340
|
-
infoDiv.innerHTML = "Waiting for the sound…";
|
|
1341
|
-
await soundtrack.ready();
|
|
1342
1401
|
const audioBuffer = soundtrack
|
|
1343
1402
|
.mix(audioStartMs, Math.min(saveEndMs, toShow.duration))
|
|
1344
1403
|
.getAudioBuffer();
|
|
@@ -1509,7 +1568,12 @@ const saveOkBtn = getById("saveOkBtn", HTMLButtonElement);
|
|
|
1509
1568
|
* HEVC stores color at half resolution (4:2:0), so both numbers must be even.
|
|
1510
1569
|
*/
|
|
1511
1570
|
function saveSizeProblem(width: number, height: number): string | undefined {
|
|
1512
|
-
if (!(
|
|
1571
|
+
if (!(
|
|
1572
|
+
Number.isInteger(width) &&
|
|
1573
|
+
width > 0 &&
|
|
1574
|
+
Number.isInteger(height) &&
|
|
1575
|
+
height > 0
|
|
1576
|
+
)) {
|
|
1513
1577
|
return "The size must be two whole numbers of pixels.";
|
|
1514
1578
|
}
|
|
1515
1579
|
if (width % 2 || height % 2) {
|
|
@@ -1532,7 +1596,7 @@ function updateSaveSizeNote(): void {
|
|
|
1532
1596
|
saveSizeNote.style.color = "#555";
|
|
1533
1597
|
} else {
|
|
1534
1598
|
const stretched =
|
|
1535
|
-
Math.abs(
|
|
1599
|
+
Math.abs(width / height / (pixelWidth / pixelHeight) - 1) > 0.001;
|
|
1536
1600
|
saveSizeNote.textContent = stretched
|
|
1537
1601
|
? `Stretched: the video is ${pixelWidth} × ${pixelHeight}.`
|
|
1538
1602
|
: `${Math.round((width / pixelWidth) * 100)}% of the video's ${pixelWidth} × ${pixelHeight}.`;
|
|
@@ -1572,8 +1636,13 @@ function matchSaveAspect(changed: "width" | "height"): void {
|
|
|
1572
1636
|
|
|
1573
1637
|
saveWidthInput.addEventListener("input", () => matchSaveAspect("width"));
|
|
1574
1638
|
saveHeightInput.addEventListener("input", () => matchSaveAspect("height"));
|
|
1575
|
-
saveKeepAspectCheckbox.addEventListener("input", () =>
|
|
1576
|
-
|
|
1639
|
+
saveKeepAspectCheckbox.addEventListener("input", () =>
|
|
1640
|
+
matchSaveAspect("width"),
|
|
1641
|
+
);
|
|
1642
|
+
getById("saveVideoSizeBtn", HTMLButtonElement).addEventListener(
|
|
1643
|
+
"click",
|
|
1644
|
+
resetSaveSize,
|
|
1645
|
+
);
|
|
1577
1646
|
|
|
1578
1647
|
function formatTimecode(ms: number): string {
|
|
1579
1648
|
const totalFrames = Math.round((ms * FPS) / 1000);
|
|
@@ -1675,9 +1744,13 @@ const saveLocalFilesBtn = getById("saveLocalFilesBtn", HTMLButtonElement);
|
|
|
1675
1744
|
async function saveDialogLocalFilesReady(): Promise<boolean> {
|
|
1676
1745
|
const problems = await checkLocalFiles(localFileUrlsIn(toShow));
|
|
1677
1746
|
saveLocalFilesRow.hidden = problems.length === 0;
|
|
1678
|
-
const needPermission = problems.some(
|
|
1747
|
+
const needPermission = problems.some(
|
|
1748
|
+
(problem) => problem.reason === "permission",
|
|
1749
|
+
);
|
|
1679
1750
|
saveLocalFilesBtn.hidden = !needPermission;
|
|
1680
|
-
saveLocalFilesNote.textContent = problems
|
|
1751
|
+
saveLocalFilesNote.textContent = problems
|
|
1752
|
+
.map((problem) => problem.message)
|
|
1753
|
+
.join(" ");
|
|
1681
1754
|
return problems.length === 0;
|
|
1682
1755
|
}
|
|
1683
1756
|
|
|
@@ -1814,6 +1887,59 @@ function currentRoot(): Showable | undefined {
|
|
|
1814
1887
|
return chapterList[select.selectedIndex]?.selectable;
|
|
1815
1888
|
}
|
|
1816
1889
|
|
|
1890
|
+
// MARK: Chapter paths
|
|
1891
|
+
|
|
1892
|
+
/**
|
|
1893
|
+
* One step down the tree: the child's position among its parent's children, and its name.
|
|
1894
|
+
*
|
|
1895
|
+
* A chapter's row in the `<select>` changes whenever the tree above it changes shape, e.g.
|
|
1896
|
+
* when saved state adds components to an earlier scene. A path of these doesn't.
|
|
1897
|
+
*/
|
|
1898
|
+
type ChapterPathStep = { readonly index: number; readonly name: string };
|
|
1899
|
+
|
|
1900
|
+
/** The name the chapter `<select>` shows. */
|
|
1901
|
+
function chapterName(showable: Showable): string {
|
|
1902
|
+
return showable.userEditableDescription ?? showable.description;
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1905
|
+
/** The way down from the top of the video to this chapter. Find it again with {@link findChapter}. */
|
|
1906
|
+
function chapterPath(info: ShowableTree): ChapterPathStep[] {
|
|
1907
|
+
const path: ChapterPathStep[] = [];
|
|
1908
|
+
for (let step = info; step.parent; step = step.parent) {
|
|
1909
|
+
const child = step.selectable;
|
|
1910
|
+
const index =
|
|
1911
|
+
step.parent.selectable.children?.findIndex((c) => c.child === child) ??
|
|
1912
|
+
-1;
|
|
1913
|
+
path.push({ index, name: chapterName(child) });
|
|
1914
|
+
}
|
|
1915
|
+
return path.reverse();
|
|
1916
|
+
}
|
|
1917
|
+
|
|
1918
|
+
/**
|
|
1919
|
+
* Find a chapter again from its {@link chapterPath}, in a tree that may have changed.
|
|
1920
|
+
*
|
|
1921
|
+
* At each step, the child at the same position if it still has the same name, otherwise the
|
|
1922
|
+
* first sibling with that name. If a step can't be found, the deepest chapter found so far.
|
|
1923
|
+
* @returns An index into {@link chapterList}. 0, the whole video, if nothing matched.
|
|
1924
|
+
*/
|
|
1925
|
+
function findChapter(path: readonly ChapterPathStep[]): number {
|
|
1926
|
+
let current: Showable = toShow;
|
|
1927
|
+
let found = 0;
|
|
1928
|
+
for (const { index, name } of path) {
|
|
1929
|
+
const children = current.children ?? [];
|
|
1930
|
+
const atIndex = children[index]?.child;
|
|
1931
|
+
const next =
|
|
1932
|
+
atIndex && chapterName(atIndex) === name
|
|
1933
|
+
? atIndex
|
|
1934
|
+
: children.find((c) => chapterName(c.child) === name)?.child;
|
|
1935
|
+
if (!next) break;
|
|
1936
|
+
current = next;
|
|
1937
|
+
const position = chapterList.findIndex((d) => d.selectable === next);
|
|
1938
|
+
if (position >= 0) found = position;
|
|
1939
|
+
}
|
|
1940
|
+
return found;
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1817
1943
|
/** When checked, picking another root leaves the play limits alone. */
|
|
1818
1944
|
const keepLimitsCheckbox = getById("keepLimits", HTMLInputElement);
|
|
1819
1945
|
/** Says what the play limits are, below the chapter `<select>`. */
|
|
@@ -1849,6 +1975,8 @@ const visualEditorAPI: VisualEditorAPI = {
|
|
|
1849
1975
|
if (howMuch === "sound") {
|
|
1850
1976
|
soundtrack.request();
|
|
1851
1977
|
} else if (howMuch === "properties") {
|
|
1978
|
+
// A property changed, so it has to be saved, like any other edit.
|
|
1979
|
+
markDirty();
|
|
1852
1980
|
updateScheduleEditor(selectedSlideChild ?? selectable);
|
|
1853
1981
|
} else {
|
|
1854
1982
|
// "structure"
|
|
@@ -2075,6 +2203,124 @@ const timelineWordsMemo = new WeakMap<
|
|
|
2075
2203
|
*/
|
|
2076
2204
|
const scheduleEditorRefreshers: Array<() => void> = [];
|
|
2077
2205
|
|
|
2206
|
+
// MARK: Editor panels
|
|
2207
|
+
|
|
2208
|
+
/** One {@link EditorPanel} shown with the selected component's properties. */
|
|
2209
|
+
type ActivePanel = {
|
|
2210
|
+
readonly panel: EditorPanel;
|
|
2211
|
+
readonly component: Showable;
|
|
2212
|
+
/** What's shown: the panel's element, or an error in its place. */
|
|
2213
|
+
element: HTMLElement;
|
|
2214
|
+
/** False once suspended or broken. Then the panel isn't called again, and its API does nothing. */
|
|
2215
|
+
live: boolean;
|
|
2216
|
+
};
|
|
2217
|
+
|
|
2218
|
+
/**
|
|
2219
|
+
* The panels shown now. Rebuilt by {@link updateScheduleEditor}.
|
|
2220
|
+
* Declared up here because the first schedule editor is built while this module is still loading.
|
|
2221
|
+
*/
|
|
2222
|
+
const activePanels: ActivePanel[] = [];
|
|
2223
|
+
|
|
2224
|
+
/** Where `component` starts, in the Visual Editor's root's time. */
|
|
2225
|
+
function componentStartMs(component: Showable): number {
|
|
2226
|
+
const root = currentRoot();
|
|
2227
|
+
return root ? (startWithin(root, component) ?? 0) : 0;
|
|
2228
|
+
}
|
|
2229
|
+
|
|
2230
|
+
/** The playhead in `component`'s own time: what its `show()` gets as `timeInMs`. */
|
|
2231
|
+
function componentTimeMs(component: Showable): number {
|
|
2232
|
+
return playheadInRootMs() - componentStartMs(component);
|
|
2233
|
+
}
|
|
2234
|
+
|
|
2235
|
+
/** Show `reason` where `active`'s panel was, and stop calling that panel. */
|
|
2236
|
+
function panelFailed(active: ActivePanel, reason: unknown): void {
|
|
2237
|
+
console.error(reason);
|
|
2238
|
+
active.live = false;
|
|
2239
|
+
const name =
|
|
2240
|
+
active.component.userEditableDescription ?? active.component.description;
|
|
2241
|
+
const line = document.createElement("div");
|
|
2242
|
+
line.style.cssText = "color:#b00;margin-bottom:0.4em";
|
|
2243
|
+
line.textContent = `✗ A panel for "${name}" failed: ${String(reason)}`;
|
|
2244
|
+
active.element.replaceWith(line);
|
|
2245
|
+
active.element = line;
|
|
2246
|
+
}
|
|
2247
|
+
|
|
2248
|
+
/** Call into a panel, unless it's suspended or broken. A bug in a panel mustn't break the editor. */
|
|
2249
|
+
function callPanel(
|
|
2250
|
+
active: ActivePanel,
|
|
2251
|
+
call: (panel: EditorPanel) => void,
|
|
2252
|
+
): void {
|
|
2253
|
+
if (!active.live) return;
|
|
2254
|
+
try {
|
|
2255
|
+
call(active.panel);
|
|
2256
|
+
} catch (reason) {
|
|
2257
|
+
panelFailed(active, reason);
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
|
|
2261
|
+
/** Tell each panel it's going away. Called before every rebuild. */
|
|
2262
|
+
function suspendEditorPanels(): void {
|
|
2263
|
+
for (const active of activePanels.splice(0)) {
|
|
2264
|
+
callPanel(active, (panel) => panel.suspend?.());
|
|
2265
|
+
active.live = false;
|
|
2266
|
+
}
|
|
2267
|
+
}
|
|
2268
|
+
|
|
2269
|
+
/**
|
|
2270
|
+
* Start `component`'s panels: its own {@link Showable.editorPanel}, then the project's,
|
|
2271
|
+
* from `canvasRecorder.addEditorPanel()`.
|
|
2272
|
+
* @returns The elements to show, in order.
|
|
2273
|
+
*/
|
|
2274
|
+
function startEditorPanels(component: Showable): HTMLElement[] {
|
|
2275
|
+
return canvasRecorder.editorPanelsFor(component).map((panel) => {
|
|
2276
|
+
const active: ActivePanel = {
|
|
2277
|
+
panel,
|
|
2278
|
+
component,
|
|
2279
|
+
element: document.createElement("div"),
|
|
2280
|
+
live: true,
|
|
2281
|
+
};
|
|
2282
|
+
activePanels.push(active);
|
|
2283
|
+
const api: EditorPanelAPI = {
|
|
2284
|
+
getTimeMs: () => componentTimeMs(component),
|
|
2285
|
+
seek(ms) {
|
|
2286
|
+
if (!active.live) return;
|
|
2287
|
+
visualEditorAPI.seek(ms + componentStartMs(component));
|
|
2288
|
+
},
|
|
2289
|
+
propertyChanged(property) {
|
|
2290
|
+
if (!active.live) return;
|
|
2291
|
+
activeRootComponentEditor?.update(component, property);
|
|
2292
|
+
markDirty();
|
|
2293
|
+
// Rebuild so the tables show the new value. That restarts this panel too.
|
|
2294
|
+
updateScheduleEditor(component);
|
|
2295
|
+
},
|
|
2296
|
+
refreshGUI(howMuch) {
|
|
2297
|
+
if (!active.live) return;
|
|
2298
|
+
visualEditorAPI.refreshGUI(howMuch);
|
|
2299
|
+
},
|
|
2300
|
+
};
|
|
2301
|
+
callPanel(active, (panel) => {
|
|
2302
|
+
const element = panel.start(api);
|
|
2303
|
+
if (!(element instanceof HTMLElement)) {
|
|
2304
|
+
throw new Error("start() didn't return an HTMLElement.");
|
|
2305
|
+
}
|
|
2306
|
+
active.element = element;
|
|
2307
|
+
});
|
|
2308
|
+
// Every keystroke in the properties, and every duration change.
|
|
2309
|
+
scheduleEditorRefreshers.push(() =>
|
|
2310
|
+
callPanel(active, (panel) => panel.update?.()),
|
|
2311
|
+
);
|
|
2312
|
+
return active.element;
|
|
2313
|
+
});
|
|
2314
|
+
}
|
|
2315
|
+
|
|
2316
|
+
/** The playhead moved. Called from {@link showFrame}. */
|
|
2317
|
+
function editorPanelsTimeChanged(): void {
|
|
2318
|
+
// A copy: a panel's call may rebuild the list.
|
|
2319
|
+
for (const active of [...activePanels]) {
|
|
2320
|
+
callPanel(active, (panel) => panel.timeChanged?.());
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
|
|
2078
2324
|
/**
|
|
2079
2325
|
* The schedules the user switched to **Durations**, as opposed to the
|
|
2080
2326
|
* default, **Times**. See {@link buildScheduleSection}.
|
|
@@ -2218,7 +2464,7 @@ function applyLimits(): void {
|
|
|
2218
2464
|
*/
|
|
2219
2465
|
function updateFromSelect() {
|
|
2220
2466
|
const info = chapterList[select.selectedIndex];
|
|
2221
|
-
|
|
2467
|
+
setRootStartMs(info.start);
|
|
2222
2468
|
if (keepLimitsCheckbox.checked && limitsShowable) {
|
|
2223
2469
|
// Only the "Play this one" button changes. Playback carries on.
|
|
2224
2470
|
applyLimits();
|
|
@@ -2265,7 +2511,7 @@ playRootBtn.addEventListener("click", () => {
|
|
|
2265
2511
|
*/
|
|
2266
2512
|
function refreshChapters(): void {
|
|
2267
2513
|
if (initChapters()) {
|
|
2268
|
-
|
|
2514
|
+
setRootStartMs(chapterList[select.selectedIndex].start);
|
|
2269
2515
|
applyLimits();
|
|
2270
2516
|
// The range clamped itself to the new bounds; show the real position again. The
|
|
2271
2517
|
// number input stays the source of truth, so a playhead past a shortened end is left
|
|
@@ -2323,8 +2569,11 @@ transcriptView = new TranscriptView({
|
|
|
2323
2569
|
transcript(source) {
|
|
2324
2570
|
const status = transcriptStatus(source);
|
|
2325
2571
|
if (!status) return undefined;
|
|
2326
|
-
return status.kind === "ready"
|
|
2572
|
+
return status.kind === "ready"
|
|
2573
|
+
? status.transcript
|
|
2574
|
+
: (statusText(status) ?? "");
|
|
2327
2575
|
},
|
|
2576
|
+
problem: (clip) => soundFileProblem(clip),
|
|
2328
2577
|
seek: (rootMs) => timelineDisplay.onSeek?.(rootMs),
|
|
2329
2578
|
selectClip: (clip) => timelineDisplay.onBlockClick?.(clip),
|
|
2330
2579
|
selectedClip: () => selectedSoundClip,
|
|
@@ -2400,6 +2649,7 @@ timelineDisplay.onBlockClick = (id) => {
|
|
|
2400
2649
|
updateComponentEditor(container);
|
|
2401
2650
|
updateScheduleEditor(child);
|
|
2402
2651
|
timelineDisplay.setSelectedId(child);
|
|
2652
|
+
activeRootComponentEditor?.selectionChanged(child);
|
|
2403
2653
|
return true;
|
|
2404
2654
|
}
|
|
2405
2655
|
if (child.children?.length && findIn(child.children, child)) return true;
|
|
@@ -2427,6 +2677,40 @@ function _onClipValueChanged(): void {
|
|
|
2427
2677
|
/** Shortest a sound clip can be trimmed to by dragging, in ms. */
|
|
2428
2678
|
const MIN_SOUND_CLIP_MS = 50;
|
|
2429
2679
|
|
|
2680
|
+
/** A sound file was decoded, or failed: update the timeline and the Sound Clips cards. */
|
|
2681
|
+
function soundFileLoaded(): void {
|
|
2682
|
+
timelineDisplay.redraw();
|
|
2683
|
+
for (const cb of soundClipSyncCallbacks) cb();
|
|
2684
|
+
}
|
|
2685
|
+
|
|
2686
|
+
/**
|
|
2687
|
+
* Why `clip`'s file can't be played, or undefined if nothing is wrong, as far as we know yet.
|
|
2688
|
+
* Shown on the timeline, on the clip's card and in the 📖 Text view. A missing file must not
|
|
2689
|
+
* look like a file full of silence, even when its old transcript still shows.
|
|
2690
|
+
*/
|
|
2691
|
+
function soundFileProblem(clip: SoundClip): string | undefined {
|
|
2692
|
+
const reason = soundtrack.failure(clip.source);
|
|
2693
|
+
if (reason === undefined) return undefined;
|
|
2694
|
+
return reason instanceof Error ? reason.message : String(reason);
|
|
2695
|
+
}
|
|
2696
|
+
|
|
2697
|
+
/** Stop a save, if any sound in it can't be read. Otherwise the saved sound would have holes. */
|
|
2698
|
+
function assertSoundFilesLoaded(): void {
|
|
2699
|
+
const failed = soundtrack.failures();
|
|
2700
|
+
if (failed.length === 0) return;
|
|
2701
|
+
const { url, reason } = failed[0]!;
|
|
2702
|
+
const why = (
|
|
2703
|
+
reason instanceof Error ? reason.message : String(reason)
|
|
2704
|
+
).replace(/([^.!?)])$/, "$1.");
|
|
2705
|
+
const which =
|
|
2706
|
+
failed.length === 1
|
|
2707
|
+
? ""
|
|
2708
|
+
: `${failed.length} sound files couldn't be read. The first: `;
|
|
2709
|
+
throw new Error(
|
|
2710
|
+
`${which}Can't play "${url}": ${why} Each clip that uses ${failed.length === 1 ? "it" : "one"} is marked ⚠ on the timeline.`,
|
|
2711
|
+
);
|
|
2712
|
+
}
|
|
2713
|
+
|
|
2430
2714
|
/** How long the file `clip` plays from is, once it has been decoded. */
|
|
2431
2715
|
function soundFileMs(clip: SoundClip): number | undefined {
|
|
2432
2716
|
const buffer = soundtrack.getDecodedBuffer(clip.source);
|
|
@@ -2511,11 +2795,15 @@ function soundClipBlock(clip: SoundClip, ownerStart: number): TimelineBlock {
|
|
|
2511
2795
|
return {
|
|
2512
2796
|
id: clip,
|
|
2513
2797
|
get label() {
|
|
2798
|
+
const problem = soundFileProblem(clip);
|
|
2799
|
+
if (problem !== undefined) return `⚠ ${problem}`;
|
|
2514
2800
|
// Notes if there are any, or else the first few words, so clips can be
|
|
2515
2801
|
// told apart even zoomed out.
|
|
2516
2802
|
return clip.notes || clipText(clip, 6) || clip.source || "—";
|
|
2517
2803
|
},
|
|
2518
|
-
color
|
|
2804
|
+
get color() {
|
|
2805
|
+
return soundFileProblem(clip) === undefined ? "#3aab3a" : "#9a3412";
|
|
2806
|
+
},
|
|
2519
2807
|
lane: "sound",
|
|
2520
2808
|
transcript: () => {
|
|
2521
2809
|
// Asking is what queues the file for transcribing.
|
|
@@ -2725,24 +3013,103 @@ function _updateTimeline(selectable: Showable): void {
|
|
|
2725
3013
|
timelineDisplay.setSelectedId(selectedSlideChild ?? undefined);
|
|
2726
3014
|
}
|
|
2727
3015
|
|
|
3016
|
+
/**
|
|
3017
|
+
* Where the user was in the video: the chapter, the play limits, the playhead, and whether
|
|
3018
|
+
* it was playing. {@link saveState} keeps it across a reload.
|
|
3019
|
+
*
|
|
3020
|
+
* Which chapters exist, and where they start, depends on the saved tree, and that's restored
|
|
3021
|
+
* asynchronously, by `initFromDB()`. So this is put back after that, by {@link restorePlace}.
|
|
3022
|
+
*/
|
|
3023
|
+
type SavedPlace = {
|
|
3024
|
+
readonly rootPath: readonly ChapterPathStep[];
|
|
3025
|
+
readonly keepLimits: boolean;
|
|
3026
|
+
readonly limitsPath: readonly ChapterPathStep[] | null;
|
|
3027
|
+
/** From the start of the root, so it stays put if an earlier chapter changes length. null for an empty field. */
|
|
3028
|
+
readonly timeInRootMs: number | null;
|
|
3029
|
+
/** The "on section end" radio button's value. */
|
|
3030
|
+
readonly onSectionEnd: string;
|
|
3031
|
+
readonly wasPlaying: boolean;
|
|
3032
|
+
};
|
|
3033
|
+
|
|
3034
|
+
/**
|
|
3035
|
+
* Read from the last session, waiting for the saved tree to load. If the page unloads
|
|
3036
|
+
* first, {@link saveState} saves this again, not the default place the page is showing.
|
|
3037
|
+
*/
|
|
3038
|
+
let placeToRestore: SavedPlace | undefined;
|
|
3039
|
+
|
|
3040
|
+
function currentPlace(): SavedPlace {
|
|
3041
|
+
const root = chapterList[select.selectedIndex];
|
|
3042
|
+
const limits = chapterList.find((d) => d.selectable === limitsShowable);
|
|
3043
|
+
const timeInRootMs = playheadInRootMs();
|
|
3044
|
+
return {
|
|
3045
|
+
rootPath: root ? chapterPath(root) : [],
|
|
3046
|
+
keepLimits: keepLimitsCheckbox.checked,
|
|
3047
|
+
limitsPath: limits ? chapterPath(limits) : null,
|
|
3048
|
+
timeInRootMs: isFinite(timeInRootMs) ? timeInRootMs : null,
|
|
3049
|
+
onSectionEnd: querySelector(
|
|
3050
|
+
'input[name="onSectionEnd"]:checked',
|
|
3051
|
+
HTMLInputElement,
|
|
3052
|
+
).value,
|
|
3053
|
+
wasPlaying: playCheckBox.checked,
|
|
3054
|
+
};
|
|
3055
|
+
}
|
|
3056
|
+
|
|
3057
|
+
/** Parse what {@link saveState} wrote. undefined if there's nothing, or it's from an older version. */
|
|
3058
|
+
function parseSavedPlace(json: string | null): SavedPlace | undefined {
|
|
3059
|
+
if (!json) return undefined;
|
|
3060
|
+
try {
|
|
3061
|
+
const place = JSON.parse(json) as SavedPlace;
|
|
3062
|
+
return Array.isArray(place?.rootPath) ? place : undefined;
|
|
3063
|
+
} catch {
|
|
3064
|
+
return undefined;
|
|
3065
|
+
}
|
|
3066
|
+
}
|
|
3067
|
+
|
|
3068
|
+
/**
|
|
3069
|
+
* Go back to the place saved by the last session, in the tree as it is now.
|
|
3070
|
+
* Call this after the saved tree is restored.
|
|
3071
|
+
*/
|
|
3072
|
+
function restorePlace(place: SavedPlace): void {
|
|
3073
|
+
// The saved tree can change which chapters exist, and where they start.
|
|
3074
|
+
initChapters();
|
|
3075
|
+
select.selectedIndex = findChapter(place.rootPath);
|
|
3076
|
+
updateFromSelect();
|
|
3077
|
+
if (place.keepLimits) {
|
|
3078
|
+
keepLimitsCheckbox.checked = true;
|
|
3079
|
+
if (place.limitsPath) {
|
|
3080
|
+
limitsShowable = chapterList[findChapter(place.limitsPath)].selectable;
|
|
3081
|
+
applyLimits();
|
|
3082
|
+
}
|
|
3083
|
+
}
|
|
3084
|
+
if (place.timeInRootMs !== null) {
|
|
3085
|
+
const savedMs = rootStartMs + place.timeInRootMs;
|
|
3086
|
+
loadPlayPositionSeconds(
|
|
3087
|
+
Math.max(sectionStartTime, Math.min(sectionEndTime, savedMs)),
|
|
3088
|
+
);
|
|
3089
|
+
}
|
|
3090
|
+
loadPlayPositionRange();
|
|
3091
|
+
// "continue" was removed. A page saved with it pauses instead.
|
|
3092
|
+
const onEnd = document.querySelector<HTMLInputElement>(
|
|
3093
|
+
`input[name="onSectionEnd"][value="${place.onSectionEnd}"]`,
|
|
3094
|
+
);
|
|
3095
|
+
if (onEnd) onEnd.checked = true;
|
|
3096
|
+
if (place.wasPlaying) playCheckBox.checked = true;
|
|
3097
|
+
}
|
|
3098
|
+
|
|
2728
3099
|
/**
|
|
2729
3100
|
* When someone hits refresh in their browser,
|
|
2730
3101
|
* or hits save in vs code so vite causes a refresh,
|
|
2731
3102
|
* restart the user with the same gui settings.
|
|
2732
3103
|
*/
|
|
2733
3104
|
function saveState() {
|
|
2734
|
-
sessionStorage.setItem("index", select.selectedIndex.toString());
|
|
2735
|
-
sessionStorage.setItem("keepLimits", keepLimitsCheckbox.checked ? "1" : "0");
|
|
2736
3105
|
sessionStorage.setItem(
|
|
2737
|
-
"
|
|
2738
|
-
|
|
3106
|
+
"place",
|
|
3107
|
+
JSON.stringify(placeToRestore ?? currentPlace()),
|
|
2739
3108
|
);
|
|
2740
|
-
sessionStorage.setItem("timeInSeconds", playPositionSeconds.value);
|
|
2741
3109
|
sessionStorage.setItem(
|
|
2742
|
-
"
|
|
2743
|
-
|
|
3110
|
+
"playPositionLocal",
|
|
3111
|
+
playPositionLocal.checked ? "1" : "0",
|
|
2744
3112
|
);
|
|
2745
|
-
sessionStorage.setItem("wasPlaying", playCheckBox.checked ? "1" : "0");
|
|
2746
3113
|
sessionStorage.setItem("zoomSelect", zoomSelect.value);
|
|
2747
3114
|
sessionStorage.setItem("panX", panX.toString());
|
|
2748
3115
|
sessionStorage.setItem("panY", panY.toString());
|
|
@@ -2839,7 +3206,8 @@ function openScheduleDB(): Promise<IDBDatabase> {
|
|
|
2839
3206
|
// Versions 1–3 had a per-chapter "history" store. "videos" replaced it in v3, and v4
|
|
2840
3207
|
// removes it. Also drop the directory handle left behind by the temporary
|
|
2841
3208
|
// "Save All 3" button. See development-plans/single-tree-per-video.md.
|
|
2842
|
-
if (db.objectStoreNames.contains("history"))
|
|
3209
|
+
if (db.objectStoreNames.contains("history"))
|
|
3210
|
+
db.deleteObjectStore("history");
|
|
2843
3211
|
if (oldVersion < 4)
|
|
2844
3212
|
req.transaction!.objectStore("files").delete("__properties-dir__");
|
|
2845
3213
|
};
|
|
@@ -3039,7 +3407,11 @@ const jsonSync = new SyncedFile({
|
|
|
3039
3407
|
if (enabled) {
|
|
3040
3408
|
// Only one file per video is synced (and so "active") at a time.
|
|
3041
3409
|
for (const r of getAllReq.result as FileRecord[]) {
|
|
3042
|
-
if (
|
|
3410
|
+
if (
|
|
3411
|
+
r.videoKey === toShowKey &&
|
|
3412
|
+
r.filename !== filename &&
|
|
3413
|
+
r.isActive
|
|
3414
|
+
)
|
|
3043
3415
|
store.put({ ...r, isActive: false, syncEnabled: false });
|
|
3044
3416
|
}
|
|
3045
3417
|
}
|
|
@@ -3146,7 +3518,10 @@ function classDefaults(cls: new () => Showable): ClassDefaults {
|
|
|
3146
3518
|
schedules: serializeSchedules(instance.schedules ?? []),
|
|
3147
3519
|
scalars: serializeScalars(instance.scalars ?? []),
|
|
3148
3520
|
duration: instance.duration,
|
|
3149
|
-
schedulePropertyNames: propertyNamesOf(
|
|
3521
|
+
schedulePropertyNames: propertyNamesOf(
|
|
3522
|
+
instance,
|
|
3523
|
+
instance.schedules ?? [],
|
|
3524
|
+
),
|
|
3150
3525
|
scalarPropertyNames: propertyNamesOf(instance, instance.scalars ?? []),
|
|
3151
3526
|
soundClips: instance.soundClips,
|
|
3152
3527
|
};
|
|
@@ -3273,7 +3648,8 @@ function buildDiffText(): string {
|
|
|
3273
3648
|
} else {
|
|
3274
3649
|
// The live object's class, so the properties below type-check.
|
|
3275
3650
|
const className = comp.constructor.name;
|
|
3276
|
-
const cast =
|
|
3651
|
+
const cast =
|
|
3652
|
+
className && className !== "Object" ? ` as ${className}` : "";
|
|
3277
3653
|
out.push(
|
|
3278
3654
|
`${indent}// No howToGenerate for "${rk}", so this makes one the way the Visual Editor does.`,
|
|
3279
3655
|
`${indent}const ${varName} = componentRegistry.get(${JSON.stringify(rk)})!.create()${cast};`,
|
|
@@ -3321,16 +3697,15 @@ function buildDiffText(): string {
|
|
|
3321
3697
|
|
|
3322
3698
|
if (
|
|
3323
3699
|
(comp.soundClips?.length || def.soundClips?.length) &&
|
|
3324
|
-
JSON.stringify(comp.soundClips ?? []) !==
|
|
3700
|
+
JSON.stringify(comp.soundClips ?? []) !==
|
|
3701
|
+
JSON.stringify(def.soundClips ?? [])
|
|
3325
3702
|
) {
|
|
3326
3703
|
out.push(
|
|
3327
3704
|
`${indent}${varName}.soundClips = ${JSON.stringify(comp.soundClips ?? [])};`,
|
|
3328
3705
|
);
|
|
3329
3706
|
}
|
|
3330
3707
|
|
|
3331
|
-
out.push(
|
|
3332
|
-
`${indent}${parentExpr}.replaceableComponents!.push(${varName});`,
|
|
3333
|
-
);
|
|
3708
|
+
out.push(`${indent}${parentExpr}.replaceableComponents!.push(${varName});`);
|
|
3334
3709
|
|
|
3335
3710
|
return out;
|
|
3336
3711
|
}
|
|
@@ -3504,7 +3879,10 @@ function buildDiffText(): string {
|
|
|
3504
3879
|
diffProperties(d, comp, childPath);
|
|
3505
3880
|
diffReplaceable(d.components ?? [], comp, childPath);
|
|
3506
3881
|
} else {
|
|
3507
|
-
printPathIfNeeded([
|
|
3882
|
+
printPathIfNeeded([
|
|
3883
|
+
...path,
|
|
3884
|
+
d.userEditableDescription ?? d.registryKey,
|
|
3885
|
+
]);
|
|
3508
3886
|
lines.push(` [deleted]`);
|
|
3509
3887
|
}
|
|
3510
3888
|
}
|
|
@@ -3547,7 +3925,6 @@ function buildDiffText(): string {
|
|
|
3547
3925
|
}
|
|
3548
3926
|
}
|
|
3549
3927
|
|
|
3550
|
-
|
|
3551
3928
|
// One tree, so one walk: diffNode() recurses through fixedComponents on its own.
|
|
3552
3929
|
if (tsDefaultsTree) {
|
|
3553
3930
|
diffNode(tsDefaultsTree, toShow, [toShow.description]);
|
|
@@ -3785,7 +4162,6 @@ function afterStateApplied(): void {
|
|
|
3785
4162
|
soundtrack.request();
|
|
3786
4163
|
}
|
|
3787
4164
|
|
|
3788
|
-
|
|
3789
4165
|
/** Saves current schedule state to IndexedDB as a full data entry.
|
|
3790
4166
|
* Pass force=true (💾 Save button) to bypass the ts-defaults-no-auto-save guard. */
|
|
3791
4167
|
/**
|
|
@@ -3820,8 +4196,7 @@ async function saveVideoStateToDb(force: boolean): Promise<void> {
|
|
|
3820
4196
|
|
|
3821
4197
|
// Nothing changed since the last data entry -- don't add a duplicate.
|
|
3822
4198
|
const last = entries.findLast((e) => !isMarker(e)) as
|
|
3823
|
-
|
|
|
3824
|
-
| undefined;
|
|
4199
|
+
VideoDataEntry | undefined;
|
|
3825
4200
|
if (last && JSON.stringify(last.tree) === newJson) return;
|
|
3826
4201
|
|
|
3827
4202
|
const entry: VideoDataEntry = { timestamp: Date.now(), tree };
|
|
@@ -4387,7 +4762,7 @@ function buildScheduleSection(
|
|
|
4387
4762
|
}
|
|
4388
4763
|
|
|
4389
4764
|
function currentTimeMs() {
|
|
4390
|
-
return
|
|
4765
|
+
return playheadInVideoMs();
|
|
4391
4766
|
}
|
|
4392
4767
|
|
|
4393
4768
|
/**
|
|
@@ -4724,8 +5099,10 @@ function buildScheduleSection(
|
|
|
4724
5099
|
} else {
|
|
4725
5100
|
const none = document.createElement("span");
|
|
4726
5101
|
none.textContent = "—";
|
|
4727
|
-
none.title =
|
|
4728
|
-
|
|
5102
|
+
none.title =
|
|
5103
|
+
"The last keyframe has no duration: nothing comes after it.";
|
|
5104
|
+
none.style.cssText =
|
|
5105
|
+
"display:inline-block;width:6em;text-align:center;color:#888";
|
|
4729
5106
|
cell.append(none);
|
|
4730
5107
|
}
|
|
4731
5108
|
const atLabel = document.createElement("span");
|
|
@@ -4976,8 +5353,9 @@ function buildScheduleSection(
|
|
|
4976
5353
|
"cellWidth",
|
|
4977
5354
|
"cellHeight",
|
|
4978
5355
|
] as const;
|
|
4979
|
-
const fieldInputs: Partial<
|
|
4980
|
-
|
|
5356
|
+
const fieldInputs: Partial<
|
|
5357
|
+
Record<(typeof fields)[number], HTMLInputElement>
|
|
5358
|
+
> = {};
|
|
4981
5359
|
for (const field of fields) {
|
|
4982
5360
|
const input = buildNumericInput(latKf.value[field], (n) => {
|
|
4983
5361
|
latKf.value = { ...latKf.value, [field]: n };
|
|
@@ -5410,7 +5788,11 @@ function updateComponentEditor(selectable: Showable) {
|
|
|
5410
5788
|
if (i !== -1) arr.splice(i, 1);
|
|
5411
5789
|
replaceables.replace(arr);
|
|
5412
5790
|
if (childStart !== undefined) {
|
|
5413
|
-
playheadAfterRemoving(
|
|
5791
|
+
playheadAfterRemoving(
|
|
5792
|
+
childStart,
|
|
5793
|
+
childStart + childDuration,
|
|
5794
|
+
chainEndMs,
|
|
5795
|
+
);
|
|
5414
5796
|
}
|
|
5415
5797
|
if (selectedSlideChild === child) {
|
|
5416
5798
|
selectedSlideChild = null;
|
|
@@ -5518,7 +5900,8 @@ function updateComponentEditor(selectable: Showable) {
|
|
|
5518
5900
|
: selectedSlideChild.replaceableComponents !== undefined
|
|
5519
5901
|
? selectedSlideChild
|
|
5520
5902
|
: null;
|
|
5521
|
-
const displayName = (s: Showable) =>
|
|
5903
|
+
const displayName = (s: Showable) =>
|
|
5904
|
+
s.userEditableDescription ?? s.description;
|
|
5522
5905
|
|
|
5523
5906
|
const toolbar = document.createElement("div");
|
|
5524
5907
|
toolbar.className = "components-toolbar";
|
|
@@ -5663,13 +6046,14 @@ function buildSoundClipSection(selectable: Showable): HTMLElement {
|
|
|
5663
6046
|
const header = document.createElement("div");
|
|
5664
6047
|
header.style.cssText =
|
|
5665
6048
|
"display:flex;align-items:center;gap:0.4em;margin-bottom:0.3em;font-size:0.85em;color:#555";
|
|
5666
|
-
header.textContent =
|
|
5667
|
-
|
|
5668
|
-
|
|
6049
|
+
header.textContent =
|
|
6050
|
+
"Times are in ms, measured from the start of this component.";
|
|
6051
|
+
const playheadInOwner = () => tidyMs(playheadInVideoMs() - selfStartMs);
|
|
5669
6052
|
const addBtn = document.createElement("button");
|
|
5670
6053
|
addBtn.type = "button";
|
|
5671
6054
|
addBtn.textContent = "+ Add";
|
|
5672
|
-
addBtn.title =
|
|
6055
|
+
addBtn.title =
|
|
6056
|
+
"Add an empty sound clip at the playhead. Then fill in its source.";
|
|
5673
6057
|
addBtn.style.marginLeft = "auto";
|
|
5674
6058
|
addBtn.addEventListener("click", () => {
|
|
5675
6059
|
const clip: SoundClip = { source: "", startMsIntoScene: playheadInOwner() };
|
|
@@ -5694,7 +6078,9 @@ function buildSoundClipSection(selectable: Showable): HTMLElement {
|
|
|
5694
6078
|
}
|
|
5695
6079
|
const pasted = parseSoundClips(text);
|
|
5696
6080
|
if (pasted.length === 0) {
|
|
5697
|
-
alert(
|
|
6081
|
+
alert(
|
|
6082
|
+
"No sound clips found on the clipboard. Each one needs at least a source.",
|
|
6083
|
+
);
|
|
5698
6084
|
return;
|
|
5699
6085
|
}
|
|
5700
6086
|
ensureList();
|
|
@@ -5887,6 +6273,18 @@ function buildSoundClipSection(selectable: Showable): HTMLElement {
|
|
|
5887
6273
|
});
|
|
5888
6274
|
row2.append(srcLabel, sourceInput);
|
|
5889
6275
|
|
|
6276
|
+
// Why the file can't be played, if it can't.
|
|
6277
|
+
const problemLine = document.createElement("div");
|
|
6278
|
+
problemLine.style.cssText =
|
|
6279
|
+
"margin-top:0.2em;font-size:0.85em;color:#b00020";
|
|
6280
|
+
const showProblem = () => {
|
|
6281
|
+
const problem = soundFileProblem(clip);
|
|
6282
|
+
problemLine.hidden = problem === undefined;
|
|
6283
|
+
problemLine.textContent = `⚠ ${problem}`;
|
|
6284
|
+
};
|
|
6285
|
+
showProblem();
|
|
6286
|
+
soundClipSyncCallbacks.push(showProblem);
|
|
6287
|
+
|
|
5890
6288
|
// Row 3: numeric time fields
|
|
5891
6289
|
const row3 = document.createElement("div");
|
|
5892
6290
|
row3.style.cssText =
|
|
@@ -5969,7 +6367,8 @@ function buildSoundClipSection(selectable: Showable): HTMLElement {
|
|
|
5969
6367
|
row4.style.cssText =
|
|
5970
6368
|
"display:flex;gap:0.4em;align-items:center;margin-top:0.2em;flex-wrap:wrap;font-size:0.85em";
|
|
5971
6369
|
const ownerLabel = document.createElement("label");
|
|
5972
|
-
ownerLabel.style.cssText =
|
|
6370
|
+
ownerLabel.style.cssText =
|
|
6371
|
+
"display:flex;align-items:center;gap:0.2em;min-width:0;flex:1";
|
|
5973
6372
|
ownerLabel.textContent = "owner:";
|
|
5974
6373
|
ownerLabel.title =
|
|
5975
6374
|
"Which component this sound belongs to. It moves when its owner moves. " +
|
|
@@ -6020,7 +6419,7 @@ function buildSoundClipSection(selectable: Showable): HTMLElement {
|
|
|
6020
6419
|
soundClipSyncCallbacks.push(drawPlaysAt);
|
|
6021
6420
|
row4.append(ownerLabel, playsAt);
|
|
6022
6421
|
|
|
6023
|
-
card.append(row1, row2, row3, row4);
|
|
6422
|
+
card.append(row1, row2, problemLine, row3, row4);
|
|
6024
6423
|
section.append(card);
|
|
6025
6424
|
if (clip === selectedSoundClip) {
|
|
6026
6425
|
requestAnimationFrame(() => card.scrollIntoView({ block: "nearest" }));
|
|
@@ -6075,6 +6474,7 @@ function buildNameSection(selectable: Showable): HTMLElement {
|
|
|
6075
6474
|
}
|
|
6076
6475
|
|
|
6077
6476
|
function updateScheduleEditor(selectable: Showable) {
|
|
6477
|
+
suspendEditorPanels();
|
|
6078
6478
|
scheduleEditorFieldset.replaceChildren();
|
|
6079
6479
|
editingRectKf = null;
|
|
6080
6480
|
viewingRectKfs.clear();
|
|
@@ -6098,7 +6498,10 @@ function updateScheduleEditor(selectable: Showable) {
|
|
|
6098
6498
|
soundClipSyncCallbacks.length = 0;
|
|
6099
6499
|
rectAspectLock = null;
|
|
6100
6500
|
// A highlighted sound clip stays highlighted only while its owner is selected.
|
|
6101
|
-
if (
|
|
6501
|
+
if (
|
|
6502
|
+
selectedSoundClip &&
|
|
6503
|
+
!selectable.soundClips?.includes(selectedSoundClip)
|
|
6504
|
+
) {
|
|
6102
6505
|
selectedSoundClip = undefined;
|
|
6103
6506
|
}
|
|
6104
6507
|
timelineDisplay.setSelectedSoundId(selectedSoundClip);
|
|
@@ -6218,13 +6621,12 @@ function updateScheduleEditor(selectable: Showable) {
|
|
|
6218
6621
|
}
|
|
6219
6622
|
if (selectable instanceof HandwritingEffectComponent) {
|
|
6220
6623
|
const handwritingPanel = buildHandwritingPanel(selectable, {
|
|
6221
|
-
localTimeMs
|
|
6222
|
-
const root = currentRoot();
|
|
6223
|
-
const ownerStart = root ? (startWithin(root, owner) ?? 0) : 0;
|
|
6224
|
-
return playheadInRootMs() - ownerStart;
|
|
6225
|
-
},
|
|
6624
|
+
localTimeMs: componentTimeMs,
|
|
6226
6625
|
progressChanged() {
|
|
6227
|
-
activeRootComponentEditor?.update(
|
|
6626
|
+
activeRootComponentEditor?.update(
|
|
6627
|
+
selectable,
|
|
6628
|
+
selectable.progressSchedule,
|
|
6629
|
+
);
|
|
6228
6630
|
markDirty();
|
|
6229
6631
|
// Rebuild so the Progress table shows the new keyframes.
|
|
6230
6632
|
updateScheduleEditor(selectable);
|
|
@@ -6234,6 +6636,9 @@ function updateScheduleEditor(selectable: Showable) {
|
|
|
6234
6636
|
// Every keystroke in Divisions or Progress updates the status.
|
|
6235
6637
|
scheduleEditorRefreshers.push(handwritingPanel.refresh);
|
|
6236
6638
|
}
|
|
6639
|
+
// A component's own panels, and the project's: after the library's, so on a Fourier
|
|
6640
|
+
// the library's status comes first.
|
|
6641
|
+
scheduleEditorFieldset.append(...startEditorPanels(selectable));
|
|
6237
6642
|
|
|
6238
6643
|
for (const info of scalars ?? []) {
|
|
6239
6644
|
const section = buildScalarSection(info, selectable, (s, i) =>
|
|
@@ -6572,9 +6977,7 @@ function rectHandlePositions(
|
|
|
6572
6977
|
* level, so local == logical and no conversion is needed).
|
|
6573
6978
|
*/
|
|
6574
6979
|
function getMarkerRelTf(): DOMMatrix | null {
|
|
6575
|
-
const component =
|
|
6576
|
-
selectedSlideChild ??
|
|
6577
|
-
currentRoot();
|
|
6980
|
+
const component = selectedSlideChild ?? currentRoot();
|
|
6578
6981
|
if (!component) return null;
|
|
6579
6982
|
const compTf = componentTransforms.get(component);
|
|
6580
6983
|
if (!compTf) return null;
|
|
@@ -6715,7 +7118,10 @@ function drawLatticeOutline(
|
|
|
6715
7118
|
}
|
|
6716
7119
|
|
|
6717
7120
|
/** Where the lattice's cell-size control point sits: bottom-right of the top-left cell. */
|
|
6718
|
-
function latticeCellHandlePosition(value: LatticeValue): {
|
|
7121
|
+
function latticeCellHandlePosition(value: LatticeValue): {
|
|
7122
|
+
x: number;
|
|
7123
|
+
y: number;
|
|
7124
|
+
} {
|
|
6719
7125
|
const lattice = new Lattice(value);
|
|
6720
7126
|
const cell = lattice.cellRect(0, 0);
|
|
6721
7127
|
return { x: cell.x + cell.width, y: cell.y + cell.height };
|
|
@@ -7392,6 +7798,12 @@ function applyMarkerDrag(localX: number, localY: number, shiftKey = false) {
|
|
|
7392
7798
|
if (jsonResult.ok) {
|
|
7393
7799
|
applyJsonSnapshot(jsonResult.data, true, false);
|
|
7394
7800
|
}
|
|
7801
|
+
// Now the chapters are the saved tree's, so the last session's place can be found.
|
|
7802
|
+
if (placeToRestore) {
|
|
7803
|
+
const place = placeToRestore;
|
|
7804
|
+
placeToRestore = undefined;
|
|
7805
|
+
restorePlace(place);
|
|
7806
|
+
}
|
|
7395
7807
|
// Catch the synced files up with whatever was restored, rather than
|
|
7396
7808
|
// trusting the last session's final write: a write started as the page
|
|
7397
7809
|
// unloads usually never finishes. (It can't leave a corrupt file, only a
|
|
@@ -7426,44 +7838,13 @@ function applyMarkerDrag(localX: number, localY: number, shiftKey = false) {
|
|
|
7426
7838
|
// So when you configure the web page, and you hit refresh, or the page automatically
|
|
7427
7839
|
// refreshes, you don't lose your settings.
|
|
7428
7840
|
try {
|
|
7429
|
-
|
|
7430
|
-
|
|
7431
|
-
|
|
7432
|
-
|
|
7433
|
-
select.selectedIndex = assertNonNullable(parseIntX(index));
|
|
7434
|
-
if (select.selectedIndex < 0) {
|
|
7435
|
-
// What if you save the state when row 13 is selected, but there are currently
|
|
7436
|
-
// only 5 rows available? That's when we get here. Without this change
|
|
7437
|
-
// updateFromSelect() would throw an exception.
|
|
7438
|
-
select.selectedIndex = 0;
|
|
7439
|
-
}
|
|
7440
|
-
updateFromSelect();
|
|
7441
|
-
if (sessionStorage.getItem("keepLimits") === "1") {
|
|
7442
|
-
keepLimitsCheckbox.checked = true;
|
|
7443
|
-
const limitsIndex = parseIntX(sessionStorage.getItem("limitsIndex") ?? "");
|
|
7444
|
-
const saved =
|
|
7445
|
-
limitsIndex === undefined ? undefined : chapterList[limitsIndex];
|
|
7446
|
-
if (saved) {
|
|
7447
|
-
limitsShowable = saved.selectable;
|
|
7448
|
-
applyLimits();
|
|
7449
|
-
}
|
|
7450
|
-
}
|
|
7451
|
-
const savedMs = parseFloat(timeInSeconds) * 1000;
|
|
7452
|
-
const clampedMs = Math.max(
|
|
7453
|
-
sectionStartTime,
|
|
7454
|
-
Math.min(sectionEndTime, savedMs),
|
|
7455
|
-
);
|
|
7456
|
-
loadPlayPositionSeconds(clampedMs);
|
|
7457
|
-
loadPlayPositionRange();
|
|
7458
|
-
// "continue" was removed. A page saved with it pauses instead.
|
|
7459
|
-
const onEnd = document.querySelector<HTMLInputElement>(
|
|
7460
|
-
`input[name="onSectionEnd"][value="${state}"]`,
|
|
7461
|
-
);
|
|
7462
|
-
if (onEnd) onEnd.checked = true;
|
|
7463
|
-
if (sessionStorage.getItem("wasPlaying") === "1") {
|
|
7464
|
-
playCheckBox.checked = true;
|
|
7465
|
-
}
|
|
7841
|
+
if (sessionStorage.getItem("playPositionLocal") === "0") {
|
|
7842
|
+
const playheadMs = playheadInVideoMs();
|
|
7843
|
+
playPositionLocal.checked = false;
|
|
7844
|
+
loadPlayPositionSeconds(playheadMs);
|
|
7466
7845
|
}
|
|
7846
|
+
// Applied when the saved tree is in: see initFromDB() above.
|
|
7847
|
+
placeToRestore = parseSavedPlace(sessionStorage.getItem("place"));
|
|
7467
7848
|
if (sessionStorage.getItem("quality") === "Low Power") {
|
|
7468
7849
|
getById("lowPower", HTMLInputElement).checked = true;
|
|
7469
7850
|
}
|
|
@@ -7691,6 +8072,12 @@ getById("recordJustSound", HTMLButtonElement).addEventListener(
|
|
|
7691
8072
|
const before = infoDiv.innerHTML;
|
|
7692
8073
|
infoDiv.innerHTML = "Waiting for the sound…";
|
|
7693
8074
|
await soundtrack.ready();
|
|
8075
|
+
try {
|
|
8076
|
+
assertSoundFilesLoaded();
|
|
8077
|
+
} catch (error) {
|
|
8078
|
+
infoDiv.innerHTML = `<strong style="color:red">Not saved:</strong> ${escapeHtml(String(error instanceof Error ? error.message : error))}`;
|
|
8079
|
+
return;
|
|
8080
|
+
}
|
|
7694
8081
|
infoDiv.innerHTML = before;
|
|
7695
8082
|
downloadBlob("sound_file.wav", soundtrack.mix(0, toShow.duration).toBlob());
|
|
7696
8083
|
},
|
|
@@ -7721,7 +8108,8 @@ function renderNewDebugLogEntries(): void {
|
|
|
7721
8108
|
debugLogPre.scrollTop + debugLogPre.clientHeight >=
|
|
7722
8109
|
debugLogPre.scrollHeight - 4;
|
|
7723
8110
|
const newLines = newEntries.map(
|
|
7724
|
-
(entry) =>
|
|
8111
|
+
(entry) =>
|
|
8112
|
+
`${(entry.time / 1000).toFixed(3)} [${entry.tag}] ${entry.message}`,
|
|
7725
8113
|
);
|
|
7726
8114
|
const allLines = debugLogPre.textContent
|
|
7727
8115
|
? debugLogPre.textContent.split("\n").concat(newLines)
|
|
@@ -7732,19 +8120,18 @@ function renderNewDebugLogEntries(): void {
|
|
|
7732
8120
|
}
|
|
7733
8121
|
}
|
|
7734
8122
|
setInterval(renderNewDebugLogEntries, 250);
|
|
7735
|
-
getById("debugLogClearBtn", HTMLButtonElement).addEventListener(
|
|
7736
|
-
"
|
|
7737
|
-
|
|
7738
|
-
debugLogPre.textContent = "";
|
|
7739
|
-
},
|
|
7740
|
-
);
|
|
8123
|
+
getById("debugLogClearBtn", HTMLButtonElement).addEventListener("click", () => {
|
|
8124
|
+
debugLogPre.textContent = "";
|
|
8125
|
+
});
|
|
7741
8126
|
|
|
7742
8127
|
getById("dumpDbBtn", HTMLButtonElement).addEventListener("click", async () => {
|
|
7743
8128
|
const videoRecord = await readVideoHistory();
|
|
7744
8129
|
const pre = getById("dbDump", HTMLPreElement);
|
|
7745
8130
|
const lines: string[] = [];
|
|
7746
8131
|
|
|
7747
|
-
lines.push(
|
|
8132
|
+
lines.push(
|
|
8133
|
+
`=== videos["${toShowKey}"] — ${videoRecord?.entries.length ?? 0} entr(ies) ===`,
|
|
8134
|
+
);
|
|
7748
8135
|
const latest = videoRecord?.entries.at(-1);
|
|
7749
8136
|
lines.push(latest ? JSON.stringify(latest, null, 2) : "(none)");
|
|
7750
8137
|
pre.textContent = lines.join("\n");
|