@nodetool-ai/timeline 0.8.1 → 0.8.2
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/dist/.nodetool-build-stamp +1 -1
- package/dist/authoring.d.ts.map +1 -1
- package/dist/authoring.js +46 -6
- package/dist/authoring.js.map +1 -1
- package/dist/composition.d.ts +11 -1
- package/dist/composition.d.ts.map +1 -1
- package/dist/composition.js +58 -12
- package/dist/composition.js.map +1 -1
- package/dist/examples/node.d.ts +18 -0
- package/dist/examples/node.d.ts.map +1 -1
- package/dist/examples/node.js +26 -0
- package/dist/examples/node.js.map +1 -1
- package/dist/finish-storyboard.d.ts +36 -0
- package/dist/finish-storyboard.d.ts.map +1 -0
- package/dist/finish-storyboard.js +554 -0
- package/dist/finish-storyboard.js.map +1 -0
- package/dist/fonts/google-fonts-fetch.d.ts +53 -0
- package/dist/fonts/google-fonts-fetch.d.ts.map +1 -0
- package/dist/fonts/google-fonts-fetch.js +184 -0
- package/dist/fonts/google-fonts-fetch.js.map +1 -0
- package/dist/fonts/google-fonts-node.d.ts +32 -0
- package/dist/fonts/google-fonts-node.d.ts.map +1 -0
- package/dist/fonts/google-fonts-node.js +60 -0
- package/dist/fonts/google-fonts-node.js.map +1 -0
- package/dist/fonts/google-fonts.d.ts +105 -0
- package/dist/fonts/google-fonts.d.ts.map +1 -0
- package/dist/fonts/google-fonts.js +178 -0
- package/dist/fonts/google-fonts.js.map +1 -0
- package/dist/fonts/index.d.ts +1 -0
- package/dist/fonts/index.d.ts.map +1 -1
- package/dist/fonts/index.js +1 -0
- package/dist/fonts/index.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/linked.d.ts +2 -1
- package/dist/linked.d.ts.map +1 -1
- package/dist/linked.js +18 -10
- package/dist/linked.js.map +1 -1
- package/dist/midi/engines/kits.d.ts +2 -0
- package/dist/midi/engines/kits.d.ts.map +1 -1
- package/dist/midi/engines/kits.js +146 -0
- package/dist/midi/engines/kits.js.map +1 -1
- package/dist/midi/index.d.ts +1 -0
- package/dist/midi/index.d.ts.map +1 -1
- package/dist/midi/index.js +1 -0
- package/dist/midi/index.js.map +1 -1
- package/dist/midi/instrument.d.ts.map +1 -1
- package/dist/midi/instrument.js +5 -0
- package/dist/midi/instrument.js.map +1 -1
- package/dist/midi/presets.d.ts.map +1 -1
- package/dist/midi/presets.js +251 -1
- package/dist/midi/presets.js.map +1 -1
- package/dist/midi/sampler.d.ts +15 -0
- package/dist/midi/sampler.d.ts.map +1 -0
- package/dist/midi/sampler.js +72 -0
- package/dist/midi/sampler.js.map +1 -0
- package/dist/midi/voice.d.ts +4 -1
- package/dist/midi/voice.d.ts.map +1 -1
- package/dist/midi/voice.js +8 -4
- package/dist/midi/voice.js.map +1 -1
- package/dist/ops/apply.d.ts +6 -1
- package/dist/ops/apply.d.ts.map +1 -1
- package/dist/ops/apply.js +843 -201
- package/dist/ops/apply.js.map +1 -1
- package/dist/ops/index.d.ts +3 -2
- package/dist/ops/index.d.ts.map +1 -1
- package/dist/ops/index.js +3 -2
- package/dist/ops/index.js.map +1 -1
- package/dist/ops/op.d.ts +15 -3
- package/dist/ops/op.d.ts.map +1 -1
- package/dist/ops/op.js +17 -8
- package/dist/ops/op.js.map +1 -1
- package/dist/ops/parse.d.ts +6 -0
- package/dist/ops/parse.d.ts.map +1 -0
- package/dist/ops/parse.js +390 -0
- package/dist/ops/parse.js.map +1 -0
- package/dist/ops/serialize.d.ts +9 -1
- package/dist/ops/serialize.d.ts.map +1 -1
- package/dist/ops/serialize.js +19 -2
- package/dist/ops/serialize.js.map +1 -1
- package/dist/ops/types.d.ts +30 -8
- package/dist/ops/types.d.ts.map +1 -1
- package/dist/ops/types.js +2 -5
- package/dist/ops/types.js.map +1 -1
- package/dist/production.d.ts.map +1 -1
- package/dist/production.js +7 -0
- package/dist/production.js.map +1 -1
- package/dist/reassemble.d.ts +3 -1
- package/dist/reassemble.d.ts.map +1 -1
- package/dist/reassemble.js +7 -0
- package/dist/reassemble.js.map +1 -1
- package/dist/render/canvas2d.d.ts +3 -3
- package/dist/render/canvas2d.d.ts.map +1 -1
- package/dist/render/draw.d.ts +29 -2
- package/dist/render/draw.d.ts.map +1 -1
- package/dist/render/draw.js +47 -3
- package/dist/render/draw.js.map +1 -1
- package/dist/render/layout.d.ts +27 -3
- package/dist/render/layout.d.ts.map +1 -1
- package/dist/render/layout.js +464 -103
- package/dist/render/layout.js.map +1 -1
- package/dist/render/sceneModel.d.ts.map +1 -1
- package/dist/render/sceneModel.js +76 -27
- package/dist/render/sceneModel.js.map +1 -1
- package/dist/render/svgPath.d.ts +36 -8
- package/dist/render/svgPath.d.ts.map +1 -1
- package/dist/render/svgPath.js +303 -30
- package/dist/render/svgPath.js.map +1 -1
- package/dist/render/textLayout.d.ts +36 -0
- package/dist/render/textLayout.d.ts.map +1 -1
- package/dist/render/textLayout.js +46 -3
- package/dist/render/textLayout.js.map +1 -1
- package/dist/render/transform.d.ts +10 -0
- package/dist/render/transform.d.ts.map +1 -1
- package/dist/render/transform.js +15 -5
- package/dist/render/transform.js.map +1 -1
- package/dist/source-merge.d.ts +84 -0
- package/dist/source-merge.d.ts.map +1 -0
- package/dist/source-merge.js +200 -0
- package/dist/source-merge.js.map +1 -0
- package/dist/storyboard.d.ts +20 -3
- package/dist/storyboard.d.ts.map +1 -1
- package/dist/storyboard.js +61 -27
- package/dist/storyboard.js.map +1 -1
- package/dist/storyboardDesignFrame.d.ts +15 -0
- package/dist/storyboardDesignFrame.d.ts.map +1 -0
- package/dist/storyboardDesignFrame.js +44 -0
- package/dist/storyboardDesignFrame.js.map +1 -0
- package/dist/storyboardValidation.d.ts +10 -0
- package/dist/storyboardValidation.d.ts.map +1 -0
- package/dist/storyboardValidation.js +47 -0
- package/dist/storyboardValidation.js.map +1 -0
- package/dist/types.d.ts +161 -20
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +28 -4
|
@@ -0,0 +1,554 @@
|
|
|
1
|
+
import { isRecord, resolveEffectiveProductionRequirement } from "@nodetool-ai/protocol";
|
|
2
|
+
import { createTimeOrderedUuid, makeClip, makeTrack } from "./defaults.js";
|
|
3
|
+
import { moveTrackOrder } from "./trackOrder.js";
|
|
4
|
+
import { buildStoryboardTimeline } from "./storyboard.js";
|
|
5
|
+
import { activeStoryboardGraphics } from "./storyboardValidation.js";
|
|
6
|
+
import { buildLinkedTimeline } from "./linked.js";
|
|
7
|
+
import { isKnownShapeKind } from "./types.js";
|
|
8
|
+
import { buildTransformMatrix, containBaseScale, IDENTITY_TRANSFORM } from "./render/transform.js";
|
|
9
|
+
import { compileClipAnimations } from "./animation/compile.js";
|
|
10
|
+
function parseBaseline(value) {
|
|
11
|
+
if (!value)
|
|
12
|
+
return undefined;
|
|
13
|
+
try {
|
|
14
|
+
const parsed = JSON.parse(value);
|
|
15
|
+
return isRecord(parsed) ? parsed : undefined;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const identity = (shotId, elementId) => `${shotId}/${elementId}`;
|
|
22
|
+
const serialize = (value) => JSON.stringify(value, (_key, entry) => isRecord(entry) ? Object.fromEntries(Object.keys(entry).sort().map(key => [key, entry[key]])) : entry);
|
|
23
|
+
const same = (a, b) => serialize(a) === serialize(b);
|
|
24
|
+
const baseline = (clip) => {
|
|
25
|
+
const { storyboardMaterializationBaseline: _baseline, id: _id, ...owned } = clip;
|
|
26
|
+
return serialize(owned);
|
|
27
|
+
};
|
|
28
|
+
/** Record the fields owned by the materializer after an accepted finishing pass. */
|
|
29
|
+
export function stampStoryboardMaterializationBaseline(clip) {
|
|
30
|
+
clip.storyboardMaterializationBaseline = baseline(clip);
|
|
31
|
+
}
|
|
32
|
+
const hasDegenerateScale = (clip) => !!clip.transform && [clip.transform.scale.x, clip.transform.scale.y].some((scale) => !Number.isFinite(scale) || scale === 0);
|
|
33
|
+
const isInvisible = (clip, track) => !!clip.hidden || clip.opacity === 0 || hasDegenerateScale(clip) || clip.durationMs <= 0 || !track || track.visible === false;
|
|
34
|
+
const hasGenerativeSource = (clip) => clip.sourceType !== "imported" || !!clip.bindingKind || !!clip.sourceClipId || clip.versions.some((version) => version.status === "success");
|
|
35
|
+
const hasGlobalTransforms = (document) => document.camera2d != null || (document.mediaTracks != null && (!Array.isArray(document.mediaTracks) || document.mediaTracks.length > 0));
|
|
36
|
+
/** Validate actual layers, rather than a caller's description of intended edits. */
|
|
37
|
+
export function validateProducedTimeline(input, document) {
|
|
38
|
+
const issues = [];
|
|
39
|
+
const layers = new Map();
|
|
40
|
+
for (const clip of document.clips) {
|
|
41
|
+
if (clip.storyboardBoardId !== input.boardId || !clip.storyboardShotId || !clip.storyboardElementId)
|
|
42
|
+
continue;
|
|
43
|
+
const key = identity(clip.storyboardShotId, clip.storyboardElementId);
|
|
44
|
+
layers.set(key, [...(layers.get(key) ?? []), clip]);
|
|
45
|
+
}
|
|
46
|
+
const tracks = new Map(document.tracks.map((track) => [track.id, track]));
|
|
47
|
+
const globalTransforms = hasGlobalTransforms(document);
|
|
48
|
+
for (const shot of input.shots) {
|
|
49
|
+
const protectedInputs = new Map((resolveEffectiveProductionRequirement(input.production, shot.production)?.protected_inputs ?? []).map((value) => [value.id, value]));
|
|
50
|
+
const referencedProtection = new Set(activeStoryboardGraphics(shot).map((element) => element.protected_input_id));
|
|
51
|
+
for (const protection of protectedInputs.values()) {
|
|
52
|
+
if (globalTransforms) {
|
|
53
|
+
issues.push({ code: "forbidden_transform", shotId: shot.id, elementId: protection.id, message: `Global camera or media tracking transforms on ${protection.id} cannot be proven faithful. Remove these transforms before production validation.` });
|
|
54
|
+
}
|
|
55
|
+
if (!referencedProtection.has(protection.id))
|
|
56
|
+
issues.push({ code: "missing_element", shotId: shot.id, elementId: protection.id, message: `Protected input ${protection.id} has no editable visible graphics element.` });
|
|
57
|
+
}
|
|
58
|
+
for (const element of activeStoryboardGraphics(shot)) {
|
|
59
|
+
const clips = layers.get(identity(shot.id, element.id)) ?? [];
|
|
60
|
+
const issue = (code, message) => {
|
|
61
|
+
issues.push({ code, shotId: shot.id, elementId: element.id, message });
|
|
62
|
+
};
|
|
63
|
+
if (clips.length === 0) {
|
|
64
|
+
issue("missing_element", `Missing ${shot.id}/${element.id}.`);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (clips.length > 1) {
|
|
68
|
+
issue("duplicate_element", `Duplicate ${shot.id}/${element.id}.`);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
const clip = clips[0];
|
|
72
|
+
const track = tracks.get(clip.trackId);
|
|
73
|
+
if (isInvisible(clip, track)) {
|
|
74
|
+
issue("missing_element", `${element.id} must be visible.`);
|
|
75
|
+
}
|
|
76
|
+
if (!intersectsCanvas(clip, input.width, input.height)) {
|
|
77
|
+
issue("missing_element", `${element.id} is outside the canvas. Move the layer into view before finishing.`);
|
|
78
|
+
}
|
|
79
|
+
if (element.kind === "shape") {
|
|
80
|
+
if (clip.mediaType !== "shape")
|
|
81
|
+
issue("protected_value", `${element.id} requires its separately editable shape.`);
|
|
82
|
+
if (!clip.shapeStyle || !isKnownShapeKind(clip.shapeStyle.kind))
|
|
83
|
+
issue("missing_element", `${element.id} has unsupported or missing visible shape geometry.`);
|
|
84
|
+
}
|
|
85
|
+
const protection = element.protected_input_id ? protectedInputs.get(element.protected_input_id) : undefined;
|
|
86
|
+
if (element.protected_input_id && !protection) {
|
|
87
|
+
issue("protected_source", `Unknown protected input ${element.protected_input_id}.`);
|
|
88
|
+
}
|
|
89
|
+
if (protection && ["product", "logo", "source_asset"].includes(protection.kind) && (element.kind !== "asset" || clip.mediaType !== "image" || clip.currentAssetId !== protection.asset_id))
|
|
90
|
+
issue("protected_source", `${protection.id} requires its original separately editable image.`);
|
|
91
|
+
if (protection?.kind === "exact_text" && (element.kind !== "text" || clip.mediaType !== "text" || clip.textStyle?.text !== protection.value))
|
|
92
|
+
issue("protected_value", `${protection.id} requires its exact editable text.`);
|
|
93
|
+
if (protection && track?.effects?.length)
|
|
94
|
+
issue("forbidden_transform", `Track effects on ${protection.id} cannot be proven faithful.`);
|
|
95
|
+
if (element.kind === "asset") {
|
|
96
|
+
const assetId = protection?.asset_id ?? element.asset_id;
|
|
97
|
+
if (!assetId || clip.mediaType !== "image" || clip.currentAssetId !== assetId) {
|
|
98
|
+
issue("protected_source", `${element.id} must use original asset ${assetId ?? "(unresolved)"}.`);
|
|
99
|
+
}
|
|
100
|
+
if (hasGenerativeSource(clip))
|
|
101
|
+
issue("forbidden_generation", `${element.id} cannot use a generative source.`);
|
|
102
|
+
}
|
|
103
|
+
if (element.kind === "text" && (clip.mediaType !== "text" || clip.textStyle?.text !== (protection?.value ?? element.text))) {
|
|
104
|
+
issue("protected_value", `${element.id} must keep exact copy.`);
|
|
105
|
+
}
|
|
106
|
+
if (protection?.kind === "brand_color" && (clip.shapeStyle?.fill ?? clip.textStyle?.color) !== protection.value) {
|
|
107
|
+
issue("protected_value", `${element.id} must keep exact brand color.`);
|
|
108
|
+
}
|
|
109
|
+
if (protection)
|
|
110
|
+
validateTransforms(clip, protection, issue);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return issues;
|
|
114
|
+
}
|
|
115
|
+
/** A contain-fit source cannot exceed this canvas-sized envelope. This checks
|
|
116
|
+
* placement, not source alpha, text glyphs or occlusion by other layers. */
|
|
117
|
+
function intersectsCanvas(clip, width, height) {
|
|
118
|
+
if (!Number.isFinite(width) || !Number.isFinite(height) || width <= 0 || height <= 0)
|
|
119
|
+
return false;
|
|
120
|
+
const transform = clip.transform ?? IDENTITY_TRANSFORM;
|
|
121
|
+
let minOffsetX = 0, maxOffsetX = 0, minOffsetY = 0, maxOffsetY = 0;
|
|
122
|
+
let scaleX = 1, scaleY = 1;
|
|
123
|
+
for (const animation of compileClipAnimations(clip.animations, clip.durationMs, { width, height })) {
|
|
124
|
+
for (const curve of animation.curves) {
|
|
125
|
+
if (curve.property === "opacity")
|
|
126
|
+
continue;
|
|
127
|
+
// Unknown or overshooting curves require sampling actual source geometry.
|
|
128
|
+
if (curve.keyframes.some((keyframe) => keyframe.easing && !["linear", "easeIn", "easeOut", "easeInOut"].includes(keyframe.easing)))
|
|
129
|
+
return true;
|
|
130
|
+
const values = curve.keyframes.map((keyframe) => keyframe.value);
|
|
131
|
+
if (curve.property === "offsetX") {
|
|
132
|
+
minOffsetX += Math.min(0, ...values);
|
|
133
|
+
maxOffsetX += Math.max(0, ...values);
|
|
134
|
+
}
|
|
135
|
+
else if (curve.property === "offsetY") {
|
|
136
|
+
minOffsetY += Math.min(0, ...values);
|
|
137
|
+
maxOffsetY += Math.max(0, ...values);
|
|
138
|
+
}
|
|
139
|
+
else if (curve.property === "scale") {
|
|
140
|
+
const maximum = Math.max(1, ...values);
|
|
141
|
+
scaleX *= maximum;
|
|
142
|
+
scaleY *= maximum;
|
|
143
|
+
}
|
|
144
|
+
else if (curve.property === "scaleX")
|
|
145
|
+
scaleX *= Math.max(1, ...values);
|
|
146
|
+
else if (curve.property === "scaleY")
|
|
147
|
+
scaleY *= Math.max(1, ...values);
|
|
148
|
+
else
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const matrix = buildTransformMatrix({ ...transform, scale: { x: transform.scale.x * scaleX, y: transform.scale.y * scaleY } }, { x: 1, y: 1 }, width, height);
|
|
153
|
+
// Include the pivot because shrinking a source can move it toward that pivot.
|
|
154
|
+
const xs = [Math.min(-1, (transform.anchor.x - 0.5) * 2), Math.max(1, (transform.anchor.x - 0.5) * 2)];
|
|
155
|
+
const ys = [Math.min(-1, (transform.anchor.y - 0.5) * 2), Math.max(1, (transform.anchor.y - 0.5) * 2)];
|
|
156
|
+
const corners = xs.flatMap((x) => ys.map((y) => {
|
|
157
|
+
const w = matrix[3] * x + matrix[7] * y + matrix[15];
|
|
158
|
+
return { x: (matrix[0] * x + matrix[4] * y + matrix[12]) / w, y: (matrix[1] * x + matrix[5] * y + matrix[13]) / w, w };
|
|
159
|
+
}));
|
|
160
|
+
// Crossing the perspective plane needs actual source bounds, not this envelope.
|
|
161
|
+
if (corners.some((point) => point.w <= 0))
|
|
162
|
+
return true;
|
|
163
|
+
if (corners.some((point) => !Number.isFinite(point.x) || !Number.isFinite(point.y)))
|
|
164
|
+
return false;
|
|
165
|
+
return Math.max(...corners.map((point) => point.x)) + 2 * maxOffsetX / width > -1 && Math.min(...corners.map((point) => point.x)) + 2 * minOffsetX / width < 1
|
|
166
|
+
&& Math.max(...corners.map((point) => point.y)) - 2 * minOffsetY / height > -1 && Math.min(...corners.map((point) => point.y)) - 2 * maxOffsetY / height < 1;
|
|
167
|
+
}
|
|
168
|
+
function validateTransforms(clip, protection, issue) {
|
|
169
|
+
const allowed = new Set(protection.allowed_transformations);
|
|
170
|
+
const transform = clip.transform;
|
|
171
|
+
const forbidden = (operation, active) => {
|
|
172
|
+
if (active && !allowed.has(operation))
|
|
173
|
+
issue("forbidden_transform", `${operation} is forbidden for ${protection.id}.`);
|
|
174
|
+
};
|
|
175
|
+
forbidden("position", !!transform && (transform.position.x !== 0 || transform.position.y !== 0));
|
|
176
|
+
forbidden("scale", !!transform && (transform.scale.x !== 1 || transform.scale.y !== 1));
|
|
177
|
+
forbidden("rotate", !!transform && (transform.rotation !== 0 || !!transform.rotationX || !!transform.rotationY));
|
|
178
|
+
forbidden("opacity", clip.opacity !== undefined && clip.opacity !== 1);
|
|
179
|
+
forbidden("mask", !!clip.matte || !!clip.mask);
|
|
180
|
+
forbidden("crop", !!clip.crop);
|
|
181
|
+
if (clip.blendMode && clip.blendMode !== "normal")
|
|
182
|
+
issue("forbidden_transform", `Color-changing blending on ${protection.id} cannot preserve protected values.`);
|
|
183
|
+
if (clip.transitionIn)
|
|
184
|
+
issue("forbidden_transform", `Transition ${clip.transitionIn.type} has no proven protected transformation policy.`);
|
|
185
|
+
if (clip.parentId || clip.effects?.length)
|
|
186
|
+
issue("forbidden_transform", `Inherited transforms or effects on ${protection.id} cannot be proven faithful by this materializer.`);
|
|
187
|
+
for (const animation of clip.animations ?? []) {
|
|
188
|
+
if (animation.enabled === false)
|
|
189
|
+
continue;
|
|
190
|
+
if (animation.preset === "fade")
|
|
191
|
+
forbidden("opacity", true);
|
|
192
|
+
else if (animation.preset === "slide") {
|
|
193
|
+
forbidden("opacity", true);
|
|
194
|
+
forbidden("position", true);
|
|
195
|
+
}
|
|
196
|
+
else if (animation.preset === "pop") {
|
|
197
|
+
forbidden("opacity", true);
|
|
198
|
+
forbidden("scale", true);
|
|
199
|
+
}
|
|
200
|
+
else
|
|
201
|
+
issue("forbidden_transform", `Animation ${animation.preset} has no proven protected transformation policy.`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/** Copy and images stay this far apart, as a fraction of frame height. */
|
|
205
|
+
const SLOT_GAP = 0.03;
|
|
206
|
+
/** Images never reach closer than this to the top or bottom frame edge. */
|
|
207
|
+
const SLOT_SAFE_EDGE = 0.04;
|
|
208
|
+
const SLOT_MAX_WIDTH = 0.86;
|
|
209
|
+
const priceDirection = (element) => element.role === "price" ? element.direction?.trim().toLowerCase() : undefined;
|
|
210
|
+
function textFontSizePx(element, width) {
|
|
211
|
+
if (element.typography?.size)
|
|
212
|
+
return width * element.typography.size;
|
|
213
|
+
const price = priceDirection(element);
|
|
214
|
+
return element.role === "price" ? width * (price === "superseded price" ? 0.055 : 0.12) : width * 0.065;
|
|
215
|
+
}
|
|
216
|
+
/** Default vertical centre and scale of one element, as fractions of the frame. */
|
|
217
|
+
function defaultSlot(element, index) {
|
|
218
|
+
const price = priceDirection(element);
|
|
219
|
+
const priceY = price === "superseded price" ? 0.65 : price === "current price" ? 0.76 : undefined;
|
|
220
|
+
return {
|
|
221
|
+
y: priceY ?? (element.role === "product" ? 0.42 : element.role === "logo" ? 0.1 : element.role === "headline" ? 0.18 : element.role === "cta" ? 0.84 : 0.66 + (index % 2) * 0.1),
|
|
222
|
+
scale: element.role === "logo" ? 0.18 : element.kind === "asset" ? 0.65 : 1
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Fit every image of known size into the vertical gap between the copy above
|
|
227
|
+
* and below it. A fixed slot cannot hold every aspect ratio: a portrait product
|
|
228
|
+
* at the default scale reaches into the headline and the price.
|
|
229
|
+
*/
|
|
230
|
+
function planShotSlots(elements, input, assetIdOf) {
|
|
231
|
+
const slots = new Map(elements.map((element, index) => [element.id, defaultSlot(element, index)]));
|
|
232
|
+
const halfHeight = new Map();
|
|
233
|
+
const assetBase = new Map();
|
|
234
|
+
for (const element of elements) {
|
|
235
|
+
// A shot's own still or video sits full-frame beneath the graphics.
|
|
236
|
+
if (element.id === "$source")
|
|
237
|
+
continue;
|
|
238
|
+
if (element.kind === "text")
|
|
239
|
+
halfHeight.set(element.id, (textFontSizePx(element, input.width) * 0.6) / input.height);
|
|
240
|
+
const assetId = element.kind === "asset" ? assetIdOf(element) : undefined;
|
|
241
|
+
const size = assetId ? input.assetSizes?.[assetId] : undefined;
|
|
242
|
+
if (size && size.width > 0 && size.height > 0) {
|
|
243
|
+
const base = containBaseScale(size.width, size.height, input.width, input.height);
|
|
244
|
+
assetBase.set(element.id, base);
|
|
245
|
+
halfHeight.set(element.id, (base.y * (slots.get(element.id)?.scale ?? 1)) / 2);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
const fitted = elements.filter((element) => assetBase.has(element.id)).sort((a, b) => (slots.get(a.id)?.y ?? 0) - (slots.get(b.id)?.y ?? 0));
|
|
249
|
+
for (const element of fitted) {
|
|
250
|
+
const slot = slots.get(element.id);
|
|
251
|
+
const base = assetBase.get(element.id);
|
|
252
|
+
if (!slot || !base)
|
|
253
|
+
continue;
|
|
254
|
+
let top = SLOT_SAFE_EDGE;
|
|
255
|
+
let bottom = 1 - SLOT_SAFE_EDGE;
|
|
256
|
+
for (const other of elements) {
|
|
257
|
+
const otherSlot = slots.get(other.id);
|
|
258
|
+
const half = halfHeight.get(other.id);
|
|
259
|
+
if (other.id === element.id || !otherSlot || half === undefined)
|
|
260
|
+
continue;
|
|
261
|
+
if (otherSlot.y < slot.y)
|
|
262
|
+
top = Math.max(top, otherSlot.y + half + SLOT_GAP);
|
|
263
|
+
else
|
|
264
|
+
bottom = Math.min(bottom, otherSlot.y - half - SLOT_GAP);
|
|
265
|
+
}
|
|
266
|
+
if (bottom - top < 0.1)
|
|
267
|
+
continue;
|
|
268
|
+
const scale = Math.min(slot.scale, (bottom - top) / base.y, SLOT_MAX_WIDTH / base.x);
|
|
269
|
+
const half = (base.y * scale) / 2;
|
|
270
|
+
// Keep the slot's centre when it fits, so a small image does not drift.
|
|
271
|
+
const y = Math.min(Math.max(slot.y, top + half), bottom - half);
|
|
272
|
+
slots.set(element.id, { y, scale });
|
|
273
|
+
halfHeight.set(element.id, half);
|
|
274
|
+
}
|
|
275
|
+
return slots;
|
|
276
|
+
}
|
|
277
|
+
const ALIGN_FRACTION = { start: 0, center: 0.5, end: 1 };
|
|
278
|
+
/**
|
|
279
|
+
* Place an image into its authored box. `contain` keeps the whole picture inside the box.
|
|
280
|
+
* `cover` fills the box. With `clip` the overflow is cut with `clip.crop`, whose kept rectangle
|
|
281
|
+
* becomes the layer's picture, so the layer is then re-fit to exactly the box.
|
|
282
|
+
* Positions are canvas-centre-relative pixels, as in `ClipTransform`. Without a known asset size
|
|
283
|
+
* the picture is assumed to have the box's own aspect.
|
|
284
|
+
*/
|
|
285
|
+
function placeInFrame(frame, size, canvas) {
|
|
286
|
+
const [bx, by, bw, bh] = frame.box;
|
|
287
|
+
const boxW = bw * canvas.width, boxH = bh * canvas.height;
|
|
288
|
+
const boxLeft = bx * canvas.width, boxTop = by * canvas.height;
|
|
289
|
+
const ax = ALIGN_FRACTION[frame.align?.x ?? "center"], ay = ALIGN_FRACTION[frame.align?.y ?? "center"];
|
|
290
|
+
const known = !!size && size.width > 0 && size.height > 0;
|
|
291
|
+
const w = known ? size.width : boxW, h = known ? size.height : boxH;
|
|
292
|
+
const cover = frame.fit === "cover";
|
|
293
|
+
const fitScale = cover ? Math.max(boxW / w, boxH / h) : Math.min(boxW / w, boxH / h);
|
|
294
|
+
const shown = { w: w * fitScale, h: h * fitScale };
|
|
295
|
+
const centreX = boxLeft + boxW / 2 - canvas.width / 2, centreY = boxTop + boxH / 2 - canvas.height / 2;
|
|
296
|
+
// Picture size on canvas for scale 1 is the contain base of the (possibly cropped) source.
|
|
297
|
+
const unitScale = (sw, sh) => containBaseScale(sw, sh, canvas.width, canvas.height).x * canvas.width;
|
|
298
|
+
if (cover && frame.clip) {
|
|
299
|
+
const keepW = Math.min(1, boxW / fitScale / w), keepH = Math.min(1, boxH / fitScale / h);
|
|
300
|
+
const cutX = 1 - keepW, cutY = 1 - keepH;
|
|
301
|
+
const crop = { left: cutX * ax, right: cutX * (1 - ax), top: cutY * ay, bottom: cutY * (1 - ay) };
|
|
302
|
+
const scale = boxW / unitScale(keepW * w, keepH * h);
|
|
303
|
+
const placed = { x: centreX, y: centreY, scale };
|
|
304
|
+
if (cutX > 1e-4 || cutY > 1e-4)
|
|
305
|
+
placed.crop = crop;
|
|
306
|
+
return placed;
|
|
307
|
+
}
|
|
308
|
+
const scale = shown.w / unitScale(w, h);
|
|
309
|
+
return { x: centreX + (ax - 0.5) * (boxW - shown.w), y: centreY + (ay - 0.5) * (boxH - shown.h), scale };
|
|
310
|
+
}
|
|
311
|
+
/** Block centre of a framed text element. Wrapping happens inside `maxWidthFrac` = box width. */
|
|
312
|
+
function placeTextInFrame(frame, fontSizePx, lines, canvas) {
|
|
313
|
+
const [bx, by, bw, bh] = frame.box;
|
|
314
|
+
const blockH = Math.min(bh * canvas.height, lines * fontSizePx * 1.2);
|
|
315
|
+
const ay = ALIGN_FRACTION[frame.align?.y ?? "center"];
|
|
316
|
+
const top = by * canvas.height + ay * (bh * canvas.height - blockH);
|
|
317
|
+
return { x: (bx + bw / 2) * canvas.width - canvas.width / 2, y: top + blockH / 2 - canvas.height / 2 };
|
|
318
|
+
}
|
|
319
|
+
/** Deterministic editable composition. Reruns preserve manually changed placement/timing. */
|
|
320
|
+
export function materializeStoryboard(input) {
|
|
321
|
+
const current = input.current ?? { tracks: [], clips: [] };
|
|
322
|
+
const unsupported = [current.camera2d != null && "camera", current.source != null && "code-authored source", current.mediaTracks != null && (!Array.isArray(current.mediaTracks) || current.mediaTracks.length > 0) && "media tracking"].filter(Boolean);
|
|
323
|
+
if (unsupported.length > 0) {
|
|
324
|
+
return {
|
|
325
|
+
document: { ...current, markers: current.markers ?? [] },
|
|
326
|
+
durationMs: Math.max(0, ...current.clips.map((clip) => clip.startMs + clip.durationMs)),
|
|
327
|
+
validation: [{ code: "manual_conflict", shotId: "", elementId: "", message: `Finishing cannot reconcile ${unsupported.join(", ")}. Use a separate Timeline or explicitly remove these features before finishing again.` }]
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
const existing = new Map();
|
|
331
|
+
const conflicts = [];
|
|
332
|
+
for (const clip of current.clips) {
|
|
333
|
+
if (clip.storyboardBoardId !== input.boardId)
|
|
334
|
+
continue;
|
|
335
|
+
if (!clip.storyboardShotId || !clip.storyboardElementId) {
|
|
336
|
+
conflicts.push({ code: "manual_conflict", shotId: clip.storyboardShotId ?? "", elementId: "$source", message: `Legacy assembled layer ${clip.id} has no materializer baseline. Preserve it in a separate Timeline before rebuilding.` });
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
const key = identity(clip.storyboardShotId, clip.storyboardElementId);
|
|
340
|
+
if (existing.has(key))
|
|
341
|
+
conflicts.push({ code: "duplicate_element", shotId: clip.storyboardShotId, elementId: clip.storyboardElementId, message: `Duplicate owned layer ${key}.` });
|
|
342
|
+
existing.set(key, clip);
|
|
343
|
+
}
|
|
344
|
+
const previousKeys = new Set(current.storyboardMaterializations?.find((entry) => entry.boardId === input.boardId)?.elementKeys ?? []);
|
|
345
|
+
const foreignClips = current.clips.filter((clip) => clip.storyboardBoardId !== input.boardId);
|
|
346
|
+
const ownedTrackIds = new Set(current.clips.filter((clip) => clip.storyboardBoardId === input.boardId).map((clip) => clip.trackId));
|
|
347
|
+
const tracks = current.tracks.filter((track) => !ownedTrackIds.has(track.id) || foreignClips.some((clip) => clip.trackId === track.id)).map((track) => ({ ...track }));
|
|
348
|
+
for (const key of previousKeys) {
|
|
349
|
+
if (!existing.has(key))
|
|
350
|
+
conflicts.push({ code: "manual_conflict", shotId: key.split("/")[0], elementId: key.slice(key.indexOf("/") + 1), message: `Owned layer ${key} was manually deleted. Restore it before finishing again.` });
|
|
351
|
+
}
|
|
352
|
+
const assemblyInput = { boardId: input.boardId, shots: [...input.shots], production: input.production };
|
|
353
|
+
const assembly = input.script ? buildLinkedTimeline({ ...assemblyInput, script: input.script }) : buildStoryboardTimeline(assemblyInput);
|
|
354
|
+
const shotWindows = assembly.shotWindows;
|
|
355
|
+
const sourceClips = new Map(assembly.clips.filter(clip => clip.mediaType !== "audio").map(clip => [clip.storyboardShotId, clip]));
|
|
356
|
+
const agentClips = [...existing.values()].filter((clip) => clip.storyboardElementId?.startsWith("$agent:"));
|
|
357
|
+
for (const clip of agentClips) {
|
|
358
|
+
if (!same(parseBaseline(clip.storyboardMaterializationBaseline), parseBaseline(baseline(clip))))
|
|
359
|
+
conflicts.push({ code: "manual_conflict", shotId: clip.storyboardShotId ?? "", elementId: clip.storyboardElementId ?? "", message: `Agent-owned layer ${clip.id} was manually edited. Use a separate Timeline or restore the accepted layer before finishing again.` });
|
|
360
|
+
if (!input.shots.some((shot) => shot.id === clip.storyboardShotId))
|
|
361
|
+
conflicts.push({ code: "manual_conflict", shotId: clip.storyboardShotId ?? "", elementId: clip.storyboardElementId ?? "", message: `Agent-owned layer ${clip.id} belongs to a removed shot. Restore the shot or use a separate Timeline before rebuilding.` });
|
|
362
|
+
const window = shotWindows.get(clip.storyboardShotId ?? "");
|
|
363
|
+
if (window && (clip.startMs < window.start || clip.startMs + clip.durationMs > window.end))
|
|
364
|
+
conflicts.push({ code: "manual_conflict", shotId: clip.storyboardShotId ?? "", elementId: clip.storyboardElementId ?? "", message: `Storyboard timing changed around agent-owned layer ${clip.id}. Restore the accepted shot timing or use a separate Timeline before rebuilding.` });
|
|
365
|
+
const track = current.tracks.find((value) => value.id === clip.trackId);
|
|
366
|
+
if (track && !tracks.some((value) => value.id === track.id))
|
|
367
|
+
tracks.push({ ...track });
|
|
368
|
+
}
|
|
369
|
+
const clips = [...foreignClips, ...agentClips.map((clip) => ({ ...structuredClone(clip), animations: (clip.animations ?? []).filter((animation) => ![`${clip.id}:cut-in`, `${clip.id}:cut-out`].includes(animation.id)) }))];
|
|
370
|
+
let startMs = 0;
|
|
371
|
+
for (const shot of [...input.shots].sort((a, b) => a.index - b.index)) {
|
|
372
|
+
const window = shotWindows.get(shot.id);
|
|
373
|
+
const durationMs = window ? window.end - window.start : 0;
|
|
374
|
+
startMs = window?.start ?? startMs;
|
|
375
|
+
const protectedInputs = new Map((resolveEffectiveProductionRequirement(input.production, shot.production)?.protected_inputs ?? []).map((value) => [value.id, value]));
|
|
376
|
+
const source = sourceClips.get(shot.id);
|
|
377
|
+
if (!window) {
|
|
378
|
+
conflicts.push({ code: "missing_element", shotId: shot.id, elementId: "$source", message: `Shot ${shot.id} has no source allowed by its media strategy.` });
|
|
379
|
+
}
|
|
380
|
+
const elements = [...activeStoryboardGraphics(shot)];
|
|
381
|
+
if (source) {
|
|
382
|
+
elements.unshift({ id: "$source", kind: "asset", asset_id: source.currentAssetId });
|
|
383
|
+
}
|
|
384
|
+
// An element with an authored frame is placed from its box, never from a slot.
|
|
385
|
+
const slots = planShotSlots(elements.filter((element) => !element.frame), input, (element) => (element.protected_input_id ? protectedInputs.get(element.protected_input_id)?.asset_id : undefined) ?? element.asset_id);
|
|
386
|
+
for (const [index, element] of elements.entries()) {
|
|
387
|
+
const key = identity(shot.id, element.id);
|
|
388
|
+
const previous = existing.get(key);
|
|
389
|
+
const track = current.tracks.find((value) => value.id === previous?.trackId) ?? makeTrack({ type: "overlay", name: `${shot.slug ?? shot.id}: ${element.id}`, index: tracks.length });
|
|
390
|
+
if (!tracks.some((value) => value.id === track.id))
|
|
391
|
+
tracks.push({ ...track, index: previous ? track.index : Math.max(-1, ...tracks.map((value) => value.index)) + 1 });
|
|
392
|
+
const protection = element.protected_input_id ? protectedInputs.get(element.protected_input_id) : undefined;
|
|
393
|
+
const creativeDirection = shot.graphics?.direction?.trim().toLowerCase();
|
|
394
|
+
const bold = creativeDirection === "bold editorial rhythm";
|
|
395
|
+
const quiet = creativeDirection === "quiet premium composition";
|
|
396
|
+
const allowedMotion = !protection || protection.allowed_transformations.includes("opacity");
|
|
397
|
+
const slideAllowed = allowedMotion && (!protection || protection.allowed_transformations.includes("position"));
|
|
398
|
+
const isBackground = element.kind === "shape" && element.id === "background";
|
|
399
|
+
const priceIntent = priceDirection(element);
|
|
400
|
+
const { y, scale } = slots.get(element.id) ?? defaultSlot(element, index);
|
|
401
|
+
const frame = element.frame;
|
|
402
|
+
const framedAssetId = (element.kind === "asset" ? protection?.asset_id ?? element.asset_id : undefined);
|
|
403
|
+
const fontSizePx = textFontSizePx(element, input.width);
|
|
404
|
+
const canvas = { width: input.width, height: input.height };
|
|
405
|
+
const placed = frame && element.kind === "asset" ? placeInFrame(frame, framedAssetId ? input.assetSizes?.[framedAssetId] : undefined, canvas) : undefined;
|
|
406
|
+
const textAt = frame && element.kind === "text" ? placeTextInFrame(frame, fontSizePx, element.typography?.maxLines ?? 1, canvas) : undefined;
|
|
407
|
+
const transform = isBackground ? undefined
|
|
408
|
+
: placed ? { position: { x: placed.x, y: placed.y }, scale: { x: placed.scale, y: placed.scale }, rotation: 0, anchor: { x: 0.5, y: 0.5 } }
|
|
409
|
+
: textAt ? { position: textAt, scale: { x: 1, y: 1 }, rotation: 0, anchor: { x: 0.5, y: 0.5 } }
|
|
410
|
+
: frame && element.kind === "shape" ? { position: { x: 0, y: 0 }, scale: { x: 1, y: 1 }, rotation: 0, anchor: { x: 0.5, y: 0.5 } }
|
|
411
|
+
: { position: { x: 0, y: (y - 0.5) * input.height }, scale: { x: scale, y: scale }, rotation: 0, anchor: { x: 0.5, y: 0.5 } };
|
|
412
|
+
const typography = element.typography;
|
|
413
|
+
const shapeBox = frame && element.kind === "shape" ? { x: frame.box[0], y: frame.box[1], width: frame.box[2], height: frame.box[3] } : undefined;
|
|
414
|
+
const generatedClip = makeClip({
|
|
415
|
+
id: previous?.id ?? createTimeOrderedUuid(), trackId: track.id, name: previous?.name ?? element.id,
|
|
416
|
+
startMs, durationMs, mediaType: element.id === "$source" && source?.mediaType === "video" ? "video" : element.kind === "asset" ? "image" : element.kind,
|
|
417
|
+
sourceType: "imported", status: "generated", versions: [],
|
|
418
|
+
storyboardBoardId: input.boardId, storyboardShotId: shot.id,
|
|
419
|
+
storyboardElementId: element.id, storyboardElementRole: element.role,
|
|
420
|
+
currentAssetId: element.kind === "asset" ? protection?.asset_id ?? element.asset_id : undefined,
|
|
421
|
+
transform,
|
|
422
|
+
textStyle: element.kind === "text" ? { text: protection?.value ?? element.text ?? "", fontSizePx, fontWeight: typography?.weight ?? 600, color: "#FFFFFF", align: typography?.align ?? "center", maxWidthFrac: frame ? Math.min(1, Math.max(0.05, frame.box[2])) : 0.85, strikethrough: priceIntent === "superseded price" || undefined } : undefined,
|
|
423
|
+
shapeStyle: element.kind === "shape" ? { kind: "rect", fill: protection?.kind === "brand_color" ? protection.value : element.style?.fill ?? "#21263A", x: shapeBox?.x ?? (isBackground ? 0 : 0.12), y: shapeBox?.y ?? (isBackground ? 0 : 0.74), width: shapeBox?.width ?? (isBackground ? 1 : 0.76), height: shapeBox?.height ?? (isBackground ? 1 : 0.008) } : undefined,
|
|
424
|
+
animations: isBackground || !allowedMotion ? [] : [{ id: previous?.animations?.[0]?.id ?? createTimeOrderedUuid(), role: "in", preset: bold && slideAllowed ? "slide" : "fade", durationMs: quiet ? 700 : 400, delayMs: (quiet ? 40 : 80) * index, params: bold && slideAllowed ? { direction: "up", distance: 0.12 } : undefined }]
|
|
425
|
+
});
|
|
426
|
+
if (placed?.crop)
|
|
427
|
+
generatedClip.crop = placed.crop;
|
|
428
|
+
// A brand-color binding decides the fill. A template-owned style supplies the rest.
|
|
429
|
+
if (generatedClip.shapeStyle && element.style?.stroke) {
|
|
430
|
+
generatedClip.shapeStyle.stroke = element.style.stroke;
|
|
431
|
+
generatedClip.shapeStyle.strokeWidthPx = (element.style.strokeWidth ?? 0.004) * input.width;
|
|
432
|
+
}
|
|
433
|
+
if (generatedClip.shapeStyle && element.style?.cornerRadius !== undefined)
|
|
434
|
+
generatedClip.shapeStyle.cornerRadius = element.style.cornerRadius;
|
|
435
|
+
const clip = element.id === "$source" && source
|
|
436
|
+
? { ...structuredClone(source), id: previous?.id ?? source.id, trackId: track.id, name: previous?.name ?? source.name, storyboardElementId: "$source", linkId: previous?.linkId ?? source.linkId }
|
|
437
|
+
: generatedClip;
|
|
438
|
+
clip.storyboardMaterializationBaseline = baseline(clip);
|
|
439
|
+
if (previous) {
|
|
440
|
+
const prior = parseBaseline(previous.storyboardMaterializationBaseline);
|
|
441
|
+
if (!prior)
|
|
442
|
+
conflicts.push({ code: "manual_conflict", shotId: shot.id, elementId: element.id, message: `Layer ${key} has no valid materializer baseline.` });
|
|
443
|
+
else {
|
|
444
|
+
const actual = parseBaseline(baseline(previous)) ?? {};
|
|
445
|
+
const preserved = new Set(["name", "trackId", "transform", "startMs", "durationMs"]);
|
|
446
|
+
const changed = [...new Set([...Object.keys(prior), ...Object.keys(actual)])].filter(field => !preserved.has(field) && !same(actual[field], prior[field]));
|
|
447
|
+
if (changed.length)
|
|
448
|
+
conflicts.push({ code: "manual_conflict", shotId: shot.id, elementId: element.id, message: `Owned fields were manually changed on ${key}: ${changed.join(", ")}.` });
|
|
449
|
+
if (!same(previous.transform, prior.transform))
|
|
450
|
+
clip.transform = previous.transform;
|
|
451
|
+
if (!same(previous.startMs, prior.startMs))
|
|
452
|
+
clip.startMs = previous.startMs;
|
|
453
|
+
if (!same(previous.durationMs, prior.durationMs))
|
|
454
|
+
clip.durationMs = previous.durationMs;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
clips.push(clip);
|
|
458
|
+
}
|
|
459
|
+
startMs += durationMs;
|
|
460
|
+
}
|
|
461
|
+
const materializedSources = new Map(clips.filter(clip => clip.storyboardElementId === "$source").map(clip => [clip.storyboardShotId, clip]));
|
|
462
|
+
for (const source of assembly.clips.filter(clip => clip.mediaType === "audio")) {
|
|
463
|
+
const shotId = source.storyboardShotId ?? "";
|
|
464
|
+
const elementId = source.scriptLineId ? `$voice:${source.scriptLineId}` : "$source-audio";
|
|
465
|
+
const key = identity(shotId, elementId);
|
|
466
|
+
const previous = existing.get(key);
|
|
467
|
+
const track = current.tracks.find(track => track.id === previous?.trackId) ?? assembly.tracks.find(track => track.id === source.trackId);
|
|
468
|
+
if (!track)
|
|
469
|
+
throw new Error(`Missing canonical audio track ${source.trackId}.`);
|
|
470
|
+
if (!tracks.some(value => value.id === track.id))
|
|
471
|
+
tracks.push({ ...track, index: previous ? track.index : tracks.length });
|
|
472
|
+
const video = materializedSources.get(shotId);
|
|
473
|
+
const clip = { ...source, id: previous?.id ?? source.id, trackId: track.id, name: previous?.name ?? source.name, storyboardElementId: elementId, linkId: source.scriptLineId ? source.linkId : video?.linkId };
|
|
474
|
+
if (previous && !same(parseBaseline(previous.storyboardMaterializationBaseline), parseBaseline(baseline(previous))))
|
|
475
|
+
conflicts.push({ code: "manual_conflict", shotId, elementId, message: `Audio layer ${key} was manually edited.` });
|
|
476
|
+
if (!source.scriptLineId && video)
|
|
477
|
+
Object.assign(clip, { startMs: video.startMs, durationMs: video.durationMs, inPointMs: video.inPointMs, outPointMs: video.outPointMs });
|
|
478
|
+
stampStoryboardMaterializationBaseline(clip);
|
|
479
|
+
clips.push(clip);
|
|
480
|
+
}
|
|
481
|
+
const retainedKeys = new Set(clips.filter(clip => clip.storyboardBoardId === input.boardId).map(clip => identity(clip.storyboardShotId ?? "", clip.storyboardElementId ?? "")));
|
|
482
|
+
for (const [key, previous] of existing) {
|
|
483
|
+
if (!retainedKeys.has(key) && !same(parseBaseline(previous.storyboardMaterializationBaseline), parseBaseline(baseline(previous))))
|
|
484
|
+
conflicts.push({ code: "manual_conflict", shotId: previous.storyboardShotId ?? "", elementId: previous.storyboardElementId ?? "", message: `Removed layer ${key} contains manual edits.` });
|
|
485
|
+
}
|
|
486
|
+
// New backgrounds belong beneath overlays. Existing track order is a user-owned edit.
|
|
487
|
+
for (const clip of clips) {
|
|
488
|
+
if (clip.storyboardBoardId !== input.boardId || !["background", "$source"].includes(clip.storyboardElementId ?? "") || existing.has(identity(clip.storyboardShotId ?? "", clip.storyboardElementId ?? "")))
|
|
489
|
+
continue;
|
|
490
|
+
const order = moveTrackOrder(tracks, clip.trackId, { toIndex: tracks.length - 1 });
|
|
491
|
+
const indices = new Map(order.map((id, index) => [id, index]));
|
|
492
|
+
for (const track of tracks) {
|
|
493
|
+
const index = indices.get(track.id);
|
|
494
|
+
if (index === undefined)
|
|
495
|
+
throw new Error(`Track ${track.id} is missing from composition order.`);
|
|
496
|
+
track.index = index;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
// These semantic directions select existing Timeline animations, never another animation model.
|
|
500
|
+
for (const transition of input.motionDesign?.transitions ?? []) {
|
|
501
|
+
const direction = transition.direction?.trim().toLowerCase() ?? "fade";
|
|
502
|
+
if (direction === "cut")
|
|
503
|
+
continue;
|
|
504
|
+
if (direction !== "fade") {
|
|
505
|
+
conflicts.push({ code: "forbidden_transform", shotId: transition.to_shot_id, elementId: "$transition", message: `Unsupported transition direction ${direction}. Use cut or fade. Crossfade requires overlapping composition and is not supported by this materializer.` });
|
|
506
|
+
continue;
|
|
507
|
+
}
|
|
508
|
+
const outgoing = clips.filter((clip) => clip.storyboardBoardId === input.boardId && clip.storyboardShotId === transition.from_shot_id && clip.mediaType !== "audio");
|
|
509
|
+
const incoming = clips.filter((clip) => clip.storyboardBoardId === input.boardId && clip.storyboardShotId === transition.to_shot_id && clip.mediaType !== "audio");
|
|
510
|
+
for (const clip of outgoing)
|
|
511
|
+
clip.animations = [...(clip.animations ?? []), { id: `${clip.id}:cut-out`, role: "out", preset: "fade", durationMs: 300 }];
|
|
512
|
+
for (const clip of incoming)
|
|
513
|
+
clip.animations = [...(clip.animations ?? []), { id: `${clip.id}:cut-in`, role: "in", preset: "fade", durationMs: 300 }];
|
|
514
|
+
}
|
|
515
|
+
for (const continuity of input.motionDesign?.continuities ?? []) {
|
|
516
|
+
const matching = continuity.shot_ids.map((shotId) => clips.find((clip) => clip.storyboardBoardId === input.boardId && clip.storyboardShotId === shotId && clip.storyboardElementId === continuity.id));
|
|
517
|
+
if (matching.some((clip) => !clip)) {
|
|
518
|
+
conflicts.push({ code: "missing_element", shotId: continuity.shot_ids[0] ?? "", elementId: continuity.id, message: `Continuity ${continuity.id} must name a graphics element present in every referenced shot.` });
|
|
519
|
+
continue;
|
|
520
|
+
}
|
|
521
|
+
const first = matching[0];
|
|
522
|
+
if (!first)
|
|
523
|
+
continue;
|
|
524
|
+
for (const [index, clip] of matching.entries()) {
|
|
525
|
+
if (!clip)
|
|
526
|
+
continue;
|
|
527
|
+
// A continuous device retains placement and does not restart its entrance at each cut.
|
|
528
|
+
if (index > 0) {
|
|
529
|
+
const previous = existing.get(identity(clip.storyboardShotId ?? "", clip.storyboardElementId ?? ""));
|
|
530
|
+
const owned = parseBaseline(previous?.storyboardMaterializationBaseline);
|
|
531
|
+
if (previous && owned && !same(previous.transform, owned.transform) && !same(previous.transform, first.transform)) {
|
|
532
|
+
conflicts.push({ code: "manual_conflict", shotId: clip.storyboardShotId ?? "", elementId: continuity.id, message: `Manual placement on continuity ${continuity.id} conflicts with shared placement.` });
|
|
533
|
+
}
|
|
534
|
+
else
|
|
535
|
+
clip.transform = first.transform ? structuredClone(first.transform) : undefined;
|
|
536
|
+
clip.animations = (clip.animations ?? []).filter((animation) => animation.role !== "in");
|
|
537
|
+
}
|
|
538
|
+
if (index < matching.length - 1)
|
|
539
|
+
clip.animations = (clip.animations ?? []).filter((animation) => animation.role !== "out");
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
for (const clip of clips) {
|
|
543
|
+
if (clip.storyboardBoardId !== input.boardId || !clip.storyboardMaterializationBaseline)
|
|
544
|
+
continue;
|
|
545
|
+
const owned = parseBaseline(clip.storyboardMaterializationBaseline);
|
|
546
|
+
if (!owned)
|
|
547
|
+
continue;
|
|
548
|
+
owned.animations = clip.animations;
|
|
549
|
+
clip.storyboardMaterializationBaseline = serialize(owned);
|
|
550
|
+
}
|
|
551
|
+
const document = { ...current, tracks, clips, markers: current.markers ?? [], storyboardMaterializations: [...(current.storyboardMaterializations ?? []).filter((entry) => entry.boardId !== input.boardId), { boardId: input.boardId, elementKeys: clips.filter((clip) => clip.storyboardBoardId === input.boardId).flatMap((clip) => clip.storyboardShotId && clip.storyboardElementId ? [identity(clip.storyboardShotId, clip.storyboardElementId)] : []) }] };
|
|
552
|
+
return { document, durationMs: Math.max(assembly.durationMs, ...clips.map((clip) => clip.startMs + clip.durationMs)), validation: [...conflicts, ...validateProducedTimeline(input, document)] };
|
|
553
|
+
}
|
|
554
|
+
//# sourceMappingURL=finish-storyboard.js.map
|