canvas-recorder-lib 0.8.3 → 0.8.4
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 +379 -45
- 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 +75 -30
- 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 +1187 -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 +304 -39
- 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 +75 -30
- 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 +948 -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 +57 -10
- 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 +6 -3
- package/dist/src/slide-components/in-parallel.d.ts.map +1 -1
- package/dist/src/slide-components/in-parallel.js +12 -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 +4 -3
- package/dist/src/slide-components/video-clip.d.ts.map +1 -1
- package/dist/src/slide-components/video-clip.js +2 -1
- 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 +79 -10
- 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 +16 -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 +5 -3
package/dev/subtitles.ts
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import type { PlacedSoundClip } from "./soundtrack.ts";
|
|
2
|
+
import type { TranscriptWord } from "./transcript-align.ts";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Subtitles for a saved video, made from the transcripts of its sound clips.
|
|
6
|
+
*
|
|
7
|
+
* Word by word, the way YouTube shows its own automatic captions: each word appears as it's
|
|
8
|
+
* spoken, and the line before stays on screen above the one being spoken. Every change is its
|
|
9
|
+
* own cue, so any player shows it this way, with no styling and no timestamps inside a cue.
|
|
10
|
+
*
|
|
11
|
+
* See "Transcript Editor" in development-plans/saturday-afternoon.md.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** One word, in the video's time. */
|
|
15
|
+
export type SubtitleWord = {
|
|
16
|
+
readonly text: string;
|
|
17
|
+
readonly startMs: number;
|
|
18
|
+
readonly endMs: number;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** A line breaks before it gets longer than this. About as long as YouTube's own lines. */
|
|
22
|
+
const MAX_LINE_CHARACTERS = 42;
|
|
23
|
+
/** A silence this long starts a new line. */
|
|
24
|
+
const PAUSE_MS = 1000;
|
|
25
|
+
/** How long the last line stays up after its last word, unless the next line comes sooner. */
|
|
26
|
+
const HOLD_MS = 1500;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Every word the video says, in the video's time, in order.
|
|
30
|
+
*
|
|
31
|
+
* A word belongs to the clip that plays its start. Speech Whisper left out (timing `letters`)
|
|
32
|
+
* isn't included: it's nearly always a repeat, a false start or an um. Editing one in the
|
|
33
|
+
* Transcript Editor makes it a real word.
|
|
34
|
+
*
|
|
35
|
+
* @param clips Every sound clip in the video.
|
|
36
|
+
* @param wordsOf A file's words, or undefined if its transcript isn't ready.
|
|
37
|
+
*/
|
|
38
|
+
export function subtitleWords(
|
|
39
|
+
clips: readonly PlacedSoundClip[],
|
|
40
|
+
wordsOf: (source: string) => readonly TranscriptWord[] | undefined,
|
|
41
|
+
): SubtitleWord[] {
|
|
42
|
+
const result: SubtitleWord[] = [];
|
|
43
|
+
for (const clip of clips) {
|
|
44
|
+
const words = wordsOf(clip.source);
|
|
45
|
+
if (!words) continue;
|
|
46
|
+
const fromMs = clip.trimMs;
|
|
47
|
+
const toMs = clip.trimMs + clip.lengthMs;
|
|
48
|
+
/** File time to video time. */
|
|
49
|
+
const shift = clip.startMs - clip.trimMs;
|
|
50
|
+
for (const word of words) {
|
|
51
|
+
if (word.startMs < fromMs || word.startMs >= toMs) continue;
|
|
52
|
+
if (word.timing === "letters") continue;
|
|
53
|
+
const text = word.text.trim();
|
|
54
|
+
if (text === "") continue;
|
|
55
|
+
result.push({
|
|
56
|
+
text,
|
|
57
|
+
startMs: word.startMs + shift,
|
|
58
|
+
endMs: Math.max(word.startMs, Math.min(word.endMs, toMs)) + shift,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return result.sort((a, b) => a.startMs - b.startMs);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Group the words into lines, breaking at the length limit, a pause, or the end of a sentence. */
|
|
66
|
+
function toLines(words: readonly SubtitleWord[]): SubtitleWord[][] {
|
|
67
|
+
const lines: SubtitleWord[][] = [];
|
|
68
|
+
let line: SubtitleWord[] = [];
|
|
69
|
+
let length = 0;
|
|
70
|
+
for (const word of words) {
|
|
71
|
+
const previous = line.at(-1);
|
|
72
|
+
if (
|
|
73
|
+
previous &&
|
|
74
|
+
(length + 1 + word.text.length > MAX_LINE_CHARACTERS ||
|
|
75
|
+
word.startMs - previous.endMs > PAUSE_MS ||
|
|
76
|
+
/[.?!]["'”’)]*$/.test(previous.text))
|
|
77
|
+
) {
|
|
78
|
+
lines.push(line);
|
|
79
|
+
line = [];
|
|
80
|
+
length = 0;
|
|
81
|
+
}
|
|
82
|
+
length += (line.length ? 1 : 0) + word.text.length;
|
|
83
|
+
line.push(word);
|
|
84
|
+
}
|
|
85
|
+
if (line.length) lines.push(line);
|
|
86
|
+
return lines;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
type Cue = {
|
|
90
|
+
readonly startMs: number;
|
|
91
|
+
readonly endMs: number;
|
|
92
|
+
readonly text: string;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* One cue for each word: the line so far, under the previous line when there was no gap.
|
|
97
|
+
* The cues are in order and never overlap.
|
|
98
|
+
*/
|
|
99
|
+
function toCues(words: readonly SubtitleWord[]): Cue[] {
|
|
100
|
+
const lines = toLines(words);
|
|
101
|
+
const result: Cue[] = [];
|
|
102
|
+
/** The previous line, while it's still on screen. */
|
|
103
|
+
let above: string | undefined;
|
|
104
|
+
for (let l = 0; l < lines.length; l++) {
|
|
105
|
+
const line = lines[l]!;
|
|
106
|
+
const nextStart = lines[l + 1]?.[0]!.startMs ?? Infinity;
|
|
107
|
+
const lineEnd = Math.min(nextStart, line.at(-1)!.endMs + HOLD_MS);
|
|
108
|
+
for (let i = 0; i < line.length; i++) {
|
|
109
|
+
const startMs = line[i]!.startMs;
|
|
110
|
+
const endMs = i + 1 < line.length ? line[i + 1]!.startMs : lineEnd;
|
|
111
|
+
// Two words at the same moment: the next cue shows both.
|
|
112
|
+
if (endMs <= startMs) continue;
|
|
113
|
+
const spoken = line
|
|
114
|
+
.slice(0, i + 1)
|
|
115
|
+
.map((word) => word.text)
|
|
116
|
+
.join(" ");
|
|
117
|
+
result.push({
|
|
118
|
+
startMs,
|
|
119
|
+
endMs,
|
|
120
|
+
text: above === undefined ? spoken : `${above}\n${spoken}`,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
// The next line keeps this one above it only if they touch.
|
|
124
|
+
above =
|
|
125
|
+
lineEnd >= nextStart
|
|
126
|
+
? line.map((word) => word.text).join(" ")
|
|
127
|
+
: undefined;
|
|
128
|
+
}
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* A WebVTT file for part of the video.
|
|
134
|
+
* @param fromMs Where the saved file starts, in the video's time. It becomes 0.
|
|
135
|
+
* @param toMs Where the saved file ends.
|
|
136
|
+
* @returns Undefined if no words are spoken in that time.
|
|
137
|
+
*/
|
|
138
|
+
export function webVtt(
|
|
139
|
+
words: readonly SubtitleWord[],
|
|
140
|
+
fromMs: number,
|
|
141
|
+
toMs: number,
|
|
142
|
+
): string | undefined {
|
|
143
|
+
const cues: string[] = [];
|
|
144
|
+
for (const cue of toCues(words)) {
|
|
145
|
+
const startMs = Math.round(Math.max(cue.startMs, fromMs) - fromMs);
|
|
146
|
+
const endMs = Math.round(Math.min(cue.endMs, toMs) - fromMs);
|
|
147
|
+
if (endMs <= startMs) continue;
|
|
148
|
+
cues.push(
|
|
149
|
+
`${timestamp(startMs)} --> ${timestamp(endMs)}\n${escapeCueText(cue.text)}`,
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
return cues.length ? `WEBVTT\n\n${cues.join("\n\n")}\n` : undefined;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** hh:mm:ss.ttt, as WebVTT wants. */
|
|
156
|
+
function timestamp(ms: number): string {
|
|
157
|
+
const pad = (n: number, width = 2) => String(n).padStart(width, "0");
|
|
158
|
+
const hours = Math.floor(ms / 3_600_000);
|
|
159
|
+
const minutes = Math.floor(ms / 60_000) % 60;
|
|
160
|
+
const seconds = Math.floor(ms / 1000) % 60;
|
|
161
|
+
return `${pad(hours)}:${pad(minutes)}:${pad(seconds)}.${pad(ms % 1000, 3)}`;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** WebVTT cue text is a little like HTML. This also rules out "-->". */
|
|
165
|
+
function escapeCueText(text: string): string {
|
|
166
|
+
return text
|
|
167
|
+
.replace(/&/g, "&")
|
|
168
|
+
.replace(/</g, "<")
|
|
169
|
+
.replace(/>/g, ">");
|
|
170
|
+
}
|
package/dev/synced-file.ts
CHANGED
|
@@ -55,6 +55,22 @@ export type SyncedFileOptions = {
|
|
|
55
55
|
readonly showPending?: boolean;
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
+
/**
|
|
59
|
+
* A synced file's state in one word, for a button that stands for several files.
|
|
60
|
+
* * `off`: the checkbox is off.
|
|
61
|
+
* * `ok`: the file matches, or will in a moment with nothing for anyone to do.
|
|
62
|
+
* * `pending`: memory is ahead of the file, waiting for the next save.
|
|
63
|
+
* * `action`: someone has to click something: permission, a conflict or an error.
|
|
64
|
+
*/
|
|
65
|
+
export type SyncSummary = "off" | "ok" | "pending" | "action";
|
|
66
|
+
|
|
67
|
+
const summaryListeners = new Set<() => void>();
|
|
68
|
+
|
|
69
|
+
/** Called whenever any synced file's status is redrawn. See {@link SyncedFile.summary}. */
|
|
70
|
+
export function onSyncStatusChange(listener: () => void): void {
|
|
71
|
+
summaryListeners.add(listener);
|
|
72
|
+
}
|
|
73
|
+
|
|
58
74
|
type State =
|
|
59
75
|
| { kind: "starting" }
|
|
60
76
|
| { kind: "off" }
|
|
@@ -73,6 +89,7 @@ export class SyncedFile {
|
|
|
73
89
|
#again = false;
|
|
74
90
|
/** The next sync may overwrite a file someone else changed: the user said so. */
|
|
75
91
|
#forceNext = false;
|
|
92
|
+
#summary: SyncSummary = "off";
|
|
76
93
|
|
|
77
94
|
constructor(options: SyncedFileOptions) {
|
|
78
95
|
this.#options = options;
|
|
@@ -135,6 +152,16 @@ export class SyncedFile {
|
|
|
135
152
|
})();
|
|
136
153
|
}
|
|
137
154
|
|
|
155
|
+
/** The state in one word, as of the last redraw. */
|
|
156
|
+
get summary(): SyncSummary {
|
|
157
|
+
return this.#summary;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** What the status shows, as plain text, for a tooltip. */
|
|
161
|
+
get statusText(): string {
|
|
162
|
+
return this.#options.status.textContent ?? "";
|
|
163
|
+
}
|
|
164
|
+
|
|
138
165
|
/** Redraw, e.g. to show or clear the pending " *" after an edit. Cheap; does no I/O. */
|
|
139
166
|
refreshStatus(): void {
|
|
140
167
|
this.#draw();
|
|
@@ -288,14 +315,17 @@ export class SyncedFile {
|
|
|
288
315
|
case "starting":
|
|
289
316
|
text("…");
|
|
290
317
|
status.style.color = "gray";
|
|
318
|
+
this.#summary = "ok";
|
|
291
319
|
break;
|
|
292
320
|
case "off":
|
|
293
321
|
text("off");
|
|
294
322
|
status.style.color = "gray";
|
|
323
|
+
this.#summary = "off";
|
|
295
324
|
break;
|
|
296
325
|
case "synced": {
|
|
297
326
|
const pending =
|
|
298
327
|
showPending && render() !== this.#record?.lastWrittenBody;
|
|
328
|
+
this.#summary = pending ? "pending" : "ok";
|
|
299
329
|
text(`${name} ${pending ? "*" : "✓"}`);
|
|
300
330
|
status.style.color = pending ? "darkorange" : "";
|
|
301
331
|
status.title = pending
|
|
@@ -311,12 +341,14 @@ export class SyncedFile {
|
|
|
311
341
|
"The browser needs your permission again to write this file. " +
|
|
312
342
|
'Choosing "Allow on every visit" stops it asking.';
|
|
313
343
|
status.onclick = () => void this.#allow();
|
|
344
|
+
this.#summary = "action";
|
|
314
345
|
break;
|
|
315
346
|
case "conflict":
|
|
316
347
|
text(`${name} ⚠ changed on disk`);
|
|
317
348
|
status.style.color = "darkorange";
|
|
318
349
|
status.title =
|
|
319
350
|
"Something else changed this file since it was last synced, so it hasn't been overwritten.";
|
|
351
|
+
this.#summary = "action";
|
|
320
352
|
button("Overwrite", `Replace ${name} with the current state`, () =>
|
|
321
353
|
this.request(true),
|
|
322
354
|
);
|
|
@@ -334,8 +366,10 @@ export class SyncedFile {
|
|
|
334
366
|
status.style.cursor = "pointer";
|
|
335
367
|
status.title = this.#state.message;
|
|
336
368
|
status.onclick = () => this.request();
|
|
369
|
+
this.#summary = "action";
|
|
337
370
|
break;
|
|
338
371
|
}
|
|
372
|
+
for (const listener of summaryListeners) listener();
|
|
339
373
|
}
|
|
340
374
|
}
|
|
341
375
|
|
package/dev/timeline-display.ts
CHANGED
|
@@ -78,7 +78,7 @@ export type TimelineWord = {
|
|
|
78
78
|
};
|
|
79
79
|
|
|
80
80
|
/** Background colors for flagged words. The 📖 Text view uses lighter versions of the same colors. */
|
|
81
|
-
const WORD_FLAG_COLORS = {
|
|
81
|
+
export const WORD_FLAG_COLORS = {
|
|
82
82
|
"left out": "rgba(225, 30, 30, 0.9)",
|
|
83
83
|
doubtful: "rgba(255, 140, 0, 0.8)",
|
|
84
84
|
} as const;
|
package/dev/transcript-align.ts
CHANGED
|
@@ -41,8 +41,10 @@ export type TranscriptWord = {
|
|
|
41
41
|
* * `letters`: speech Whisper **left out**, such as a repeated word, a false
|
|
42
42
|
* start or an "um". Whisper tidies what it hears; the letter model doesn't.
|
|
43
43
|
* See {@link recoverSkippedSpeech}.
|
|
44
|
+
* * `edited`: a person typed, timed or checked this word in the Transcript
|
|
45
|
+
* Editor. Never flagged, and always in the subtitles.
|
|
44
46
|
*/
|
|
45
|
-
readonly timing: "aligned" | "whisper" | "letters";
|
|
47
|
+
readonly timing: "aligned" | "whisper" | "letters" | "edited";
|
|
46
48
|
/**
|
|
47
49
|
* How sure the letter model was, 0 to 1: the average probability it gave
|
|
48
50
|
* the letters it was made to hear. Low in noise and mumbling. Only
|
|
@@ -588,6 +590,7 @@ const squash = (s: string) => s.toLowerCase().replace(/[^a-z']/g, "");
|
|
|
588
590
|
export function wordFlag(
|
|
589
591
|
word: TranscriptWord,
|
|
590
592
|
): "left out" | "doubtful" | undefined {
|
|
593
|
+
if (word.timing === "edited") return undefined;
|
|
591
594
|
if (word.timing === "letters") return "left out";
|
|
592
595
|
const text = squash(word.text);
|
|
593
596
|
// `heard` is missing from transcripts made before it existed.
|