diff --git a/packages/studio/src/components/editor/domEditOverlayStartGesture.ts b/packages/studio/src/components/editor/domEditOverlayStartGesture.ts
index f2e87ddabb..dde18971ce 100644
--- a/packages/studio/src/components/editor/domEditOverlayStartGesture.ts
+++ b/packages/studio/src/components/editor/domEditOverlayStartGesture.ts
@@ -35,7 +35,6 @@ import {
type UseDomEditOverlayGesturesOptions,
} from "./domEditOverlayGestures";
import { collectSnapContext, buildExcludeElements, type SnapContext } from "./snapTargetCollection";
-import { MOVING_LAYER_UNREADABLE } from "./plainTranslate";
import type { PreviewGestureStart } from "./previewGestureStartRead";
import { editsPlainCss } from "../../hooks/gsapRuntimeKeyframes";
import { logResize, resetResizeMoveLog } from "../../utils/resizeDebug";
@@ -68,14 +67,6 @@ export function startGroupDrag(
notifyBlockedPress(e, opts, blockedSelection);
return false;
}
- const moving = items.find((item) => item.start?.gsap?.moving)?.selection;
- if (moving) {
- e.preventDefault();
- e.stopPropagation();
- opts.onBlockedMoveRef.current(moving, MOVING_LAYER_UNREADABLE);
- return false;
- }
-
opts.onManualDragStartRef.current?.();
const dragItems = filterNestedDomEditGroupItems(items);
const members: ManualOffsetDragMember[] = [];
@@ -212,11 +203,6 @@ export function startGesture(
let pathOffsetMember: ManualOffsetDragMember | undefined;
if (kind === "drag") {
- if (start?.gsap?.moving) {
- opts.onBlockedMoveRef.current(sel, MOVING_LAYER_UNREADABLE);
- e.preventDefault();
- return false;
- }
opts.onManualDragStartRef.current?.();
const result = createManualOffsetDragMember({
key: selectionCacheKey(sel),
diff --git a/packages/studio/src/components/editor/gestureUndoRevert.ts b/packages/studio/src/components/editor/gestureUndoRevert.ts
index ce5300c701..d64a328c72 100644
--- a/packages/studio/src/components/editor/gestureUndoRevert.ts
+++ b/packages/studio/src/components/editor/gestureUndoRevert.ts
@@ -6,11 +6,8 @@ import {
} from "./manualEdits";
import { readTranslatePx } from "./plainTranslate";
import { drawPreviewDraft } from "./previewDrafts";
-import {
- getOffsetDragGsap,
- stampGestureBase,
- type ManualOffsetDragMember,
-} from "./manualOffsetDrag";
+import { getOffsetDragGsap, type ManualOffsetDragMember } from "./manualOffsetDrag";
+import { stampGestureBase } from "../../hooks/draggedGsapPosition";
import type { StudioEditRevert } from "../../utils/studioPendingEdits";
interface MemberPosition {
@@ -49,7 +46,7 @@ function showMemberPosition(member: ManualOffsetDragMember, position: MemberPosi
if (position.gsap) getOffsetDragGsap(member.element)?.set(member.element, { ...position.gsap });
// The restore drops the gesture's base stamps; its save still reads them.
if (!member.plainTranslate)
- stampGestureBase(member.element, member.initialOffset, member.baseGsap);
+ stampGestureBase(member.element, member.initialOffset, member.baseGsap, !!member.moving);
}
function redrawMemberOnFrame(member: ManualOffsetDragMember): void {
diff --git a/packages/studio/src/components/editor/gsapMoveSealedPreview.test.ts b/packages/studio/src/components/editor/gsapMoveSealedPreview.test.ts
new file mode 100644
index 0000000000..174a544935
--- /dev/null
+++ b/packages/studio/src/components/editor/gsapMoveSealedPreview.test.ts
@@ -0,0 +1,267 @@
+// @vitest-environment happy-dom
+
+import { gsap } from "gsap";
+import { parseGsapScriptAcorn } from "@hyperframes/parsers/gsap-parser-acorn";
+import { afterEach, expect, it, vi } from "vitest";
+// The frame's real runtime agent, serving the opaque frame from this document.
+import { installMarkedEditingAgent } from "../../../../core/src/runtime/editingAgent.test-helpers";
+import { makeSelection } from "../../hooks/domSelectionTestHarness";
+import { freezeDragStamp } from "../../hooks/draggedGsapPosition";
+import { settleGsapSnapshot } from "../../hooks/gsapFrameSnapshot";
+import { tryGsapDragIntercept } from "../../hooks/gsapRuntimeBridge";
+import { watchPreviewFrame } from "../../player/lib/bridgePlayback";
+import { describePreviewElements, queryPreviewElements } from "../../player/lib/previewElements";
+import { detachedFakeIframe } from "../../player/hooks/timelinePlayerTestHarness";
+import { usePlayerStore } from "../../player/store/playerStore";
+import type { UseDomEditOverlayGesturesOptions } from "./domEditOverlayGestures";
+import { startGesture } from "./domEditOverlayStartGesture";
+import {
+ applyManualOffsetDragCommit,
+ applyManualOffsetDragDraft,
+ endManualOffsetDragMembers,
+} from "./manualOffsetDrag";
+import { measurePreviewGestureStart } from "./previewGestureStartRead";
+import { standInFor } from "./previewSelection";
+
+const timeline = (tweens: string) => `var tl = gsap.timeline({ paused: true });
+${tweens}
+window.__timelines["main"] = tl;`;
+const MOVES_BOX = `tl.to("#box", { x: 200, y: 80, duration: 1, ease: "none" }, 0);`;
+const SCRIPT = timeline(MOVES_BOX);
+// Split-text output: more tween targets than the frame's GSAP snapshot carries, so Studio gets none.
+const SPLIT_TEXT = `tl.to(".c", { opacity: 0, stagger: 0.001 }, 0);`;
+const SPANS = ''.repeat(600);
+
+/** Frame px of a translate the draft drew, e.g. "calc(0px + 20px) calc(0px + 0px)". */
+const drawnTranslate = (box: HTMLElement) =>
+ box.style.translate
+ .split(/ (?![^(]*\))/)
+ .map((axis) =>
+ [...axis.matchAll(/-?[\d.]+px/g)].reduce((sum, [px]) => sum + Number.parseFloat(px), 0),
+ );
+
+/** Where the box is drawn in the frame: the translate GSAP's transform starts with, plus any translate on top. */
+function drawnAt(box: HTMLElement) {
+ const [tx = 0, ty = 0] = drawnTranslate(box);
+ const [gx = 0, gy = 0] = (/translate(?:3d)?\(([^)]*)\)/.exec(box.style.transform)?.[1] ?? "")
+ .split(",")
+ .map((part) => Number.parseFloat(part) || 0);
+ return { x: gx + tx, y: gy + ty };
+}
+
+const mainTimeline = () =>
+ (window as unknown as { __timelines?: Record }).__timelines?.main;
+
+const closers: Array<() => void> = [];
+function mount(script: string, extra = "") {
+ document.body.innerHTML = ``;
+ const box = document.getElementById("box")!;
+ box.getBoundingClientRect = () => {
+ const { x, y } = drawnAt(box);
+ return {
+ x: 300 + x,
+ y: 200 + y,
+ width: 100,
+ height: 50,
+ left: 300 + x,
+ top: 200 + y,
+ } as DOMRect;
+ };
+ Object.defineProperty(box, "offsetWidth", { value: 100 });
+ Object.defineProperty(box, "offsetHeight", { value: 50 });
+ Object.assign(window, { gsap, __timelines: {} });
+ new Function("gsap", "window", script)(gsap, window);
+ // The preview paused half way through the tween: GSAP has the box at 100, 40.
+ mainTimeline()?.seek(0.5);
+ usePlayerStore.setState({ currentTime: 0.5, isPlaying: false, autoKeyframeEnabled: true });
+}
+afterEach(() => {
+ closers.splice(0).forEach((close) => close());
+ mainTimeline()?.kill();
+ document.body.innerHTML = "";
+ for (const name of ["gsap", "__timelines"]) Reflect.deleteProperty(window, name);
+ usePlayerStore.setState({ currentTime: 0, isPlaying: false });
+});
+
+function sized(element: T, [x, y, width, height]: number[]): T {
+ element.getBoundingClientRect = () =>
+ ({ x, y, width, height, left: x, top: y, right: x + width, bottom: y + height }) as DOMRect;
+ return element;
+}
+
+/** A frame Studio cannot read, whose runtime is the real editing agent over this document. */
+function opaqueFrame() {
+ const frame: Record = {};
+ const iframe = sized(detachedFakeIframe(frame), [100, 50, 960, 540]) as HTMLIFrameElement;
+ Object.defineProperty(iframe, "contentDocument", { value: null });
+ Object.defineProperty(frame, "document", {
+ get: () => {
+ throw new DOMException("blocked", "SecurityError");
+ },
+ });
+ const parent = {
+ postMessage: (data: unknown, _origin: string, ports: MessagePort[]) =>
+ window.dispatchEvent(
+ new MessageEvent("message", { source: frame as unknown as Window, data, ports }),
+ ),
+ } as unknown as Window;
+ const agent = installMarkedEditingAgent(parent);
+ frame.postMessage = (data: unknown) =>
+ window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
+ closers.push(() => agent.dispose());
+ watchPreviewFrame(iframe);
+ window.dispatchEvent(
+ new MessageEvent("message", {
+ source: frame as unknown as Window,
+ origin: window.location.origin,
+ data: { source: "hf-preview", type: "stage-size", width: 1920, height: 1080 },
+ }),
+ );
+ return iframe;
+}
+
+function gestureOpts(iframe: HTMLIFrameElement) {
+ const ref = (current: T) => ({ current });
+ const overlayEl = sized(document.createElement("div"), [20, 10, 1200, 800]);
+ return {
+ selectionRef: ref(null),
+ overlayRectRef: ref(null),
+ boxRef: ref(document.createElement("div")),
+ overlayRef: ref(overlayEl),
+ iframeRef: ref(iframe),
+ gestureRef: ref(null),
+ groupGestureRef: ref(null),
+ groupOverlayItemsRef: ref([]),
+ rafPausedRef: ref(false),
+ onManualDragStartRef: ref(vi.fn()),
+ onBlockedMoveRef: ref(vi.fn()),
+ } as unknown as UseDomEditOverlayGesturesOptions;
+}
+
+const press = () =>
+ ({
+ clientX: 10,
+ clientY: 10,
+ pointerId: 1,
+ button: 0,
+ preventDefault() {},
+ stopPropagation() {},
+ currentTarget: { setPointerCapture() {} },
+ }) as unknown as React.PointerEvent;
+
+/** Presses the box on a sealed frame, drags it 10 page px right and lets go, as the overlay does. */
+async function dragBoxOnSealedFrame(
+ script: string,
+ beforePress?: (iframe: HTMLIFrameElement) => void,
+) {
+ const box = document.getElementById("box")!;
+ const iframe = opaqueFrame();
+ beforePress?.(iframe);
+ const handle = (await queryPreviewElements(iframe, "#box"))!.matches[0]!.handle;
+ const standIn = standInFor(iframe, (await describePreviewElements(iframe, [handle]))![0]!);
+ const selection = { ...makeSelection("box", standIn), id: "box", handle };
+ const opts = gestureOpts(iframe);
+ const read = await measurePreviewGestureStart(iframe, opts.overlayRef.current!, [handle]);
+ const { rect, start } = read!.elements[0]!;
+ const started = startGesture("drag", press(), opts, { selection, rect, start, snap: read!.snap });
+ expect(opts.onBlockedMoveRef.current).not.toHaveBeenCalled();
+ const member = opts.gestureRef.current!.pathOffsetMember!;
+
+ // A page px is two frame px: the frame shows 1920 px in 960.
+ applyManualOffsetDragDraft(member, 10, 0);
+ await vi.waitFor(() => expect(drawnAt(box)).toEqual({ x: 120, y: 40 }));
+
+ const offset = applyManualOffsetDragCommit(member, 10, 0);
+ const commit = vi.fn(async () => undefined);
+ const [anim] = parseGsapScriptAcorn(script).animations;
+ const outcome = await tryGsapDragIntercept(
+ selection,
+ offset,
+ [anim!],
+ iframe,
+ commit,
+ undefined,
+ {
+ stamp: freezeDragStamp(standIn),
+ },
+ );
+ endManualOffsetDragMembers([member]);
+ return { started, start, anim: anim!, outcome, commit };
+}
+
+// fails without the fix: a sealed preview refused to drag a layer its animation moves.
+it("drags a layer its tween moves in a sealed preview: it moves live and saves a keyframe there", async () => {
+ mount(SCRIPT);
+ const { started, start, anim, outcome, commit } = await dragBoxOnSealedFrame(SCRIPT);
+
+ expect(start.gsap).toEqual({ x: 100, y: 40, moving: true });
+ expect(started).toBe(true);
+ expect(outcome).toEqual({ status: "persisted" });
+ expect(commit).toHaveBeenCalledTimes(1);
+ // The keyframe a same-origin preview writes for the same move: GSAP's 100, 40 plus the drag's 20.
+ expect(commit.mock.calls[0]![1]).toEqual({
+ type: "replace-with-keyframes",
+ animationId: anim.id,
+ targetSelector: "#box",
+ position: 0,
+ duration: 1,
+ keyframes: [
+ { percentage: 50, properties: { x: 120, y: 40 } },
+ { percentage: 100, properties: { x: 200, y: 80 } },
+ ],
+ easeEach: "none",
+ });
+});
+
+it("saves the keyframe of a drag pressed right after two quick seeks", async () => {
+ mount(SCRIPT);
+ const seek = (time: number) => {
+ mainTimeline()?.seek(time);
+ usePlayerStore.setState({ currentTime: time });
+ };
+ const { outcome, commit } = await dragBoxOnSealedFrame(SCRIPT, (iframe) => {
+ seek(0.3);
+ void settleGsapSnapshot(iframe);
+ seek(0.4);
+ seek(0.5);
+ });
+
+ expect(outcome).toEqual({ status: "persisted" });
+ expect(commit.mock.calls.map(([, mutation]) => mutation)).toMatchObject([
+ {
+ type: "replace-with-keyframes",
+ keyframes: [{ percentage: 50, properties: { x: 120, y: 40 } }, {}],
+ },
+ ]);
+});
+
+it("saves nothing for a moving layer when the sealed preview's tweens can't be read", async () => {
+ const script = timeline(`${MOVES_BOX}\n${SPLIT_TEXT}`);
+ mount(script, SPANS);
+ const { start, outcome, commit } = await dragBoxOnSealedFrame(script);
+
+ expect(start.gsap).toEqual({ x: 100, y: 40, moving: true });
+ // Routed without the frame's tweens, the move would save a `set` that pins the layer.
+ expect(outcome).toEqual({
+ status: "blocked",
+ reason: "source-uneditable",
+ detail: "frame-tweens-unreadable",
+ });
+ expect(commit).not.toHaveBeenCalled();
+});
+
+it("still saves a layer GSAP only holds when the sealed preview's tweens can't be read", async () => {
+ const script = timeline(`tl.set("#box", { x: 100, y: 40 }, 0);\n${SPLIT_TEXT}`);
+ mount(script, SPANS);
+ const { start, outcome, commit } = await dragBoxOnSealedFrame(script);
+
+ expect(start.gsap).toEqual({ x: 100, y: 40, moving: false });
+ expect(outcome).toEqual({ status: "persisted" });
+ expect(commit).toHaveBeenCalledTimes(1);
+ // The hold's own `set` takes the new place, as when the frame's tweens are read.
+ expect(commit.mock.calls[0]![1]).toEqual({
+ type: "update-properties",
+ animationId: "#box-set-0-position",
+ properties: { x: 120, y: 40 },
+ });
+});
diff --git a/packages/studio/src/components/editor/manualEditsSnapshot.ts b/packages/studio/src/components/editor/manualEditsSnapshot.ts
index da7ac853eb..75c20f8a4c 100644
--- a/packages/studio/src/components/editor/manualEditsSnapshot.ts
+++ b/packages/studio/src/components/editor/manualEditsSnapshot.ts
@@ -37,6 +37,7 @@ import {
STUDIO_ROTATION_DRAFT_ATTR,
} from "./manualEditsTypes";
import { endPreviewDraft } from "./previewDrafts";
+import { DRAG_MOVING_ATTR } from "../../hooks/draggedGsapPosition";
import type {
StudioBoxSizeSnapshot,
StudioRotationSnapshot,
@@ -218,6 +219,7 @@ export function restoreStudioPathOffsetStyles(
}
element.removeAttribute("data-hf-drag-gsap-base-x");
element.removeAttribute("data-hf-drag-gsap-base-y");
+ element.removeAttribute(DRAG_MOVING_ATTR);
}
}
diff --git a/packages/studio/src/components/editor/manualOffsetDrag.ts b/packages/studio/src/components/editor/manualOffsetDrag.ts
index cb26b1fb52..6a1781c2f0 100644
--- a/packages/studio/src/components/editor/manualOffsetDrag.ts
+++ b/packages/studio/src/components/editor/manualOffsetDrag.ts
@@ -14,7 +14,11 @@ import {
type StudioPathOffsetSnapshot,
} from "./manualEdits";
import type { EditMoment } from "./manualEditsTypes";
-import { computeDraggedGsapPosition } from "../../hooks/draggedGsapPosition";
+import {
+ computeDraggedGsapPosition,
+ DRAG_MOVING_ATTR,
+ stampGestureBase,
+} from "../../hooks/draggedGsapPosition";
import { editsPlainCss } from "../../hooks/gsapRuntimeKeyframes";
import { readTranslatePx, UNREADABLE_TRANSLATE, writeTranslatePx } from "./plainTranslate";
import { drawPreviewDraft, endPreviewDraft } from "./previewDrafts";
@@ -94,6 +98,8 @@ export interface ManualOffsetDragMember {
* making the element accelerate away ("flies"). See applyOffsetDragDraftViaGsap.
*/
baseGsap: { x: number; y: number };
+ /** The sealed preview's gesture start reported a tween moving it. */
+ moving?: true;
initialPathOffset: StudioPathOffsetSnapshot;
gestureToken: string;
screenToOffset: ManualOffsetDragMatrix;
@@ -344,7 +350,8 @@ export function createManualOffsetDragMember(input: {
const gsapX = (!plainTranslate && win?.gsap?.getProperty?.(input.element, "x")) || 0;
const gsapY = (!plainTranslate && win?.gsap?.getProperty?.(input.element, "y")) || 0;
const baseGsap = start?.gsap ? { x: start.gsap.x, y: start.gsap.y } : { x: gsapX, y: gsapY };
- if (!plainTranslate) stampGestureBase(input.element, initialOffset, baseGsap);
+ const moving = start?.gsap?.moving === true;
+ if (!plainTranslate) stampGestureBase(input.element, initialOffset, baseGsap, moving);
if (win?.__timelines) {
const paused: string[] = [];
@@ -390,6 +397,7 @@ export function createManualOffsetDragMember(input: {
initialOffset,
plainTranslate,
baseGsap,
+ ...(moving && { moving }),
initialPathOffset,
gestureToken,
screenToOffset: start?.screenToOffset ?? { a: w / scaleX, b: 0, c: 0, d: w / scaleY },
@@ -407,6 +415,7 @@ export function createManualOffsetDragMember(input: {
initialOffset,
plainTranslate,
baseGsap,
+ ...(moving && { moving }),
initialPathOffset,
gestureToken,
screenToOffset: measured.matrix,
@@ -452,27 +461,12 @@ export function applyManualOffsetDragDraft(
return offset;
}
-/**
- * Re-stamp the STABLE gesture-start base/offset before the source commit reads
- * them. A mid-gesture re-render can wipe these attrs; the commit converts the
- * drop offset → gsap x/y via computeDraggedGsapPosition, which without the base
- * falls back to the live (already-dragged) transform and re-adds the delta — so
- * the element flies off-screen the instant you drop it. The member holds the
- * true gesture-start values in JS, immune to the re-render.
- */
-export function stampGestureBase(el: HTMLElement, initialOffset: Point, baseGsap: Point): void {
- el.setAttribute("data-hf-drag-gsap-base-x", String(baseGsap.x));
- el.setAttribute("data-hf-drag-gsap-base-y", String(baseGsap.y));
- el.setAttribute("data-hf-drag-initial-offset-x", String(initialOffset.x));
- el.setAttribute("data-hf-drag-initial-offset-y", String(initialOffset.y));
-}
-
function applyManualOffsetCommitValue(
member: ManualOffsetDragMember,
offset: { x: number; y: number },
): { x: number; y: number } {
if (!member.plainTranslate)
- stampGestureBase(member.element, member.initialOffset, member.baseGsap);
+ stampGestureBase(member.element, member.initialOffset, member.baseGsap, !!member.moving);
drawMemberOffset(member, offset, true);
return offset;
}
@@ -552,6 +546,7 @@ export function endManualOffsetDragMembers(members: ManualOffsetDragMember[]): v
member.element.removeAttribute("data-hf-drag-initial-offset-y");
member.element.removeAttribute("data-hf-drag-gsap-base-x");
member.element.removeAttribute("data-hf-drag-gsap-base-y");
+ member.element.removeAttribute(DRAG_MOVING_ATTR);
// Do NOT clearProps:"transform" — that nukes the committed GSAP position
// and causes a visual snap-back before the soft reload re-applies it.
const gsapOwnsPosition = !member.plainTranslate && Boolean(getOffsetDragGsap(member.element));
diff --git a/packages/studio/src/components/editor/plainTranslate.ts b/packages/studio/src/components/editor/plainTranslate.ts
index c953b1399a..640aa97ec9 100644
--- a/packages/studio/src/components/editor/plainTranslate.ts
+++ b/packages/studio/src/components/editor/plainTranslate.ts
@@ -128,8 +128,6 @@ export function readTranslatePxLeavingPercent(el: HTMLElement): Point {
export const UNREADABLE_TRANSLATE =
"Studio can't read this layer's translate. Move it in the Code tab.";
-export const MOVING_LAYER_UNREADABLE =
- "This preview can't save a move of a layer its animation moves yet. Move it in the Code tab.";
/** Plain px only: GSAP's CSSPlugin splits `translate` on spaces and drops a calc(). */
function formatTranslatePx(p: Point): string {
diff --git a/packages/studio/src/components/editor/previewGestureStartRead.test.ts b/packages/studio/src/components/editor/previewGestureStartRead.test.ts
index f4f47cf534..54b3cf247c 100644
--- a/packages/studio/src/components/editor/previewGestureStartRead.test.ts
+++ b/packages/studio/src/components/editor/previewGestureStartRead.test.ts
@@ -15,7 +15,6 @@ import {
createManualOffsetDragMember,
restoreManualOffsetDragMembers,
} from "./manualOffsetDrag";
-import { MOVING_LAYER_UNREADABLE } from "./plainTranslate";
import { measurePreviewGestureStart, type PreviewGestureStart } from "./previewGestureStartRead";
import { standInFor } from "./previewSelection";
import { collectSnapContext } from "./snapTargetCollection";
@@ -242,16 +241,6 @@ describe("starting a gesture from what an opaque frame read", () => {
restoreManualOffsetDragMembers(g.pathOffsetMember ? [g.pathOffsetMember] : []);
});
- it("refuses a drag of a layer a tween moves, which this preview cannot save yet", () => {
- const element = document.createElement("div");
- const selection = makeSelection("card", element);
- const opts = gestureOpts(selection);
- const moving = { ...START, gsap: { x: 0, y: 0, moving: true } };
- expect(startGesture("drag", press(), opts, { start: moving })).toBe(false);
- expect(opts.onBlockedMoveRef.current).toHaveBeenCalledWith(selection, MOVING_LAYER_UNREADABLE);
- expect(opts.gestureRef.current).toBeNull();
- });
-
it("drags a group from each member's GSAP position, snapping with the targets it read", () => {
const items = ["a", "b"].map((key, i) => {
const element = document.createElement("div");
diff --git a/packages/studio/src/hooks/draggedGsapPosition.ts b/packages/studio/src/hooks/draggedGsapPosition.ts
index de84f55b31..acfaa635a3 100644
--- a/packages/studio/src/hooks/draggedGsapPosition.ts
+++ b/packages/studio/src/hooks/draggedGsapPosition.ts
@@ -37,6 +37,8 @@ export function readCssRotation(element: HTMLElement, withRotate = true): number
}
}
+export const DRAG_MOVING_ATTR = "data-hf-drag-gsap-moving";
+
export interface DragStamp {
origX: number;
origY: number;
@@ -44,6 +46,23 @@ export interface DragStamp {
baseY: number;
at?: EditMoment;
frozen?: boolean;
+ moving?: true;
+}
+
+/** Writes the gesture-start stamp `readDragStamp` reads. The member's JS values are re-stamped before the commit
+ * because a mid-gesture re-render can wipe these attributes, and without the base the drop re-adds the drag. */
+export function stampGestureBase(
+ el: HTMLElement,
+ initialOffset: { x: number; y: number },
+ baseGsap: { x: number; y: number },
+ moving = false,
+): void {
+ if (moving) el.setAttribute(DRAG_MOVING_ATTR, "");
+ else el.removeAttribute(DRAG_MOVING_ATTR);
+ el.setAttribute("data-hf-drag-gsap-base-x", String(baseGsap.x));
+ el.setAttribute("data-hf-drag-gsap-base-y", String(baseGsap.y));
+ el.setAttribute("data-hf-drag-initial-offset-x", String(initialOffset.x));
+ el.setAttribute("data-hf-drag-initial-offset-y", String(initialOffset.y));
}
/** The drag-start attributes as they are now; NaN for an absent base. */
@@ -55,6 +74,7 @@ export function readDragStamp(element: HTMLElement): DragStamp {
baseX: read("data-hf-drag-gsap-base-x"),
baseY: read("data-hf-drag-gsap-base-y"),
at: readEditMoment(element),
+ ...(element.getAttribute(DRAG_MOVING_ATTR) !== null && { moving: true }),
};
}
diff --git a/packages/studio/src/hooks/gsapEditOutcome.ts b/packages/studio/src/hooks/gsapEditOutcome.ts
index 2f329d2a46..eacce462ba 100644
--- a/packages/studio/src/hooks/gsapEditOutcome.ts
+++ b/packages/studio/src/hooks/gsapEditOutcome.ts
@@ -27,6 +27,7 @@ export type GsapEditBlockDetail =
| "live-rotation-no-source-tween"
| "live-resize-no-source-tween"
| "zero-duration-tween"
+ | "frame-tweens-unreadable"
| PlayheadEditRefusal;
/** Why an edit at the playhead could not be written as keyframes of the file's tween. */
@@ -90,6 +91,8 @@ const GSAP_EDIT_DETAIL_COPY: Partial> = {
"array-step-computed": `${STEP_LIST} whose value comes from code, which Studio can't keep while it edits them. ${IN_CODE}`,
"array-step-relative": `${STEP_LIST} with a relative value (like "+=40"), which an edit would apply again. ${IN_CODE}`,
"array-step-random": `${STEP_LIST} with a random() value, which an edit would roll again. ${IN_CODE}`,
+ "frame-tweens-unreadable":
+ "This preview couldn't read the layer's animation, so Studio can't save the move. Move it in the Code tab.",
};
export function gsapEditBlockMessage(
diff --git a/packages/studio/src/hooks/gsapFrameSnapshot.test.ts b/packages/studio/src/hooks/gsapFrameSnapshot.test.ts
index 56087a3b50..4208931b8a 100644
--- a/packages/studio/src/hooks/gsapFrameSnapshot.test.ts
+++ b/packages/studio/src/hooks/gsapFrameSnapshot.test.ts
@@ -43,11 +43,11 @@ afterEach(() => {
usePlayerStore.setState({ currentTime: 0, isPlaying: false });
});
-async function readReply(reply: unknown) {
+async function readReply(reply: unknown, holds = true) {
usePlayerStore.setState({ currentTime: 0.5, isPlaying: false });
request.mockResolvedValue(reply);
const iframe = document.createElement("iframe");
- await expect(settleGsapSnapshot(iframe)).resolves.toBeUndefined();
+ await expect(settleGsapSnapshot(iframe)).resolves.toBe(holds);
return iframe;
}
@@ -78,7 +78,7 @@ it.each([
["an id past the text bound", snapshot({ targets: [{ ...target, id: "b".repeat(4_097) }] })],
["a reply that is not a record", "gsap"],
])("refuses %s and holds nothing", async (_name, reply) => {
- const iframe = await readReply(reply);
+ const iframe = await readReply(reply, false);
expect(frameTimelines(iframe)).toBeNull();
expect(frameDocument(iframe)).toBeNull();
diff --git a/packages/studio/src/hooks/gsapFrameSnapshot.ts b/packages/studio/src/hooks/gsapFrameSnapshot.ts
index 0f68e29c16..22eaf8815c 100644
--- a/packages/studio/src/hooks/gsapFrameSnapshot.ts
+++ b/packages/studio/src/hooks/gsapFrameSnapshot.ts
@@ -75,15 +75,16 @@ function refreshGsapSnapshot(iframe: HTMLIFrameElement): Promise {
return pending;
}
-/** Reads the frame again unless the held read is at the paused playhead, for async callers. */
-export async function settleGsapSnapshot(iframe: HTMLIFrameElement | null): Promise {
- if (!iframe || !previewFrameOpaque(iframe)) return;
+/** Reads the frame again unless the held read is at the paused playhead; false if an opaque frame holds none. */
+export async function settleGsapSnapshot(iframe: HTMLIFrameElement | null): Promise {
+ if (!iframe || !previewFrameOpaque(iframe)) return true;
const client = previewEditingClient(iframe);
for (let reads = 0; reads < 2; reads++) {
const snapshot = held.get(client);
- if (snapshot && fresh(snapshot)) return;
+ if (snapshot && fresh(snapshot)) return true;
await refreshGsapSnapshot(iframe);
}
+ return held.has(client);
}
async function read(iframe: HTMLIFrameElement, client: EditingPortClient): Promise {
diff --git a/packages/studio/src/hooks/gsapRuntimeBridge.ts b/packages/studio/src/hooks/gsapRuntimeBridge.ts
index 8abb258470..a8fcba3792 100644
--- a/packages/studio/src/hooks/gsapRuntimeBridge.ts
+++ b/packages/studio/src/hooks/gsapRuntimeBridge.ts
@@ -33,6 +33,7 @@ import { roundTo3 } from "../utils/rounding";
import type { GsapDragCommitCallbacks } from "./gsapDragCommit";
import { readDragStamp, type DragStamp } from "./draggedGsapPosition";
import { editMoment } from "./editMoment";
+import { settleGsapSnapshot } from "./gsapFrameSnapshot";
import type { EditMoment } from "../components/editor/manualEditsTypes";
import { isInstantHold, selectorFromSelection, writeTargetSelector } from "./gsapShared";
import {
@@ -261,6 +262,9 @@ export async function tryGsapDragIntercept(
const stamp = options?.stamp ?? readDragStamp(selection.element);
const moment = editMoment(stamp);
const time = moment.time;
+ if (!(await settleGsapSnapshot(iframe)) && stamp.moving) {
+ return { status: "blocked", reason: "source-uneditable", detail: "frame-tweens-unreadable" };
+ }
if (!options?.preflightPassed) {
const preflight = await preflightGsapDragIntercept(
selection,