@kriya-ai/harness 0.2.5 → 2.0.1
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/RELEASE_NOTES.md +121 -0
- package/SAFETY.md +181 -0
- package/THIRD_PARTY_NOTICES.md +113 -0
- package/bin/kriya.js +188 -2
- package/bundle/cordis.patch.yml +60 -5
- package/contract/SOURCE.md +3 -3
- package/contract/contract.json +498 -3
- package/contract/schemas/api.json +64 -0
- package/contract/schemas/auth_matrix.json +44 -0
- package/contract/schemas/component_states.json +33 -0
- package/contract/schemas/design_tokens.json +34 -0
- package/contract/schemas/scene_direction.json +82 -0
- package/contract/schemas/threat_model.json +44 -0
- package/package.json +2 -1
- package/plugins/changes/client.js +5 -3
- package/plugins/deploy/index.js +215 -0
- package/plugins/deploy/package.json +13 -0
- package/plugins/grounding/index.js +81 -0
- package/plugins/grounding/lookup.js +373 -0
- package/plugins/grounding/package.json +13 -0
- package/plugins/kriya-tools/index.js +2 -1
- package/plugins/loop/index.js +381 -10
- package/plugins/mcp/index.js +79 -0
- package/plugins/mcp/package.json +13 -0
- package/plugins/mirror/index.js +17 -0
- package/plugins/overview/client.js +5 -2
- package/plugins/preview/client.js +12 -6
- package/plugins/progress/client.js +7 -4
- package/plugins/repo/index.js +230 -0
- package/plugins/repo/package.json +13 -0
- package/plugins/repo/repo.js +348 -0
- package/plugins/runstrip/client.js +436 -0
- package/plugins/runstrip/index.js +312 -0
- package/plugins/runstrip/package.json +23 -0
- package/src/cartridges.js +133 -0
- package/src/contracts.js +130 -0
- package/src/critic.js +78 -0
- package/src/daemon.js +7 -1
- package/src/doctor.js +67 -0
- package/src/edit/core/effects.js +185 -0
- package/src/edit/core/ffmpeg.js +65 -6
- package/src/edit/core/layout.js +46 -1
- package/src/edit/core/ops.js +169 -2
- package/src/edit/core/plan.js +65 -9
- package/src/edit/core/project.d.ts +24 -0
- package/src/edit/core/project.js +64 -0
- package/src/edit/core/solver.js +34 -6
- package/src/edit/core/style-brief.js +211 -0
- package/src/edit/core/style-packs.js +57 -0
- package/src/edit/core/type-kit.js +173 -0
- package/src/edit/director/ask.js +37 -3
- package/src/edit/director/assembly.js +829 -0
- package/src/edit/director/continuity.js +9 -1
- package/src/edit/director/custom-motion.js +88 -0
- package/src/edit/director/graphics.js +44 -10
- package/src/edit/director/intent.js +125 -0
- package/src/edit/director/mentions.js +52 -0
- package/src/edit/director/plan.js +43 -11
- package/src/edit/director/revise.js +132 -9
- package/src/edit/director/viewer.js +136 -0
- package/src/edit/director/watch-fix.js +119 -0
- package/src/edit/engine/captions.js +110 -5
- package/src/edit/engine/confine.js +81 -4
- package/src/edit/engine/custom.js +243 -0
- package/src/edit/engine/dna2.js +893 -0
- package/src/edit/engine/fonts.js +218 -0
- package/src/edit/engine/graphics.js +271 -10
- package/src/edit/engine/index.js +14 -5
- package/src/edit/engine/motion.js +148 -13
- package/src/edit/engine/music-bed.js +59 -1
- package/src/edit/engine/packs.js +11 -0
- package/src/edit/engine/reference2.js +26 -0
- package/src/edit/engine/sfx.js +56 -1
- package/src/edit/engine/tool.js +21 -5
- package/src/edit/gates/assembly.js +194 -0
- package/src/edit/gates/copy.js +7 -4
- package/src/edit/gates/index.js +72 -7
- package/src/edit/gates/reference.js +115 -0
- package/src/edit/gates/tile.js +96 -0
- package/src/edit/host/client.js +8 -3
- package/src/edit/host/clips.js +33 -0
- package/src/edit/host/jobs.js +9 -3
- package/src/edit/host/layers.js +134 -0
- package/src/edit/host/main.js +10 -3
- package/src/edit/host/paths.js +21 -3
- package/src/edit/host/preview.js +108 -0
- package/src/edit/host/projects.js +443 -34
- package/src/edit/host/server.js +235 -20
- package/src/edit/host/tavi.js +77 -0
- package/src/edit/index/index.js +3 -2
- package/src/edit/loop/make.js +28 -3
- package/src/edit/recipes/assembly.js +352 -0
- package/src/edit/recipes/graphic-clips.js +4 -2
- package/src/edit/recipes/openings.js +36 -0
- package/src/edit/recipes/reel.js +104 -14
- package/src/edit/recipes/reference-look.js +29 -0
- package/src/edit/recipes/short-from-long.js +3 -3
- package/src/edit/recipes/sound.js +71 -0
- package/src/edit/runtime/cli.js +26 -5
- package/src/edit/runtime/fetch.js +4 -4
- package/src/edit/runtime/licences.js +7 -1
- package/src/explore.js +103 -0
- package/src/failure.js +1 -1
- package/src/gate-commands.js +114 -0
- package/src/gates/api.js +127 -0
- package/src/gates/commands.js +111 -0
- package/src/gates/detectors.js +370 -0
- package/src/gates/http.js +62 -0
- package/src/gates/index.js +196 -0
- package/src/gates/page.js +264 -0
- package/src/gates/sast.js +64 -0
- package/src/gates/stack.js +110 -0
- package/src/gates/tenant.js +162 -0
- package/src/gates/three.js +431 -0
- package/src/gates/ui.js +111 -0
- package/src/gateway-proxy.js +20 -2
- package/src/launch.js +39 -5
- package/src/loop.js +199 -7
- package/src/mcp.js +126 -0
- package/src/milestones.js +188 -0
- package/src/modes.js +67 -0
- package/src/orchestra.js +50 -0
- package/src/outcomes.js +88 -0
- package/src/profiles.js +5 -0
- package/src/receipts.js +238 -0
- package/src/release.js +356 -0
- package/src/runstrip.js +122 -0
- package/src/stack.js +120 -0
- package/src/verify.js +67 -20
- package/studio/dist/fonts/fraunces.woff2 +0 -0
- package/studio/dist/fonts/geist.woff2 +0 -0
- package/studio/dist/fonts/jetbrains-mono.woff2 +0 -0
- package/studio/dist/studio.css +449 -1
- package/studio/dist/studio.js +3 -3
package/src/daemon.js
CHANGED
|
@@ -190,6 +190,10 @@ export async function runDaemon(options) {
|
|
|
190
190
|
const canceling = new Set() // forwarded to the Host and not yet over
|
|
191
191
|
let allowEdit = Boolean(options.allowEdit)
|
|
192
192
|
let editAdvertised = false
|
|
193
|
+
// TP11: each folder's clip numbers and labels go in the hello only after Kriya said taviOrder (rule 17)
|
|
194
|
+
let orderAdvertised = false
|
|
195
|
+
const clipsOf = options.clipsOf ?? (async (folder) => (await import("./edit/host/clips.js")).advertisedClips(folder))
|
|
196
|
+
const featuresOf = options.featuresOf ?? (async () => (await import("./edit/runtime/fetch.js")).fetchFeatures(device))
|
|
193
197
|
const editHost = options.editHost ?? {
|
|
194
198
|
async hand(job) {
|
|
195
199
|
const { ensureHost, hostCall } = await import("./edit/host/client.js")
|
|
@@ -218,6 +222,7 @@ export async function runDaemon(options) {
|
|
|
218
222
|
// Not on this Kriya yet; asked again at the next hello
|
|
219
223
|
}
|
|
220
224
|
}
|
|
225
|
+
orderAdvertised = editSwitch && allowEdit && editAdvertised ? (await featuresOf().catch(() => null))?.taviOrder === true : false
|
|
221
226
|
if (editSwitch && allowEdit && editAdvertised) {
|
|
222
227
|
capabilities.edit = true
|
|
223
228
|
await editHost.wake?.().catch((error) => log(`kriya daemon: the Edit Host didn't start: ${error.message}`))
|
|
@@ -226,7 +231,8 @@ export async function runDaemon(options) {
|
|
|
226
231
|
|
|
227
232
|
const hello = async () => {
|
|
228
233
|
await refreshEdit()
|
|
229
|
-
|
|
234
|
+
const clips = orderAdvertised ? await Promise.all(projects.map((p) => clipsOf(p.path).catch(() => []))) : []
|
|
235
|
+
await send("POST", "/daemon/hello", { daemonVersion: CLIENT_VERSION, capabilities, projects: projects.map((p, i) => ({ id: p.id, name: p.name, path: p.shown, git: p.git, ...(clips[i]?.length ? { clips: clips[i] } : {}) })), rules: projectRules(projects) })
|
|
230
236
|
helloAt = Date.now()
|
|
231
237
|
}
|
|
232
238
|
// Remote Control changes folders and switches without stopping running tasks
|
package/src/doctor.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { execFileSync } from "node:child_process"
|
|
2
|
+
import { existsSync } from "node:fs"
|
|
2
3
|
import { homedir } from "node:os"
|
|
3
4
|
import { join, sep } from "node:path"
|
|
4
5
|
|
|
@@ -135,3 +136,69 @@ export async function doctor(io = {}) {
|
|
|
135
136
|
}
|
|
136
137
|
return ok
|
|
137
138
|
}
|
|
139
|
+
|
|
140
|
+
/* ─────────────── Harness 2.0 W17: gates on this machine (kriya doctor --gates) ─────────────── */
|
|
141
|
+
|
|
142
|
+
/** Whether a program is on PATH, found by looking, never by running it. */
|
|
143
|
+
export function onPath(name, env = process.env, exists = existsSync) {
|
|
144
|
+
const dirs = String(env.PATH ?? "").split(process.platform === "win32" ? ";" : ":").filter(Boolean)
|
|
145
|
+
const exts = process.platform === "win32" ? ["", ".exe", ".cmd"] : [""]
|
|
146
|
+
return dirs.some((d) => exts.some((e) => exists(join(d, `${name}${e}`))))
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* The capability matrix (DELIVERY_AND_STABILITY §5): which gates can run
|
|
151
|
+
* here and, for the others, what they would need. Nothing is started.
|
|
152
|
+
*/
|
|
153
|
+
export async function gateMatrix({ has = (n) => onPath(n), chrome } = {}) {
|
|
154
|
+
const browser = chrome ?? chromeInstalled()
|
|
155
|
+
const row = (gate, ok, needs) => ({ gate, works: Boolean(ok), ...(!ok && { needs }) })
|
|
156
|
+
return [
|
|
157
|
+
row("G-CONTRACT", true),
|
|
158
|
+
row("G-DETECT", true),
|
|
159
|
+
row("G-SECRETS", true),
|
|
160
|
+
row("G-TRACE", true),
|
|
161
|
+
row("G-FLAKE", true),
|
|
162
|
+
row("G-UI", browser, "Google Chrome or another Chromium browser"),
|
|
163
|
+
row("G-A11Y", browser, "Google Chrome or another Chromium browser"),
|
|
164
|
+
row("G-STACK", has("psql"), "psql (PostgreSQL client) and kriya stack use --db"),
|
|
165
|
+
row("G-API", true),
|
|
166
|
+
row("G-TENANT", true),
|
|
167
|
+
row("G-SAST", has("semgrep"), "semgrep and the project's own rules file"),
|
|
168
|
+
row("G-DATA", true),
|
|
169
|
+
row("G-EVAL", true),
|
|
170
|
+
row("G-SAN", has("clang") || has("gcc"), "a C/C++ toolchain (clang or gcc)"),
|
|
171
|
+
row("G-IAC", has("tofu") || has("terraform"), "OpenTofu or Terraform"),
|
|
172
|
+
row("G-SIM", has("xcrun") || has("adb"), "Xcode (xcrun) or Android platform tools (adb)"),
|
|
173
|
+
row("G-DEPLOYED", has("vercel"), "a confirmed provider CLI (vercel), signed in by you"),
|
|
174
|
+
row("G-3D", browser, "Google Chrome or another Chromium browser that creates WebGL"),
|
|
175
|
+
]
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Self-tests of the gates that need nothing installed: each checks a clean
|
|
180
|
+
* and a mutant fixture, so a gate that stopped catching what it should is
|
|
181
|
+
* seen here before it misses something in a real step.
|
|
182
|
+
*/
|
|
183
|
+
export async function gateSelfTests() {
|
|
184
|
+
const { DETECTORS, findSecrets } = await import("./gates/detectors.js")
|
|
185
|
+
const file = (path, text) => ({ path, content: text, added: text.split("\n").map((t, i) => ({ line: i + 1, text: t })) })
|
|
186
|
+
const tests = [
|
|
187
|
+
["G-SECRETS", findSecrets(file("src/a.js", "const key = process.env.KEY\n")).length === 0, findSecrets(file("src/a.js", `const key = "${"AKIA" + "QWERTYUIOPASDFGH"}"\n`)).length > 0],
|
|
188
|
+
["G-DETECT DB-DROP", DETECTORS["DB-DROP"].find(file("db/1.sql", "create table t (id int);")).length === 0, DETECTORS["DB-DROP"].find(file("db/2.sql", "drop table t;")).length > 0],
|
|
189
|
+
["G-DETECT OPS-MIGRATE-LOCK", DETECTORS["OPS-MIGRATE-LOCK"].find(file("db/1.sql", "create index concurrently i on t (a);")).length === 0, DETECTORS["OPS-MIGRATE-LOCK"].find(file("db/2.sql", "create index i on t (a);")).length > 0],
|
|
190
|
+
]
|
|
191
|
+
return tests.map(([name, clean, mutant]) => ({ name, ok: clean && mutant, clean, mutant }))
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** `kriya doctor --gates`: the matrix and the self-tests; false if a self-test fails. */
|
|
195
|
+
export async function doctorGates(io = {}) {
|
|
196
|
+
const say = io.say ?? ((line) => process.stdout.write(`${line}\n`))
|
|
197
|
+
let ok = true
|
|
198
|
+
for (const t of await gateSelfTests()) {
|
|
199
|
+
say(`${t.ok ? "ok " : "FAIL"} self-test ${t.name}${t.ok ? "" : ` — ${t.clean ? "" : "flags clean code"}${!t.clean && !t.mutant ? ", " : ""}${t.mutant ? "" : "misses the planted problem"}`}`)
|
|
200
|
+
if (!t.ok) ok = false
|
|
201
|
+
}
|
|
202
|
+
for (const r of await gateMatrix(io)) say(`${r.works ? "works" : "not checked here"} ${r.gate}${r.works ? "" : ` (needs ${r.needs})`}`)
|
|
203
|
+
return ok
|
|
204
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
// The effects registry (TP5, CRAFT_UPGRADE §3, EDD-64), behind editing.craft: every effect is a
|
|
2
|
+
// typed row of data. An operation may store only an id and values the row allows, so nothing is
|
|
3
|
+
// stored that the render can't draw; code alone turns a row into FFmpeg filter steps, from numbers.
|
|
4
|
+
// Each row's `needs` were confirmed against this computer's FFmpeg (9.0.2) in spike TPX-02; a
|
|
5
|
+
// runtime without one of them drops the effect at compile with a note, never fakes it.
|
|
6
|
+
|
|
7
|
+
import { escapeFilterValue } from "./ffmpeg.js"
|
|
8
|
+
|
|
9
|
+
const FLICKS = 705_600_000
|
|
10
|
+
export const MAX_POINTS = 16
|
|
11
|
+
export const EASES = ["linear", "in", "out", "inOut", "hold"]
|
|
12
|
+
// A look may move skin this far, no further (CRAFT §3.4); beyond it the effect is eased on that clip
|
|
13
|
+
export const SKIN = { hue: 12, saturation: 0.35 }
|
|
14
|
+
// Restraint (CRAFT §3.5): what an agent may add, per minute of the cut; the person is never capped
|
|
15
|
+
export const AGENT_CAP_PER_MINUTE = 3
|
|
16
|
+
|
|
17
|
+
const filter = (name, options = {}) => (Object.keys(options).length ? `${name}=${Object.entries(options).map(([k, v]) => `${k}=${escapeFilterValue(v)}`).join(":")}` : name)
|
|
18
|
+
const n = (value) => (Number.isInteger(value) ? String(value) : value.toFixed(4))
|
|
19
|
+
|
|
20
|
+
// A hue angle as an RGB colour in 0…1, for duotone's ends
|
|
21
|
+
const rgbOf = (hue, light) => {
|
|
22
|
+
const k = (m) => (m + hue / 30) % 12
|
|
23
|
+
const a = 0.6 * Math.min(light, 1 - light)
|
|
24
|
+
return [0, 8, 4].map((m) => light - a * Math.max(-1, Math.min(k(m) - 3, 9 - k(m), 1)))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The rows. params: name → [min, max, default]. keyable: params a keyframe may move (the filter takes
|
|
29
|
+
* an expression evaluated per frame). build(values, ctx) → filter steps, where a keyed value arrives as
|
|
30
|
+
* an expression string. preview: a CSS filter, or null when the monitor can't draw it. gate: what QG-07
|
|
31
|
+
* and QG-11 should expect inside it. skin: how far it moves skin hue (degrees) and saturation, at most.
|
|
32
|
+
*/
|
|
33
|
+
export const EFFECTS = {
|
|
34
|
+
// region (TP9): may act on a box drawn on the frame only
|
|
35
|
+
blur: { group: "focus", label: "Blur", params: { amount: [0.5, 40, 8] }, needs: ["gblur"], weight: "light", region: true, build: ({ amount }) => [filter("gblur", { sigma: amount })], preview: ({ amount }) => `blur(${(amount * 0.5).toFixed(1)}px)` },
|
|
36
|
+
sharpen: { group: "focus", label: "Sharpen", params: { amount: [0.1, 3, 1] }, needs: ["unsharp"], weight: "light", build: ({ amount }) => [filter("unsharp", { luma_msize_x: 5, luma_msize_y: 5, luma_amount: amount })], preview: () => "contrast(1.05)" },
|
|
37
|
+
vignette: { group: "focus", label: "Vignette", params: { strength: [0, 1, 0.5] }, keyable: ["strength"], needs: ["vignette"], weight: "light", build: ({ strength }) => [filter("vignette", { angle: typeof strength === "string" ? `0.25+0.45*(${strength})` : n(0.25 + 0.45 * strength), eval: "frame" })], preview: () => null },
|
|
38
|
+
grain: { group: "texture", label: "Grain", params: { amount: [1, 40, 12] }, needs: ["noise"], weight: "light", build: ({ amount }) => [filter("noise", { alls: Math.round(amount), allf: "t+u", all_seed: 1234 })], preview: () => null },
|
|
39
|
+
glow: { group: "texture", label: "Glow", params: { amount: [0.05, 1, 0.4], radius: [2, 40, 12] }, needs: ["split", "gblur", "blend"], weight: "light", build: ({ amount, radius }, { uid }) => { const i = uid(); return [`split[gw${i}][gx${i}];[gx${i}]${filter("gblur", { sigma: radius })}[gy${i}];[gw${i}][gy${i}]${filter("blend", { all_mode: "screen", all_opacity: amount })}`] }, preview: ({ amount }) => `brightness(${(1 + amount * 0.25).toFixed(2)})` },
|
|
40
|
+
blackWhite: { group: "colour", label: "Black and white", params: { amount: [0, 1, 1] }, keyable: ["amount"], needs: ["hue"], weight: "light", build: ({ amount }) => [filter("hue", { s: typeof amount === "string" ? `1-(${amount})` : n(1 - amount) })], preview: ({ amount }) => `grayscale(${amount})` },
|
|
41
|
+
tint: { group: "colour", label: "Tint", params: { hue: [0, 360, 30], amount: [0, 1, 0.3] }, needs: ["colorize"], weight: "light", build: ({ hue, amount }) => [filter("colorize", { hue, saturation: 0.6, lightness: 0.5, mix: amount })], preview: ({ amount }) => `sepia(${amount})`, skin: ({ amount }) => ({ hue: 180 * amount, saturation: 0 }) },
|
|
42
|
+
duotone: { group: "colour", label: "Duotone", params: { dark: [0, 360, 220], light: [0, 360, 40] }, needs: ["hue", "curves"], weight: "heavy", build: ({ dark, light }) => { const [d, l] = [rgbOf(dark, 0.2), rgbOf(light, 0.85)]; return [filter("hue", { s: 0 }), filter("curves", { r: `0/${d[0].toFixed(3)} 1/${l[0].toFixed(3)}`, g: `0/${d[1].toFixed(3)} 1/${l[1].toFixed(3)}`, b: `0/${d[2].toFixed(3)} 1/${l[2].toFixed(3)}` })] }, preview: () => "grayscale(1) sepia(0.6)", skin: () => ({ hue: 180, saturation: 0 }) },
|
|
43
|
+
invert: { group: "colour", label: "Invert", params: {}, needs: ["negate"], weight: "heavy", build: () => ["negate"], preview: () => "invert(1)", skin: () => ({ hue: 180, saturation: 0 }) },
|
|
44
|
+
mirror: { group: "frame", label: "Mirror", params: {}, needs: ["hflip"], weight: "light", build: () => ["hflip"], preview: () => null },
|
|
45
|
+
letterbox: { group: "frame", label: "Letterbox", params: { ratio: [1.5, 3, 2.39] }, needs: ["drawbox"], weight: "light", build: ({ ratio }, { width, height }) => { const bar = Math.max(0, Math.floor((height - width / ratio) / 2)); return bar ? [filter("drawbox", { x: 0, y: 0, w: width, h: bar, color: "black", t: "fill" }), filter("drawbox", { x: 0, y: height - bar, w: width, h: bar, color: "black", t: "fill" })] : [] }, preview: () => null },
|
|
46
|
+
pixelate: { group: "energy", label: "Pixelate", params: { size: [2, 64, 16] }, needs: ["scale"], weight: "heavy", region: true, build: ({ size }, { width, height }) => [filter("scale", { w: Math.max(2, Math.round(width / size)), h: Math.max(2, Math.round(height / size)), flags: "neighbor" }), filter("scale", { w: width, h: height, flags: "neighbor" })], preview: () => null },
|
|
47
|
+
colourSplit: { group: "energy", label: "Colour split", params: { amount: [1, 30, 6] }, needs: ["rgbashift"], weight: "heavy", build: ({ amount }) => [filter("rgbashift", { rh: -Math.round(amount), bh: Math.round(amount) })], preview: () => null },
|
|
48
|
+
shake: { group: "energy", label: "Shake", params: { amount: [1, 40, 8], speed: [1, 30, 8] }, keyable: ["amount"], needs: ["crop", "scale"], weight: "heavy", gate: "motion", build: ({ amount, speed }, { width, height, max }) => { const a = typeof amount === "string" ? `(${amount})` : n(amount); const m = Math.ceil(max.amount); return [filter("crop", { w: width - 2 * m, h: height - 2 * m, x: `${m}+${a}*sin(2*PI*${n(speed)}*t)`, y: `${m}+${a}*cos(2*PI*${n(speed * 1.3)}*t)` }), filter("scale", { w: width, h: height })] }, preview: () => null },
|
|
49
|
+
flash: { group: "energy", label: "Flash", params: { length: [0.05, 1, 0.2] }, needs: ["fade"], weight: "heavy", gate: "flash", build: ({ length }, { origin }) => (origin < -length ? [] : [filter("fade", { t: "in", st: n(Math.max(0, origin)), d: n(Math.max(0.01, length + Math.min(0, origin))), color: "white" })]), preview: () => null },
|
|
50
|
+
glitch: { group: "energy", label: "Glitch", params: { amount: [0.1, 1, 0.5] }, needs: ["crop", "scale", "rgbashift"], weight: "heavy", gate: "motion", build: ({ amount }, { width, height }) => { const m = Math.max(2, Math.round(16 * amount)); return [filter("crop", { w: width - 2 * m, h: height - 2 * m, x: `${m}+if(lt(mod(n*7919,97),${Math.round(30 * amount)}),${m}*(mod(n*104729,3)-1),0)`, y: m }), filter("scale", { w: width, h: height }), filter("rgbashift", { rh: -m, bh: m })] }, preview: () => null },
|
|
51
|
+
// TP9: "mask this": the frame outside a drawn box darkened and drained, so the eye goes to what was drawn.
|
|
52
|
+
// Needs a region; drawn on the whole frame, then the box laid back over it untouched (fxSteps)
|
|
53
|
+
mask: { group: "focus", label: "Mask", params: { amount: [0.1, 1, 0.6] }, needs: ["eq", "crop", "split"], weight: "light", region: true, needsRegion: true, outside: true, build: ({ amount }) => [filter("eq", { brightness: n(-0.45 * amount), saturation: n(1 - 0.7 * amount) })], preview: () => null },
|
|
54
|
+
// Looks (CRAFT §3.4): data, made by Kriya, each a few filters with fixed numbers
|
|
55
|
+
film: { group: "look", label: "Film", params: {}, needs: ["curves", "noise", "vignette"], weight: "light", build: () => [filter("curves", { preset: "vintage" }), filter("noise", { alls: 8, allf: "t+u", all_seed: 2718 }), filter("vignette", { angle: 0.45 })], preview: () => "sepia(0.25) contrast(1.05)", skin: () => ({ hue: 8, saturation: 0 }) },
|
|
56
|
+
noir: { group: "look", label: "Noir", params: {}, needs: ["hue", "eq", "noise", "vignette"], weight: "light", build: () => [filter("hue", { s: 0 }), filter("eq", { contrast: 1.25 }), filter("noise", { alls: 10, allf: "t+u", all_seed: 3141 }), filter("vignette", { angle: 0.6 })], preview: () => "grayscale(1) contrast(1.25)" },
|
|
57
|
+
faded: { group: "look", label: "Faded", params: {}, needs: ["curves", "eq"], weight: "light", build: () => [filter("curves", { all: "0/0.08 1/0.92" }), filter("eq", { saturation: 0.8 })], preview: () => "saturate(0.8) contrast(0.85)" },
|
|
58
|
+
punchy: { group: "look", label: "Punchy", params: {}, needs: ["eq"], weight: "light", build: () => [filter("eq", { contrast: 1.12, saturation: 1.3 })], preview: () => "contrast(1.12) saturate(1.3)", skin: () => ({ hue: 0, saturation: 0.3 }) },
|
|
59
|
+
tealOrange: { group: "look", label: "Teal and orange", params: {}, needs: ["colorbalance"], weight: "light", build: () => [filter("colorbalance", { rs: -0.08, bs: 0.1, rh: 0.1, bh: -0.08 })], preview: () => null, skin: () => ({ hue: 6, saturation: 0.1 }) },
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Named moves (CRAFT §3.3): what the Director picks instead of writing points; code expands each
|
|
64
|
+
* over the effect's own span into keyframes, so the same move is the same expression every render.
|
|
65
|
+
*/
|
|
66
|
+
export const MOVES = {
|
|
67
|
+
drain: { effect: "blackWhite", param: "amount", label: "colour drains to black and white", points: (span) => [{ at: 0, value: 0, ease: "inOut" }, { at: span, value: 1, ease: "linear" }] },
|
|
68
|
+
settle: { effect: "shake", param: "amount", label: "a shake that settles", points: (span, v) => [{ at: 0, value: v, ease: "out" }, { at: span, value: 1, ease: "linear" }] },
|
|
69
|
+
closeIn: { effect: "vignette", param: "strength", label: "the edges close in", points: (span, v) => [{ at: 0, value: 0, ease: "in" }, { at: span, value: v, ease: "linear" }] },
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** A drawn region (TP9): whole thousandths of the frame, inside it, each side at least 10. @returns {{ x: number, y: number, w: number, h: number } | null} */
|
|
73
|
+
export function regionOf(raw) {
|
|
74
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw) || Object.keys(raw).some((key) => !["x", "y", "w", "h"].includes(key))) return null
|
|
75
|
+
const { x, y, w, h } = raw
|
|
76
|
+
if (![x, y, w, h].every(Number.isSafeInteger) || x < 0 || y < 0 || w < 10 || h < 10 || x + w > 1000 || y + h > 1000) return null
|
|
77
|
+
return { x, y, w, h }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// A region in whole, even pixels of a width × height picture, so 4:2:0 chroma never splits (shortcut: even
|
|
81
|
+
// edges move a box by at most a pixel; a 4:4:4 pipeline would take them as drawn)
|
|
82
|
+
const even = (v) => 2 * Math.round(v / 2)
|
|
83
|
+
export function regionPixels(region, width, height) {
|
|
84
|
+
const x = Math.min(even((region.x * width) / 1000), width - 2)
|
|
85
|
+
const y = Math.min(even((region.y * height) / 1000), height - 2)
|
|
86
|
+
return { x, y, w: Math.max(2, Math.min(even((region.w * width) / 1000), width - x)), h: Math.max(2, Math.min(even((region.h * height) / 1000), height - y)) }
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** A row's values: the defaults, then what was given; each checked against its range. @returns {{ values: object } | { problem: string }} */
|
|
90
|
+
export function valuesOf(id, params = {}) {
|
|
91
|
+
const row = EFFECTS[id]
|
|
92
|
+
if (!row) return { problem: `there is no "${id}" effect: ${Object.keys(EFFECTS).join(", ")}` }
|
|
93
|
+
if (params === null || typeof params !== "object" || Array.isArray(params)) return { problem: "an effect's values are named numbers" }
|
|
94
|
+
for (const key of Object.keys(params)) if (!Object.hasOwn(row.params, key)) return { problem: `${row.label} has no value "${key}"` }
|
|
95
|
+
const values = {}
|
|
96
|
+
for (const [key, [min, max, fallback]] of Object.entries(row.params)) {
|
|
97
|
+
const value = params[key] ?? fallback
|
|
98
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < min || value > max) return { problem: `${row.label}'s ${key} is between ${min} and ${max}` }
|
|
99
|
+
values[key] = value
|
|
100
|
+
}
|
|
101
|
+
return { values }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Keyframes checked: keyable params only, at most 16 points, integer flicks in order, values in range, a known ease. */
|
|
105
|
+
export function keysProblem(id, keys) {
|
|
106
|
+
const row = EFFECTS[id]
|
|
107
|
+
if (!Array.isArray(keys)) return "keyframes are a list"
|
|
108
|
+
for (const key of keys) {
|
|
109
|
+
if (!key || !(row.keyable ?? []).includes(key.param)) return `${row.label} can't be keyframed${row.keyable?.length ? ` except ${row.keyable.join(", ")}` : ""}`
|
|
110
|
+
const [min, max] = row.params[key.param]
|
|
111
|
+
if (!Array.isArray(key.points) || key.points.length < 2 || key.points.length > MAX_POINTS) return `keyframes have 2 to ${MAX_POINTS} points`
|
|
112
|
+
let last = -1
|
|
113
|
+
for (const p of key.points) {
|
|
114
|
+
if (!Number.isSafeInteger(p?.at) || p.at < 0 || p.at <= last) return "keyframe times are whole flicks from the effect's start, in order"
|
|
115
|
+
if (typeof p.value !== "number" || p.value < min || p.value > max) return `${key.param} is between ${min} and ${max}`
|
|
116
|
+
if (!EASES.includes(p.ease ?? "linear")) return `an ease is one of ${EASES.join(", ")}`
|
|
117
|
+
last = p.at
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return null
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const EASE = { linear: (u) => u, in: (u) => `(${u})*(${u})`, out: (u) => `(1-(1-(${u}))*(1-(${u})))`, inOut: (u) => `(${u})*(${u})*(3-2*(${u}))`, hold: () => "0" }
|
|
124
|
+
|
|
125
|
+
/** Points → one piecewise expression in the filter's `t`, shifted so 0 is the effect's start (origin, seconds). */
|
|
126
|
+
export function keyExpression(points, origin = 0) {
|
|
127
|
+
const T = origin === 0 ? "t" : `(t-${n(origin)})`
|
|
128
|
+
const secs = (at) => n(at / FLICKS)
|
|
129
|
+
let expr = n(points.at(-1).value)
|
|
130
|
+
for (let i = points.length - 2; i >= 0; i--) {
|
|
131
|
+
const [a, b] = [points[i], points[i + 1]]
|
|
132
|
+
const u = `(${T}-${secs(a.at)})/${secs(b.at - a.at)}`
|
|
133
|
+
expr = `if(lt(${T},${secs(b.at)}),${n(a.value)}+${n(b.value - a.value)}*${EASE[a.ease ?? "linear"](u)},${expr})`
|
|
134
|
+
}
|
|
135
|
+
return `if(lt(${T},${secs(points[0].at)}),${n(points[0].value)},${expr})`
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** A named move expanded over a span (flicks) into keys; null when the move isn't for this effect. */
|
|
139
|
+
export function expandMove(move, id, values, span) {
|
|
140
|
+
const m = MOVES[move]
|
|
141
|
+
if (!m || m.effect !== id || span <= 0) return null
|
|
142
|
+
return [{ param: m.param, points: m.points(span, values[m.param]) }]
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* The filter steps for one stored effect `{ type: "fx", id, params?, keys?, move?, ease? }`.
|
|
147
|
+
* origin: seconds from this chain's 0 to the effect's start; span: its length in flicks.
|
|
148
|
+
* ease (the skin guard's): the effect is mixed back with the picture at that strength.
|
|
149
|
+
*/
|
|
150
|
+
export function fxSteps(fx, { width, height, uid, origin = 0, span = 0 }) {
|
|
151
|
+
const row = EFFECTS[fx.id]
|
|
152
|
+
const { values } = valuesOf(fx.id, fx.params)
|
|
153
|
+
const keys = fx.keys ?? (fx.move ? expandMove(fx.move, fx.id, values, span) : null) ?? []
|
|
154
|
+
const max = { ...values }
|
|
155
|
+
const given = { ...values }
|
|
156
|
+
for (const key of keys) {
|
|
157
|
+
given[key.param] = keyExpression(key.points, origin)
|
|
158
|
+
max[key.param] = Math.max(...key.points.map((p) => p.value))
|
|
159
|
+
}
|
|
160
|
+
let steps
|
|
161
|
+
if (fx.region) {
|
|
162
|
+
// TP9: crop the drawn box, act on it, lay it back exactly where it was; a mask acts outside it instead
|
|
163
|
+
const box = regionPixels(fx.region, width, height)
|
|
164
|
+
const crop = filter("crop", { w: box.w, h: box.h, x: box.x, y: box.y })
|
|
165
|
+
const place = filter("overlay", { x: box.x, y: box.y })
|
|
166
|
+
const i = uid()
|
|
167
|
+
const inner = row.build(given, { width: row.outside ? width : box.w, height: row.outside ? height : box.h, uid, origin, max })
|
|
168
|
+
if (!inner.length) return []
|
|
169
|
+
steps = row.outside ? [`split[ra${i}][rb${i}];[ra${i}]${inner.join(",")}[rc${i}];[rb${i}]${crop}[rd${i}];[rc${i}][rd${i}]${place}`] : [`split[ra${i}][rb${i}];[rb${i}]${crop},${inner.join(",")}[rc${i}];[ra${i}][rc${i}]${place}`]
|
|
170
|
+
} else steps = row.build(given, { width, height, uid, origin, max })
|
|
171
|
+
if (!steps.length || fx.ease === undefined || fx.ease >= 1) return steps
|
|
172
|
+
const i = uid()
|
|
173
|
+
return [`split[sk${i}][sl${i}];[sl${i}]${steps.join(",")}[sm${i}];[sk${i}][sm${i}]${filter("blend", { all_mode: "normal", all_opacity: n(fx.ease) })}`]
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** How strongly the skin guard lets this effect act on a clip with faces: 1, or less with the reason. */
|
|
177
|
+
export function skinEase(fx) {
|
|
178
|
+
const row = EFFECTS[fx.id]
|
|
179
|
+
const moved = row?.skin?.(valuesOf(fx.id, fx.params).values ?? {}) ?? { hue: 0, saturation: 0 }
|
|
180
|
+
const k = Math.min(1, moved.hue > SKIN.hue ? SKIN.hue / moved.hue : 1, moved.saturation > SKIN.saturation ? SKIN.saturation / moved.saturation : 1)
|
|
181
|
+
return k
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** What an effect's span means to the health gate: its planned motion or flash, so neither is a fault. */
|
|
185
|
+
export const gateOf = (id) => EFFECTS[id]?.gate ?? null
|
package/src/edit/core/ffmpeg.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { secondsArg } from "./time.js"
|
|
5
5
|
import { TRANSITIONS } from "./transitions.js"
|
|
6
|
+
import { fxSteps } from "./effects.js"
|
|
6
7
|
|
|
7
8
|
const BT709 = ["-colorspace", "bt709", "-color_primaries", "bt709", "-color_trc", "bt709", "-color_range", "tv"]
|
|
8
9
|
// On the frames too: FFmpeg can drop the output flags alone when it converts a format
|
|
@@ -82,7 +83,22 @@ export function colourSteps(color, toneMap) {
|
|
|
82
83
|
return [filter("scale", { in_color_matrix: "bt2020", in_range: "tv", out_range: "pc" }), "format=gbrp16le", filter("lut3d", { file: toneMap(color.transfer) }), filter("scale", { out_color_matrix: "bt709", out_range: "tv" }), "format=yuv420p"]
|
|
83
84
|
}
|
|
84
85
|
|
|
85
|
-
|
|
86
|
+
export const PLATE = "0x101014" // the bars of a fitted picture: near black, as the Studio's stage is
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The `frame` effect (TP2, ASSEMBLY_AND_INTENT §6.2): the whole picture inside the frame. `fit` puts
|
|
90
|
+
* it on bars; `blur` puts it over a blurred, darkened copy of itself that fills the frame. One
|
|
91
|
+
* step of a comma chain: the blur's two branches carry labels of their own (`n` keeps them apart).
|
|
92
|
+
* shortcut: the bars are one colour, not the look's plate; a look that sets one replaces PLATE
|
|
93
|
+
*/
|
|
94
|
+
export function frameSteps(frame, width, height, n) {
|
|
95
|
+
const whole = filter("scale", { w: width, h: height, force_original_aspect_ratio: "decrease", force_divisible_by: 2 })
|
|
96
|
+
if (frame.mode === "fit") return [whole, filter("pad", { w: width, h: height, x: "(ow-iw)/2", y: "(oh-ih)/2", color: PLATE })]
|
|
97
|
+
const behind = [filter("scale", { w: width, h: height, force_original_aspect_ratio: "increase" }), filter("crop", { w: width, h: height }), filter("boxblur", { luma_radius: Math.max(2, Math.round(Math.min(width, height) / 24)), luma_power: 2 }), filter("eq", { brightness: -0.12, saturation: 0.9 })].join(",")
|
|
98
|
+
return [`split[fa${n}][fb${n}];[fa${n}]${behind}[fbg${n}];[fb${n}]${whole}[ffg${n}];[fbg${n}][ffg${n}]${filter("overlay", { x: "(W-w)/2", y: "(H-h)/2" })}`]
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function pictureChain(item, width, height, plan, { input, toneMap, uid }) {
|
|
86
102
|
const steps = []
|
|
87
103
|
// The input already seeks to item.in, so a long file isn't decoded from its start
|
|
88
104
|
if (item.hold) {
|
|
@@ -94,12 +110,17 @@ function pictureChain(item, width, height, plan, { input, toneMap }) {
|
|
|
94
110
|
steps.push(...colourSteps(item.color, toneMap))
|
|
95
111
|
if (item.crop?.length) steps.push(filter("crop", { w: `ih*${plan.canvas.width}/${plan.canvas.height}`, h: "ih", x: cropX(item.crop, item.in), y: 0 }))
|
|
96
112
|
if (item.zoom && !animatedZoom(item.zoom)) steps.push(filter("crop", { w: `iw/${item.zoom.scale}`, h: `ih/${item.zoom.scale}` }))
|
|
97
|
-
|
|
113
|
+
const frame = item.effects.find((e) => e.type === "frame")
|
|
114
|
+
if (frame) steps.push(...frameSteps(frame, width, height, uid?.() ?? 0))
|
|
115
|
+
else steps.push(filter("scale", { w: width, h: height, force_original_aspect_ratio: "increase" }), filter("crop", { w: width, h: height }))
|
|
98
116
|
if (animatedZoom(item.zoom)) steps.push(...zoomSteps(item.zoom, width, height, plan.output.fps))
|
|
99
117
|
for (const effect of item.effects) {
|
|
100
118
|
if (effect.type === "lut") steps.push(filter("lut3d", { file: input(effect.asset) }))
|
|
101
119
|
else if (effect.type === "grade") steps.push(...gradeSteps(effect, input))
|
|
102
|
-
|
|
120
|
+
// TP5: a registry effect, from numbers only; stabilize drawn at last (EH-57: the operation always stored it)
|
|
121
|
+
else if (effect.type === "fx") steps.push(...fxSteps(effect, { width, height, uid: uid ?? (() => 0), origin: effect.origin ?? 0, span: effect.span ?? 0 }))
|
|
122
|
+
else if (effect.type === "stabilize") steps.push("deshake")
|
|
123
|
+
else if (effect.type !== "reframe" && effect.type !== "frame") throw new RangeError(`this render can't do ${effect.type} yet`)
|
|
103
124
|
}
|
|
104
125
|
// Square pixels on every piece: a zoom's crop leaves a fractional aspect, and concat refuses a mix (found in ED7)
|
|
105
126
|
steps.push("setsar=1", TAG_BT709)
|
|
@@ -137,6 +158,8 @@ export function segmentArgs(plan, segment, { input, tile, output, encoder, toneM
|
|
|
137
158
|
const { node } = segment
|
|
138
159
|
const inputs = []
|
|
139
160
|
const inputFor = (path, seek = null) => inputs.push({ path: absolute(path), seek }) - 1
|
|
161
|
+
let framed = 0
|
|
162
|
+
const uid = () => framed++ // a label for each framed picture's two branches
|
|
140
163
|
const tiles = node.tiles
|
|
141
164
|
.map((part) => ({ ...plan.tiles.find((t) => t.key === part.key), ...part }))
|
|
142
165
|
.filter((part) => !without?.(part))
|
|
@@ -146,7 +169,7 @@ export function segmentArgs(plan, segment, { input, tile, output, encoder, toneM
|
|
|
146
169
|
const chains = []
|
|
147
170
|
|
|
148
171
|
const labels = node.picture.map((item, i) => {
|
|
149
|
-
const chain = `[${inputFor(input(item.asset), item.in)}:v]${pictureChain(item, width, height, plan, { input, toneMap })}`
|
|
172
|
+
const chain = `[${inputFor(input(item.asset), item.in)}:v]${pictureChain(item, width, height, plan, { input, toneMap, uid })}`
|
|
150
173
|
if (!item.enter) {
|
|
151
174
|
chains.push(`${chain}[p${i}]`)
|
|
152
175
|
return `[p${i}]`
|
|
@@ -159,7 +182,7 @@ export function segmentArgs(plan, segment, { input, tile, output, encoder, toneM
|
|
|
159
182
|
// xfade needs both sides alike: one frame rate, one pixel format, one time base
|
|
160
183
|
const alike = `${filter("fps", { fps: `${plan.output.fps.n}/${plan.output.fps.d}` })},format=yuv420p,settb=AVTB`
|
|
161
184
|
chains.push(`${chain},${alike},split[ph${i}][pt${i}]`)
|
|
162
|
-
chains.push(`[${inputFor(input(from.asset), from.in)}:v]${pictureChain(from, width, height, plan, { input, toneMap })},${alike}[pf${i}]`)
|
|
185
|
+
chains.push(`[${inputFor(input(from.asset), from.in)}:v]${pictureChain(from, width, height, plan, { input, toneMap, uid })},${alike}[pf${i}]`)
|
|
163
186
|
chains.push(`[ph${i}]${filter("trim", { end: length })},setpts=PTS-STARTPTS[pa${i}]`)
|
|
164
187
|
chains.push(`[pf${i}][pa${i}]${filter("xfade", { transition: TRANSITIONS[kind], duration: length, offset: 0 })}[px${i}]`)
|
|
165
188
|
chains.push(`[pt${i}]${filter("trim", { start: length })},setpts=PTS-STARTPTS[pb${i}]`)
|
|
@@ -180,10 +203,19 @@ export function segmentArgs(plan, segment, { input, tile, output, encoder, toneM
|
|
|
180
203
|
current = next
|
|
181
204
|
}
|
|
182
205
|
node.overlays.forEach((item, i) => {
|
|
183
|
-
chains.push(`[${inputFor(input(item.asset), item.in)}:v]${pictureChain(item, width, height, plan, { input, toneMap })},setpts=PTS+${secondsArg(item.at)}/TB[o${i}]`)
|
|
206
|
+
chains.push(`[${inputFor(input(item.asset), item.in)}:v]${pictureChain(item, width, height, plan, { input, toneMap, uid })},setpts=PTS+${secondsArg(item.at)}/TB[o${i}]`)
|
|
184
207
|
layer(`[o${i}]`, item.at, item.end)
|
|
185
208
|
})
|
|
186
209
|
|
|
210
|
+
// An effect over a stretch of the cut (TP5): the picture split, the effect on one copy, laid back over its window
|
|
211
|
+
for (const [i, adjust] of (node.adjust ?? []).entries()) {
|
|
212
|
+
const steps = fxSteps(adjust.fx, { width, height, uid, origin: adjust.fx.origin ?? 0, span: adjust.fx.span ?? 0 })
|
|
213
|
+
if (!steps.length) continue
|
|
214
|
+
chains.push(`${current}split[aj${i}][ak${i}]`, `[ak${i}]${steps.join(",")}[al${i}]`)
|
|
215
|
+
current = `[aj${i}]`
|
|
216
|
+
layer(`[al${i}]`, adjust.at, adjust.end)
|
|
217
|
+
}
|
|
218
|
+
|
|
187
219
|
// The speaker, cut from the picture before anything covers it, goes back over the text behind
|
|
188
220
|
const mattes = node.mattes ?? []
|
|
189
221
|
const keeps = []
|
|
@@ -222,6 +254,33 @@ export function segmentArgs(plan, segment, { input, tile, output, encoder, toneM
|
|
|
222
254
|
}
|
|
223
255
|
if (!matted) drawMattes()
|
|
224
256
|
|
|
257
|
+
// TP7 (CRAFT §5.4): the type kit's bar and logo bug, over everything and across the cut, so each
|
|
258
|
+
// segment draws its share of them on the cut's own clock (from: where this segment starts)
|
|
259
|
+
if (node.brand) {
|
|
260
|
+
const { bar, bug, from } = node.brand
|
|
261
|
+
const draw = (chain) => {
|
|
262
|
+
const next = `[v${step++}]`
|
|
263
|
+
chains.push(`${current}${chain}${next}`)
|
|
264
|
+
current = next
|
|
265
|
+
}
|
|
266
|
+
if (bar) {
|
|
267
|
+
const h = Math.max(4, Math.round(height * 0.008))
|
|
268
|
+
const y = height > width ? 0 : height - h
|
|
269
|
+
const total = secondsArg(bar.total)
|
|
270
|
+
draw(filter("drawbox", { x: 0, y, w: width, h, color: `${bar.track}@0.35`, t: "fill" }))
|
|
271
|
+
chains.push(`${filter("color", { c: bar.color, s: `${width}x${h}`, r: `${plan.output.fps.n}/${plan.output.fps.d}`, d: secondsArg(segment.end - segment.start) })}[bar]`)
|
|
272
|
+
// The filled part grows with the cut's time: this segment's t plus where it starts
|
|
273
|
+
draw(`[bar]${filter("overlay", { x: `-${width}+${width}*(t+${secondsArg(from)})/${total}`, y, eval: "frame" })}`)
|
|
274
|
+
for (const at of bar.chapters ?? []) draw(filter("drawbox", { x: Math.max(0, Math.round((width * at) / bar.total) - 1), y, w: Math.max(2, Math.round(h * 0.6)), h, color: bar.track, t: "fill" }))
|
|
275
|
+
}
|
|
276
|
+
if (bug) {
|
|
277
|
+
const side = Math.round(Math.min(width, height) * 0.11)
|
|
278
|
+
const margin = Math.round(Math.min(width, height) * 0.04)
|
|
279
|
+
chains.push(`[${inputFor(input(bug.asset))}:v]${filter("scale", { w: side, h: side, force_original_aspect_ratio: "decrease" })},format=rgba[bug]`)
|
|
280
|
+
draw(`[bug]${filter("overlay", { x: bug.corner.endsWith("r") ? `W-w-${margin}` : margin, y: bug.corner.startsWith("b") ? `H-h-${margin}` : margin, eof_action: "repeat" })}`)
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
225
284
|
const head = ["-nostdin", "-hide_banner", ...inputs.flatMap(({ path, seek }) => [...(seek === null ? [] : ["-ss", secondsArg(seek)]), "-protocol_whitelist", "file,pipe", "-i", path])]
|
|
226
285
|
if (frames) {
|
|
227
286
|
chains.push(`${current}${filter("select", { expr: frames.map((n) => `eq(n,${n})`).join("+") })},format=rgb24[still]`)
|
package/src/edit/core/layout.js
CHANGED
|
@@ -54,13 +54,58 @@ export function sceneFrame(canvas, safe, caption) {
|
|
|
54
54
|
|
|
55
55
|
const overlaps =(a, b) => a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h
|
|
56
56
|
|
|
57
|
+
/**
|
|
58
|
+
* TP7 (CRAFT_UPGRADE §5.4): the boxes motion kit 2 needs, by the graphic's kind. "full" covers
|
|
59
|
+
* the frame like a scene; "frame" is a border round the whole picture, with no text; "third",
|
|
60
|
+
* "corner" and "point" are placed by the solver, still clear of faces (a point marks one), safe
|
|
61
|
+
* zones and captions. A kind not here is a caption-sized row, as before.
|
|
62
|
+
* size: shares of the frame (w of the safe width or the frame's width, h of its height)
|
|
63
|
+
*/
|
|
64
|
+
export const REGIONS = {
|
|
65
|
+
card: { region: "full" },
|
|
66
|
+
frame: { region: "frame" },
|
|
67
|
+
list: { region: "third", w: 0.9, h: 0.36 },
|
|
68
|
+
count: { region: "third", w: 0.7, h: 0.16 },
|
|
69
|
+
cta: { region: "third", w: 0.86, h: 0.15 },
|
|
70
|
+
handle: { region: "corner", w: 0.5, h: 0.075 },
|
|
71
|
+
callout: { region: "point", w: 0.26, h: 0.26 },
|
|
72
|
+
}
|
|
73
|
+
const CORNER_ORDER = ["tr", "tl", "br", "bl"]
|
|
74
|
+
|
|
75
|
+
/** A kit-2 item's own places, cheapest first; faces are cleared, except by a callout, which points at one. */
|
|
76
|
+
function regionCandidates(item, { canvas, safe }) {
|
|
77
|
+
const { top = 0, right = 0, bottom = 0, left = 0 } = safe
|
|
78
|
+
const W = canvas.width - left - right
|
|
79
|
+
const H = canvas.height - top - bottom
|
|
80
|
+
const w = Math.min(item.w, W)
|
|
81
|
+
const h = Math.min(item.h, H)
|
|
82
|
+
let boxes = []
|
|
83
|
+
if (item.region === "third") {
|
|
84
|
+
const x = left + Math.floor((W - w) / 2)
|
|
85
|
+
boxes = [top + H - h, top + Math.floor((H - h) / 2), top].map((y) => ({ x, y, w, h }))
|
|
86
|
+
} else if (item.region === "corner") {
|
|
87
|
+
const at = { tl: { x: left, y: top }, tr: { x: left + W - w, y: top }, bl: { x: left, y: top + H - h }, br: { x: left + W - w, y: top + H - h } }
|
|
88
|
+
const order = [item.corner, ...CORNER_ORDER.filter((c) => c !== item.corner)].filter(Boolean)
|
|
89
|
+
boxes = order.map((c) => ({ ...at[c], w, h }))
|
|
90
|
+
} else if (item.region === "point") {
|
|
91
|
+
const side = Math.min(w, h)
|
|
92
|
+
const p = item.point ?? { x: Math.round(canvas.width / 2), y: Math.round(canvas.height / 2) }
|
|
93
|
+
const x = Math.min(Math.max(left, Math.round(p.x - side / 2)), left + W - side)
|
|
94
|
+
const y = Math.min(Math.max(top, Math.round(p.y - side / 2)), top + H - side)
|
|
95
|
+
return [{ box: { x, y, w: side, h: side }, cost: 0 }]
|
|
96
|
+
}
|
|
97
|
+
return boxes.map((box, i) => ({ box, cost: i * Math.round(canvas.height / 4) })).filter(({ box }) => !(item.faces ?? []).some((face) => overlaps(box, face)))
|
|
98
|
+
}
|
|
99
|
+
|
|
57
100
|
function candidates(item, { canvas, safe, prefer }) {
|
|
58
101
|
if (item.fixed) return [{ box: item.fixed, cost: 0 }]
|
|
102
|
+
if (item.region) return regionCandidates(item, { canvas, safe })
|
|
59
103
|
const { top = 0, right = 0, bottom = 0, left = 0 } = safe
|
|
60
104
|
const width = canvas.width - left - right
|
|
61
105
|
const last = canvas.height - bottom - item.h
|
|
62
106
|
if (item.w > width || last < top) return []
|
|
63
|
-
|
|
107
|
+
// A look that sits higher (TP7's caption looks) asks for its own row; others use the recipe's
|
|
108
|
+
const wanted = Math.round((canvas.height * (item.prefer ?? prefer)) / 100)
|
|
64
109
|
const rows = new Set([Math.min(last, Math.max(top, wanted))])
|
|
65
110
|
for (let i = 0; i < ROWS; i++) rows.add(top + Math.floor(((last - top) * i) / (ROWS - 1)))
|
|
66
111
|
const x = left + Math.floor((width - item.w) / 2)
|