rvlib-shipkit 2.21.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.
Files changed (100) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/package.json +1 -1
  3. package/src/asks/asks-queue.ts +8 -7
  4. package/src/assets/kits/identity-kit.ts +158 -2
  5. package/src/cli/cmd_Bump.ts +3 -3
  6. package/src/cli/cmd_Rec.ts +349 -0
  7. package/src/cli/cmd_Releases.ts +4 -1
  8. package/src/cli/cmd_Secret.ts +10 -3
  9. package/src/cli/cmd_Sign.ts +24 -0
  10. package/src/cli/cmd_Social.ts +44 -1
  11. package/src/cli/family-pages.ts +1 -0
  12. package/src/cli/registry.ts +4 -0
  13. package/src/core/agent-spawn.ts +4 -17
  14. package/src/core/code-lines.ts +49 -0
  15. package/src/core/discover-checks.ts +27 -3
  16. package/src/core/hard-reset.ts +34 -0
  17. package/src/core/raw-access.ts +3 -13
  18. package/src/core/throwaway-worktree.ts +72 -0
  19. package/src/home/app-sign.ts +98 -0
  20. package/src/home/gui-app.ts +31 -12
  21. package/src/home/home-routes.ts +6 -0
  22. package/src/home/serve-web.ts +1 -1
  23. package/src/identities/identities.ts +6 -0
  24. package/src/media-kinds.ts +5 -3
  25. package/src/media-store/forget.ts +54 -0
  26. package/src/media-store/put.ts +4 -3
  27. package/src/media-store/space.ts +63 -24
  28. package/src/recordings/delete.ts +19 -0
  29. package/src/recordings/edit.ts +231 -0
  30. package/src/recordings/load.ts +37 -0
  31. package/src/recordings/marks-draw.ts +111 -0
  32. package/src/recordings/marks-png.ts +25 -0
  33. package/src/recordings/marks.ts +138 -0
  34. package/src/recordings/media-kind.ts +67 -0
  35. package/src/recordings/model.ts +170 -0
  36. package/src/recordings/open.ts +33 -0
  37. package/src/recordings/place.ts +89 -0
  38. package/src/recordings/presets.ts +99 -0
  39. package/src/recordings/recorder-app/Capture.swift +510 -0
  40. package/src/recordings/recorder-app/Clip.swift +107 -0
  41. package/src/recordings/recorder-app/Editor.swift +39 -0
  42. package/src/recordings/recorder-app/Tray.swift +298 -0
  43. package/src/recordings/recorder-app/main.swift +859 -0
  44. package/src/recordings/recorder-app.ts +46 -0
  45. package/src/recordings/recorder.shipkit.ts +11 -0
  46. package/src/recordings/routes.ts +140 -0
  47. package/src/recordings/run-recorder.ts +40 -0
  48. package/src/recordings/share.ts +107 -0
  49. package/src/recordings/take.ts +146 -0
  50. package/src/recordings/view.ts +40 -0
  51. package/src/release/gate-checkout.ts +74 -0
  52. package/src/release/release-scope.ts +35 -26
  53. package/src/release/run-bump.ts +79 -37
  54. package/src/release/run-release.ts +67 -53
  55. package/src/releases/add.ts +7 -2
  56. package/src/releases/from-card.ts +3 -3
  57. package/src/releases/model.ts +29 -7
  58. package/src/repo-config.ts +7 -3
  59. package/src/review/trailer-desk.ts +1 -0
  60. package/src/review/trailer-model.ts +2 -0
  61. package/src/secrets/manager.ts +18 -1
  62. package/src/serve/hub-app/home-st.ts +15 -5
  63. package/src/serve/hub-app/home.html +1 -0
  64. package/src/serve/hub-app/hub-app.tsx +6 -1
  65. package/src/serve/hub-app/icons.tsx +2 -0
  66. package/src/serve/hub-app/palette-st.ts +1 -0
  67. package/src/serve/hub-app/project-list.tsx +1 -0
  68. package/src/serve/hub-app/projects-svc.ts +1 -1
  69. package/src/serve/hub-app/recordings-st.ts +641 -0
  70. package/src/serve/hub-app/recordings-view.tsx +504 -0
  71. package/src/serve/hub-app/recordings.css +82 -0
  72. package/src/serve/hub-app/repo-st.ts +1 -1
  73. package/src/serve/hub-app/review/trailer-page.tsx +1 -0
  74. package/src/serve/hub-app/review/trailer-st.ts +16 -0
  75. package/src/serve/hub-app/review/trailer-timeline.tsx +3 -0
  76. package/src/serve/hub-app/review.css +2 -0
  77. package/src/serve/hub-app/social/post-card.tsx +31 -3
  78. package/src/serve/hub-app/social/social-model.ts +4 -0
  79. package/src/serve/hub-app/social/social-st.ts +12 -0
  80. package/src/serve/hub-app/social.css +4 -0
  81. package/src/shipkit.ts +2 -2
  82. package/src/shot/box.ts +23 -17
  83. package/src/shot/browser-slot.ts +13 -3
  84. package/src/shot/film-box.ts +193 -117
  85. package/src/shot/shooter.ts +5 -3
  86. package/src/smoke/run-smoke.ts +8 -6
  87. package/src/social/compose.ts +14 -0
  88. package/src/social/drafts.ts +1 -1
  89. package/src/social/load.ts +16 -2
  90. package/src/social/publish/index.ts +3 -1
  91. package/src/social/publish/secret.ts +12 -4
  92. package/src/social/release-card.ts +69 -0
  93. package/src/social/release-stage.ts +49 -10
  94. package/src/social/routes.ts +5 -0
  95. package/src/social/stage.ts +9 -5
  96. package/src/trailer/build.ts +24 -0
  97. package/src/trailer/ffmpeg.ts +8 -0
  98. package/src/trailer/grammar.ts +9 -2
  99. package/src/trailer/look.ts +7 -0
  100. package/src/veille/chrome.ts +6 -3
@@ -0,0 +1,231 @@
1
+ // the edit of a recording as text he reads and types (wiki tools/shipkit/recordings.md, The edit): `edit.txt` beside
2
+ // the take, never a change to the take. One line per verb:
3
+ // keep 0:01.5-0:12, 0:15-0:40 the parts that stay, in the take's time (none: all of it)
4
+ // speed 2x 0:20-0:30 a part played faster or slower (in the take's time, inside what is kept)
5
+ // crop 1280x720+40+80 WxH+X+Y of the take's frame
6
+ // mute no sound
7
+ // arrow, rect, text, step, blur the marks drawn on it, each with an optional span (marks.ts)
8
+ // The export is one ffmpeg pass into `out.<ext>`; the hub's editor writes the same text
9
+ import { boundsOf, MARK_VERBS, parseMark, printMark, style, type Mark, type Span } from './marks.ts'
10
+
11
+ export type { Span }
12
+ export type Crop = { w: number; h: number; x: number; y: number }
13
+ export type Edit = { keep: Span[]; speed: (Span & { factor: number })[]; crop: Crop | null; mute: boolean; marks: Mark[] }
14
+
15
+ export const EMPTY_EDIT: Edit = { keep: [], speed: [], crop: null, mute: false, marks: [] }
16
+
17
+ /** `75.5`, `1:15.5` or `0:01:15.5` as seconds */
18
+ export function parseTime(t: string): number {
19
+ if (!/^\d+(:\d{1,2}){0,2}(\.\d+)?$/.test(t)) throw new Error(`${t}: a time is seconds (75.5) or m:ss (1:15.5)`)
20
+ return t.split(':').reduce((acc, p) => acc * 60 + Number(p), 0)
21
+ }
22
+
23
+ /** seconds as `m:ss.s`, the tenth only when there is one */
24
+ export function printTime(s: number): string {
25
+ const tenths = Math.round(s * 10)
26
+ const m = Math.floor(tenths / 600)
27
+ const rest = (tenths - m * 600) / 10
28
+ const ss = rest < 10 ? `0${rest}` : String(rest)
29
+ return `${m}:${ss}`
30
+ }
31
+
32
+ const span = (w: string): Span => {
33
+ const m = /^([\d:.]+)-([\d:.]+)$/.exec(w)
34
+ if (!m) throw new Error(`${w}: a part is <from>-<to>, like 0:01-0:12`)
35
+ const s = { from: parseTime(m[1]!), to: parseTime(m[2]!) }
36
+ if (!(s.to > s.from)) throw new Error(`${w}: it ends before it starts`)
37
+ return s
38
+ }
39
+
40
+ /** the text as an edit; every error names its line */
41
+ export function parseEdit(text: string): Edit {
42
+ const e: Edit = { keep: [], speed: [], crop: null, mute: false, marks: [] }
43
+ text.split('\n').forEach((raw, i) => {
44
+ // a comment starts at a # outside quotes: a text mark may hold one
45
+ const line = raw.replace(/^((?:[^"#]|"(?:[^"\\]|\\.)*")*)#.*$/, '$1').trim()
46
+ if (line === '') return
47
+ const [verb, ...rest] = line.split(/\s+/)
48
+ const at = (msg: string): Error => new Error(`edit line ${i + 1}: ${msg}`)
49
+ try {
50
+ if (verb === 'keep') {
51
+ e.keep.push(...rest.join(' ').split(',').map((w) => w.trim()).filter((w) => w !== '').map(span))
52
+ } else if (verb === 'speed') {
53
+ const f = /^(\d+(?:\.\d+)?)x$/.exec(rest[0] ?? '')
54
+ if (!f || !(Number(f[1]) >= 0.25 && Number(f[1]) <= 16)) throw new Error('speed <factor>x <from>-<to>, the factor 0.25 to 16')
55
+ if (rest.length !== 2) throw new Error('speed <factor>x <from>-<to>')
56
+ e.speed.push({ ...span(rest[1]!), factor: Number(f[1]) })
57
+ } else if (verb === 'crop') {
58
+ const c = /^(\d+)x(\d+)\+(\d+)\+(\d+)$/.exec(rest[0] ?? '')
59
+ if (!c || rest.length !== 1) throw new Error('crop WxH+X+Y, like 1280x720+40+80')
60
+ e.crop = { w: Number(c[1]), h: Number(c[2]), x: Number(c[3]), y: Number(c[4]) }
61
+ } else if (verb === 'mute') {
62
+ if (rest.length > 0) throw new Error('mute takes no word')
63
+ e.mute = true
64
+ } else if ((MARK_VERBS as readonly string[]).includes(verb!)) {
65
+ e.marks.push(parseMark(line, parseTime))
66
+ } else throw new Error(`${verb}: the verbs are keep, speed, crop, mute, ${MARK_VERBS.join(', ')}`)
67
+ } catch (err) {
68
+ throw at((err as Error).message)
69
+ }
70
+ })
71
+ e.keep.sort((a, b) => a.from - b.from)
72
+ for (let i = 1; i < e.keep.length; i++) if (e.keep[i]!.from < e.keep[i - 1]!.to) throw new Error(`keep: ${printTime(e.keep[i]!.from)} overlaps the part before it`)
73
+ e.speed.sort((a, b) => a.from - b.from)
74
+ for (let i = 1; i < e.speed.length; i++) if (e.speed[i]!.from < e.speed[i - 1]!.to) throw new Error(`speed: ${printTime(e.speed[i]!.from)} overlaps the part before it`)
75
+ return e
76
+ }
77
+
78
+ export function printEdit(e: Edit): string {
79
+ const l: string[] = []
80
+ const sp = (s: Span): string => `${printTime(s.from)}-${printTime(s.to)}`
81
+ if (e.keep.length > 0) l.push(`keep ${e.keep.map(sp).join(', ')}`)
82
+ for (const s of e.speed) l.push(`speed ${s.factor}x ${sp(s)}`)
83
+ if (e.crop) l.push(`crop ${e.crop.w}x${e.crop.h}+${e.crop.x}+${e.crop.y}`)
84
+ if (e.mute) l.push('mute')
85
+ for (const m of e.marks) l.push(printMark(m, printTime))
86
+ return l.length === 0 ? '' : `${l.join('\n')}\n`
87
+ }
88
+
89
+ export const isEmpty = (e: Edit): boolean => e.keep.length === 0 && e.speed.length === 0 && e.crop === null && !e.mute && e.marks.length === 0
90
+
91
+ /** the pieces of the take that play, in order, each at its factor: the kept parts cut at every speed change */
92
+ export function pieces(e: Edit, length: number): (Span & { factor: number })[] {
93
+ const keep = e.keep.length === 0 ? [{ from: 0, to: length }] : e.keep.map((k) => ({ from: Math.max(0, k.from), to: Math.min(length, k.to) })).filter((k) => k.to > k.from)
94
+ if (keep.length === 0) throw new Error(`keep: nothing of the take's ${printTime(length)} is kept`)
95
+ const out: (Span & { factor: number })[] = []
96
+ for (const k of keep) {
97
+ const cuts = new Set([k.from, k.to])
98
+ for (const s of e.speed) for (const t of [s.from, s.to]) if (t > k.from && t < k.to) cuts.add(t)
99
+ const ts = [...cuts].sort((a, b) => a - b)
100
+ for (let i = 0; i + 1 < ts.length; i++) {
101
+ const from = ts[i]!
102
+ const to = ts[i + 1]!
103
+ const f = e.speed.find((s) => s.from <= from && s.to >= to)?.factor ?? 1
104
+ out.push({ from, to, factor: f })
105
+ }
106
+ }
107
+ return out
108
+ }
109
+
110
+ /** the length of the export */
111
+ export const editedLength = (e: Edit, length: number): number => pieces(e, length).reduce((a, p) => a + (p.to - p.from) / p.factor, 0)
112
+
113
+ /** atempo takes 0.5 to 100: a slower factor is a chain of halves */
114
+ function atempo(f: number): string {
115
+ const parts: string[] = []
116
+ let rest = f
117
+ while (rest < 0.5) {
118
+ parts.push('atempo=0.5')
119
+ rest /= 0.5
120
+ }
121
+ parts.push(`atempo=${rest}`)
122
+ return parts.join(',')
123
+ }
124
+
125
+ const even = (n: number): number => Math.max(2, Math.floor(n / 2) * 2)
126
+
127
+ /** the crop kept inside the frame, its size even (h264 refuses an odd one) */
128
+ export function fitCrop(c: Crop, w: number, h: number): Crop {
129
+ const x = Math.min(Math.max(0, c.x), w - 2)
130
+ const y = Math.min(Math.max(0, c.y), h - 2)
131
+ return { x, y, w: even(Math.min(c.w, w - x)), h: even(Math.min(c.h, h - y)) }
132
+ }
133
+
134
+ /** the canvas an export draws on, in the take's pixels: the take, grown to hold every drawn mark that reaches past it
135
+ * with a margin (x and y at most 0), its size even (h264 refuses an odd one) */
136
+ export function canvasOf(e: Pick<Edit, 'marks'>, frame: { width: number; height: number }): { x: number; y: number; w: number; h: number } {
137
+ let x0 = 0
138
+ let y0 = 0
139
+ let x1 = frame.width
140
+ let y1 = frame.height
141
+ const st = style(frame)
142
+ const pad = st.stroke * 3
143
+ for (const m of e.marks) {
144
+ if (m.kind === 'blur') continue
145
+ // the mark's own extent (an arrow's two points, a box, a step's disc, a text's estimate): a side grows only where
146
+ // the mark itself goes past the take, then by a margin its stroke and its head fit in
147
+ const b = m.kind === 'arrow' ? { x: Math.min(m.from.x, m.to.x), y: Math.min(m.from.y, m.to.y), w: Math.abs(m.to.x - m.from.x), h: Math.abs(m.to.y - m.from.y) } : boundsOf(m, frame)
148
+ if (b.x < 0) x0 = Math.min(x0, Math.floor(b.x - pad))
149
+ if (b.y < 0) y0 = Math.min(y0, Math.floor(b.y - pad))
150
+ if (b.x + b.w > frame.width) x1 = Math.max(x1, Math.ceil(b.x + b.w + pad))
151
+ if (b.y + b.h > frame.height) y1 = Math.max(y1, Math.ceil(b.y + b.h + pad))
152
+ }
153
+ const w = x1 - x0 + ((x1 - x0) % 2)
154
+ const h = y1 - y0 + ((y1 - y0) % 2)
155
+ return { x: x0, y: y0, w, h }
156
+ }
157
+
158
+ /** the take placed on its canvas, when the canvas grew: transparent around a still, black around a video */
159
+ function grown(input: string, frame: { width: number; height: number }, c: { x: number; y: number; w: number; h: number }, still: boolean): { filters: string[]; out: string } {
160
+ if (c.x === 0 && c.y === 0 && c.w === frame.width && c.h === frame.height) return { filters: [], out: input }
161
+ return { filters: [`[${input}]${still ? 'format=rgba,' : ''}pad=${c.w}:${c.h}:${-c.x}:${-c.y}:color=${still ? '0x00000000' : 'black'}[cv]`], out: 'cv' }
162
+ }
163
+
164
+ /** the box kept inside the frame, its size even and at least 2 */
165
+ const fitBox = (b: Crop, w: number, h: number): Crop => fitCrop(b, w, h)
166
+
167
+ /** the marks burnt into `[in]`, in their order: a drawn mark is the overlay of its PNG (input `inputs[j]`, the whole
168
+ * frame), a blur is its box blurred in place; each only inside its span when it has one, in the take's time, so this
169
+ * runs before any trim. Returns the filters and the label of the result */
170
+ export function markFilters(e: Edit, frame: { width: number; height: number }, input: string, overlayInputs: readonly number[], o: { still?: boolean } = {}): { filters: string[]; out: string } {
171
+ const cv = canvasOf(e, frame)
172
+ const g = grown(input, frame, cv, o.still === true)
173
+ const f: string[] = [...g.filters]
174
+ let cur = g.out
175
+ let j = 0
176
+ e.marks.forEach((m, i) => {
177
+ const en = m.span ? `:enable='between(t,${m.span.from},${m.span.to})'` : ''
178
+ if (m.kind === 'blur') {
179
+ // a blur blurs the take, never the space around it: kept inside the take, placed on the canvas
180
+ const t = fitBox(m.box, frame.width, frame.height)
181
+ const b = { ...t, x: t.x - cv.x, y: t.y - cv.y }
182
+ const r = Math.max(1, Math.min(Math.round(Math.min(frame.width, frame.height) / 60), Math.floor(Math.min(b.w, b.h) / 2) - 1))
183
+ const c = Math.max(1, Math.min(r, Math.floor(Math.min(b.w, b.h) / 4) - 1))
184
+ f.push(`[${cur}]split[ma${i}][mb${i}]`)
185
+ f.push(`[mb${i}]crop=${b.w}:${b.h}:${b.x}:${b.y},boxblur=${r}:3:${c}:3[mc${i}]`)
186
+ f.push(`[ma${i}][mc${i}]overlay=${b.x}:${b.y}${en}[m${i}]`)
187
+ } else {
188
+ f.push(`[${cur}][${overlayInputs[j++]}:v]overlay=0:0${en}[m${i}]`)
189
+ }
190
+ cur = `m${i}`
191
+ })
192
+ return { filters: f, out: cur }
193
+ }
194
+
195
+ /** the marks that are drawn (all but blur), each to its own PNG */
196
+ export const drawnMarks = (e: Edit): number[] => e.marks.flatMap((m, i) => (m.kind === 'blur' ? [] : [i]))
197
+
198
+ /** the crop on the canvas: the take's box moved by the canvas's own place, kept inside it */
199
+ function cropOn(e: Edit, frame: { width: number; height: number }): Crop | null {
200
+ if (!e.crop) return null
201
+ const c = canvasOf(e, frame)
202
+ return fitCrop({ ...e.crop, x: e.crop.x - c.x, y: e.crop.y - c.y }, c.w, c.h)
203
+ }
204
+
205
+ /** ffmpeg's arguments for the export of a video, `-i` to the output; `overlays`: the PNG of each drawn mark, in order */
206
+ export function exportArgs(e: Edit, src: { file: string; seconds: number; width: number; height: number; audio: boolean }, out: string, codec: string[], overlays: readonly string[] = []): string[] {
207
+ const ps = pieces(e, src.seconds)
208
+ const audio = src.audio && !e.mute
209
+ const marked = markFilters(e, src, '0:v', overlays.map((_, k) => k + 1))
210
+ const f: string[] = [...marked.filters]
211
+ const vin = (i: number): string => (ps.length === 1 ? marked.out : `s${i}`)
212
+ if (ps.length > 1) f.push(`[${marked.out}]split=${ps.length}${ps.map((_, i) => `[s${i}]`).join('')}`)
213
+ ps.forEach((p, i) => {
214
+ f.push(`[${vin(i)}]trim=start=${p.from}:end=${p.to},setpts=(PTS-STARTPTS)/${p.factor}[v${i}]`)
215
+ if (audio) f.push(`[0:a]atrim=start=${p.from}:end=${p.to},asetpts=PTS-STARTPTS${p.factor === 1 ? '' : `,${atempo(p.factor)}`}[a${i}]`)
216
+ })
217
+ const ins = ps.map((_, i) => (audio ? `[v${i}][a${i}]` : `[v${i}]`)).join('')
218
+ const crop = cropOn(e, src)
219
+ f.push(`${ins}concat=n=${ps.length}:v=1:a=${audio ? 1 : 0}[vc]${audio ? '[ac]' : ''}`)
220
+ f.push(`[vc]${crop ? `crop=${crop.w}:${crop.h}:${crop.x}:${crop.y},` : ''}format=yuv420p[vo]`)
221
+ return ['-i', src.file, ...overlays.flatMap((o) => ['-i', o]), '-filter_complex', f.join(';'), '-map', '[vo]', ...(audio ? ['-map', '[ac]', '-c:a', 'aac', '-b:a', '160k'] : ['-an']), ...codec, '-movflags', '+faststart', out]
222
+ }
223
+
224
+ /** ffmpeg's arguments for the export of a still: its marks, then its crop, to a png */
225
+ export function stillArgs(e: Edit, src: { file: string; width: number; height: number }, out: string, overlays: readonly string[] = []): string[] {
226
+ if (e.keep.length || e.speed.length || e.mute) throw new Error('a still takes crop and marks only')
227
+ const marked = markFilters(e, src, '0:v', overlays.map((_, k) => k + 1), { still: true })
228
+ const crop = cropOn(e, src)
229
+ const f = [...marked.filters, `[${marked.out}]${crop ? `crop=${crop.w}:${crop.h}:${crop.x}:${crop.y}` : 'null'}[vo]`]
230
+ return ['-i', src.file, ...overlays.flatMap((o) => ['-i', o]), '-filter_complex', f.join(';'), '-map', '[vo]', '-frames:v', '1', '-f', 'image2', '-c:v', 'png', out]
231
+ }
@@ -0,0 +1,37 @@
1
+ // what the recorder app and the hub read of the machine: the presets (the house's, then each repo's own), and the
2
+ // folders a take can be filed under: unassigned first (the default), then every house repo. The app's pick lasts
3
+ // until it restarts, never longer
4
+ import { homedir } from 'node:os'
5
+ import { basename } from 'node:path'
6
+ import { UNASSIGNED } from './place.ts'
7
+ import { mergePresets, type NamedPreset } from './presets.ts'
8
+
9
+ export type RecorderState = { presets: NamedPreset[]; problems: string[]; repos: string[]; repo: string; home: string | null }
10
+
11
+
12
+ /** the house repos and every preset, read from their configs side by side */
13
+ export async function recorderState(cwd = process.cwd()): Promise<RecorderState> {
14
+ const { houseRoot } = await import('../home/home-start.ts')
15
+ const { loadRepoConfig } = await import('../repo-config.ts')
16
+ const { houseRepos } = await import('../serve/project-gutter.ts')
17
+ const { homeUrl } = await import('../home/home-paths.ts')
18
+ const house = houseRoot(cwd)
19
+ const repos = house ? houseRepos(house, homedir()).repos.map((r) => r.path) : []
20
+ const broken: string[] = []
21
+ // a repo whose config does not load keeps its presets out of the menu, said in the problems
22
+ const read = async (root: string) =>
23
+ (
24
+ await loadRepoConfig(root).catch((e: Error) => {
25
+ broken.push(`${basename(root)}: its repo.config.ts does not load, so its presets are left out: ${e.message}`)
26
+ return null
27
+ })
28
+ )?.recorder
29
+ const own = house ? (await loadRepoConfig(house)).recorder : undefined
30
+ const others = repos.filter((r) => r !== house)
31
+ const each = await Promise.all(others.map(read))
32
+ const merged = mergePresets(own, others.map((root, i) => ({ root, recorder: each[i] })))
33
+ const { presets } = merged
34
+ const problems = [...broken, ...merged.problems]
35
+ const names = [UNASSIGNED, ...repos.map((r) => basename(r)).sort()]
36
+ return { presets, problems, repos: names, repo: UNASSIGNED, home: house ? homeUrl() : null }
37
+ }
@@ -0,0 +1,111 @@
1
+ // a mark drawn on a 2D canvas, the ONE drawing of every mark: the page draws its preview with it on a browser canvas,
2
+ // the export draws the PNG it burns in with it on @napi-rs/canvas, so what he sees is what ships. Blur is no drawing
3
+ // (ffmpeg blurs the box): here it is only a dashed frame, for the page
4
+ import { HEX, stepNumber, style, type Mark, type Pt } from './marks.ts'
5
+
6
+ /** what both canvases offer that the marks use */
7
+ export interface Ctx2D {
8
+ lineWidth: number
9
+ lineCap: string
10
+ lineJoin: string
11
+ strokeStyle: unknown
12
+ fillStyle: unknown
13
+ font: string
14
+ textBaseline: string
15
+ textAlign: string
16
+ beginPath(): void
17
+ moveTo(x: number, y: number): void
18
+ lineTo(x: number, y: number): void
19
+ closePath(): void
20
+ stroke(): void
21
+ fill(): void
22
+ arc(x: number, y: number, r: number, a: number, b: number): void
23
+ strokeRect(x: number, y: number, w: number, h: number): void
24
+ fillText(t: string, x: number, y: number): void
25
+ strokeText(t: string, x: number, y: number): void
26
+ setLineDash(d: number[]): void
27
+ save(): void
28
+ restore(): void
29
+ }
30
+
31
+ const FONT = '600 {px}px -apple-system, "Helvetica Neue", Helvetica, Arial, sans-serif'
32
+
33
+ /** the arrow's head: a filled triangle whose tip is the point, sized from the stroke */
34
+ function head(ctx: Ctx2D, from: Pt, to: Pt, stroke: number): Pt {
35
+ const a = Math.atan2(to.y - from.y, to.x - from.x)
36
+ const len = stroke * 4.5
37
+ const wide = stroke * 2.6
38
+ const back = { x: to.x - Math.cos(a) * len, y: to.y - Math.sin(a) * len }
39
+ ctx.beginPath()
40
+ ctx.moveTo(to.x, to.y)
41
+ ctx.lineTo(back.x + Math.sin(a) * wide, back.y - Math.cos(a) * wide)
42
+ ctx.lineTo(back.x - Math.sin(a) * wide, back.y + Math.cos(a) * wide)
43
+ ctx.closePath()
44
+ ctx.fill()
45
+ return back
46
+ }
47
+
48
+ /** the mark at `i` of `marks` in the take's pixels (a step counts the steps before it) */
49
+ export function drawMark(ctx: Ctx2D, marks: readonly Mark[], i: number, frame: { width: number; height: number }, o: { preview?: boolean } = {}): void {
50
+ const m = marks[i]!
51
+ const s = style(frame)
52
+ ctx.save()
53
+ ctx.lineCap = 'round'
54
+ ctx.lineJoin = 'round'
55
+ if (m.kind === 'blur') {
56
+ if (o.preview) {
57
+ ctx.setLineDash([s.stroke * 2, s.stroke * 2])
58
+ ctx.lineWidth = Math.max(2, s.stroke / 2)
59
+ ctx.strokeStyle = '#ffffff'
60
+ ctx.strokeRect(m.box.x, m.box.y, m.box.w, m.box.h)
61
+ }
62
+ ctx.restore()
63
+ return
64
+ }
65
+ const color = HEX[m.color]
66
+ // a dark edge under every mark: it reads on a white page and on a dark one
67
+ const edge = m.color === 'black' ? 'rgba(255,255,255,0.8)' : 'rgba(0,0,0,0.45)'
68
+ if (m.kind === 'arrow') {
69
+ for (const [w, c] of [[s.stroke + 2, edge], [s.stroke, color]] as const) {
70
+ ctx.strokeStyle = c
71
+ ctx.fillStyle = c
72
+ ctx.lineWidth = w
73
+ const back = head(ctx, m.from, m.to, s.stroke)
74
+ ctx.beginPath()
75
+ ctx.moveTo(m.from.x, m.from.y)
76
+ ctx.lineTo(back.x, back.y)
77
+ ctx.stroke()
78
+ }
79
+ } else if (m.kind === 'rect') {
80
+ for (const [w, c] of [[s.stroke + 2, edge], [s.stroke, color]] as const) {
81
+ ctx.strokeStyle = c
82
+ ctx.lineWidth = w
83
+ ctx.strokeRect(m.box.x, m.box.y, m.box.w, m.box.h)
84
+ }
85
+ } else if (m.kind === 'text') {
86
+ const size = m.size ?? s.text
87
+ ctx.font = FONT.replace('{px}', String(size))
88
+ ctx.textBaseline = 'top'
89
+ ctx.textAlign = 'left'
90
+ ctx.lineWidth = Math.max(3, size / 7)
91
+ ctx.strokeStyle = edge
92
+ ctx.strokeText(m.text, m.at.x, m.at.y)
93
+ ctx.fillStyle = color
94
+ ctx.fillText(m.text, m.at.x, m.at.y)
95
+ } else {
96
+ const n = String(stepNumber(marks, i))
97
+ ctx.fillStyle = color
98
+ ctx.beginPath()
99
+ ctx.arc(m.at.x, m.at.y, s.step, 0, Math.PI * 2)
100
+ ctx.fill()
101
+ ctx.lineWidth = Math.max(2, s.step / 8)
102
+ ctx.strokeStyle = '#ffffff'
103
+ ctx.stroke()
104
+ ctx.fillStyle = m.color === 'white' || m.color === 'yellow' ? '#111111' : '#ffffff'
105
+ ctx.font = FONT.replace('{px}', String(Math.round(s.step * 1.15)))
106
+ ctx.textBaseline = 'middle'
107
+ ctx.textAlign = 'center'
108
+ ctx.fillText(n, m.at.x, m.at.y + s.step * 0.06)
109
+ }
110
+ ctx.restore()
111
+ }
@@ -0,0 +1,25 @@
1
+ // each drawn mark of an edit as a PNG the size of the frame, transparent but for the mark: the export overlays them
2
+ // in order, each inside its span. Drawn by marks-draw.ts, the same drawing the page previews
3
+ import { join } from 'node:path'
4
+ import type { Edit } from './edit.ts'
5
+ import { canvasOf, drawnMarks } from './edit.ts'
6
+ import { drawMark, type Ctx2D } from './marks-draw.ts'
7
+
8
+ export async function markPngs(e: Edit, frame: { width: number; height: number }, dir: string): Promise<string[]> {
9
+ const idx = drawnMarks(e)
10
+ if (idx.length === 0) return []
11
+ const { createCanvas } = await import('@napi-rs/canvas')
12
+ const out: string[] = []
13
+ // each PNG is the whole canvas: the take's place on it moved by the canvas's own corner
14
+ const cv = canvasOf(e, frame)
15
+ for (const i of idx) {
16
+ const c = createCanvas(cv.w, cv.h)
17
+ const ctx = c.getContext('2d')
18
+ ctx.translate(-cv.x, -cv.y)
19
+ drawMark(ctx as unknown as Ctx2D, e.marks, i, frame)
20
+ const file = join(dir, `.mark-${i}.png`)
21
+ await Bun.write(file, await c.encode('png'))
22
+ out.push(file)
23
+ }
24
+ return out
25
+ }
@@ -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 })])