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.
- package/README.md +10 -2
- package/dev/canvas-recorder.css +14 -0
- package/dev/canvas-recorder.ts +500 -84
- package/dev/color-picker.ts +13 -0
- package/dev/component-picker.ts +60 -11
- package/dev/font-widgets.ts +2 -2
- package/dev/format-editor.ts +3 -1
- package/dev/fourier-panel.ts +7 -3
- package/dev/handwriting-panel.ts +7 -7
- package/dev/multi-text-dialog.ts +28 -15
- package/dev/player-body.ts +95 -36
- package/dev/schedule-helpers.ts +10 -3
- package/dev/static-image-panel.ts +4 -4
- package/dev/subtitles.ts +170 -0
- package/dev/synced-file.ts +34 -0
- package/dev/timeline-display.ts +1 -1
- package/dev/transcript-align.ts +4 -1
- package/dev/transcript-editor.ts +1205 -0
- package/dev/transcript-export.ts +90 -0
- package/dev/transcript-view.ts +8 -5
- package/dev/transcripts.ts +140 -15
- package/dev/video-clip-panel.ts +4 -4
- package/dist/dev/canvas-recorder.css +14 -0
- package/dist/dev/canvas-recorder.js +408 -74
- package/dist/dev/canvas-recorder.js.map +1 -1
- package/dist/dev/color-picker.d.ts.map +1 -1
- package/dist/dev/color-picker.js +15 -0
- package/dist/dev/color-picker.js.map +1 -1
- package/dist/dev/component-picker.d.ts +2 -1
- package/dist/dev/component-picker.d.ts.map +1 -1
- package/dist/dev/component-picker.js +56 -11
- package/dist/dev/component-picker.js.map +1 -1
- package/dist/dev/font-widgets.d.ts +2 -2
- package/dist/dev/font-widgets.d.ts.map +1 -1
- package/dist/dev/font-widgets.js.map +1 -1
- package/dist/dev/format-editor.d.ts.map +1 -1
- package/dist/dev/format-editor.js +3 -1
- package/dist/dev/format-editor.js.map +1 -1
- package/dist/dev/fourier-panel.d.ts.map +1 -1
- package/dist/dev/fourier-panel.js +4 -3
- package/dist/dev/fourier-panel.js.map +1 -1
- package/dist/dev/handwriting-panel.d.ts +4 -4
- package/dist/dev/handwriting-panel.d.ts.map +1 -1
- package/dist/dev/handwriting-panel.js.map +1 -1
- package/dist/dev/multi-text-dialog.d.ts.map +1 -1
- package/dist/dev/multi-text-dialog.js +23 -12
- package/dist/dev/multi-text-dialog.js.map +1 -1
- package/dist/dev/player-body.d.ts +1 -1
- package/dist/dev/player-body.d.ts.map +1 -1
- package/dist/dev/player-body.js +95 -36
- package/dist/dev/player-body.js.map +1 -1
- package/dist/dev/schedule-helpers.d.ts.map +1 -1
- package/dist/dev/schedule-helpers.js +4 -2
- package/dist/dev/schedule-helpers.js.map +1 -1
- package/dist/dev/static-image-panel.d.ts +3 -3
- package/dist/dev/static-image-panel.d.ts.map +1 -1
- package/dist/dev/subtitles.d.ts +36 -0
- package/dist/dev/subtitles.d.ts.map +1 -0
- package/dist/dev/subtitles.js +135 -0
- package/dist/dev/subtitles.js.map +1 -0
- package/dist/dev/synced-file.d.ts +14 -0
- package/dist/dev/synced-file.d.ts.map +1 -1
- package/dist/dev/synced-file.js +22 -0
- package/dist/dev/synced-file.js.map +1 -1
- package/dist/dev/timeline-display.d.ts +5 -0
- package/dist/dev/timeline-display.d.ts.map +1 -1
- package/dist/dev/timeline-display.js +1 -1
- package/dist/dev/timeline-display.js.map +1 -1
- package/dist/dev/transcript-align.d.ts +3 -1
- package/dist/dev/transcript-align.d.ts.map +1 -1
- package/dist/dev/transcript-align.js +2 -0
- package/dist/dev/transcript-align.js.map +1 -1
- package/dist/dev/transcript-editor.d.ts +36 -0
- package/dist/dev/transcript-editor.d.ts.map +1 -0
- package/dist/dev/transcript-editor.js +964 -0
- package/dist/dev/transcript-editor.js.map +1 -0
- package/dist/dev/transcript-export.d.ts +21 -0
- package/dist/dev/transcript-export.d.ts.map +1 -1
- package/dist/dev/transcript-export.js +65 -0
- package/dist/dev/transcript-export.js.map +1 -1
- package/dist/dev/transcript-view.d.ts +2 -0
- package/dist/dev/transcript-view.d.ts.map +1 -1
- package/dist/dev/transcript-view.js +1 -1
- package/dist/dev/transcript-view.js.map +1 -1
- package/dist/dev/transcripts.d.ts +18 -1
- package/dist/dev/transcripts.d.ts.map +1 -1
- package/dist/dev/transcripts.js +102 -12
- package/dist/dev/transcripts.js.map +1 -1
- package/dist/dev/video-clip-panel.d.ts +3 -3
- package/dist/dev/video-clip-panel.d.ts.map +1 -1
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +1 -0
- package/dist/lib/index.js.map +1 -1
- package/dist/src/glib/line-font.d.ts +6 -0
- package/dist/src/glib/line-font.d.ts.map +1 -1
- package/dist/src/glib/line-font.js +9 -0
- package/dist/src/glib/line-font.js.map +1 -1
- package/dist/src/glib/path-shape.d.ts +16 -0
- package/dist/src/glib/path-shape.d.ts.map +1 -1
- package/dist/src/glib/path-shape.js +23 -0
- package/dist/src/glib/path-shape.js.map +1 -1
- package/dist/src/glib/transforms.d.ts +9 -0
- package/dist/src/glib/transforms.d.ts.map +1 -1
- package/dist/src/glib/transforms.js +7 -4
- package/dist/src/glib/transforms.js.map +1 -1
- package/dist/src/interpolate.d.ts +17 -10
- package/dist/src/interpolate.d.ts.map +1 -1
- package/dist/src/interpolate.js +1 -17
- package/dist/src/interpolate.js.map +1 -1
- package/dist/src/morph-animation.js +1 -1
- package/dist/src/morph-animation.js.map +1 -1
- package/dist/src/peano-fourier/fourier-shared.d.ts.map +1 -1
- package/dist/src/peano-fourier/fourier-shared.js +4 -2
- package/dist/src/peano-fourier/fourier-shared.js.map +1 -1
- package/dist/src/schedule-helper.d.ts +50 -28
- package/dist/src/schedule-helper.d.ts.map +1 -1
- package/dist/src/schedule-helper.js +22 -0
- package/dist/src/schedule-helper.js.map +1 -1
- package/dist/src/showable.d.ts +59 -11
- package/dist/src/showable.d.ts.map +1 -1
- package/dist/src/showable.js +19 -0
- package/dist/src/showable.js.map +1 -1
- package/dist/src/slide-components/arrow.d.ts +4 -4
- package/dist/src/slide-components/arrow.d.ts.map +1 -1
- package/dist/src/slide-components/cross-fade-transition.d.ts +2 -1
- package/dist/src/slide-components/cross-fade-transition.d.ts.map +1 -1
- package/dist/src/slide-components/cross-fade-transition.js +2 -1
- package/dist/src/slide-components/cross-fade-transition.js.map +1 -1
- package/dist/src/slide-components/duration-agnostic.d.ts +3 -2
- package/dist/src/slide-components/duration-agnostic.d.ts.map +1 -1
- package/dist/src/slide-components/duration-agnostic.js +4 -2
- package/dist/src/slide-components/duration-agnostic.js.map +1 -1
- package/dist/src/slide-components/fixed-duration.d.ts +3 -1
- package/dist/src/slide-components/fixed-duration.d.ts.map +1 -1
- package/dist/src/slide-components/fixed-duration.js +4 -2
- package/dist/src/slide-components/fixed-duration.js.map +1 -1
- package/dist/src/slide-components/fourier.d.ts +19 -12
- package/dist/src/slide-components/fourier.d.ts.map +1 -1
- package/dist/src/slide-components/fourier.js +70 -22
- package/dist/src/slide-components/fourier.js.map +1 -1
- package/dist/src/slide-components/function-graph.d.ts +4 -3
- package/dist/src/slide-components/function-graph.d.ts.map +1 -1
- package/dist/src/slide-components/function-graph.js +6 -2
- package/dist/src/slide-components/function-graph.js.map +1 -1
- package/dist/src/slide-components/halftone-shadow.d.ts +8 -7
- package/dist/src/slide-components/halftone-shadow.d.ts.map +1 -1
- package/dist/src/slide-components/halftone-shadow.js +2 -1
- package/dist/src/slide-components/halftone-shadow.js.map +1 -1
- package/dist/src/slide-components/handwriting-effect.d.ts +8 -6
- package/dist/src/slide-components/handwriting-effect.d.ts.map +1 -1
- package/dist/src/slide-components/handwriting-effect.js +4 -2
- package/dist/src/slide-components/handwriting-effect.js.map +1 -1
- package/dist/src/slide-components/hold.d.ts +4 -2
- package/dist/src/slide-components/hold.d.ts.map +1 -1
- package/dist/src/slide-components/hold.js +4 -2
- package/dist/src/slide-components/hold.js.map +1 -1
- package/dist/src/slide-components/image.d.ts +7 -7
- package/dist/src/slide-components/image.d.ts.map +1 -1
- package/dist/src/slide-components/image.js +4 -2
- package/dist/src/slide-components/image.js.map +1 -1
- package/dist/src/slide-components/in-parallel.d.ts +12 -3
- package/dist/src/slide-components/in-parallel.d.ts.map +1 -1
- package/dist/src/slide-components/in-parallel.js +27 -2
- package/dist/src/slide-components/in-parallel.js.map +1 -1
- package/dist/src/slide-components/in-series.d.ts +2 -1
- package/dist/src/slide-components/in-series.d.ts.map +1 -1
- package/dist/src/slide-components/in-series.js +2 -1
- package/dist/src/slide-components/in-series.js.map +1 -1
- package/dist/src/slide-components/live-duration.d.ts +3 -1
- package/dist/src/slide-components/live-duration.d.ts.map +1 -1
- package/dist/src/slide-components/live-duration.js +4 -2
- package/dist/src/slide-components/live-duration.js.map +1 -1
- package/dist/src/slide-components/multi-text.d.ts +39 -26
- package/dist/src/slide-components/multi-text.d.ts.map +1 -1
- package/dist/src/slide-components/multi-text.js +44 -29
- package/dist/src/slide-components/multi-text.js.map +1 -1
- package/dist/src/slide-components/rectangle.d.ts +5 -4
- package/dist/src/slide-components/rectangle.d.ts.map +1 -1
- package/dist/src/slide-components/rectangle.js +2 -1
- package/dist/src/slide-components/rectangle.js.map +1 -1
- package/dist/src/slide-components/registry.d.ts +5 -0
- package/dist/src/slide-components/registry.d.ts.map +1 -1
- package/dist/src/slide-components/registry.js +28 -27
- package/dist/src/slide-components/registry.js.map +1 -1
- package/dist/src/slide-components/show-error.d.ts.map +1 -1
- package/dist/src/slide-components/show-error.js +3 -2
- package/dist/src/slide-components/show-error.js.map +1 -1
- package/dist/src/slide-components/simple-text.d.ts +11 -10
- package/dist/src/slide-components/simple-text.d.ts.map +1 -1
- package/dist/src/slide-components/simple-text.js +5 -3
- package/dist/src/slide-components/simple-text.js.map +1 -1
- package/dist/src/slide-components/slide-component.d.ts +14 -13
- package/dist/src/slide-components/slide-component.d.ts.map +1 -1
- package/dist/src/slide-components/slide-component.js +2 -1
- package/dist/src/slide-components/slide-component.js.map +1 -1
- package/dist/src/slide-components/slide-left.d.ts +2 -1
- package/dist/src/slide-components/slide-left.d.ts.map +1 -1
- package/dist/src/slide-components/slide-left.js +2 -1
- package/dist/src/slide-components/slide-left.js.map +1 -1
- package/dist/src/slide-components/text-effect.d.ts +9 -1
- package/dist/src/slide-components/text-effect.d.ts.map +1 -1
- package/dist/src/slide-components/text-effect.js.map +1 -1
- package/dist/src/slide-components/traditional-text.d.ts +8 -8
- package/dist/src/slide-components/traditional-text.d.ts.map +1 -1
- package/dist/src/slide-components/video-clip.d.ts +5 -4
- package/dist/src/slide-components/video-clip.d.ts.map +1 -1
- package/dist/src/slide-components/video-clip.js +5 -2
- package/dist/src/slide-components/video-clip.js.map +1 -1
- package/lib/index.ts +1 -0
- package/package.json +2 -2
- package/src/glib/line-font.ts +9 -0
- package/src/glib/path-shape.ts +35 -0
- package/src/glib/transforms.ts +7 -4
- package/src/interpolate.ts +18 -27
- package/src/morph-animation.ts +1 -1
- package/src/peano-fourier/fourier-shared.ts +4 -2
- package/src/schedule-helper.ts +50 -28
- package/src/showable.ts +81 -11
- package/src/slide-components/arrow.ts +4 -4
- package/src/slide-components/cross-fade-transition.ts +9 -2
- package/src/slide-components/duration-agnostic.ts +4 -3
- package/src/slide-components/fixed-duration.ts +4 -2
- package/src/slide-components/fourier.ts +89 -32
- package/src/slide-components/function-graph.ts +7 -3
- package/src/slide-components/halftone-shadow.ts +9 -7
- package/src/slide-components/handwriting-effect.ts +8 -6
- package/src/slide-components/hold.ts +18 -4
- package/src/slide-components/image.ts +9 -7
- package/src/slide-components/in-parallel.ts +31 -1
- package/src/slide-components/in-series.ts +3 -1
- package/src/slide-components/live-duration.ts +4 -2
- package/src/slide-components/multi-text.ts +71 -44
- package/src/slide-components/rectangle.ts +6 -4
- package/src/slide-components/registry.ts +33 -27
- package/src/slide-components/show-error.ts +4 -2
- package/src/slide-components/simple-text.ts +22 -12
- package/src/slide-components/slide-component.ts +15 -13
- package/src/slide-components/slide-left.ts +9 -2
- package/src/slide-components/text-effect.ts +9 -0
- package/src/slide-components/traditional-text.ts +8 -8
- package/src/slide-components/video-clip.ts +9 -5
package/dev/transcript-export.ts
CHANGED
|
@@ -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
|
+
}
|
package/dev/transcript-view.ts
CHANGED
|
@@ -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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
}),
|
package/dev/transcripts.ts
CHANGED
|
@@ -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
|
|
223
|
+
let fingerprint: string;
|
|
217
224
|
try {
|
|
218
|
-
|
|
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 & {
|
|
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
|
|
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
|
|
353
|
-
if (modified && length) return `${
|
|
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
|
|
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<
|
|
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
|
-
/**
|
|
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
|
}
|
package/dev/video-clip-panel.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReadOnlyRect } from "phil-lib/misc";
|
|
2
|
-
import {
|
|
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:
|
|
50
|
+
readonly rectKeyframeChanged: (keyframe: TimedKeyframe<ReadOnlyRect>) => void;
|
|
51
51
|
/** The Dest Rect keyframe in ✎ edit mode, if there is one. */
|
|
52
|
-
readonly editingRectKeyframe: () =>
|
|
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():
|
|
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 {
|