AI media harness for planning, generating, and editing locally
TypeScript
Snap Extend bounds to image borders
Bitti66c6aa35efaf
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.mdindex 9d4c1d5..c91e4c9 100644--- a/RELEASE_NOTES.md+++ b/RELEASE_NOTES.md@@ -34,6 +34,7 @@ This alpha update adds LAN generation workers, Linux support, expanded color gra- Continue preserves the full joined video and audio from Slopfab. Adjacent source and continuation scenes use that shared decode in preview and export, preserving context across the cut. Regenerate older Continue scenes to apply the fix.- The timeline playhead follows playback without waiting for editor updates.- Character sheets give side and back views explicit orientation instructions, keeping reference identity and clothing without copying the front-facing pose.+- Extend bounding box edges gently snap to nearby original image borders when drawing, moving or resizing.- Removing a reference from a scene's last prompt citation now removes it from generation inputs and “Used by.” References selected as frame or motion inputs remain active.- Copy and paste effect settings between matching effects from their **…** menus, including bypass state and LUT data.- Add voice reference chips directly in a shot's Speech field. Voice guidance stays separate from the words spoken.diff --git a/src/components/workspace/Extend.test.tsx b/src/components/workspace/Extend.test.tsxindex f35acd5..54abf70 100644--- a/src/components/workspace/Extend.test.tsx+++ b/src/components/workspace/Extend.test.tsx@@ -86,3 +86,53 @@ it("moves, resizes, redraws and cancels box drags in original pixel coordinates"fireEvent.keyDown(canvas, { key: "Escape" });expect(latest).toEqual({ x: -130, y: -100, width: 330, height: 300 });});++it.each([0.5, 2])("snaps within six screen pixels at %sx scale without trapping the drag or resizing a moved box", (scale) => {+ vi.spyOn(persistence, "readMediaFileUrl").mockResolvedValue(null);+ const original = { x: -100, y: -75, width: 600, height: 450 };+ let latest: ExtendBounds = original;+ function Harness() {+ const [bounds, setBounds] = useState(original); latest = bounds;+ return <ExtendCanvas source={source} folderPath="D:/Images" bounds={bounds} onChange={setBounds} disabled={false} />;+ }+ render(<Harness />);+ const canvas = screen.getByLabelText("Extend bounding box tool");+ const pointer = (type: "pointerDown" | "pointerMove" | "pointerUp" | "pointerCancel", target: Element, x: number, y: number) => {+ const view = canvas.getAttribute("viewBox")!.split(" ").map(Number);+ vi.spyOn(canvas, "getBoundingClientRect").mockReturnValue({ left: 0, top: 0, width: view[2] * scale, height: view[3] * scale } as DOMRect);+ const event = createEvent[type](target);+ Object.defineProperties(event, { button: { value: 0 }, pointerId: { value: 1 }, clientX: { value: (x - view[0]) * scale }, clientY: { value: (y - view[1]) * scale } });+ fireEvent(target, event);+ };+ // Resize only the active edge, leaving its opposite edge and vertical bounds fixed.+ pointer("pointerDown", canvas.querySelector('[data-handle="e"]')!, 500, 150);+ pointer("pointerMove", canvas, 400 + 4 / scale, 150);+ expect(latest).toEqual({ ...original, width: 500 });+ pointer("pointerMove", canvas, 400 + 8 / scale, 150);+ expect(latest).toEqual({ ...original, width: 500 + 8 / scale });+ pointer("pointerMove", canvas, 400 - 4 / scale, 150);+ expect(latest).toEqual({ ...original, width: 500 });+ pointer("pointerCancel", canvas, 400, 150);+ expect(latest).toEqual(original);++ // A corner snaps to both original borders while preserving the opposite corner.+ pointer("pointerDown", canvas.querySelector('[data-handle="nw"]')!, -100, -75);+ pointer("pointerMove", canvas, -4 / scale, 4 / scale);+ expect(latest).toEqual({ x: 0, y: 0, width: 500, height: 375 });+ fireEvent.keyDown(canvas, { key: "Escape" });+ expect(latest).toEqual(original);++ // Moving snaps by translation, never by stretching the box.+ pointer("pointerDown", screen.getByRole("button", { name: "Move Extend box" }), 0, 0);+ pointer("pointerMove", canvas, 100 - 4 / scale, 75 + 4 / scale);+ expect(latest).toEqual({ ...original, x: 0, y: 0 });+ pointer("pointerCancel", canvas, 100, 75);++ // Both endpoints of a newly drawn box can align exactly with the source.+ pointer("pointerDown", canvas, -4 / scale, -4 / scale);+ pointer("pointerMove", canvas, 400 + 4 / scale, 300 + 4 / scale);+ expect(latest).toEqual({ x: 0, y: 0, width: 400, height: 300 });+ pointer("pointerUp", canvas, 400, 300);+ fireEvent.keyDown(screen.getByRole("button", { name: "Move Extend box" }), { key: "ArrowLeft" });+ expect(latest).toEqual({ x: -1, y: 0, width: 400, height: 300 });+});diff --git a/src/components/workspace/ExtendCanvas.tsx b/src/components/workspace/ExtendCanvas.tsxindex 130942e..4242969 100644--- a/src/components/workspace/ExtendCanvas.tsx+++ b/src/components/workspace/ExtendCanvas.tsx@@ -11,6 +11,24 @@ function cameraFor(width: number, height: number, box: ExtendBounds) {return { x: left - margin, y: top - margin, width: right - left + margin * 2, height: bottom - top + margin * 2 };}const handles = ["nw", "n", "ne", "e", "se", "s", "sw", "w"] as const;+const SNAP_DISTANCE = 6; // CSS pixels, independent of the image/canvas scale.++function snapAxis(start: number, size: number, sourceSize: number, tolerance: number, move: boolean, leading: boolean, trailing: boolean) {+ const nearest = (deltas: number[]) => deltas.filter((delta) => Math.abs(delta) <= tolerance)+ .sort((a, b) => Math.abs(a) - Math.abs(b))[0] ?? 0;+ if (move) {+ // Translate the whole box to the closest border without changing its size.+ const delta = nearest([0, sourceSize].flatMap((edge) => [edge - start, edge - start - size])+ .filter((delta) => Math.abs(start + delta) <= 8192));+ return [start + delta, size];+ }+ let end = start + size;+ if (leading) start += nearest([0, sourceSize].map((edge) => edge - start)+ .filter((delta) => end - start - delta >= 1 && end - start - delta <= 8192));+ if (trailing) end += nearest([0, sourceSize].map((edge) => edge - end)+ .filter((delta) => end + delta - start >= 1 && end + delta - start <= 8192));+ return [start, end - start];+}export function ExtendCanvas({ source, folderPath, bounds, onChange, disabled }: {source: ProjectAsset; folderPath: string; bounds: ExtendBounds; onChange: (bounds: ExtendBounds) => void; disabled: boolean;@@ -54,6 +72,7 @@ export function ExtendCanvas({ source, folderPath, bounds, onChange, disabled }:}} onPointerMove={(event) => {const start = drag.current; if (!start || disabled || start.pointerId !== event.pointerId) return;const at = point(event), dx = at.x - start.x, dy = at.y - start.y;+ if (!Number.isFinite(dx + dy)) return;let { x, y, width: w, height: h } = start.box;if (start.mode === "move") { x += dx; y += dy; }else if (start.mode === "draw") { x = Math.min(start.x, at.x); y = Math.min(start.y, at.y); w = Math.max(1, Math.abs(dx)); h = Math.max(1, Math.abs(dy)); }@@ -63,7 +82,13 @@ export function ExtendCanvas({ source, folderPath, bounds, onChange, disabled }:if (start.mode.includes("w")) { x = Math.min(x + dx, x + w - 1); w += start.box.x - x; }if (start.mode.includes("n")) { y = Math.min(y + dy, y + h - 1); h += start.box.y - y; }}- onChange({ x: Math.max(-8192, Math.min(8192, x)), y: Math.max(-8192, Math.min(8192, y)), width: Math.min(8192, w), height: Math.min(8192, h) });+ const rect = event.currentTarget.getBoundingClientRect();+ const move = start.mode === "move", draw = start.mode === "draw";+ [x, w] = snapAxis(Math.max(-8192, Math.min(8192, x)), Math.min(8192, w), width,+ SNAP_DISTANCE * camera.width / rect.width, move, draw || start.mode.includes("w"), draw || start.mode.includes("e"));+ [y, h] = snapAxis(Math.max(-8192, Math.min(8192, y)), Math.min(8192, h), height,+ SNAP_DISTANCE * camera.height / rect.height, move, draw || start.mode.includes("n"), draw || start.mode.includes("s"));+ onChange({ x, y, width: w, height: h });}} onPointerUp={(event) => finish(event)} onPointerCancel={(event) => finish(event, true)} onLostPointerCapture={(event) => finish(event)}onKeyDown={(event) => {if (event.key !== "Escape" || !drag.current) return;