rvlib-shipkit 2.18.0 → 2.19.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 +15 -0
- package/package.json +1 -1
- package/src/asks/asks-queue.ts +63 -10
- package/src/cli/cmd_Asks.ts +3 -1
- package/src/cli/cmd_GlobalProcesses.ts +34 -11
- package/src/cli/cmd_Home.ts +38 -2
- package/src/cli/cmd_Secret.ts +4 -30
- package/src/cli/cmd_Social.ts +40 -1
- package/src/cli/cmd_Trailer.ts +15 -3
- package/src/cli/registry.ts +2 -1
- package/src/collections/actions.ts +29 -1
- package/src/collections/collection-types.ts +2 -0
- package/src/collections/providers.ts +1 -1
- package/src/home/home-paths.ts +5 -1
- package/src/home/home-start.ts +12 -12
- package/src/home/run-daemon.ts +11 -2
- package/src/home/run-pm.ts +9 -1
- package/src/home/supervise.ts +3 -1
- package/src/identities/identities.ts +22 -5
- package/src/review/http.ts +7 -2
- package/src/review/store.ts +81 -19
- package/src/secrets/manager.ts +59 -0
- package/src/secrets/name.ts +2 -0
- package/src/serve/hub-app/col-card.tsx +10 -0
- package/src/serve/hub-app/cols-svc.ts +37 -6
- package/src/serve/hub-app/hub.css +1 -0
- package/src/serve/hub-app/social/identity-pictures.ts +74 -0
- package/src/serve/hub-app/social/social-page.tsx +77 -37
- package/src/serve/hub-app/social.css +8 -3
- package/src/serve/serve-hub.ts +12 -2
- package/src/social/discord-layout.ts +239 -0
- package/src/social/md.ts +14 -6
- package/src/social/publish/discord.ts +3 -2
- package/src/social/routes.ts +3 -3
- package/src/stores/routes.ts +2 -2
- package/src/suite/judge-suites.ts +1 -1
- package/src/suite/suite-cli.ts +5 -5
- package/src/trailer/build.ts +75 -50
- package/src/trailer/draft.ts +28 -0
- package/src/trailer/footage.ts +4 -2
- package/src/trailer/grammar.ts +11 -9
- package/src/trailer/graph.ts +32 -9
- package/src/trailer/profile.ts +35 -0
- package/src/trailer/prune.ts +15 -10
- package/src/trailer/stitch.ts +22 -10
- package/src/trailer/titles.ts +47 -2
package/src/suite/suite-cli.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
|
-
// the floor `test` slot for a plain `bun test` script:
|
|
3
|
-
//
|
|
2
|
+
// the floor `test` slot for a plain `bun test` script: every suite in parallel
|
|
3
|
+
// workers (the full tier adds the slow ones), the declared serial ones after,
|
|
4
4
|
// and each quick tier suite timed against the budget.
|
|
5
5
|
// The LAST stdout line is the task headline the gate prints, and it keeps bun's
|
|
6
6
|
// `Ran N tests` so the gate can still report what ran.
|
|
@@ -124,9 +124,9 @@ async function runSuites(argv: string[], ctx: SelectCtx): Promise<number> {
|
|
|
124
124
|
|
|
125
125
|
const help = Bun.spawnSync(['bun', 'test', '--help'], { stdout: 'pipe', stderr: 'pipe' })
|
|
126
126
|
const helpText = `${help.stdout.toString()}${help.stderr.toString()}`
|
|
127
|
-
// the full tier
|
|
128
|
-
//
|
|
129
|
-
const parallel = helpText.includes('--parallel')
|
|
127
|
+
// both tiers share workers: the full tier adds the slow suites to the parallel phase, and a suite that cannot
|
|
128
|
+
// share a run is named in tests.serial
|
|
129
|
+
const parallel = helpText.includes('--parallel')
|
|
130
130
|
const timed = helpText.includes('--update-timings')
|
|
131
131
|
// bun drops these the moment any ignore reaches its command line
|
|
132
132
|
const bunfig = bunfigTest(existsSync('bunfig.toml') ? readFileSync('bunfig.toml', 'utf8') : null)
|
package/src/trailer/build.ts
CHANGED
|
@@ -14,6 +14,8 @@ import type { TitleMotion } from './motion.ts'
|
|
|
14
14
|
import type { TitleRequest } from './titles.ts'
|
|
15
15
|
import type { Stitched } from './stitch.ts'
|
|
16
16
|
import { projectCli, readVocab } from './vocab.ts'
|
|
17
|
+
import { timed } from './profile.ts'
|
|
18
|
+
import type { Draft } from './draft.ts'
|
|
17
19
|
|
|
18
20
|
export type Say = (line: string) => void
|
|
19
21
|
|
|
@@ -458,6 +460,10 @@ export interface BuildOptions {
|
|
|
458
460
|
final: boolean
|
|
459
461
|
say: Say
|
|
460
462
|
cwd: string
|
|
463
|
+
/** a draft of the cut (draft.ts): smaller, quicker, its own mp4, no strip unless `strip` */
|
|
464
|
+
draft?: Draft
|
|
465
|
+
/** the strip of a draft too */
|
|
466
|
+
strip?: boolean
|
|
461
467
|
}
|
|
462
468
|
|
|
463
469
|
/** the shots `names` names and the cells their grids and splits read: what a preview films */
|
|
@@ -476,16 +482,16 @@ async function browserLanes(root: string): Promise<number> {
|
|
|
476
482
|
}
|
|
477
483
|
|
|
478
484
|
/** film the takes missing (and what --refilm names), as many at once as the repo's browser cap; every shot is tried,
|
|
479
|
-
* the failures said together */
|
|
480
|
-
async function filmAll(l: Loaded, world: World, refilm: Refilm, say: Say, only?: ReadonlySet<string
|
|
481
|
-
const { filmTake } = await import('./footage.ts')
|
|
482
|
-
const takes = takesOfLoaded(l)
|
|
485
|
+
* the failures said together. A draft's (`small`, the draft's trailer) reads the cut's own takes and films the rest small */
|
|
486
|
+
async function filmAll(l: Loaded, world: World, refilm: Refilm, say: Say, only?: ReadonlySet<string>, small?: Trailer): Promise<Take[]> {
|
|
487
|
+
const [{ filmTake, takesOf }, { draftTakes }] = await Promise.all([import('./footage.ts'), import('./draft.ts')])
|
|
488
|
+
const takes = small ? draftTakes(takesOfLoaded(l), takesOf(small, l.root, l), world, refilm) : takesOfLoaded(l)
|
|
483
489
|
const ask = takesToFilm(takes, world, refilm, only)
|
|
484
490
|
const failed: string[] = []
|
|
485
491
|
const lane = async (): Promise<void> => {
|
|
486
492
|
for (let group = ask.shift(); group; group = ask.shift()) {
|
|
487
493
|
try {
|
|
488
|
-
const got = await filmTake(group[0]!, { root: l.root, t: l.t, world: worldFor(world, group[0]!), cli: l.cli, holes: l.unit?.holes === true, say })
|
|
494
|
+
const got = await timed(`film ${group[0]!.shot.name}`, () => filmTake(group[0]!, { root: l.root, t: small ?? l.t, world: worldFor(world, group[0]!), cli: l.cli, holes: l.unit?.holes === true, draft: small !== undefined, say }))
|
|
489
495
|
for (const tk of group) {
|
|
490
496
|
const i = takes.indexOf(tk)
|
|
491
497
|
takes[i] = { ...tk, stamp: got.stamp }
|
|
@@ -528,8 +534,32 @@ export async function scoreFile(l: Loaded, seconds: number, say: Say): Promise<s
|
|
|
528
534
|
return w.file
|
|
529
535
|
}
|
|
530
536
|
|
|
531
|
-
/**
|
|
532
|
-
async function
|
|
537
|
+
/** every sound the shots play, made where the house or the unit has to: the music cues, each shot's sfx and voices */
|
|
538
|
+
async function soundsOf(l: Loaded, shots: readonly Shot[], say: Say) {
|
|
539
|
+
const { durationOf } = await import('./ffmpeg.ts')
|
|
540
|
+
const resolve = (req: SoundRequest): Promise<string> => soundFile(l, req, say)
|
|
541
|
+
const ask = (kind: SoundRequest['kind'], text: string, x: { prompt?: true; gen?: SoundGen; run?: SoundRun; line: number }, seconds?: number, take?: string): SoundRequest => soundRequest(kind, text, x, l.dir, seconds, take)
|
|
542
|
+
const music = await timed('sounds', () => Promise.all(
|
|
543
|
+
musicCues(l.t).map(({ cue, at, end }) => {
|
|
544
|
+
if (cue.song === SCORE) return scoreFile(l, cue.from + end - at, say)
|
|
545
|
+
const seconds = cue.from + end - at
|
|
546
|
+
if (isFileSound(cue.song, cue)) return cue.song.endsWith('.mid') ? resolve(ask('music', fileOf(cue.song, l)!, cue, seconds)) : fileOf(cue.song, l)!
|
|
547
|
+
return resolve(ask('music', cue.song, cue, seconds, cue.take))
|
|
548
|
+
}),
|
|
549
|
+
))
|
|
550
|
+
const sfx = await Promise.all(shots.map((s) => Promise.all(s.sfx.map(async (x) => {
|
|
551
|
+
const file = isFileSound(x.id, x) ? fileOf(x.id, l)! : await resolve(ask('sfx', x.id, x))
|
|
552
|
+
return { file, seconds: await durationOf(file) }
|
|
553
|
+
}))))
|
|
554
|
+
const voices = await Promise.all(shots.map((s) => Promise.all(s.voices.map(async (v) => {
|
|
555
|
+
const file = v.file ? fileOf(v.file, l)! : await resolve(ask('voice', v.text ?? 'run', v))
|
|
556
|
+
return { file, seconds: await durationOf(file) }
|
|
557
|
+
}))))
|
|
558
|
+
return { music, sfx, voices }
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/** everything the stitch reads but its output: sources, titles, sounds (`sounds` when the caller started them), the look */
|
|
562
|
+
async function stitchInput(l: Loaded, takes: readonly Take[], shots: readonly Shot[], silent: boolean, say: Say = () => undefined, sounds?: ReturnType<typeof soundsOf>) {
|
|
533
563
|
const { gridMask, splitMasks } = await import('./stitch.ts')
|
|
534
564
|
const [{ cardPng, titlePng }, { lookOf }, { durationOf }, { trailerCache }, { loadBrand, identityLogo }] = await Promise.all([
|
|
535
565
|
import('./titles.ts'),
|
|
@@ -569,27 +599,9 @@ async function stitchInput(l: Loaded, takes: readonly Take[], shots: readonly Sh
|
|
|
569
599
|
const styleErrors = resolveStyles(l.t, brand?.trailer?.styles ?? {})
|
|
570
600
|
if (styleErrors.length > 0) throw new Refused(styleErrors.map((e) => `${relative(l.root, l.file)}:${e.line}: ${e.message}`).join('\n'))
|
|
571
601
|
const motions = titleMotions({ ...l.t, shots: [...shots] })
|
|
572
|
-
const drawn = await Promise.all(shots.map((s, i) => Promise.all(s.titles.map(async (ti, j) => titlePng(titles, { ...titleRequest(l, ti, look, motions[i]![j]!), font: await titleFont(l, ti) })))))
|
|
602
|
+
const drawn = await timed('titles', () => Promise.all(shots.map((s, i) => Promise.all(s.titles.map(async (ti, j) => titlePng(titles, { ...titleRequest(l, ti, look, motions[i]![j]!), font: await titleFont(l, ti) }))))))
|
|
573
603
|
if (silent) return { ...base, sources, titles: drawn, music: [], sfx: shots.map(() => []), voices: shots.map(() => []) }
|
|
574
|
-
|
|
575
|
-
const ask = (kind: SoundRequest['kind'], text: string, x: { prompt?: true; gen?: SoundGen; run?: SoundRun; line: number }, seconds?: number, take?: string): SoundRequest => soundRequest(kind, text, x, l.dir, seconds, take)
|
|
576
|
-
const music = await Promise.all(
|
|
577
|
-
musicCues(l.t).map(({ cue, at, end }) => {
|
|
578
|
-
if (cue.song === SCORE) return scoreFile(l, cue.from + end - at, say)
|
|
579
|
-
const seconds = cue.from + end - at
|
|
580
|
-
if (isFileSound(cue.song, cue)) return cue.song.endsWith('.mid') ? resolve(ask('music', fileOf(cue.song, l)!, cue, seconds)) : fileOf(cue.song, l)!
|
|
581
|
-
return resolve(ask('music', cue.song, cue, seconds, cue.take))
|
|
582
|
-
}),
|
|
583
|
-
)
|
|
584
|
-
const sfx = await Promise.all(shots.map((s) => Promise.all(s.sfx.map(async (x) => {
|
|
585
|
-
const file = isFileSound(x.id, x) ? fileOf(x.id, l)! : await resolve(ask('sfx', x.id, x))
|
|
586
|
-
return { file, seconds: await durationOf(file) }
|
|
587
|
-
}))))
|
|
588
|
-
const voices = await Promise.all(shots.map((s) => Promise.all(s.voices.map(async (v) => {
|
|
589
|
-
const file = v.file ? fileOf(v.file, l)! : await resolve(ask('voice', v.text ?? 'run', v))
|
|
590
|
-
return { file, seconds: await durationOf(file) }
|
|
591
|
-
}))))
|
|
592
|
-
return { ...base, sources, titles: drawn, music, sfx, voices }
|
|
604
|
+
return { ...base, sources, titles: drawn, ...(await (sounds ?? soundsOf(l, shots, say))) }
|
|
593
605
|
}
|
|
594
606
|
|
|
595
607
|
/** a vertical cut finished: what the brand's vertical look draws over the stitched cut, the outro, the end card. The
|
|
@@ -671,38 +683,51 @@ async function pruneAfter(root: string, say: Say): Promise<void> {
|
|
|
671
683
|
/** the whole cut: out/<cut>.mp4, its strip, montage page and shelf of takes; the timeline and what was rendered, said */
|
|
672
684
|
export async function build(l: Loaded, o: BuildOptions): Promise<string> {
|
|
673
685
|
const t0 = performance.now()
|
|
674
|
-
const [{ trailerCache }, { stitch, strip, rendered }, { ffmpegMissing }] = await Promise.all([import('./footage.ts'), import('./stitch.ts'), import('./ffmpeg.ts')])
|
|
686
|
+
const [{ trailerCache }, { stitch, strip, rendered, renderMix }, { ffmpegMissing }] = await Promise.all([import('./footage.ts'), import('./stitch.ts'), import('./ffmpeg.ts')])
|
|
675
687
|
const missing = ffmpegMissing()
|
|
676
688
|
if (missing) throw new Refused(missing)
|
|
677
|
-
|
|
678
|
-
const
|
|
679
|
-
|
|
689
|
+
// the sound reads no take: it is made and mixed while the takes film, off the stitch's path
|
|
690
|
+
const sounds = soundsOf(l, l.t.shots, o.say)
|
|
691
|
+
const mixing = timed('the sound mixed', async () => renderMix({ t: l.t, ...(await sounds), cache: trailerCache(l.root, 'pieces') }))
|
|
692
|
+
// a take that fails throws first: the sound's own failure is said where the stitch awaits it
|
|
693
|
+
mixing.catch(() => undefined)
|
|
694
|
+
const world = await timed('world', () => worldOf(l))
|
|
695
|
+
// a draft draws the picture of its own smaller trailer (draft.ts); the sound stays the cut's
|
|
696
|
+
const small = o.draft ? (await import('./draft.ts')).draftOf(l.t, o.draft) : undefined
|
|
697
|
+
const lv: Loaded = small ? { ...l, t: small } : l
|
|
698
|
+
const takes = await timed('filming', () => filmAll(l, world, o.refilm, o.say, undefined, small))
|
|
699
|
+
// the shelf is what `keep` clones: a draft never writes it
|
|
700
|
+
if (!small) await timed('shelve', () => shelve(l, takes))
|
|
680
701
|
const tFilm = performance.now()
|
|
681
|
-
const input = await stitchInput(
|
|
682
|
-
const out = join(outDir(l), `${
|
|
702
|
+
const input = await timed('stitch input (sources, titles, sounds)', () => stitchInput(lv, takes, lv.t.shots, false, o.say, sounds))
|
|
703
|
+
const out = join(outDir(l), `${lv.t.name}.mp4`)
|
|
683
704
|
// a vertical cut stitches into the cache, and its finish writes the mp4
|
|
684
|
-
const cut =
|
|
685
|
-
const
|
|
686
|
-
const
|
|
687
|
-
const
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
705
|
+
const cut = lv.t.vertical ? join(trailerCache(l.root, 'pieces'), `${lv.t.name}-cut.mp4`) : out
|
|
706
|
+
const withStrip = !small || o.strip === true
|
|
707
|
+
const done = await timed('stitch', () => stitch({ ...input, t: lv.t, out: cut, cache: trailerCache(l.root, 'pieces'), encoder: o.final ? 'final' : 'draft', mixing, thumbs: withStrip }))
|
|
708
|
+
const finished = lv.t.vertical ? await finishVertical(lv, input, done, cut, out, o.final) : null
|
|
709
|
+
const stripFile = join(outDir(l), `${lv.t.name}.strip.png`)
|
|
710
|
+
if (withStrip) {
|
|
711
|
+
// the strip is drawn from the pieces' thumbs: the same pieces draw the same strip, so a build that rendered no
|
|
712
|
+
// section keeps it
|
|
713
|
+
const stripKey = join(trailerCache(l.root, 'pieces'), `${lv.t.name}.strip.key`)
|
|
714
|
+
const key = done.pieces.map((p) => p.thumbs).join('\n')
|
|
715
|
+
const drawn = (): string => `${key}\n${statSync(stripFile).mtimeMs}`
|
|
716
|
+
if (!existsSync(stripFile) || !existsSync(stripKey) || readFileSync(stripKey, 'utf8') !== drawn()) {
|
|
717
|
+
await timed('strip', () => strip(done.pieces, stripFile))
|
|
718
|
+
writeFileSync(stripKey, drawn())
|
|
719
|
+
}
|
|
696
720
|
}
|
|
697
|
-
writeFileSync(join(outDir(l), `${l.t.name}.montage.md`), montage(l.t, basename(l.file)))
|
|
721
|
+
if (!small) writeFileSync(join(outDir(l), `${l.t.name}.montage.md`), montage(l.t, basename(l.file)))
|
|
698
722
|
for (const line of timeline(l, takes, world, o.cwd)) o.say(line)
|
|
699
|
-
|
|
700
|
-
o.say(`ok: ${
|
|
723
|
+
const what = small ? `a draft at ${small.size.join('x')}, ` : ''
|
|
724
|
+
o.say(`ok: ${out} (${what}${(finished?.seconds ?? total(lv.t)).toFixed(2)} s) in ${((performance.now() - t0) / 1000).toFixed(1)} s: filming ${((tFilm - t0) / 1000).toFixed(1)} s, ${rendered(done)}${finished ? `, ${finished.note}` : ''}`)
|
|
725
|
+
if (withStrip) o.say(`ok: ${stripFile}`)
|
|
701
726
|
// the vertical's finish can lay an outro's own sound after the mix: its mp4 is what is measured then
|
|
702
727
|
const heard = finished ? out : done.mix
|
|
703
728
|
if (heard) {
|
|
704
729
|
const [{ loudness, loudnessKept }, { MIX_TRUE_PEAK }] = await Promise.all([import('./ffmpeg.ts'), import('./graph.ts')])
|
|
705
|
-
const { lufs, truePeak } = await (finished ? loudness(heard) : loudnessKept(heard))
|
|
730
|
+
const { lufs, truePeak } = await timed('the mix measured', () => (finished ? loudness(heard) : loudnessKept(heard)))
|
|
706
731
|
const { master } = l.t
|
|
707
732
|
const line = `the mix: ${lufs.toFixed(1)} LUFS integrated${master === null ? '' : ` (master ${master})`}, true peak ${truePeak.toFixed(1)} dBTP`
|
|
708
733
|
if (truePeak > 0) refuse(`${line}, past 0 dBTP: it clips on a player. ${out} is written; lower the loudest sounds (a score's volume, a sfx or voice volume)`)
|
|
@@ -711,7 +736,7 @@ export async function build(l: Loaded, o: BuildOptions): Promise<string> {
|
|
|
711
736
|
else if (Math.abs(off) > 0.5) o.say(`WARN ${line}, ${Math.abs(off).toFixed(1)} LU ${off < 0 ? 'under' : 'over'} its master, past what one gain into the ${MIX_TRUE_PEAK} dBTP limiter reaches (its loudest sound held down while the rest stays quiet)`)
|
|
712
737
|
else o.say(`ok: ${line}`)
|
|
713
738
|
}
|
|
714
|
-
await pruneAfter(l.root, o.say)
|
|
739
|
+
await timed('prune', () => pruneAfter(l.root, o.say))
|
|
715
740
|
return out
|
|
716
741
|
}
|
|
717
742
|
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// a cut's draft (`sk trailer --draft`): the same cut, smaller and quicker, to judge its beats. It reads every take the
|
|
2
|
+
// cut has filmed as it is and films a missing one small, under a key of its own (a take's key holds its size), so a
|
|
3
|
+
// draft take never stands in a full build or a kept version. Its rate stays the cut's: every take decodes each of its
|
|
4
|
+
// frames anyway, and a rate converted down made the stitch slower (8.3 s at 30 fps, 11.9 s at 15 on a 74 s cut). Its
|
|
5
|
+
// sound is the cut's own mix, its pieces render under `<name>-draft-<section>`, its mp4 is `out/<name>-draft.mp4`
|
|
6
|
+
import { type Refilm, type Take, takesToFilm, type World } from './plan.ts'
|
|
7
|
+
import type { Trailer } from './grammar.ts'
|
|
8
|
+
|
|
9
|
+
/** how a draft is smaller than its cut: each side scaled */
|
|
10
|
+
export interface Draft {
|
|
11
|
+
scale: number
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const DRAFT: Draft = { scale: 0.5 }
|
|
15
|
+
|
|
16
|
+
/** the name a draft's pieces, takes and mp4 go under */
|
|
17
|
+
export const draftName = (name: string): string => `${name}-draft`
|
|
18
|
+
|
|
19
|
+
/** the cut as its draft draws it: its size scaled (even sides, as H.264 takes), its own name */
|
|
20
|
+
export function draftOf<T extends Pick<Trailer, 'name' | 'size'>>(t: T, d: Draft = DRAFT): T {
|
|
21
|
+
const even = (x: number): number => Math.max(2, 2 * Math.round((x * d.scale) / 2))
|
|
22
|
+
return { ...t, name: draftName(t.name), size: [even(t.size[0]), even(t.size[1])] }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** the takes a draft reads: the cut's own wherever it has one the build would not film again, else the draft's */
|
|
26
|
+
export function draftTakes(full: readonly Take[], small: readonly Take[], world: World, refilm: Refilm): Take[] {
|
|
27
|
+
return full.map((tk, i) => (takesToFilm([tk], world, refilm).length === 0 ? tk : small[i]!))
|
|
28
|
+
}
|
package/src/trailer/footage.ts
CHANGED
|
@@ -122,6 +122,8 @@ export interface FilmContext {
|
|
|
122
122
|
cli: readonly string[] | null
|
|
123
123
|
/** a clip take that drops its picture is filmed again once, then refused (the unit's `holes`) */
|
|
124
124
|
holes?: boolean
|
|
125
|
+
/** a draft's take (draft.ts): `t` is the draft's size and rate, and the row is told so */
|
|
126
|
+
draft?: boolean
|
|
125
127
|
say: (line: string) => void
|
|
126
128
|
}
|
|
127
129
|
|
|
@@ -167,8 +169,8 @@ export async function filmTake(tk: Take, c: FilmContext): Promise<Take> {
|
|
|
167
169
|
async function commandTake(tk: Take, f: Exclude<TakeFilm, { kind: 'url' | 'page' }>, part: string, seconds: number | null, c: FilmContext): Promise<string> {
|
|
168
170
|
if (f.kind === 'cli' && c.cli === null) throw new Error(`shot ${tk.shot.name} (line ${f.line}): film ${f.argv.join(' ')} needs the project CLI (the cli script of package.json)`)
|
|
169
171
|
const argv = f.kind === 'run' ? ['sh', '-c', runCommand(f, { out: part, seconds, size: c.t.size, fps: c.t.fps })] : cliArgv(c.cli!, f, part, seconds, tk.argv)
|
|
170
|
-
// the cut's frame and rate: a row that films at the cut's size reads them
|
|
171
|
-
const env = { ...process.env, SK_TRAILER_SIZE: `${c.t.size[0]}x${c.t.size[1]}`, SK_TRAILER_FPS: String(c.t.fps) }
|
|
172
|
+
// the cut's frame and rate: a row that films at the cut's size reads them; a draft's row may film smaller and quicker
|
|
173
|
+
const env = { ...process.env, SK_TRAILER_SIZE: `${c.t.size[0]}x${c.t.size[1]}`, SK_TRAILER_FPS: String(c.t.fps), ...(c.draft ? { SK_TRAILER_DRAFT: '1' } : {}) }
|
|
172
174
|
const p = Bun.spawn(argv, { cwd: c.root, stdout: 'pipe', stderr: 'pipe', env })
|
|
173
175
|
const [out, err, code] = await Promise.all([new Response(p.stdout).text(), new Response(p.stderr).text(), p.exited])
|
|
174
176
|
const said = `${out}${err}`.trim()
|
package/src/trailer/grammar.ts
CHANGED
|
@@ -147,8 +147,8 @@ export interface Title {
|
|
|
147
147
|
/** null: to the shot's end */
|
|
148
148
|
for: number | null
|
|
149
149
|
style: TitleStyle
|
|
150
|
-
/** where a caption sits: the bottom by default */
|
|
151
|
-
place?:
|
|
150
|
+
/** where a caption sits: the bottom by default; `middle` centres a big title on both axes */
|
|
151
|
+
place?: TitlePlace
|
|
152
152
|
/** knocked off the frame from this second of its shot: it tips and flies out */
|
|
153
153
|
knock?: number
|
|
154
154
|
/** a `progress` line's step: the i-th of n notches filled under its name */
|
|
@@ -186,18 +186,20 @@ export interface TitleFx {
|
|
|
186
186
|
glow?: { px: number; color?: string }
|
|
187
187
|
/** the widest share of the frame's width the word takes */
|
|
188
188
|
fit?: number
|
|
189
|
-
/** the subtitle's height to the word's */
|
|
189
|
+
/** the subtitle's height to the word's (a big title: its lines after the first break, to the first's) */
|
|
190
190
|
sub?: number
|
|
191
191
|
/** the space between the word and its subtitle, a share of the word's height */
|
|
192
192
|
gap?: number
|
|
193
193
|
/** the word's middle at this share of the frame's height (default: the whole block's middle at 0.48) */
|
|
194
194
|
middle?: number
|
|
195
|
-
/** the soft shade round the logo, its radius a share of the frame's longer side; 0 for none
|
|
195
|
+
/** the soft shade round the logo, its radius a share of the frame's longer side; 0 for none (a big title: a scrim
|
|
196
|
+
* round its words, its alpha at the middle, so they read over a busy picture) */
|
|
196
197
|
shade?: number
|
|
197
198
|
}
|
|
198
199
|
|
|
199
|
-
/** the look words only a logo title reads */
|
|
200
|
+
/** the look words only a logo title reads, `sub` and `shade` a big title too */
|
|
200
201
|
export const LOGO_WORDS = ['fit', 'sub', 'gap', 'middle', 'shade'] as const
|
|
202
|
+
const BIG_TOO: readonly string[] = ['sub', 'shade']
|
|
201
203
|
|
|
202
204
|
/** how a made sound is made (design call 9): its seed, the voice or engine it is made `by`, its length (`for`), an sfx
|
|
203
205
|
* trimmed to its first `hit` */
|
|
@@ -566,7 +568,7 @@ const TITLE_WORDS: Record<string, (w: Word | undefined, k: string) => unknown> =
|
|
|
566
568
|
for: (w, k) => time(k, w),
|
|
567
569
|
place: (w, k) => {
|
|
568
570
|
const pl = word(k, w)
|
|
569
|
-
return pl === 'top' || pl === 'bottom' ? pl : bad(`${k} wants top|bottom, got ${pl}`)
|
|
571
|
+
return pl === 'top' || pl === 'middle' || pl === 'bottom' ? pl : bad(`${k} wants top|middle|bottom, got ${pl}`)
|
|
570
572
|
},
|
|
571
573
|
knock: (w, k) => time(k, w),
|
|
572
574
|
font: (w, k) => pathWord(k, w),
|
|
@@ -636,7 +638,7 @@ const fxOf = (v: Record<string, unknown>): TitleFx => Object.fromEntries(FX_WORD
|
|
|
636
638
|
const builtInStyle = (st: string): st is TitleStyle => (TITLE_STYLES as readonly string[]).includes(st)
|
|
637
639
|
/** a logo word on a title of another style fails: nothing would read it */
|
|
638
640
|
const logoOnly = (style: TitleStyle, fx: TitleFx | undefined): void => {
|
|
639
|
-
const odd = LOGO_WORDS.filter((w) => fx?.[w] !== undefined)
|
|
641
|
+
const odd = LOGO_WORDS.filter((w) => fx?.[w] !== undefined && !(style === 'big' && BIG_TOO.includes(w)))
|
|
640
642
|
if (style !== 'logo' && odd.length > 0) bad(`title ${odd.join(', ')}: a logo's words, this title is ${style}`)
|
|
641
643
|
}
|
|
642
644
|
|
|
@@ -673,7 +675,7 @@ export function resolveStyles(t: Pick<Trailer, 'shots'>, styles: Readonly<Record
|
|
|
673
675
|
const fx = { ...fxOf(under), ...ti.fx }
|
|
674
676
|
logoOnly(ti.style, fx)
|
|
675
677
|
if (Object.keys(fx).length > 0) ti.fx = fx
|
|
676
|
-
if (under.place && !ti.place) ti.place = under.place as
|
|
678
|
+
if (under.place && !ti.place) ti.place = under.place as TitlePlace
|
|
677
679
|
if (under.in && !ti.in) ti.in = under.in as Move
|
|
678
680
|
if (under.out && !ti.out && ti.knock === undefined) ti.out = under.out as Move
|
|
679
681
|
} catch (e) {
|
|
@@ -1379,7 +1381,7 @@ export function parseTrailer(text: string, o: ParseOptions = {}): { trailer: Tra
|
|
|
1379
1381
|
// a brand style is laid in by resolveStyles, once the brand is read
|
|
1380
1382
|
style: builtInStyle(st) ? st : 'caption',
|
|
1381
1383
|
...(builtInStyle(st) ? {} : { named: st }),
|
|
1382
|
-
...(p.place ? { place: p.place as
|
|
1384
|
+
...(p.place ? { place: p.place as TitlePlace } : {}),
|
|
1383
1385
|
...(p.knock !== undefined ? { knock: p.knock as number } : {}),
|
|
1384
1386
|
...(p.in ? { in: p.in as Move } : {}),
|
|
1385
1387
|
...(p.out ? { out: p.out as Move } : {}),
|
package/src/trailer/graph.ts
CHANGED
|
@@ -529,16 +529,39 @@ export interface MixLevel {
|
|
|
529
529
|
/** how close a mix lands to its `master`, LU */
|
|
530
530
|
export const MASTER_TOLERANCE = 0.3
|
|
531
531
|
|
|
532
|
-
/**
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
532
|
+
/** one pass of the mix: its level and what ebur128 measured of it */
|
|
533
|
+
export interface MixPass {
|
|
534
|
+
level: MixLevel
|
|
535
|
+
m: { lufs: number; truePeak: number }
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/** a dB of gain moves the loudness by less once the limiter takes the peaks it raises: this much at least */
|
|
539
|
+
const MIN_SLOPE = 0.25
|
|
540
|
+
|
|
541
|
+
/** the level of the mix's next pass, from the passes so far (the last one last); null: it holds. Over the ceiling, the
|
|
542
|
+
* trim drops by the overshoot. Off its master, the gain moves by the gap that trim leaves (it lowers the loudness dB
|
|
543
|
+
* for dB), over how much a dB of gain moved the loudness between the last two gains (1 before a second gain). The
|
|
544
|
+
* gaps are rounded to ebur128's tenth, so a mix measured on the tolerance holds */
|
|
545
|
+
export function nextMixLevel(master: number | null, passes: readonly MixPass[]): MixLevel | null {
|
|
546
|
+
const { level, m } = passes.at(-1)!
|
|
547
|
+
const over = +(m.truePeak - MIX_TRUE_PEAK).toFixed(2)
|
|
548
|
+
const gap = master === null ? 0 : +(master - m.lufs).toFixed(2)
|
|
537
549
|
if (over <= 0 && Math.abs(gap) <= MASTER_TOLERANCE) return null
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
550
|
+
const trim = over > 0 ? +(level.trim - over - 0.1).toFixed(2) : level.trim
|
|
551
|
+
const left = +(gap - (trim - level.trim)).toFixed(2)
|
|
552
|
+
if (master === null || Math.abs(left) <= MASTER_TOLERANCE) return { gain: level.gain, trim }
|
|
553
|
+
const before = passes.findLast((p) => p.level.gain !== level.gain)
|
|
554
|
+
const moved = before ? (m.lufs - level.trim - (before.m.lufs - before.level.trim)) / (level.gain - before.level.gain) : 1
|
|
555
|
+
const slope = Math.min(1, Math.max(MIN_SLOPE, moved))
|
|
556
|
+
return { gain: +(level.gain + left / slope).toFixed(2), trim }
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/** the pass a mix that never held keeps: under the ceiling and nearest its master, else the lowest peak */
|
|
560
|
+
export function bestMixPass<P extends MixPass>(master: number | null, passes: readonly P[]): P {
|
|
561
|
+
const under = passes.filter((p) => +(p.m.truePeak - MIX_TRUE_PEAK).toFixed(2) <= 0)
|
|
562
|
+
const off = (p: MixPass): number => (master === null ? 0 : Math.abs(master - p.m.lufs))
|
|
563
|
+
if (under.length > 0) return under.reduce((a, b) => (off(b) < off(a) ? b : a))
|
|
564
|
+
return passes.reduce((a, b) => (b.m.truePeak < a.m.truePeak ? b : a))
|
|
542
565
|
}
|
|
543
566
|
|
|
544
567
|
/** the ffmpeg arguments that mix the cut's sound: the music trimmed, faded and ducked under each voice line, the sfx
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// a build's phases on one clock, for `sk trailer --profile`: each span its name, its start and its length since the
|
|
2
|
+
// process started. A few performance.now calls a phase, so always recorded, printed only when asked. Spans that run
|
|
3
|
+
// side by side (the takes, the sections, the mix) overlap: their shares sum past 100 %
|
|
4
|
+
export interface Span {
|
|
5
|
+
name: string
|
|
6
|
+
at: number
|
|
7
|
+
ms: number
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const spans: Span[] = []
|
|
11
|
+
|
|
12
|
+
/** `fn` timed under `name` */
|
|
13
|
+
export async function timed<T>(name: string, fn: () => Promise<T> | T): Promise<T> {
|
|
14
|
+
const at = performance.now()
|
|
15
|
+
try {
|
|
16
|
+
return await fn()
|
|
17
|
+
} finally {
|
|
18
|
+
spans.push({ name, at, ms: performance.now() - at })
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** a span measured by its caller: the process's own start, before any module of the build loaded */
|
|
23
|
+
export const span = (name: string, at: number, ms: number): void => void spans.push({ name, at, ms })
|
|
24
|
+
|
|
25
|
+
/** every span by its start, its seconds and its share of the whole run, then the whole run */
|
|
26
|
+
export function profileLines(): string[] {
|
|
27
|
+
const wall = performance.now()
|
|
28
|
+
const s = (ms: number): string => (ms / 1000).toFixed(2).padStart(7)
|
|
29
|
+
const w = Math.max(5, ...spans.map((x) => x.name.length))
|
|
30
|
+
return [
|
|
31
|
+
`profile: ${'phase'.padEnd(w)} start seconds share`,
|
|
32
|
+
...[...spans].sort((a, b) => a.at - b.at).map((x) => `profile: ${x.name.padEnd(w)} ${s(x.at)} ${s(x.ms)} ${((100 * x.ms) / wall).toFixed(0).padStart(4)} %`),
|
|
33
|
+
`profile: ${'the whole run'.padEnd(w)} ${s(0)} ${s(wall)} 100 %`,
|
|
34
|
+
]
|
|
35
|
+
}
|
package/src/trailer/prune.ts
CHANGED
|
@@ -29,7 +29,7 @@ export interface Live {
|
|
|
29
29
|
/** the live set: each cut read, the name of every cache file its build reads, by the build's own key functions */
|
|
30
30
|
export async function liveSet(root: string): Promise<Live> {
|
|
31
31
|
const live: Live = { footage: new Set(), stems: new Set(), sound: new Set(), score: new Set(), titles: new Set(), broken: [] }
|
|
32
|
-
const [{ fileOf,
|
|
32
|
+
const [{ fileOf, titleRequest }, { trailerCache, takesOf }, { scoreWavFile }, { scoreModuleFile, scoreModule }, titles, { lookOf }, { loadBrand, identityLogo }, fonts, { titleMotions }, { resolveStyles }, { draftOf }] = await Promise.all([
|
|
33
33
|
import('./build.ts'),
|
|
34
34
|
import('./footage.ts'),
|
|
35
35
|
import('./score/sound.ts'),
|
|
@@ -40,6 +40,7 @@ export async function liveSet(root: string): Promise<Live> {
|
|
|
40
40
|
import('./fonts.ts'),
|
|
41
41
|
import('./graph.ts'),
|
|
42
42
|
import('./grammar.ts'),
|
|
43
|
+
import('./draft.ts'),
|
|
43
44
|
])
|
|
44
45
|
const brand = await loadBrand(root)
|
|
45
46
|
const look = typeof brand === 'string' ? null : lookOf(brand, await identityLogo(root))
|
|
@@ -53,19 +54,23 @@ export async function liveSet(root: string): Promise<Live> {
|
|
|
53
54
|
continue
|
|
54
55
|
}
|
|
55
56
|
const t = l.t
|
|
56
|
-
const names = { footage:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
const names = { footage: [] as string[], stems: [`mix-${t.name}`] as string[], titles: [] as string[], score: [] as string[], sound: [] as string[] }
|
|
58
|
+
// the cut and its draft (draft.ts), each its takes, pieces and titles; the draft plays the cut's mix
|
|
59
|
+
for (const lv of [l, { ...l, t: draftOf(t) }]) {
|
|
60
|
+
const tv = lv.t
|
|
61
|
+
names.footage.push(...takesOf(tv, root, l).map((tk) => basename(tk.file)))
|
|
62
|
+
for (const p of pieces(tv)) names.stems.push(`${tv.name}-${p.name}`)
|
|
63
|
+
names.stems.push(`${tv.name}-vertical`)
|
|
64
|
+
if (!look) continue
|
|
60
65
|
const dir = trailerCache(root, 'titles')
|
|
61
|
-
names.titles.push(basename(titles.cardFile(dir,
|
|
62
|
-
resolveStyles(
|
|
63
|
-
const motions = titleMotions(
|
|
64
|
-
|
|
66
|
+
names.titles.push(basename(titles.cardFile(dir, tv.size, look)))
|
|
67
|
+
resolveStyles(tv, (typeof brand === 'object' && brand?.trailer?.styles) || {})
|
|
68
|
+
const motions = titleMotions(tv)
|
|
69
|
+
tv.shots.forEach((s, i) =>
|
|
65
70
|
s.titles.forEach((ti, j) => {
|
|
66
71
|
const f = ti.fx?.font
|
|
67
72
|
const font = f === undefined ? null : fonts.isFontFile(f) ? fileOf(f, l) : fonts.googleFile(f, ti.fx?.weight ?? 400)
|
|
68
|
-
names.titles.push(basename(titles.titleFile(dir, { ...titleRequest(
|
|
73
|
+
names.titles.push(basename(titles.titleFile(dir, { ...titleRequest(lv, ti, look, motions[i]![j]!), font })))
|
|
69
74
|
}),
|
|
70
75
|
)
|
|
71
76
|
}
|
package/src/trailer/stitch.ts
CHANGED
|
@@ -6,9 +6,10 @@ import { availableParallelism } from 'node:os'
|
|
|
6
6
|
import { dirname, join } from 'node:path'
|
|
7
7
|
import sharp from 'sharp'
|
|
8
8
|
import { ffmpeg, loudnessKept } from './ffmpeg.ts'
|
|
9
|
-
import { type Encoder, GRID_RADIUS, gridLayout, type MixLevel, mixArgs, nextMixLevel, pieceArgs, type SplitMasks, splitPane, type StitchInput, THUMB_W } from './graph.ts'
|
|
9
|
+
import { bestMixPass, type Encoder, GRID_RADIUS, gridLayout, type MixLevel, type MixPass, mixArgs, nextMixLevel, pieceArgs, type SplitMasks, splitPane, type StitchInput, THUMB_W } from './graph.ts'
|
|
10
10
|
import type { TrailerLook } from './look.ts'
|
|
11
11
|
import { type Piece, pieces, twinStem } from './plan.ts'
|
|
12
|
+
import { timed } from './profile.ts'
|
|
12
13
|
|
|
13
14
|
/** bump when the stitch changes what the same arguments make */
|
|
14
15
|
const STITCH_VERSION = 1
|
|
@@ -182,13 +183,18 @@ export interface StitchRun extends StitchInput {
|
|
|
182
183
|
encoder?: Encoder
|
|
183
184
|
/** no sound at all: a shot's preview */
|
|
184
185
|
silent?: boolean
|
|
186
|
+
/** the mix its caller started (renderMix of the same sounds), awaited in place of mixing again */
|
|
187
|
+
mixing?: ReturnType<typeof renderMix>
|
|
188
|
+
/** each piece draws its row of the strip (default); false: none, `thumbs` empty */
|
|
189
|
+
thumbs?: boolean
|
|
185
190
|
}
|
|
186
191
|
|
|
187
192
|
async function renderPieces(a: StitchRun, ps: Piece[]): Promise<Stitched['pieces']> {
|
|
193
|
+
const exts = a.thumbs === false ? ['mp4'] : ['mp4', 'png']
|
|
188
194
|
return pool(
|
|
189
195
|
ps.map((p) => async () => {
|
|
190
|
-
const { files, made, twin, key } = await cached(a.cache, `${a.t.name}-${p.name}`,
|
|
191
|
-
return { ...p, made, key, ...(twin !== undefined ? { twin } : {}), file: files[0]!, thumbs: files[1]
|
|
196
|
+
const { files, made, twin, key } = await timed(`section ${p.name}`, () => cached(a.cache, `${a.t.name}-${p.name}`, exts, ([video, row]) => pieceArgs(a, p, video!, a.encoder, row)))
|
|
197
|
+
return { ...p, made, key, ...(twin !== undefined ? { twin } : {}), file: files[0]!, thumbs: files[1] ?? '' }
|
|
192
198
|
}),
|
|
193
199
|
LANES,
|
|
194
200
|
)
|
|
@@ -196,16 +202,22 @@ async function renderPieces(a: StitchRun, ps: Piece[]): Promise<Stitched['pieces
|
|
|
196
202
|
|
|
197
203
|
/** the mix, its true peak held under MIX_TRUE_PEAK after the aac encode (the encoder's band limit rings over a limited
|
|
198
204
|
* harsh sound: a square wave measured +2.1 dB), and with a `master` its integrated loudness on it: each pass measured
|
|
199
|
-
* as ebur128 hears it, then made again at the level nextMixLevel says, every pass kept in the cache
|
|
205
|
+
* as ebur128 hears it, then made again at the level nextMixLevel says, every pass kept in the cache; a mix that never
|
|
206
|
+
* holds keeps its best pass (bestMixPass) */
|
|
200
207
|
export async function renderMix(a: Pick<StitchRun, 't' | 'music' | 'sfx' | 'voices' | 'cache'>): Promise<{ file: string; key: string; made: boolean; twin?: string }> {
|
|
201
|
-
const
|
|
208
|
+
const cap = a.t.master === null ? 3 : 6
|
|
209
|
+
const passes: (MixPass & { r: Render })[] = []
|
|
202
210
|
let level: MixLevel = { gain: 0, trim: 0 }
|
|
203
211
|
let made = false
|
|
204
212
|
for (let pass = 1; ; pass++) {
|
|
205
|
-
const r = await cached(join(a.cache, 'mix'), `mix-${a.t.name}`, ['m4a'], ([out]) => mixArgs(a, out!, level))
|
|
213
|
+
const r = await timed(`mix pass ${pass}`, () => cached(join(a.cache, 'mix'), `mix-${a.t.name}`, ['m4a'], ([out]) => mixArgs(a, out!, level)))
|
|
206
214
|
made ||= r.made
|
|
207
|
-
|
|
208
|
-
|
|
215
|
+
passes.push({ level, m: await timed(`mix pass ${pass} measured`, () => loudnessKept(r.files[0]!)), r })
|
|
216
|
+
const next = nextMixLevel(a.t.master, passes)
|
|
217
|
+
if (next === null || pass === cap) {
|
|
218
|
+
const kept = next === null ? r : bestMixPass(a.t.master, passes).r
|
|
219
|
+
return { file: kept.files[0]!, key: kept.key, made, ...(kept.twin !== undefined && !made ? { twin: kept.twin } : {}) }
|
|
220
|
+
}
|
|
209
221
|
level = next
|
|
210
222
|
}
|
|
211
223
|
}
|
|
@@ -230,8 +242,8 @@ async function joinPieces(files: string[], sound: { file: string; start?: number
|
|
|
230
242
|
|
|
231
243
|
/** the whole cut: every piece (rendered where the cache misses it), joined, with its sound */
|
|
232
244
|
export async function stitch(a: StitchRun): Promise<Stitched> {
|
|
233
|
-
const [ps, mix] = await Promise.all([renderPieces(a, pieces(a.t)), a.silent ? null : renderMix(a)])
|
|
234
|
-
await joinPieces(ps.map((p) => p.file), mix ? { file: mix.file } : null, a.out)
|
|
245
|
+
const [ps, mix] = await Promise.all([renderPieces(a, pieces(a.t)), a.silent ? null : (a.mixing ?? renderMix(a))])
|
|
246
|
+
await timed('join', () => joinPieces(ps.map((p) => p.file), mix ? { file: mix.file } : null, a.out))
|
|
235
247
|
return { pieces: ps, ...mixOf(mix) }
|
|
236
248
|
}
|
|
237
249
|
|
package/src/trailer/titles.ts
CHANGED
|
@@ -86,6 +86,20 @@ interface Ctx {
|
|
|
86
86
|
const restCtx = (): Ctx => ({ n: 0, i: 0, decor: 1 })
|
|
87
87
|
|
|
88
88
|
/** a plate, a band, a glow or the logo image: faded with the title's decor */
|
|
89
|
+
/** a paint at `s` times its size, every stroke and blur with it */
|
|
90
|
+
function scaled(p: Paint, s: number): Paint {
|
|
91
|
+
return {
|
|
92
|
+
...p,
|
|
93
|
+
px: p.px * s,
|
|
94
|
+
spacing: p.spacing * s,
|
|
95
|
+
drop: p.drop ? { ...p.drop, dy: p.drop.dy * s } : (p.drop ?? null),
|
|
96
|
+
outline: p.outline ? { ...p.outline, w: p.outline.w * s, ...(p.outline.dy !== undefined ? { dy: p.outline.dy * s } : {}) } : null,
|
|
97
|
+
inner: p.inner ? { ...p.inner, w: p.inner.w * s } : null,
|
|
98
|
+
shadow: p.shadow ? { ...p.shadow, blur: p.shadow.blur * s, dy: p.shadow.dy * s } : null,
|
|
99
|
+
glow: p.glow ? { ...p.glow, blur: p.glow.blur * s } : null,
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
89
103
|
function decor(cx: Ctx, g: SKRSContext2D, draw: () => void): void {
|
|
90
104
|
g.save()
|
|
91
105
|
g.globalAlpha *= cx.decor
|
|
@@ -400,9 +414,40 @@ function drawInto(g: SKRSContext2D, d: TitleDraw, [W, H]: readonly [number, numb
|
|
|
400
414
|
} else if (style === 'big') {
|
|
401
415
|
// a strong display line in the upper third: light words in a thick edge outline, an accent stroke inside it
|
|
402
416
|
const p = own({ ...base((d.fx?.size ?? 112) * k, 900), outline: { w: 22 * k, color: look.edge }, inner: { w: 8 * k, color: look.accent }, shadow: { blur: 26 * k, dy: 10 * k, color: alpha(look.edge, 0.55) } })
|
|
417
|
+
// `place middle` centres the block on both axes; `sub` draws the lines after the first break that much smaller,
|
|
418
|
+
// `shade` lays a soft dark ellipse round the words (its alpha at the middle) so they read over a busy picture
|
|
419
|
+
const fx = d.fx
|
|
420
|
+
const small = fx?.sub !== undefined && more.length > 0 ? scaled(p, fx.sub) : null
|
|
403
421
|
setFace(g, p)
|
|
404
|
-
const
|
|
405
|
-
|
|
422
|
+
const rows: { l: string; p: Paint }[] = (small ? wrap(g, first, W * 0.82) : wrap(g, text, W * 0.82)).map((l) => ({ l, p }))
|
|
423
|
+
if (small) {
|
|
424
|
+
setFace(g, small)
|
|
425
|
+
rows.push(...wrap(g, more.join('\\n'), W * 0.82).map((l) => ({ l, p: small })))
|
|
426
|
+
}
|
|
427
|
+
const block = rows.reduce((s, r) => s + r.p.px * 1.12, 0)
|
|
428
|
+
const cy = d.place === 'middle' ? H * 0.5 : H * 0.26
|
|
429
|
+
if (fx?.shade)
|
|
430
|
+
decor(cx, g, () => {
|
|
431
|
+
const wide = Math.max(...rows.map((r) => (setFace(g, r.p), g.measureText(r.l.replaceAll('*', '')).width)))
|
|
432
|
+
const [rx, ry] = [wide / 2 + 160 * k, block / 2 + 110 * k]
|
|
433
|
+
g.save()
|
|
434
|
+
g.translate(W / 2, cy)
|
|
435
|
+
g.scale(rx / ry, 1)
|
|
436
|
+
const a = Math.min(1, fx.shade!)
|
|
437
|
+
const s = g.createRadialGradient(0, 0, 0, 0, 0, ry)
|
|
438
|
+
s.addColorStop(0, alpha(look.edge, a))
|
|
439
|
+
s.addColorStop(0.55, alpha(look.edge, a * 0.75))
|
|
440
|
+
s.addColorStop(1, alpha(look.edge, 0))
|
|
441
|
+
g.fillStyle = s
|
|
442
|
+
g.fillRect(-ry, -ry, ry * 2, ry * 2)
|
|
443
|
+
g.restore()
|
|
444
|
+
})
|
|
445
|
+
let y = cy - block / 2
|
|
446
|
+
for (const r of rows) {
|
|
447
|
+
setFace(g, r.p)
|
|
448
|
+
ink(cx, g, r.p, r.l, W / 2, y + (r.p.px * 1.12) / 2)
|
|
449
|
+
y += r.p.px * 1.12
|
|
450
|
+
}
|
|
406
451
|
} else if (style === 'line') {
|
|
407
452
|
// a tagline: light words centred low on a soft dark band, no plate, the frame stays the picture
|
|
408
453
|
const p = own({ ...base((d.fx?.size ?? 64) * k, look.font.weight), outline: { w: 9 * k, color: alpha(look.edge, 0.82) }, shadow: { blur: 18 * k, dy: 4 * k, color: alpha(look.edge, 0.85) } })
|