canvas-recorder-lib 0.7.1 → 0.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/README.md +51 -8
  2. package/dev/audio-builder.ts +5 -1
  3. package/dev/canvas-recorder.css +15 -4
  4. package/dev/canvas-recorder.ts +518 -131
  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 +375 -85
  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 +35 -1
  110. package/dist/lib/main-control.d.ts.map +1 -1
  111. package/dist/lib/main-control.js +76 -0
  112. package/dist/lib/main-control.js.map +1 -1
  113. package/dist/src/corner-rounder.d.ts.map +1 -1
  114. package/dist/src/corner-rounder.js +1 -1
  115. package/dist/src/corner-rounder.js.map +1 -1
  116. package/dist/src/local-files.d.ts.map +1 -1
  117. package/dist/src/local-files.js +5 -2
  118. package/dist/src/local-files.js.map +1 -1
  119. package/dist/src/peano-fourier/fourier-shared.d.ts +7 -0
  120. package/dist/src/peano-fourier/fourier-shared.d.ts.map +1 -1
  121. package/dist/src/peano-fourier/fourier-shared.js +8 -1
  122. package/dist/src/peano-fourier/fourier-shared.js.map +1 -1
  123. package/dist/src/showable.d.ts +74 -0
  124. package/dist/src/showable.d.ts.map +1 -1
  125. package/dist/src/showable.js.map +1 -1
  126. package/dist/src/slide-components/fourier.d.ts.map +1 -1
  127. package/dist/src/slide-components/fourier.js +12 -4
  128. package/dist/src/slide-components/fourier.js.map +1 -1
  129. package/dist/src/slide-components/image.d.ts.map +1 -1
  130. package/dist/src/slide-components/image.js +1 -1
  131. package/dist/src/slide-components/image.js.map +1 -1
  132. package/dist/src/slide-components/in-parallel.d.ts.map +1 -1
  133. package/dist/src/slide-components/in-parallel.js.map +1 -1
  134. package/dist/src/slide-components/multi-text.d.ts.map +1 -1
  135. package/dist/src/slide-components/multi-text.js +1 -1
  136. package/dist/src/slide-components/multi-text.js.map +1 -1
  137. package/dist/src/slide-components/rectangle.d.ts.map +1 -1
  138. package/dist/src/slide-components/rectangle.js +1 -1
  139. package/dist/src/slide-components/rectangle.js.map +1 -1
  140. package/dist/src/slide-components/registry.js.map +1 -1
  141. package/dist/src/slide-components/serialize.d.ts.map +1 -1
  142. package/dist/src/slide-components/serialize.js +2 -1
  143. package/dist/src/slide-components/serialize.js.map +1 -1
  144. package/dist/src/slide-components/split-video-clip.d.ts.map +1 -1
  145. package/dist/src/slide-components/split-video-clip.js +4 -1
  146. package/dist/src/slide-components/split-video-clip.js.map +1 -1
  147. package/dist/src/slide-components/video-clip.d.ts.map +1 -1
  148. package/dist/src/slide-components/video-clip.js +7 -4
  149. package/dist/src/slide-components/video-clip.js.map +1 -1
  150. package/dist/src/slide-components/video-info.d.ts.map +1 -1
  151. package/dist/src/slide-components/video-info.js.map +1 -1
  152. package/dist/src/slow-image-sources.d.ts.map +1 -1
  153. package/dist/src/slow-image-sources.js +1 -1
  154. package/dist/src/slow-image-sources.js.map +1 -1
  155. package/dist/src/snapshot.d.ts.map +1 -1
  156. package/dist/src/snapshot.js +1 -1
  157. package/dist/src/snapshot.js.map +1 -1
  158. package/dist/src/utility.d.ts.map +1 -1
  159. package/dist/src/utility.js +1 -3
  160. package/dist/src/utility.js.map +1 -1
  161. package/lib/main-control.ts +95 -2
  162. package/package.json +4 -1
  163. package/src/corner-rounder.ts +5 -12
  164. package/src/glib/letters-base.ts +1 -1
  165. package/src/local-files.ts +19 -6
  166. package/src/peano-fourier/fourier-shared.ts +8 -1
  167. package/src/showable.ts +79 -0
  168. package/src/slide-components/fourier.ts +32 -10
  169. package/src/slide-components/image.ts +4 -1
  170. package/src/slide-components/in-parallel.ts +1 -2
  171. package/src/slide-components/multi-text.ts +17 -4
  172. package/src/slide-components/rectangle.ts +4 -1
  173. package/src/slide-components/registry.ts +1 -1
  174. package/src/slide-components/serialize.ts +4 -1
  175. package/src/slide-components/split-video-clip.ts +4 -1
  176. package/src/slide-components/video-clip.ts +21 -8
  177. package/src/slide-components/video-info.ts +4 -1
  178. package/src/slow-image-sources.ts +5 -1
  179. package/src/snapshot.ts +13 -4
  180. package/src/utility.ts +70 -33
@@ -1,5 +1,5 @@
1
1
  import "./canvas-recorder.css";
2
- import { assertNonNullable, FIGURE_SPACE, parseFloatX, parseIntX, } from "phil-lib/misc";
2
+ import { assertNonNullable, FIGURE_SPACE, parseFloatX, } from "phil-lib/misc";
3
3
  import { AnimationLoop, getById, querySelector, } from "phil-lib/client-misc";
4
4
  import { Output, StreamTarget, CanvasSource, Mp4OutputFormat, AudioBufferSource, QUALITY_HIGH, } from "mediabunny";
5
5
  import { discreteKeyframes, interpolateColors, interpolateLattices, interpolateNumbers, interpolatePoints, interpolateRects, } from "../src/interpolate.js";
@@ -136,7 +136,7 @@ function applyZoom(zoom, px = panX, py = panY) {
136
136
  canvas.height = physH;
137
137
  canvas.style.width = `${cssW}px`;
138
138
  canvas.style.height = `${cssH}px`;
139
- showFrame(playPositionSeconds.valueAsNumber * 1000, true);
139
+ showFrame(playheadInVideoMs(), true);
140
140
  }
141
141
  [panX, panY] = clampPan(cssW, cssH, px, py);
142
142
  canvas.style.left = `${panX}px`;
@@ -166,7 +166,7 @@ function zoomToFit() {
166
166
  canvas.style.left = `${Math.round((vpW - cssW) / 2)}px`;
167
167
  canvas.style.top = `${Math.round((vpH - cssH) / 2)}px`;
168
168
  // Immediately redraw so the canvas clear doesn't show as a gray flash.
169
- showFrame(playPositionSeconds.valueAsNumber * 1000, true);
169
+ showFrame(playheadInVideoMs(), true);
170
170
  }
171
171
  zoomSelect.addEventListener("change", () => {
172
172
  if (zoomSelect.value === "fit") {
@@ -261,9 +261,10 @@ function showVideoSize(size) {
261
261
  videoSizeWarning.title = stretched
262
262
  ? `The pixels are ${pixelAspect.toFixed(3)} : 1 and the units are ${unitAspect.toFixed(3)} : 1, so the picture is stretched to fit.`
263
263
  : "";
264
- getById("videoSizeControls", HTMLSpanElement).title = canvasRecorder.sizeLocked
265
- ? "The size of the video. This program sets it, so it can't be changed here."
266
- : "The size of the video. Pixels: the saved file. Units: the coordinates everything is drawn in. Remembered for this video.";
264
+ getById("videoSizeControls", HTMLSpanElement).title =
265
+ canvasRecorder.sizeLocked
266
+ ? "The size of the video. This program sets it, so it can't be changed here."
267
+ : "The size of the video. Pixels: the saved file. Units: the coordinates everything is drawn in. Remembered for this video.";
267
268
  }
268
269
  showVideoSize(canvasRecorder.size);
269
270
  /**
@@ -326,9 +327,12 @@ function updateLocalFilesButton() {
326
327
  const names = localFilesNeedingPermission();
327
328
  localFilesBtn.hidden = names.length === 0;
328
329
  localFilesBtn.textContent =
329
- names.length === 1 ? "🔓 Allow local file" : `🔓 Allow ${names.length} local files`;
330
+ names.length === 1
331
+ ? "🔓 Allow local file"
332
+ : `🔓 Allow ${names.length} local files`;
330
333
  localFilesBtn.title =
331
- "The browser needs your OK before it reads these files again:\n" + names.join("\n");
334
+ "The browser needs your OK before it reads these files again:\n" +
335
+ names.join("\n");
332
336
  }
333
337
  onLocalFilesChange(updateLocalFilesButton);
334
338
  /** Ask about every file that needs it. Then the sounds can load. */
@@ -376,6 +380,7 @@ function showFrame(timeInMs, live) {
376
380
  transcriptView?.update(timeInMs - rootStartMs, playCheckBox.checked);
377
381
  for (const update of goToButtonUpdaters)
378
382
  update();
383
+ editorPanelsTimeChanged();
379
384
  context.reset();
380
385
  context.setTransform(mainTransform());
381
386
  if (live) {
@@ -461,29 +466,65 @@ const playPositionRange = getById("playPositionRange", HTMLInputElement);
461
466
  * This can be a number outside of the normal range of the current section.
462
467
  * This, like all user visible number, is measured in seconds. Internal
463
468
  * things measure time in milliseconds.
469
+ *
470
+ * It's measured from the start of the Visual Editor's root when
471
+ * {@link playPositionLocal} is checked, otherwise from the start of the video.
472
+ * Read it with {@link playheadInVideoMs} and write it with
473
+ * {@link loadPlayPositionSeconds}, which take care of that.
464
474
  */
465
475
  const playPositionSeconds = getById("playPositionSeconds", HTMLInputElement);
476
+ /**
477
+ * Checked: {@link playPositionSeconds} is measured from the start of the
478
+ * Visual Editor's root. Unchecked: from the start of the video.
479
+ */
480
+ const playPositionLocal = getById("playPositionLocal", HTMLInputElement);
466
481
  /**
467
482
  * When we get to the end of the section, automatically jump back to the
468
483
  * beginning of the section.
469
484
  */
470
485
  const repeatRadioButton = querySelector('input[name="onSectionEnd"][value="repeat"]', HTMLInputElement);
486
+ /**
487
+ * The playhead, measured from the start of the whole video.
488
+ * {@link playPositionSeconds} is the source of truth.
489
+ */
490
+ function playheadInVideoMs() {
491
+ const shownMs = playPositionSeconds.valueAsNumber * 1000;
492
+ return playPositionLocal.checked ? shownMs + rootStartMs : shownMs;
493
+ }
471
494
  /**
472
495
  * The playhead, measured from the start of the Visual Editor's root: the
473
496
  * time its keyframes use.
474
497
  */
475
498
  function playheadInRootMs() {
476
- return playPositionSeconds.valueAsNumber * 1000 - rootStartMs;
499
+ return playheadInVideoMs() - rootStartMs;
477
500
  }
478
501
  /**
479
502
  * Update the input that shows the time as a number.
480
- * @param timeInMs The time to display in the number control.
503
+ * @param timeInMs The time to display in the number control, measured from the start of the
504
+ * video. It's shown from the start of the root instead if {@link playPositionLocal} says so.
481
505
  * This is *automatically* converted to seconds and rounded to the nearest ⅒ of a millisecond.
482
506
  * We only use milliseconds, not seconds, inside the code.
483
507
  */
484
508
  function loadPlayPositionSeconds(timeInMs) {
485
- playPositionSeconds.value = (timeInMs / 1000).toFixed(4);
509
+ const shownMs = playPositionLocal.checked ? timeInMs - rootStartMs : timeInMs;
510
+ playPositionSeconds.value = (shownMs / 1000).toFixed(4);
486
511
  }
512
+ /**
513
+ * Move the Visual Editor's root. The playhead stays where it is in the video, so a local
514
+ * {@link playPositionSeconds} changes to match.
515
+ */
516
+ function setRootStartMs(ms) {
517
+ if (ms === rootStartMs)
518
+ return;
519
+ const playheadMs = playheadInVideoMs();
520
+ rootStartMs = ms;
521
+ loadPlayPositionSeconds(playheadMs);
522
+ }
523
+ playPositionLocal.addEventListener("input", () => {
524
+ // The same time, shown the other way. The number still means what the checkbox used to say.
525
+ const shownMs = playPositionSeconds.valueAsNumber * 1000;
526
+ loadPlayPositionSeconds(playPositionLocal.checked ? shownMs : shownMs + rootStartMs);
527
+ });
487
528
  /**
488
529
  * Update the range input to show the same time as the number input.
489
530
  *
@@ -493,7 +534,7 @@ function loadPlayPositionSeconds(timeInMs) {
493
534
  * If the user changes the range input, and the value is immediately copied to the number input for use in the program.
494
535
  */
495
536
  function loadPlayPositionRange() {
496
- playPositionRange.valueAsNumber = playPositionSeconds.valueAsNumber * 1000;
537
+ playPositionRange.valueAsNumber = playheadInVideoMs();
497
538
  }
498
539
  // The same rate as the decoded files and the voice recorder, whatever the hardware uses.
499
540
  const audioContext = new AudioContext({ sampleRate: SAMPLE_RATE });
@@ -510,7 +551,9 @@ const soundtrack = new Soundtrack({
510
551
  root: () => toShow,
511
552
  // Sound clips on the timeline can now show their waveforms, and the ones
512
553
  // that play to the end of their file now know how long that is.
513
- onDecoded: () => timelineDisplay.redraw(),
554
+ onDecoded: soundFileLoaded,
555
+ // Marked ⚠, on the timeline and on its card. See soundFileProblem().
556
+ onFailed: soundFileLoaded,
514
557
  // The new file may be a local one that needs 🔓.
515
558
  onNewSource: () => checkVideosLocalFiles(),
516
559
  });
@@ -691,7 +734,7 @@ const animationLoop = new AnimationLoop((_rAFTimeInMs) => {
691
734
  if (voiceRecording && !voiceChirping)
692
735
  stopVoiceRecording();
693
736
  playPositionSeconds.disabled = false;
694
- showFrame(playPositionSeconds.valueAsNumber * 1000, true);
737
+ showFrame(playheadInVideoMs(), true);
695
738
  return;
696
739
  }
697
740
  // Playing.
@@ -699,7 +742,7 @@ const animationLoop = new AnimationLoop((_rAFTimeInMs) => {
699
742
  if (!audioPlaying && !rafFallbackPlaying) {
700
743
  // Not running: first play, after pause/seek, or after repeat.
701
744
  // Clips whose file isn't decoded yet join in when it is, so nothing waits for them.
702
- let startMs = playPositionSeconds.valueAsNumber * 1000;
745
+ let startMs = playheadInVideoMs();
703
746
  if (startMs >= sectionEndTime - 0.05) {
704
747
  // At the end — jump to the beginning.
705
748
  startMs = sectionStartTime;
@@ -795,7 +838,7 @@ addEventListener("keypress", (event) => {
795
838
  }
796
839
  });
797
840
  getById("back5s", HTMLButtonElement).addEventListener("click", () => {
798
- const backMs = Math.max(sectionStartTime, playPositionSeconds.valueAsNumber * 1000 - 5000);
841
+ const backMs = Math.max(sectionStartTime, playheadInVideoMs() - 5000);
799
842
  loadPlayPositionSeconds(backMs);
800
843
  loadPlayPositionRange();
801
844
  stopAudio();
@@ -843,7 +886,7 @@ function framesBetween(startMs, endMs) {
843
886
  * It stays inside the play limits.
844
887
  */
845
888
  function stepOneFrame(direction) {
846
- const position = framePosition(playPositionSeconds.valueAsNumber * 1000);
889
+ const position = framePosition(playheadInVideoMs());
847
890
  let frame = direction > 0
848
891
  ? Math.floor(position + FRAME_TOLERANCE) + 1
849
892
  : Math.ceil(position - FRAME_TOLERANCE) - 1;
@@ -1094,6 +1137,12 @@ async function startRecording(saveStartMs = 0, saveEndMs = toShow.duration, pixe
1094
1137
  },
1095
1138
  ],
1096
1139
  });
1140
+ // The newest soundtrack, with every file in it decoded. Right after a reload or an
1141
+ // edit, that can take a moment. (After the file picker, which needs the click.)
1142
+ // Before anything is written: a sound that can't be read stops the save here.
1143
+ infoDiv.innerHTML = "Waiting for the sound…";
1144
+ await soundtrack.ready();
1145
+ assertSoundFilesLoaded();
1097
1146
  const writableStream = await fileHandle.createWritable();
1098
1147
  // Set up Mediabunny output (streaming to file)
1099
1148
  output = new Output({
@@ -1112,10 +1161,6 @@ async function startRecording(saveStartMs = 0, saveEndMs = toShow.duration, pixe
1112
1161
  const firstFrame = firstFrameAtOrAfter(saveStartMs);
1113
1162
  // The file starts where its first frame starts, so the sound starts there too.
1114
1163
  const audioStartMs = (firstFrame * 1000) / FPS;
1115
- // The newest soundtrack, with every file in it decoded. Right after a reload or an
1116
- // edit, that can take a moment. (After the file picker, which needs the click.)
1117
- infoDiv.innerHTML = "Waiting for the sound…";
1118
- await soundtrack.ready();
1119
1164
  const audioBuffer = soundtrack
1120
1165
  .mix(audioStartMs, Math.min(saveEndMs, toShow.duration))
1121
1166
  .getAudioBuffer();
@@ -1268,7 +1313,10 @@ const saveOkBtn = getById("saveOkBtn", HTMLButtonElement);
1268
1313
  * HEVC stores color at half resolution (4:2:0), so both numbers must be even.
1269
1314
  */
1270
1315
  function saveSizeProblem(width, height) {
1271
- if (!(Number.isInteger(width) && width > 0 && Number.isInteger(height) && height > 0)) {
1316
+ if (!(Number.isInteger(width) &&
1317
+ width > 0 &&
1318
+ Number.isInteger(height) &&
1319
+ height > 0)) {
1272
1320
  return "The size must be two whole numbers of pixels.";
1273
1321
  }
1274
1322
  if (width % 2 || height % 2) {
@@ -1291,7 +1339,7 @@ function updateSaveSizeNote() {
1291
1339
  saveSizeNote.style.color = "#555";
1292
1340
  }
1293
1341
  else {
1294
- const stretched = Math.abs((width / height) / (pixelWidth / pixelHeight) - 1) > 0.001;
1342
+ const stretched = Math.abs(width / height / (pixelWidth / pixelHeight) - 1) > 0.001;
1295
1343
  saveSizeNote.textContent = stretched
1296
1344
  ? `Stretched: the video is ${pixelWidth} × ${pixelHeight}.`
1297
1345
  : `${Math.round((width / pixelWidth) * 100)}% of the video's ${pixelWidth} × ${pixelHeight}.`;
@@ -1415,7 +1463,9 @@ async function saveDialogLocalFilesReady() {
1415
1463
  saveLocalFilesRow.hidden = problems.length === 0;
1416
1464
  const needPermission = problems.some((problem) => problem.reason === "permission");
1417
1465
  saveLocalFilesBtn.hidden = !needPermission;
1418
- saveLocalFilesNote.textContent = problems.map((problem) => problem.message).join(" ");
1466
+ saveLocalFilesNote.textContent = problems
1467
+ .map((problem) => problem.message)
1468
+ .join(" ");
1419
1469
  return problems.length === 0;
1420
1470
  }
1421
1471
  saveLocalFilesBtn.addEventListener("click", async () => {
@@ -1522,6 +1572,46 @@ initChapters();
1522
1572
  function currentRoot() {
1523
1573
  return chapterList[select.selectedIndex]?.selectable;
1524
1574
  }
1575
+ /** The name the chapter `<select>` shows. */
1576
+ function chapterName(showable) {
1577
+ return showable.userEditableDescription ?? showable.description;
1578
+ }
1579
+ /** The way down from the top of the video to this chapter. Find it again with {@link findChapter}. */
1580
+ function chapterPath(info) {
1581
+ const path = [];
1582
+ for (let step = info; step.parent; step = step.parent) {
1583
+ const child = step.selectable;
1584
+ const index = step.parent.selectable.children?.findIndex((c) => c.child === child) ??
1585
+ -1;
1586
+ path.push({ index, name: chapterName(child) });
1587
+ }
1588
+ return path.reverse();
1589
+ }
1590
+ /**
1591
+ * Find a chapter again from its {@link chapterPath}, in a tree that may have changed.
1592
+ *
1593
+ * At each step, the child at the same position if it still has the same name, otherwise the
1594
+ * first sibling with that name. If a step can't be found, the deepest chapter found so far.
1595
+ * @returns An index into {@link chapterList}. 0, the whole video, if nothing matched.
1596
+ */
1597
+ function findChapter(path) {
1598
+ let current = toShow;
1599
+ let found = 0;
1600
+ for (const { index, name } of path) {
1601
+ const children = current.children ?? [];
1602
+ const atIndex = children[index]?.child;
1603
+ const next = atIndex && chapterName(atIndex) === name
1604
+ ? atIndex
1605
+ : children.find((c) => chapterName(c.child) === name)?.child;
1606
+ if (!next)
1607
+ break;
1608
+ current = next;
1609
+ const position = chapterList.findIndex((d) => d.selectable === next);
1610
+ if (position >= 0)
1611
+ found = position;
1612
+ }
1613
+ return found;
1614
+ }
1525
1615
  /** When checked, picking another root leaves the play limits alone. */
1526
1616
  const keepLimitsCheckbox = getById("keepLimits", HTMLInputElement);
1527
1617
  /** Says what the play limits are, below the chapter `<select>`. */
@@ -1551,6 +1641,8 @@ const visualEditorAPI = {
1551
1641
  soundtrack.request();
1552
1642
  }
1553
1643
  else if (howMuch === "properties") {
1644
+ // A property changed, so it has to be saved, like any other edit.
1645
+ markDirty();
1554
1646
  updateScheduleEditor(selectedSlideChild ?? selectable);
1555
1647
  }
1556
1648
  else {
@@ -1705,6 +1797,103 @@ const timelineWordsMemo = new WeakMap();
1705
1797
  * Cleared whenever {@link updateScheduleEditor} rebuilds.
1706
1798
  */
1707
1799
  const scheduleEditorRefreshers = [];
1800
+ /**
1801
+ * The panels shown now. Rebuilt by {@link updateScheduleEditor}.
1802
+ * Declared up here because the first schedule editor is built while this module is still loading.
1803
+ */
1804
+ const activePanels = [];
1805
+ /** Where `component` starts, in the Visual Editor's root's time. */
1806
+ function componentStartMs(component) {
1807
+ const root = currentRoot();
1808
+ return root ? (startWithin(root, component) ?? 0) : 0;
1809
+ }
1810
+ /** The playhead in `component`'s own time: what its `show()` gets as `timeInMs`. */
1811
+ function componentTimeMs(component) {
1812
+ return playheadInRootMs() - componentStartMs(component);
1813
+ }
1814
+ /** Show `reason` where `active`'s panel was, and stop calling that panel. */
1815
+ function panelFailed(active, reason) {
1816
+ console.error(reason);
1817
+ active.live = false;
1818
+ const name = active.component.userEditableDescription ?? active.component.description;
1819
+ const line = document.createElement("div");
1820
+ line.style.cssText = "color:#b00;margin-bottom:0.4em";
1821
+ line.textContent = `✗ A panel for "${name}" failed: ${String(reason)}`;
1822
+ active.element.replaceWith(line);
1823
+ active.element = line;
1824
+ }
1825
+ /** Call into a panel, unless it's suspended or broken. A bug in a panel mustn't break the editor. */
1826
+ function callPanel(active, call) {
1827
+ if (!active.live)
1828
+ return;
1829
+ try {
1830
+ call(active.panel);
1831
+ }
1832
+ catch (reason) {
1833
+ panelFailed(active, reason);
1834
+ }
1835
+ }
1836
+ /** Tell each panel it's going away. Called before every rebuild. */
1837
+ function suspendEditorPanels() {
1838
+ for (const active of activePanels.splice(0)) {
1839
+ callPanel(active, (panel) => panel.suspend?.());
1840
+ active.live = false;
1841
+ }
1842
+ }
1843
+ /**
1844
+ * Start `component`'s panels: its own {@link Showable.editorPanel}, then the project's,
1845
+ * from `canvasRecorder.addEditorPanel()`.
1846
+ * @returns The elements to show, in order.
1847
+ */
1848
+ function startEditorPanels(component) {
1849
+ return canvasRecorder.editorPanelsFor(component).map((panel) => {
1850
+ const active = {
1851
+ panel,
1852
+ component,
1853
+ element: document.createElement("div"),
1854
+ live: true,
1855
+ };
1856
+ activePanels.push(active);
1857
+ const api = {
1858
+ getTimeMs: () => componentTimeMs(component),
1859
+ seek(ms) {
1860
+ if (!active.live)
1861
+ return;
1862
+ visualEditorAPI.seek(ms + componentStartMs(component));
1863
+ },
1864
+ propertyChanged(property) {
1865
+ if (!active.live)
1866
+ return;
1867
+ activeRootComponentEditor?.update(component, property);
1868
+ markDirty();
1869
+ // Rebuild so the tables show the new value. That restarts this panel too.
1870
+ updateScheduleEditor(component);
1871
+ },
1872
+ refreshGUI(howMuch) {
1873
+ if (!active.live)
1874
+ return;
1875
+ visualEditorAPI.refreshGUI(howMuch);
1876
+ },
1877
+ };
1878
+ callPanel(active, (panel) => {
1879
+ const element = panel.start(api);
1880
+ if (!(element instanceof HTMLElement)) {
1881
+ throw new Error("start() didn't return an HTMLElement.");
1882
+ }
1883
+ active.element = element;
1884
+ });
1885
+ // Every keystroke in the properties, and every duration change.
1886
+ scheduleEditorRefreshers.push(() => callPanel(active, (panel) => panel.update?.()));
1887
+ return active.element;
1888
+ });
1889
+ }
1890
+ /** The playhead moved. Called from {@link showFrame}. */
1891
+ function editorPanelsTimeChanged() {
1892
+ // A copy: a panel's call may rebuild the list.
1893
+ for (const active of [...activePanels]) {
1894
+ callPanel(active, (panel) => panel.timeChanged?.());
1895
+ }
1896
+ }
1708
1897
  /**
1709
1898
  * The schedules the user switched to **Durations**, as opposed to the
1710
1899
  * default, **Times**. See {@link buildScheduleSection}.
@@ -1844,7 +2033,7 @@ function applyLimits() {
1844
2033
  */
1845
2034
  function updateFromSelect() {
1846
2035
  const info = chapterList[select.selectedIndex];
1847
- rootStartMs = info.start;
2036
+ setRootStartMs(info.start);
1848
2037
  if (keepLimitsCheckbox.checked && limitsShowable) {
1849
2038
  // Only the "Play this one" button changes. Playback carries on.
1850
2039
  applyLimits();
@@ -1890,7 +2079,7 @@ playRootBtn.addEventListener("click", () => {
1890
2079
  */
1891
2080
  function refreshChapters() {
1892
2081
  if (initChapters()) {
1893
- rootStartMs = chapterList[select.selectedIndex].start;
2082
+ setRootStartMs(chapterList[select.selectedIndex].start);
1894
2083
  applyLimits();
1895
2084
  // The range clamped itself to the new bounds; show the real position again. The
1896
2085
  // number input stays the source of truth, so a playhead past a shortened end is left
@@ -1945,8 +2134,11 @@ transcriptView = new TranscriptView({
1945
2134
  const status = transcriptStatus(source);
1946
2135
  if (!status)
1947
2136
  return undefined;
1948
- return status.kind === "ready" ? status.transcript : (statusText(status) ?? "");
2137
+ return status.kind === "ready"
2138
+ ? status.transcript
2139
+ : (statusText(status) ?? "");
1949
2140
  },
2141
+ problem: (clip) => soundFileProblem(clip),
1950
2142
  seek: (rootMs) => timelineDisplay.onSeek?.(rootMs),
1951
2143
  selectClip: (clip) => timelineDisplay.onBlockClick?.(clip),
1952
2144
  selectedClip: () => selectedSoundClip,
@@ -2023,6 +2215,7 @@ timelineDisplay.onBlockClick = (id) => {
2023
2215
  updateComponentEditor(container);
2024
2216
  updateScheduleEditor(child);
2025
2217
  timelineDisplay.setSelectedId(child);
2218
+ activeRootComponentEditor?.selectionChanged(child);
2026
2219
  return true;
2027
2220
  }
2028
2221
  if (child.children?.length && findIn(child.children, child))
@@ -2047,6 +2240,35 @@ function _onClipValueChanged() {
2047
2240
  // MARK: Sound clips
2048
2241
  /** Shortest a sound clip can be trimmed to by dragging, in ms. */
2049
2242
  const MIN_SOUND_CLIP_MS = 50;
2243
+ /** A sound file was decoded, or failed: update the timeline and the Sound Clips cards. */
2244
+ function soundFileLoaded() {
2245
+ timelineDisplay.redraw();
2246
+ for (const cb of soundClipSyncCallbacks)
2247
+ cb();
2248
+ }
2249
+ /**
2250
+ * Why `clip`'s file can't be played, or undefined if nothing is wrong, as far as we know yet.
2251
+ * Shown on the timeline, on the clip's card and in the 📖 Text view. A missing file must not
2252
+ * look like a file full of silence, even when its old transcript still shows.
2253
+ */
2254
+ function soundFileProblem(clip) {
2255
+ const reason = soundtrack.failure(clip.source);
2256
+ if (reason === undefined)
2257
+ return undefined;
2258
+ return reason instanceof Error ? reason.message : String(reason);
2259
+ }
2260
+ /** Stop a save, if any sound in it can't be read. Otherwise the saved sound would have holes. */
2261
+ function assertSoundFilesLoaded() {
2262
+ const failed = soundtrack.failures();
2263
+ if (failed.length === 0)
2264
+ return;
2265
+ const { url, reason } = failed[0];
2266
+ const why = (reason instanceof Error ? reason.message : String(reason)).replace(/([^.!?)])$/, "$1.");
2267
+ const which = failed.length === 1
2268
+ ? ""
2269
+ : `${failed.length} sound files couldn't be read. The first: `;
2270
+ throw new Error(`${which}Can't play "${url}": ${why} Each clip that uses ${failed.length === 1 ? "it" : "one"} is marked ⚠ on the timeline.`);
2271
+ }
2050
2272
  /** How long the file `clip` plays from is, once it has been decoded. */
2051
2273
  function soundFileMs(clip) {
2052
2274
  const buffer = soundtrack.getDecodedBuffer(clip.source);
@@ -2125,11 +2347,16 @@ function soundClipBlock(clip, ownerStart) {
2125
2347
  return {
2126
2348
  id: clip,
2127
2349
  get label() {
2350
+ const problem = soundFileProblem(clip);
2351
+ if (problem !== undefined)
2352
+ return `⚠ ${problem}`;
2128
2353
  // Notes if there are any, or else the first few words, so clips can be
2129
2354
  // told apart even zoomed out.
2130
2355
  return clip.notes || clipText(clip, 6) || clip.source || "—";
2131
2356
  },
2132
- color: "#3aab3a",
2357
+ get color() {
2358
+ return soundFileProblem(clip) === undefined ? "#3aab3a" : "#9a3412";
2359
+ },
2133
2360
  lane: "sound",
2134
2361
  transcript: () => {
2135
2362
  // Asking is what queues the file for transcribing.
@@ -2322,18 +2549,72 @@ function _updateTimeline(selectable) {
2322
2549
  timelineDisplay.setBlocks(_buildTimelineBlocks(selectable));
2323
2550
  timelineDisplay.setSelectedId(selectedSlideChild ?? undefined);
2324
2551
  }
2552
+ /**
2553
+ * Read from the last session, waiting for the saved tree to load. If the page unloads
2554
+ * first, {@link saveState} saves this again, not the default place the page is showing.
2555
+ */
2556
+ let placeToRestore;
2557
+ function currentPlace() {
2558
+ const root = chapterList[select.selectedIndex];
2559
+ const limits = chapterList.find((d) => d.selectable === limitsShowable);
2560
+ const timeInRootMs = playheadInRootMs();
2561
+ return {
2562
+ rootPath: root ? chapterPath(root) : [],
2563
+ keepLimits: keepLimitsCheckbox.checked,
2564
+ limitsPath: limits ? chapterPath(limits) : null,
2565
+ timeInRootMs: isFinite(timeInRootMs) ? timeInRootMs : null,
2566
+ onSectionEnd: querySelector('input[name="onSectionEnd"]:checked', HTMLInputElement).value,
2567
+ wasPlaying: playCheckBox.checked,
2568
+ };
2569
+ }
2570
+ /** Parse what {@link saveState} wrote. undefined if there's nothing, or it's from an older version. */
2571
+ function parseSavedPlace(json) {
2572
+ if (!json)
2573
+ return undefined;
2574
+ try {
2575
+ const place = JSON.parse(json);
2576
+ return Array.isArray(place?.rootPath) ? place : undefined;
2577
+ }
2578
+ catch {
2579
+ return undefined;
2580
+ }
2581
+ }
2582
+ /**
2583
+ * Go back to the place saved by the last session, in the tree as it is now.
2584
+ * Call this after the saved tree is restored.
2585
+ */
2586
+ function restorePlace(place) {
2587
+ // The saved tree can change which chapters exist, and where they start.
2588
+ initChapters();
2589
+ select.selectedIndex = findChapter(place.rootPath);
2590
+ updateFromSelect();
2591
+ if (place.keepLimits) {
2592
+ keepLimitsCheckbox.checked = true;
2593
+ if (place.limitsPath) {
2594
+ limitsShowable = chapterList[findChapter(place.limitsPath)].selectable;
2595
+ applyLimits();
2596
+ }
2597
+ }
2598
+ if (place.timeInRootMs !== null) {
2599
+ const savedMs = rootStartMs + place.timeInRootMs;
2600
+ loadPlayPositionSeconds(Math.max(sectionStartTime, Math.min(sectionEndTime, savedMs)));
2601
+ }
2602
+ loadPlayPositionRange();
2603
+ // "continue" was removed. A page saved with it pauses instead.
2604
+ const onEnd = document.querySelector(`input[name="onSectionEnd"][value="${place.onSectionEnd}"]`);
2605
+ if (onEnd)
2606
+ onEnd.checked = true;
2607
+ if (place.wasPlaying)
2608
+ playCheckBox.checked = true;
2609
+ }
2325
2610
  /**
2326
2611
  * When someone hits refresh in their browser,
2327
2612
  * or hits save in vs code so vite causes a refresh,
2328
2613
  * restart the user with the same gui settings.
2329
2614
  */
2330
2615
  function saveState() {
2331
- sessionStorage.setItem("index", select.selectedIndex.toString());
2332
- sessionStorage.setItem("keepLimits", keepLimitsCheckbox.checked ? "1" : "0");
2333
- sessionStorage.setItem("limitsIndex", chapterList.findIndex((d) => d.selectable === limitsShowable).toString());
2334
- sessionStorage.setItem("timeInSeconds", playPositionSeconds.value);
2335
- sessionStorage.setItem("state", querySelector('input[name="onSectionEnd"]:checked', HTMLInputElement).value);
2336
- sessionStorage.setItem("wasPlaying", playCheckBox.checked ? "1" : "0");
2616
+ sessionStorage.setItem("place", JSON.stringify(placeToRestore ?? currentPlace()));
2617
+ sessionStorage.setItem("playPositionLocal", playPositionLocal.checked ? "1" : "0");
2337
2618
  sessionStorage.setItem("zoomSelect", zoomSelect.value);
2338
2619
  sessionStorage.setItem("panX", panX.toString());
2339
2620
  sessionStorage.setItem("panY", panY.toString());
@@ -2553,7 +2834,9 @@ const jsonSync = new SyncedFile({
2553
2834
  if (enabled) {
2554
2835
  // Only one file per video is synced (and so "active") at a time.
2555
2836
  for (const r of getAllReq.result) {
2556
- if (r.videoKey === toShowKey && r.filename !== filename && r.isActive)
2837
+ if (r.videoKey === toShowKey &&
2838
+ r.filename !== filename &&
2839
+ r.isActive)
2557
2840
  store.put({ ...r, isActive: false, syncEnabled: false });
2558
2841
  }
2559
2842
  }
@@ -2774,7 +3057,8 @@ function buildDiffText() {
2774
3057
  out.push(`${indent}${varName}.setDuration(${comp.duration});`);
2775
3058
  }
2776
3059
  if ((comp.soundClips?.length || def.soundClips?.length) &&
2777
- JSON.stringify(comp.soundClips ?? []) !== JSON.stringify(def.soundClips ?? [])) {
3060
+ JSON.stringify(comp.soundClips ?? []) !==
3061
+ JSON.stringify(def.soundClips ?? [])) {
2778
3062
  out.push(`${indent}${varName}.soundClips = ${JSON.stringify(comp.soundClips ?? [])};`);
2779
3063
  }
2780
3064
  out.push(`${indent}${parentExpr}.replaceableComponents!.push(${varName});`);
@@ -2906,7 +3190,10 @@ function buildDiffText() {
2906
3190
  diffReplaceable(d.components ?? [], comp, childPath);
2907
3191
  }
2908
3192
  else {
2909
- printPathIfNeeded([...path, d.userEditableDescription ?? d.registryKey]);
3193
+ printPathIfNeeded([
3194
+ ...path,
3195
+ d.userEditableDescription ?? d.registryKey,
3196
+ ]);
2910
3197
  lines.push(` [deleted]`);
2911
3198
  }
2912
3199
  }
@@ -3692,7 +3979,7 @@ function buildScheduleSection(info, selectable) {
3692
3979
  markDirty();
3693
3980
  }
3694
3981
  function currentTimeMs() {
3695
- return playPositionSeconds.valueAsNumber * 1000;
3982
+ return playheadInVideoMs();
3696
3983
  }
3697
3984
  /**
3698
3985
  * Where the component that owns this schedule starts, measured from the start of the Visual
@@ -3988,8 +4275,10 @@ function buildScheduleSection(info, selectable) {
3988
4275
  else {
3989
4276
  const none = document.createElement("span");
3990
4277
  none.textContent = "—";
3991
- none.title = "The last keyframe has no duration: nothing comes after it.";
3992
- none.style.cssText = "display:inline-block;width:6em;text-align:center;color:#888";
4278
+ none.title =
4279
+ "The last keyframe has no duration: nothing comes after it.";
4280
+ none.style.cssText =
4281
+ "display:inline-block;width:6em;text-align:center;color:#888";
3993
4282
  cell.append(none);
3994
4283
  }
3995
4284
  const atLabel = document.createElement("span");
@@ -4866,12 +5155,14 @@ function buildSoundClipSection(selectable) {
4866
5155
  const header = document.createElement("div");
4867
5156
  header.style.cssText =
4868
5157
  "display:flex;align-items:center;gap:0.4em;margin-bottom:0.3em;font-size:0.85em;color:#555";
4869
- header.textContent = "Times are in ms, measured from the start of this component.";
4870
- const playheadInOwner = () => tidyMs(playPositionSeconds.valueAsNumber * 1000 - selfStartMs);
5158
+ header.textContent =
5159
+ "Times are in ms, measured from the start of this component.";
5160
+ const playheadInOwner = () => tidyMs(playheadInVideoMs() - selfStartMs);
4871
5161
  const addBtn = document.createElement("button");
4872
5162
  addBtn.type = "button";
4873
5163
  addBtn.textContent = "+ Add";
4874
- addBtn.title = "Add an empty sound clip at the playhead. Then fill in its source.";
5164
+ addBtn.title =
5165
+ "Add an empty sound clip at the playhead. Then fill in its source.";
4875
5166
  addBtn.style.marginLeft = "auto";
4876
5167
  addBtn.addEventListener("click", () => {
4877
5168
  const clip = { source: "", startMsIntoScene: playheadInOwner() };
@@ -5063,6 +5354,17 @@ function buildSoundClipSection(selectable) {
5063
5354
  _onClipValueChanged();
5064
5355
  });
5065
5356
  row2.append(srcLabel, sourceInput);
5357
+ // Why the file can't be played, if it can't.
5358
+ const problemLine = document.createElement("div");
5359
+ problemLine.style.cssText =
5360
+ "margin-top:0.2em;font-size:0.85em;color:#b00020";
5361
+ const showProblem = () => {
5362
+ const problem = soundFileProblem(clip);
5363
+ problemLine.hidden = problem === undefined;
5364
+ problemLine.textContent = `⚠ ${problem}`;
5365
+ };
5366
+ showProblem();
5367
+ soundClipSyncCallbacks.push(showProblem);
5066
5368
  // Row 3: numeric time fields
5067
5369
  const row3 = document.createElement("div");
5068
5370
  row3.style.cssText =
@@ -5113,7 +5415,8 @@ function buildSoundClipSection(selectable) {
5113
5415
  row4.style.cssText =
5114
5416
  "display:flex;gap:0.4em;align-items:center;margin-top:0.2em;flex-wrap:wrap;font-size:0.85em";
5115
5417
  const ownerLabel = document.createElement("label");
5116
- ownerLabel.style.cssText = "display:flex;align-items:center;gap:0.2em;min-width:0;flex:1";
5418
+ ownerLabel.style.cssText =
5419
+ "display:flex;align-items:center;gap:0.2em;min-width:0;flex:1";
5117
5420
  ownerLabel.textContent = "owner:";
5118
5421
  ownerLabel.title =
5119
5422
  "Which component this sound belongs to. It moves when its owner moves. " +
@@ -5165,7 +5468,7 @@ function buildSoundClipSection(selectable) {
5165
5468
  drawPlaysAt();
5166
5469
  soundClipSyncCallbacks.push(drawPlaysAt);
5167
5470
  row4.append(ownerLabel, playsAt);
5168
- card.append(row1, row2, row3, row4);
5471
+ card.append(row1, row2, problemLine, row3, row4);
5169
5472
  section.append(card);
5170
5473
  if (clip === selectedSoundClip) {
5171
5474
  requestAnimationFrame(() => card.scrollIntoView({ block: "nearest" }));
@@ -5211,6 +5514,7 @@ function buildNameSection(selectable) {
5211
5514
  return section;
5212
5515
  }
5213
5516
  function updateScheduleEditor(selectable) {
5517
+ suspendEditorPanels();
5214
5518
  scheduleEditorFieldset.replaceChildren();
5215
5519
  editingRectKf = null;
5216
5520
  viewingRectKfs.clear();
@@ -5234,7 +5538,8 @@ function updateScheduleEditor(selectable) {
5234
5538
  soundClipSyncCallbacks.length = 0;
5235
5539
  rectAspectLock = null;
5236
5540
  // A highlighted sound clip stays highlighted only while its owner is selected.
5237
- if (selectedSoundClip && !selectable.soundClips?.includes(selectedSoundClip)) {
5541
+ if (selectedSoundClip &&
5542
+ !selectable.soundClips?.includes(selectedSoundClip)) {
5238
5543
  selectedSoundClip = undefined;
5239
5544
  }
5240
5545
  timelineDisplay.setSelectedSoundId(selectedSoundClip);
@@ -5337,11 +5642,7 @@ function updateScheduleEditor(selectable) {
5337
5642
  }
5338
5643
  if (selectable instanceof HandwritingEffectComponent) {
5339
5644
  const handwritingPanel = buildHandwritingPanel(selectable, {
5340
- localTimeMs(owner) {
5341
- const root = currentRoot();
5342
- const ownerStart = root ? (startWithin(root, owner) ?? 0) : 0;
5343
- return playheadInRootMs() - ownerStart;
5344
- },
5645
+ localTimeMs: componentTimeMs,
5345
5646
  progressChanged() {
5346
5647
  activeRootComponentEditor?.update(selectable, selectable.progressSchedule);
5347
5648
  markDirty();
@@ -5353,6 +5654,9 @@ function updateScheduleEditor(selectable) {
5353
5654
  // Every keystroke in Divisions or Progress updates the status.
5354
5655
  scheduleEditorRefreshers.push(handwritingPanel.refresh);
5355
5656
  }
5657
+ // A component's own panels, and the project's: after the library's, so on a Fourier
5658
+ // the library's status comes first.
5659
+ scheduleEditorFieldset.append(...startEditorPanels(selectable));
5356
5660
  for (const info of scalars ?? []) {
5357
5661
  const section = buildScalarSection(info, selectable, (s, i) => activeRootComponentEditor?.update(s, i));
5358
5662
  // Rebuild the Transform Info panel whenever the template string changes.
@@ -5658,8 +5962,7 @@ function rectHandlePositions(r) {
5658
5962
  * level, so local == logical and no conversion is needed).
5659
5963
  */
5660
5964
  function getMarkerRelTf() {
5661
- const component = selectedSlideChild ??
5662
- currentRoot();
5965
+ const component = selectedSlideChild ?? currentRoot();
5663
5966
  if (!component)
5664
5967
  return null;
5665
5968
  const compTf = componentTransforms.get(component);
@@ -6388,6 +6691,12 @@ function applyMarkerDrag(localX, localY, shiftKey = false) {
6388
6691
  if (jsonResult.ok) {
6389
6692
  applyJsonSnapshot(jsonResult.data, true, false);
6390
6693
  }
6694
+ // Now the chapters are the saved tree's, so the last session's place can be found.
6695
+ if (placeToRestore) {
6696
+ const place = placeToRestore;
6697
+ placeToRestore = undefined;
6698
+ restorePlace(place);
6699
+ }
6391
6700
  // Catch the synced files up with whatever was restored, rather than
6392
6701
  // trusting the last session's final write: a write started as the page
6393
6702
  // unloads usually never finishes. (It can't leave a corrupt file, only a
@@ -6416,39 +6725,13 @@ function applyMarkerDrag(localX, localY, shiftKey = false) {
6416
6725
  // So when you configure the web page, and you hit refresh, or the page automatically
6417
6726
  // refreshes, you don't lose your settings.
6418
6727
  try {
6419
- const index = sessionStorage.getItem("index");
6420
- const timeInSeconds = sessionStorage.getItem("timeInSeconds");
6421
- const state = sessionStorage.getItem("state");
6422
- if (index && timeInSeconds && state) {
6423
- select.selectedIndex = assertNonNullable(parseIntX(index));
6424
- if (select.selectedIndex < 0) {
6425
- // What if you save the state when row 13 is selected, but there are currently
6426
- // only 5 rows available? That's when we get here. Without this change
6427
- // updateFromSelect() would throw an exception.
6428
- select.selectedIndex = 0;
6429
- }
6430
- updateFromSelect();
6431
- if (sessionStorage.getItem("keepLimits") === "1") {
6432
- keepLimitsCheckbox.checked = true;
6433
- const limitsIndex = parseIntX(sessionStorage.getItem("limitsIndex") ?? "");
6434
- const saved = limitsIndex === undefined ? undefined : chapterList[limitsIndex];
6435
- if (saved) {
6436
- limitsShowable = saved.selectable;
6437
- applyLimits();
6438
- }
6439
- }
6440
- const savedMs = parseFloat(timeInSeconds) * 1000;
6441
- const clampedMs = Math.max(sectionStartTime, Math.min(sectionEndTime, savedMs));
6442
- loadPlayPositionSeconds(clampedMs);
6443
- loadPlayPositionRange();
6444
- // "continue" was removed. A page saved with it pauses instead.
6445
- const onEnd = document.querySelector(`input[name="onSectionEnd"][value="${state}"]`);
6446
- if (onEnd)
6447
- onEnd.checked = true;
6448
- if (sessionStorage.getItem("wasPlaying") === "1") {
6449
- playCheckBox.checked = true;
6450
- }
6728
+ if (sessionStorage.getItem("playPositionLocal") === "0") {
6729
+ const playheadMs = playheadInVideoMs();
6730
+ playPositionLocal.checked = false;
6731
+ loadPlayPositionSeconds(playheadMs);
6451
6732
  }
6733
+ // Applied when the saved tree is in: see initFromDB() above.
6734
+ placeToRestore = parseSavedPlace(sessionStorage.getItem("place"));
6452
6735
  if (sessionStorage.getItem("quality") === "Low Power") {
6453
6736
  getById("lowPower", HTMLInputElement).checked = true;
6454
6737
  }
@@ -6669,6 +6952,13 @@ getById("recordJustSound", HTMLButtonElement).addEventListener("click", async ()
6669
6952
  const before = infoDiv.innerHTML;
6670
6953
  infoDiv.innerHTML = "Waiting for the sound…";
6671
6954
  await soundtrack.ready();
6955
+ try {
6956
+ assertSoundFilesLoaded();
6957
+ }
6958
+ catch (error) {
6959
+ infoDiv.innerHTML = `<strong style="color:red">Not saved:</strong> ${escapeHtml(String(error instanceof Error ? error.message : error))}`;
6960
+ return;
6961
+ }
6672
6962
  infoDiv.innerHTML = before;
6673
6963
  downloadBlob("sound_file.wav", soundtrack.mix(0, toShow.duration).toBlob());
6674
6964
  });