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
@@ -136,4 +136,4 @@ philDebug.unloadServiceWorker = unloadServiceWorker;
136
136
  // JavaScript are loaded, and the service worker could actually monitor or change
137
137
  // those pages.
138
138
  // Reloading the service worker is also very fast,
139
- // faster than I could manually start the next step of my testing.
139
+ // faster than I could manually start the next step of my testing.
@@ -139,7 +139,11 @@ export class FormatEditor {
139
139
  return serialize(this.#units());
140
140
  }
141
141
  set value(newValue: string) {
142
- this.#replace({ start: 0, end: this.#units().length }, parse(newValue), "set");
142
+ this.#replace(
143
+ { start: 0, end: this.#units().length },
144
+ parse(newValue),
145
+ "set",
146
+ );
143
147
  }
144
148
 
145
149
  get knownNames(): readonly string[] {
@@ -174,7 +178,8 @@ export class FormatEditor {
174
178
  this.#replace(selection, [{ format: name }], "insert format");
175
179
  // The new chip is immediately before the cursor.
176
180
  const cursor = this.#getSelection();
177
- const chip = cursor && this.#chipElements()[this.#chipIndexBefore(cursor.start)];
181
+ const chip =
182
+ cursor && this.#chipElements()[this.#chipIndexBefore(cursor.start)];
178
183
  const select = chip?.querySelector("select");
179
184
  if (select) {
180
185
  select.focus();
@@ -116,8 +116,13 @@ export function buildFourierPanel(component: FourierComponent): FourierPanel {
116
116
  const prefix = keyframes.length > 1 ? `At ${keyframe.time} ms: ` : "";
117
117
  const parsed = parseTermGroups(keyframe.value);
118
118
  groupCounts.add(parsed.groups.length);
119
- const source = component.termsFor(component.sourceSchedule.at(keyframe.time));
120
- const termCount = parsed.groups.reduce((sum, group) => sum + group.length, 0);
119
+ const source = component.termsFor(
120
+ component.sourceSchedule.at(keyframe.time),
121
+ );
122
+ const termCount = parsed.groups.reduce(
123
+ (sum, group) => sum + group.length,
124
+ 0,
125
+ );
121
126
  const problems = [...parsed.warnings];
122
127
  let summary = `${parsed.groups.length} group${parsed.groups.length === 1 ? "" : "s"}, ${termCount} term${termCount === 1 ? "" : "s"}`;
123
128
  if (typeof source === "string") {
@@ -133,7 +138,10 @@ export function buildFourierPanel(component: FourierComponent): FourierPanel {
133
138
  }
134
139
  if (groupCounts.size === 1) {
135
140
  const [groupCount] = groupCounts;
136
- const stepProblems = checkStepRange(component.stepSchedule.schedule, groupCount);
141
+ const stepProblems = checkStepRange(
142
+ component.stepSchedule.schedule,
143
+ groupCount,
144
+ );
137
145
  if (stepProblems.length === 0) {
138
146
  line(`Step runs from 0 to ${groupCount} ✓`, "#070");
139
147
  }
@@ -30,7 +30,7 @@ const HELP =
30
30
  "in between, the pen moves through the next unit at a steady speed. " +
31
31
  "Letters are visible characters only: spaces take no time. " +
32
32
  "Words are split as the layout splits them, and each Text Span starts a new word. " +
33
- "Lines end at a \"\\n\", not at word wrap. Total: 1 is the whole text.";
33
+ 'Lines end at a "\\n", not at word wrap. Total: 1 is the whole text.';
34
34
 
35
35
  /** Singular, for "line 3"; plural, for "4 lines". */
36
36
  const UNIT_NAMES: Record<HandwritingDivision, [string, string]> = {
@@ -146,9 +146,7 @@ export function buildHandwritingPanel(
146
146
  );
147
147
  if (peak < count) {
148
148
  const goal =
149
- division === "Total"
150
- ? "1"
151
- : `${count}, the number of ${plural}`;
149
+ division === "Total" ? "1" : `${count}, the number of ${plural}`;
152
150
  line(
153
151
  `⚠ Progress never reaches ${goal}, so the text is never finished. ` +
154
152
  `It peaks at ${formatNumber(peak)}, ${whereThePenIs(units, peak, division, words)}.`,
@@ -168,7 +166,10 @@ export function buildHandwritingPanel(
168
166
  });
169
167
  status.append(fillBtn);
170
168
  } else {
171
- line(`Progress reaches ${formatNumber(count)}, the end of the text ✓`, "#070");
169
+ line(
170
+ `Progress reaches ${formatNumber(count)}, the end of the text ✓`,
171
+ "#070",
172
+ );
172
173
  if (peak > count) {
173
174
  line(
174
175
  `It goes up to ${formatNumber(peak)}. Anything from ${count} up shows the finished text.`,
@@ -257,7 +258,9 @@ export function fillInKeyframes(
257
258
  value: number,
258
259
  startsTransition: boolean,
259
260
  ): Keyframe<number> =>
260
- startsTransition && ease ? { time, value, easeAfter: ease } : { time, value };
261
+ startsTransition && ease
262
+ ? { time, value, easeAfter: ease }
263
+ : { time, value };
261
264
  const added: Keyframe<number>[] = [];
262
265
  let time = last.time;
263
266
  let lastEase = ease;
@@ -295,8 +298,9 @@ function askToFillIn(
295
298
  ): Promise<boolean> {
296
299
  const schedule = component.progressSchedule.schedule;
297
300
  const [singular] = UNIT_NAMES[division];
298
- const startValue = [...schedule].sort((a, b) => a.time - b.time).at(-1)!
299
- .value;
301
+ const startValue = [...schedule]
302
+ .sort((a, b) => a.time - b.time)
303
+ .at(-1)!.value;
300
304
 
301
305
  const dialog = document.createElement("dialog");
302
306
  dialog.style.cssText = "min-width:26em;max-width:36em;padding:1em";
@@ -304,7 +308,8 @@ function askToFillIn(
304
308
  heading.style.margin = "0 0 0.4em 0";
305
309
  heading.textContent = "Fill in the rest";
306
310
  const hint = document.createElement("div");
307
- hint.style.cssText = "margin-bottom:0.8em;font-size:0.85em;color:#555;font-style:italic";
311
+ hint.style.cssText =
312
+ "margin-bottom:0.8em;font-size:0.85em;color:#555;font-style:italic";
308
313
  hint.textContent =
309
314
  `Progress ends at ${formatNumber(startValue)}. ` +
310
315
  (division === "Total"
@@ -28,7 +28,8 @@ export type LocalFileRowOptions = {
28
28
  */
29
29
  export function buildLocalFileRow(options: LocalFileRowOptions): HTMLElement {
30
30
  const row = document.createElement("div");
31
- row.style.cssText = "margin-bottom:0.3em;display:flex;gap:0.3em;align-items:center;flex-wrap:wrap";
31
+ row.style.cssText =
32
+ "margin-bottom:0.3em;display:flex;gap:0.3em;align-items:center;flex-wrap:wrap";
32
33
 
33
34
  const pickButton = document.createElement("button");
34
35
  pickButton.type = "button";
@@ -51,7 +52,11 @@ export function buildLocalFileRow(options: LocalFileRowOptions): HTMLElement {
51
52
  async function redraw() {
52
53
  const myGeneration = ++generation;
53
54
  const url = options.currentUrl();
54
- where.textContent = isLocalFileUrl(url) ? "On this computer" : url ? "On the web server" : "";
55
+ where.textContent = isLocalFileUrl(url)
56
+ ? "On this computer"
57
+ : url
58
+ ? "On the web server"
59
+ : "";
55
60
  let files: Awaited<ReturnType<typeof listLocalFiles>>;
56
61
  try {
57
62
  files = await listLocalFiles();
@@ -60,7 +65,9 @@ export function buildLocalFileRow(options: LocalFileRowOptions): HTMLElement {
60
65
  }
61
66
  if (myGeneration !== generation) return;
62
67
  const placeholder = document.createElement("option");
63
- placeholder.textContent = files.length ? "Recent files…" : "No recent files";
68
+ placeholder.textContent = files.length
69
+ ? "Recent files…"
70
+ : "No recent files";
64
71
  placeholder.value = "";
65
72
  placeholder.disabled = true;
66
73
  const choices = files.map((file) => {
@@ -70,7 +77,8 @@ export function buildLocalFileRow(options: LocalFileRowOptions): HTMLElement {
70
77
  return option;
71
78
  });
72
79
  recentSelect.replaceChildren(placeholder, ...choices);
73
- recentSelect.value = isLocalFileUrl(url) && files.some((f) => f.url === url) ? url : "";
80
+ recentSelect.value =
81
+ isLocalFileUrl(url) && files.some((f) => f.url === url) ? url : "";
74
82
  recentSelect.disabled = files.length === 0;
75
83
  }
76
84
 
@@ -104,4 +112,3 @@ export function buildLocalFileRow(options: LocalFileRowOptions): HTMLElement {
104
112
  void redraw();
105
113
  return row;
106
114
  }
107
-
@@ -124,7 +124,8 @@ export async function openMultiTextDialog(
124
124
  const revertBtn = document.createElement("button");
125
125
  revertBtn.type = "button";
126
126
  revertBtn.textContent = "Revert";
127
- revertBtn.title = "Put the text and the formats back the way they were when this opened.";
127
+ revertBtn.title =
128
+ "Put the text and the formats back the way they were when this opened.";
128
129
  revertBtn.disabled = true;
129
130
  const doneBtn = document.createElement("button");
130
131
  doneBtn.type = "button";
@@ -150,10 +151,13 @@ export async function openMultiTextDialog(
150
151
  }
151
152
  if (
152
153
  text.children.some(
153
- ({ replaceable, child }) => !replaceable && child instanceof TextSpanComponent,
154
+ ({ replaceable, child }) =>
155
+ !replaceable && child instanceof TextSpanComponent,
154
156
  )
155
157
  ) {
156
- note("This Multi Text also has Text Spans built in TypeScript. They can't be edited here.");
158
+ note(
159
+ "This Multi Text also has Text Spans built in TypeScript. They can't be edited here.",
160
+ );
157
161
  }
158
162
  for (const { span } of originalSpans) {
159
163
  if (isAnimated(span)) {
@@ -227,7 +231,9 @@ export async function openMultiTextDialog(
227
231
  }
228
232
 
229
233
  // Keep the focus, and so the cursor, in the editor.
230
- insertFormatBtn.addEventListener("mousedown", (event) => event.preventDefault());
234
+ insertFormatBtn.addEventListener("mousedown", (event) =>
235
+ event.preventDefault(),
236
+ );
231
237
  insertFormatBtn.addEventListener("click", () => editor.insertFormat());
232
238
 
233
239
  revertBtn.addEventListener("click", () => {
@@ -286,7 +292,9 @@ export async function openMultiTextDialog(
286
292
  * @param existing The names already in use. Picking one of these is allowed: it uses that format.
287
293
  * @returns The name, or undefined if the user cancelled.
288
294
  */
289
- function askFormatName(existing: readonly string[]): Promise<string | undefined> {
295
+ function askFormatName(
296
+ existing: readonly string[],
297
+ ): Promise<string | undefined> {
290
298
  const dialog = document.createElement("dialog");
291
299
  dialog.style.cssText = "min-width:26em;max-width:36em;padding:1em";
292
300
 
@@ -307,7 +315,8 @@ function askFormatName(existing: readonly string[]): Promise<string | undefined>
307
315
  label.append(input);
308
316
 
309
317
  const message = document.createElement("div");
310
- message.style.cssText = "font-size:0.85em;min-height:1.3em;margin:0.3em 0 0.8em 0";
318
+ message.style.cssText =
319
+ "font-size:0.85em;min-height:1.3em;margin:0.3em 0 0.8em 0";
311
320
 
312
321
  const buttons = document.createElement("div");
313
322
  buttons.style.cssText = "display:flex;gap:0.5em;justify-content:flex-end";
@@ -14,7 +14,10 @@ import {
14
14
  import { buildNumericInput } from "./schedule-helpers.ts";
15
15
 
16
16
  /** Whether the frame is drawn on the canvas (👁), and whether it has handles to drag (✎). */
17
- export type CanvasState = { readonly viewing: boolean; readonly editing: boolean };
17
+ export type CanvasState = {
18
+ readonly viewing: boolean;
19
+ readonly editing: boolean;
20
+ };
18
21
 
19
22
  /** What the panel needs from the Visual Editor. It never reaches into canvas-recorder.ts directly. */
20
23
  export type TextFramePanelHooks = {
@@ -158,7 +161,8 @@ export function buildTextFramePanel(
158
161
 
159
162
  function turnBy(quarterTurns: 1 | 3): void {
160
163
  const before = text.frameIsEditable ? text.frameAt(0) : undefined;
161
- text.rotationScalar.value = ROTATIONS[(text.quarterTurns + quarterTurns) % 4];
164
+ text.rotationScalar.value =
165
+ ROTATIONS[(text.quarterTurns + quarterTurns) % 4];
162
166
  if (before) {
163
167
  // Turn in place, about the frame's center, the way PowerPoint does. A
164
168
  // quarter turn swaps the frame's width and height on screen.
@@ -129,6 +129,10 @@ export const playerBodyHtml = `
129
129
  value="0"
130
130
  title="The play position, in seconds. Option-← and Option-→ step one frame."
131
131
  />
132
+ <label
133
+ title="Checked: the time is measured from the start of the component you're editing. Unchecked: from the start of the video."
134
+ ><input type="checkbox" id="playPositionLocal" checked />local</label
135
+ >
132
136
  <input type="range" id="playPositionRange" value="0" step="any" />
133
137
  </div>
134
138
  </fieldset>
@@ -97,7 +97,12 @@ export function scheduleToTypeScript(
97
97
  `cellWidth: ${v.cellWidth}, cellHeight: ${v.cellHeight} }`
98
98
  );
99
99
  } else {
100
- const v = value as { x: number; y: number; width: number; height: number };
100
+ const v = value as {
101
+ x: number;
102
+ y: number;
103
+ width: number;
104
+ height: number;
105
+ };
101
106
  return `{ x: ${v.x}, y: ${v.y}, width: ${v.width}, height: ${v.height} }`;
102
107
  }
103
108
  }
@@ -165,7 +170,10 @@ export function validateKfValue(
165
170
  if (typeof value !== "object" || value === null) return false;
166
171
  const v = value as Record<string, unknown>;
167
172
  const isPoint = (p: unknown): boolean =>
168
- typeof p === "object" && p !== null && typeof (p as Record<string, unknown>).x === "number" && typeof (p as Record<string, unknown>).y === "number";
173
+ typeof p === "object" &&
174
+ p !== null &&
175
+ typeof (p as Record<string, unknown>).x === "number" &&
176
+ typeof (p as Record<string, unknown>).y === "number";
169
177
  return isPoint(v.flat) && isPoint(v.pointy);
170
178
  }
171
179
  }
@@ -176,8 +184,7 @@ export function parseScheduleFromClipboard(
176
184
  text: string,
177
185
  type: ScheduleInfo["type"],
178
186
  ):
179
- | { time: number; value: unknown; easeAfter?: (t: number) => number }[]
180
- | null {
187
+ { time: number; value: unknown; easeAfter?: (t: number) => number }[] | null {
181
188
  try {
182
189
  let cleaned = text
183
190
  .split("\n")
@@ -55,7 +55,10 @@ export function soundOwners(root: Showable): SoundOwner[] {
55
55
  * When `target` starts, relative to `root`. `undefined` if it isn't in the tree.
56
56
  * Uses the same walk as {@link soundOwners}.
57
57
  */
58
- export function startWithin(root: Showable, target: Showable): number | undefined {
58
+ export function startWithin(
59
+ root: Showable,
60
+ target: Showable,
61
+ ): number | undefined {
59
62
  function walk(item: Showable, startMs: number): number | undefined {
60
63
  if (item === target) return startMs;
61
64
  for (const { child, start } of item.children ?? []) {
package/dev/soundtrack.ts CHANGED
@@ -102,6 +102,8 @@ export type SoundtrackOptions = {
102
102
  readonly root: () => Showable;
103
103
  /** A file finished decoding: its waveform and length are known now. */
104
104
  readonly onDecoded?: () => void;
105
+ /** A file couldn't be read or decoded. See {@link Soundtrack.failure}. */
106
+ readonly onFailed?: () => void;
105
107
  /** A clip names a file that wasn't in the list before. */
106
108
  readonly onNewSource?: () => void;
107
109
  };
@@ -122,8 +124,8 @@ export class Soundtrack {
122
124
  });
123
125
  readonly #decoding = new Map<string, Promise<AudioBuffer>>();
124
126
  readonly #decoded = new Map<string, AudioBuffer>();
125
- /** Files that couldn't be read. Not tried again until {@link forgetFailures}. */
126
- readonly #failed = new Set<string>();
127
+ /** Files that couldn't be read, and why. Not tried again until {@link forgetFailures}. */
128
+ readonly #failed = new Map<string, unknown>();
127
129
 
128
130
  /**
129
131
  * The decoded file, mono, or null if it hasn't been decoded yet (or can't be).
@@ -133,6 +135,23 @@ export class Soundtrack {
133
135
  return this.#decoded.get(url) ?? null;
134
136
  }
135
137
 
138
+ /** Why the file couldn't be read or decoded, or undefined if it hasn't failed (yet). */
139
+ failure(url: string): unknown {
140
+ return this.#failed.get(url);
141
+ }
142
+
143
+ /**
144
+ * Every file the clips name that couldn't be read or decoded, and why.
145
+ * Call {@link ready} first, or the files still loading aren't known yet.
146
+ */
147
+ failures(): { url: string; reason: unknown }[] {
148
+ if (this.#requested) this.#update();
149
+ const urls = new Set(this.#clips.map(({ source }) => source));
150
+ return [...urls]
151
+ .filter((url) => this.#failed.has(url))
152
+ .map((url) => ({ url, reason: this.#failed.get(url) }));
153
+ }
154
+
136
155
  /** Read and decode every file again, e.g. one re-recorded under the same name. */
137
156
  forget(): void {
138
157
  this.#decoding.clear();
@@ -158,7 +177,7 @@ export class Soundtrack {
158
177
 
159
178
  /** Try the files that couldn't be read again, e.g. after 🔓 Allow local files. */
160
179
  forgetFailures(): void {
161
- for (const url of this.#failed) this.#decoding.delete(url);
180
+ for (const url of this.#failed.keys()) this.#decoding.delete(url);
162
181
  this.#failed.clear();
163
182
  this.#loadAgain();
164
183
  }
@@ -182,7 +201,10 @@ export class Soundtrack {
182
201
  return buffer;
183
202
  },
184
203
  (reason) => {
185
- if (this.#decoding.get(url) === promise) this.#failed.add(url);
204
+ if (this.#decoding.get(url) === promise) {
205
+ this.#failed.set(url, reason);
206
+ this.#options.onFailed?.();
207
+ }
186
208
  debugLog("audio", `Skipped "${url}": ${reason}`);
187
209
  throw reason;
188
210
  },
@@ -196,6 +218,9 @@ export class Soundtrack {
196
218
  async #decode(url: string): Promise<AudioBuffer> {
197
219
  const time1 = performance.now();
198
220
  const response = await fetchMedia(url);
221
+ // Or the error page would be decoded, and fail with a message that doesn't say why.
222
+ if (!response.ok)
223
+ throw new Error(`${response.status} ${response.statusText}`);
199
224
  const encoded = await response.arrayBuffer();
200
225
  // Before decoding: decodeAudioData() detaches the buffer, so it reads as 0 bytes after.
201
226
  const bytes = encoded.byteLength;
@@ -278,7 +303,9 @@ export class Soundtrack {
278
303
  for (;;) {
279
304
  if (this.#requested) this.#update();
280
305
  const json = this.#clipsJson;
281
- await Promise.allSettled(this.#clips.map(({ source }) => this.#load(source)));
306
+ await Promise.allSettled(
307
+ this.#clips.map(({ source }) => this.#load(source)),
308
+ );
282
309
  if (!this.#requested && json === this.#clipsJson) return;
283
310
  }
284
311
  }
@@ -289,10 +316,7 @@ export class Soundtrack {
289
316
  */
290
317
  mix(fromMs: number, toMs: number): AudioBuilder {
291
318
  if (this.#requested) this.#update();
292
- const builder = new AudioBuilder(
293
- Math.max(0, toMs - fromMs),
294
- SAMPLE_RATE,
295
- );
319
+ const builder = new AudioBuilder(Math.max(0, toMs - fromMs), SAMPLE_RATE);
296
320
  for (const clip of this.#clips) {
297
321
  const buffer = this.#decoded.get(clip.source);
298
322
  if (buffer) {
@@ -354,7 +378,9 @@ export class Soundtrack {
354
378
  /** The video's time at `contextTime`, by the current anchor. */
355
379
  #mediaMsAt(contextTime: number): number {
356
380
  const anchor = this.#anchor!;
357
- return anchor.mediaMs + (contextTime - anchor.contextTime) * anchor.rate * 1000;
381
+ return (
382
+ anchor.mediaMs + (contextTime - anchor.contextTime) * anchor.rate * 1000
383
+ );
358
384
  }
359
385
 
360
386
  /**
@@ -362,7 +388,12 @@ export class Soundtrack {
362
388
  * same time, so a node can be kept.
363
389
  */
364
390
  #keyOf(clip: PlacedSoundClip): string {
365
- return JSON.stringify([clip.source, clip.startMs, clip.trimMs, clip.lengthMs]);
391
+ return JSON.stringify([
392
+ clip.source,
393
+ clip.startMs,
394
+ clip.trimMs,
395
+ clip.lengthMs,
396
+ ]);
366
397
  }
367
398
 
368
399
  /**
@@ -111,7 +111,8 @@ export function askHowToSplit(options: {
111
111
  const note = document.createElement("div");
112
112
  note.style.cssText = "font-size:0.85em;color:#555;margin-top:0.3em";
113
113
  fieldset.append(note);
114
- const value = () => (inputs.find((input) => input.checked)?.value ?? initial) as T;
114
+ const value = () =>
115
+ (inputs.find((input) => input.checked)?.value ?? initial) as T;
115
116
  return { fieldset, inputs, note, value };
116
117
  }
117
118
 
@@ -127,12 +128,14 @@ export function askHowToSplit(options: {
127
128
  {
128
129
  value: "first",
129
130
  label: "Attach to first",
130
- title: "Keep each one whole, on the first piece. It plays past that piece's end.",
131
+ title:
132
+ "Keep each one whole, on the first piece. It plays past that piece's end.",
131
133
  },
132
134
  {
133
135
  value: "second",
134
136
  label: "Attach to second",
135
- title: "Keep each one whole, on the second piece. It starts before that piece does.",
137
+ title:
138
+ "Keep each one whole, on the second piece. It starts before that piece does.",
136
139
  },
137
140
  ],
138
141
  readCrossing(),
@@ -142,16 +145,18 @@ export function askHowToSplit(options: {
142
145
  "Keep",
143
146
  "splitKeep",
144
147
  [
145
- { value: "both", label: "Both pieces", title: "An ordinary split." },
148
+ { value: "both", label: "Both ■■", title: "An ordinary split." },
146
149
  {
147
150
  value: "first",
148
- label: "First only",
149
- title: "Trim the end of the clip at the split. The second piece and its sounds are removed.",
151
+ label: "First ■□",
152
+ title:
153
+ "Trim the end of the clip at the split. The second piece and its sounds are removed.",
150
154
  },
151
155
  {
152
156
  value: "second",
153
- label: "Second only",
154
- title: "Trim the start of the clip at the split. The first piece and its sounds are removed.",
157
+ label: "Second □■",
158
+ title:
159
+ "Trim the start of the clip at the split. The first piece and its sounds are removed.",
155
160
  },
156
161
  ],
157
162
  "both",
@@ -192,7 +197,8 @@ export function askHowToSplit(options: {
192
197
  whereNote.style.color = valid ? "#555" : "#a06000";
193
198
 
194
199
  const crossingCount = valid
195
- ? clip.soundClips.filter((sound) => crossesSplit(sound, atMs, lengthOf)).length
200
+ ? clip.soundClips.filter((sound) => crossesSplit(sound, atMs, lengthOf))
201
+ .length
196
202
  : 0;
197
203
  for (const input of crossing.inputs) input.disabled = crossingCount === 0;
198
204
  crossing.note.textContent =
@@ -210,7 +216,13 @@ export function askHowToSplit(options: {
210
216
  const endFile = Math.max(startFile, clip.endMsIntoClipScalar.value);
211
217
  const atFile = clip.locationInClip(atMs);
212
218
  const kept = keep.value();
213
- const line = (name: string, from: number, to: number, length: number, gone: boolean) => {
219
+ const line = (
220
+ name: string,
221
+ from: number,
222
+ to: number,
223
+ length: number,
224
+ gone: boolean,
225
+ ) => {
214
226
  const div = document.createElement("div");
215
227
  div.textContent = `${name}: ${seconds(length)} long, showing ${seconds(from)}–${seconds(to)} of the file${gone ? " (removed)" : ""}`;
216
228
  if (gone) div.style.cssText = "color:#999;text-decoration:line-through";
@@ -349,15 +361,15 @@ export function askHowToSplitSound(options: {
349
361
  keepFieldset.append(keepLegend);
350
362
  const keepInputs = (
351
363
  [
352
- { value: "both", label: "Both pieces", title: "An ordinary split." },
364
+ { value: "both", label: "Both ■■", title: "An ordinary split." },
353
365
  {
354
366
  value: "first",
355
- label: "First only",
367
+ label: "First ■□",
356
368
  title: "Trim the end of the clip at the split.",
357
369
  },
358
370
  {
359
371
  value: "second",
360
- label: "Second only",
372
+ label: "Second □■",
361
373
  title: "Trim the start of the clip at the split.",
362
374
  },
363
375
  ] as const
@@ -390,7 +402,16 @@ export function askHowToSplitSound(options: {
390
402
  okBtn.textContent = "Split";
391
403
  buttons.append(cancelBtn, okBtn);
392
404
 
393
- dialog.append(heading, hint, whereRow, snapRow, whereNote, keepFieldset, preview, buttons);
405
+ dialog.append(
406
+ heading,
407
+ hint,
408
+ whereRow,
409
+ snapRow,
410
+ whereNote,
411
+ keepFieldset,
412
+ preview,
413
+ buttons,
414
+ );
394
415
 
395
416
  // MARK: Behavior
396
417
  const inside = (atMs: number) => atMs > 0 && atMs < lengthMs;
@@ -404,7 +425,9 @@ export function askHowToSplitSound(options: {
404
425
  function snapped(atMs: number): number {
405
426
  if (!snapInput.checked || !words?.length) return atMs;
406
427
  const fileMs = startMsIntoClip + atMs;
407
- const inWord = words.some((w) => w.cutBeforeMs < fileMs && fileMs < w.cutAfterMs);
428
+ const inWord = words.some(
429
+ (w) => w.cutBeforeMs < fileMs && fileMs < w.cutAfterMs,
430
+ );
408
431
  if (!inWord) return atMs;
409
432
  let best = atMs;
410
433
  let bestDistance = Infinity;
@@ -437,7 +460,8 @@ export function askHowToSplitSound(options: {
437
460
  if (within) return ` ⚠ That's in the middle of ${quoted(within)}.`;
438
461
  const before = words.findLast((w) => w.endMs <= fileMs);
439
462
  const after = words.find((w) => w.startMs >= fileMs);
440
- if (before && after) return ` Between ${quoted(before)} and ${quoted(after)}.`;
463
+ if (before && after)
464
+ return ` Between ${quoted(before)} and ${quoted(after)}.`;
441
465
  if (after) return ` Before ${quoted(after)}.`;
442
466
  if (before) return ` After ${quoted(before)}.`;
443
467
  return "";
@@ -461,13 +485,19 @@ export function askHowToSplitSound(options: {
461
485
  (moved
462
486
  ? `Snapped to ${Math.round(atMs)} ms, ${Math.round(Math.abs(atMs - typed))} ms ${direction}.`
463
487
  : "") + aroundWords(atMs);
464
- whereNote.style.color = whereNote.textContent.includes("⚠") ? "#a06000" : "#555";
488
+ whereNote.style.color = whereNote.textContent.includes("⚠")
489
+ ? "#a06000"
490
+ : "#555";
465
491
 
466
492
  const kept = keep();
467
493
  const line = (name: string, from: number, to: number, gone: boolean) => {
468
494
  const div = document.createElement("div");
469
- const length = Number.isFinite(to - from) ? `${seconds(to - from)} long` : "to the end of the file";
470
- const fileTo = Number.isFinite(to) ? seconds(startMsIntoClip + to) : "the end";
495
+ const length = Number.isFinite(to - from)
496
+ ? `${seconds(to - from)} long`
497
+ : "to the end of the file";
498
+ const fileTo = Number.isFinite(to)
499
+ ? seconds(startMsIntoClip + to)
500
+ : "the end";
471
501
  div.textContent = `${name}: ${length}, playing ${seconds(startMsIntoClip + from)}–${fileTo} of the file${gone ? " (removed)" : ""}`;
472
502
  if (gone) div.style.cssText = "color:#999;text-decoration:line-through";
473
503
  return div;
@@ -11,7 +11,11 @@ import {
11
11
  shrinkToAspect,
12
12
  } from "../src/slide-components/video-info.ts";
13
13
  import { SingleImage } from "../src/slow-image-sources.ts";
14
- import { ALIGN_HORIZONTALLY, ALIGN_VERTICALLY, buildSnapRow } from "./rect-snap.ts";
14
+ import {
15
+ ALIGN_HORIZONTALLY,
16
+ ALIGN_VERTICALLY,
17
+ buildSnapRow,
18
+ } from "./rect-snap.ts";
15
19
  import { buildLocalFileRow } from "./local-file-row.ts";
16
20
  import { IMAGE_FILE_TYPES, onLocalFilesChange } from "../src/local-files.ts";
17
21
 
@@ -63,7 +67,10 @@ export function buildStaticImagePanel(
63
67
  currentUrl: () => component.urlSchedule.at(0),
64
68
  choose(url) {
65
69
  if (component.urlSchedule.schedule.length > 1) {
66
- alert("URL has several keyframes. Type the file's URL into the one you want.\n\n" + url);
70
+ alert(
71
+ "URL has several keyframes. Type the file's URL into the one you want.\n\n" +
72
+ url,
73
+ );
67
74
  return;
68
75
  }
69
76
  component.urlSchedule.set(url);
@@ -96,12 +103,14 @@ export function buildStaticImagePanel(
96
103
  const rectButtons = [
97
104
  {
98
105
  text: "Fit canvas",
99
- title: "As large as possible while the whole image stays on the canvas. Centered.",
106
+ title:
107
+ "As large as possible while the whole image stays on the canvas. Centered.",
100
108
  make: (size: Size) => centeredOnCanvas(maxFit(size.width, size.height)),
101
109
  },
102
110
  {
103
111
  text: "Cover canvas",
104
- title: "Just large enough to cover the whole canvas. Some of the image will be off screen. Centered.",
112
+ title:
113
+ "Just large enough to cover the whole canvas. Some of the image will be off screen. Centered.",
105
114
  make: (size: Size) => centeredOnCanvas(minCover(size.width, size.height)),
106
115
  },
107
116
  {
@@ -110,7 +119,10 @@ export function buildStaticImagePanel(
110
119
  make: (size: Size, rect: ReadOnlyRect) =>
111
120
  sameCenter(preservePixels(size.width, size.height), rect),
112
121
  },
113
- ].map(({ text, title, make }) => ({ btn: button(rectRow, text, title), make }));
122
+ ].map(({ text, title, make }) => ({
123
+ btn: button(rectRow, text, title),
124
+ make,
125
+ }));
114
126
 
115
127
  /**
116
128
  * Snap one edge of the Dest Rect to the canvas, or center it, keeping its
@@ -207,7 +207,8 @@ export class SyncedFile {
207
207
  } catch (error) {
208
208
  // Starting next to a file that has since been deleted can make the
209
209
  // picker itself fail. Starting anywhere is better than not at all.
210
- if (error instanceof DOMException && error.name === "AbortError") throw error;
210
+ if (error instanceof DOMException && error.name === "AbortError")
211
+ throw error;
211
212
  handle = await ask();
212
213
  }
213
214
  } catch (error) {
@@ -316,10 +317,8 @@ export class SyncedFile {
316
317
  status.style.color = "darkorange";
317
318
  status.title =
318
319
  "Something else changed this file since it was last synced, so it hasn't been overwritten.";
319
- button(
320
- "Overwrite",
321
- `Replace ${name} with the current state`,
322
- () => this.request(true),
320
+ button("Overwrite", `Replace ${name} with the current state`, () =>
321
+ this.request(true),
323
322
  );
324
323
  if (this.#options.open) {
325
324
  button(