canvas-recorder-lib 0.7.0 → 0.7.2

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.
Files changed (175) hide show
  1. package/README.md +38 -8
  2. package/dev/audio-builder.ts +5 -1
  3. package/dev/canvas-recorder.css +15 -4
  4. package/dev/canvas-recorder.ts +276 -88
  5. package/dev/delay-files.ts +1 -1
  6. package/dev/format-editor.ts +7 -2
  7. package/dev/fourier-panel.ts +11 -3
  8. package/dev/handwriting-panel.ts +14 -9
  9. package/dev/local-file-row.ts +12 -5
  10. package/dev/multi-text-dialog.ts +15 -6
  11. package/dev/multi-text-panel.ts +6 -2
  12. package/dev/player-body.ts +4 -0
  13. package/dev/schedule-helpers.ts +11 -4
  14. package/dev/sound-clips.ts +4 -1
  15. package/dev/soundtrack.ts +52 -13
  16. package/dev/split-dialog.ts +49 -19
  17. package/dev/static-image-panel.ts +17 -5
  18. package/dev/synced-file.ts +4 -5
  19. package/dev/timeline-display.ts +152 -50
  20. package/dev/transcribe-core.ts +48 -17
  21. package/dev/transcribe-worker.ts +20 -9
  22. package/dev/transcript-align.ts +95 -20
  23. package/dev/transcript-export.ts +18 -7
  24. package/dev/transcript-view.ts +78 -22
  25. package/dev/transcripts.ts +97 -26
  26. package/dev/video-clip-panel.ts +64 -18
  27. package/dev/voice/chirp.ts +21 -5
  28. package/dev/voice/folder.ts +22 -7
  29. package/dev/voice/voice-panel.ts +61 -27
  30. package/dev/voice/voice-recorder.ts +74 -18
  31. package/dist/dev/audio-builder.js.map +1 -1
  32. package/dist/dev/canvas-recorder.css +15 -4
  33. package/dist/dev/canvas-recorder.js +185 -48
  34. package/dist/dev/canvas-recorder.js.map +1 -1
  35. package/dist/dev/format-editor.d.ts.map +1 -1
  36. package/dist/dev/format-editor.js.map +1 -1
  37. package/dist/dev/fourier-panel.d.ts.map +1 -1
  38. package/dist/dev/fourier-panel.js.map +1 -1
  39. package/dist/dev/handwriting-panel.d.ts.map +1 -1
  40. package/dist/dev/handwriting-panel.js +10 -8
  41. package/dist/dev/handwriting-panel.js.map +1 -1
  42. package/dist/dev/local-file-row.d.ts.map +1 -1
  43. package/dist/dev/local-file-row.js +12 -4
  44. package/dist/dev/local-file-row.js.map +1 -1
  45. package/dist/dev/multi-text-dialog.d.ts.map +1 -1
  46. package/dist/dev/multi-text-dialog.js +4 -2
  47. package/dist/dev/multi-text-dialog.js.map +1 -1
  48. package/dist/dev/multi-text-panel.d.ts.map +1 -1
  49. package/dist/dev/multi-text-panel.js +2 -1
  50. package/dist/dev/multi-text-panel.js.map +1 -1
  51. package/dist/dev/player-body.d.ts +1 -1
  52. package/dist/dev/player-body.d.ts.map +1 -1
  53. package/dist/dev/player-body.js +4 -0
  54. package/dist/dev/player-body.js.map +1 -1
  55. package/dist/dev/schedule-helpers.d.ts.map +1 -1
  56. package/dist/dev/schedule-helpers.js +4 -1
  57. package/dist/dev/schedule-helpers.js.map +1 -1
  58. package/dist/dev/sound-clips.d.ts.map +1 -1
  59. package/dist/dev/sound-clips.js.map +1 -1
  60. package/dist/dev/soundtrack.d.ts +12 -0
  61. package/dist/dev/soundtrack.d.ts.map +1 -1
  62. package/dist/dev/soundtrack.js +42 -9
  63. package/dist/dev/soundtrack.js.map +1 -1
  64. package/dist/dev/split-dialog.d.ts.map +1 -1
  65. package/dist/dev/split-dialog.js +17 -10
  66. package/dist/dev/split-dialog.js.map +1 -1
  67. package/dist/dev/static-image-panel.d.ts.map +1 -1
  68. package/dist/dev/static-image-panel.js +7 -3
  69. package/dist/dev/static-image-panel.js.map +1 -1
  70. package/dist/dev/synced-file.d.ts.map +1 -1
  71. package/dist/dev/synced-file.js.map +1 -1
  72. package/dist/dev/timeline-display.d.ts.map +1 -1
  73. package/dist/dev/timeline-display.js +62 -17
  74. package/dist/dev/timeline-display.js.map +1 -1
  75. package/dist/dev/transcribe-core.d.ts.map +1 -1
  76. package/dist/dev/transcribe-core.js +13 -3
  77. package/dist/dev/transcribe-core.js.map +1 -1
  78. package/dist/dev/transcribe-worker.d.ts.map +1 -1
  79. package/dist/dev/transcribe-worker.js +9 -3
  80. package/dist/dev/transcribe-worker.js.map +1 -1
  81. package/dist/dev/transcript-align.d.ts.map +1 -1
  82. package/dist/dev/transcript-align.js +52 -9
  83. package/dist/dev/transcript-align.js.map +1 -1
  84. package/dist/dev/transcript-export.d.ts.map +1 -1
  85. package/dist/dev/transcript-export.js +10 -4
  86. package/dist/dev/transcript-export.js.map +1 -1
  87. package/dist/dev/transcript-view.d.ts +2 -0
  88. package/dist/dev/transcript-view.d.ts.map +1 -1
  89. package/dist/dev/transcript-view.js +32 -11
  90. package/dist/dev/transcript-view.js.map +1 -1
  91. package/dist/dev/transcripts.d.ts +5 -0
  92. package/dist/dev/transcripts.d.ts.map +1 -1
  93. package/dist/dev/transcripts.js +54 -6
  94. package/dist/dev/transcripts.js.map +1 -1
  95. package/dist/dev/video-clip-panel.d.ts.map +1 -1
  96. package/dist/dev/video-clip-panel.js +25 -8
  97. package/dist/dev/video-clip-panel.js.map +1 -1
  98. package/dist/dev/voice/chirp.d.ts.map +1 -1
  99. package/dist/dev/voice/chirp.js +5 -1
  100. package/dist/dev/voice/chirp.js.map +1 -1
  101. package/dist/dev/voice/folder.d.ts.map +1 -1
  102. package/dist/dev/voice/folder.js +1 -1
  103. package/dist/dev/voice/folder.js.map +1 -1
  104. package/dist/dev/voice/voice-panel.d.ts.map +1 -1
  105. package/dist/dev/voice/voice-panel.js +42 -23
  106. package/dist/dev/voice/voice-panel.js.map +1 -1
  107. package/dist/dev/voice/voice-recorder.d.ts.map +1 -1
  108. package/dist/dev/voice/voice-recorder.js +34 -9
  109. package/dist/dev/voice/voice-recorder.js.map +1 -1
  110. package/dist/lib/main-control.d.ts.map +1 -1
  111. package/dist/lib/main-control.js.map +1 -1
  112. package/dist/src/corner-rounder.d.ts.map +1 -1
  113. package/dist/src/corner-rounder.js +1 -1
  114. package/dist/src/corner-rounder.js.map +1 -1
  115. package/dist/src/local-files.d.ts.map +1 -1
  116. package/dist/src/local-files.js +5 -2
  117. package/dist/src/local-files.js.map +1 -1
  118. package/dist/src/peano-fourier/fourier-shared.d.ts +7 -0
  119. package/dist/src/peano-fourier/fourier-shared.d.ts.map +1 -1
  120. package/dist/src/peano-fourier/fourier-shared.js +8 -1
  121. package/dist/src/peano-fourier/fourier-shared.js.map +1 -1
  122. package/dist/src/slide-components/fourier.d.ts.map +1 -1
  123. package/dist/src/slide-components/fourier.js +12 -4
  124. package/dist/src/slide-components/fourier.js.map +1 -1
  125. package/dist/src/slide-components/image.d.ts.map +1 -1
  126. package/dist/src/slide-components/image.js +1 -1
  127. package/dist/src/slide-components/image.js.map +1 -1
  128. package/dist/src/slide-components/in-parallel.d.ts.map +1 -1
  129. package/dist/src/slide-components/in-parallel.js.map +1 -1
  130. package/dist/src/slide-components/multi-text.d.ts.map +1 -1
  131. package/dist/src/slide-components/multi-text.js +1 -1
  132. package/dist/src/slide-components/multi-text.js.map +1 -1
  133. package/dist/src/slide-components/rectangle.d.ts.map +1 -1
  134. package/dist/src/slide-components/rectangle.js +1 -1
  135. package/dist/src/slide-components/rectangle.js.map +1 -1
  136. package/dist/src/slide-components/registry.js.map +1 -1
  137. package/dist/src/slide-components/serialize.d.ts.map +1 -1
  138. package/dist/src/slide-components/serialize.js +2 -1
  139. package/dist/src/slide-components/serialize.js.map +1 -1
  140. package/dist/src/slide-components/split-video-clip.d.ts.map +1 -1
  141. package/dist/src/slide-components/split-video-clip.js +4 -1
  142. package/dist/src/slide-components/split-video-clip.js.map +1 -1
  143. package/dist/src/slide-components/video-clip.d.ts.map +1 -1
  144. package/dist/src/slide-components/video-clip.js +7 -4
  145. package/dist/src/slide-components/video-clip.js.map +1 -1
  146. package/dist/src/slide-components/video-info.d.ts.map +1 -1
  147. package/dist/src/slide-components/video-info.js.map +1 -1
  148. package/dist/src/slow-image-sources.d.ts.map +1 -1
  149. package/dist/src/slow-image-sources.js +1 -1
  150. package/dist/src/slow-image-sources.js.map +1 -1
  151. package/dist/src/snapshot.d.ts.map +1 -1
  152. package/dist/src/snapshot.js +1 -1
  153. package/dist/src/snapshot.js.map +1 -1
  154. package/dist/src/utility.d.ts.map +1 -1
  155. package/dist/src/utility.js +1 -3
  156. package/dist/src/utility.js.map +1 -1
  157. package/lib/main-control.ts +3 -1
  158. package/package.json +4 -1
  159. package/src/corner-rounder.ts +5 -12
  160. package/src/glib/letters-base.ts +1 -1
  161. package/src/local-files.ts +19 -6
  162. package/src/peano-fourier/fourier-shared.ts +8 -1
  163. package/src/slide-components/fourier.ts +32 -10
  164. package/src/slide-components/image.ts +4 -1
  165. package/src/slide-components/in-parallel.ts +1 -2
  166. package/src/slide-components/multi-text.ts +17 -4
  167. package/src/slide-components/rectangle.ts +4 -1
  168. package/src/slide-components/registry.ts +1 -1
  169. package/src/slide-components/serialize.ts +4 -1
  170. package/src/slide-components/split-video-clip.ts +4 -1
  171. package/src/slide-components/video-clip.ts +21 -8
  172. package/src/slide-components/video-info.ts +4 -1
  173. package/src/slow-image-sources.ts +5 -1
  174. package/src/snapshot.ts +13 -4
  175. package/src/utility.ts +70 -33
@@ -99,6 +99,7 @@ import {
99
99
  type TimelineWord,
100
100
  } from "./timeline-display.ts";
101
101
  import {
102
+ forgetTranscriptFailures,
102
103
  forgetTranscripts,
103
104
  makeTranscript,
104
105
  onTranscriptsChange,
@@ -261,7 +262,7 @@ function applyZoom(zoom: number, px = panX, py = panY) {
261
262
  canvas.height = physH;
262
263
  canvas.style.width = `${cssW}px`;
263
264
  canvas.style.height = `${cssH}px`;
264
- showFrame(playPositionSeconds.valueAsNumber * 1000, true);
265
+ showFrame(playheadInVideoMs(), true);
265
266
  }
266
267
  [panX, panY] = clampPan(cssW, cssH, px, py);
267
268
  canvas.style.left = `${panX}px`;
@@ -296,7 +297,7 @@ function zoomToFit() {
296
297
  canvas.style.left = `${Math.round((vpW - cssW) / 2)}px`;
297
298
  canvas.style.top = `${Math.round((vpH - cssH) / 2)}px`;
298
299
  // Immediately redraw so the canvas clear doesn't show as a gray flash.
299
- showFrame(playPositionSeconds.valueAsNumber * 1000, true);
300
+ showFrame(playheadInVideoMs(), true);
300
301
  }
301
302
 
302
303
  zoomSelect.addEventListener("change", () => {
@@ -364,7 +365,8 @@ function readSavedVideoSize(): VideoSize | undefined {
364
365
  height: record.height,
365
366
  };
366
367
  const valid = Object.values(size).every(
367
- (value) => typeof value === "number" && Number.isFinite(value) && value > 0,
368
+ (value) =>
369
+ typeof value === "number" && Number.isFinite(value) && value > 0,
368
370
  );
369
371
  return valid ? (size as VideoSize) : undefined;
370
372
  } catch {
@@ -400,9 +402,10 @@ function showVideoSize(size: VideoSize) {
400
402
  videoSizeWarning.title = stretched
401
403
  ? `The pixels are ${pixelAspect.toFixed(3)} : 1 and the units are ${unitAspect.toFixed(3)} : 1, so the picture is stretched to fit.`
402
404
  : "";
403
- getById("videoSizeControls", HTMLSpanElement).title = canvasRecorder.sizeLocked
404
- ? "The size of the video. This program sets it, so it can't be changed here."
405
- : "The size of the video. Pixels: the saved file. Units: the coordinates everything is drawn in. Remembered for this video.";
405
+ getById("videoSizeControls", HTMLSpanElement).title =
406
+ canvasRecorder.sizeLocked
407
+ ? "The size of the video. This program sets it, so it can't be changed here."
408
+ : "The size of the video. Pixels: the saved file. Units: the coordinates everything is drawn in. Remembered for this video.";
406
409
  }
407
410
  showVideoSize(canvasRecorder.size);
408
411
 
@@ -420,7 +423,10 @@ function setVideoSizeFromGui(size: VideoSize): boolean {
420
423
  return false;
421
424
  }
422
425
  try {
423
- localStorage.setItem(videoSizeStorageKey, JSON.stringify(canvasRecorder.size));
426
+ localStorage.setItem(
427
+ videoSizeStorageKey,
428
+ JSON.stringify(canvasRecorder.size),
429
+ );
424
430
  } catch {
425
431
  // Private browsing, or storage is full. The size still works until the page reloads.
426
432
  }
@@ -465,9 +471,12 @@ function updateLocalFilesButton() {
465
471
  const names = localFilesNeedingPermission();
466
472
  localFilesBtn.hidden = names.length === 0;
467
473
  localFilesBtn.textContent =
468
- names.length === 1 ? "🔓 Allow local file" : `🔓 Allow ${names.length} local files`;
474
+ names.length === 1
475
+ ? "🔓 Allow local file"
476
+ : `🔓 Allow ${names.length} local files`;
469
477
  localFilesBtn.title =
470
- "The browser needs your OK before it reads these files again:\n" + names.join("\n");
478
+ "The browser needs your OK before it reads these files again:\n" +
479
+ names.join("\n");
471
480
  }
472
481
  onLocalFilesChange(updateLocalFilesButton);
473
482
 
@@ -476,6 +485,7 @@ async function allowLocalFiles() {
476
485
  await requestLocalFileAccess();
477
486
  // The images and video clips try again by themselves.
478
487
  soundtrack.forgetFailures();
488
+ forgetTranscriptFailures();
479
489
  }
480
490
  localFilesBtn.addEventListener("click", () => void allowLocalFiles());
481
491
 
@@ -516,7 +526,8 @@ function showFrame(timeInMs: number, live: boolean) {
516
526
  timeInMs - rootStartMs,
517
527
  live && playCheckBox.checked,
518
528
  );
519
- if (live) transcriptView?.update(timeInMs - rootStartMs, playCheckBox.checked);
529
+ if (live)
530
+ transcriptView?.update(timeInMs - rootStartMs, playCheckBox.checked);
520
531
  for (const update of goToButtonUpdaters) update();
521
532
  context.reset();
522
533
  context.setTransform(mainTransform());
@@ -613,8 +624,18 @@ const playPositionRange = getById("playPositionRange", HTMLInputElement);
613
624
  * This can be a number outside of the normal range of the current section.
614
625
  * This, like all user visible number, is measured in seconds. Internal
615
626
  * things measure time in milliseconds.
627
+ *
628
+ * It's measured from the start of the Visual Editor's root when
629
+ * {@link playPositionLocal} is checked, otherwise from the start of the video.
630
+ * Read it with {@link playheadInVideoMs} and write it with
631
+ * {@link loadPlayPositionSeconds}, which take care of that.
616
632
  */
617
633
  const playPositionSeconds = getById("playPositionSeconds", HTMLInputElement);
634
+ /**
635
+ * Checked: {@link playPositionSeconds} is measured from the start of the
636
+ * Visual Editor's root. Unchecked: from the start of the video.
637
+ */
638
+ const playPositionLocal = getById("playPositionLocal", HTMLInputElement);
618
639
  /**
619
640
  * When we get to the end of the section, automatically jump back to the
620
641
  * beginning of the section.
@@ -624,24 +645,54 @@ const repeatRadioButton = querySelector(
624
645
  HTMLInputElement,
625
646
  );
626
647
 
648
+ /**
649
+ * The playhead, measured from the start of the whole video.
650
+ * {@link playPositionSeconds} is the source of truth.
651
+ */
652
+ function playheadInVideoMs(): number {
653
+ const shownMs = playPositionSeconds.valueAsNumber * 1000;
654
+ return playPositionLocal.checked ? shownMs + rootStartMs : shownMs;
655
+ }
656
+
627
657
  /**
628
658
  * The playhead, measured from the start of the Visual Editor's root: the
629
659
  * time its keyframes use.
630
660
  */
631
661
  function playheadInRootMs(): number {
632
- return playPositionSeconds.valueAsNumber * 1000 - rootStartMs;
662
+ return playheadInVideoMs() - rootStartMs;
633
663
  }
634
664
 
635
665
  /**
636
666
  * Update the input that shows the time as a number.
637
- * @param timeInMs The time to display in the number control.
667
+ * @param timeInMs The time to display in the number control, measured from the start of the
668
+ * video. It's shown from the start of the root instead if {@link playPositionLocal} says so.
638
669
  * This is *automatically* converted to seconds and rounded to the nearest ⅒ of a millisecond.
639
670
  * We only use milliseconds, not seconds, inside the code.
640
671
  */
641
672
  function loadPlayPositionSeconds(timeInMs: number) {
642
- playPositionSeconds.value = (timeInMs / 1000).toFixed(4);
673
+ const shownMs = playPositionLocal.checked ? timeInMs - rootStartMs : timeInMs;
674
+ playPositionSeconds.value = (shownMs / 1000).toFixed(4);
643
675
  }
644
676
 
677
+ /**
678
+ * Move the Visual Editor's root. The playhead stays where it is in the video, so a local
679
+ * {@link playPositionSeconds} changes to match.
680
+ */
681
+ function setRootStartMs(ms: number): void {
682
+ if (ms === rootStartMs) return;
683
+ const playheadMs = playheadInVideoMs();
684
+ rootStartMs = ms;
685
+ loadPlayPositionSeconds(playheadMs);
686
+ }
687
+
688
+ playPositionLocal.addEventListener("input", () => {
689
+ // The same time, shown the other way. The number still means what the checkbox used to say.
690
+ const shownMs = playPositionSeconds.valueAsNumber * 1000;
691
+ loadPlayPositionSeconds(
692
+ playPositionLocal.checked ? shownMs : shownMs + rootStartMs,
693
+ );
694
+ });
695
+
645
696
  /**
646
697
  * Update the range input to show the same time as the number input.
647
698
  *
@@ -651,7 +702,7 @@ function loadPlayPositionSeconds(timeInMs: number) {
651
702
  * If the user changes the range input, and the value is immediately copied to the number input for use in the program.
652
703
  */
653
704
  function loadPlayPositionRange() {
654
- playPositionRange.valueAsNumber = playPositionSeconds.valueAsNumber * 1000;
705
+ playPositionRange.valueAsNumber = playheadInVideoMs();
655
706
  }
656
707
 
657
708
  // The same rate as the decoded files and the voice recorder, whatever the hardware uses.
@@ -670,7 +721,9 @@ const soundtrack = new Soundtrack({
670
721
  root: () => toShow,
671
722
  // Sound clips on the timeline can now show their waveforms, and the ones
672
723
  // that play to the end of their file now know how long that is.
673
- onDecoded: () => timelineDisplay.redraw(),
724
+ onDecoded: soundFileLoaded,
725
+ // Marked ⚠, on the timeline and on its card. See soundFileProblem().
726
+ onFailed: soundFileLoaded,
674
727
  // The new file may be a local one that needs 🔓.
675
728
  onNewSource: () => checkVideosLocalFiles(),
676
729
  });
@@ -864,7 +917,7 @@ const animationLoop = new AnimationLoop((_rAFTimeInMs: number) => {
864
917
  // Pausing is how a voice recording stops, once the video has started.
865
918
  if (voiceRecording && !voiceChirping) stopVoiceRecording();
866
919
  playPositionSeconds.disabled = false;
867
- showFrame(playPositionSeconds.valueAsNumber * 1000, true);
920
+ showFrame(playheadInVideoMs(), true);
868
921
  return;
869
922
  }
870
923
 
@@ -874,7 +927,7 @@ const animationLoop = new AnimationLoop((_rAFTimeInMs: number) => {
874
927
  if (!audioPlaying && !rafFallbackPlaying) {
875
928
  // Not running: first play, after pause/seek, or after repeat.
876
929
  // Clips whose file isn't decoded yet join in when it is, so nothing waits for them.
877
- let startMs = playPositionSeconds.valueAsNumber * 1000;
930
+ let startMs = playheadInVideoMs();
878
931
  if (startMs >= sectionEndTime - 0.05) {
879
932
  // At the end — jump to the beginning.
880
933
  startMs = sectionStartTime;
@@ -976,10 +1029,7 @@ addEventListener("keypress", (event) => {
976
1029
  });
977
1030
 
978
1031
  getById("back5s", HTMLButtonElement).addEventListener("click", () => {
979
- const backMs = Math.max(
980
- sectionStartTime,
981
- playPositionSeconds.valueAsNumber * 1000 - 5000,
982
- );
1032
+ const backMs = Math.max(sectionStartTime, playheadInVideoMs() - 5000);
983
1033
  loadPlayPositionSeconds(backMs);
984
1034
  loadPlayPositionRange();
985
1035
  stopAudio();
@@ -1035,7 +1085,7 @@ function framesBetween(startMs: number, endMs: number): number {
1035
1085
  * It stays inside the play limits.
1036
1086
  */
1037
1087
  function stepOneFrame(direction: 1 | -1): void {
1038
- const position = framePosition(playPositionSeconds.valueAsNumber * 1000);
1088
+ const position = framePosition(playheadInVideoMs());
1039
1089
  let frame =
1040
1090
  direction > 0
1041
1091
  ? Math.floor(position + FRAME_TOLERANCE) + 1
@@ -1098,7 +1148,8 @@ const sectionEndRadios = document.querySelectorAll<HTMLInputElement>(
1098
1148
  );
1099
1149
 
1100
1150
  /** Where the clip being recorded will go. For its block on the timeline. */
1101
- let liveVoiceClip: { readonly owner: Showable; readonly startInOwnerMs: number } | undefined;
1151
+ let liveVoiceClip:
1152
+ { readonly owner: Showable; readonly startInOwnerMs: number } | undefined;
1102
1153
 
1103
1154
  recordModeButton.addEventListener("click", async () => {
1104
1155
  if (voicePanel) {
@@ -1219,7 +1270,11 @@ function endVoiceClip(): void {
1219
1270
  }
1220
1271
 
1221
1272
  /** A clip's file is finished. Put it on the timeline. */
1222
- function addVoiceClip(owner: Showable, startInOwnerMs: number, recorded: RecordedClip): void {
1273
+ function addVoiceClip(
1274
+ owner: Showable,
1275
+ startInOwnerMs: number,
1276
+ recorded: RecordedClip,
1277
+ ): void {
1223
1278
  // The samples are in memory already. Don't read the file back.
1224
1279
  soundtrack.provide(recorded.url, recorded.buffer);
1225
1280
  (owner.soundClips ??= []).push({
@@ -1231,7 +1286,8 @@ function addVoiceClip(owner: Showable, startInOwnerMs: number, recorded: Recorde
1231
1286
  markDirty();
1232
1287
  soundtrack.request();
1233
1288
  refreshTimeline();
1234
- if ((selectedSlideChild ?? currentRoot()) === owner) updateScheduleEditor(owner);
1289
+ if ((selectedSlideChild ?? currentRoot()) === owner)
1290
+ updateScheduleEditor(owner);
1235
1291
  }
1236
1292
 
1237
1293
  /**
@@ -1310,6 +1366,13 @@ async function startRecording(
1310
1366
  ],
1311
1367
  });
1312
1368
 
1369
+ // The newest soundtrack, with every file in it decoded. Right after a reload or an
1370
+ // edit, that can take a moment. (After the file picker, which needs the click.)
1371
+ // Before anything is written: a sound that can't be read stops the save here.
1372
+ infoDiv.innerHTML = "Waiting for the sound…";
1373
+ await soundtrack.ready();
1374
+ assertSoundFilesLoaded();
1375
+
1313
1376
  const writableStream = await fileHandle.createWritable();
1314
1377
 
1315
1378
  // Set up Mediabunny output (streaming to file)
@@ -1333,10 +1396,6 @@ async function startRecording(
1333
1396
  // The file starts where its first frame starts, so the sound starts there too.
1334
1397
  const audioStartMs = (firstFrame * 1000) / FPS;
1335
1398
 
1336
- // The newest soundtrack, with every file in it decoded. Right after a reload or an
1337
- // edit, that can take a moment. (After the file picker, which needs the click.)
1338
- infoDiv.innerHTML = "Waiting for the sound…";
1339
- await soundtrack.ready();
1340
1399
  const audioBuffer = soundtrack
1341
1400
  .mix(audioStartMs, Math.min(saveEndMs, toShow.duration))
1342
1401
  .getAudioBuffer();
@@ -1507,7 +1566,12 @@ const saveOkBtn = getById("saveOkBtn", HTMLButtonElement);
1507
1566
  * HEVC stores color at half resolution (4:2:0), so both numbers must be even.
1508
1567
  */
1509
1568
  function saveSizeProblem(width: number, height: number): string | undefined {
1510
- if (!(Number.isInteger(width) && width > 0 && Number.isInteger(height) && height > 0)) {
1569
+ if (!(
1570
+ Number.isInteger(width) &&
1571
+ width > 0 &&
1572
+ Number.isInteger(height) &&
1573
+ height > 0
1574
+ )) {
1511
1575
  return "The size must be two whole numbers of pixels.";
1512
1576
  }
1513
1577
  if (width % 2 || height % 2) {
@@ -1530,7 +1594,7 @@ function updateSaveSizeNote(): void {
1530
1594
  saveSizeNote.style.color = "#555";
1531
1595
  } else {
1532
1596
  const stretched =
1533
- Math.abs((width / height) / (pixelWidth / pixelHeight) - 1) > 0.001;
1597
+ Math.abs(width / height / (pixelWidth / pixelHeight) - 1) > 0.001;
1534
1598
  saveSizeNote.textContent = stretched
1535
1599
  ? `Stretched: the video is ${pixelWidth} × ${pixelHeight}.`
1536
1600
  : `${Math.round((width / pixelWidth) * 100)}% of the video's ${pixelWidth} × ${pixelHeight}.`;
@@ -1570,8 +1634,13 @@ function matchSaveAspect(changed: "width" | "height"): void {
1570
1634
 
1571
1635
  saveWidthInput.addEventListener("input", () => matchSaveAspect("width"));
1572
1636
  saveHeightInput.addEventListener("input", () => matchSaveAspect("height"));
1573
- saveKeepAspectCheckbox.addEventListener("input", () => matchSaveAspect("width"));
1574
- getById("saveVideoSizeBtn", HTMLButtonElement).addEventListener("click", resetSaveSize);
1637
+ saveKeepAspectCheckbox.addEventListener("input", () =>
1638
+ matchSaveAspect("width"),
1639
+ );
1640
+ getById("saveVideoSizeBtn", HTMLButtonElement).addEventListener(
1641
+ "click",
1642
+ resetSaveSize,
1643
+ );
1575
1644
 
1576
1645
  function formatTimecode(ms: number): string {
1577
1646
  const totalFrames = Math.round((ms * FPS) / 1000);
@@ -1673,9 +1742,13 @@ const saveLocalFilesBtn = getById("saveLocalFilesBtn", HTMLButtonElement);
1673
1742
  async function saveDialogLocalFilesReady(): Promise<boolean> {
1674
1743
  const problems = await checkLocalFiles(localFileUrlsIn(toShow));
1675
1744
  saveLocalFilesRow.hidden = problems.length === 0;
1676
- const needPermission = problems.some((problem) => problem.reason === "permission");
1745
+ const needPermission = problems.some(
1746
+ (problem) => problem.reason === "permission",
1747
+ );
1677
1748
  saveLocalFilesBtn.hidden = !needPermission;
1678
- saveLocalFilesNote.textContent = problems.map((problem) => problem.message).join(" ");
1749
+ saveLocalFilesNote.textContent = problems
1750
+ .map((problem) => problem.message)
1751
+ .join(" ");
1679
1752
  return problems.length === 0;
1680
1753
  }
1681
1754
 
@@ -2216,7 +2289,7 @@ function applyLimits(): void {
2216
2289
  */
2217
2290
  function updateFromSelect() {
2218
2291
  const info = chapterList[select.selectedIndex];
2219
- rootStartMs = info.start;
2292
+ setRootStartMs(info.start);
2220
2293
  if (keepLimitsCheckbox.checked && limitsShowable) {
2221
2294
  // Only the "Play this one" button changes. Playback carries on.
2222
2295
  applyLimits();
@@ -2263,7 +2336,7 @@ playRootBtn.addEventListener("click", () => {
2263
2336
  */
2264
2337
  function refreshChapters(): void {
2265
2338
  if (initChapters()) {
2266
- rootStartMs = chapterList[select.selectedIndex].start;
2339
+ setRootStartMs(chapterList[select.selectedIndex].start);
2267
2340
  applyLimits();
2268
2341
  // The range clamped itself to the new bounds; show the real position again. The
2269
2342
  // number input stays the source of truth, so a playhead past a shortened end is left
@@ -2321,8 +2394,11 @@ transcriptView = new TranscriptView({
2321
2394
  transcript(source) {
2322
2395
  const status = transcriptStatus(source);
2323
2396
  if (!status) return undefined;
2324
- return status.kind === "ready" ? status.transcript : (statusText(status) ?? "");
2397
+ return status.kind === "ready"
2398
+ ? status.transcript
2399
+ : (statusText(status) ?? "");
2325
2400
  },
2401
+ problem: (clip) => soundFileProblem(clip),
2326
2402
  seek: (rootMs) => timelineDisplay.onSeek?.(rootMs),
2327
2403
  selectClip: (clip) => timelineDisplay.onBlockClick?.(clip),
2328
2404
  selectedClip: () => selectedSoundClip,
@@ -2425,6 +2501,40 @@ function _onClipValueChanged(): void {
2425
2501
  /** Shortest a sound clip can be trimmed to by dragging, in ms. */
2426
2502
  const MIN_SOUND_CLIP_MS = 50;
2427
2503
 
2504
+ /** A sound file was decoded, or failed: update the timeline and the Sound Clips cards. */
2505
+ function soundFileLoaded(): void {
2506
+ timelineDisplay.redraw();
2507
+ for (const cb of soundClipSyncCallbacks) cb();
2508
+ }
2509
+
2510
+ /**
2511
+ * Why `clip`'s file can't be played, or undefined if nothing is wrong, as far as we know yet.
2512
+ * Shown on the timeline, on the clip's card and in the 📖 Text view. A missing file must not
2513
+ * look like a file full of silence, even when its old transcript still shows.
2514
+ */
2515
+ function soundFileProblem(clip: SoundClip): string | undefined {
2516
+ const reason = soundtrack.failure(clip.source);
2517
+ if (reason === undefined) return undefined;
2518
+ return reason instanceof Error ? reason.message : String(reason);
2519
+ }
2520
+
2521
+ /** Stop a save, if any sound in it can't be read. Otherwise the saved sound would have holes. */
2522
+ function assertSoundFilesLoaded(): void {
2523
+ const failed = soundtrack.failures();
2524
+ if (failed.length === 0) return;
2525
+ const { url, reason } = failed[0]!;
2526
+ const why = (
2527
+ reason instanceof Error ? reason.message : String(reason)
2528
+ ).replace(/([^.!?)])$/, "$1.");
2529
+ const which =
2530
+ failed.length === 1
2531
+ ? ""
2532
+ : `${failed.length} sound files couldn't be read. The first: `;
2533
+ throw new Error(
2534
+ `${which}Can't play "${url}": ${why} Each clip that uses ${failed.length === 1 ? "it" : "one"} is marked ⚠ on the timeline.`,
2535
+ );
2536
+ }
2537
+
2428
2538
  /** How long the file `clip` plays from is, once it has been decoded. */
2429
2539
  function soundFileMs(clip: SoundClip): number | undefined {
2430
2540
  const buffer = soundtrack.getDecodedBuffer(clip.source);
@@ -2509,11 +2619,15 @@ function soundClipBlock(clip: SoundClip, ownerStart: number): TimelineBlock {
2509
2619
  return {
2510
2620
  id: clip,
2511
2621
  get label() {
2622
+ const problem = soundFileProblem(clip);
2623
+ if (problem !== undefined) return `⚠ ${problem}`;
2512
2624
  // Notes if there are any, or else the first few words, so clips can be
2513
2625
  // told apart even zoomed out.
2514
2626
  return clip.notes || clipText(clip, 6) || clip.source || "—";
2515
2627
  },
2516
- color: "#3aab3a",
2628
+ get color() {
2629
+ return soundFileProblem(clip) === undefined ? "#3aab3a" : "#9a3412";
2630
+ },
2517
2631
  lane: "sound",
2518
2632
  transcript: () => {
2519
2633
  // Asking is what queues the file for transcribing.
@@ -2735,7 +2849,16 @@ function saveState() {
2735
2849
  "limitsIndex",
2736
2850
  chapterList.findIndex((d) => d.selectable === limitsShowable).toString(),
2737
2851
  );
2738
- sessionStorage.setItem("timeInSeconds", playPositionSeconds.value);
2852
+ // From the start of the video, however the field shows it. "" for an empty field.
2853
+ const playheadMs = playheadInVideoMs();
2854
+ sessionStorage.setItem(
2855
+ "timeInSeconds",
2856
+ isFinite(playheadMs) ? (playheadMs / 1000).toString() : "",
2857
+ );
2858
+ sessionStorage.setItem(
2859
+ "playPositionLocal",
2860
+ playPositionLocal.checked ? "1" : "0",
2861
+ );
2739
2862
  sessionStorage.setItem(
2740
2863
  "state",
2741
2864
  querySelector('input[name="onSectionEnd"]:checked', HTMLInputElement).value,
@@ -2837,7 +2960,8 @@ function openScheduleDB(): Promise<IDBDatabase> {
2837
2960
  // Versions 1–3 had a per-chapter "history" store. "videos" replaced it in v3, and v4
2838
2961
  // removes it. Also drop the directory handle left behind by the temporary
2839
2962
  // "Save All 3" button. See development-plans/single-tree-per-video.md.
2840
- if (db.objectStoreNames.contains("history")) db.deleteObjectStore("history");
2963
+ if (db.objectStoreNames.contains("history"))
2964
+ db.deleteObjectStore("history");
2841
2965
  if (oldVersion < 4)
2842
2966
  req.transaction!.objectStore("files").delete("__properties-dir__");
2843
2967
  };
@@ -3037,7 +3161,11 @@ const jsonSync = new SyncedFile({
3037
3161
  if (enabled) {
3038
3162
  // Only one file per video is synced (and so "active") at a time.
3039
3163
  for (const r of getAllReq.result as FileRecord[]) {
3040
- if (r.videoKey === toShowKey && r.filename !== filename && r.isActive)
3164
+ if (
3165
+ r.videoKey === toShowKey &&
3166
+ r.filename !== filename &&
3167
+ r.isActive
3168
+ )
3041
3169
  store.put({ ...r, isActive: false, syncEnabled: false });
3042
3170
  }
3043
3171
  }
@@ -3144,7 +3272,10 @@ function classDefaults(cls: new () => Showable): ClassDefaults {
3144
3272
  schedules: serializeSchedules(instance.schedules ?? []),
3145
3273
  scalars: serializeScalars(instance.scalars ?? []),
3146
3274
  duration: instance.duration,
3147
- schedulePropertyNames: propertyNamesOf(instance, instance.schedules ?? []),
3275
+ schedulePropertyNames: propertyNamesOf(
3276
+ instance,
3277
+ instance.schedules ?? [],
3278
+ ),
3148
3279
  scalarPropertyNames: propertyNamesOf(instance, instance.scalars ?? []),
3149
3280
  soundClips: instance.soundClips,
3150
3281
  };
@@ -3271,7 +3402,8 @@ function buildDiffText(): string {
3271
3402
  } else {
3272
3403
  // The live object's class, so the properties below type-check.
3273
3404
  const className = comp.constructor.name;
3274
- const cast = className && className !== "Object" ? ` as ${className}` : "";
3405
+ const cast =
3406
+ className && className !== "Object" ? ` as ${className}` : "";
3275
3407
  out.push(
3276
3408
  `${indent}// No howToGenerate for "${rk}", so this makes one the way the Visual Editor does.`,
3277
3409
  `${indent}const ${varName} = componentRegistry.get(${JSON.stringify(rk)})!.create()${cast};`,
@@ -3319,16 +3451,15 @@ function buildDiffText(): string {
3319
3451
 
3320
3452
  if (
3321
3453
  (comp.soundClips?.length || def.soundClips?.length) &&
3322
- JSON.stringify(comp.soundClips ?? []) !== JSON.stringify(def.soundClips ?? [])
3454
+ JSON.stringify(comp.soundClips ?? []) !==
3455
+ JSON.stringify(def.soundClips ?? [])
3323
3456
  ) {
3324
3457
  out.push(
3325
3458
  `${indent}${varName}.soundClips = ${JSON.stringify(comp.soundClips ?? [])};`,
3326
3459
  );
3327
3460
  }
3328
3461
 
3329
- out.push(
3330
- `${indent}${parentExpr}.replaceableComponents!.push(${varName});`,
3331
- );
3462
+ out.push(`${indent}${parentExpr}.replaceableComponents!.push(${varName});`);
3332
3463
 
3333
3464
  return out;
3334
3465
  }
@@ -3502,7 +3633,10 @@ function buildDiffText(): string {
3502
3633
  diffProperties(d, comp, childPath);
3503
3634
  diffReplaceable(d.components ?? [], comp, childPath);
3504
3635
  } else {
3505
- printPathIfNeeded([...path, d.userEditableDescription ?? d.registryKey]);
3636
+ printPathIfNeeded([
3637
+ ...path,
3638
+ d.userEditableDescription ?? d.registryKey,
3639
+ ]);
3506
3640
  lines.push(` [deleted]`);
3507
3641
  }
3508
3642
  }
@@ -3545,7 +3679,6 @@ function buildDiffText(): string {
3545
3679
  }
3546
3680
  }
3547
3681
 
3548
-
3549
3682
  // One tree, so one walk: diffNode() recurses through fixedComponents on its own.
3550
3683
  if (tsDefaultsTree) {
3551
3684
  diffNode(tsDefaultsTree, toShow, [toShow.description]);
@@ -3783,7 +3916,6 @@ function afterStateApplied(): void {
3783
3916
  soundtrack.request();
3784
3917
  }
3785
3918
 
3786
-
3787
3919
  /** Saves current schedule state to IndexedDB as a full data entry.
3788
3920
  * Pass force=true (💾 Save button) to bypass the ts-defaults-no-auto-save guard. */
3789
3921
  /**
@@ -3818,8 +3950,7 @@ async function saveVideoStateToDb(force: boolean): Promise<void> {
3818
3950
 
3819
3951
  // Nothing changed since the last data entry -- don't add a duplicate.
3820
3952
  const last = entries.findLast((e) => !isMarker(e)) as
3821
- | VideoDataEntry
3822
- | undefined;
3953
+ VideoDataEntry | undefined;
3823
3954
  if (last && JSON.stringify(last.tree) === newJson) return;
3824
3955
 
3825
3956
  const entry: VideoDataEntry = { timestamp: Date.now(), tree };
@@ -3880,11 +4011,6 @@ function currentSaveTarget(): Showable | null {
3880
4011
  }
3881
4012
 
3882
4013
  function saveOnUnload() {
3883
- // Start closing any voice recording's files. They may not finish in time.
3884
- // TODO: test this, and add the clip being recorded before the save below.
3885
- // See "Risks" in development-plans/voice-recording.md.
3886
- voicePanel?.recorder.flush();
3887
-
3888
4014
  // When the history dialog is open the live tree may hold a transient preview from
3889
4015
  // _dialogSelectItem. Back up the pre-dialog state instead, so a preview is never
3890
4016
  // persisted as if the user had accepted it.
@@ -4390,7 +4516,7 @@ function buildScheduleSection(
4390
4516
  }
4391
4517
 
4392
4518
  function currentTimeMs() {
4393
- return playPositionSeconds.valueAsNumber * 1000;
4519
+ return playheadInVideoMs();
4394
4520
  }
4395
4521
 
4396
4522
  /**
@@ -4727,8 +4853,10 @@ function buildScheduleSection(
4727
4853
  } else {
4728
4854
  const none = document.createElement("span");
4729
4855
  none.textContent = "—";
4730
- none.title = "The last keyframe has no duration: nothing comes after it.";
4731
- none.style.cssText = "display:inline-block;width:6em;text-align:center;color:#888";
4856
+ none.title =
4857
+ "The last keyframe has no duration: nothing comes after it.";
4858
+ none.style.cssText =
4859
+ "display:inline-block;width:6em;text-align:center;color:#888";
4732
4860
  cell.append(none);
4733
4861
  }
4734
4862
  const atLabel = document.createElement("span");
@@ -4979,8 +5107,9 @@ function buildScheduleSection(
4979
5107
  "cellWidth",
4980
5108
  "cellHeight",
4981
5109
  ] as const;
4982
- const fieldInputs: Partial<Record<(typeof fields)[number], HTMLInputElement>> =
4983
- {};
5110
+ const fieldInputs: Partial<
5111
+ Record<(typeof fields)[number], HTMLInputElement>
5112
+ > = {};
4984
5113
  for (const field of fields) {
4985
5114
  const input = buildNumericInput(latKf.value[field], (n) => {
4986
5115
  latKf.value = { ...latKf.value, [field]: n };
@@ -5413,7 +5542,11 @@ function updateComponentEditor(selectable: Showable) {
5413
5542
  if (i !== -1) arr.splice(i, 1);
5414
5543
  replaceables.replace(arr);
5415
5544
  if (childStart !== undefined) {
5416
- playheadAfterRemoving(childStart, childStart + childDuration, chainEndMs);
5545
+ playheadAfterRemoving(
5546
+ childStart,
5547
+ childStart + childDuration,
5548
+ chainEndMs,
5549
+ );
5417
5550
  }
5418
5551
  if (selectedSlideChild === child) {
5419
5552
  selectedSlideChild = null;
@@ -5521,7 +5654,8 @@ function updateComponentEditor(selectable: Showable) {
5521
5654
  : selectedSlideChild.replaceableComponents !== undefined
5522
5655
  ? selectedSlideChild
5523
5656
  : null;
5524
- const displayName = (s: Showable) => s.userEditableDescription ?? s.description;
5657
+ const displayName = (s: Showable) =>
5658
+ s.userEditableDescription ?? s.description;
5525
5659
 
5526
5660
  const toolbar = document.createElement("div");
5527
5661
  toolbar.className = "components-toolbar";
@@ -5666,13 +5800,14 @@ function buildSoundClipSection(selectable: Showable): HTMLElement {
5666
5800
  const header = document.createElement("div");
5667
5801
  header.style.cssText =
5668
5802
  "display:flex;align-items:center;gap:0.4em;margin-bottom:0.3em;font-size:0.85em;color:#555";
5669
- header.textContent = "Times are in ms, measured from the start of this component.";
5670
- const playheadInOwner = () =>
5671
- tidyMs(playPositionSeconds.valueAsNumber * 1000 - selfStartMs);
5803
+ header.textContent =
5804
+ "Times are in ms, measured from the start of this component.";
5805
+ const playheadInOwner = () => tidyMs(playheadInVideoMs() - selfStartMs);
5672
5806
  const addBtn = document.createElement("button");
5673
5807
  addBtn.type = "button";
5674
5808
  addBtn.textContent = "+ Add";
5675
- addBtn.title = "Add an empty sound clip at the playhead. Then fill in its source.";
5809
+ addBtn.title =
5810
+ "Add an empty sound clip at the playhead. Then fill in its source.";
5676
5811
  addBtn.style.marginLeft = "auto";
5677
5812
  addBtn.addEventListener("click", () => {
5678
5813
  const clip: SoundClip = { source: "", startMsIntoScene: playheadInOwner() };
@@ -5697,7 +5832,9 @@ function buildSoundClipSection(selectable: Showable): HTMLElement {
5697
5832
  }
5698
5833
  const pasted = parseSoundClips(text);
5699
5834
  if (pasted.length === 0) {
5700
- alert("No sound clips found on the clipboard. Each one needs at least a source.");
5835
+ alert(
5836
+ "No sound clips found on the clipboard. Each one needs at least a source.",
5837
+ );
5701
5838
  return;
5702
5839
  }
5703
5840
  ensureList();
@@ -5890,6 +6027,18 @@ function buildSoundClipSection(selectable: Showable): HTMLElement {
5890
6027
  });
5891
6028
  row2.append(srcLabel, sourceInput);
5892
6029
 
6030
+ // Why the file can't be played, if it can't.
6031
+ const problemLine = document.createElement("div");
6032
+ problemLine.style.cssText =
6033
+ "margin-top:0.2em;font-size:0.85em;color:#b00020";
6034
+ const showProblem = () => {
6035
+ const problem = soundFileProblem(clip);
6036
+ problemLine.hidden = problem === undefined;
6037
+ problemLine.textContent = `⚠ ${problem}`;
6038
+ };
6039
+ showProblem();
6040
+ soundClipSyncCallbacks.push(showProblem);
6041
+
5893
6042
  // Row 3: numeric time fields
5894
6043
  const row3 = document.createElement("div");
5895
6044
  row3.style.cssText =
@@ -5972,7 +6121,8 @@ function buildSoundClipSection(selectable: Showable): HTMLElement {
5972
6121
  row4.style.cssText =
5973
6122
  "display:flex;gap:0.4em;align-items:center;margin-top:0.2em;flex-wrap:wrap;font-size:0.85em";
5974
6123
  const ownerLabel = document.createElement("label");
5975
- ownerLabel.style.cssText = "display:flex;align-items:center;gap:0.2em;min-width:0;flex:1";
6124
+ ownerLabel.style.cssText =
6125
+ "display:flex;align-items:center;gap:0.2em;min-width:0;flex:1";
5976
6126
  ownerLabel.textContent = "owner:";
5977
6127
  ownerLabel.title =
5978
6128
  "Which component this sound belongs to. It moves when its owner moves. " +
@@ -6023,7 +6173,7 @@ function buildSoundClipSection(selectable: Showable): HTMLElement {
6023
6173
  soundClipSyncCallbacks.push(drawPlaysAt);
6024
6174
  row4.append(ownerLabel, playsAt);
6025
6175
 
6026
- card.append(row1, row2, row3, row4);
6176
+ card.append(row1, row2, problemLine, row3, row4);
6027
6177
  section.append(card);
6028
6178
  if (clip === selectedSoundClip) {
6029
6179
  requestAnimationFrame(() => card.scrollIntoView({ block: "nearest" }));
@@ -6101,7 +6251,10 @@ function updateScheduleEditor(selectable: Showable) {
6101
6251
  soundClipSyncCallbacks.length = 0;
6102
6252
  rectAspectLock = null;
6103
6253
  // A highlighted sound clip stays highlighted only while its owner is selected.
6104
- if (selectedSoundClip && !selectable.soundClips?.includes(selectedSoundClip)) {
6254
+ if (
6255
+ selectedSoundClip &&
6256
+ !selectable.soundClips?.includes(selectedSoundClip)
6257
+ ) {
6105
6258
  selectedSoundClip = undefined;
6106
6259
  }
6107
6260
  timelineDisplay.setSelectedSoundId(selectedSoundClip);
@@ -6227,7 +6380,10 @@ function updateScheduleEditor(selectable: Showable) {
6227
6380
  return playheadInRootMs() - ownerStart;
6228
6381
  },
6229
6382
  progressChanged() {
6230
- activeRootComponentEditor?.update(selectable, selectable.progressSchedule);
6383
+ activeRootComponentEditor?.update(
6384
+ selectable,
6385
+ selectable.progressSchedule,
6386
+ );
6231
6387
  markDirty();
6232
6388
  // Rebuild so the Progress table shows the new keyframes.
6233
6389
  updateScheduleEditor(selectable);
@@ -6575,9 +6731,7 @@ function rectHandlePositions(
6575
6731
  * level, so local == logical and no conversion is needed).
6576
6732
  */
6577
6733
  function getMarkerRelTf(): DOMMatrix | null {
6578
- const component =
6579
- selectedSlideChild ??
6580
- currentRoot();
6734
+ const component = selectedSlideChild ?? currentRoot();
6581
6735
  if (!component) return null;
6582
6736
  const compTf = componentTransforms.get(component);
6583
6737
  if (!compTf) return null;
@@ -6718,7 +6872,10 @@ function drawLatticeOutline(
6718
6872
  }
6719
6873
 
6720
6874
  /** Where the lattice's cell-size control point sits: bottom-right of the top-left cell. */
6721
- function latticeCellHandlePosition(value: LatticeValue): { x: number; y: number } {
6875
+ function latticeCellHandlePosition(value: LatticeValue): {
6876
+ x: number;
6877
+ y: number;
6878
+ } {
6722
6879
  const lattice = new Lattice(value);
6723
6880
  const cell = lattice.cellRect(0, 0);
6724
6881
  return { x: cell.x + cell.width, y: cell.y + cell.height };
@@ -7429,6 +7586,11 @@ function applyMarkerDrag(localX: number, localY: number, shiftKey = false) {
7429
7586
  // So when you configure the web page, and you hit refresh, or the page automatically
7430
7587
  // refreshes, you don't lose your settings.
7431
7588
  try {
7589
+ if (sessionStorage.getItem("playPositionLocal") === "0") {
7590
+ const playheadMs = playheadInVideoMs();
7591
+ playPositionLocal.checked = false;
7592
+ loadPlayPositionSeconds(playheadMs);
7593
+ }
7432
7594
  const index = sessionStorage.getItem("index");
7433
7595
  const timeInSeconds = sessionStorage.getItem("timeInSeconds");
7434
7596
  const state = sessionStorage.getItem("state");
@@ -7443,7 +7605,9 @@ function applyMarkerDrag(localX: number, localY: number, shiftKey = false) {
7443
7605
  updateFromSelect();
7444
7606
  if (sessionStorage.getItem("keepLimits") === "1") {
7445
7607
  keepLimitsCheckbox.checked = true;
7446
- const limitsIndex = parseIntX(sessionStorage.getItem("limitsIndex") ?? "");
7608
+ const limitsIndex = parseIntX(
7609
+ sessionStorage.getItem("limitsIndex") ?? "",
7610
+ );
7447
7611
  const saved =
7448
7612
  limitsIndex === undefined ? undefined : chapterList[limitsIndex];
7449
7613
  if (saved) {
@@ -7694,6 +7858,12 @@ getById("recordJustSound", HTMLButtonElement).addEventListener(
7694
7858
  const before = infoDiv.innerHTML;
7695
7859
  infoDiv.innerHTML = "Waiting for the sound…";
7696
7860
  await soundtrack.ready();
7861
+ try {
7862
+ assertSoundFilesLoaded();
7863
+ } catch (error) {
7864
+ infoDiv.innerHTML = `<strong style="color:red">Not saved:</strong> ${escapeHtml(String(error instanceof Error ? error.message : error))}`;
7865
+ return;
7866
+ }
7697
7867
  infoDiv.innerHTML = before;
7698
7868
  downloadBlob("sound_file.wav", soundtrack.mix(0, toShow.duration).toBlob());
7699
7869
  },
@@ -7724,7 +7894,8 @@ function renderNewDebugLogEntries(): void {
7724
7894
  debugLogPre.scrollTop + debugLogPre.clientHeight >=
7725
7895
  debugLogPre.scrollHeight - 4;
7726
7896
  const newLines = newEntries.map(
7727
- (entry) => `${(entry.time / 1000).toFixed(3)} [${entry.tag}] ${entry.message}`,
7897
+ (entry) =>
7898
+ `${(entry.time / 1000).toFixed(3)} [${entry.tag}] ${entry.message}`,
7728
7899
  );
7729
7900
  const allLines = debugLogPre.textContent
7730
7901
  ? debugLogPre.textContent.split("\n").concat(newLines)
@@ -7735,19 +7906,18 @@ function renderNewDebugLogEntries(): void {
7735
7906
  }
7736
7907
  }
7737
7908
  setInterval(renderNewDebugLogEntries, 250);
7738
- getById("debugLogClearBtn", HTMLButtonElement).addEventListener(
7739
- "click",
7740
- () => {
7741
- debugLogPre.textContent = "";
7742
- },
7743
- );
7909
+ getById("debugLogClearBtn", HTMLButtonElement).addEventListener("click", () => {
7910
+ debugLogPre.textContent = "";
7911
+ });
7744
7912
 
7745
7913
  getById("dumpDbBtn", HTMLButtonElement).addEventListener("click", async () => {
7746
7914
  const videoRecord = await readVideoHistory();
7747
7915
  const pre = getById("dbDump", HTMLPreElement);
7748
7916
  const lines: string[] = [];
7749
7917
 
7750
- lines.push(`=== videos["${toShowKey}"] — ${videoRecord?.entries.length ?? 0} entr(ies) ===`);
7918
+ lines.push(
7919
+ `=== videos["${toShowKey}"] — ${videoRecord?.entries.length ?? 0} entr(ies) ===`,
7920
+ );
7751
7921
  const latest = videoRecord?.entries.at(-1);
7752
7922
  lines.push(latest ? JSON.stringify(latest, null, 2) : "(none)");
7753
7923
  pre.textContent = lines.join("\n");
@@ -8085,12 +8255,30 @@ if (import.meta.hot) {
8085
8255
  // Changing a typescript file invokes this.
8086
8256
  // Changing a css file would cause vite:beforeUpdate, instead.
8087
8257
  import.meta.hot.on("vite:beforeFullReload", (_data) => {
8258
+ finishVoiceOnUnload();
8088
8259
  saveState();
8089
8260
  saveOnUnload();
8090
8261
  });
8091
8262
  }
8092
8263
 
8093
- window.addEventListener("beforeunload", saveOnUnload);
8264
+ /**
8265
+ * Start closing any voice recording's files. They may not finish in time.
8266
+ *
8267
+ * Only when the page is really going away. Not on visibilitychange: a page is hidden by
8268
+ * another tab, another app or another desktop, often to read a script, and the recording
8269
+ * should keep going.
8270
+ *
8271
+ * TODO: test this, and add the clip being recorded before {@link saveOnUnload}'s backup.
8272
+ * See "Risks" in development-plans/voice-recording.md.
8273
+ */
8274
+ function finishVoiceOnUnload() {
8275
+ voicePanel?.recorder.flush();
8276
+ }
8277
+
8278
+ window.addEventListener("beforeunload", () => {
8279
+ finishVoiceOnUnload();
8280
+ saveOnUnload();
8281
+ });
8094
8282
  document.addEventListener("visibilitychange", () => {
8095
8283
  if (document.visibilityState === "hidden") saveOnUnload();
8096
8284
  });