canvas-recorder-lib 0.7.1 → 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 (174) 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 +255 -82
  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 +42 -11
  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 +43 -23
  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 +34 -10
  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 +165 -42
  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 +33 -7
  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.map +1 -1
  92. package/dist/dev/transcripts.js +5 -3
  93. package/dist/dev/transcripts.js.map +1 -1
  94. package/dist/dev/video-clip-panel.d.ts.map +1 -1
  95. package/dist/dev/video-clip-panel.js +25 -8
  96. package/dist/dev/video-clip-panel.js.map +1 -1
  97. package/dist/dev/voice/chirp.d.ts.map +1 -1
  98. package/dist/dev/voice/chirp.js +5 -1
  99. package/dist/dev/voice/chirp.js.map +1 -1
  100. package/dist/dev/voice/folder.d.ts.map +1 -1
  101. package/dist/dev/voice/folder.js +1 -1
  102. package/dist/dev/voice/folder.js.map +1 -1
  103. package/dist/dev/voice/voice-panel.d.ts.map +1 -1
  104. package/dist/dev/voice/voice-panel.js +15 -6
  105. package/dist/dev/voice/voice-panel.js.map +1 -1
  106. package/dist/dev/voice/voice-recorder.d.ts.map +1 -1
  107. package/dist/dev/voice/voice-recorder.js +34 -9
  108. package/dist/dev/voice/voice-recorder.js.map +1 -1
  109. package/dist/lib/main-control.d.ts.map +1 -1
  110. package/dist/lib/main-control.js.map +1 -1
  111. package/dist/src/corner-rounder.d.ts.map +1 -1
  112. package/dist/src/corner-rounder.js +1 -1
  113. package/dist/src/corner-rounder.js.map +1 -1
  114. package/dist/src/local-files.d.ts.map +1 -1
  115. package/dist/src/local-files.js +5 -2
  116. package/dist/src/local-files.js.map +1 -1
  117. package/dist/src/peano-fourier/fourier-shared.d.ts +7 -0
  118. package/dist/src/peano-fourier/fourier-shared.d.ts.map +1 -1
  119. package/dist/src/peano-fourier/fourier-shared.js +8 -1
  120. package/dist/src/peano-fourier/fourier-shared.js.map +1 -1
  121. package/dist/src/slide-components/fourier.d.ts.map +1 -1
  122. package/dist/src/slide-components/fourier.js +12 -4
  123. package/dist/src/slide-components/fourier.js.map +1 -1
  124. package/dist/src/slide-components/image.d.ts.map +1 -1
  125. package/dist/src/slide-components/image.js +1 -1
  126. package/dist/src/slide-components/image.js.map +1 -1
  127. package/dist/src/slide-components/in-parallel.d.ts.map +1 -1
  128. package/dist/src/slide-components/in-parallel.js.map +1 -1
  129. package/dist/src/slide-components/multi-text.d.ts.map +1 -1
  130. package/dist/src/slide-components/multi-text.js +1 -1
  131. package/dist/src/slide-components/multi-text.js.map +1 -1
  132. package/dist/src/slide-components/rectangle.d.ts.map +1 -1
  133. package/dist/src/slide-components/rectangle.js +1 -1
  134. package/dist/src/slide-components/rectangle.js.map +1 -1
  135. package/dist/src/slide-components/registry.js.map +1 -1
  136. package/dist/src/slide-components/serialize.d.ts.map +1 -1
  137. package/dist/src/slide-components/serialize.js +2 -1
  138. package/dist/src/slide-components/serialize.js.map +1 -1
  139. package/dist/src/slide-components/split-video-clip.d.ts.map +1 -1
  140. package/dist/src/slide-components/split-video-clip.js +4 -1
  141. package/dist/src/slide-components/split-video-clip.js.map +1 -1
  142. package/dist/src/slide-components/video-clip.d.ts.map +1 -1
  143. package/dist/src/slide-components/video-clip.js +7 -4
  144. package/dist/src/slide-components/video-clip.js.map +1 -1
  145. package/dist/src/slide-components/video-info.d.ts.map +1 -1
  146. package/dist/src/slide-components/video-info.js.map +1 -1
  147. package/dist/src/slow-image-sources.d.ts.map +1 -1
  148. package/dist/src/slow-image-sources.js +1 -1
  149. package/dist/src/slow-image-sources.js.map +1 -1
  150. package/dist/src/snapshot.d.ts.map +1 -1
  151. package/dist/src/snapshot.js +1 -1
  152. package/dist/src/snapshot.js.map +1 -1
  153. package/dist/src/utility.d.ts.map +1 -1
  154. package/dist/src/utility.js +1 -3
  155. package/dist/src/utility.js.map +1 -1
  156. package/lib/main-control.ts +3 -1
  157. package/package.json +4 -1
  158. package/src/corner-rounder.ts +5 -12
  159. package/src/glib/letters-base.ts +1 -1
  160. package/src/local-files.ts +19 -6
  161. package/src/peano-fourier/fourier-shared.ts +8 -1
  162. package/src/slide-components/fourier.ts +32 -10
  163. package/src/slide-components/image.ts +4 -1
  164. package/src/slide-components/in-parallel.ts +1 -2
  165. package/src/slide-components/multi-text.ts +17 -4
  166. package/src/slide-components/rectangle.ts +4 -1
  167. package/src/slide-components/registry.ts +1 -1
  168. package/src/slide-components/serialize.ts +4 -1
  169. package/src/slide-components/split-video-clip.ts +4 -1
  170. package/src/slide-components/video-clip.ts +21 -8
  171. package/src/slide-components/video-info.ts +4 -1
  172. package/src/slow-image-sources.ts +5 -1
  173. package/src/snapshot.ts +13 -4
  174. package/src/utility.ts +70 -33
@@ -262,7 +262,7 @@ function applyZoom(zoom: number, px = panX, py = panY) {
262
262
  canvas.height = physH;
263
263
  canvas.style.width = `${cssW}px`;
264
264
  canvas.style.height = `${cssH}px`;
265
- showFrame(playPositionSeconds.valueAsNumber * 1000, true);
265
+ showFrame(playheadInVideoMs(), true);
266
266
  }
267
267
  [panX, panY] = clampPan(cssW, cssH, px, py);
268
268
  canvas.style.left = `${panX}px`;
@@ -297,7 +297,7 @@ function zoomToFit() {
297
297
  canvas.style.left = `${Math.round((vpW - cssW) / 2)}px`;
298
298
  canvas.style.top = `${Math.round((vpH - cssH) / 2)}px`;
299
299
  // Immediately redraw so the canvas clear doesn't show as a gray flash.
300
- showFrame(playPositionSeconds.valueAsNumber * 1000, true);
300
+ showFrame(playheadInVideoMs(), true);
301
301
  }
302
302
 
303
303
  zoomSelect.addEventListener("change", () => {
@@ -365,7 +365,8 @@ function readSavedVideoSize(): VideoSize | undefined {
365
365
  height: record.height,
366
366
  };
367
367
  const valid = Object.values(size).every(
368
- (value) => typeof value === "number" && Number.isFinite(value) && value > 0,
368
+ (value) =>
369
+ typeof value === "number" && Number.isFinite(value) && value > 0,
369
370
  );
370
371
  return valid ? (size as VideoSize) : undefined;
371
372
  } catch {
@@ -401,9 +402,10 @@ function showVideoSize(size: VideoSize) {
401
402
  videoSizeWarning.title = stretched
402
403
  ? `The pixels are ${pixelAspect.toFixed(3)} : 1 and the units are ${unitAspect.toFixed(3)} : 1, so the picture is stretched to fit.`
403
404
  : "";
404
- getById("videoSizeControls", HTMLSpanElement).title = canvasRecorder.sizeLocked
405
- ? "The size of the video. This program sets it, so it can't be changed here."
406
- : "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.";
407
409
  }
408
410
  showVideoSize(canvasRecorder.size);
409
411
 
@@ -421,7 +423,10 @@ function setVideoSizeFromGui(size: VideoSize): boolean {
421
423
  return false;
422
424
  }
423
425
  try {
424
- localStorage.setItem(videoSizeStorageKey, JSON.stringify(canvasRecorder.size));
426
+ localStorage.setItem(
427
+ videoSizeStorageKey,
428
+ JSON.stringify(canvasRecorder.size),
429
+ );
425
430
  } catch {
426
431
  // Private browsing, or storage is full. The size still works until the page reloads.
427
432
  }
@@ -466,9 +471,12 @@ function updateLocalFilesButton() {
466
471
  const names = localFilesNeedingPermission();
467
472
  localFilesBtn.hidden = names.length === 0;
468
473
  localFilesBtn.textContent =
469
- 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`;
470
477
  localFilesBtn.title =
471
- "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");
472
480
  }
473
481
  onLocalFilesChange(updateLocalFilesButton);
474
482
 
@@ -518,7 +526,8 @@ function showFrame(timeInMs: number, live: boolean) {
518
526
  timeInMs - rootStartMs,
519
527
  live && playCheckBox.checked,
520
528
  );
521
- if (live) transcriptView?.update(timeInMs - rootStartMs, playCheckBox.checked);
529
+ if (live)
530
+ transcriptView?.update(timeInMs - rootStartMs, playCheckBox.checked);
522
531
  for (const update of goToButtonUpdaters) update();
523
532
  context.reset();
524
533
  context.setTransform(mainTransform());
@@ -615,8 +624,18 @@ const playPositionRange = getById("playPositionRange", HTMLInputElement);
615
624
  * This can be a number outside of the normal range of the current section.
616
625
  * This, like all user visible number, is measured in seconds. Internal
617
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.
618
632
  */
619
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);
620
639
  /**
621
640
  * When we get to the end of the section, automatically jump back to the
622
641
  * beginning of the section.
@@ -626,24 +645,54 @@ const repeatRadioButton = querySelector(
626
645
  HTMLInputElement,
627
646
  );
628
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
+
629
657
  /**
630
658
  * The playhead, measured from the start of the Visual Editor's root: the
631
659
  * time its keyframes use.
632
660
  */
633
661
  function playheadInRootMs(): number {
634
- return playPositionSeconds.valueAsNumber * 1000 - rootStartMs;
662
+ return playheadInVideoMs() - rootStartMs;
635
663
  }
636
664
 
637
665
  /**
638
666
  * Update the input that shows the time as a number.
639
- * @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.
640
669
  * This is *automatically* converted to seconds and rounded to the nearest ⅒ of a millisecond.
641
670
  * We only use milliseconds, not seconds, inside the code.
642
671
  */
643
672
  function loadPlayPositionSeconds(timeInMs: number) {
644
- playPositionSeconds.value = (timeInMs / 1000).toFixed(4);
673
+ const shownMs = playPositionLocal.checked ? timeInMs - rootStartMs : timeInMs;
674
+ playPositionSeconds.value = (shownMs / 1000).toFixed(4);
645
675
  }
646
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
+
647
696
  /**
648
697
  * Update the range input to show the same time as the number input.
649
698
  *
@@ -653,7 +702,7 @@ function loadPlayPositionSeconds(timeInMs: number) {
653
702
  * If the user changes the range input, and the value is immediately copied to the number input for use in the program.
654
703
  */
655
704
  function loadPlayPositionRange() {
656
- playPositionRange.valueAsNumber = playPositionSeconds.valueAsNumber * 1000;
705
+ playPositionRange.valueAsNumber = playheadInVideoMs();
657
706
  }
658
707
 
659
708
  // The same rate as the decoded files and the voice recorder, whatever the hardware uses.
@@ -672,7 +721,9 @@ const soundtrack = new Soundtrack({
672
721
  root: () => toShow,
673
722
  // Sound clips on the timeline can now show their waveforms, and the ones
674
723
  // that play to the end of their file now know how long that is.
675
- onDecoded: () => timelineDisplay.redraw(),
724
+ onDecoded: soundFileLoaded,
725
+ // Marked ⚠, on the timeline and on its card. See soundFileProblem().
726
+ onFailed: soundFileLoaded,
676
727
  // The new file may be a local one that needs 🔓.
677
728
  onNewSource: () => checkVideosLocalFiles(),
678
729
  });
@@ -866,7 +917,7 @@ const animationLoop = new AnimationLoop((_rAFTimeInMs: number) => {
866
917
  // Pausing is how a voice recording stops, once the video has started.
867
918
  if (voiceRecording && !voiceChirping) stopVoiceRecording();
868
919
  playPositionSeconds.disabled = false;
869
- showFrame(playPositionSeconds.valueAsNumber * 1000, true);
920
+ showFrame(playheadInVideoMs(), true);
870
921
  return;
871
922
  }
872
923
 
@@ -876,7 +927,7 @@ const animationLoop = new AnimationLoop((_rAFTimeInMs: number) => {
876
927
  if (!audioPlaying && !rafFallbackPlaying) {
877
928
  // Not running: first play, after pause/seek, or after repeat.
878
929
  // Clips whose file isn't decoded yet join in when it is, so nothing waits for them.
879
- let startMs = playPositionSeconds.valueAsNumber * 1000;
930
+ let startMs = playheadInVideoMs();
880
931
  if (startMs >= sectionEndTime - 0.05) {
881
932
  // At the end — jump to the beginning.
882
933
  startMs = sectionStartTime;
@@ -978,10 +1029,7 @@ addEventListener("keypress", (event) => {
978
1029
  });
979
1030
 
980
1031
  getById("back5s", HTMLButtonElement).addEventListener("click", () => {
981
- const backMs = Math.max(
982
- sectionStartTime,
983
- playPositionSeconds.valueAsNumber * 1000 - 5000,
984
- );
1032
+ const backMs = Math.max(sectionStartTime, playheadInVideoMs() - 5000);
985
1033
  loadPlayPositionSeconds(backMs);
986
1034
  loadPlayPositionRange();
987
1035
  stopAudio();
@@ -1037,7 +1085,7 @@ function framesBetween(startMs: number, endMs: number): number {
1037
1085
  * It stays inside the play limits.
1038
1086
  */
1039
1087
  function stepOneFrame(direction: 1 | -1): void {
1040
- const position = framePosition(playPositionSeconds.valueAsNumber * 1000);
1088
+ const position = framePosition(playheadInVideoMs());
1041
1089
  let frame =
1042
1090
  direction > 0
1043
1091
  ? Math.floor(position + FRAME_TOLERANCE) + 1
@@ -1100,7 +1148,8 @@ const sectionEndRadios = document.querySelectorAll<HTMLInputElement>(
1100
1148
  );
1101
1149
 
1102
1150
  /** Where the clip being recorded will go. For its block on the timeline. */
1103
- let liveVoiceClip: { readonly owner: Showable; readonly startInOwnerMs: number } | undefined;
1151
+ let liveVoiceClip:
1152
+ { readonly owner: Showable; readonly startInOwnerMs: number } | undefined;
1104
1153
 
1105
1154
  recordModeButton.addEventListener("click", async () => {
1106
1155
  if (voicePanel) {
@@ -1221,7 +1270,11 @@ function endVoiceClip(): void {
1221
1270
  }
1222
1271
 
1223
1272
  /** A clip's file is finished. Put it on the timeline. */
1224
- function addVoiceClip(owner: Showable, startInOwnerMs: number, recorded: RecordedClip): void {
1273
+ function addVoiceClip(
1274
+ owner: Showable,
1275
+ startInOwnerMs: number,
1276
+ recorded: RecordedClip,
1277
+ ): void {
1225
1278
  // The samples are in memory already. Don't read the file back.
1226
1279
  soundtrack.provide(recorded.url, recorded.buffer);
1227
1280
  (owner.soundClips ??= []).push({
@@ -1233,7 +1286,8 @@ function addVoiceClip(owner: Showable, startInOwnerMs: number, recorded: Recorde
1233
1286
  markDirty();
1234
1287
  soundtrack.request();
1235
1288
  refreshTimeline();
1236
- if ((selectedSlideChild ?? currentRoot()) === owner) updateScheduleEditor(owner);
1289
+ if ((selectedSlideChild ?? currentRoot()) === owner)
1290
+ updateScheduleEditor(owner);
1237
1291
  }
1238
1292
 
1239
1293
  /**
@@ -1312,6 +1366,13 @@ async function startRecording(
1312
1366
  ],
1313
1367
  });
1314
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
+
1315
1376
  const writableStream = await fileHandle.createWritable();
1316
1377
 
1317
1378
  // Set up Mediabunny output (streaming to file)
@@ -1335,10 +1396,6 @@ async function startRecording(
1335
1396
  // The file starts where its first frame starts, so the sound starts there too.
1336
1397
  const audioStartMs = (firstFrame * 1000) / FPS;
1337
1398
 
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
1399
  const audioBuffer = soundtrack
1343
1400
  .mix(audioStartMs, Math.min(saveEndMs, toShow.duration))
1344
1401
  .getAudioBuffer();
@@ -1509,7 +1566,12 @@ const saveOkBtn = getById("saveOkBtn", HTMLButtonElement);
1509
1566
  * HEVC stores color at half resolution (4:2:0), so both numbers must be even.
1510
1567
  */
1511
1568
  function saveSizeProblem(width: number, height: number): string | undefined {
1512
- 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
+ )) {
1513
1575
  return "The size must be two whole numbers of pixels.";
1514
1576
  }
1515
1577
  if (width % 2 || height % 2) {
@@ -1532,7 +1594,7 @@ function updateSaveSizeNote(): void {
1532
1594
  saveSizeNote.style.color = "#555";
1533
1595
  } else {
1534
1596
  const stretched =
1535
- Math.abs((width / height) / (pixelWidth / pixelHeight) - 1) > 0.001;
1597
+ Math.abs(width / height / (pixelWidth / pixelHeight) - 1) > 0.001;
1536
1598
  saveSizeNote.textContent = stretched
1537
1599
  ? `Stretched: the video is ${pixelWidth} × ${pixelHeight}.`
1538
1600
  : `${Math.round((width / pixelWidth) * 100)}% of the video's ${pixelWidth} × ${pixelHeight}.`;
@@ -1572,8 +1634,13 @@ function matchSaveAspect(changed: "width" | "height"): void {
1572
1634
 
1573
1635
  saveWidthInput.addEventListener("input", () => matchSaveAspect("width"));
1574
1636
  saveHeightInput.addEventListener("input", () => matchSaveAspect("height"));
1575
- saveKeepAspectCheckbox.addEventListener("input", () => matchSaveAspect("width"));
1576
- getById("saveVideoSizeBtn", HTMLButtonElement).addEventListener("click", resetSaveSize);
1637
+ saveKeepAspectCheckbox.addEventListener("input", () =>
1638
+ matchSaveAspect("width"),
1639
+ );
1640
+ getById("saveVideoSizeBtn", HTMLButtonElement).addEventListener(
1641
+ "click",
1642
+ resetSaveSize,
1643
+ );
1577
1644
 
1578
1645
  function formatTimecode(ms: number): string {
1579
1646
  const totalFrames = Math.round((ms * FPS) / 1000);
@@ -1675,9 +1742,13 @@ const saveLocalFilesBtn = getById("saveLocalFilesBtn", HTMLButtonElement);
1675
1742
  async function saveDialogLocalFilesReady(): Promise<boolean> {
1676
1743
  const problems = await checkLocalFiles(localFileUrlsIn(toShow));
1677
1744
  saveLocalFilesRow.hidden = problems.length === 0;
1678
- const needPermission = problems.some((problem) => problem.reason === "permission");
1745
+ const needPermission = problems.some(
1746
+ (problem) => problem.reason === "permission",
1747
+ );
1679
1748
  saveLocalFilesBtn.hidden = !needPermission;
1680
- saveLocalFilesNote.textContent = problems.map((problem) => problem.message).join(" ");
1749
+ saveLocalFilesNote.textContent = problems
1750
+ .map((problem) => problem.message)
1751
+ .join(" ");
1681
1752
  return problems.length === 0;
1682
1753
  }
1683
1754
 
@@ -2218,7 +2289,7 @@ function applyLimits(): void {
2218
2289
  */
2219
2290
  function updateFromSelect() {
2220
2291
  const info = chapterList[select.selectedIndex];
2221
- rootStartMs = info.start;
2292
+ setRootStartMs(info.start);
2222
2293
  if (keepLimitsCheckbox.checked && limitsShowable) {
2223
2294
  // Only the "Play this one" button changes. Playback carries on.
2224
2295
  applyLimits();
@@ -2265,7 +2336,7 @@ playRootBtn.addEventListener("click", () => {
2265
2336
  */
2266
2337
  function refreshChapters(): void {
2267
2338
  if (initChapters()) {
2268
- rootStartMs = chapterList[select.selectedIndex].start;
2339
+ setRootStartMs(chapterList[select.selectedIndex].start);
2269
2340
  applyLimits();
2270
2341
  // The range clamped itself to the new bounds; show the real position again. The
2271
2342
  // number input stays the source of truth, so a playhead past a shortened end is left
@@ -2323,8 +2394,11 @@ transcriptView = new TranscriptView({
2323
2394
  transcript(source) {
2324
2395
  const status = transcriptStatus(source);
2325
2396
  if (!status) return undefined;
2326
- return status.kind === "ready" ? status.transcript : (statusText(status) ?? "");
2397
+ return status.kind === "ready"
2398
+ ? status.transcript
2399
+ : (statusText(status) ?? "");
2327
2400
  },
2401
+ problem: (clip) => soundFileProblem(clip),
2328
2402
  seek: (rootMs) => timelineDisplay.onSeek?.(rootMs),
2329
2403
  selectClip: (clip) => timelineDisplay.onBlockClick?.(clip),
2330
2404
  selectedClip: () => selectedSoundClip,
@@ -2427,6 +2501,40 @@ function _onClipValueChanged(): void {
2427
2501
  /** Shortest a sound clip can be trimmed to by dragging, in ms. */
2428
2502
  const MIN_SOUND_CLIP_MS = 50;
2429
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
+
2430
2538
  /** How long the file `clip` plays from is, once it has been decoded. */
2431
2539
  function soundFileMs(clip: SoundClip): number | undefined {
2432
2540
  const buffer = soundtrack.getDecodedBuffer(clip.source);
@@ -2511,11 +2619,15 @@ function soundClipBlock(clip: SoundClip, ownerStart: number): TimelineBlock {
2511
2619
  return {
2512
2620
  id: clip,
2513
2621
  get label() {
2622
+ const problem = soundFileProblem(clip);
2623
+ if (problem !== undefined) return `⚠ ${problem}`;
2514
2624
  // Notes if there are any, or else the first few words, so clips can be
2515
2625
  // told apart even zoomed out.
2516
2626
  return clip.notes || clipText(clip, 6) || clip.source || "—";
2517
2627
  },
2518
- color: "#3aab3a",
2628
+ get color() {
2629
+ return soundFileProblem(clip) === undefined ? "#3aab3a" : "#9a3412";
2630
+ },
2519
2631
  lane: "sound",
2520
2632
  transcript: () => {
2521
2633
  // Asking is what queues the file for transcribing.
@@ -2737,7 +2849,16 @@ function saveState() {
2737
2849
  "limitsIndex",
2738
2850
  chapterList.findIndex((d) => d.selectable === limitsShowable).toString(),
2739
2851
  );
2740
- 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
+ );
2741
2862
  sessionStorage.setItem(
2742
2863
  "state",
2743
2864
  querySelector('input[name="onSectionEnd"]:checked', HTMLInputElement).value,
@@ -2839,7 +2960,8 @@ function openScheduleDB(): Promise<IDBDatabase> {
2839
2960
  // Versions 1–3 had a per-chapter "history" store. "videos" replaced it in v3, and v4
2840
2961
  // removes it. Also drop the directory handle left behind by the temporary
2841
2962
  // "Save All 3" button. See development-plans/single-tree-per-video.md.
2842
- if (db.objectStoreNames.contains("history")) db.deleteObjectStore("history");
2963
+ if (db.objectStoreNames.contains("history"))
2964
+ db.deleteObjectStore("history");
2843
2965
  if (oldVersion < 4)
2844
2966
  req.transaction!.objectStore("files").delete("__properties-dir__");
2845
2967
  };
@@ -3039,7 +3161,11 @@ const jsonSync = new SyncedFile({
3039
3161
  if (enabled) {
3040
3162
  // Only one file per video is synced (and so "active") at a time.
3041
3163
  for (const r of getAllReq.result as FileRecord[]) {
3042
- if (r.videoKey === toShowKey && r.filename !== filename && r.isActive)
3164
+ if (
3165
+ r.videoKey === toShowKey &&
3166
+ r.filename !== filename &&
3167
+ r.isActive
3168
+ )
3043
3169
  store.put({ ...r, isActive: false, syncEnabled: false });
3044
3170
  }
3045
3171
  }
@@ -3146,7 +3272,10 @@ function classDefaults(cls: new () => Showable): ClassDefaults {
3146
3272
  schedules: serializeSchedules(instance.schedules ?? []),
3147
3273
  scalars: serializeScalars(instance.scalars ?? []),
3148
3274
  duration: instance.duration,
3149
- schedulePropertyNames: propertyNamesOf(instance, instance.schedules ?? []),
3275
+ schedulePropertyNames: propertyNamesOf(
3276
+ instance,
3277
+ instance.schedules ?? [],
3278
+ ),
3150
3279
  scalarPropertyNames: propertyNamesOf(instance, instance.scalars ?? []),
3151
3280
  soundClips: instance.soundClips,
3152
3281
  };
@@ -3273,7 +3402,8 @@ function buildDiffText(): string {
3273
3402
  } else {
3274
3403
  // The live object's class, so the properties below type-check.
3275
3404
  const className = comp.constructor.name;
3276
- const cast = className && className !== "Object" ? ` as ${className}` : "";
3405
+ const cast =
3406
+ className && className !== "Object" ? ` as ${className}` : "";
3277
3407
  out.push(
3278
3408
  `${indent}// No howToGenerate for "${rk}", so this makes one the way the Visual Editor does.`,
3279
3409
  `${indent}const ${varName} = componentRegistry.get(${JSON.stringify(rk)})!.create()${cast};`,
@@ -3321,16 +3451,15 @@ function buildDiffText(): string {
3321
3451
 
3322
3452
  if (
3323
3453
  (comp.soundClips?.length || def.soundClips?.length) &&
3324
- JSON.stringify(comp.soundClips ?? []) !== JSON.stringify(def.soundClips ?? [])
3454
+ JSON.stringify(comp.soundClips ?? []) !==
3455
+ JSON.stringify(def.soundClips ?? [])
3325
3456
  ) {
3326
3457
  out.push(
3327
3458
  `${indent}${varName}.soundClips = ${JSON.stringify(comp.soundClips ?? [])};`,
3328
3459
  );
3329
3460
  }
3330
3461
 
3331
- out.push(
3332
- `${indent}${parentExpr}.replaceableComponents!.push(${varName});`,
3333
- );
3462
+ out.push(`${indent}${parentExpr}.replaceableComponents!.push(${varName});`);
3334
3463
 
3335
3464
  return out;
3336
3465
  }
@@ -3504,7 +3633,10 @@ function buildDiffText(): string {
3504
3633
  diffProperties(d, comp, childPath);
3505
3634
  diffReplaceable(d.components ?? [], comp, childPath);
3506
3635
  } else {
3507
- printPathIfNeeded([...path, d.userEditableDescription ?? d.registryKey]);
3636
+ printPathIfNeeded([
3637
+ ...path,
3638
+ d.userEditableDescription ?? d.registryKey,
3639
+ ]);
3508
3640
  lines.push(` [deleted]`);
3509
3641
  }
3510
3642
  }
@@ -3547,7 +3679,6 @@ function buildDiffText(): string {
3547
3679
  }
3548
3680
  }
3549
3681
 
3550
-
3551
3682
  // One tree, so one walk: diffNode() recurses through fixedComponents on its own.
3552
3683
  if (tsDefaultsTree) {
3553
3684
  diffNode(tsDefaultsTree, toShow, [toShow.description]);
@@ -3785,7 +3916,6 @@ function afterStateApplied(): void {
3785
3916
  soundtrack.request();
3786
3917
  }
3787
3918
 
3788
-
3789
3919
  /** Saves current schedule state to IndexedDB as a full data entry.
3790
3920
  * Pass force=true (💾 Save button) to bypass the ts-defaults-no-auto-save guard. */
3791
3921
  /**
@@ -3820,8 +3950,7 @@ async function saveVideoStateToDb(force: boolean): Promise<void> {
3820
3950
 
3821
3951
  // Nothing changed since the last data entry -- don't add a duplicate.
3822
3952
  const last = entries.findLast((e) => !isMarker(e)) as
3823
- | VideoDataEntry
3824
- | undefined;
3953
+ VideoDataEntry | undefined;
3825
3954
  if (last && JSON.stringify(last.tree) === newJson) return;
3826
3955
 
3827
3956
  const entry: VideoDataEntry = { timestamp: Date.now(), tree };
@@ -4387,7 +4516,7 @@ function buildScheduleSection(
4387
4516
  }
4388
4517
 
4389
4518
  function currentTimeMs() {
4390
- return playPositionSeconds.valueAsNumber * 1000;
4519
+ return playheadInVideoMs();
4391
4520
  }
4392
4521
 
4393
4522
  /**
@@ -4724,8 +4853,10 @@ function buildScheduleSection(
4724
4853
  } else {
4725
4854
  const none = document.createElement("span");
4726
4855
  none.textContent = "—";
4727
- none.title = "The last keyframe has no duration: nothing comes after it.";
4728
- 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";
4729
4860
  cell.append(none);
4730
4861
  }
4731
4862
  const atLabel = document.createElement("span");
@@ -4976,8 +5107,9 @@ function buildScheduleSection(
4976
5107
  "cellWidth",
4977
5108
  "cellHeight",
4978
5109
  ] as const;
4979
- const fieldInputs: Partial<Record<(typeof fields)[number], HTMLInputElement>> =
4980
- {};
5110
+ const fieldInputs: Partial<
5111
+ Record<(typeof fields)[number], HTMLInputElement>
5112
+ > = {};
4981
5113
  for (const field of fields) {
4982
5114
  const input = buildNumericInput(latKf.value[field], (n) => {
4983
5115
  latKf.value = { ...latKf.value, [field]: n };
@@ -5410,7 +5542,11 @@ function updateComponentEditor(selectable: Showable) {
5410
5542
  if (i !== -1) arr.splice(i, 1);
5411
5543
  replaceables.replace(arr);
5412
5544
  if (childStart !== undefined) {
5413
- playheadAfterRemoving(childStart, childStart + childDuration, chainEndMs);
5545
+ playheadAfterRemoving(
5546
+ childStart,
5547
+ childStart + childDuration,
5548
+ chainEndMs,
5549
+ );
5414
5550
  }
5415
5551
  if (selectedSlideChild === child) {
5416
5552
  selectedSlideChild = null;
@@ -5518,7 +5654,8 @@ function updateComponentEditor(selectable: Showable) {
5518
5654
  : selectedSlideChild.replaceableComponents !== undefined
5519
5655
  ? selectedSlideChild
5520
5656
  : null;
5521
- const displayName = (s: Showable) => s.userEditableDescription ?? s.description;
5657
+ const displayName = (s: Showable) =>
5658
+ s.userEditableDescription ?? s.description;
5522
5659
 
5523
5660
  const toolbar = document.createElement("div");
5524
5661
  toolbar.className = "components-toolbar";
@@ -5663,13 +5800,14 @@ function buildSoundClipSection(selectable: Showable): HTMLElement {
5663
5800
  const header = document.createElement("div");
5664
5801
  header.style.cssText =
5665
5802
  "display:flex;align-items:center;gap:0.4em;margin-bottom:0.3em;font-size:0.85em;color:#555";
5666
- header.textContent = "Times are in ms, measured from the start of this component.";
5667
- const playheadInOwner = () =>
5668
- 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);
5669
5806
  const addBtn = document.createElement("button");
5670
5807
  addBtn.type = "button";
5671
5808
  addBtn.textContent = "+ Add";
5672
- 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.";
5673
5811
  addBtn.style.marginLeft = "auto";
5674
5812
  addBtn.addEventListener("click", () => {
5675
5813
  const clip: SoundClip = { source: "", startMsIntoScene: playheadInOwner() };
@@ -5694,7 +5832,9 @@ function buildSoundClipSection(selectable: Showable): HTMLElement {
5694
5832
  }
5695
5833
  const pasted = parseSoundClips(text);
5696
5834
  if (pasted.length === 0) {
5697
- 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
+ );
5698
5838
  return;
5699
5839
  }
5700
5840
  ensureList();
@@ -5887,6 +6027,18 @@ function buildSoundClipSection(selectable: Showable): HTMLElement {
5887
6027
  });
5888
6028
  row2.append(srcLabel, sourceInput);
5889
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
+
5890
6042
  // Row 3: numeric time fields
5891
6043
  const row3 = document.createElement("div");
5892
6044
  row3.style.cssText =
@@ -5969,7 +6121,8 @@ function buildSoundClipSection(selectable: Showable): HTMLElement {
5969
6121
  row4.style.cssText =
5970
6122
  "display:flex;gap:0.4em;align-items:center;margin-top:0.2em;flex-wrap:wrap;font-size:0.85em";
5971
6123
  const ownerLabel = document.createElement("label");
5972
- 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";
5973
6126
  ownerLabel.textContent = "owner:";
5974
6127
  ownerLabel.title =
5975
6128
  "Which component this sound belongs to. It moves when its owner moves. " +
@@ -6020,7 +6173,7 @@ function buildSoundClipSection(selectable: Showable): HTMLElement {
6020
6173
  soundClipSyncCallbacks.push(drawPlaysAt);
6021
6174
  row4.append(ownerLabel, playsAt);
6022
6175
 
6023
- card.append(row1, row2, row3, row4);
6176
+ card.append(row1, row2, problemLine, row3, row4);
6024
6177
  section.append(card);
6025
6178
  if (clip === selectedSoundClip) {
6026
6179
  requestAnimationFrame(() => card.scrollIntoView({ block: "nearest" }));
@@ -6098,7 +6251,10 @@ function updateScheduleEditor(selectable: Showable) {
6098
6251
  soundClipSyncCallbacks.length = 0;
6099
6252
  rectAspectLock = null;
6100
6253
  // A highlighted sound clip stays highlighted only while its owner is selected.
6101
- if (selectedSoundClip && !selectable.soundClips?.includes(selectedSoundClip)) {
6254
+ if (
6255
+ selectedSoundClip &&
6256
+ !selectable.soundClips?.includes(selectedSoundClip)
6257
+ ) {
6102
6258
  selectedSoundClip = undefined;
6103
6259
  }
6104
6260
  timelineDisplay.setSelectedSoundId(selectedSoundClip);
@@ -6224,7 +6380,10 @@ function updateScheduleEditor(selectable: Showable) {
6224
6380
  return playheadInRootMs() - ownerStart;
6225
6381
  },
6226
6382
  progressChanged() {
6227
- activeRootComponentEditor?.update(selectable, selectable.progressSchedule);
6383
+ activeRootComponentEditor?.update(
6384
+ selectable,
6385
+ selectable.progressSchedule,
6386
+ );
6228
6387
  markDirty();
6229
6388
  // Rebuild so the Progress table shows the new keyframes.
6230
6389
  updateScheduleEditor(selectable);
@@ -6572,9 +6731,7 @@ function rectHandlePositions(
6572
6731
  * level, so local == logical and no conversion is needed).
6573
6732
  */
6574
6733
  function getMarkerRelTf(): DOMMatrix | null {
6575
- const component =
6576
- selectedSlideChild ??
6577
- currentRoot();
6734
+ const component = selectedSlideChild ?? currentRoot();
6578
6735
  if (!component) return null;
6579
6736
  const compTf = componentTransforms.get(component);
6580
6737
  if (!compTf) return null;
@@ -6715,7 +6872,10 @@ function drawLatticeOutline(
6715
6872
  }
6716
6873
 
6717
6874
  /** Where the lattice's cell-size control point sits: bottom-right of the top-left cell. */
6718
- function latticeCellHandlePosition(value: LatticeValue): { x: number; y: number } {
6875
+ function latticeCellHandlePosition(value: LatticeValue): {
6876
+ x: number;
6877
+ y: number;
6878
+ } {
6719
6879
  const lattice = new Lattice(value);
6720
6880
  const cell = lattice.cellRect(0, 0);
6721
6881
  return { x: cell.x + cell.width, y: cell.y + cell.height };
@@ -7426,6 +7586,11 @@ function applyMarkerDrag(localX: number, localY: number, shiftKey = false) {
7426
7586
  // So when you configure the web page, and you hit refresh, or the page automatically
7427
7587
  // refreshes, you don't lose your settings.
7428
7588
  try {
7589
+ if (sessionStorage.getItem("playPositionLocal") === "0") {
7590
+ const playheadMs = playheadInVideoMs();
7591
+ playPositionLocal.checked = false;
7592
+ loadPlayPositionSeconds(playheadMs);
7593
+ }
7429
7594
  const index = sessionStorage.getItem("index");
7430
7595
  const timeInSeconds = sessionStorage.getItem("timeInSeconds");
7431
7596
  const state = sessionStorage.getItem("state");
@@ -7440,7 +7605,9 @@ function applyMarkerDrag(localX: number, localY: number, shiftKey = false) {
7440
7605
  updateFromSelect();
7441
7606
  if (sessionStorage.getItem("keepLimits") === "1") {
7442
7607
  keepLimitsCheckbox.checked = true;
7443
- const limitsIndex = parseIntX(sessionStorage.getItem("limitsIndex") ?? "");
7608
+ const limitsIndex = parseIntX(
7609
+ sessionStorage.getItem("limitsIndex") ?? "",
7610
+ );
7444
7611
  const saved =
7445
7612
  limitsIndex === undefined ? undefined : chapterList[limitsIndex];
7446
7613
  if (saved) {
@@ -7691,6 +7858,12 @@ getById("recordJustSound", HTMLButtonElement).addEventListener(
7691
7858
  const before = infoDiv.innerHTML;
7692
7859
  infoDiv.innerHTML = "Waiting for the sound…";
7693
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
+ }
7694
7867
  infoDiv.innerHTML = before;
7695
7868
  downloadBlob("sound_file.wav", soundtrack.mix(0, toShow.duration).toBlob());
7696
7869
  },
@@ -7721,7 +7894,8 @@ function renderNewDebugLogEntries(): void {
7721
7894
  debugLogPre.scrollTop + debugLogPre.clientHeight >=
7722
7895
  debugLogPre.scrollHeight - 4;
7723
7896
  const newLines = newEntries.map(
7724
- (entry) => `${(entry.time / 1000).toFixed(3)} [${entry.tag}] ${entry.message}`,
7897
+ (entry) =>
7898
+ `${(entry.time / 1000).toFixed(3)} [${entry.tag}] ${entry.message}`,
7725
7899
  );
7726
7900
  const allLines = debugLogPre.textContent
7727
7901
  ? debugLogPre.textContent.split("\n").concat(newLines)
@@ -7732,19 +7906,18 @@ function renderNewDebugLogEntries(): void {
7732
7906
  }
7733
7907
  }
7734
7908
  setInterval(renderNewDebugLogEntries, 250);
7735
- getById("debugLogClearBtn", HTMLButtonElement).addEventListener(
7736
- "click",
7737
- () => {
7738
- debugLogPre.textContent = "";
7739
- },
7740
- );
7909
+ getById("debugLogClearBtn", HTMLButtonElement).addEventListener("click", () => {
7910
+ debugLogPre.textContent = "";
7911
+ });
7741
7912
 
7742
7913
  getById("dumpDbBtn", HTMLButtonElement).addEventListener("click", async () => {
7743
7914
  const videoRecord = await readVideoHistory();
7744
7915
  const pre = getById("dbDump", HTMLPreElement);
7745
7916
  const lines: string[] = [];
7746
7917
 
7747
- lines.push(`=== videos["${toShowKey}"] — ${videoRecord?.entries.length ?? 0} entr(ies) ===`);
7918
+ lines.push(
7919
+ `=== videos["${toShowKey}"] — ${videoRecord?.entries.length ?? 0} entr(ies) ===`,
7920
+ );
7748
7921
  const latest = videoRecord?.entries.at(-1);
7749
7922
  lines.push(latest ? JSON.stringify(latest, null, 2) : "(none)");
7750
7923
  pre.textContent = lines.join("\n");