@kriya-ai/harness 0.2.4 → 2.0.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/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 +49 -0
- package/contract/SOURCE.md +3 -3
- package/contract/contract.json +504 -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 +376 -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 +426 -0
- package/plugins/runstrip/index.js +301 -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 +82 -5
- package/src/edit/core/layout.js +46 -1
- package/src/edit/core/ops.js +175 -3
- package/src/edit/core/plan.js +95 -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/transitions.js +17 -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 +137 -0
- package/src/edit/director/custom-motion.js +88 -0
- package/src/edit/director/graphics.js +186 -0
- package/src/edit/director/intent.js +125 -0
- package/src/edit/director/mentions.js +52 -0
- package/src/edit/director/plan.js +89 -12
- package/src/edit/director/revise.js +172 -7
- 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 +439 -0
- package/src/edit/engine/index.js +14 -5
- package/src/edit/engine/motion.js +153 -14
- 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 +76 -8
- package/src/edit/gates/picture.js +6 -3
- package/src/edit/gates/reference.js +115 -0
- package/src/edit/gates/tile.js +96 -0
- package/src/edit/host/client.js +4 -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 +17 -7
- package/src/edit/host/paths.js +34 -3
- package/src/edit/host/preview.js +108 -0
- package/src/edit/host/projects.js +494 -29
- package/src/edit/host/server.js +263 -19
- package/src/edit/host/tavi.js +77 -0
- package/src/edit/loop/make.js +44 -3
- package/src/edit/recipes/assembly.js +352 -0
- package/src/edit/recipes/graphic-clips.js +59 -0
- package/src/edit/recipes/openings.js +36 -0
- package/src/edit/recipes/reel.js +138 -17
- 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 -3
- 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 +407 -0
- package/src/gates/ui.js +111 -0
- package/src/launch.js +15 -3
- package/src/loop.js +199 -7
- package/src/mcp.js +126 -0
- package/src/milestones.js +188 -0
- package/src/modes.js +32 -0
- package/src/orchestra.js +43 -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 +452 -3
- package/studio/dist/studio.js +3 -3
package/src/edit/core/ops.js
CHANGED
|
@@ -3,8 +3,12 @@
|
|
|
3
3
|
// no inverse per operation: history moves HEAD and replays (history.js).
|
|
4
4
|
|
|
5
5
|
import { anchorSource, openIndex, wordAfter, wordAt, wordBefore } from "./anchors.js"
|
|
6
|
-
import {
|
|
6
|
+
import { TRANSITION_MAX, TRANSITION_MIN, TRANSITIONS } from "./transitions.js"
|
|
7
|
+
import { check, cleanLabel, EFFECTS, KEYS, SHAPES, validateProject } from "./project.js"
|
|
7
8
|
import { snapToFrame } from "./time.js"
|
|
9
|
+
import { AGENT_CAP_PER_MINUTE, EFFECTS as FX, keysProblem, MOVES, regionOf, valuesOf } from "./effects.js"
|
|
10
|
+
import { STYLE_PACKS } from "./style-packs.js"
|
|
11
|
+
import { cleanTypeKit } from "./type-kit.js"
|
|
8
12
|
|
|
9
13
|
class Refused extends Error {
|
|
10
14
|
constructor(code, message) {
|
|
@@ -366,7 +370,11 @@ const OPS = {
|
|
|
366
370
|
transition: {
|
|
367
371
|
fields: { clip: "id", kind: "str", duration: "flicks" },
|
|
368
372
|
run(op, s) {
|
|
369
|
-
|
|
373
|
+
if (!Object.hasOwn(TRANSITIONS, op.kind)) refuse("unknown_transition", `there is no "${op.kind}" transition: ${Object.keys(TRANSITIONS).join(", ")}`)
|
|
374
|
+
if (op.duration < TRANSITION_MIN || op.duration > TRANSITION_MAX) refuse("bad_duration", "a transition lasts 0.2 to 0.8 seconds")
|
|
375
|
+
const clip = writable(s, op.clip)
|
|
376
|
+
if (!clip.source) refuse("not_footage", `clip "${op.clip}" isn't footage, so nothing can transition into it`)
|
|
377
|
+
setEffect(clip, { type: "transition", kind: op.kind, duration: op.duration })
|
|
370
378
|
},
|
|
371
379
|
},
|
|
372
380
|
stabilize: {
|
|
@@ -622,7 +630,171 @@ const CODE_OPS = {
|
|
|
622
630
|
},
|
|
623
631
|
}
|
|
624
632
|
|
|
625
|
-
|
|
633
|
+
// TP1 (ASSEMBLY_AND_INTENT §2, §3). Kept out of OPS: the Director's operation list and the
|
|
634
|
+
// console's schema are the objects they were (TOP_TIER_FORENSIC_AUDIT §6 rule 1)
|
|
635
|
+
const SPINE = ["story", "whole"]
|
|
636
|
+
const ASSEMBLY_MAX = { parts: 200, files: 64 }
|
|
637
|
+
const ASSEMBLY_OPS = {
|
|
638
|
+
describe_asset: {
|
|
639
|
+
fields: { asset: "id", "label?": "str", "role?": SHAPES.project.assets.list["role?"] },
|
|
640
|
+
run(op, s) {
|
|
641
|
+
if (op.label === undefined && op.role === undefined) refuse("needs_a_value", "give a label or a role")
|
|
642
|
+
if (op.label !== undefined && s.author !== "person") refuse("person_only", "a clip's label is the person's to set")
|
|
643
|
+
if (s.author === "agent") refuse("person_only", "a clip's role is set by the person, or by code from the index")
|
|
644
|
+
const asset = assetOf(s, op.asset)
|
|
645
|
+
if (asset.kind === "reference") refuse("wrong_asset_kind", `asset "${op.asset}" is a reference, not a clip`)
|
|
646
|
+
// Cleaned here, so the stored label is already data (EH-71); an empty one takes the label away
|
|
647
|
+
const label = op.label === undefined ? undefined : cleanLabel(op.label)
|
|
648
|
+
if (label) asset.label = label
|
|
649
|
+
else if (label === "") delete asset.label
|
|
650
|
+
if (op.role !== undefined) asset.role = op.role
|
|
651
|
+
},
|
|
652
|
+
},
|
|
653
|
+
set_assembly: {
|
|
654
|
+
fields: { assembly: SHAPES.project.sequences.list["assembly?"] },
|
|
655
|
+
run(op, s) {
|
|
656
|
+
const { version, parts } = op.assembly
|
|
657
|
+
if (version !== 1) refuse("bad_assembly", "this storyboard is a version this Kriya doesn't know")
|
|
658
|
+
if (parts.length > ASSEMBLY_MAX.parts) refuse("too_many_parts", `a storyboard holds up to ${ASSEMBLY_MAX.parts} parts`)
|
|
659
|
+
if (new Set(parts.map((part) => part.asset)).size > ASSEMBLY_MAX.files) refuse("too_many_files", `a storyboard uses up to ${ASSEMBLY_MAX.files} files`)
|
|
660
|
+
const ids = new Set()
|
|
661
|
+
for (const part of parts) {
|
|
662
|
+
if (ids.has(part.id)) refuse("duplicate_part", `two parts are called "${part.id}"`)
|
|
663
|
+
ids.add(part.id)
|
|
664
|
+
// A reference's kind is "reference", so it's refused here: measured, never placed (EDD-23)
|
|
665
|
+
const asset = assetOf(s, part.asset, SEQUENCED)
|
|
666
|
+
if (part.from === undefined && part.to === undefined) continue
|
|
667
|
+
const to = part.to === undefined ? asset.facts.duration : sourceEdge(s, part.to, asset.id, "end")
|
|
668
|
+
if (to === undefined) refuse("not_probed", `asset "${asset.id}" has no length, so a part of it can't be taken`)
|
|
669
|
+
checkRange(s, asset, part.from === undefined ? 0 : sourceEdge(s, part.from, asset.id, "start"), to)
|
|
670
|
+
}
|
|
671
|
+
const spine = new Set(parts.filter((part) => SPINE.includes(part.use)).map((part) => part.id))
|
|
672
|
+
for (const part of parts) {
|
|
673
|
+
if (SPINE.includes(part.use)) {
|
|
674
|
+
if (part.at !== undefined) refuse("bad_part", `part "${part.id}" is in the film's order, so it has no "at"`)
|
|
675
|
+
continue
|
|
676
|
+
}
|
|
677
|
+
if (part.at === undefined && part.use === "sound") continue // a song under the whole film
|
|
678
|
+
if (!part.at || !spine.has(part.at.part)) refuse("no_host", `part "${part.id}" plays over another part: name one that is in the film's order`)
|
|
679
|
+
if (["where", "word", "t"].filter((key) => part.at[key] !== undefined).length !== 1) refuse("bad_part", `part "${part.id}" needs one place: where, word or t`)
|
|
680
|
+
if (part.at.word !== undefined) known(s, { word: part.at.word })
|
|
681
|
+
}
|
|
682
|
+
// No parts is no storyboard: the key goes, so the project is what it was before one
|
|
683
|
+
if (parts.length) sequenceOf(s).assembly = { version, parts }
|
|
684
|
+
else delete sequenceOf(s).assembly
|
|
685
|
+
},
|
|
686
|
+
},
|
|
687
|
+
// TP2: a part's picture over another part's voice. place_broll as it is, and the clip carries
|
|
688
|
+
// the make's mark, so a remake finds it and never places it twice (EH-60)
|
|
689
|
+
place_over: {
|
|
690
|
+
fields: OPS.place_broll.fields,
|
|
691
|
+
run(op, s) {
|
|
692
|
+
OPS.place_broll.run(op, s)
|
|
693
|
+
sequenceOf(s).clips.at(-1).plan = true
|
|
694
|
+
},
|
|
695
|
+
},
|
|
696
|
+
// TP2: how a clip of another shape sits in the frame. fill takes the effect away (EH-59)
|
|
697
|
+
set_frame: {
|
|
698
|
+
fields: { clip: "id", mode: { enum: ["fill", "fit", "blur"] } },
|
|
699
|
+
run(op, s) {
|
|
700
|
+
const clip = writable(s, op.clip)
|
|
701
|
+
if (!clip.source || !PICTURE.includes(assetOf(s, clip.source.asset).kind)) refuse("not_footage", `clip "${op.clip}" has no picture to frame`)
|
|
702
|
+
if (op.mode === "fill") clip.effects = clip.effects.filter((e) => e.type !== "frame")
|
|
703
|
+
else setEffect(clip, { type: "frame", mode: op.mode })
|
|
704
|
+
},
|
|
705
|
+
},
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
// TP5 (CRAFT_UPGRADE §3, EDD-64), behind editing.craft: an effect from the registry on a clip, or on a
|
|
709
|
+
// stretch of the cut. Refused unless the id, every value and every keyframe is one the render draws.
|
|
710
|
+
// An agent is held to restraint (§3.5): never two heavy effects at once, a few a minute; the person never is
|
|
711
|
+
function checkFx(op, span) {
|
|
712
|
+
const { values, problem } = valuesOf(op.effect, op.params ?? {})
|
|
713
|
+
if (problem) refuse("bad_effect", problem)
|
|
714
|
+
if (op.keys !== undefined && op.move !== undefined) refuse("bad_effect", "give keyframes or a named move, not both")
|
|
715
|
+
if (op.keys !== undefined) {
|
|
716
|
+
const why = keysProblem(op.effect, op.keys)
|
|
717
|
+
if (why) refuse("bad_keyframes", why)
|
|
718
|
+
if (span !== null && op.keys.some((k) => k.points.at(-1).at > span)) refuse("bad_keyframes", "a keyframe falls after the effect ends")
|
|
719
|
+
}
|
|
720
|
+
if (op.move !== undefined && MOVES[op.move]?.effect !== op.effect) refuse("bad_move", `"${op.move}" isn't a move of ${FX[op.effect].label}: ${Object.entries(MOVES).filter(([, m]) => m.effect === op.effect).map(([id]) => id).join(", ") || "it has none"}`)
|
|
721
|
+
// TP9: a drawn region, whole thousandths of the frame, inside it; only on effects that can act on part of it
|
|
722
|
+
const region = op.region === undefined ? null : regionOf(op.region)
|
|
723
|
+
if (op.region !== undefined && !region) refuse("bad_region", "a region is whole thousandths of the frame: x, y, w and h, inside it, each side at least 10")
|
|
724
|
+
if (region && !FX[op.effect].region) refuse("bad_region", `${FX[op.effect].label} acts on the whole frame: ${Object.entries(FX).filter(([, row]) => row.region).map(([id]) => id).join(", ")} can take a region`)
|
|
725
|
+
if (FX[op.effect].needsRegion && !region) refuse("needs_region", `${FX[op.effect].label} needs a region drawn on the frame`)
|
|
726
|
+
return { type: "fx", id: op.effect, ...(op.params && Object.keys(op.params).length ? { params: values } : {}), ...(op.keys ? { keys: op.keys } : {}), ...(op.move ? { move: op.move } : {}), ...(region ? { region } : {}) }
|
|
727
|
+
}
|
|
728
|
+
function restrain(s, fx, { clip, window }) {
|
|
729
|
+
if (s.author !== "agent") return fx
|
|
730
|
+
const clips = sequenceOf(s).clips
|
|
731
|
+
const added = clips.flatMap((c) => c.effects.filter((e) => e.type === "fx" && e.by === "agent").map((e) => ({ c, e })))
|
|
732
|
+
const length = clips.filter((c) => c.source && !c.at).reduce((sum, c) => sum + (c.source.out - c.source.in), 0)
|
|
733
|
+
if (added.length >= AGENT_CAP_PER_MINUTE * Math.max(1, Math.ceil(length / (60 * 705_600_000)))) refuse("restraint", `Kriya adds at most ${AGENT_CAP_PER_MINUTE} effects a minute; the rest are yours to ask for`)
|
|
734
|
+
if (FX[fx.id].weight === "heavy") {
|
|
735
|
+
const heavy = added.filter(({ e }) => FX[e.id]?.weight === "heavy")
|
|
736
|
+
const overlaps = ({ c }) => (clip ? c.id === clip.id : c.at !== null && window && (typeof c.at === "number" && typeof window.at === "number" ? c.at < window.at + window.length && window.at < c.at + (c.duration ?? Infinity) : JSON.stringify(c.at) === JSON.stringify(window.at)))
|
|
737
|
+
if (heavy.some(overlaps)) refuse("restraint", "two heavy effects at once is too much: one at a time")
|
|
738
|
+
}
|
|
739
|
+
return { ...fx, by: "agent" }
|
|
740
|
+
}
|
|
741
|
+
const CRAFT_OPS = {
|
|
742
|
+
add_effect: {
|
|
743
|
+
fields: { clip: "id", effect: "id", "params?": "plain", "keys?": KEYS, "move?": "str", "region?": "plain" },
|
|
744
|
+
run(op, s) {
|
|
745
|
+
const clip = writable(s, op.clip)
|
|
746
|
+
if (!clip.source || !PICTURE.includes(assetOf(s, clip.source.asset).kind)) refuse("not_footage", `clip "${op.clip}" has no picture for an effect`)
|
|
747
|
+
const rate = clip.speed ?? { n: 1, d: 1 }
|
|
748
|
+
const fx = restrain(s, checkFx(op, Math.round(((clip.source.out - clip.source.in) * rate.d) / rate.n)), { clip })
|
|
749
|
+
// One of each effect per clip: the same id again replaces it
|
|
750
|
+
clip.effects = [...clip.effects.filter((e) => !(e.type === "fx" && e.id === fx.id)), fx]
|
|
751
|
+
},
|
|
752
|
+
},
|
|
753
|
+
add_adjustment: {
|
|
754
|
+
fields: { at: "ref", effect: "id", "params?": "plain", "keys?": KEYS, "move?": "str", "region?": "plain", ...SPAN },
|
|
755
|
+
run(op, s) {
|
|
756
|
+
known(s, op.at)
|
|
757
|
+
const length = op.duration ?? null
|
|
758
|
+
const fx = restrain(s, checkFx(op, length), { window: { at: op.at, length: length ?? 0 } })
|
|
759
|
+
addClip(s, "overlay", { at: op.at, ...span(s, op), effects: [fx] })
|
|
760
|
+
},
|
|
761
|
+
},
|
|
762
|
+
remove_effect: {
|
|
763
|
+
fields: { clip: "id", effect: "id" },
|
|
764
|
+
run(op, s) {
|
|
765
|
+
const clip = writable(s, op.clip)
|
|
766
|
+
if (!clip.effects.some((e) => e.type === "fx" && e.id === op.effect)) refuse("no_effect", `clip "${op.clip}" has no ${FX[op.effect]?.label ?? op.effect} effect`)
|
|
767
|
+
clip.effects = clip.effects.filter((e) => !(e.type === "fx" && e.id === op.effect))
|
|
768
|
+
},
|
|
769
|
+
},
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
// TP7 (CRAFT_UPGRADE §5.2, EDD-67), behind editing.typeKit: the film's type kit, the person's colours,
|
|
773
|
+
// a logo bug and a bar, stored in look.brand.type. Only the person (or the make of a plan they approved)
|
|
774
|
+
// sets it, so a project nobody chose a kit for keeps the system stacks (EH-69); `clear` goes back to them
|
|
775
|
+
const TYPE_OPS = {
|
|
776
|
+
set_type_kit: {
|
|
777
|
+
fields: { "pair?": "str", "colors?": "plain", "logo?": "str", "corner?": "str", "bar?": "str", "pack?": "str", "clear?": "bool" },
|
|
778
|
+
run({ op: _, clear, ...raw }, s) {
|
|
779
|
+
if (s.author === "agent") refuse("person_only", "the type kit is the person's to choose")
|
|
780
|
+
const brand = { ...s.project.look.brand }
|
|
781
|
+
if (clear === true) {
|
|
782
|
+
delete brand.type
|
|
783
|
+
s.project.look.brand = brand
|
|
784
|
+
return
|
|
785
|
+
}
|
|
786
|
+
const { kit, problem } = cleanTypeKit(raw, { packs: STYLE_PACKS })
|
|
787
|
+
if (problem || !kit) refuse("bad_type_kit", problem ?? "a type kit needs a pair")
|
|
788
|
+
// A person's own PNG comes into the bin as a picture with a width, so a logo is either kind of picture
|
|
789
|
+
if (kit.logo) assetOf(s, kit.logo, PICTURE)
|
|
790
|
+
s.project.look.brand = { ...brand, type: kit }
|
|
791
|
+
},
|
|
792
|
+
},
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
const ALL_OPS = { ...OPS, ...CODE_OPS, ...ASSEMBLY_OPS, ...CRAFT_OPS, ...TYPE_OPS }
|
|
796
|
+
export const CRAFT_OP_NAMES = Object.keys(CRAFT_OPS)
|
|
797
|
+
export const TYPE_OP_NAMES = Object.keys(TYPE_OPS)
|
|
626
798
|
|
|
627
799
|
function captionOf(s, id) {
|
|
628
800
|
const caption = writable(s, id).effects.find((e) => e.type === "caption")
|
package/src/edit/core/plan.js
CHANGED
|
@@ -7,11 +7,14 @@ import { outputFaces, unionBox } from "./faces.js"
|
|
|
7
7
|
import { canonical, sha256 } from "./project.js"
|
|
8
8
|
import { solveReframe } from "./reframe.js"
|
|
9
9
|
import { solve } from "./solver.js"
|
|
10
|
-
import {
|
|
10
|
+
import { EFFECTS as FX, skinEase } from "./effects.js"
|
|
11
|
+
import { against, kitNode, typeKitOf } from "./type-kit.js"
|
|
12
|
+
import { flicksToFrames, FLICKS, frameFlicks, framesToFlicks, scaleFlicks, snapToFrame } from "./time.js"
|
|
11
13
|
|
|
12
14
|
const MAX_SEGMENT = 6 * FLICKS
|
|
13
15
|
const DRAFT_SHORT_SIDE = 720
|
|
14
|
-
|
|
16
|
+
// A transition isn't an effect on the piece's own frames: it becomes the piece's `enter` below
|
|
17
|
+
const PICTURE_EFFECTS = new Set(["reframe", "grade", "lut", "stabilize", "fade", "frame", "fx"])
|
|
15
18
|
const AUDIO_EFFECTS = new Set(["level", "eq", "duck", "fade", "fit"])
|
|
16
19
|
|
|
17
20
|
const even = (value) => Math.round(value / 2) * 2
|
|
@@ -72,6 +75,14 @@ function zoomNode(zoom, start) {
|
|
|
72
75
|
return node
|
|
73
76
|
}
|
|
74
77
|
|
|
78
|
+
// The crop's x at one moment of a path: the same straight lines ffmpeg.js draws between its points
|
|
79
|
+
function cropAt(path, t) {
|
|
80
|
+
const after = path.findIndex((point) => point.t >= t)
|
|
81
|
+
if (after <= 0) return path[after === 0 ? 0 : path.length - 1].x
|
|
82
|
+
const [a, b] = [path[after - 1], path[after]]
|
|
83
|
+
return Math.round(a.x + ((b.x - a.x) * (t - a.t)) / (b.t - a.t))
|
|
84
|
+
}
|
|
85
|
+
|
|
75
86
|
function boundaries(timeline, rawIndex, fps) {
|
|
76
87
|
const cuts = new Set([0, timeline.duration])
|
|
77
88
|
for (const piece of timeline.picture) {
|
|
@@ -118,6 +129,8 @@ export function wholeSegment(plan) {
|
|
|
118
129
|
overlays: plan.segments.flatMap((s) => s.node.overlays.map(absolute(s.start))),
|
|
119
130
|
tiles: plan.tiles.filter((tile) => !seen.has(tile.key) && seen.add(tile.key)).map(({ key, at, end }) => ({ key, at, end })),
|
|
120
131
|
...(plan.mattes?.length ? { mattes: plan.mattes } : {}),
|
|
132
|
+
...(plan.adjustments?.length ? { adjust: plan.adjustments.map((a) => ({ at: a.at, end: a.end, fx: { ...a.fx, origin: a.at / FLICKS, span: a.end - a.at } })) } : {}),
|
|
133
|
+
...(plan.brand ? { brand: { ...plan.brand, from: 0 } } : {}),
|
|
121
134
|
},
|
|
122
135
|
}
|
|
123
136
|
}
|
|
@@ -125,10 +138,11 @@ export function wholeSegment(plan) {
|
|
|
125
138
|
/**
|
|
126
139
|
* @param {object} project
|
|
127
140
|
* @param {object} rawIndex
|
|
128
|
-
* @param {{ engineVersion: string, runtimeVersion: string, quality?: "draft" | "master", deliverable?: string, rules?: object }} options
|
|
141
|
+
* @param {{ engineVersion: string, runtimeVersion: string, quality?: "draft" | "master", deliverable?: string, rules?: object, filters?: Set<string> }} options
|
|
142
|
+
* filters: this runtime's FFmpeg filters (TP5): an effect needing one it lacks is left out with a note, never faked
|
|
129
143
|
* @returns {object} the RenderPlan: plain data, no I/O
|
|
130
144
|
*/
|
|
131
|
-
export function compile(project, rawIndex, { engineVersion, runtimeVersion, quality = "draft", deliverable, rules } = {}) {
|
|
145
|
+
export function compile(project, rawIndex, { engineVersion, runtimeVersion, quality = "draft", deliverable, rules, filters, fonts, customMotion = false } = {}) {
|
|
132
146
|
if (!engineVersion || !runtimeVersion) throw new TypeError("compile needs engineVersion and runtimeVersion: they are part of every cache key")
|
|
133
147
|
const timeline = solve(project, rawIndex, rules)
|
|
134
148
|
const output = outputOf(project, quality, deliverable)
|
|
@@ -140,6 +154,11 @@ export function compile(project, rawIndex, { engineVersion, runtimeVersion, qual
|
|
|
140
154
|
// key = sha256(engine ‖ runtime ‖ inputs' content ids ‖ resolved plan node ‖ output settings)
|
|
141
155
|
const key = (node, assets) => sha256(canonical([engineVersion, runtimeVersion, [...new Set(assets)].map((id) => fingerprint.get(id)).sort(), node, settings]))
|
|
142
156
|
|
|
157
|
+
// TP7: a type kit the person or an approved plan chose (look.brand.type); none, and every node is the one it was (EH-69)
|
|
158
|
+
const kit = typeKitOf(project)
|
|
159
|
+
const typeNode = kit ? kitNode(kit, fonts) : null
|
|
160
|
+
if (kit && !typeNode.shipped) issues.push({ code: "fonts_missing", message: "the Fonts pack isn't installed here, so this film's type kit draws in the system fonts (kriya edit setup --pack fonts)" })
|
|
161
|
+
|
|
143
162
|
const burnCaptions = deliverable === undefined || project.deliverables.find((d) => d.id === deliverable)?.burnCaptions !== false
|
|
144
163
|
const captionTiles = burnCaptions
|
|
145
164
|
? timeline.captions.map((caption) => {
|
|
@@ -152,15 +171,19 @@ export function compile(project, rawIndex, { engineVersion, runtimeVersion, qual
|
|
|
152
171
|
placement: caption.placement,
|
|
153
172
|
duration: caption.end - caption.at,
|
|
154
173
|
...(caption.behind ? { behind: true } : {}),
|
|
174
|
+
...(typeNode ? { type: typeNode } : {}),
|
|
155
175
|
}
|
|
156
176
|
return { key: key(node, []), kind: "caption", at: caption.at, end: caption.end, node }
|
|
157
177
|
})
|
|
158
178
|
: []
|
|
179
|
+
// TP9: a model-written animation is drawn only while editing.customMotion is on; off, it stays in the project and out of the film
|
|
180
|
+
const custom = timeline.overlays.filter((overlay) => overlay.block?.blockId === "custom")
|
|
181
|
+
if (custom.length && customMotion !== true) issues.push({ code: "custom_motion_off", message: `custom motion is switched off, so ${custom.length === 1 ? "a custom animation isn't" : `${custom.length} custom animations aren't`} drawn` })
|
|
159
182
|
const blockTiles = timeline.overlays
|
|
160
183
|
// A definition with no clear place stays out (the solver has said why), rather than land on a face
|
|
161
|
-
.filter((overlay) => overlay.block && !(overlay.block.blockId === "term" && !overlay.placement))
|
|
184
|
+
.filter((overlay) => overlay.block && !(overlay.block.blockId === "term" && !overlay.placement) && (overlay.block.blockId !== "custom" || customMotion === true))
|
|
162
185
|
.map((overlay) => {
|
|
163
|
-
const node = { kind: "block", ...overlay.block, placement: overlay.placement, duration: overlay.end - overlay.at, ...(overlay.behind ? { behind: true } : {}) }
|
|
186
|
+
const node = { kind: "block", ...overlay.block, placement: overlay.placement, duration: overlay.end - overlay.at, ...(overlay.behind ? { behind: true } : {}), ...(typeNode && overlay.block.blockId === "graphic" ? { type: typeNode } : {}) }
|
|
164
187
|
return { key: key(node, []), kind: "block", at: overlay.at, end: overlay.end, node }
|
|
165
188
|
})
|
|
166
189
|
const tiles = [...captionTiles, ...blockTiles].sort((a, b) => a.at - b.at || (a.key < b.key ? -1 : 1))
|
|
@@ -207,6 +230,60 @@ export function compile(project, rawIndex, { engineVersion, runtimeVersion, qual
|
|
|
207
230
|
const hidden = (tile) => tile.node.behind === true && mattes.some((m) => m.at <= tile.at && tile.end <= m.end)
|
|
208
231
|
for (const tile of tiles) if (tile.node.behind && !hidden(tile)) tile.front = true
|
|
209
232
|
|
|
233
|
+
// A transition into a piece (transitions.js): the piece before it, frozen on its last frame and
|
|
234
|
+
// dressed as it was, for the incoming piece to arrive over. Only in the segment the piece starts
|
|
235
|
+
// in, never longer than half the piece or than that segment less two frames, so the cut stays put
|
|
236
|
+
// Effects from the registry (TP5): each knows where it starts in its chain, how long it is, and how strongly
|
|
237
|
+
// the skin guard lets it act; one this runtime can't draw goes, with a note. Nothing here without an fx effect
|
|
238
|
+
const clipSpan = new Map()
|
|
239
|
+
for (const piece of timeline.picture) {
|
|
240
|
+
const span = clipSpan.get(piece.clip)
|
|
241
|
+
clipSpan.set(piece.clip, span ? { at: Math.min(span.at, piece.at), end: Math.max(span.end, piece.end) } : { at: piece.at, end: piece.end })
|
|
242
|
+
}
|
|
243
|
+
const noted = new Set()
|
|
244
|
+
const note = (code, clip, message) => !noted.has(`${code}:${clip}:${message}`) && (noted.add(`${code}:${clip}:${message}`), issues.push({ code, clip, message }))
|
|
245
|
+
const drawable = (effect, clip) => {
|
|
246
|
+
if (effect.type === "stabilize" && filters && !filters.has("deshake")) return note("effect_unavailable", clip, "this FFmpeg has no deshake filter, so the picture isn't steadied"), false
|
|
247
|
+
if (effect.type !== "fx") return true
|
|
248
|
+
const missing = FX[effect.id].needs.filter((name) => filters && !filters.has(name))
|
|
249
|
+
if (missing.length) return note("effect_unavailable", clip, `this FFmpeg has no ${missing.join(", ")} filter, so ${FX[effect.id].label.toLowerCase()} is left out`), false
|
|
250
|
+
return true
|
|
251
|
+
}
|
|
252
|
+
const faced = (item) => (rawIndex.faces ?? []).some((face) => face.asset === item.asset && face.t >= item.in && face.t <= item.out)
|
|
253
|
+
const dressed = (effects, { clip, chainAt, item }) =>
|
|
254
|
+
effects.filter((effect) => drawable(effect, clip)).map((effect) => {
|
|
255
|
+
if (effect.type !== "fx") return effect
|
|
256
|
+
const span = clipSpan.get(clip) ?? { at: chainAt, end: chainAt }
|
|
257
|
+
const ease = item && faced(item) ? skinEase(effect) : 1
|
|
258
|
+
if (ease < 1) note("skin_guard", clip, `${FX[effect.id].label} would move skin tones too far, so it is eased on this clip`)
|
|
259
|
+
return { ...effect, origin: (span.at - chainAt) / FLICKS, span: span.end - span.at, ...(ease < 1 ? { ease: Math.round(ease * 1000) / 1000 } : {}) }
|
|
260
|
+
})
|
|
261
|
+
const adjustments = (timeline.adjustments ?? []).filter((a) => drawable(a.fx, a.clip)).map(({ at, end, fx, clip }) => ({ clip, at, end, fx }))
|
|
262
|
+
|
|
263
|
+
const frame = frameFlicks(project.canvas.fps)
|
|
264
|
+
const enterOf = (piece, start, end) => {
|
|
265
|
+
const asked = piece.effects.find((e) => e.type === "transition")
|
|
266
|
+
if (!asked || piece.hold || piece.at !== start) return null
|
|
267
|
+
const before = timeline.picture.find((p) => p !== piece && p.end === piece.at)
|
|
268
|
+
if (!before) return null
|
|
269
|
+
const duration = snapToFrame(Math.min(asked.duration, Math.floor((piece.end - piece.at) / 2), end - start - 2 * frame), project.canvas.fps, "floor")
|
|
270
|
+
if (duration < 2 * frame) return null
|
|
271
|
+
const last = before.hold ? before.in : Math.max(before.in, before.out - scaleFlicks(frame, before.speed))
|
|
272
|
+
const path = crops.get(before.clip)
|
|
273
|
+
const color = sourceColor(before.asset)
|
|
274
|
+
// shortcut: a punch-in still on at the cut is kept only when it's a plain centred one; an eased or focused zoom is left off the held frame
|
|
275
|
+
const zoom = timeline.zooms.find((z) => z.at < piece.at && piece.at <= z.end && z.x === undefined && z.ease !== "smooth")
|
|
276
|
+
const from = { asset: before.asset, in: last, out: before.out, at: 0, end: duration, speed: { n: 1, d: 1 }, hold: true, effects: dressed(only(resolved(before), PICTURE_EFFECTS), { clip: before.clip, chainAt: piece.at, item: null }), ...(path ? { crop: [{ t: last, x: cropAt(path, last) }] } : {}), ...(zoom ? { zoom: zoomNode(zoom, start) } : {}), ...(color ? { color } : {}) }
|
|
277
|
+
return { kind: asked.kind, duration, from }
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// TP7: the kit's bar and logo bug span the cut, so FFmpeg draws them on every segment (CRAFT §5.4)
|
|
281
|
+
const logo = kit?.logo ? project.assets.find((a) => a.id === kit.logo && ["image", "video"].includes(a.kind)) : null
|
|
282
|
+
if (kit?.logo && !logo) issues.push({ code: "logo_missing", message: "the logo chosen for this film isn't a picture in its bin any more, so no logo is shown" })
|
|
283
|
+
const chapterStarts = timeline.overlays.filter((o) => o.block?.blockId === "graphic" && ["chapter", "card"].includes(o.block.variables?.kind)).map((o) => o.at).filter((t) => t > 0)
|
|
284
|
+
const accent = kit?.colors?.accent ?? "#ffd23f"
|
|
285
|
+
const brand = kit && (kit.bar || logo) ? { ...(kit.bar ? { bar: { kind: kit.bar, color: accent, track: against(accent), total: timeline.duration, ...(kit.bar === "chapters" ? { chapters: [...new Set(chapterStarts)].sort((a, b) => a - b) } : {}) } } : {}), ...(logo ? { bug: { asset: logo.id, corner: kit.corner ?? "tr" } } : {}) } : null
|
|
286
|
+
|
|
210
287
|
const segments = boundaries(timeline, rawIndex, project.canvas.fps).map(([start, end], i) => {
|
|
211
288
|
const picture = timeline.picture.filter(during(start, end)).map((piece) => {
|
|
212
289
|
const part = clipped(piece, start, end)
|
|
@@ -214,17 +291,24 @@ export function compile(project, rawIndex, { engineVersion, runtimeVersion, qual
|
|
|
214
291
|
const path = crops.get(piece.clip)
|
|
215
292
|
const crop = path ? cropFor(path, part, (rawIndex.shots ?? []).filter((s) => s.asset === piece.asset).map((s) => s.start)) : undefined
|
|
216
293
|
const zoom = timeline.zooms.find(during(start, end))
|
|
217
|
-
|
|
294
|
+
const enter = enterOf(piece, start, end)
|
|
295
|
+
return { ...part, ...(piece.hold ? { hold: true } : {}), effects: dressed(only(resolved(piece), PICTURE_EFFECTS), { clip: piece.clip, chainAt: start + part.at, item: part }), ...(crop ? { crop } : {}), ...(zoom ? { zoom: zoomNode(zoom, start) } : {}), ...(color ? { color } : {}), ...(enter ? { enter } : {}) }
|
|
296
|
+
})
|
|
297
|
+
const overlays = footage.filter(during(start, end)).map((overlay) => {
|
|
298
|
+
const part = clipped(overlay, start, end)
|
|
299
|
+
// A B-roll's own effect starts with the B-roll
|
|
300
|
+
return { ...part, effects: dressed(only(overlay.effects, PICTURE_EFFECTS), { clip: overlay.clip, chainAt: overlay.at, item: part }).map((e) => (e.type === "fx" ? { ...e, origin: (overlay.at - Math.max(overlay.at, start)) / FLICKS, span: overlay.end - overlay.at } : e)) }
|
|
218
301
|
})
|
|
219
|
-
const overlays = footage.filter(during(start, end)).map((overlay) => ({ ...clipped(overlay, start, end), effects: only(overlay.effects, PICTURE_EFFECTS) }))
|
|
220
302
|
const node = {
|
|
221
303
|
picture,
|
|
222
304
|
overlays,
|
|
223
305
|
tiles: tiles.filter(during(start, end)).map((tile) => ({ key: tile.key, at: tile.at - start, end: tile.end - start })),
|
|
224
306
|
...(mattes.some(during(start, end)) ? { mattes: mattes.filter(during(start, end)).map((m) => ({ at: m.at - start, end: m.end - start, box: m.box })) } : {}),
|
|
307
|
+
...(adjustments.some(during(start, end)) ? { adjust: adjustments.filter(during(start, end)).map((a) => ({ at: Math.max(0, a.at - start), end: Math.min(end, a.end) - start, fx: { ...a.fx, origin: (a.at - start) / FLICKS, span: a.end - a.at } })) } : {}),
|
|
308
|
+
...(brand ? { brand: { ...brand, from: start } } : {}),
|
|
225
309
|
}
|
|
226
310
|
const luts = picture.flatMap((item) => item.effects.filter((e) => e.type === "lut").map((e) => e.asset))
|
|
227
|
-
return { id: `s${i}`, start, end, key: key(node, [...picture.
|
|
311
|
+
return { id: `s${i}`, start, end, key: key(node, [...picture.flatMap((item) => [item.asset, ...(item.enter ? [item.enter.from.asset] : [])]), ...overlays.map((item) => item.asset), ...luts, ...(brand?.bug ? [brand.bug.asset] : [])]), node }
|
|
228
312
|
})
|
|
229
313
|
|
|
230
314
|
issues.push(...crowdedEffects(timeline.audio))
|
|
@@ -260,6 +344,8 @@ export function compile(project, rawIndex, { engineVersion, runtimeVersion, qual
|
|
|
260
344
|
segments,
|
|
261
345
|
tiles,
|
|
262
346
|
...(mattes.length ? { mattes } : {}),
|
|
347
|
+
...(adjustments.length ? { adjustments } : {}),
|
|
348
|
+
...(brand ? { brand } : {}),
|
|
263
349
|
audio,
|
|
264
350
|
keys: { picture: sha256(canonical(pictureNodes)), audio: audio.key, caption: sha256(canonical(tiles.map((tile) => tile.key))) },
|
|
265
351
|
issues,
|
|
@@ -35,6 +35,8 @@ export type Effect =
|
|
|
35
35
|
| { type: "eq"; preset: string; strength?: number }
|
|
36
36
|
| { type: "duck"; depth?: number; attack?: Flicks; release?: Flicks }
|
|
37
37
|
| { type: "freeze"; at: TimeRef; duration: Flicks }
|
|
38
|
+
/** The whole picture inside the frame: on bars, or over a blurred copy of itself. Fill is the absence of it */
|
|
39
|
+
| { type: "frame"; mode: "fit" | "blur" }
|
|
38
40
|
|
|
39
41
|
export type Clip = {
|
|
40
42
|
id: string
|
|
@@ -54,6 +56,8 @@ export type Clip = {
|
|
|
54
56
|
/** J and L cuts: how far sound starts before, or ends after, the picture */
|
|
55
57
|
audioLead?: Flicks
|
|
56
58
|
audioLag?: Flicks
|
|
59
|
+
/** An assembly make placed this clip; the next make removes it before placing again */
|
|
60
|
+
plan?: boolean
|
|
57
61
|
createdBy: Author
|
|
58
62
|
}
|
|
59
63
|
|
|
@@ -67,6 +71,8 @@ export type Asset = {
|
|
|
67
71
|
rights: "own" | "licensed" | "public_domain" | "unknown"
|
|
68
72
|
rightsNote?: string
|
|
69
73
|
role?: "aroll" | "broll" | "screen" | "music" | "sfx" | "logo"
|
|
74
|
+
/** The person's name for the clip: letters, digits and spaces, 40 at most. Untrusted text. Its number is computed (clipNumbers), never stored */
|
|
75
|
+
label?: string
|
|
70
76
|
facts: {
|
|
71
77
|
duration?: Flicks
|
|
72
78
|
fps?: Rate | null
|
|
@@ -89,8 +95,26 @@ export type Sequence = {
|
|
|
89
95
|
markers: { id: string; name: string; at: TimeRef }[]
|
|
90
96
|
clips: Clip[]
|
|
91
97
|
parent?: string
|
|
98
|
+
/** The storyboard (ASSEMBLY_AND_INTENT §3). Changed only by set_assembly; a make follows one only from its own brief */
|
|
99
|
+
assembly?: Assembly
|
|
92
100
|
}
|
|
93
101
|
|
|
102
|
+
export type AssemblyPart = {
|
|
103
|
+
id: string
|
|
104
|
+
asset: string
|
|
105
|
+
/** A stretch of the file; absent, the whole file */
|
|
106
|
+
from?: TimeRef
|
|
107
|
+
to?: TimeRef
|
|
108
|
+
/** story and whole are the film's order; over and sound sit on another part */
|
|
109
|
+
use: "story" | "whole" | "over" | "sound"
|
|
110
|
+
at?: { part: string; where?: "start" | "middle" | "end"; word?: string; t?: Flicks }
|
|
111
|
+
/** Absent means fill */
|
|
112
|
+
fit?: "fill" | "fit" | "blur"
|
|
113
|
+
why?: "person" | "storyboard" | "director" | "default"
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export type Assembly = { version: 1; parts: AssemblyPart[] }
|
|
117
|
+
|
|
94
118
|
export type Deliverable = {
|
|
95
119
|
id: string
|
|
96
120
|
preset: string
|
package/src/edit/core/project.js
CHANGED
|
@@ -20,6 +20,8 @@ export const ANCHORS = {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
const BOX = { x: "int", y: "int", w: "pos", h: "pos" }
|
|
23
|
+
// Keyframes on an effect (TP5): a value of the effect, moved through points in flicks from its start
|
|
24
|
+
export const KEYS = { list: { param: "str", points: { list: { at: "flicks", value: "num", "ease?": "str" } } } }
|
|
23
25
|
|
|
24
26
|
export const EFFECTS = {
|
|
25
27
|
reframe: { mode: { enum: ["subject", "fixed"] }, "x?": "int", "y?": "int" },
|
|
@@ -37,6 +39,14 @@ export const EFFECTS = {
|
|
|
37
39
|
duck: { "depth?": "num", "attack?": "flicks", "release?": "flicks" },
|
|
38
40
|
fit: {},
|
|
39
41
|
freeze: { at: "ref", duration: "flicks" },
|
|
42
|
+
// How a picture of another shape sits in the frame (TP2, ASSEMBLY_AND_INTENT §6.2). Fill is the
|
|
43
|
+
// absence of this effect, so today's cuts compile to today's plan (EH-59). Never named `fit`:
|
|
44
|
+
// that is the music effect (EH-56)
|
|
45
|
+
frame: { mode: { enum: ["fit", "blur"] } },
|
|
46
|
+
// An effect from the registry (TP5, core/effects.js, EDD-64): its id and checked values; keyframes
|
|
47
|
+
// as numbers, or a named move code expands. `by` marks one an agent added, for the cap per minute
|
|
48
|
+
// TP9: `region`, a box the person drew, in thousandths of the frame: the effect acts only inside it (mask: only outside)
|
|
49
|
+
fx: { id: "id", "params?": "plain", "keys?": KEYS, "move?": "str", "by?": { enum: ["agent"] }, "region?": BOX },
|
|
40
50
|
}
|
|
41
51
|
|
|
42
52
|
export const SHAPES = {
|
|
@@ -62,6 +72,8 @@ export const SHAPES = {
|
|
|
62
72
|
rights: { enum: ["own", "licensed", "public_domain", "unknown"] },
|
|
63
73
|
"rightsNote?": "str",
|
|
64
74
|
"role?": { enum: ["aroll", "broll", "screen", "music", "sfx", "logo"] },
|
|
75
|
+
// The person's name for a clip (TP1, EDD-60). Absent until they set one; untrusted text like a file name
|
|
76
|
+
"label?": "str",
|
|
65
77
|
facts: {
|
|
66
78
|
"duration?": "flicks",
|
|
67
79
|
"fps?": { nullable: "rate" },
|
|
@@ -103,10 +115,29 @@ export const SHAPES = {
|
|
|
103
115
|
"seamOut?": "bool",
|
|
104
116
|
"audioLead?": "flicks",
|
|
105
117
|
"audioLag?": "flicks",
|
|
118
|
+
// An assembly make placed this (TP2): the next make takes it out before placing again (EH-60)
|
|
119
|
+
"plan?": "bool",
|
|
106
120
|
createdBy: AUTHOR,
|
|
107
121
|
},
|
|
108
122
|
},
|
|
109
123
|
"parent?": "id",
|
|
124
|
+
// The storyboard (TP1, ASSEMBLY_AND_INTENT §3): which files, which stretch of each, in what order.
|
|
125
|
+
// Changed only by set_assembly; absent means none. A make reads it only from its own brief (EH-63)
|
|
126
|
+
"assembly?": {
|
|
127
|
+
version: "pos",
|
|
128
|
+
parts: {
|
|
129
|
+
list: {
|
|
130
|
+
id: "id",
|
|
131
|
+
asset: "id",
|
|
132
|
+
"from?": "ref",
|
|
133
|
+
"to?": "ref",
|
|
134
|
+
use: { enum: ["story", "whole", "over", "sound"] },
|
|
135
|
+
"at?": { part: "id", "where?": { enum: ["start", "middle", "end"] }, "word?": "id", "t?": "flicks" },
|
|
136
|
+
"fit?": { enum: ["fill", "fit", "blur"] },
|
|
137
|
+
"why?": { enum: ["person", "storyboard", "director", "default"] },
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
},
|
|
110
141
|
},
|
|
111
142
|
},
|
|
112
143
|
active: "id",
|
|
@@ -298,6 +329,39 @@ export function newProject({ id, name, width = 1080, height = 1920, fps = { n: 3
|
|
|
298
329
|
}
|
|
299
330
|
}
|
|
300
331
|
|
|
332
|
+
export const LABEL_MAX = 40
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* A label or a file name as data (EH-71): letters, digits and single spaces, 40 characters at most.
|
|
336
|
+
* Marks stay with their letters: Telugu and Hindi vowel signs are marks, and a label without them is unreadable.
|
|
337
|
+
*/
|
|
338
|
+
export const cleanLabel = (text) =>
|
|
339
|
+
String(text ?? "")
|
|
340
|
+
.replace(/[^\p{L}\p{M}\p{N}]+/gu, " ")
|
|
341
|
+
.trim()
|
|
342
|
+
.slice(0, LABEL_MAX)
|
|
343
|
+
.trim()
|
|
344
|
+
|
|
345
|
+
// A clip is a file the person brought in. References aren't, and nor is what Kriya wrote or
|
|
346
|
+
// fetched itself (music beds, sound effects, found pictures): the Host gives those a
|
|
347
|
+
// rightsNote when it adds them, and a person's file never has one (host/projects.js)
|
|
348
|
+
const isClip = (asset) => ["video", "audio", "image"].includes(asset.kind) && asset.rightsNote === undefined
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Each clip's number: its place among the files the person added. Computed, never stored
|
|
352
|
+
* (EH-54): assets are only ever appended, so a number never moves. If an operation that
|
|
353
|
+
* removes an asset is ever added, numbers need storing: stop and ask.
|
|
354
|
+
* @returns {Map<string, number>} asset id → 1, 2, …
|
|
355
|
+
*/
|
|
356
|
+
export function clipNumbers(project) {
|
|
357
|
+
const numbers = new Map()
|
|
358
|
+
for (const asset of project.assets) if (isClip(asset)) numbers.set(asset.id, numbers.size + 1)
|
|
359
|
+
return numbers
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/** @returns {number | null} null for a reference, a file Kriya wrote, or no such asset */
|
|
363
|
+
export const getClipNumber = (project, assetId) => clipNumbers(project).get(assetId) ?? null
|
|
364
|
+
|
|
301
365
|
/** JSON with sorted keys: the same value always gives the same bytes. */
|
|
302
366
|
export function canonical(value) {
|
|
303
367
|
return JSON.stringify(value, (_, v) => (isObject(v) ? Object.fromEntries(Object.entries(v).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))) : v))
|
package/src/edit/core/solver.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { anchorSource, openIndex, wordAfter, wordAt, wordBefore } from "./anchors.js"
|
|
6
6
|
import { mapBox } from "./faces.js"
|
|
7
|
-
import { isSceneBlock, safeZoneFor, sceneFrame, solveLayout } from "./layout.js"
|
|
7
|
+
import { isSceneBlock, REGIONS, safeZoneFor, sceneFrame, solveLayout } from "./layout.js"
|
|
8
8
|
import { flicksToFrames, frameAtTimestamp, framesToFlicks, scaleFlicks, snapToFrame } from "./time.js"
|
|
9
9
|
|
|
10
10
|
const ms = (n) => n * 705_600
|
|
@@ -326,6 +326,8 @@ function placeRest(s) {
|
|
|
326
326
|
const item = { clip: clip.id, role: spot.role, at: spot.at, end: spot.end }
|
|
327
327
|
if (zoom) s.zooms.push({ ...item, scale: zoom.scale, ease: zoom.ease ?? null, ...(zoom.x === undefined ? {} : { x: zoom.x, y: zoom.y }) })
|
|
328
328
|
else if (matte) s.mattes.push({ ...item, model: matte.model ?? "face-box" })
|
|
329
|
+
// An effect over a stretch of the cut (TP5): no picture of its own, the effect's window on the timeline
|
|
330
|
+
else if (!clip.source && clip.effects.some((e) => e.type === "fx")) s.adjustments.push({ ...item, fx: clip.effects.find((e) => e.type === "fx") })
|
|
329
331
|
else if (AUDIO_ROLES.includes(spot.role)) {
|
|
330
332
|
if (!s.tracks.get(clip.track).muted) s.audio.push({ ...item, asset: clip.source.asset, in: spot.from, out: spot.to, speed: clip.speed, effects: clip.effects, ...(clip.loop ? { loop: true } : {}), ...(clip.peak ? { peak: clip.peak } : {}) })
|
|
331
333
|
} else if (block) s.overlays.push({ ...item, block: { blockId: block.blockId, version: block.version, variables: block.variables }, placement: null, ...(behind(clip) ? { behind: true } : {}) })
|
|
@@ -375,6 +377,9 @@ function holdCaptions(s) {
|
|
|
375
377
|
})
|
|
376
378
|
}
|
|
377
379
|
|
|
380
|
+
/** A drawn box (thousandths of the frame) as whole pixels of a canvas. */
|
|
381
|
+
export const markPixels = (mark, { width, height }) => ({ x: Math.round((mark.x * width) / 1000), y: Math.round((mark.y * height) / 1000), w: Math.max(1, Math.round((mark.w * width) / 1000)), h: Math.max(1, Math.round((mark.h * height) / 1000)) })
|
|
382
|
+
|
|
378
383
|
/** Step 6: every caption and card gets a place, or a report. */
|
|
379
384
|
function layOut(s) {
|
|
380
385
|
holdCaptions(s)
|
|
@@ -385,7 +390,13 @@ function layOut(s) {
|
|
|
385
390
|
const w = Math.min(Math.floor((width * rules.boxWidth) / 100), width - (safe.left ?? 0) - (safe.right ?? 0))
|
|
386
391
|
const h = Math.floor((height * rules.boxHeight) / 100)
|
|
387
392
|
// A scene takes its content box; what plays over it sits on the row below that, with no face to clear
|
|
388
|
-
|
|
393
|
+
// TP7: a full-frame card covers the frame as a scene does; a screen frame is drawn round all of it, with no text to place
|
|
394
|
+
const regionOf = (o) => (o.block?.blockId === "graphic" ? REGIONS[o.block.variables?.kind] : undefined)
|
|
395
|
+
const covers = (o) => isSceneBlock(o.block) || regionOf(o)?.region === "full"
|
|
396
|
+
for (const o of s.overlays) if (regionOf(o)?.region === "frame") o.placement = { x: 0, y: 0, w: width, h: height }
|
|
397
|
+
// TP9: a custom animation is drawn over the whole frame by its own design; the gates judge where its words land
|
|
398
|
+
for (const o of s.overlays) if (o.block?.blockId === "custom") o.placement = { x: 0, y: 0, w: width, h: height }
|
|
399
|
+
const scenes = s.overlays.filter(covers)
|
|
389
400
|
const frame = sceneFrame({ width, height }, safe, { w, h })
|
|
390
401
|
for (const scene of scenes) scene.placement = frame.content
|
|
391
402
|
// A definition has its own place, above the caption row or at the top, wherever no face is; with none free
|
|
@@ -403,11 +414,26 @@ function layOut(s) {
|
|
|
403
414
|
// Footage over the whole frame hides the speaker, so a caption there has no face to clear
|
|
404
415
|
const footage = s.overlays.filter((o) => !o.block)
|
|
405
416
|
const hidden = (item) => footage.some((o) => o.at <= item.at && item.end <= o.end)
|
|
406
|
-
const placeable = [...s.captions, ...s.overlays.filter((o) => o.block && !
|
|
417
|
+
const placeable = [...s.captions, ...s.overlays.filter((o) => o.block && !covers(o) && regionOf(o)?.region !== "frame" && o.block.blockId !== "term" && o.block.blockId !== "custom")]
|
|
418
|
+
// A caption look that sits in the middle or at the top (TP7) says so in look.caption.place; none, and the recipe's row as before
|
|
419
|
+
const place = s.project.look?.caption?.place
|
|
420
|
+
const captionPrefer = place === "middle" ? Math.round(((height - h) / 2 / height) * 100) : place === "top" ? 0 : undefined
|
|
421
|
+
const captionIds = new Set(s.captions.map((c) => c.clip))
|
|
407
422
|
// Text behind the speaker may sit on the face: the matte puts the speaker in front of it
|
|
408
423
|
const items = placeable.map((item) => {
|
|
409
424
|
const covered = onScene(item)
|
|
410
|
-
|
|
425
|
+
const region = regionOf(item)
|
|
426
|
+
const faces = item.behind || covered || hidden(item) ? [] : facesDuring(s, item.at, item.end)
|
|
427
|
+
if (region && !item.placement && !covered) {
|
|
428
|
+
const v = item.block.variables
|
|
429
|
+
// A callout marks a point the person gave, or else the first face it sees
|
|
430
|
+
// TP9: a box the person drew (thousandths of the frame) is placed exactly, as pixels of this canvas
|
|
431
|
+
if (region.region === "point" && v.mark) return { id: item.clip, at: item.at, end: item.end, w: 0, h: 0, region: "point", fixed: markPixels(v.mark, { width, height }), faces: [] }
|
|
432
|
+
const point = region.region === "point" ? (v.point ?? (faces[0] ? { x: Math.round(faces[0].x + faces[0].w / 2), y: Math.round(faces[0].y + faces[0].h / 2) } : undefined)) : undefined
|
|
433
|
+
const across = region.region === "corner" ? width : width - (safe.left ?? 0) - (safe.right ?? 0)
|
|
434
|
+
return { id: item.clip, at: item.at, end: item.end, w: Math.floor(across * region.w), h: Math.floor(height * region.h), region: region.region, ...(point ? { point } : {}), ...(v.corner ? { corner: v.corner } : {}), faces: region.region === "point" ? [] : faces }
|
|
435
|
+
}
|
|
436
|
+
return { id: item.clip, at: item.at, end: item.end, w, h, faces, ...(item.placement ? { fixed: item.placement } : covered ? { fixed: frame.row } : {}), ...(captionPrefer !== undefined && captionIds.has(item.clip) ? { prefer: captionPrefer } : {}) }
|
|
411
437
|
})
|
|
412
438
|
const { placements, issues } = solveLayout(items, { canvas: { width, height }, safe, prefer: rules.prefer })
|
|
413
439
|
for (const item of placeable) item.placement = placements[item.clip]
|
|
@@ -449,6 +475,7 @@ export function solve(project, rawIndex = {}, overrides = {}) {
|
|
|
449
475
|
zooms: [],
|
|
450
476
|
captions: [],
|
|
451
477
|
mattes: [],
|
|
478
|
+
adjustments: [],
|
|
452
479
|
issues: [],
|
|
453
480
|
duration: 0,
|
|
454
481
|
issue(code, details) {
|
|
@@ -462,6 +489,7 @@ export function solve(project, rawIndex = {}, overrides = {}) {
|
|
|
462
489
|
placeRest(s)
|
|
463
490
|
layOut(s)
|
|
464
491
|
checkBudget(s)
|
|
465
|
-
const { picture, audio, overlays, zooms, captions, mattes, issues, duration, fps } = s
|
|
466
|
-
|
|
492
|
+
const { picture, audio, overlays, zooms, captions, mattes, issues, duration, fps, adjustments } = s
|
|
493
|
+
// An adjustment's key exists only when one is used, so today's timelines are the objects they were (EH-59)
|
|
494
|
+
return { fps, duration, picture, audio, overlays, zooms, captions, mattes, issues, ...(adjustments.length ? { adjustments } : {}) }
|
|
467
495
|
}
|