Open source CapCut alternative.
TypeScript
feat(site): an element's Subject mask starts behind the person [rebuild]
David Le29438075780f
diff --git a/site/src/cut/components/Inspector.tools.ts b/site/src/cut/components/Inspector.tools.tsindex 3e1026b0..187e82d6 100644--- a/site/src/cut/components/Inspector.tools.ts+++ b/site/src/cut/components/Inspector.tools.ts@@ -92,7 +92,7 @@ export const INSPECTOR_TOOLS = [{name: "set_mask",description:- "Mask an overlay element or a video clip — trim its picture to a shape or to the person in the shot. Kinds: rect (rounded box), square (rounded square, side = w of the frame width), circle (ellipse; w and h are frame fractions, so a perfect circle needs w × frame width = h × frame height — omitting h gives you that circle), linear (half-plane: at rotation 0 the top side stays), mirror (band across the item), subject (the person matte: plain keeps the picture only on the person; invert keeps it off the person — behind the speaker). Position is the mask center's offset from the item's own center (a clip's region center), in frame fractions; w/h size it in frame fractions; feather softens the edge; invert keeps what the shape leaves out. Subject masks use only feather and invert. Pass kind \"none\" to remove the mask. `keys` animates the geometry over time — each key is the full geometry at a moment, moving linearly between keys; pass an empty list to clear the keys and keep the mask still.",+ "Mask an overlay element or a video clip — trim its picture to a shape or to the person in the shot. Kinds: rect (rounded box), square (rounded square, side = w of the frame width), circle (ellipse; w and h are frame fractions, so a perfect circle needs w × frame width = h × frame height — omitting h gives you that circle), linear (half-plane: at rotation 0 the top side stays), mirror (band across the item), subject (the person matte: invert true sits the item behind the speaker; invert false keeps it only on the person — an element newly masked as subject defaults to behind, a clip to on-person). Position is the mask center's offset from the item's own center (a clip's region center), in frame fractions; w/h size it in frame fractions; feather softens the edge; invert keeps what the shape leaves out. Subject masks use only feather and invert. Pass kind \"none\" to remove the mask. `keys` animates the geometry over time — each key is the full geometry at a moment, moving linearly between keys; pass an empty list to clear the keys and keep the mask still.",inputSchema: obj({id: str("Overlay element id or video clip id"),kind: {diff --git a/site/src/cut/components/Inspector.tsx b/site/src/cut/components/Inspector.tsxindex 0e6e79f5..c1f0c3e7 100644--- a/site/src/cut/components/Inspector.tsx+++ b/site/src/cut/components/Inspector.tsx@@ -2530,6 +2530,11 @@ interface MaskTarget {/** Timeline window for the keyframe row and playhead-local time. */element: { start: number; end: number };mask?: Mask;+ /** Picking Subject starts inverted — behind the person. Elements set this:+ * a shape or title masked by the person is almost always meant to sit+ * behind them, and the Invert toggle flips it to on-person. Clips keep the+ * plain direction, where Subject means keep the person. */+ subjectStartsBehind?: boolean;/** Replace the mask outright (or remove it), as one undo step. */set: (mask: Mask | undefined) => void;/** Live-drag mask update, no undo entry. */@@ -2668,6 +2673,7 @@ function OverlayMaskSection({ overlay: o }: { overlay: Overlay }) {target={{element: o,mask: o.mask,+ subjectStartsBehind: true,set: (mask) => st().updateOverlay(o.id, { mask }),setTransient: (mask) => st().updateOverlayTransient(o.id, { mask }),setKey: (t, patch, opts) => st().setOverlayMaskKey(o.id, t, patch, opts),@@ -2950,7 +2956,9 @@ function MaskSection({ target }: { target: MaskTarget }) {const w = m.w ?? 0.5;return { w, h: (w * fr.w) / fr.h };})()- : {};+ : kind === "subject" && m.kind !== "subject" && target.subjectStartsBehind+ ? { invert: true }+ : {};target.set({ ...m, ...patch, kind: kind as MaskKind });}}>diff --git a/site/src/cut/lib/aiTools.ts b/site/src/cut/lib/aiTools.tsindex c903ca2b..091c3e92 100644--- a/site/src/cut/lib/aiTools.ts+++ b/site/src/cut/lib/aiTools.ts@@ -635,6 +635,17 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {...(typeof input.invert === "boolean" ? { invert: input.invert || undefined } : {}),...(isNum(input.radius) ? { radius: clamp(input.radius, 0, 400) || undefined } : {}),};+ // An element newly masked by the person starts behind them — the common+ // ask — unless the call named a direction; invert false shows it only on+ // the person. Clips keep the plain direction (Subject keeps the person).+ if (+ o &&+ mask.kind === "subject" &&+ current?.kind !== "subject" &&+ typeof input.invert !== "boolean"+ ) {+ mask.invert = true;+ }// A circle with no explicit h is a perfect circle: w and h are fractions// of different frame edges, so round means unequal fractions.if (mask.kind === "circle" && !isNum(input.h)) {