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,138 @@
|
|
|
1
|
+
// the marks drawn on a recording (wiki tools/shipkit/recordings.md, The edit): arrows, rectangles, text, numbered
|
|
2
|
+
// steps and blurred boxes, one line each in the edit, in the take's pixels, each with an optional span of the take's
|
|
3
|
+
// time (none: the whole clip). Their order is the drawing order, and the steps count in it. Pure: the page imports it
|
|
4
|
+
// arrow 100,200 400,300 red 0:02-0:05
|
|
5
|
+
// rect 400x300+100+200 yellow
|
|
6
|
+
// text 120,80 "the bug is here" 48px white
|
|
7
|
+
// step 300,400 blue
|
|
8
|
+
// blur 400x120+10+10 0:00-0:04
|
|
9
|
+
export const COLORS = ['red', 'yellow', 'green', 'blue', 'white', 'black'] as const
|
|
10
|
+
export type MarkColor = (typeof COLORS)[number]
|
|
11
|
+
export const HEX: Record<MarkColor, string> = { red: '#e8364a', yellow: '#f5c518', green: '#2fb36f', blue: '#2f7ff0', white: '#ffffff', black: '#111111' }
|
|
12
|
+
|
|
13
|
+
export type Pt = { x: number; y: number }
|
|
14
|
+
export type Box = { w: number; h: number; x: number; y: number }
|
|
15
|
+
export type Span = { from: number; to: number }
|
|
16
|
+
|
|
17
|
+
export type Mark =
|
|
18
|
+
| { kind: 'arrow'; from: Pt; to: Pt; color: MarkColor; span: Span | null }
|
|
19
|
+
| { kind: 'rect'; box: Box; color: MarkColor; span: Span | null }
|
|
20
|
+
| { kind: 'text'; at: Pt; text: string; size: number | null; color: MarkColor; span: Span | null }
|
|
21
|
+
| { kind: 'step'; at: Pt; color: MarkColor; span: Span | null }
|
|
22
|
+
| { kind: 'blur'; box: Box; span: Span | null }
|
|
23
|
+
|
|
24
|
+
export const MARK_VERBS = ['arrow', 'rect', 'text', 'step', 'blur'] as const
|
|
25
|
+
export type MarkKind = Mark['kind']
|
|
26
|
+
|
|
27
|
+
/** a line's words: a double quoted run is one word, its quotes gone, `\"` a quote inside it */
|
|
28
|
+
export function words(line: string): string[] {
|
|
29
|
+
const out: string[] = []
|
|
30
|
+
const re = /"((?:[^"\\]|\\.)*)"|(\S+)/g
|
|
31
|
+
for (let m = re.exec(line); m; m = re.exec(line)) out.push(m[1] !== undefined ? m[1].replace(/\\(.)/g, '$1') : m[2]!)
|
|
32
|
+
return out
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// a point or a box may sit outside the take (a negative place): the canvas grows to hold it (edit.ts canvasOf)
|
|
36
|
+
const PT = /^(-?\d+),(-?\d+)$/
|
|
37
|
+
const BOX = /^(\d+)x(\d+)([+-]\d+)([+-]\d+)$/
|
|
38
|
+
const SIZE = /^(\d+)px$/
|
|
39
|
+
const SPAN = /^([\d:.]+)-([\d:.]+)$/
|
|
40
|
+
|
|
41
|
+
const pt = (w: string | undefined, what: string): Pt => {
|
|
42
|
+
const m = PT.exec(w ?? '')
|
|
43
|
+
if (!m) throw new Error(`${what}: a point is x,y in the take's pixels, like 120,80`)
|
|
44
|
+
return { x: Number(m[1]), y: Number(m[2]) }
|
|
45
|
+
}
|
|
46
|
+
const box = (w: string | undefined, what: string): Box => {
|
|
47
|
+
const m = BOX.exec(w ?? '')
|
|
48
|
+
if (!m) throw new Error(`${what}: a box is WxH+X+Y (or -X, -Y outside the take), like 400x300+100+200`)
|
|
49
|
+
return { w: Number(m[1]), h: Number(m[2]), x: Number(m[3]), y: Number(m[4]) }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** the optional words after a mark's place, in any order: a colour, a span, a text size */
|
|
53
|
+
function options(rest: string[], verb: string, parseTime: (t: string) => number, o: { color: boolean; size: boolean }): { color: MarkColor; span: Span | null; size: number | null } {
|
|
54
|
+
let color: MarkColor = 'red'
|
|
55
|
+
let span: Span | null = null
|
|
56
|
+
let size: number | null = null
|
|
57
|
+
for (const w of rest) {
|
|
58
|
+
const s = SPAN.exec(w)
|
|
59
|
+
if ((COLORS as readonly string[]).includes(w) && o.color) color = w as MarkColor
|
|
60
|
+
else if (s) {
|
|
61
|
+
span = { from: parseTime(s[1]!), to: parseTime(s[2]!) }
|
|
62
|
+
if (!(span.to > span.from)) throw new Error(`${w}: it ends before it starts`)
|
|
63
|
+
} else if (SIZE.test(w) && o.size) size = Number(SIZE.exec(w)![1])
|
|
64
|
+
else throw new Error(`${verb}: ${w}? after the place come ${[o.color && `a colour (${COLORS.join(', ')})`, 'a span (0:02-0:05)', o.size && 'a size (48px)'].filter(Boolean).join(', ')}`)
|
|
65
|
+
}
|
|
66
|
+
return { color, span, size }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** one mark line, its verb first; throws the reason it is not one */
|
|
70
|
+
export function parseMark(line: string, parseTime: (t: string) => number): Mark {
|
|
71
|
+
const [verb, ...rest] = words(line)
|
|
72
|
+
if (verb === 'arrow') {
|
|
73
|
+
const o = options(rest.slice(2), verb, parseTime, { color: true, size: false })
|
|
74
|
+
return { kind: 'arrow', from: pt(rest[0], 'arrow'), to: pt(rest[1], 'arrow'), color: o.color, span: o.span }
|
|
75
|
+
}
|
|
76
|
+
if (verb === 'rect' || verb === 'blur') {
|
|
77
|
+
const o = options(rest.slice(1), verb, parseTime, { color: verb === 'rect', size: false })
|
|
78
|
+
const b = box(rest[0], verb)
|
|
79
|
+
return verb === 'rect' ? { kind: 'rect', box: b, color: o.color, span: o.span } : { kind: 'blur', box: b, span: o.span }
|
|
80
|
+
}
|
|
81
|
+
if (verb === 'text') {
|
|
82
|
+
const text = rest[1]
|
|
83
|
+
if (text === undefined || text === '') throw new Error('text x,y "the words", like text 120,80 "here"')
|
|
84
|
+
const o = options(rest.slice(2), verb, parseTime, { color: true, size: true })
|
|
85
|
+
return { kind: 'text', at: pt(rest[0], 'text'), text, size: o.size, color: o.color, span: o.span }
|
|
86
|
+
}
|
|
87
|
+
if (verb === 'step') {
|
|
88
|
+
const o = options(rest.slice(1), verb, parseTime, { color: true, size: false })
|
|
89
|
+
return { kind: 'step', at: pt(rest[0], 'step'), color: o.color, span: o.span }
|
|
90
|
+
}
|
|
91
|
+
throw new Error(`${verb}: not a mark`)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const quote = (s: string): string => `"${s.replace(/(["\\])/g, '\\$1')}"`
|
|
95
|
+
|
|
96
|
+
export function printMark(m: Mark, printTime: (s: number) => string): string {
|
|
97
|
+
const sp = m.span ? ` ${printTime(m.span.from)}-${printTime(m.span.to)}` : ''
|
|
98
|
+
const sg = (n: number): string => (n < 0 ? String(n) : `+${n}`)
|
|
99
|
+
const bx = (b: Box): string => `${b.w}x${b.h}${sg(b.x)}${sg(b.y)}`
|
|
100
|
+
if (m.kind === 'arrow') return `arrow ${m.from.x},${m.from.y} ${m.to.x},${m.to.y} ${m.color}${sp}`
|
|
101
|
+
if (m.kind === 'rect') return `rect ${bx(m.box)} ${m.color}${sp}`
|
|
102
|
+
if (m.kind === 'blur') return `blur ${bx(m.box)}${sp}`
|
|
103
|
+
if (m.kind === 'text') return `text ${m.at.x},${m.at.y} ${quote(m.text)}${m.size ? ` ${m.size}px` : ''} ${m.color}${sp}`
|
|
104
|
+
return `step ${m.at.x},${m.at.y} ${m.color}${sp}`
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** the number a step shows: its rank among the steps */
|
|
108
|
+
export const stepNumber = (marks: readonly Mark[], i: number): number => marks.slice(0, i + 1).filter((m) => m.kind === 'step').length
|
|
109
|
+
|
|
110
|
+
/** a mark moved by dx, dy (the select tool's drag) */
|
|
111
|
+
export function moved(m: Mark, dx: number, dy: number): Mark {
|
|
112
|
+
const p = (q: Pt): Pt => ({ x: Math.round(q.x + dx), y: Math.round(q.y + dy) })
|
|
113
|
+
const b = (q: Box): Box => ({ ...q, x: Math.round(q.x + dx), y: Math.round(q.y + dy) })
|
|
114
|
+
if (m.kind === 'arrow') return { ...m, from: p(m.from), to: p(m.to) }
|
|
115
|
+
if (m.kind === 'rect' || m.kind === 'blur') return { ...m, box: b(m.box) }
|
|
116
|
+
return { ...m, at: p(m.at) }
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** the rectangle a mark covers, in the take's pixels, for the select tool's hit and frame (text and steps estimated) */
|
|
120
|
+
export function boundsOf(m: Mark, frame: { width: number; height: number }): Box {
|
|
121
|
+
const s = style(frame)
|
|
122
|
+
if (m.kind === 'arrow') {
|
|
123
|
+
const x = Math.min(m.from.x, m.to.x)
|
|
124
|
+
const y = Math.min(m.from.y, m.to.y)
|
|
125
|
+
const pad = s.stroke * 3
|
|
126
|
+
return { x: x - pad, y: y - pad, w: Math.abs(m.to.x - m.from.x) + pad * 2, h: Math.abs(m.to.y - m.from.y) + pad * 2 }
|
|
127
|
+
}
|
|
128
|
+
if (m.kind === 'rect' || m.kind === 'blur') return m.box
|
|
129
|
+
if (m.kind === 'step') return { x: m.at.x - s.step, y: m.at.y - s.step, w: s.step * 2, h: s.step * 2 }
|
|
130
|
+
const size = m.size ?? s.text
|
|
131
|
+
return { x: m.at.x, y: m.at.y, w: Math.max(size, m.text.length * size * 0.56), h: size * 1.25 }
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** the sizes a frame draws its marks at: thick enough to read once the clip is shrunk in a chat */
|
|
135
|
+
export function style(frame: { width: number; height: number }): { stroke: number; text: number; step: number; blur: number } {
|
|
136
|
+
const short = Math.min(frame.width, frame.height)
|
|
137
|
+
return { stroke: Math.max(3, Math.round(short / 160)), text: Math.max(16, Math.round(short / 22)), step: Math.max(12, Math.round(short / 34)), blur: Math.max(8, Math.round(short / 60)) }
|
|
138
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// the recordings as a kind of the media store (wiki tools/shipkit/recordings.md, In the media store): each take, its
|
|
2
|
+
// export and its poster, by the facts its meta.json keeps. One kind object per root a take was written to (the drive,
|
|
3
|
+
// the Mac's disk), each with a store per repo. A poster stays on the disk (the grid reads it); the rest goes when
|
|
4
|
+
// unused for the store's window and the drive runs short
|
|
5
|
+
import { statSync } from 'node:fs'
|
|
6
|
+
import { join, resolve } from 'node:path'
|
|
7
|
+
import { factOf, shaOf, shaOfKey } from '../media-store/content.ts'
|
|
8
|
+
import type { MediaKind, MediaRow } from '../media-store/kind.ts'
|
|
9
|
+
import { fallbackDir, knownRoots, repoDir, UNASSIGNED } from './place.ts'
|
|
10
|
+
import { readMeta, recordingsIn, usedAt, writeMeta, POSTER } from './model.ts'
|
|
11
|
+
|
|
12
|
+
export const RECORDING_KIND = 'recording'
|
|
13
|
+
|
|
14
|
+
/** the kind of one root: a store per repo, or (`unassigned`) the one folder no repo owns, whatever repo asks */
|
|
15
|
+
export function recordingKindAt(root: string, o: { unassigned?: boolean } = {}): MediaKind {
|
|
16
|
+
return {
|
|
17
|
+
kind: RECORDING_KIND,
|
|
18
|
+
storeOf: (repoRoot) => (o.unassigned ? join(root, UNASSIGNED) : repoDir(root, repoRoot)),
|
|
19
|
+
stamp(store) {
|
|
20
|
+
const parts = recordingsIn(root, store).map((r) => `${r.id}:${statSync(join(r.dir, 'meta.json'), { throwIfNoEntry: false })?.mtimeMs ?? '-'}:${Object.keys(r.files).map((n) => `${n}=${statSync(join(r.dir, n), { throwIfNoEntry: false })?.size ?? '-'}`).join(',')}`)
|
|
21
|
+
return Bun.hash(parts.join('\n')).toString(36)
|
|
22
|
+
},
|
|
23
|
+
async scan(store, o) {
|
|
24
|
+
const rows: MediaRow[] = []
|
|
25
|
+
let budget = o.fill
|
|
26
|
+
let filled = 0
|
|
27
|
+
let left = 0
|
|
28
|
+
for (const r of recordingsIn(root, store)) {
|
|
29
|
+
const m = readMeta(r.dir)
|
|
30
|
+
if (!m) continue
|
|
31
|
+
let moved = false
|
|
32
|
+
for (const n of Object.keys(m.files)) {
|
|
33
|
+
const size = statSync(join(r.dir, n), { throwIfNoEntry: false })?.size
|
|
34
|
+
if (size === undefined || size === m.files[n]!.size) continue
|
|
35
|
+
// a file that changed under its name (an export again): its fact again, within the budget
|
|
36
|
+
if (budget <= 0) {
|
|
37
|
+
left++
|
|
38
|
+
continue
|
|
39
|
+
}
|
|
40
|
+
budget--
|
|
41
|
+
filled++
|
|
42
|
+
m.files[n] = await factOf(join(r.dir, n))
|
|
43
|
+
moved = true
|
|
44
|
+
}
|
|
45
|
+
if (moved) writeMeta(r.dir, m)
|
|
46
|
+
for (const [n, f] of Object.entries(m.files)) {
|
|
47
|
+
const size = statSync(join(r.dir, n), { throwIfNoEntry: false })?.size
|
|
48
|
+
rows.push({ item: r.id, name: n, fact: f, local: size === f.size })
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return { rows, filled, left }
|
|
52
|
+
},
|
|
53
|
+
async holds(store) {
|
|
54
|
+
return (row) => ({ pinned: row.name === POSTER, used: usedAt(join(store, row.item)) })
|
|
55
|
+
},
|
|
56
|
+
async beforePurge(store, _space, row) {
|
|
57
|
+
const sha = await shaOf(join(store, row.item, row.name))
|
|
58
|
+
if (sha !== shaOfKey(row.key)) throw new Error(`${join(row.item, row.name)} changed since its fact: kept`)
|
|
59
|
+
},
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** the kind on the Mac's disk: always one, so the code's labels name it */
|
|
64
|
+
export const recordingMedia: MediaKind = recordingKindAt(fallbackDir())
|
|
65
|
+
|
|
66
|
+
/** two kinds per root a take was ever written to (the Mac's disk among them): its repo folders, its unassigned one */
|
|
67
|
+
export const recordingKinds = (): MediaKind[] => knownRoots().flatMap((r) => [r === resolve(fallbackDir()) ? recordingMedia : recordingKindAt(r), recordingKindAt(r, { unassigned: true })])
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
// one recording on the disk (wiki tools/shipkit/recordings.md, A recording): `<root>/<repo>/<id>/` holds `raw.<ext>`
|
|
2
|
+
// (the take, never changed), `edit.txt` and `out.<ext>` (the export of that edit), `poster.webp` and `meta.json`, its
|
|
3
|
+
// facts and the sha of each media file. The id is the take's time and never moves; the name is what a trailer, a link
|
|
4
|
+
// and the hub say, unique in its repo
|
|
5
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, statSync, writeFileSync } from 'node:fs'
|
|
6
|
+
import { mediaDb } from '../media-store/db.ts'
|
|
7
|
+
import { join } from 'node:path'
|
|
8
|
+
import { mediaKey } from '../media-store/content.ts'
|
|
9
|
+
import type { MediaFact } from '../media-store/fact.ts'
|
|
10
|
+
import { recordingRoots, repoDir } from './place.ts'
|
|
11
|
+
|
|
12
|
+
export type RecMeta = {
|
|
13
|
+
id: string
|
|
14
|
+
name: string
|
|
15
|
+
/** the repo's name, its folder under the root */
|
|
16
|
+
repo: string
|
|
17
|
+
still: boolean
|
|
18
|
+
/** ISO time of the take */
|
|
19
|
+
created: string
|
|
20
|
+
preset?: string
|
|
21
|
+
width: number
|
|
22
|
+
height: number
|
|
23
|
+
/** 0 for a still */
|
|
24
|
+
seconds: number
|
|
25
|
+
audio: boolean
|
|
26
|
+
/** `raw.mp4` or `raw.png` */
|
|
27
|
+
raw: string
|
|
28
|
+
/** the media files and their content, by name: raw, out, poster */
|
|
29
|
+
files: Record<string, MediaFact>
|
|
30
|
+
/** the permanent URL of its public copy, once published */
|
|
31
|
+
publicUrl?: string
|
|
32
|
+
/** every Space key it had that its files no longer name (an export, a poster or a public copy replaced): a delete
|
|
33
|
+
* takes them too, so a link copied before an export dies with the rest */
|
|
34
|
+
former?: string[]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export type Recording = RecMeta & { dir: string; root: string }
|
|
38
|
+
|
|
39
|
+
export const META = 'meta.json'
|
|
40
|
+
export const EDIT = 'edit.txt'
|
|
41
|
+
export const POSTER = 'poster.webp'
|
|
42
|
+
export const NAME = /^[a-z0-9][a-z0-9-]{0,63}$/
|
|
43
|
+
|
|
44
|
+
export const outOf = (m: Pick<RecMeta, 'raw'>): string => m.raw.replace(/^raw\./, 'out.')
|
|
45
|
+
|
|
46
|
+
/** a Space key the meta is about to stop naming, kept in `former` */
|
|
47
|
+
export function retireKey(m: RecMeta, key: string): void {
|
|
48
|
+
const f = new Set(m.former ?? [])
|
|
49
|
+
f.add(key)
|
|
50
|
+
m.former = [...f]
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** the file `name`'s key kept in `former` before its fact is replaced or dropped */
|
|
54
|
+
export function retire(m: RecMeta, name: string): void {
|
|
55
|
+
const f = m.files[name]
|
|
56
|
+
if (f) retireKey(m, mediaKey('recording', f, name))
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** the file a reader plays: the export of the edit when it is there and current, else the take */
|
|
60
|
+
export function currentFile(r: Recording): string {
|
|
61
|
+
const out = join(r.dir, outOf(r))
|
|
62
|
+
return existsSync(join(r.dir, EDIT)) && (existsSync(out) || r.files[outOf(r)]) ? outOf(r) : r.raw
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** a take's id from its time: `20261109-191230` */
|
|
66
|
+
export function idOf(at: Date): string {
|
|
67
|
+
const p = (n: number): string => String(n).padStart(2, '0')
|
|
68
|
+
return `${at.getFullYear()}${p(at.getMonth() + 1)}${p(at.getDate())}-${p(at.getHours())}${p(at.getMinutes())}${p(at.getSeconds())}`
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function readMeta(dir: string): RecMeta | null {
|
|
72
|
+
try {
|
|
73
|
+
return JSON.parse(readFileSync(join(dir, META), 'utf8')) as RecMeta
|
|
74
|
+
} catch {
|
|
75
|
+
return null
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** written beside, then renamed: a reader never sees half a file */
|
|
80
|
+
export function writeMeta(dir: string, m: RecMeta): void {
|
|
81
|
+
const tmp = join(dir, `.${META}.tmp`)
|
|
82
|
+
writeFileSync(tmp, `${JSON.stringify(m, null, 2)}\n`)
|
|
83
|
+
renameSync(tmp, join(dir, META))
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const dirs = (p: string): string[] => {
|
|
87
|
+
try {
|
|
88
|
+
return readdirSync(p, { withFileTypes: true }).filter((e) => e.isDirectory() && !e.name.startsWith('.')).map((e) => e.name)
|
|
89
|
+
} catch {
|
|
90
|
+
return []
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** every recording of one repo folder */
|
|
95
|
+
export function recordingsIn(root: string, repoFolder: string): Recording[] {
|
|
96
|
+
const out: Recording[] = []
|
|
97
|
+
for (const id of dirs(repoFolder)) {
|
|
98
|
+
const dir = join(repoFolder, id)
|
|
99
|
+
const m = readMeta(dir)
|
|
100
|
+
if (m) out.push({ ...m, dir, root })
|
|
101
|
+
}
|
|
102
|
+
return out
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** every recording of every root, of one repo or all, newest first */
|
|
106
|
+
export async function listRecordings(o: { repo?: string } = {}): Promise<Recording[]> {
|
|
107
|
+
const out: Recording[] = []
|
|
108
|
+
for (const root of await recordingRoots()) {
|
|
109
|
+
const repos = o.repo === undefined ? dirs(root) : [o.repo]
|
|
110
|
+
for (const repo of repos) out.push(...recordingsIn(root, repoDir(root, repo)))
|
|
111
|
+
}
|
|
112
|
+
return out.sort((a, b) => b.created.localeCompare(a.created) || b.id.localeCompare(a.id))
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** a recording by `<name>`, `<id>`, or `<repo>/<name>`; `repo` is where a bare name looks first */
|
|
116
|
+
export async function findRecording(ref: string, o: { repo?: string } = {}): Promise<Recording> {
|
|
117
|
+
const at = ref.indexOf('/')
|
|
118
|
+
const repo = at > 0 ? ref.slice(0, at) : o.repo
|
|
119
|
+
const word = at > 0 ? ref.slice(at + 1) : ref
|
|
120
|
+
const all = await listRecordings(repo === undefined ? {} : { repo })
|
|
121
|
+
const hits = all.filter((r) => r.name === word || r.id === word)
|
|
122
|
+
if (hits.length === 1) return hits[0]!
|
|
123
|
+
if (hits.length > 1) throw new Error(`${ref}: ${hits.length} recordings answer to it (${hits.map((r) => `${r.repo}/${r.name}`).join(', ')}); name the repo`)
|
|
124
|
+
throw new Error(`${ref}: no recording of that name${repo ? ` in ${repo}` : ''} (sk rec ls lists them)`)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** the name given, checked free in the repo folder */
|
|
128
|
+
export function checkName(repoFolder: string, name: string, self?: string): void {
|
|
129
|
+
if (!NAME.test(name)) throw new Error(`${name}: a name is lowercase letters, digits and dashes`)
|
|
130
|
+
for (const id of dirs(repoFolder)) {
|
|
131
|
+
if (id === self) continue
|
|
132
|
+
const m = readMeta(join(repoFolder, id))
|
|
133
|
+
if (m && (m.name === name || m.id === name)) throw new Error(`${name}: ${m.repo} already has a recording of that name`)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function rename(r: Recording, name: string): Recording {
|
|
138
|
+
checkName(join(r.root, r.repo), name, r.id)
|
|
139
|
+
const m = readMeta(r.dir)
|
|
140
|
+
if (!m) throw new Error(`${r.dir}: no ${META}`)
|
|
141
|
+
m.name = name
|
|
142
|
+
writeMeta(r.dir, m)
|
|
143
|
+
return { ...m, dir: r.dir, root: r.root }
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** the take filed under another repo (or `unassigned`) on its own root: its folder moved, its meta and its media
|
|
147
|
+
* index rows following, so the upload, the purge and a delete still find every file */
|
|
148
|
+
export function moveRecording(r: Recording, repo: string): Recording {
|
|
149
|
+
if (!NAME.test(repo)) throw new Error(`${repo}: a repo is lowercase letters, digits and dashes`)
|
|
150
|
+
if (repo === r.repo) return r
|
|
151
|
+
const folder = join(r.root, repo)
|
|
152
|
+
mkdirSync(folder, { recursive: true })
|
|
153
|
+
checkName(folder, r.name)
|
|
154
|
+
const to = join(folder, r.id)
|
|
155
|
+
if (existsSync(to)) throw new Error(`${repo} already has a take ${r.id}`)
|
|
156
|
+
renameSync(r.dir, to)
|
|
157
|
+
const m = readMeta(to)!
|
|
158
|
+
m.repo = repo
|
|
159
|
+
writeMeta(to, m)
|
|
160
|
+
const db = mediaDb()
|
|
161
|
+
db?.query('update files set store = ? where store = ? and item = ?').run(folder, join(r.root, r.repo), r.id)
|
|
162
|
+
return { ...m, dir: to, root: r.root }
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** the newest mtime of what a person touches: the meta and the edit */
|
|
166
|
+
export const usedAt = (dir: string): number | undefined => {
|
|
167
|
+
const t = [META, EDIT].map((n) => statSync(join(dir, n), { throwIfNoEntry: false })?.mtimeMs ?? 0)
|
|
168
|
+
const m = Math.max(...t)
|
|
169
|
+
return m > 0 ? m : undefined
|
|
170
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// the recordings' doors to the rest of the Mac: the hub's editor opened on a take, the recorder app asked to record
|
|
2
|
+
// through its url scheme, a folder sent to the Trash
|
|
3
|
+
import { join } from 'node:path'
|
|
4
|
+
import { homeUrl } from '../home/home-paths.ts'
|
|
5
|
+
import type { Recording } from './model.ts'
|
|
6
|
+
import { recordingAddress } from './view.ts'
|
|
7
|
+
import type { RecPreset } from './presets.ts'
|
|
8
|
+
|
|
9
|
+
export const RECORDER_SCHEME = 'shipkit-recorder'
|
|
10
|
+
|
|
11
|
+
/** the editor in a shipkit window, its own short process like every window the home opens */
|
|
12
|
+
export async function openEditor(r: Recording): Promise<void> {
|
|
13
|
+
const url = `${homeUrl()}${recordingAddress(r)}`
|
|
14
|
+
const p = Bun.spawn([process.execPath, join(import.meta.dir, '..', 'home', 'open-app.ts'), url], { stdout: 'ignore', stderr: 'pipe' })
|
|
15
|
+
if ((await p.exited) !== 0) throw new Error(`the editor did not open: ${(await new Response(p.stderr).text()).trim()}`)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** the url that asks the app to record: a preset by id, or a whole preset of its own (a trailer's shot) */
|
|
19
|
+
export function recorderUrl(o: { preset?: string; spec?: RecPreset; repo?: string; name?: string; replace?: string }): string {
|
|
20
|
+
const q = new URLSearchParams()
|
|
21
|
+
if (o.preset) q.set('preset', o.preset)
|
|
22
|
+
if (o.spec) q.set('spec', JSON.stringify(o.spec))
|
|
23
|
+
if (o.repo) q.set('repo', o.repo)
|
|
24
|
+
if (o.name) q.set('name', o.name)
|
|
25
|
+
if (o.replace) q.set('replace', o.replace)
|
|
26
|
+
return `${RECORDER_SCHEME}://record?${q.toString()}`
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** a folder to the Trash through the Finder: it works across drives, and it can be put back */
|
|
30
|
+
export async function trash(dir: string): Promise<void> {
|
|
31
|
+
const p = Bun.spawn(['osascript', '-e', 'on run argv', '-e', 'tell application "Finder" to delete (POSIX file (item 1 of argv) as alias)', '-e', 'end run', dir], { stdout: 'ignore', stderr: 'pipe' })
|
|
32
|
+
if ((await p.exited) !== 0) throw new Error(`the Trash refused ${dir}: ${(await new Response(p.stderr).text()).trim()}`)
|
|
33
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// where the recordings live (wiki tools/shipkit/recordings.md, Where takes live): the house config's `recorder.dir`
|
|
2
|
+
// (an external drive), else the machine's home dir. A dir under `/Volumes/<drive>` counts only while that drive is
|
|
3
|
+
// mounted: `/Volumes` is root's, so an unplugged drive is never a phantom folder we write into. Then the home dir holds
|
|
4
|
+
// the take, said loud, and both roots stay listed so nothing recorded on the road is lost
|
|
5
|
+
import { existsSync, mkdirSync } from 'node:fs'
|
|
6
|
+
import { basename, join, resolve, sep } from 'node:path'
|
|
7
|
+
import { machineGet, machineSet } from '../core/machine-db.ts'
|
|
8
|
+
import { homeDir } from '../home/home-paths.ts'
|
|
9
|
+
|
|
10
|
+
/** the folder of the takes no repo owns yet: where every take goes unless one is picked */
|
|
11
|
+
export const UNASSIGNED = 'unassigned'
|
|
12
|
+
|
|
13
|
+
/** a folder in place of the house config's `recorder.dir`, for one process (a test's temp folder) */
|
|
14
|
+
export const RECORDINGS_ENV = 'SHIPKIT_RECORDINGS'
|
|
15
|
+
|
|
16
|
+
/** the machine's own fallback: the Mac's disk, under the shipkit home dir */
|
|
17
|
+
export const fallbackDir = (): string => join(homeDir(), 'recordings')
|
|
18
|
+
|
|
19
|
+
/** the drive a path sits on when it is an external one (`/Volumes/<drive>`), null on the system disk */
|
|
20
|
+
export function driveOf(path: string): string | null {
|
|
21
|
+
const parts = resolve(path).split(sep)
|
|
22
|
+
return parts[1] === 'Volumes' && parts[2] ? `/Volumes/${parts[2]}` : null
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** the configured dir can take a file now: its drive mounted, or no drive to wait for */
|
|
26
|
+
export function usable(dir: string): boolean {
|
|
27
|
+
const drive = driveOf(dir)
|
|
28
|
+
return drive === null || existsSync(drive)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let held: Promise<string | null> | null = null
|
|
32
|
+
|
|
33
|
+
/** the house config's `recorder.dir`, or the env's; null when neither names one */
|
|
34
|
+
export function configuredDir(): Promise<string | null> {
|
|
35
|
+
held ??= (async (): Promise<string | null> => {
|
|
36
|
+
const env = process.env[RECORDINGS_ENV]
|
|
37
|
+
if (env !== undefined) return env === '' ? null : env
|
|
38
|
+
const { houseRoot } = await import('../home/home-start.ts')
|
|
39
|
+
const { loadRepoConfig } = await import('../repo-config.ts')
|
|
40
|
+
const house = houseRoot(process.cwd())
|
|
41
|
+
return house ? ((await loadRepoConfig(house)).recorder?.dir ?? null) : null
|
|
42
|
+
})()
|
|
43
|
+
return held
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** a test's own dir in place of the machine's; undefined reads it again */
|
|
47
|
+
export function useRecordingsDir(dir: string | null | undefined): void {
|
|
48
|
+
held = dir === undefined ? null : Promise.resolve(dir)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const KNOWN = 'recordings-roots'
|
|
52
|
+
|
|
53
|
+
/** every root a take was ever written to, the media store's sync read of where recordings sit: a root holds a take
|
|
54
|
+
* only once a write named it here, so the list is never short of one */
|
|
55
|
+
export function knownRoots(): string[] {
|
|
56
|
+
const env = process.env[RECORDINGS_ENV]
|
|
57
|
+
const own = env !== undefined && env !== '' ? [resolve(env)] : (machineGet<string[]>(KNOWN) ?? [])
|
|
58
|
+
return [...new Set([...own, resolve(fallbackDir())])]
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function rememberRoot(root: string): void {
|
|
62
|
+
if (process.env[RECORDINGS_ENV] !== undefined) return
|
|
63
|
+
const had = machineGet<string[]>(KNOWN) ?? []
|
|
64
|
+
if (!had.includes(resolve(root))) machineSet(KNOWN, [...had, resolve(root)])
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** every root a recording may sit in, the configured one first: all are read, only a usable one is written */
|
|
68
|
+
export async function recordingRoots(): Promise<string[]> {
|
|
69
|
+
const dir = await configuredDir()
|
|
70
|
+
return [...new Set([...(dir === null ? [] : [resolve(dir)]), ...knownRoots()])]
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** the root a new take goes to, and the warning when it is not the configured one */
|
|
74
|
+
export async function writeRoot(): Promise<{ root: string; warn: string | null }> {
|
|
75
|
+
const dir = await configuredDir()
|
|
76
|
+
if (dir === null) return { root: fallbackDir(), warn: null }
|
|
77
|
+
if (usable(dir)) return { root: dir, warn: null }
|
|
78
|
+
return { root: fallbackDir(), warn: `WARN recordings: ${driveOf(dir)} is not mounted, so this take stays on the Mac's disk (${fallbackDir()})` }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** a repo's folder under a root: its name, the same on every root */
|
|
82
|
+
export const repoDir = (root: string, repo: string): string => join(root, basename(repo))
|
|
83
|
+
|
|
84
|
+
/** the folder made when absent; refused under an unmounted drive */
|
|
85
|
+
export function ensureDir(dir: string): string {
|
|
86
|
+
if (!usable(dir)) throw new Error(`${dir}: ${driveOf(dir)} is not mounted`)
|
|
87
|
+
mkdirSync(dir, { recursive: true })
|
|
88
|
+
return dir
|
|
89
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// the recorder's presets (wiki tools/shipkit/recordings.md, Presets): each one is a hotkey, what it shoots, its
|
|
2
|
+
// options and what runs after. Data only: the shipkit app reads them through `sk rec presets --json` and records,
|
|
3
|
+
// `sk rec import` files the take and runs `after`. The house config's presets replace the built-in ones by name, a
|
|
4
|
+
// repo's own join them under its name
|
|
5
|
+
import { basename } from 'node:path'
|
|
6
|
+
|
|
7
|
+
/** what a preset shoots: `select` the crosshair (a click takes a window, a drag an area; a video's choice is adjusted,
|
|
8
|
+
* its handles resizing the window itself), `region` the same with areas only, `freeze` the crosshair on the screen
|
|
9
|
+
* under the pointer frozen the instant the hotkey is pressed (a screenshot only), `pick` the system's picker, `screen`
|
|
10
|
+
* the screen under the pointer, or one app's window (its name or a word of its title), resized to `size` first */
|
|
11
|
+
export type RecShoot = 'select' | 'pick' | 'region' | 'freeze' | 'screen' | { window: string; size?: string }
|
|
12
|
+
|
|
13
|
+
export const AFTERS = ['upload', 'copy-link', 'copy-public-link', 'copy-file', 'copy-markdown', 'open-editor', 'reveal'] as const
|
|
14
|
+
/** a step run after the take is filed, in order: `copy-link` is a private link (7 days), `copy-public-link` a
|
|
15
|
+
* permanent one anyone opens, `copy-file` puts the file itself on the clipboard (a paste attaches it) */
|
|
16
|
+
export type RecAfter = (typeof AFTERS)[number]
|
|
17
|
+
|
|
18
|
+
export type RecPreset = {
|
|
19
|
+
/** the global hotkey, `alt+shift+r`, or several: modifiers (cmd, ctrl, alt, shift) and one key each */
|
|
20
|
+
key?: string | string[]
|
|
21
|
+
/** the menu's words; the preset's name when none */
|
|
22
|
+
label?: string
|
|
23
|
+
shoot: RecShoot
|
|
24
|
+
/** a screenshot, not a video */
|
|
25
|
+
still?: boolean
|
|
26
|
+
mic?: boolean
|
|
27
|
+
/** the sound the Mac plays (apps, games) */
|
|
28
|
+
systemAudio?: boolean
|
|
29
|
+
/** a ring on every click */
|
|
30
|
+
clicks?: boolean
|
|
31
|
+
/** the pointer in the frame (on unless false) */
|
|
32
|
+
cursor?: boolean
|
|
33
|
+
/** seconds of countdown before it starts */
|
|
34
|
+
countdown?: number
|
|
35
|
+
/** stops on its own after this long */
|
|
36
|
+
seconds?: number
|
|
37
|
+
/** the frames per second of a video (30 unless set) */
|
|
38
|
+
fps?: number
|
|
39
|
+
after?: RecAfter[]
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type RecorderConfig = {
|
|
43
|
+
/** the folder every take goes to, a folder per repo inside (house config only): an external drive's folder is
|
|
44
|
+
* used while the drive is mounted, else the Mac's disk takes the take, said loud */
|
|
45
|
+
dir?: string
|
|
46
|
+
presets?: Record<string, RecPreset>
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** what ships when the house names none: a video and a screenshot, each a window or an area, and a screenshot taken
|
|
50
|
+
* on the screen as it was the instant its hotkey was pressed */
|
|
51
|
+
export const BUILTIN_PRESETS: Record<string, RecPreset> = {
|
|
52
|
+
video: { key: 'alt+shift+r', label: 'Video', shoot: 'select', mic: true, clicks: true, after: ['upload', 'copy-link'] },
|
|
53
|
+
still: { key: 'alt+shift+s', label: 'Screenshot', shoot: 'select', still: true, after: ['copy-file', 'upload', 'open-editor'] },
|
|
54
|
+
instant: { key: 'alt+shift+i', label: 'Screenshot, frozen', shoot: 'freeze', still: true, after: ['copy-file', 'upload', 'open-editor'] },
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** one preset as the app and the hub read it: its id (`video`, or `<repo>/<name>` for a repo's own), its source, and
|
|
58
|
+
* its hotkeys as a list */
|
|
59
|
+
export type NamedPreset = RecPreset & { id: string; from: 'shipkit' | 'house' | string; keys: string[] }
|
|
60
|
+
|
|
61
|
+
/** a preset's hotkeys, none, one or several, as a list */
|
|
62
|
+
export const keysOf = (p: Pick<RecPreset, 'key'>): string[] => (p.key === undefined ? [] : typeof p.key === 'string' ? [p.key] : p.key)
|
|
63
|
+
|
|
64
|
+
const KEY = /^((cmd|ctrl|alt|shift)\+)+([a-z0-9]|f\d{1,2}|space)$/
|
|
65
|
+
const SIZE = /^\d{2,5}x\d{2,5}$/
|
|
66
|
+
|
|
67
|
+
/** the reasons a preset is wrong, empty when it is fine */
|
|
68
|
+
export function presetProblems(id: string, p: RecPreset): string[] {
|
|
69
|
+
const out: string[] = []
|
|
70
|
+
for (const k of keysOf(p)) if (!KEY.test(k)) out.push(`${id}: key ${k}: modifiers (cmd, ctrl, alt, shift) then one key, like alt+shift+r`)
|
|
71
|
+
const s = p.shoot
|
|
72
|
+
if (typeof s === 'string' ? !['select', 'pick', 'region', 'freeze', 'screen'].includes(s) : typeof s?.window !== 'string' || s.window === '') out.push(`${id}: shoot is select, pick, region, freeze, screen or { window: '<app>' }`)
|
|
73
|
+
if (s === 'freeze' && !p.still) out.push(`${id}: shoot freeze takes a screenshot: still: true`)
|
|
74
|
+
if (typeof s === 'object' && s?.size !== undefined && !SIZE.test(s.size)) out.push(`${id}: size ${s.size}: WIDTHxHEIGHT, like 1920x1080`)
|
|
75
|
+
for (const a of p.after ?? []) if (!(AFTERS as readonly string[]).includes(a)) out.push(`${id}: after ${a}: one of ${AFTERS.join(', ')}`)
|
|
76
|
+
if (p.still && (p.seconds !== undefined || p.systemAudio || p.mic)) out.push(`${id}: a still has no seconds, mic or sound`)
|
|
77
|
+
if (p.seconds !== undefined && !(p.seconds > 0)) out.push(`${id}: seconds must be above 0`)
|
|
78
|
+
if (p.countdown !== undefined && !(p.countdown >= 0 && p.countdown <= 10)) out.push(`${id}: countdown is 0 to 10 seconds`)
|
|
79
|
+
if (p.fps !== undefined && !(p.fps >= 1 && p.fps <= 120)) out.push(`${id}: fps is 1 to 120`)
|
|
80
|
+
return out
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** the presets of the menu: the house's (or the built-in ones), then each repo's own as `<repo>/<name>`; a hotkey
|
|
84
|
+
* two presets claim is a problem */
|
|
85
|
+
export function mergePresets(house: RecorderConfig | undefined, repos: { root: string; recorder: RecorderConfig | undefined }[]): { presets: NamedPreset[]; problems: string[] } {
|
|
86
|
+
const presets: NamedPreset[] = []
|
|
87
|
+
const base = house?.presets ?? BUILTIN_PRESETS
|
|
88
|
+
for (const [id, p] of Object.entries(base)) presets.push({ ...p, id, from: house?.presets ? 'house' : 'shipkit', keys: keysOf(p) })
|
|
89
|
+
for (const r of repos) for (const [n, p] of Object.entries(r.recorder?.presets ?? {})) presets.push({ ...p, id: `${basename(r.root)}/${n}`, from: basename(r.root), keys: keysOf(p) })
|
|
90
|
+
const problems = presets.flatMap((p) => presetProblems(p.id, p))
|
|
91
|
+
const keys = new Map<string, string>()
|
|
92
|
+
for (const p of presets)
|
|
93
|
+
for (const k of p.keys) {
|
|
94
|
+
const had = keys.get(k)
|
|
95
|
+
if (had) problems.push(`${p.id}: key ${k} is already ${had}'s`)
|
|
96
|
+
else keys.set(k, p.id)
|
|
97
|
+
}
|
|
98
|
+
return { presets, problems }
|
|
99
|
+
}
|