canvas-recorder-lib 0.8.3 → 0.8.5

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 (242) hide show
  1. package/README.md +10 -2
  2. package/dev/canvas-recorder.css +14 -0
  3. package/dev/canvas-recorder.ts +500 -84
  4. package/dev/color-picker.ts +13 -0
  5. package/dev/component-picker.ts +60 -11
  6. package/dev/font-widgets.ts +2 -2
  7. package/dev/format-editor.ts +3 -1
  8. package/dev/fourier-panel.ts +7 -3
  9. package/dev/handwriting-panel.ts +7 -7
  10. package/dev/multi-text-dialog.ts +28 -15
  11. package/dev/player-body.ts +95 -36
  12. package/dev/schedule-helpers.ts +10 -3
  13. package/dev/static-image-panel.ts +4 -4
  14. package/dev/subtitles.ts +170 -0
  15. package/dev/synced-file.ts +34 -0
  16. package/dev/timeline-display.ts +1 -1
  17. package/dev/transcript-align.ts +4 -1
  18. package/dev/transcript-editor.ts +1205 -0
  19. package/dev/transcript-export.ts +90 -0
  20. package/dev/transcript-view.ts +8 -5
  21. package/dev/transcripts.ts +140 -15
  22. package/dev/video-clip-panel.ts +4 -4
  23. package/dist/dev/canvas-recorder.css +14 -0
  24. package/dist/dev/canvas-recorder.js +408 -74
  25. package/dist/dev/canvas-recorder.js.map +1 -1
  26. package/dist/dev/color-picker.d.ts.map +1 -1
  27. package/dist/dev/color-picker.js +15 -0
  28. package/dist/dev/color-picker.js.map +1 -1
  29. package/dist/dev/component-picker.d.ts +2 -1
  30. package/dist/dev/component-picker.d.ts.map +1 -1
  31. package/dist/dev/component-picker.js +56 -11
  32. package/dist/dev/component-picker.js.map +1 -1
  33. package/dist/dev/font-widgets.d.ts +2 -2
  34. package/dist/dev/font-widgets.d.ts.map +1 -1
  35. package/dist/dev/font-widgets.js.map +1 -1
  36. package/dist/dev/format-editor.d.ts.map +1 -1
  37. package/dist/dev/format-editor.js +3 -1
  38. package/dist/dev/format-editor.js.map +1 -1
  39. package/dist/dev/fourier-panel.d.ts.map +1 -1
  40. package/dist/dev/fourier-panel.js +4 -3
  41. package/dist/dev/fourier-panel.js.map +1 -1
  42. package/dist/dev/handwriting-panel.d.ts +4 -4
  43. package/dist/dev/handwriting-panel.d.ts.map +1 -1
  44. package/dist/dev/handwriting-panel.js.map +1 -1
  45. package/dist/dev/multi-text-dialog.d.ts.map +1 -1
  46. package/dist/dev/multi-text-dialog.js +23 -12
  47. package/dist/dev/multi-text-dialog.js.map +1 -1
  48. package/dist/dev/player-body.d.ts +1 -1
  49. package/dist/dev/player-body.d.ts.map +1 -1
  50. package/dist/dev/player-body.js +95 -36
  51. package/dist/dev/player-body.js.map +1 -1
  52. package/dist/dev/schedule-helpers.d.ts.map +1 -1
  53. package/dist/dev/schedule-helpers.js +4 -2
  54. package/dist/dev/schedule-helpers.js.map +1 -1
  55. package/dist/dev/static-image-panel.d.ts +3 -3
  56. package/dist/dev/static-image-panel.d.ts.map +1 -1
  57. package/dist/dev/subtitles.d.ts +36 -0
  58. package/dist/dev/subtitles.d.ts.map +1 -0
  59. package/dist/dev/subtitles.js +135 -0
  60. package/dist/dev/subtitles.js.map +1 -0
  61. package/dist/dev/synced-file.d.ts +14 -0
  62. package/dist/dev/synced-file.d.ts.map +1 -1
  63. package/dist/dev/synced-file.js +22 -0
  64. package/dist/dev/synced-file.js.map +1 -1
  65. package/dist/dev/timeline-display.d.ts +5 -0
  66. package/dist/dev/timeline-display.d.ts.map +1 -1
  67. package/dist/dev/timeline-display.js +1 -1
  68. package/dist/dev/timeline-display.js.map +1 -1
  69. package/dist/dev/transcript-align.d.ts +3 -1
  70. package/dist/dev/transcript-align.d.ts.map +1 -1
  71. package/dist/dev/transcript-align.js +2 -0
  72. package/dist/dev/transcript-align.js.map +1 -1
  73. package/dist/dev/transcript-editor.d.ts +36 -0
  74. package/dist/dev/transcript-editor.d.ts.map +1 -0
  75. package/dist/dev/transcript-editor.js +964 -0
  76. package/dist/dev/transcript-editor.js.map +1 -0
  77. package/dist/dev/transcript-export.d.ts +21 -0
  78. package/dist/dev/transcript-export.d.ts.map +1 -1
  79. package/dist/dev/transcript-export.js +65 -0
  80. package/dist/dev/transcript-export.js.map +1 -1
  81. package/dist/dev/transcript-view.d.ts +2 -0
  82. package/dist/dev/transcript-view.d.ts.map +1 -1
  83. package/dist/dev/transcript-view.js +1 -1
  84. package/dist/dev/transcript-view.js.map +1 -1
  85. package/dist/dev/transcripts.d.ts +18 -1
  86. package/dist/dev/transcripts.d.ts.map +1 -1
  87. package/dist/dev/transcripts.js +102 -12
  88. package/dist/dev/transcripts.js.map +1 -1
  89. package/dist/dev/video-clip-panel.d.ts +3 -3
  90. package/dist/dev/video-clip-panel.d.ts.map +1 -1
  91. package/dist/lib/index.d.ts +1 -0
  92. package/dist/lib/index.d.ts.map +1 -1
  93. package/dist/lib/index.js +1 -0
  94. package/dist/lib/index.js.map +1 -1
  95. package/dist/src/glib/line-font.d.ts +6 -0
  96. package/dist/src/glib/line-font.d.ts.map +1 -1
  97. package/dist/src/glib/line-font.js +9 -0
  98. package/dist/src/glib/line-font.js.map +1 -1
  99. package/dist/src/glib/path-shape.d.ts +16 -0
  100. package/dist/src/glib/path-shape.d.ts.map +1 -1
  101. package/dist/src/glib/path-shape.js +23 -0
  102. package/dist/src/glib/path-shape.js.map +1 -1
  103. package/dist/src/glib/transforms.d.ts +9 -0
  104. package/dist/src/glib/transforms.d.ts.map +1 -1
  105. package/dist/src/glib/transforms.js +7 -4
  106. package/dist/src/glib/transforms.js.map +1 -1
  107. package/dist/src/interpolate.d.ts +17 -10
  108. package/dist/src/interpolate.d.ts.map +1 -1
  109. package/dist/src/interpolate.js +1 -17
  110. package/dist/src/interpolate.js.map +1 -1
  111. package/dist/src/morph-animation.js +1 -1
  112. package/dist/src/morph-animation.js.map +1 -1
  113. package/dist/src/peano-fourier/fourier-shared.d.ts.map +1 -1
  114. package/dist/src/peano-fourier/fourier-shared.js +4 -2
  115. package/dist/src/peano-fourier/fourier-shared.js.map +1 -1
  116. package/dist/src/schedule-helper.d.ts +50 -28
  117. package/dist/src/schedule-helper.d.ts.map +1 -1
  118. package/dist/src/schedule-helper.js +22 -0
  119. package/dist/src/schedule-helper.js.map +1 -1
  120. package/dist/src/showable.d.ts +59 -11
  121. package/dist/src/showable.d.ts.map +1 -1
  122. package/dist/src/showable.js +19 -0
  123. package/dist/src/showable.js.map +1 -1
  124. package/dist/src/slide-components/arrow.d.ts +4 -4
  125. package/dist/src/slide-components/arrow.d.ts.map +1 -1
  126. package/dist/src/slide-components/cross-fade-transition.d.ts +2 -1
  127. package/dist/src/slide-components/cross-fade-transition.d.ts.map +1 -1
  128. package/dist/src/slide-components/cross-fade-transition.js +2 -1
  129. package/dist/src/slide-components/cross-fade-transition.js.map +1 -1
  130. package/dist/src/slide-components/duration-agnostic.d.ts +3 -2
  131. package/dist/src/slide-components/duration-agnostic.d.ts.map +1 -1
  132. package/dist/src/slide-components/duration-agnostic.js +4 -2
  133. package/dist/src/slide-components/duration-agnostic.js.map +1 -1
  134. package/dist/src/slide-components/fixed-duration.d.ts +3 -1
  135. package/dist/src/slide-components/fixed-duration.d.ts.map +1 -1
  136. package/dist/src/slide-components/fixed-duration.js +4 -2
  137. package/dist/src/slide-components/fixed-duration.js.map +1 -1
  138. package/dist/src/slide-components/fourier.d.ts +19 -12
  139. package/dist/src/slide-components/fourier.d.ts.map +1 -1
  140. package/dist/src/slide-components/fourier.js +70 -22
  141. package/dist/src/slide-components/fourier.js.map +1 -1
  142. package/dist/src/slide-components/function-graph.d.ts +4 -3
  143. package/dist/src/slide-components/function-graph.d.ts.map +1 -1
  144. package/dist/src/slide-components/function-graph.js +6 -2
  145. package/dist/src/slide-components/function-graph.js.map +1 -1
  146. package/dist/src/slide-components/halftone-shadow.d.ts +8 -7
  147. package/dist/src/slide-components/halftone-shadow.d.ts.map +1 -1
  148. package/dist/src/slide-components/halftone-shadow.js +2 -1
  149. package/dist/src/slide-components/halftone-shadow.js.map +1 -1
  150. package/dist/src/slide-components/handwriting-effect.d.ts +8 -6
  151. package/dist/src/slide-components/handwriting-effect.d.ts.map +1 -1
  152. package/dist/src/slide-components/handwriting-effect.js +4 -2
  153. package/dist/src/slide-components/handwriting-effect.js.map +1 -1
  154. package/dist/src/slide-components/hold.d.ts +4 -2
  155. package/dist/src/slide-components/hold.d.ts.map +1 -1
  156. package/dist/src/slide-components/hold.js +4 -2
  157. package/dist/src/slide-components/hold.js.map +1 -1
  158. package/dist/src/slide-components/image.d.ts +7 -7
  159. package/dist/src/slide-components/image.d.ts.map +1 -1
  160. package/dist/src/slide-components/image.js +4 -2
  161. package/dist/src/slide-components/image.js.map +1 -1
  162. package/dist/src/slide-components/in-parallel.d.ts +12 -3
  163. package/dist/src/slide-components/in-parallel.d.ts.map +1 -1
  164. package/dist/src/slide-components/in-parallel.js +27 -2
  165. package/dist/src/slide-components/in-parallel.js.map +1 -1
  166. package/dist/src/slide-components/in-series.d.ts +2 -1
  167. package/dist/src/slide-components/in-series.d.ts.map +1 -1
  168. package/dist/src/slide-components/in-series.js +2 -1
  169. package/dist/src/slide-components/in-series.js.map +1 -1
  170. package/dist/src/slide-components/live-duration.d.ts +3 -1
  171. package/dist/src/slide-components/live-duration.d.ts.map +1 -1
  172. package/dist/src/slide-components/live-duration.js +4 -2
  173. package/dist/src/slide-components/live-duration.js.map +1 -1
  174. package/dist/src/slide-components/multi-text.d.ts +39 -26
  175. package/dist/src/slide-components/multi-text.d.ts.map +1 -1
  176. package/dist/src/slide-components/multi-text.js +44 -29
  177. package/dist/src/slide-components/multi-text.js.map +1 -1
  178. package/dist/src/slide-components/rectangle.d.ts +5 -4
  179. package/dist/src/slide-components/rectangle.d.ts.map +1 -1
  180. package/dist/src/slide-components/rectangle.js +2 -1
  181. package/dist/src/slide-components/rectangle.js.map +1 -1
  182. package/dist/src/slide-components/registry.d.ts +5 -0
  183. package/dist/src/slide-components/registry.d.ts.map +1 -1
  184. package/dist/src/slide-components/registry.js +28 -27
  185. package/dist/src/slide-components/registry.js.map +1 -1
  186. package/dist/src/slide-components/show-error.d.ts.map +1 -1
  187. package/dist/src/slide-components/show-error.js +3 -2
  188. package/dist/src/slide-components/show-error.js.map +1 -1
  189. package/dist/src/slide-components/simple-text.d.ts +11 -10
  190. package/dist/src/slide-components/simple-text.d.ts.map +1 -1
  191. package/dist/src/slide-components/simple-text.js +5 -3
  192. package/dist/src/slide-components/simple-text.js.map +1 -1
  193. package/dist/src/slide-components/slide-component.d.ts +14 -13
  194. package/dist/src/slide-components/slide-component.d.ts.map +1 -1
  195. package/dist/src/slide-components/slide-component.js +2 -1
  196. package/dist/src/slide-components/slide-component.js.map +1 -1
  197. package/dist/src/slide-components/slide-left.d.ts +2 -1
  198. package/dist/src/slide-components/slide-left.d.ts.map +1 -1
  199. package/dist/src/slide-components/slide-left.js +2 -1
  200. package/dist/src/slide-components/slide-left.js.map +1 -1
  201. package/dist/src/slide-components/text-effect.d.ts +9 -1
  202. package/dist/src/slide-components/text-effect.d.ts.map +1 -1
  203. package/dist/src/slide-components/text-effect.js.map +1 -1
  204. package/dist/src/slide-components/traditional-text.d.ts +8 -8
  205. package/dist/src/slide-components/traditional-text.d.ts.map +1 -1
  206. package/dist/src/slide-components/video-clip.d.ts +5 -4
  207. package/dist/src/slide-components/video-clip.d.ts.map +1 -1
  208. package/dist/src/slide-components/video-clip.js +5 -2
  209. package/dist/src/slide-components/video-clip.js.map +1 -1
  210. package/lib/index.ts +1 -0
  211. package/package.json +2 -2
  212. package/src/glib/line-font.ts +9 -0
  213. package/src/glib/path-shape.ts +35 -0
  214. package/src/glib/transforms.ts +7 -4
  215. package/src/interpolate.ts +18 -27
  216. package/src/morph-animation.ts +1 -1
  217. package/src/peano-fourier/fourier-shared.ts +4 -2
  218. package/src/schedule-helper.ts +50 -28
  219. package/src/showable.ts +81 -11
  220. package/src/slide-components/arrow.ts +4 -4
  221. package/src/slide-components/cross-fade-transition.ts +9 -2
  222. package/src/slide-components/duration-agnostic.ts +4 -3
  223. package/src/slide-components/fixed-duration.ts +4 -2
  224. package/src/slide-components/fourier.ts +89 -32
  225. package/src/slide-components/function-graph.ts +7 -3
  226. package/src/slide-components/halftone-shadow.ts +9 -7
  227. package/src/slide-components/handwriting-effect.ts +8 -6
  228. package/src/slide-components/hold.ts +18 -4
  229. package/src/slide-components/image.ts +9 -7
  230. package/src/slide-components/in-parallel.ts +31 -1
  231. package/src/slide-components/in-series.ts +3 -1
  232. package/src/slide-components/live-duration.ts +4 -2
  233. package/src/slide-components/multi-text.ts +71 -44
  234. package/src/slide-components/rectangle.ts +6 -4
  235. package/src/slide-components/registry.ts +33 -27
  236. package/src/slide-components/show-error.ts +4 -2
  237. package/src/slide-components/simple-text.ts +22 -12
  238. package/src/slide-components/slide-component.ts +15 -13
  239. package/src/slide-components/slide-left.ts +9 -2
  240. package/src/slide-components/text-effect.ts +9 -0
  241. package/src/slide-components/traditional-text.ts +8 -8
  242. package/src/slide-components/video-clip.ts +9 -5
@@ -123,3 +123,93 @@ export function transcriptFileName(source: string): string {
123
123
  decodeURIComponent(source.split("/").pop() ?? "sound") || "sound";
124
124
  return name.replace(/\.[^.]*$/, "") + ".transcript.json";
125
125
  }
126
+
127
+ // MARK: Every transcript in the video
128
+
129
+ /** One sound file the video uses, for {@link transcriptsFileText}. */
130
+ export type VideoTranscript = {
131
+ readonly source: string;
132
+ /** Undefined until it's ready. Then {@link status} says why. */
133
+ readonly transcript: Transcript | undefined;
134
+ /** "ready", or how it's coming along. */
135
+ readonly status: string;
136
+ /** Each place the video plays this file. */
137
+ readonly uses: readonly {
138
+ readonly startsInVideoMs: number;
139
+ readonly playsFileFromMs: number;
140
+ /** Null when it plays to the end of the file. */
141
+ readonly playsFileToMs: number | null;
142
+ }[];
143
+ };
144
+
145
+ /**
146
+ * Every transcript the video uses, for the "Sync transcripts to file" checkbox. It's written
147
+ * for a second pair of eyes, a person or Claude, looking for words that are probably wrong.
148
+ * Each word is on its own line, so the file diffs and greps by word.
149
+ */
150
+ export function transcriptsFileText(
151
+ videoName: string,
152
+ files: readonly VideoTranscript[],
153
+ ): string {
154
+ const wordLists: string[] = [];
155
+ const body = {
156
+ about: [
157
+ "Every word-by-word transcript the video uses, saved from the canvas-recorder Visual Editor.",
158
+ "Fix words in the editor: select a sound clip, then ✎ (Edit Transcript). This file is only a copy, and changes made here are overwritten.",
159
+ "Times are in milliseconds from the start of each FILE. For video time: startsInVideoMs + (time - playsFileFromMs).",
160
+ "timing: 'aligned' is Whisper's word, timed by a letter model (wav2vec2). 'whisper' kept Whisper's rougher times. " +
161
+ "'letters' is speech Whisper LEFT OUT (repeats, false starts, ums), spelled by sound; it isn't in the subtitles. " +
162
+ "'edited' was typed, timed or checked by a person.",
163
+ "heard: what the letter model heard on its own, spelled by sound. When it disagrees with text, or is empty, that's worth a listen.",
164
+ "confidence: 0 to 1, how well the audio matched the letters.",
165
+ "flag: only on words worth a look. See 'timing' and 'heard'.",
166
+ ],
167
+ video: videoName,
168
+ pipelineVersion: PIPELINE_VERSION,
169
+ models: MODELS,
170
+ files: files.map(({ source, transcript, status, uses }) => {
171
+ if (!transcript) return { file: source, status, usedInVideo: uses };
172
+ const placeholder = `@@WORDS${wordLists.length}@@`;
173
+ wordLists.push(wordList(transcript.words));
174
+ return {
175
+ file: source,
176
+ status,
177
+ madeAt: new Date(transcript.madeAt).toISOString(),
178
+ editedAt:
179
+ transcript.editedAt === undefined
180
+ ? null
181
+ : new Date(transcript.editedAt).toISOString(),
182
+ usedInVideo: uses.map((use) => ({
183
+ startsInVideoMs: ms(use.startsInVideoMs),
184
+ playsFileFromMs: ms(use.playsFileFromMs),
185
+ playsFileToMs:
186
+ use.playsFileToMs === null ? null : ms(use.playsFileToMs),
187
+ })),
188
+ text: asText(transcript.words),
189
+ words: placeholder,
190
+ };
191
+ }),
192
+ };
193
+ let text = JSON.stringify(body, null, 2);
194
+ wordLists.forEach((list, i) => {
195
+ text = text.replace(`"@@WORDS${i}@@"`, () => list);
196
+ });
197
+ return text + "\n";
198
+ }
199
+
200
+ /** One word per line, indented to sit inside a file's entry. */
201
+ function wordList(words: readonly TranscriptWord[]): string {
202
+ if (words.length === 0) return "[]";
203
+ const lines = words.map((w) =>
204
+ JSON.stringify({
205
+ text: w.text,
206
+ startMs: ms(w.startMs),
207
+ endMs: ms(w.endMs),
208
+ timing: w.timing,
209
+ confidence: Math.round(w.confidence * 1000) / 1000,
210
+ heard: w.heard,
211
+ flag: wordFlag(w),
212
+ }),
213
+ );
214
+ return `[\n ${lines.join(",\n ")}\n ]`;
215
+ }
@@ -21,10 +21,13 @@ export type TranscriptViewHooks = {
21
21
  * A file's transcript, a line saying how it's coming along, or undefined
22
22
  * when transcripts are off.
23
23
  */
24
- transcript(
25
- source: string,
26
- ):
27
- | { readonly words: readonly TranscriptWord[]; readonly madeAt: number }
24
+ transcript(source: string):
25
+ | {
26
+ readonly words: readonly TranscriptWord[];
27
+ readonly madeAt: number;
28
+ /** Set by the Transcript Editor. */
29
+ readonly editedAt?: number;
30
+ }
28
31
  | string
29
32
  | undefined;
30
33
  /** Why this clip's file can't be played, if it can't. Shown above its words. */
@@ -324,7 +327,7 @@ export class TranscriptView {
324
327
  clip.startMsIntoClip ?? 0,
325
328
  lengthMs ?? null,
326
329
  clip.notes ?? "",
327
- typeof t === "object" ? t.madeAt : (t ?? null),
330
+ typeof t === "object" ? (t.editedAt ?? t.madeAt) : (t ?? null),
328
331
  problems[i] ?? null,
329
332
  ];
330
333
  }),
@@ -35,8 +35,15 @@ export type Transcript = {
35
35
  readonly device: string;
36
36
  readonly elapsedMs: number;
37
37
  readonly madeAt: number;
38
+ /** When someone last changed it in the Transcript Editor. Undefined if nobody has. */
39
+ readonly editedAt?: number;
38
40
  };
39
41
 
42
+ /** Changes whenever the words do: when it's made, and on every edit. For caches. */
43
+ export function transcriptVersion(transcript: Transcript): number {
44
+ return transcript.editedAt ?? transcript.madeAt;
45
+ }
46
+
40
47
  export type TranscriptStatus =
41
48
  | { readonly kind: "waiting" }
42
49
  | {
@@ -213,9 +220,9 @@ async function transcriptFor(
213
220
  url: string,
214
221
  onProgress: (progress: TranscribeProgress) => void,
215
222
  ): Promise<Transcript> {
216
- let key: string;
223
+ let fingerprint: string;
217
224
  try {
218
- key = await cacheKey(url);
225
+ fingerprint = await fileFingerprint(url);
219
226
  } catch (error) {
220
227
  const newest = await newestCached(url);
221
228
  if (!newest) throw error;
@@ -223,12 +230,21 @@ async function transcriptFor(
223
230
  "transcripts",
224
231
  `Using the last transcript of "${url}" without checking the file: ${String(error).replace(/^Error:\s*/, "")}`,
225
232
  );
233
+ cacheKeys.set(url, { key: newest.key, fingerprint: newest.fingerprint });
226
234
  return newest;
227
235
  }
236
+ const key = keyPrefix(url) + fingerprint;
237
+ cacheKeys.set(url, { key, fingerprint });
228
238
  const cached = await readCache(key);
229
239
  if (cached) return cached;
240
+ // A new pipeline makes a new transcript, but a person's edits win: they were checked by ear.
241
+ const edited = await editedBefore(url, fingerprint);
242
+ if (edited) {
243
+ await writeCache(key, url, edited, fingerprint);
244
+ return edited;
245
+ }
230
246
  const transcript = await makeTranscript(url, onProgress);
231
- await writeCache(key, url, transcript);
247
+ await writeCache(key, url, transcript, fingerprint);
232
248
  return transcript;
233
249
  }
234
250
 
@@ -251,6 +267,108 @@ export async function makeTranscript(
251
267
  };
252
268
  }
253
269
 
270
+ // MARK: Editing
271
+
272
+ /** Where each ready transcript is in IndexedDB, so an edit replaces that record. */
273
+ const cacheKeys = new Map<
274
+ string,
275
+ { readonly key: string; readonly fingerprint: string | undefined }
276
+ >();
277
+
278
+ /** Edits not written to IndexedDB yet: the newest version of each. */
279
+ const unsaved = new Map<
280
+ string,
281
+ {
282
+ readonly key: string;
283
+ readonly fingerprint: string | undefined;
284
+ readonly transcript: Transcript;
285
+ }
286
+ >();
287
+ let saving = Promise.resolve();
288
+
289
+ /**
290
+ * Replace the words of `url`'s transcript, as the Transcript Editor does. Everything that
291
+ * shows the transcript follows at once.
292
+ *
293
+ * The edited transcript replaces the one in IndexedDB, under the same key, so it belongs to
294
+ * the file as it is now. Re-recording the file starts over with a new transcript. A new
295
+ * transcription pipeline keeps the edits: see {@link editedBefore}.
296
+ * @returns False if the transcript isn't ready, so there's nothing to edit.
297
+ */
298
+ export function editTranscript(
299
+ url: string,
300
+ words: readonly TranscriptWord[],
301
+ ): boolean {
302
+ const status = statuses.get(url);
303
+ const where = cacheKeys.get(url);
304
+ if (status?.kind !== "ready" || !where) return false;
305
+ const previous = status.transcript;
306
+ const transcript: Transcript = {
307
+ words,
308
+ device: previous.device,
309
+ elapsedMs: previous.elapsedMs,
310
+ madeAt: previous.madeAt,
311
+ // Always larger than last time, since caches compare it.
312
+ editedAt: Math.max(Date.now(), (previous.editedAt ?? 0) + 1),
313
+ };
314
+ setStatus(url, { kind: "ready", transcript });
315
+ unsaved.set(url, { ...where, transcript });
316
+ saving = saving.then(saveEdits);
317
+ return true;
318
+ }
319
+
320
+ /** Write the newest version of each edited transcript. A burst of edits writes each once. */
321
+ async function saveEdits(): Promise<void> {
322
+ for (const [url, { key, fingerprint, transcript }] of unsaved) {
323
+ unsaved.delete(url);
324
+ try {
325
+ await writeCache(key, url, transcript, fingerprint);
326
+ } catch (error) {
327
+ console.error(`Couldn't save the edits to "${url}":`, error);
328
+ debugLog(
329
+ "transcripts",
330
+ `Couldn't save the edits to "${url}": ${String(error)}`,
331
+ );
332
+ }
333
+ }
334
+ }
335
+
336
+ /**
337
+ * The newest edited transcript of this file, as it is now, made by any pipeline. So a new
338
+ * pipeline version doesn't throw away what a person fixed.
339
+ */
340
+ async function editedBefore(
341
+ url: string,
342
+ fingerprint: string,
343
+ ): Promise<Transcript | undefined> {
344
+ const db = await openDb();
345
+ const records = await new Promise<CacheRecord[]>((resolve, reject) => {
346
+ const request = db.transaction(STORE).objectStore(STORE).getAll();
347
+ request.onsuccess = () => resolve(request.result as CacheRecord[]);
348
+ request.onerror = () => reject(request.error);
349
+ });
350
+ const newest = records
351
+ .filter(
352
+ (r) =>
353
+ r.url === url &&
354
+ r.fingerprint === fingerprint &&
355
+ r.editedAt !== undefined,
356
+ )
357
+ .reduce<CacheRecord | undefined>(
358
+ (newest, r) => (newest && newest.editedAt! >= r.editedAt! ? newest : r),
359
+ undefined,
360
+ );
361
+ if (!newest) return undefined;
362
+ debugLog("transcripts", `Kept the edited transcript of "${url}".`);
363
+ return {
364
+ words: newest.words,
365
+ device: newest.device,
366
+ elapsedMs: newest.elapsedMs,
367
+ madeAt: newest.madeAt,
368
+ editedAt: newest.editedAt,
369
+ };
370
+ }
371
+
254
372
  // MARK: Audio
255
373
 
256
374
  /** The file at `url` as 16 kHz mono, the way the models want it. */
@@ -331,7 +449,12 @@ function runWorker(
331
449
  const DB_NAME = "canvas-recorder-transcripts";
332
450
  const STORE = "transcripts";
333
451
 
334
- type CacheRecord = Transcript & { readonly key: string; readonly url: string };
452
+ type CacheRecord = Transcript & {
453
+ readonly key: string;
454
+ readonly url: string;
455
+ /** The file's part of the key. Missing from records made before edits were possible. */
456
+ readonly fingerprint?: string;
457
+ };
335
458
 
336
459
  /**
337
460
  * Which transcript belongs to this file, as it is now.
@@ -341,30 +464,27 @@ type CacheRecord = Transcript & { readonly key: string; readonly url: string };
341
464
  * would cost real time on every page load, and the page reloads on every
342
465
  * save. Only a server that sends none of those headers gets its files hashed.
343
466
  */
344
- async function cacheKey(url: string): Promise<string> {
345
- const prefix = keyPrefix(url);
467
+ async function fileFingerprint(url: string): Promise<string> {
346
468
  // For a local file, fetchMedia() answers with its size and modification time.
347
469
  const head = await fetchMedia(url, { method: "HEAD", cache: "no-cache" });
348
470
  if (!head.ok) throw new Error(`${head.status} ${head.statusText}`);
349
471
  const etag = head.headers.get("etag");
350
472
  const modified = head.headers.get("last-modified");
351
473
  const length = head.headers.get("content-length");
352
- if (etag) return prefix + etag;
353
- if (modified && length) return `${prefix}${modified} ${length}`;
474
+ if (etag) return etag;
475
+ if (modified && length) return `${modified} ${length}`;
354
476
  const bytes = await (await fetchMedia(url)).arrayBuffer();
355
477
  const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", bytes));
356
- return (
357
- prefix + Array.from(digest, (b) => b.toString(16).padStart(2, "0")).join("")
358
- );
478
+ return Array.from(digest, (b) => b.toString(16).padStart(2, "0")).join("");
359
479
  }
360
480
 
361
- /** Every {@link cacheKey} of this URL starts with this: everything but the file's fingerprint. */
481
+ /** Every cache key of this URL starts with this, and ends with the file's {@link fileFingerprint}. */
362
482
  function keyPrefix(url: string): string {
363
483
  return `${PIPELINE_VERSION}|${MODELS.whisper}|${new URL(url, location.href).href}|`;
364
484
  }
365
485
 
366
486
  /** The newest transcript of this URL, whatever the file's fingerprint was then. */
367
- async function newestCached(url: string): Promise<Transcript | undefined> {
487
+ async function newestCached(url: string): Promise<CacheRecord | undefined> {
368
488
  const prefix = keyPrefix(url);
369
489
  const db = await openDb();
370
490
  const records = await new Promise<CacheRecord[]>((resolve, reject) => {
@@ -409,19 +529,23 @@ async function writeCache(
409
529
  key: string,
410
530
  url: string,
411
531
  transcript: Transcript,
532
+ fingerprint: string | undefined,
412
533
  ): Promise<void> {
413
534
  const db = await openDb();
414
535
  return new Promise((resolve, reject) => {
415
536
  const transaction = db.transaction(STORE, "readwrite");
416
537
  transaction
417
538
  .objectStore(STORE)
418
- .put({ ...transcript, key, url } satisfies CacheRecord);
539
+ .put({ ...transcript, key, url, fingerprint } satisfies CacheRecord);
419
540
  transaction.oncomplete = () => resolve();
420
541
  transaction.onerror = () => reject(transaction.error);
421
542
  });
422
543
  }
423
544
 
424
- /** Throw away every saved transcript, so they're all made again. For the console. */
545
+ /**
546
+ * Throw away every saved transcript, so they're all made again. For the console.
547
+ * This throws away the Transcript Editor's changes too.
548
+ */
425
549
  export async function forgetTranscripts(): Promise<void> {
426
550
  const db = await openDb();
427
551
  await new Promise<void>((resolve, reject) => {
@@ -431,5 +555,6 @@ export async function forgetTranscripts(): Promise<void> {
431
555
  transaction.onerror = () => reject(transaction.error);
432
556
  });
433
557
  statuses.clear();
558
+ cacheKeys.clear();
434
559
  changed();
435
560
  }
@@ -1,5 +1,5 @@
1
1
  import { ReadOnlyRect } from "phil-lib/misc";
2
- import { Keyframe } from "../src/interpolate.ts";
2
+ import { TimedKeyframe } from "../src/interpolate.ts";
3
3
  import { SoundClip } from "../src/showable.ts";
4
4
  import { canvasRecorder, type VideoSize } from "../lib/main-control.ts";
5
5
  import { VideoClipComponent } from "../src/slide-components/video-clip.ts";
@@ -47,9 +47,9 @@ export type VideoClipPanelHooks = {
47
47
  */
48
48
  readonly scalarsChanged: () => void;
49
49
  /** A Dest Rect keyframe's value was replaced. Sync its number fields and on-canvas handles, and save. */
50
- readonly rectKeyframeChanged: (keyframe: Keyframe<ReadOnlyRect>) => void;
50
+ readonly rectKeyframeChanged: (keyframe: TimedKeyframe<ReadOnlyRect>) => void;
51
51
  /** The Dest Rect keyframe in ✎ edit mode, if there is one. */
52
- readonly editingRectKeyframe: () => Keyframe<ReadOnlyRect> | null;
52
+ readonly editingRectKeyframe: () => TimedKeyframe<ReadOnlyRect> | null;
53
53
  /** The clip's sound clips were replaced by a button here. Rebuild the Sound Clips list. */
54
54
  readonly soundClipsChanged: () => void;
55
55
  /** Why ✂ Split… can't be used right now, or undefined when it can. */
@@ -608,7 +608,7 @@ export function buildVideoClipPanel(
608
608
  });
609
609
 
610
610
  /** Which Dest Rect keyframe a button should change, or why it can't decide. */
611
- function targetKeyframe(): Keyframe<ReadOnlyRect> | string {
611
+ function targetKeyframe(): TimedKeyframe<ReadOnlyRect> | string {
612
612
  const schedule = clip.destinationRectSchedule.schedule;
613
613
  if (schedule.length === 1) return schedule[0];
614
614
  const editing = hooks.editingRectKeyframe();
@@ -331,6 +331,20 @@ body {
331
331
  margin: 0;
332
332
  }
333
333
 
334
+ /* A text schedule's table, whose text box takes the spare width. See growValue in
335
+ canvas-recorder.ts. Its Value column asks for all the width, which squeezes the other
336
+ columns to their narrowest. With room to spare, the headers stay on one line, so the
337
+ other columns keep their natural widths. Only a narrow panel wraps them. */
338
+ .grow-value {
339
+ container-type: inline-size;
340
+ }
341
+
342
+ @container (min-width: 30em) {
343
+ .grow-value th {
344
+ white-space: nowrap;
345
+ }
346
+ }
347
+
334
348
  /* ── Misc retained rules ─────────────────────────────────────────────── */
335
349
 
336
350
  #limitsRow {