rvlib-shipkit 2.20.0 → 2.22.0
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/CHANGELOG.md +35 -0
- package/package.json +1 -1
- package/src/asks/asks-queue.ts +8 -7
- package/src/assets/kits/identity-kit.ts +158 -2
- package/src/checks/SK004-gitignore-policy.check.ts +6 -3
- package/src/cli/cmd_Bump.ts +3 -3
- package/src/cli/cmd_GlobalProcesses.ts +2 -107
- package/src/cli/cmd_Home.ts +1 -1
- package/src/cli/cmd_Overview.ts +2 -1
- package/src/cli/cmd_Rec.ts +349 -0
- package/src/cli/cmd_Releases.ts +42 -3
- package/src/cli/cmd_Review.ts +22 -13
- package/src/cli/cmd_Secret.ts +10 -3
- package/src/cli/cmd_Sign.ts +24 -0
- package/src/cli/cmd_Social.ts +57 -8
- package/src/cli/cmd_Sound.ts +17 -4
- package/src/cli/cmd_Trailer.ts +67 -1
- package/src/cli/family-pages.ts +1 -0
- package/src/cli/registry.ts +6 -1
- package/src/collections/collection-types.ts +1 -1
- package/src/collections/review.ts +23 -4
- package/src/core/agent-spawn.ts +4 -17
- package/src/core/code-lines.ts +49 -0
- package/src/core/discover-checks.ts +27 -3
- package/src/core/hard-reset.ts +34 -0
- package/src/core/layout.ts +6 -0
- package/src/core/raw-access.ts +3 -13
- package/src/core/throwaway-worktree.ts +72 -0
- package/src/home/app-sign.ts +98 -0
- package/src/home/gui-app/ShipkitGui.swift +35 -0
- package/src/home/gui-app.ts +31 -11
- package/src/home/home-routes.ts +6 -0
- package/src/home/pm-switch.ts +112 -0
- package/src/home/serve-web.ts +1 -1
- package/src/identities/identities.ts +17 -6
- package/src/media-kinds.ts +5 -3
- package/src/media-store/forget.ts +54 -0
- package/src/media-store/put.ts +4 -3
- package/src/media-store/space.ts +63 -24
- package/src/messages/brief.ts +3 -3
- package/src/messages/score.ts +2 -0
- package/src/recordings/delete.ts +19 -0
- package/src/recordings/edit.ts +231 -0
- package/src/recordings/load.ts +37 -0
- package/src/recordings/marks-draw.ts +111 -0
- package/src/recordings/marks-png.ts +25 -0
- package/src/recordings/marks.ts +138 -0
- package/src/recordings/media-kind.ts +67 -0
- package/src/recordings/model.ts +170 -0
- package/src/recordings/open.ts +33 -0
- package/src/recordings/place.ts +89 -0
- package/src/recordings/presets.ts +99 -0
- package/src/recordings/recorder-app/Capture.swift +510 -0
- package/src/recordings/recorder-app/Clip.swift +107 -0
- package/src/recordings/recorder-app/Editor.swift +39 -0
- package/src/recordings/recorder-app/Tray.swift +298 -0
- package/src/recordings/recorder-app/main.swift +859 -0
- package/src/recordings/recorder-app.ts +46 -0
- package/src/recordings/recorder.shipkit.ts +11 -0
- package/src/recordings/routes.ts +140 -0
- package/src/recordings/run-recorder.ts +40 -0
- package/src/recordings/share.ts +107 -0
- package/src/recordings/take.ts +146 -0
- package/src/recordings/view.ts +40 -0
- package/src/release/gate-checkout.ts +74 -0
- package/src/release/release-scope.ts +35 -26
- package/src/release/run-bump.ts +79 -37
- package/src/release/run-release.ts +67 -53
- package/src/releases/add.ts +38 -5
- package/src/releases/before.ts +31 -0
- package/src/releases/from-card.ts +105 -20
- package/src/releases/model.ts +100 -18
- package/src/releases/pictures.ts +29 -8
- package/src/repo-config.ts +7 -3
- package/src/review/http.ts +1 -1
- package/src/review/model.ts +12 -2
- package/src/review/stage-card.ts +1 -1
- package/src/review/store.ts +12 -2
- package/src/review/trailer-desk.ts +20 -0
- package/src/review/trailer-model.ts +67 -0
- package/src/review/trailer-routes.ts +98 -1
- package/src/review/trailer-voices.ts +144 -0
- package/src/review/watchers.ts +58 -1
- package/src/secrets/manager.ts +18 -1
- package/src/serve/hub-app/benign-errors.ts +22 -0
- package/src/serve/hub-app/hash-route.ts +27 -15
- package/src/serve/hub-app/home-st.ts +23 -5
- package/src/serve/hub-app/home.html +1 -0
- package/src/serve/hub-app/hub-app.tsx +8 -1
- package/src/serve/hub-app/icons.tsx +2 -0
- package/src/serve/hub-app/palette-st.ts +1 -0
- package/src/serve/hub-app/project-list.css +7 -2
- package/src/serve/hub-app/project-list.tsx +10 -0
- package/src/serve/hub-app/projects-svc.ts +17 -7
- package/src/serve/hub-app/recordings-st.ts +641 -0
- package/src/serve/hub-app/recordings-view.tsx +504 -0
- package/src/serve/hub-app/recordings.css +82 -0
- package/src/serve/hub-app/releases/releases-page.tsx +121 -28
- package/src/serve/hub-app/releases/releases-st.ts +46 -4
- package/src/serve/hub-app/releases.css +30 -3
- package/src/serve/hub-app/repo-sections.ts +1 -1
- package/src/serve/hub-app/repo-st.ts +16 -11
- package/src/serve/hub-app/review/clip-st.ts +3 -1
- package/src/serve/hub-app/review/kit.tsx +3 -3
- package/src/serve/hub-app/review/trailer-page.tsx +32 -6
- package/src/serve/hub-app/review/trailer-st.ts +184 -8
- package/src/serve/hub-app/review/trailer-timeline.tsx +39 -4
- package/src/serve/hub-app/review/trailer-voices-st.ts +370 -0
- package/src/serve/hub-app/review/trailer-voices.tsx +574 -0
- package/src/serve/hub-app/review.css +90 -0
- package/src/serve/hub-app/social/comms-page.tsx +10 -5
- package/src/serve/hub-app/social/next-release.tsx +118 -0
- package/src/serve/hub-app/social/post-card.tsx +31 -3
- package/src/serve/hub-app/social/social-model.ts +6 -0
- package/src/serve/hub-app/social/social-st.ts +50 -1
- package/src/serve/hub-app/social.css +12 -0
- package/src/serve/hub-app/tree-build.ts +2 -0
- package/src/serve/project-gutter-route.ts +8 -0
- package/src/serve/project-gutter.ts +4 -2
- package/src/shipkit.ts +2 -2
- package/src/shot/box.ts +49 -22
- package/src/shot/browser-slot.ts +13 -3
- package/src/shot/client.ts +1 -1
- package/src/shot/film-box.ts +193 -117
- package/src/shot/shooter.ts +20 -8
- package/src/smoke/run-smoke.ts +8 -6
- package/src/social/compose.ts +14 -0
- package/src/social/desk-index.ts +49 -8
- package/src/social/discord-layout.ts +6 -2
- package/src/social/drafts.ts +1 -1
- package/src/social/kinds.ts +3 -2
- package/src/social/load.ts +42 -9
- package/src/social/publish/index.ts +27 -10
- package/src/social/publish/secret.ts +12 -4
- package/src/social/release-card.ts +69 -0
- package/src/social/release-stage.ts +173 -30
- package/src/social/routes.ts +7 -1
- package/src/social/stage.ts +45 -22
- package/src/trailer/bed.ts +111 -0
- package/src/trailer/build.ts +81 -38
- package/src/trailer/ffmpeg.ts +14 -0
- package/src/trailer/grammar.ts +32 -4
- package/src/trailer/graph.ts +12 -1
- package/src/trailer/look.ts +7 -0
- package/src/trailer/shot-plan.ts +75 -0
- package/src/trailer/shot-state.ts +191 -0
- package/src/trailer/sound/audio.ts +28 -0
- package/src/trailer/sound/brand.ts +53 -3
- package/src/trailer/sound/gen.ts +61 -2
- package/src/trailer/sound/index.ts +25 -11
- package/src/trailer/sound/presets.ts +86 -5
- package/src/trailer/sound/run.ts +1 -1
- package/src/trailer/sound/takes.ts +94 -0
- package/src/trailer/titles.ts +36 -0
- package/src/trailer/url.ts +1 -1
- package/src/veille/chrome.ts +6 -3
|
@@ -0,0 +1,641 @@
|
|
|
1
|
+
// the Recordings page's state (wiki tools/shipkit/recordings.md, The hub page): every capture of every repo in the
|
|
2
|
+
// strip, the repo filter, and the editor of the one picked (the hash's, else the newest). The editor plays the TAKE
|
|
3
|
+
// and previews its edit live (cut parts skipped, a sped part faster, the marks and the crop drawn over it); the text
|
|
4
|
+
// is the edit's one truth: every tool writes it, undo walks it back, the export sends it, and a draft not exported
|
|
5
|
+
// stays with its capture while another is open. Reads when the page shows and after each action, never on a clock
|
|
6
|
+
import { makeAutoObservable, observableRef, runInAction } from 'mobx'
|
|
7
|
+
import { EMPTY_EDIT, parseEdit, pieces, printEdit, type Crop, type Edit, type Span } from '../../recordings/edit.ts'
|
|
8
|
+
import { moved, type Mark, type MarkColor, type Pt } from '../../recordings/marks.ts'
|
|
9
|
+
import { parseRecordingHash, recordingAddress, type RecList, type RecView } from '../../recordings/view.ts'
|
|
10
|
+
import type { HomeSt } from './home-st.ts'
|
|
11
|
+
import { ownTrouble, reach } from './reach.ts'
|
|
12
|
+
|
|
13
|
+
const REPO_KEY = 'home:recordings:repo'
|
|
14
|
+
const API = '/api/home/recordings'
|
|
15
|
+
|
|
16
|
+
function kept(): string {
|
|
17
|
+
try {
|
|
18
|
+
return globalThis.localStorage?.getItem(REPO_KEY) ?? ''
|
|
19
|
+
} catch {
|
|
20
|
+
return ''
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** the parts of the take that stay once `cut` is taken out of them */
|
|
25
|
+
export function without(keep: readonly Span[], cut: Span): Span[] {
|
|
26
|
+
const out: Span[] = []
|
|
27
|
+
for (const k of keep) {
|
|
28
|
+
if (cut.to <= k.from || cut.from >= k.to) out.push(k)
|
|
29
|
+
else {
|
|
30
|
+
if (cut.from > k.from) out.push({ from: k.from, to: cut.from })
|
|
31
|
+
if (cut.to < k.to) out.push({ from: cut.to, to: k.to })
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return out.filter((s) => s.to - s.from >= 0.05)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** the parts of the take that stay inside `only` */
|
|
38
|
+
export function within(keep: readonly Span[], only: Span): Span[] {
|
|
39
|
+
return keep.map((k) => ({ from: Math.max(k.from, only.from), to: Math.min(k.to, only.to) })).filter((s) => s.to - s.from >= 0.05)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const round = (t: number): number => Math.round(t * 10) / 10
|
|
43
|
+
|
|
44
|
+
export const TOOLS = ['select', 'arrow', 'rect', 'text', 'step', 'blur', 'crop'] as const
|
|
45
|
+
export type Tool = (typeof TOOLS)[number]
|
|
46
|
+
|
|
47
|
+
/** the text written last is one undo step with the one before it when they came this close (typing, a drag) */
|
|
48
|
+
const COALESCE_MS = 700
|
|
49
|
+
|
|
50
|
+
export class EditorSt {
|
|
51
|
+
/** the take's playhead, in the take's time */
|
|
52
|
+
time = 0
|
|
53
|
+
playing = false
|
|
54
|
+
mark: { in: number | null; out: number | null } = { in: null, out: null }
|
|
55
|
+
text: string
|
|
56
|
+
tool: Tool = 'select'
|
|
57
|
+
color: MarkColor = 'red'
|
|
58
|
+
/** the mark picked with the select tool, by its index */
|
|
59
|
+
selected: number | null = null
|
|
60
|
+
/** what a drag draws before it lands: a mark, or a crop box */
|
|
61
|
+
draft: Mark | null = null
|
|
62
|
+
cropDraft: Crop | null = null
|
|
63
|
+
/** a text mark being typed, at its place */
|
|
64
|
+
typing: { at: Pt; value: string } | null = null
|
|
65
|
+
exporting = false
|
|
66
|
+
video: HTMLVideoElement | null = null
|
|
67
|
+
private raf = 0
|
|
68
|
+
private past: string[] = []
|
|
69
|
+
private future: string[] = []
|
|
70
|
+
private wroteAt = 0
|
|
71
|
+
|
|
72
|
+
constructor(public rec: RecView, private page: RecordingsSt, draft: string | null = null) {
|
|
73
|
+
this.text = draft ?? rec.edit
|
|
74
|
+
makeAutoObservable<this, 'page' | 'raf' | 'past' | 'future' | 'wroteAt'>(this, { rec: false, page: false, video: false, raf: false, past: false, future: false, wroteAt: false })
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get cropping(): boolean {
|
|
78
|
+
return this.tool === 'crop'
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
get marks(): Mark[] {
|
|
82
|
+
return this.edit.marks
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** the marks shown at the playhead: those with no span, and those whose span holds it (a still shows them all) */
|
|
86
|
+
get marksNow(): number[] {
|
|
87
|
+
return this.marks.flatMap((m, i) => (this.rec.still || !m.span || (this.time >= m.span.from && this.time <= m.span.to) ? [i] : []))
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** the text as an edit, or the reason it is not one */
|
|
91
|
+
get parsed(): { edit: Edit; error: string } {
|
|
92
|
+
try {
|
|
93
|
+
return { edit: parseEdit(this.text), error: '' }
|
|
94
|
+
} catch (e) {
|
|
95
|
+
return { edit: EMPTY_EDIT, error: (e as Error).message }
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
get edit(): Edit {
|
|
100
|
+
return this.parsed.edit
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
get dirty(): boolean {
|
|
104
|
+
return this.text.trim() !== this.rec.edit.trim()
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
get length(): number {
|
|
108
|
+
return this.rec.seconds
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** the pieces that play, or the reason none does */
|
|
112
|
+
get plays(): { from: number; to: number; factor: number }[] {
|
|
113
|
+
try {
|
|
114
|
+
return this.rec.still ? [] : pieces(this.edit, this.length)
|
|
115
|
+
} catch {
|
|
116
|
+
return []
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
get kept(): Span[] {
|
|
121
|
+
return this.edit.keep.length > 0 ? this.edit.keep : [{ from: 0, to: this.length }]
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
get selection(): Span | null {
|
|
125
|
+
const a = this.mark.in ?? 0
|
|
126
|
+
const b = this.mark.out ?? this.length
|
|
127
|
+
if (this.mark.in == null && this.mark.out == null) return null
|
|
128
|
+
return b - a >= 0.05 ? { from: Math.min(a, b), to: Math.max(a, b) } : null
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
setText(t: string): void {
|
|
132
|
+
this.remember()
|
|
133
|
+
this.text = t
|
|
134
|
+
this.page.keepDraft(this)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
private remember(): void {
|
|
138
|
+
const now = Date.now()
|
|
139
|
+
if (now - this.wroteAt > COALESCE_MS) this.past.push(this.text)
|
|
140
|
+
if (this.past.length > 200) this.past.shift()
|
|
141
|
+
this.future = []
|
|
142
|
+
this.wroteAt = now
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private write(e: Edit): void {
|
|
146
|
+
this.wroteAt = 0
|
|
147
|
+
this.remember()
|
|
148
|
+
this.text = printEdit(e)
|
|
149
|
+
this.page.keepDraft(this)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
get canUndo(): boolean {
|
|
153
|
+
return this.past.length > 0
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
undo(): void {
|
|
157
|
+
const t = this.past.pop()
|
|
158
|
+
if (t === undefined) return
|
|
159
|
+
this.future.push(this.text)
|
|
160
|
+
this.text = t
|
|
161
|
+
this.selected = null
|
|
162
|
+
this.page.keepDraft(this)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
redo(): void {
|
|
166
|
+
const t = this.future.pop()
|
|
167
|
+
if (t === undefined) return
|
|
168
|
+
this.past.push(this.text)
|
|
169
|
+
this.text = t
|
|
170
|
+
this.page.keepDraft(this)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
setTool(t: Tool): void {
|
|
174
|
+
this.tool = t
|
|
175
|
+
this.draft = null
|
|
176
|
+
this.cropDraft = null
|
|
177
|
+
if (t !== 'select') this.selected = null
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** the colour of the next mark, and of the mark picked */
|
|
181
|
+
setColor(c: MarkColor): void {
|
|
182
|
+
this.color = c
|
|
183
|
+
const i = this.selected
|
|
184
|
+
const m = i === null ? null : this.marks[i]
|
|
185
|
+
if (m && m.kind !== 'blur') this.updateMark(i!, { ...m, color: c })
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
setDraft(m: Mark | null): void {
|
|
189
|
+
this.draft = m
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
setCropDraft(c: Crop | null): void {
|
|
193
|
+
this.cropDraft = c
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
select(i: number | null): void {
|
|
197
|
+
this.selected = i
|
|
198
|
+
const m = i === null ? null : this.marks[i]
|
|
199
|
+
if (m && m.kind !== 'blur') this.color = m.color
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** a mark lands at the end of the list, picked */
|
|
203
|
+
addMark(m: Mark): void {
|
|
204
|
+
this.write({ ...this.edit, marks: [...this.marks, m] })
|
|
205
|
+
this.selected = this.marks.length - 1
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
updateMark(i: number, m: Mark): void {
|
|
209
|
+
this.write({ ...this.edit, marks: this.marks.map((x, j) => (j === i ? m : x)) })
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
moveMark(i: number, dx: number, dy: number): void {
|
|
213
|
+
const m = this.marks[i]
|
|
214
|
+
if (m && (dx !== 0 || dy !== 0)) this.updateMark(i, moved(m, dx, dy))
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
removeSelected(): void {
|
|
218
|
+
const i = this.selected
|
|
219
|
+
if (i === null) return
|
|
220
|
+
this.write({ ...this.edit, marks: this.marks.filter((_, j) => j !== i) })
|
|
221
|
+
this.selected = null
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** a mark's span on the timeline; null is the whole clip */
|
|
225
|
+
setMarkSpan(i: number, span: Span | null): void {
|
|
226
|
+
const m = this.marks[i]
|
|
227
|
+
if (!m) return
|
|
228
|
+
const whole = span && span.from <= 0.05 && span.to >= this.length - 0.05
|
|
229
|
+
this.updateMark(i, { ...m, span: whole ? null : span && { from: round(span.from), to: round(span.to) } })
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** the trim: what plays starts at `from` and ends at `to`, the cuts between kept */
|
|
233
|
+
setTrim(from: number, to: number): void {
|
|
234
|
+
const a = Math.max(0, round(Math.min(from, to - 0.2)))
|
|
235
|
+
const b = Math.min(this.length, round(Math.max(to, a + 0.2)))
|
|
236
|
+
const keep = within(this.kept, { from: a, to: b })
|
|
237
|
+
const parts = keep.length === 0 ? [{ from: a, to: b }] : keep
|
|
238
|
+
if (parts[0]!.from > a) parts[0] = { ...parts[0]!, from: a }
|
|
239
|
+
if (parts.at(-1)!.to < b) parts[parts.length - 1] = { ...parts.at(-1)!, to: b }
|
|
240
|
+
const whole = parts.length === 1 && parts[0]!.from <= 0.05 && parts[0]!.to >= this.length - 0.05
|
|
241
|
+
this.write({ ...this.edit, keep: whole ? [] : parts })
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
startText(at: Pt): void {
|
|
245
|
+
this.typing = { at, value: '' }
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
setTyping(v: string): void {
|
|
249
|
+
if (this.typing) this.typing = { ...this.typing, value: v }
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
commitText(): void {
|
|
253
|
+
const t = this.typing
|
|
254
|
+
this.typing = null
|
|
255
|
+
if (t && t.value.trim() !== '') this.addMark({ kind: 'text', at: t.at, text: t.value.trim(), size: null, color: this.color, span: null })
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
cancelText(): void {
|
|
259
|
+
this.typing = null
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
setVideo(v: HTMLVideoElement | null): void {
|
|
263
|
+
this.video = v
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
seek(t: number): void {
|
|
267
|
+
const to = Math.max(0, Math.min(this.length, t))
|
|
268
|
+
this.time = to
|
|
269
|
+
if (this.video) this.video.currentTime = to
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/** the video says where it is (a seek done, a time while paused): the playhead follows, the video is never
|
|
273
|
+
* sought again, or each `seeked` would start the next seek and the player never rests */
|
|
274
|
+
onVideoMoved(): void {
|
|
275
|
+
if (this.video) this.time = this.video.currentTime
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
nudge(by: number): void {
|
|
279
|
+
this.seek(this.time + by)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
toggle(): void {
|
|
283
|
+
const v = this.video
|
|
284
|
+
if (!v) return
|
|
285
|
+
if (v.paused) {
|
|
286
|
+
// from the end, play again from the first piece
|
|
287
|
+
const ps = this.plays
|
|
288
|
+
const last = ps.at(-1)
|
|
289
|
+
if (last && this.time >= last.to - 0.05) this.seek(ps[0]!.from)
|
|
290
|
+
void v.play()
|
|
291
|
+
} else v.pause()
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
onPlay(): void {
|
|
295
|
+
this.playing = true
|
|
296
|
+
const loop = (): void => {
|
|
297
|
+
this.follow()
|
|
298
|
+
if (this.playing) this.raf = requestAnimationFrame(loop)
|
|
299
|
+
}
|
|
300
|
+
this.raf = requestAnimationFrame(loop)
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
onPause(): void {
|
|
304
|
+
this.playing = false
|
|
305
|
+
cancelAnimationFrame(this.raf)
|
|
306
|
+
if (this.video) this.time = this.video.currentTime
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** the live preview: a cut part skipped, a sped part played at its factor, the end of the last piece stops it */
|
|
310
|
+
follow(): void {
|
|
311
|
+
const v = this.video
|
|
312
|
+
if (!v) return
|
|
313
|
+
const t = v.currentTime
|
|
314
|
+
this.time = t
|
|
315
|
+
const ps = this.plays
|
|
316
|
+
if (ps.length === 0) return
|
|
317
|
+
const at = ps.find((p) => t >= p.from - 0.02 && t < p.to)
|
|
318
|
+
if (at) {
|
|
319
|
+
if (v.playbackRate !== at.factor) v.playbackRate = at.factor
|
|
320
|
+
return
|
|
321
|
+
}
|
|
322
|
+
const next = ps.find((p) => p.from > t)
|
|
323
|
+
if (next) v.currentTime = next.from
|
|
324
|
+
else {
|
|
325
|
+
v.pause()
|
|
326
|
+
v.currentTime = ps.at(-1)!.to
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
setIn(): void {
|
|
331
|
+
this.mark.in = round(this.time)
|
|
332
|
+
if (this.mark.out != null && this.mark.out <= this.mark.in) this.mark.out = null
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
setOut(): void {
|
|
336
|
+
this.mark.out = round(this.time)
|
|
337
|
+
if (this.mark.in != null && this.mark.in >= this.mark.out) this.mark.in = null
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
clearMarks(): void {
|
|
341
|
+
this.mark = { in: null, out: null }
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/** the selection taken out of what is kept */
|
|
345
|
+
cut(): void {
|
|
346
|
+
const s = this.selection
|
|
347
|
+
if (!s) return this.page.say('mark a part first: i at its start, o at its end')
|
|
348
|
+
const keep = without(this.kept, s)
|
|
349
|
+
if (keep.length === 0) return this.page.say('that would cut everything')
|
|
350
|
+
this.write({ ...this.edit, keep: keep.length === 1 && keep[0]!.from === 0 && keep[0]!.to >= this.length - 0.05 ? [] : keep, speed: this.edit.speed.filter((p) => without([p], s).length > 0) })
|
|
351
|
+
this.clearMarks()
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** only the selection kept: both ends trimmed */
|
|
355
|
+
trim(): void {
|
|
356
|
+
const s = this.selection
|
|
357
|
+
if (!s) return this.page.say('mark a part first: i at its start, o at its end')
|
|
358
|
+
const keep = within(this.kept, s)
|
|
359
|
+
if (keep.length === 0) return this.page.say('nothing is kept inside that part')
|
|
360
|
+
this.write({ ...this.edit, keep })
|
|
361
|
+
this.clearMarks()
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/** the selection played at `factor`; 1 takes its speed away */
|
|
365
|
+
speed(factor: number): void {
|
|
366
|
+
const s = this.selection
|
|
367
|
+
if (!s) return this.page.say('mark a part first: i at its start, o at its end')
|
|
368
|
+
const rest = this.edit.speed.flatMap((p) => without([p], s).map((x) => ({ ...x, factor: p.factor })))
|
|
369
|
+
this.write({ ...this.edit, speed: [...rest, ...(factor === 1 ? [] : [{ ...s, factor }])].sort((a, b) => a.from - b.from) })
|
|
370
|
+
this.clearMarks()
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
toggleMute(): void {
|
|
374
|
+
if (this.rec.still) return
|
|
375
|
+
this.write({ ...this.edit, mute: !this.edit.mute })
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
toggleCropping(): void {
|
|
379
|
+
this.setTool(this.tool === 'crop' ? 'select' : 'crop')
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
setCrop(c: Crop | null): void {
|
|
383
|
+
this.write({ ...this.edit, crop: c })
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
reset(): void {
|
|
387
|
+
this.write(EMPTY_EDIT)
|
|
388
|
+
this.clearMarks()
|
|
389
|
+
this.selected = null
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
async save(): Promise<void> {
|
|
393
|
+
if (this.parsed.error) return this.page.say(this.parsed.error)
|
|
394
|
+
this.exporting = true
|
|
395
|
+
try {
|
|
396
|
+
const r = await this.page.post<{ recording: RecView; said: string }>(this.rec, 'edit', { text: this.text })
|
|
397
|
+
if (r) {
|
|
398
|
+
this.page.dropDraft(this.rec)
|
|
399
|
+
this.page.replace(r.recording)
|
|
400
|
+
}
|
|
401
|
+
} finally {
|
|
402
|
+
runInAction(() => (this.exporting = false))
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
dispose(): void {
|
|
407
|
+
cancelAnimationFrame(this.raf)
|
|
408
|
+
this.playing = false
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
export class RecordingsSt {
|
|
413
|
+
data: RecList | null = null
|
|
414
|
+
error = ''
|
|
415
|
+
loading = false
|
|
416
|
+
/** what the last action said, shown a few seconds */
|
|
417
|
+
said = ''
|
|
418
|
+
/** the repo whose recordings show, '' for every repo */
|
|
419
|
+
repo = kept()
|
|
420
|
+
/** the capture the hash names; null: the newest one shown */
|
|
421
|
+
open: { repo: string; id: string } | null = null
|
|
422
|
+
/** every thumb at once, big, in place of the editor */
|
|
423
|
+
gallery = false
|
|
424
|
+
editor: EditorSt | null = null
|
|
425
|
+
busy = ''
|
|
426
|
+
/** the thumb whose delete waits for its second click */
|
|
427
|
+
arming: string | null = null
|
|
428
|
+
private gen = 0
|
|
429
|
+
private sayTimer: ReturnType<typeof setTimeout> | null = null
|
|
430
|
+
/** each capture's edit text not exported yet, by `<repo>/<id>`: it waits there while another is open */
|
|
431
|
+
private drafts = new Map<string, string>()
|
|
432
|
+
|
|
433
|
+
constructor(private st: HomeSt) {
|
|
434
|
+
makeAutoObservable<this, 'st' | 'gen' | 'sayTimer' | 'drafts' | 'poll'>(this, { st: false, gen: false, sayTimer: false, drafts: false, poll: false, data: observableRef, editor: observableRef })
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
get repos(): string[] {
|
|
438
|
+
return [...new Set((this.data?.recordings ?? []).map((r) => r.repo))].sort()
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
get shown(): RecView[] {
|
|
442
|
+
return (this.data?.recordings ?? []).filter((r) => this.repo === '' || r.repo === this.repo)
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/** the capture in the editor: the one asked, else the newest shown */
|
|
446
|
+
get current(): RecView | null {
|
|
447
|
+
const o = this.open
|
|
448
|
+
if (o == null) return this.shown[0] ?? null
|
|
449
|
+
return (this.data?.recordings ?? []).find((r) => r.repo === o.repo && r.id === o.id) ?? null
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
get address(): string {
|
|
453
|
+
return this.gallery ? '/recordings#gallery' : recordingAddress(this.open)
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
setRepo(r: string): void {
|
|
457
|
+
this.repo = r
|
|
458
|
+
try { globalThis.localStorage?.setItem(REPO_KEY, r) } catch { /* private window: the pick lasts the tab */ }
|
|
459
|
+
if (this.open && r !== '' && this.open.repo !== r) this.open = null
|
|
460
|
+
this.syncEditor()
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
say(text: string): void {
|
|
464
|
+
this.said = text
|
|
465
|
+
if (this.sayTimer) clearTimeout(this.sayTimer)
|
|
466
|
+
this.sayTimer = setTimeout(() => runInAction(() => (this.said = '')), 5000)
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/** the address's hash: a capture in the editor, the gallery, or (none) the newest */
|
|
470
|
+
fromHash(hash: string): void {
|
|
471
|
+
this.gallery = hash === '#gallery'
|
|
472
|
+
this.open = this.gallery ? this.open : parseRecordingHash(hash)
|
|
473
|
+
this.syncEditor()
|
|
474
|
+
// a capture newer than the list (the tray names one taken after this page loaded): the list is read again
|
|
475
|
+
if (this.open && this.data && !this.current && !this.loading) void this.load()
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
keepDraft(ed: EditorSt): void {
|
|
479
|
+
const k = `${ed.rec.repo}/${ed.rec.id}`
|
|
480
|
+
if (ed.dirty) this.drafts.set(k, ed.text)
|
|
481
|
+
else this.drafts.delete(k)
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
dropDraft(r: Pick<RecView, 'repo' | 'id'>): void {
|
|
485
|
+
this.drafts.delete(`${r.repo}/${r.id}`)
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
hasDraft(r: Pick<RecView, 'repo' | 'id'>): boolean {
|
|
489
|
+
return this.drafts.has(`${r.repo}/${r.id}`)
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
private syncEditor(): void {
|
|
493
|
+
const r = this.current
|
|
494
|
+
if (r == null) {
|
|
495
|
+
this.editor?.dispose()
|
|
496
|
+
this.editor = null
|
|
497
|
+
return
|
|
498
|
+
}
|
|
499
|
+
if (this.editor?.rec === r) return
|
|
500
|
+
// the same capture read again with the same edit (its upload state moved): the editor keeps its playhead,
|
|
501
|
+
// its tool, its pick
|
|
502
|
+
const ed = this.editor
|
|
503
|
+
if (ed && ed.rec.repo === r.repo && ed.rec.id === r.id && ed.rec.edit === r.edit && ed.rec.current === r.current) {
|
|
504
|
+
ed.rec = r
|
|
505
|
+
return
|
|
506
|
+
}
|
|
507
|
+
this.editor?.dispose()
|
|
508
|
+
this.editor = new EditorSt(r, this, this.drafts.get(`${r.repo}/${r.id}`) ?? null)
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
select(r: RecView | null): void {
|
|
512
|
+
this.open = r == null ? null : { repo: r.repo, id: r.id }
|
|
513
|
+
this.gallery = false
|
|
514
|
+
this.arming = null
|
|
515
|
+
this.syncEditor()
|
|
516
|
+
this.st.navigate(this.address)
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
setGallery(on: boolean): void {
|
|
520
|
+
this.gallery = on
|
|
521
|
+
this.st.navigate(this.address)
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/** a recording the server answered, in place of the list's copy */
|
|
525
|
+
replace(r: RecView): void {
|
|
526
|
+
if (!this.data) return
|
|
527
|
+
this.data = { ...this.data, recordings: this.data.recordings.map((x) => (x.repo === r.repo && x.id === r.id ? r : x)) }
|
|
528
|
+
this.syncEditor()
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
async post<T extends { said?: string }>(r: RecView | null, verb: string, body: Record<string, unknown> = {}): Promise<T | null> {
|
|
532
|
+
this.busy = verb
|
|
533
|
+
try {
|
|
534
|
+
const url = r == null ? `${API}/${verb}` : `${API}/${encodeURIComponent(r.repo)}/${encodeURIComponent(r.id)}/${verb}`
|
|
535
|
+
const res = await reach(url, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body), signal: AbortSignal.timeout(600_000) })
|
|
536
|
+
const j = (await res.json().catch(() => ({ error: `${res.status}` }))) as T & { error?: string }
|
|
537
|
+
if (!res.ok) throw new Error(j.error ?? `${res.status}`)
|
|
538
|
+
if (j.said) this.say(j.said)
|
|
539
|
+
return j
|
|
540
|
+
} catch (e) {
|
|
541
|
+
this.say(ownTrouble(e, this.st.machine) || (e as Error).message)
|
|
542
|
+
return null
|
|
543
|
+
} finally {
|
|
544
|
+
runInAction(() => (this.busy = ''))
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/** a share of a thumb (copy file, copy link, Finder): the edit open on it exported first, so what goes out is what he sees */
|
|
549
|
+
async share(r: RecView, verb: 'link' | 'copy-file' | 'reveal', body: Record<string, unknown> = {}): Promise<void> {
|
|
550
|
+
const ed = this.editor
|
|
551
|
+
if (ed && ed.rec.repo === r.repo && ed.rec.id === r.id && ed.dirty) {
|
|
552
|
+
await ed.save()
|
|
553
|
+
if (this.editor?.dirty) return
|
|
554
|
+
} else if (this.hasDraft(r)) return this.say(`${r.name} has an edit not exported: open it and export it first`)
|
|
555
|
+
await this.post(r, verb, body)
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/** the take filed under another repo (or unassigned): its address follows it */
|
|
559
|
+
async move(r: RecView, repo: string): Promise<void> {
|
|
560
|
+
if (repo === r.repo) return
|
|
561
|
+
const j = await this.post<{ recording: RecView; said: string }>(r, 'move', { repo })
|
|
562
|
+
if (!j) return
|
|
563
|
+
await this.load()
|
|
564
|
+
runInAction(() => {
|
|
565
|
+
this.open = { repo: j.recording.repo, id: j.recording.id }
|
|
566
|
+
this.syncEditor()
|
|
567
|
+
this.st.navigate(this.address)
|
|
568
|
+
})
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
async rename(r: RecView, name: string): Promise<void> {
|
|
572
|
+
if (name === r.name) return
|
|
573
|
+
const j = await this.post<{ recording: RecView; said: string }>(r, 'rename', { name })
|
|
574
|
+
if (j) this.replace(j.recording)
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/** a thumb's delete: the first click arms it, the second deletes for good (the Space too, every link dies) */
|
|
578
|
+
async remove(r: RecView): Promise<void> {
|
|
579
|
+
const k = `${r.repo}/${r.id}`
|
|
580
|
+
if (this.arming !== k) {
|
|
581
|
+
this.arming = k
|
|
582
|
+
setTimeout(() => runInAction(() => { if (this.arming === k) this.arming = null }), 4000)
|
|
583
|
+
return
|
|
584
|
+
}
|
|
585
|
+
this.arming = null
|
|
586
|
+
const at = this.shown.findIndex((x) => x.repo === r.repo && x.id === r.id)
|
|
587
|
+
if (!(await this.post(r, 'delete'))) return
|
|
588
|
+
this.dropDraft(r)
|
|
589
|
+
await this.load()
|
|
590
|
+
const next = this.shown[Math.min(at, this.shown.length - 1)] ?? null
|
|
591
|
+
runInAction(() => {
|
|
592
|
+
this.open = next && { repo: next.repo, id: next.id }
|
|
593
|
+
this.syncEditor()
|
|
594
|
+
})
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/** a preset run by the recorder app, filed under the repo shown (or its default) */
|
|
598
|
+
async record(preset: string): Promise<void> {
|
|
599
|
+
await this.post(null, 'start', { preset, ...(this.repo ? { repo: this.repo } : {}) })
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
async load(): Promise<void> {
|
|
603
|
+
const id = ++this.gen
|
|
604
|
+
this.loading = true
|
|
605
|
+
try {
|
|
606
|
+
const r = await reach(`${API}.json`, { signal: AbortSignal.timeout(30_000) })
|
|
607
|
+
if (!r.ok) throw new Error(`${r.status} ${await r.text()}`)
|
|
608
|
+
const j = (await r.json()) as RecList
|
|
609
|
+
runInAction(() => {
|
|
610
|
+
if (id !== this.gen) return
|
|
611
|
+
this.data = j
|
|
612
|
+
this.error = ''
|
|
613
|
+
this.syncEditor()
|
|
614
|
+
})
|
|
615
|
+
} catch (e) {
|
|
616
|
+
runInAction(() => { if (id === this.gen) this.error = ownTrouble(e, this.st.machine) || (e as Error).message })
|
|
617
|
+
} finally {
|
|
618
|
+
runInAction(() => { if (id === this.gen) this.loading = false })
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
private poll: ReturnType<typeof setInterval> | null = null
|
|
623
|
+
|
|
624
|
+
/** a capture still uploading: the list is read again every few seconds until it is up */
|
|
625
|
+
get uploading(): boolean {
|
|
626
|
+
return (this.data?.recordings ?? []).some((r) => !r.up)
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
start(): void {
|
|
630
|
+
void this.load()
|
|
631
|
+
this.poll ??= setInterval(() => {
|
|
632
|
+
if (this.uploading && !this.loading) void this.load()
|
|
633
|
+
}, 3000)
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
stop(): void {
|
|
637
|
+
this.editor?.dispose()
|
|
638
|
+
if (this.poll) clearInterval(this.poll)
|
|
639
|
+
this.poll = null
|
|
640
|
+
}
|
|
641
|
+
}
|