Skip to content

Open source CapCut alternative.

TypeScript

feat(site): update_overlay lands one change on several elements [rebuild]

David Leb170845c7e19
diff --git a/site/src/cut/components/Inspector.tools.ts b/site/src/cut/components/Inspector.tools.ts
index df26cff8..1194c821 100644
--- a/site/src/cut/components/Inspector.tools.ts
+++ b/site/src/cut/components/Inspector.tools.ts
@@ -69,9 +69,10 @@ export const INSPECTOR_TOOLS = [
{
name: "update_overlay",
description:
- "Update any overlay element — title, shape, or sticker — by id (from the selection or state). Titles take text/size/font/weight/color/shadow/plate; shapes take w/h/fill/fill_opacity/radius/stroke; stickers take w/h. Every kind takes name, timing, position, rotation, opacity, hidden. This is the tool for 'make this text better' requests too.",
+ "Update any overlay element — title, shape, or sticker — by id (from the selection or state). Titles take text/size/font/weight/color/shadow/plate; shapes take w/h/fill/fill_opacity/radius/stroke; stickers take w/h. Every kind takes name, timing, position, rotation, opacity, hidden. This is the tool for 'make this text better' requests too. Pass ids to land one change on several elements at once (a group, every title in a run): fields a kind lacks are skipped on that element, and the whole write is one undo step.",
inputSchema: obj({
id: str("Overlay element id"),
+ ids: { type: "array", items: { type: "string" }, description: "Several element ids to change together (instead of id)" },
name: str("What the person calls this element — shown on its timeline chip and inspector title (empty string clears it, back to what it is)"),
text: str("New text (titles)"),
start: num("Start s"),
@@ -101,7 +102,7 @@ export const INSPECTOR_TOOLS = [
opacity: num("Whole-element opacity 0..1 (1 clears)"),
hidden: bool("Hide the element without deleting it"),
lane: num("Move the element to another row (0 = the front row, drawn over every higher row). Elements on one row never overlap — a title over a shape needs a lower row than the shape."),
- }, ["id"]),
+ }, []),
},
{
name: "set_mask",
diff --git a/site/src/cut/lib/aiTools.ts b/site/src/cut/lib/aiTools.ts
index 981bb641..5f7fc6f3 100644
--- a/site/src/cut/lib/aiTools.ts
+++ b/site/src/cut/lib/aiTools.ts
@@ -2194,16 +2194,23 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {
},
update_overlay: (s, input) => {
- const o = requireItem(s.overlays, input.id, "overlay element");
- s.updateOverlay(o.id, overlayPatch(input, o.kind ?? "text"));
- const next = useEditor.getState().overlays.find((x) => x.id === o.id)!;
- return {
- id: next.id,
- kind: next.kind ?? "text",
- ...(isTextOverlay(next) ? { text: next.text, color: next.color, size: next.size } : {}),
- start: round2(next.start),
- end: round2(next.end),
+ const ids = Array.isArray(input.ids) && input.ids.length ? input.ids.map(String) : null;
+ if (!ids && typeof input.id !== "string") throw new ToolError("Pass id or ids.");
+ const targets = (ids ?? [String(input.id)]).map((id) => requireItem(s.overlays, id, "overlay element"));
+ // One undo step for the whole write, however many elements it lands on.
+ s.pushHistory();
+ for (const o of targets) applyOverlayPatchSettled(o.id, overlayPatch(input, o.kind ?? "text"));
+ const report = (id: string) => {
+ const next = useEditor.getState().overlays.find((x) => x.id === id)!;
+ return {
+ id: next.id,
+ kind: next.kind ?? "text",
+ ...(isTextOverlay(next) ? { text: next.text, color: next.color, size: next.size } : {}),
+ start: round2(next.start),
+ end: round2(next.end),
+ };
};
+ return ids ? { overlayIds: targets.map((o) => o.id), updated: targets.map((o) => report(o.id)) } : report(targets[0].id);
},
update_audio: (s, input) => {
diff --git a/site/src/cut/server/ai/catalog.ts b/site/src/cut/server/ai/catalog.ts
index 334d63f4..0dc71291 100644
--- a/site/src/cut/server/ai/catalog.ts
+++ b/site/src/cut/server/ai/catalog.ts
@@ -202,6 +202,7 @@ What the user sees on the transitions row: one badge per bar, and nothing else
"graphics": `# Graphics: titles, shapes & stickers
The title lanes hold three overlay element kinds, all sharing a name (what the person calls it, or what it is — a title's text, "Rectangle"; \`name\` on update_overlay renames it, and the timeline chip, the inspector and @-references show that name, which is how a cut full of look-alike shapes stays legible), timing (start/end), center position (x/y fractions 0..1), rotation (degrees), opacity, and a lane; \`overlays\` in editor_state lists them with their \`kind\` and \`name\`. All burn into the export exactly as previewed.
+Several elements change together through one update_overlay call with \`ids\` — a group, every title in a run — the way the group panel edits a multi-selection; the fields a kind lacks are skipped on that element.
Rows are how elements stack (\`lane\`, 0 = the front row; a higher row draws further back). Two elements on ONE row never overlap in time — placing a title where a shape already sits slides it clear instead of laying it on top — so anything meant to sit over something else names a LOWER row: title on lane 0, the background shape behind it on lane 1. Every add tool and update_overlay take \`lane\`.
Use copy_selection and paste_selection for any timeline type, including effects and transitions. Copies preserve properties and relative timing. Transitions cannot be split.
Timeline items start ungrouped. Use group_items to group any selection of clips, audio, elements, captions and transitions, and ungroup_items to separate them. Selecting a member selects the whole group; moving the group preserves its relative timing.