Open source CapCut alternative.
TypeScript
fix(site): let keys sit past the frame edge [rebuild]
David Le9a947ed4cb67
diff --git a/site/src/cut/components/AnimationTiles.tools.ts b/site/src/cut/components/AnimationTiles.tools.tsindex 7ccca62e..68d2169f 100644--- a/site/src/cut/components/AnimationTiles.tools.ts+++ b/site/src/cut/components/AnimationTiles.tools.ts@@ -44,6 +44,7 @@ import {WORD_SWELL_MIN,} from "@donkeycut/effects-kit";import { bool, num, obj, str, type AiToolDef } from "@/cut/lib/aiToolDef";+import { OVERLAY_KEY_POS_MAX, OVERLAY_KEY_POS_MIN } from "@/cut/lib/types";import {MOVE_STRENGTH_MAX,MOVE_STRENGTH_MIN,@@ -62,11 +63,6 @@ const RAMP_SECONDS = `${OVERLAY_ANIM_MIN_SECONDS}..${OVERLAY_ANIM_MAX_SECONDS} (export const LOOP_SPEED_MIN = 0.25;export const LOOP_SPEED_MAX = 8;-/** How far beyond the frame a keyed position may sit, so an element can enter- * or leave across an edge; its resting position stays on the frame. */-export const OVERLAY_KEY_POS_MIN = -0.5;-export const OVERLAY_KEY_POS_MAX = 1.5;-// Each loop's cycle at speed 1, e.g. "spin 4s", so a rate can be set from a measured one.const LOOP_CYCLES = OVERLAY_LOOP_STYLE_IDS.map((id) => `${id} ${LOOP_PERIODS[id]}s`).join(", ");diff --git a/site/src/cut/components/Inspector.tsx b/site/src/cut/components/Inspector.tsxindex 24d3d570..1229dd15 100644--- a/site/src/cut/components/Inspector.tsx+++ b/site/src/cut/components/Inspector.tsx@@ -180,6 +180,7 @@ import {SPEED_MAX,SPEED_MIN,assetIsSilent,+ clampKeyPos,clampOverlayPos,type AudioClip,type BoxStyle,@@ -3773,15 +3774,16 @@ function TransformRows({ overlay: o }: { overlay: Overlay }) {// Position reads as a percentage of the frame, which is what the document// stores — an element sits in the same spot at any aspect, and the number// means the same thing on a square as on a widescreen.+ const clampPos = keyed ? clampKeyPos : clampOverlayPos;const setPos = (axis: "x" | "y", pct: number) => {- const v = clampOverlayPos(pct / 100, o);+ const v = clampPos(pct / 100, o);if (keyed) return setKey({ [axis]: v });useEditor.getState().updateOverlayTransient(o.id, { [axis]: v });};return (<Section title="Transform"><KeyframeControls overlay={o} />- <PositionRow pose={pose} min={clampOverlayPos(-Infinity, o) * 100} max={clampOverlayPos(Infinity, o) * 100} ck={posCk} onSet={setPos} />+ <PositionRow pose={pose} min={clampPos(-Infinity, o) * 100} max={clampPos(Infinity, o) * 100} ck={posCk} onSet={setPos} />{keyed && (<Row label="Scale"><ValueSliderdiff --git a/site/src/cut/components/OverlayLayer.tsx b/site/src/cut/components/OverlayLayer.tsxindex 4b62a401..3019caa1 100644--- a/site/src/cut/components/OverlayLayer.tsx+++ b/site/src/cut/components/OverlayLayer.tsx@@ -41,6 +41,7 @@ import {import { fitTextToFrame, textBoxSize } from "@/cut/lib/textFit";import {behindSubjectOverlay,+ clampKeyPos,clampOverlayPos,frameOf,fontStack,@@ -988,7 +989,7 @@ function OverlayItem({const all = useEditor.getState().overlays;return o.groupId ? all.filter((x) => x.groupId === o.groupId) : [o];};- const clampPos = (v: number) => clampOverlayPos(v, o);+ const clampPos = (v: number) => (hasOverlayKeys(o) ? clampKeyPos(v, o) : clampOverlayPos(v, o));/*** Commit a live transform. Position and rotation are pose: on a keyframeddiff --git a/site/src/cut/lib/aiTools.ts b/site/src/cut/lib/aiTools.tsindex f248ec57..783c1dbd 100644--- a/site/src/cut/lib/aiTools.ts+++ b/site/src/cut/lib/aiTools.ts@@ -123,7 +123,7 @@ import {type TextWeight,} from "@donkeycut/effects-kit";import type { AiPanelToolName } from "@/cut/components/AiPanel.tools";-import { LOOP_SPEED_MAX, LOOP_SPEED_MIN, OVERLAY_KEY_POS_MAX, OVERLAY_KEY_POS_MIN, type OverlayAnimationToolName } from "@/cut/components/AnimationTiles.tools";+import { LOOP_SPEED_MAX, LOOP_SPEED_MIN, type OverlayAnimationToolName } from "@/cut/components/AnimationTiles.tools";import type { AudioToolName } from "@/cut/components/AudioPanel.tools";import type { CameraCardToolName } from "@/cut/components/CameraCardSection.tools";import type { EditorToolName } from "@/cut/components/Editor.tools";@@ -297,6 +297,7 @@ import {CLIP_MAX_ZOOM,clipCovers,DEFAULT_BACKGROUND,+ clampKeyPos,clampOverlayPos,clipZoom,frameOf,@@ -844,8 +845,8 @@ const toolRuns: Record<BrowserToolName, ToolRun> = {o.id,onFrame(clamp(k.t, 0, dur)),{- ...(isNum(k.x) ? { x: o.groupId ? clampOverlayPos(k.x, o) : clamp(k.x, OVERLAY_KEY_POS_MIN, OVERLAY_KEY_POS_MAX) } : {}),- ...(isNum(k.y) ? { y: o.groupId ? clampOverlayPos(k.y, o) : clamp(k.y, OVERLAY_KEY_POS_MIN, OVERLAY_KEY_POS_MAX) } : {}),+ ...(isNum(k.x) ? { x: clampKeyPos(k.x, o) } : {}),+ ...(isNum(k.y) ? { y: clampKeyPos(k.y, o) } : {}),...(isNum(k.scale) ? { scale: clamp(k.scale, 0.1, 4) } : {}),...(isNum(k.scale_x) ? { scaleX: clamp(k.scale_x, 0, 4) } : {}),...(isNum(k.scale_y) ? { scaleY: clamp(k.scale_y, 0, 4) } : {}),diff --git a/site/src/cut/lib/types.test.ts b/site/src/cut/lib/types.test.tsindex fae7b449..6cf67bdd 100644--- a/site/src/cut/lib/types.test.ts+++ b/site/src/cut/lib/types.test.ts@@ -1,5 +1,5 @@import { describe, expect, test } from "bun:test";-import { animStyleOfTransition, AUDIO_TRANSITION_STYLES, clipCovers, contentRect, migrateLegacyTransitions, normalizeAspect, TRANSITION_STYLE_GROUPS, TRANSITION_STYLE_IDS, TRANSITION_STYLE_LABELS, type VideoClip } from "./types";+import { animStyleOfTransition, AUDIO_TRANSITION_STYLES, clampKeyPos, clipCovers, contentRect, migrateLegacyTransitions, normalizeAspect, TRANSITION_STYLE_GROUPS, TRANSITION_STYLE_IDS, TRANSITION_STYLE_LABELS, type VideoClip } from "./types";/** A minimal track-0 clip; legacy docs carry retired transitionStyle strings. */function clip(@@ -207,3 +207,11 @@ describe("clipCovers", () => {).toBe(false);});});++describe("clampKeyPos", () => {+ test("a key may sit past the frame edge so an element can enter across it", () => {+ expect(clampKeyPos(1.3, {})).toBe(1.3);+ expect(clampKeyPos(-0.4, {})).toBe(-0.4);+ expect(clampKeyPos(9, {})).toBe(1.5);+ });+});diff --git a/site/src/cut/lib/types.ts b/site/src/cut/lib/types.tsindex 769d1428..0639ede1 100644--- a/site/src/cut/lib/types.ts+++ b/site/src/cut/lib/types.ts@@ -91,12 +91,23 @@ export function normalizeAspect(a: string | undefined | null): Aspect | null {/** An overlay's center, held far enough inside the frame that the element it* belongs to always has a grabbable piece on screen. Every path that writes a- * position — dragging in the preview, the inspector's own fields — passes- * through it, so no route can strand an element off-frame. An element in a- * group may sit anywhere in the camera's world, for a camera to pan to. */+ * resting position — dragging in the preview, the inspector's own fields —+ * passes through it. An element in a group may sit anywhere in the camera's+ * world, for a camera to pan to. */export const clampOverlayPos = (v: number, o?: { groupId?: string }) =>o?.groupId ? Math.min(CAMERA_WORLD_MAX, Math.max(CAMERA_WORLD_MIN, v)) : Math.min(0.98, Math.max(0.02, v));+/** How far beyond the frame a keyed position may sit, so an element can enter+ * or leave across an edge; its resting position stays on the frame. */+export const OVERLAY_KEY_POS_MIN = -0.5;+export const OVERLAY_KEY_POS_MAX = 1.5;++/** A keyed center: past the frame edge by up to half a frame, for a pointer+ * that slides in from below. Every path that writes a key — the chat, the+ * inspector, a preview drag — passes through it. */+export const clampKeyPos = (v: number, o: { groupId?: string }) =>+ o.groupId ? clampOverlayPos(v, o) : Math.min(OVERLAY_KEY_POS_MAX, Math.max(OVERLAY_KEY_POS_MIN, v));+/** Output frame in pixels. The short side is pinned to 1080 — the design* short side that text scaling and overlay math assume — and the long side* follows the ratio, rounded to even for the encoder. */