Skip to content

Open source CapCut alternative.

TypeScript

fix(site): short-form safe zone matches the phone apps [rebuild]

David Lecd13940b0c83
diff --git a/docs/guides/cut/README.md b/docs/guides/cut/README.md
index c25aa007..14caa438 100644
--- a/docs/guides/cut/README.md
+++ b/docs/guides/cut/README.md
@@ -28,7 +28,7 @@ AI is hosted whatever the home: image, video, and voiceover generation and the a
The preview scrubs and plays from per-clip decoders held in memory. It shows a frame the moment it arrives and refines behind it, so the timeline always answers and a jump lands on a picture. Every cache is bounded by one memory budget sized to the machine. The performance guide holds the frame budget and how a change is measured.
-Guides draw over the preview from the button beside the timeline zoom: thirds, center, safe margins, the short-form keep-out zone where TikTok, Reels and Shorts draw their own UI, and custom lines dragged into place on the preview. They save with the project, snap a dragged element to their edges, never export, and the assistant reads the safe area they leave when it places graphics.
+Guides draw over the preview from the button beside the timeline zoom: thirds, center, safe margins, the short-form keep-out zone where TikTok, Reels and Shorts draw their own UI or crop the sides of a 9:16 frame, and custom lines dragged into place on the preview. They save with the project, snap a dragged element to their edges, never export, and the assistant reads the safe area they leave when it places graphics.
## The export
diff --git a/site/src/cut/components/GuideOverlay.tsx b/site/src/cut/components/GuideOverlay.tsx
index 6ef335d7..5ff1cc97 100644
--- a/site/src/cut/components/GuideOverlay.tsx
+++ b/site/src/cut/components/GuideOverlay.tsx
@@ -134,7 +134,9 @@ export function GuideOverlay({ stage }: { stage: { w: number; h: number } }) {
const bh = b.h * h;
// A full-width band names itself at its inner edge; a side rail at
// its top, so the label sits where the keep-out meets the picture.
+ // A strip too narrow for its label runs the label down its length.
const labelY = b.w >= 0.99 && b.y <= 0.01 ? y + bh - 5 : y + label + 4;
+ const narrow = bw <= 40 && bh > 120;
return (
<g key={`box-${i}`}>
<rect x={x} y={y} width={bw} height={bh} fill="rgba(239,68,68,0.12)" />
@@ -149,10 +151,11 @@ export function GuideOverlay({ stage }: { stage: { w: number; h: number } }) {
strokeWidth="1"
strokeDasharray="4 3"
/>
- {bw > 40 && bh > label * 2 && (
+ {(narrow || (bw > 40 && bh > label * 2)) && (
<text
- x={x + 6}
- y={labelY}
+ x={narrow ? x + bw / 2 + label / 2 - 1 : x + 6}
+ y={narrow ? y + 8 : labelY}
+ transform={narrow ? `rotate(90 ${x + bw / 2 + label / 2 - 1} ${y + 8})` : undefined}
fontSize={label}
fontWeight={600}
fill="rgba(255,255,255,0.95)"
diff --git a/site/src/cut/components/TopBar.tools.ts b/site/src/cut/components/TopBar.tools.ts
index d782fab8..cf4e4184 100644
--- a/site/src/cut/components/TopBar.tools.ts
+++ b/site/src/cut/components/TopBar.tools.ts
@@ -18,7 +18,7 @@ export const TOP_BAR_TOOLS = [
{
name: "set_guides",
description:
- `Choose the guides drawn over the preview — lines and shaded keep-out regions that show where titles, stickers and captions can sit. They draw in the editor only and never export. Presets: ${GUIDE_PRESETS.map((p) => `${p.id} (${p.name}${p.sublabel ? `, ${p.sublabel.toLowerCase()}` : ""})`).join(", ")}. The short-form preset shades the phone UI of TikTok, Instagram Reels and YouTube Shorts merged — top bar, right-hand action rail, bottom caption block — and fits portrait frames. The custom preset draws the user's own lines, which they drag on the preview; \`lines\` writes that list (frame fractions: v is x positions, h is y) and turns custom on. \`show\` replaces the whole set; [] turns every guide off. Placement never needs a guide on: editor_state project.safeZones already carries every preset's safe area for the frame. project.guides reports what shows and the custom lines.`,
+ `Choose the guides drawn over the preview — lines and shaded keep-out regions that show where titles, stickers and captions can sit. They draw in the editor only and never export. Presets: ${GUIDE_PRESETS.map((p) => `${p.id} (${p.name}${p.sublabel ? `, ${p.sublabel.toLowerCase()}` : ""})`).join(", ")}. The short-form preset shades the phone UI of TikTok, Instagram Reels and YouTube Shorts merged — top bar, right-hand action rail, bottom caption block, and the side strips Reels and Shorts crop when they fill a taller phone screen — and fits portrait frames. The custom preset draws the user's own lines, which they drag on the preview; \`lines\` writes that list (frame fractions: v is x positions, h is y) and turns custom on. \`show\` replaces the whole set; [] turns every guide off. Placement never needs a guide on: editor_state project.safeZones already carries every preset's safe area for the frame. project.guides reports what shows and the custom lines.`,
inputSchema: obj(
{
show: {
diff --git a/site/src/cut/lib/guides.test.ts b/site/src/cut/lib/guides.test.ts
index c5edda4d..5ed16144 100644
--- a/site/src/cut/lib/guides.test.ts
+++ b/site/src/cut/lib/guides.test.ts
@@ -8,16 +8,16 @@ describe("guides", () => {
});
test("platform zones apply to portrait frames only", () => {
- expect(guideGeometry(["shortform"], "9:16").boxes.length).toBe(3);
+ expect(guideGeometry(["shortform"], "9:16").boxes.length).toBe(5);
expect(guideGeometry(["shortform"], "16:9").boxes.length).toBe(0);
expect(guideGeometry(["thirds"], "16:9").v).toEqual([1 / 3, 2 / 3]);
});
test("the safe area is the frame minus every keep-out band and rail", () => {
const safe = safeAreaOf(["shortform"], "9:16")!;
- expect(safe.x).toBe(0);
- expect(safe.y).toBeGreaterThan(0.07);
- expect(safe.x + safe.w).toBeLessThan(0.88);
+ expect(safe.x).toBeGreaterThan(0.04);
+ expect(safe.y).toBeGreaterThan(0.1);
+ expect(safe.x + safe.w).toBeLessThan(0.84);
expect(safe.y + safe.h).toBeLessThan(0.77);
expect(safeAreaOf(["thirds", "center"], "9:16")).toBeNull();
expect(safeAreaOf(["margins"], "16:9")).toEqual({ x: 0.05, y: 0.05, w: 0.9, h: 0.9 });
@@ -36,6 +36,6 @@ describe("guides", () => {
expect(lines.v.includes(0.5)).toBe(true);
expect(lines.h.includes(0.5)).toBe(true);
expect(lines.h.length).toBe(3);
- expect(lines.v.length).toBe(2);
+ expect(lines.v.length).toBe(4);
});
});
diff --git a/site/src/cut/lib/guides.ts b/site/src/cut/lib/guides.ts
index a4a8d575..7d161d8f 100644
--- a/site/src/cut/lib/guides.ts
+++ b/site/src/cut/lib/guides.ts
@@ -3,8 +3,8 @@
* stickers and captions land where a phone will show them. Geometry is in
* frame fractions (0..1 of width and height), so one preset serves every
* frame size. Guides draw in the editor only; exports and captured frames
- * never carry them. The short-form preset is measured on a 1080×1920 phone
- * screen and dated, so a change in an app's UI is one edit here.
+ * never carry them. The short-form preset is measured on a phone and dated,
+ * so a change in an app's UI is one edit here.
*/
import { aspectOrientation, type Aspect } from "./types";
@@ -80,7 +80,11 @@ export const GUIDE_PRESETS: readonly GuidePreset[] = [
},
// The phone UI of TikTok, Instagram Reels and YouTube Shorts, merged into
// one keep-out: each region is the widest of the three. Measured September
- // 2026 on a 1080×1920 screen.
+ // 2026 on a 1170×2532 phone, mapped onto the 1080×1920 frame. Reels and
+ // Shorts scale a 9:16 frame to fill the player and crop 4.4% off each
+ // side; TikTok crops 1.4%. The top band covers the status bar and the
+ // search row under it, the rail the actions from the avatar down, the
+ // bottom band the username, caption and music line.
{
id: "shortform",
name: "Short form",
@@ -90,8 +94,10 @@ export const GUIDE_PRESETS: readonly GuidePreset[] = [
v: [],
h: [],
boxes: [
- { x: 0, y: 0, w: 1, h: phone(150, 1920), label: "Top bar" },
- { x: phone(930, 1080), y: phone(800, 1920), w: phone(150, 1080), h: phone(740, 1920), label: "Actions" },
+ { x: 0, y: 0, w: 1, h: phone(215, 1920), label: "Top bar" },
+ { x: 0, y: 0, w: phone(50, 1080), h: 1, label: "Cropped" },
+ { x: 1 - phone(50, 1080), y: 0, w: phone(50, 1080), h: 1, label: "Cropped" },
+ { x: phone(895, 1080), y: phone(730, 1920), w: phone(185, 1080), h: phone(730, 1920), label: "Actions" },
{ x: 0, y: phone(1460, 1920), w: 1, h: phone(460, 1920), label: "Caption · music · nav" },
],
},
diff --git a/site/src/cut/server/ai/catalog.ts b/site/src/cut/server/ai/catalog.ts
index 75c3792a..02bea345 100644
--- a/site/src/cut/server/ai/catalog.ts
+++ b/site/src/cut/server/ai/catalog.ts
@@ -409,7 +409,7 @@ Rules:
- Keep replies short and concrete — one or two sentences. When the work is done: state what changed, in terms your tool results confirm, and end there. You may close with at most one suggestion, phrased as a statement ("A 0.5s crossfade on the middle cut would smooth the jump."); a suggestion the user has already passed on stays retired. A question belongs in a reply only when the request is genuinely ambiguous or you are blocked. The same cadence holds for answers in chat: give the answer and stop — no trailing offer, no "would you like me to", no "let me know if". You have no name and never name the app; a message that asks for nothing (a greeting, thanks) gets a short "How can I help?" / "What would you like to do?" back — words alone, no tool calls. No headings, no fluff, and never paste the editor_state snapshot or raw JSON back — say what it means in plain words (a failed render: name the error and offer to retry).
- Edits are undoable (unlimited undo), so prefer doing over asking; only ask when the request is genuinely ambiguous. Ambiguous means the target itself is unresolvable — "shorten that clip" with nothing selected and several clips gets "Which clip?" and no edit; guessing a target and editing it is worse than the question. The existing cut is the user's work: adding media adds — never delete, trim, or reorder a timeline clip unless the user said to. Read "change it / make it X / try again / closer to the original" as a fresh take that lands on its own card beside the old, never as license to delete the old clip first; only an explicit "replace / delete / remove this" clears what's already there. Items you placed yourself while working the current ask are your own scaffolding: revise, retime, or delete them freely until the result matches the ask — tearing down your own misstep and rebuilding is part of doing the job. The guardrail covers the user's media and the settled work of earlier turns. Generation is different: undo removes the clip but the credits stay spent, so be certain the user asked for the media before calling a generation tool. Removing media is different too — delete_asset and library_organize deletes don't come back with undo, so they take an explicit ask naming the media.
- Times are seconds. The frame follows project.aspect in editor_state — any "W:H" ratio, short side 1080px; project.frame has the exact pixels. The frame is the user's setting: work within the shape they chose, and change it only when they ask for a different one. A generation that renders in another shape letterboxes inside their frame — mention that if it matters, and leave the choice to them.
-- project.safeZones in editor_state gives, for this frame, the safe area of every guide preset (frame fractions, x/y/w/h) and the keepOut boxes where TikTok, Reels and Shorts draw their own UI — known whether or not a guide shows. When the user names a platform, asks for a safe zone, or wants graphics kept clear of the app's UI, place every title, sticker and caption inside safeZones.shortform.safeArea and check with capture_frame; safeZones.margins is the general 5% inset. A safeArea is a rect — x/y its top-left corner, w/h its size — while an element's x/y is its center: centered in the safe area means x + w/2, y + h/2, and an element of width ew stays inside while its center is between x + ew/2 and x + w − ew/2. Guides are a view: set_guides shows one when the user asks to see it, and showing one changes nothing in the cut.
+- project.safeZones in editor_state gives, for this frame, the safe area of every guide preset (frame fractions, x/y/w/h) and the keepOut boxes where TikTok, Reels and Shorts draw their own UI or crop the frame's sides — known whether or not a guide shows. When the user names a platform, asks for a safe zone, or wants graphics kept clear of the app's UI, place every title, sticker and caption inside safeZones.shortform.safeArea and check with capture_frame; safeZones.margins is the general 5% inset. A safeArea is a rect — x/y its top-left corner, w/h its size — while an element's x/y is its center: centered in the safe area means x + w/2, y + h/2, and an element of width ew stays inside while its center is between x + ew/2 and x + w − ew/2. Guides are a view: set_guides shows one when the user asks to see it, and showing one changes nothing in the cut.
- Exercise judgment on details the user left open, and state the choice you made. Judgment fills in the parameters of the asked-for change (style, length, placement); the scope stays the ask, and extra tools, tracks, or treatments beyond it wait for the user to ask. Editing defaults: a hard cut at every joint; when transitions are asked for, one style family per video at 0.4–0.6s. The editing-taste skill carries the full doctrine.
- Styling is part of the ask, never a bonus. Words the user asked to put on screen — a title, the lines from the audio, a caption run — go on in one plain readable face at one place, timed to what they are for. Per-line typefaces, tilts, color cards, moves, word effects and a repainted frame are a design, and a design is something the user asks for: a lyric video, kinetic type, a named style or vibe, a reference to match, "make it fun". Call add_text_sequence with no \`look\` for the plain job, and leave the caption styling and the background as you found them.
- Read list_skills / read_skill before working in an area you're unsure about — they document every setting. A tool whose description already answers the ask goes straight through.