Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
fix(studio): drags after a resize, undo or reload land where they were pressed (#5088)
Miguel Ángeldc244d765c3e
diff --git a/.fallowrc.jsonc b/.fallowrc.jsoncindex c26b78416b..e7642999fe 100644--- a/.fallowrc.jsonc+++ b/.fallowrc.jsonc@@ -524,6 +524,15 @@"packages/studio/src/components/editor/domEditOverlayStartGesture.test.ts","packages/studio/src/components/editor/anchoredResizeCommitFeedsOffset.test.ts","packages/studio/src/components/editor/rotateInlineSave.test.ts",+ // Waiting-press and drag tests: each case spells out its own press, reload and release; a shared+ // helper would hide the sequence each one asserts.+ "packages/studio/src/components/editor/domEditOverlayStartGesture.blocked.test.ts",+ "packages/studio/src/components/editor/dragUndoPaint.test.ts",+ "packages/studio/src/components/editor/manualOffsetDrag.test.ts",+ "packages/studio/src/components/editor/gestureHoldsPreviewReload.test.tsx",+ // Preview reload tests: each case spells out its own mount, reload and swap sequence.+ "packages/studio/src/player/hooks/useTimelinePlayer.shadowReload.test.ts",+ "packages/studio/src/components/nle/NLEContext.test.ts","packages/studio/src/hooks/useDomGeometryCommits.test.tsx",// extractionCache.test.ts: pre-existing parallel describe setup and publish-case arrange/assert blocks."packages/engine/src/services/extractionCache.test.ts",diff --git a/packages/parsers/src/gsapConstants.ts b/packages/parsers/src/gsapConstants.tsindex 43ea02ca6a..1ee9d9e689 100644--- a/packages/parsers/src/gsapConstants.ts+++ b/packages/parsers/src/gsapConstants.ts@@ -147,7 +147,7 @@ export interface HoldScope {const tweenSignature = (a: GsapAnimation) =>JSON.stringify([a.targetSelector, a.method, a.position, a.duration, a.properties, a.keyframes]);-/** The tweens an edit touched (not in `previous`; none without it), and what the script's holds already pin. */+/** The tweens an edit touched (not in `previous`; all without it), and what the script's holds already pin. */export function holdScope(before: readonly GsapAnimation[],previous: readonly GsapAnimation[] | null,@@ -160,14 +160,14 @@ export function holdScope(held.set(a.targetSelector, props);}return {- touched: (a) => previous !== null && !kept.has(tweenSignature(a)),+ touched: (a) => previous === null || !kept.has(tweenSignature(a)),held: (selector) => held.get(selector) ?? new Map(),};}/**- * What a Studio hold pins from t=0: a keyframed tween's 0% position props before a later start, and the position and- * size of a lone key (GSAP renders none) only where this edit made it or a hold already pins it, minus earlier tweens.+ * What a Studio hold pins from t=0, only for a tween this edit touched or a hold already pins: the 0% position props+ * before a later start, and the position and size of a lone key (GSAP renders none), minus earlier tweens.*/export function keyframeHoldForAnimation(animation: GsapAnimation,@@ -196,9 +196,10 @@ export function keyframeHoldForAnimation(// An untouched tween keeps only the hold it made: one with its own first value.const kept = (property: string, value: unknown) =>touched ? pinned.has(property) : pinned.get(property) === value;+ const startsLate = start > 0.001;const pins = (group: PropertyGroupName, property: string, value: unknown) =>- (group === "position" && start > 0.001) ||- ((group === "position" || group === "size") && ((lone && touched) || kept(property, value)));+ (group === "position" || group === "size") &&+ (((lone || (group === "position" && startsLate)) && touched) || kept(property, value));const hold: Record<string, number> = {};for (const [property, value] of Object.entries(atStart.properties)) {if (!pins(classifyPropertyGroup(property), property, value) || typeof value !== "number")diff --git a/packages/parsers/src/gsapParser.test.ts b/packages/parsers/src/gsapParser.test.tsindex 78bab7cef2..d8b63f1213 100644--- a/packages/parsers/src/gsapParser.test.ts+++ b/packages/parsers/src/gsapParser.test.ts@@ -1787,6 +1787,15 @@ describe("keyframe mutations", () => {expect((out2.match(/hf-hold/g) ?? []).length).toBe(1); // still just one});+ it.each([+ ["recast", syncPositionHoldsBeforeKeyframes],+ ["acorn", syncPositionHoldsBeforeKeyframesAcorn],+ ])("%s: an edit to another element pins no position on a tween it did not touch", (_, sync) => {+ const before = `${posTweenAt(1.2)}\ntl.to("#q", { x: 10, duration: 1 }, 0);`;+ const after = before.replace("x: 10", "x: 40");+ expect(sync(after, before)).toBe(after);+ });+it("adds no hold for a tween that already starts at t=0", () => {expect(syncPositionHoldsBeforeKeyframes(posTweenAt(0))).not.toContain("hf-hold");});diff --git a/packages/studio-server/src/routes/files.test.ts b/packages/studio-server/src/routes/files.test.tsindex 24cada34dd..c3e6368147 100644--- a/packages/studio-server/src/routes/files.test.ts+++ b/packages/studio-server/src/routes/files.test.ts@@ -2830,6 +2830,30 @@ ${authored}expect(result.after).toContain("tl.to(kicker,");});+ it.each([+ ["#b", false],+ ["#p", true],+ ])("shifting %s pins #p before its first key: %s", async (targetSelector, held) => {+ const dir = createProjectDir();+ writeHtml(+ dir,+ "index.html",+ `<!DOCTYPE html><html><body><script data-hyperframes-gsap>+const tl = gsap.timeline({ paused: true });+tl.to("#p", { keyframes: { "0%": { x: -150 }, "100%": { x: 0 } }, duration: 2 }, 1.2);+tl.to("#b", { duration: 1, x: 200 }, 2);+</script></body></html>`,+ );+ const app = new Hono();+ registerFileRoutes(app, createAdapter(dir));+ const res = await app.request("http://localhost/projects/demo/gsap-mutations/index.html", {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({ type: "shift-positions", targetSelector, delta: 1 }),+ });+ expect(((await res.json()) as { after: string }).after.includes("hf-hold")).toBe(held);+ });+it("shift-positions-batch equals sequential single shifts (atomic multi-clip)", async () => {const TWO_TWEENS = `<!DOCTYPE html><html><body><script data-hyperframes-gsap>const tl = gsap.timeline({ paused: true });diff --git a/packages/studio-server/src/routes/files.ts b/packages/studio-server/src/routes/files.tsindex 8d8083e027..7f479bc842 100644--- a/packages/studio-server/src/routes/files.ts+++ b/packages/studio-server/src/routes/files.ts@@ -1527,7 +1527,7 @@ function clipRetimeOf(mutation: GsapMutationRequest): RetimeSlot | null {function retimeRun(script: string, run: readonly RetimeSlot[], root: ParentNode | undefined) {const live = run.filter((slot): slot is ClipTweenRetime => slot !== "no-op");const retimed = retimeClipTweensInScript(script, live, root);- const synced = syncPositionHoldsBeforeKeyframes(retimed.script);+ const synced = syncPositionHoldsBeforeKeyframes(retimed.script, script);let next = 0;const changed = run.map((slot) => slot !== "no-op" && retimed.changed[next++]!);if (synced !== retimed.script) changed[changed.length - 1] = true;diff --git a/packages/studio/src/App.tsx b/packages/studio/src/App.tsxindex 7a30d3c4fa..e9b0ce971b 100644--- a/packages/studio/src/App.tsx+++ b/packages/studio/src/App.tsx@@ -1,6 +1,6 @@import { useOwnPreviewIframe, usePreviewIframeStore } from "./player/store/previewIframeStore";import { buildProjectApiPath } from "./utils/projectRouting";-import { useState, useCallback, useRef, useMemo } from "react";+import { useState, useCallback, useRef, useMemo, type SetStateAction } from "react";import { useStableHandlers } from "./hooks/useStableHandlers";import { useHistoryFlags, useToolbarSession } from "./hooks/useShellSlices";import { useDismissingTabSetter, useRightPanelIntent } from "./hooks/useRightPanelIntents";@@ -62,6 +62,7 @@ import { useStudioSessionStart } from "./hooks/useStudioSessionStart";import { useTimelineAddAtPlayhead } from "./hooks/useTimelineAddAtPlayhead";import { readStudioUrlStateFromWindow, resolveMasterCompositionPath } from "./utils/studioUrlState";import { useActiveComposition } from "./hooks/useActiveComposition";+import { requestPreviewReload } from "./player/previewReloading";const getTimelineSelectionSet = () => usePlayerStore.getState().selectedElementIds;export interface StudioAppProps {@@ -79,7 +80,7 @@ export function StudioApp({ readOnlyPreview = false, readOnlyPreviewReason }: Stconst [compIdToSrc, setCompIdToSrc] = useState<Map<string, string>>(new Map());const previewIframe = useOwnPreviewIframe();const [compositionLoading, setCompositionLoading] = useState(true);- const [refreshKey, setRefreshKey] = useState(0);+ const [refreshKey, setRefreshKeyState] = useState(0);const [previewDocumentVersion, refreshPreviewDocumentVersion] = usePreviewDocumentVersion();const [blockPreview, setBlockPreview] = useState<BlockPreviewInfo | null>(null);const previewIframeRef = useRef<HTMLIFrameElement | null>(null);@@ -104,7 +105,11 @@ export function StudioApp({ readOnlyPreview = false, readOnlyPreviewReason }: Stconst handleDomZIndexReorderCommitRef = useRef<TimelineZIndexReorderCommit | null>(null);const pendingTimelineEditPathRef = useRef(new Set<string>());const isGestureRecordingRef = useRef(false);- const reloadPreview = useCallback(() => setRefreshKey((k) => k + 1), []);+ const setRefreshKey = useCallback((next: SetStateAction<number>) => {+ requestPreviewReload();+ setRefreshKeyState(next);+ }, []);+ const reloadPreview = useCallback(() => setRefreshKey((k) => k + 1), [setRefreshKey]);const fileManagerResult = useFileManager({projectId,showToast,@@ -144,7 +149,7 @@ export function StudioApp({ readOnlyPreview = false, readOnlyPreviewReason }: StrecordEdit: editHistory.recordEdit,previewIframeRef,activeCompPathRef,- reloadPreview: () => setRefreshKey((k) => k + 1),+ reloadPreview,});const previewPersistence = useStableHandlers(previewPersistenceResult, projectId);const externalFileChanges = useStudioExternalFileChanges({diff --git a/packages/studio/src/components/editor/DomEditOverlay.tsx b/packages/studio/src/components/editor/DomEditOverlay.tsxindex e740013132..4edd7a3b0f 100644--- a/packages/studio/src/components/editor/DomEditOverlay.tsx+++ b/packages/studio/src/components/editor/DomEditOverlay.tsx@@ -10,6 +10,7 @@ import { useZOrderCrossedFlash, ZOrderCrossedFlash } from "./useZOrderCrossedFlaimport { useCanvasContextMenuState } from "./useCanvasContextMenuState";import {type BlockedMoveState,+ type WaitingPressState,type DomEditGroupPathOffsetCommit,type FocusableDomEditOverlay,type MoveCommitOptions,@@ -166,6 +167,7 @@ export const DomEditOverlay = memo(function DomEditOverlay({const gestureRef = useRef<GestureState | null>(null);const groupGestureRef = useRef<GroupGestureState | null>(null);const blockedMoveRef = useRef<BlockedMoveState | null>(null);+ const waitingPressRef = useRef<WaitingPressState | null>(null);const suppressNextBoxClickRef = useRef(false);const snapGuidesRef = useRef<SnapGuidesState | null>(null);const rafPausedRef = useRef(false);@@ -273,6 +275,7 @@ export const DomEditOverlay = memo(function DomEditOverlay({});const gestures = createDomEditOverlayGestureHandlers({+ activeCompositionPathRef,overlayRef,iframeRef,boxRef,@@ -283,6 +286,7 @@ export const DomEditOverlay = memo(function DomEditOverlay({gestureRef,groupGestureRef,blockedMoveRef,+ waitingPressRef,rafPausedRef,suppressNextBoxClickRef,setOverlayRect,@@ -299,17 +303,17 @@ export const DomEditOverlay = memo(function DomEditOverlay({});useEffect(() => {- if (readOnly) gestures.clearPointerState(selectionRef);+ if (readOnly) gestures.clearPointerState(selectionRef, true);}, [gestures, readOnly, selectionRef]);// A gesture that loses its pointer, the window or the overlay is cancelled, so its mark goes too.- const cancelGestureRef = useRef(() => {});- cancelGestureRef.current = () => gestures.clearPointerState(selectionRef);+ const cancelGestureRef = useRef((_dropQueued?: boolean) => {});+ cancelGestureRef.current = (dropQueued) => gestures.clearPointerState(selectionRef, dropQueued);useMountEffect(() => {const cancel = () => cancelGestureRef.current();window.addEventListener("blur", cancel);return () => {window.removeEventListener("blur", cancel);- cancel();+ cancelGestureRef.current(true);};});@@ -493,7 +497,7 @@ export const DomEditOverlay = memo(function DomEditOverlay({onPointerLeave={() => onCanvasPointerLeaveRef.current()}onPointerUp={marquee.onPointerUp}onPointerCancel={marquee.onPointerCancel}- onLostPointerCapture={() => cancelGestureRef.current()}+ onLostPointerCapture={gestures.onLostPointerCapture}onContextMenu={hostInput ? undefined : handleContextMenu}>{!hostInput && hoverSelection && hoverRect && compRect.width > 0 && (diff --git a/packages/studio/src/components/editor/PropertyPanel.test.tsx b/packages/studio/src/components/editor/PropertyPanel.test.tsxindex 5cfdf7659f..91e820fa96 100644--- a/packages/studio/src/components/editor/PropertyPanel.test.tsx+++ b/packages/studio/src/components/editor/PropertyPanel.test.tsx@@ -5,6 +5,9 @@ import { createRoot } from "react-dom/client";import { afterEach, describe, expect, it, vi } from "vitest";import type { PropertyPanelProps } from "./propertyPanelHelpers";import type { TimelineEditCallbacks } from "../../player/components/timelineCallbacks";+import { PropertyPanel } from "./PropertyPanel";+import { TimelineEditProvider } from "../../contexts/TimelineEditContext";+import { usePlayerStore } from "../../player/store/playerStore";(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;@@ -17,10 +20,35 @@ vi.mock("../../contexts/StudioContext", async () => {return { ...actual, useStudioShellContext: () => ({ showToast: vi.fn() }) };});+// The panel is imported once: re-importing it per test made the first test pay a cold transform.+const panel = vi.hoisted(() => ({+ flat: false,+ actions: null as null | {+ refreshDomEditSelectionFromPreview: unknown;+ domEditSelectionRef: unknown;+ },+}));+vi.mock("./manualEditingAvailability", async (importOriginal) => ({+ ...(await importOriginal<typeof import("./manualEditingAvailability")>()),+ get STUDIO_FLAT_INSPECTOR_ENABLED() {+ return panel.flat;+ },+}));+vi.mock("../../contexts/DomEditContext", async (importOriginal) => {+ const actual = await importOriginal<typeof import("../../contexts/DomEditContext")>();+ return {+ ...actual,+ useDomEditActionsContextOptional: () =>+ panel.actions ?? actual.useDomEditActionsContextOptional(),+ };+});++const initialPlayerState = usePlayerStore.getState();+afterEach(() => {document.body.innerHTML = "";- vi.doUnmock("./manualEditingAvailability");- vi.resetModules();+ panel.actions = null;+ usePlayerStore.setState(initialPlayerState, true);});function baseElement(): NonNullable<PropertyPanelProps["element"]> {@@ -244,39 +272,17 @@ async function renderPanel(selectionRef?: { current: unknown };} = {},) {- vi.resetModules();- vi.doMock("./manualEditingAvailability", async () => {- const actual = await vi.importActual<typeof import("./manualEditingAvailability")>(- "./manualEditingAvailability",- );- return { ...actual, STUDIO_FLAT_INSPECTOR_ENABLED: flatEnabled };- });- vi.doMock("../../contexts/DomEditContext", async () => {- const actual = await vi.importActual<typeof import("../../contexts/DomEditContext")>(- "../../contexts/DomEditContext",- );- const { refreshSelection: refresh, selectionRef } = options;- return refresh && selectionRef- ? {- ...actual,- useDomEditActionsContextOptional: () => ({- refreshDomEditSelectionFromPreview: refresh,- domEditSelectionRef: selectionRef,- }),- }- : actual;- });- // Seed the playhead and selection on the same store instance PropertyPanel.tsx- // reads (module-fresh after the resetModules() above), before it is imported so- // its first render sees them.- const { usePlayerStore } = await import("../../player/store/playerStore");+ panel.flat = flatEnabled;+ const { refreshSelection: refresh, selectionRef } = options;+ panel.actions =+ refresh && selectionRef+ ? { refreshDomEditSelectionFromPreview: refresh, domEditSelectionRef: selectionRef }+ : null;if (options.currentTime !== undefined) {usePlayerStore.getState().setCurrentTime(options.currentTime);}if (options.selectedElementId)usePlayerStore.setState({ selectedElementId: options.selectedElementId });- const { PropertyPanel } = await import("./PropertyPanel");- const { TimelineEditProvider } = await import("../../contexts/TimelineEditContext");const host = document.createElement("div");document.body.append(host);const root = createRoot(host);@@ -304,15 +310,6 @@ async function renderPanel(return { host, root, render };}-// renderPanel resetModules()+dynamic-imports PropertyPanel (needed for a fresh-// flag read); transforming the full section graph uncached can exceed the 5s-// default under heavy parallel full-suite load, so give these a wider margin.-// 20s itself has now been observed timing out in CI's full-monorepo run (the-// same suite passes in well under 2s standalone) — widened again rather than-// re-tuned down to a number that will just need doing again next time CI adds-// load.-const RENDER_TIMEOUT_MS = 45_000;-// Find the collapsed accordion row whose title matches and click it open.function openFlatGroup(host: HTMLElement, title: string) {const row = Array.from(host.querySelectorAll('[data-flat-group-collapsed="true"]')).find((el) =>@@ -326,229 +323,181 @@ const openGroupText = (host: HTMLElement) =>host.querySelector('[data-flat-group-open="true"]')?.textContent ?? "";describe("PropertyPanel — STUDIO_FLAT_INSPECTOR_ENABLED off", () => {- it(- "renders the legacy header, not the flat header",- async () => {- const { host, root } = await renderPanel(false);- expect(host.querySelector('[data-flat-header-icon="true"]')).toBeNull();- expect(host.textContent).toContain("Mono Label");- act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ it("renders the legacy header, not the flat header", async () => {+ const { host, root } = await renderPanel(false);+ expect(host.querySelector('[data-flat-header-icon="true"]')).toBeNull();+ expect(host.textContent).toContain("Mono Label");+ act(() => root.unmount());+ });});describe("PropertyPanel — STUDIO_FLAT_INSPECTOR_ENABLED on", () => {- it(- "renders the flat header, the Text group open by default, and the flat footer",- async () => {- const { host, root } = await renderPanel(true);- expect(host.querySelector('[data-flat-header-icon="true"]')).not.toBeNull();- expect(host.querySelector('[data-flat-group-open="true"]')).not.toBeNull();- expect(host.textContent).toContain("Ask agent about this element");- act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ it("renders the flat header, the Text group open by default, and the flat footer", async () => {+ const { host, root } = await renderPanel(true);+ expect(host.querySelector('[data-flat-header-icon="true"]')).not.toBeNull();+ expect(host.querySelector('[data-flat-group-open="true"]')).not.toBeNull();+ expect(host.textContent).toContain("Ask agent about this element");+ act(() => root.unmount());+ });- it(- "collapses the Text group on caret click and can reopen it",- async () => {- const { host, root } = await renderPanel(true);- const collapseButton = host.querySelector<HTMLButtonElement>(- '[data-flat-group-open="true"] button[title="Collapse"]',- );- act(() => collapseButton?.dispatchEvent(new MouseEvent("click", { bubbles: true })));- expect(host.querySelector('[data-flat-group-open="true"]')).toBeNull();- const collapsedRow = host.querySelector<HTMLButtonElement>(- '[data-flat-group-collapsed="true"]',- );- expect(collapsedRow).not.toBeNull();- act(() => collapsedRow?.dispatchEvent(new MouseEvent("click", { bubbles: true })));- expect(host.querySelector('[data-flat-group-open="true"]')).not.toBeNull();- act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ it("collapses the Text group on caret click and can reopen it", async () => {+ const { host, root } = await renderPanel(true);+ const collapseButton = host.querySelector<HTMLButtonElement>(+ '[data-flat-group-open="true"] button[title="Collapse"]',+ );+ act(() => collapseButton?.dispatchEvent(new MouseEvent("click", { bubbles: true })));+ expect(host.querySelector('[data-flat-group-open="true"]')).toBeNull();+ const collapsedRow = host.querySelector<HTMLButtonElement>(+ '[data-flat-group-collapsed="true"]',+ );+ expect(collapsedRow).not.toBeNull();+ act(() => collapsedRow?.dispatchEvent(new MouseEvent("click", { bubbles: true })));+ expect(host.querySelector('[data-flat-group-open="true"]')).not.toBeNull();+ act(() => root.unmount());+ });- it(- "renders no Text group at all for a non-text element (bug 1)",- async () => {- // nonTextElement() inherits canEditStyles: true from baseElement(), so- // the Style group (Task 10) renders and opens by default here — the- // invariant under test is narrower than "no flat group at all": no- // group titled "Text" may appear, open or collapsed.- const { host, root } = await renderPanel(true, nonTextElement());- const openTitle = host.querySelector(- '[data-flat-group-open="true"] .text-panel-text-0',- )?.textContent;- const collapsedTitles = Array.from(- host.querySelectorAll('[data-flat-group-collapsed="true"] .text-panel-text-2'),- ).map((el) => el.textContent);- expect(openTitle).not.toBe("Text");- expect(collapsedTitles).not.toContain("Text");- act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ it("renders no Text group at all for a non-text element (bug 1)", async () => {+ // nonTextElement() inherits canEditStyles: true from baseElement(), so+ // the Style group (Task 10) renders and opens by default here — the+ // invariant under test is narrower than "no flat group at all": no+ // group titled "Text" may appear, open or collapsed.+ const { host, root } = await renderPanel(true, nonTextElement());+ const openTitle = host.querySelector(+ '[data-flat-group-open="true"] .text-panel-text-0',+ )?.textContent;+ const collapsedTitles = Array.from(+ host.querySelectorAll('[data-flat-group-collapsed="true"] .text-panel-text-2'),+ ).map((el) => el.textContent);+ expect(openTitle).not.toBe("Text");+ expect(collapsedTitles).not.toContain("Text");+ act(() => root.unmount());+ });- it(- "renders exactly one Text heading for a multi-field text element (bug 2)",- async () => {- const { host, root } = await renderPanel(true, multiFieldTextElement());- // The FlatGroup's own "Text" heading is the only one that should exist —- // the legacy TextSection's internal Section heading (data-panel-section- // ="text") must never appear, since the flat multi-field path no longer- // delegates to that component at all.- expect(host.querySelector('[data-flat-group-open="true"]')).not.toBeNull();- expect(host.querySelector('[data-panel-section="text"]')).toBeNull();- // Content from the flat multi-field layer list must render.- expect(host.textContent).toContain("Text layers");- act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ it("renders exactly one Text heading for a multi-field text element (bug 2)", async () => {+ const { host, root } = await renderPanel(true, multiFieldTextElement());+ // The FlatGroup's own "Text" heading is the only one that should exist —+ // the legacy TextSection's internal Section heading (data-panel-section+ // ="text") must never appear, since the flat multi-field path no longer+ // delegates to that component at all.+ expect(host.querySelector('[data-flat-group-open="true"]')).not.toBeNull();+ expect(host.querySelector('[data-panel-section="text"]')).toBeNull();+ // Content from the flat multi-field layer list must render.+ expect(host.textContent).toContain("Text layers");+ act(() => root.unmount());+ });});describe("PropertyPanel — Style group (flag on)", () => {- it(- "renders the Style group for a style-editable, non-text element",- async () => {- const { host, root } = await renderPanel(true, styleOnlyElement());- expect(host.textContent).toContain("Style");- expect(host.textContent).toContain("Fill");- act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ it("renders the Style group for a style-editable, non-text element", async () => {+ const { host, root } = await renderPanel(true, styleOnlyElement());+ expect(host.textContent).toContain("Style");+ expect(host.textContent).toContain("Fill");+ act(() => root.unmount());+ });- it(- "one-open accordion: opening Style closes Text",- async () => {- // baseElement() is text-editable and has capabilities.canEditStyles:- // true, so both the Text and Style groups render for it.- const { host, root } = await renderPanel(true);- const textGroup = () => host.querySelector('[data-flat-group-open="true"]');- expect(textGroup()?.textContent).toContain("Text");- const styleCollapsedRow = Array.from(- host.querySelectorAll('[data-flat-group-collapsed="true"]'),- ).find((el) => el.textContent?.includes("Style"));- if (!styleCollapsedRow) throw new Error("expected a collapsed Style row");- act(() => styleCollapsedRow.dispatchEvent(new MouseEvent("click", { bubbles: true })));- expect(textGroup()?.textContent).not.toContain("Text");- expect(host.querySelector('[data-flat-group-open="true"]')?.textContent).toContain("Style");- act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ it("one-open accordion: opening Style closes Text", async () => {+ // baseElement() is text-editable and has capabilities.canEditStyles:+ // true, so both the Text and Style groups render for it.+ const { host, root } = await renderPanel(true);+ const textGroup = () => host.querySelector('[data-flat-group-open="true"]');+ expect(textGroup()?.textContent).toContain("Text");+ const styleCollapsedRow = Array.from(+ host.querySelectorAll('[data-flat-group-collapsed="true"]'),+ ).find((el) => el.textContent?.includes("Style"));+ if (!styleCollapsedRow) throw new Error("expected a collapsed Style row");+ act(() => styleCollapsedRow.dispatchEvent(new MouseEvent("click", { bubbles: true })));+ expect(textGroup()?.textContent).not.toContain("Text");+ expect(host.querySelector('[data-flat-group-open="true"]')?.textContent).toContain("Style");+ act(() => root.unmount());+ });});describe("PropertyPanel — Layout group (Plan 3a)", () => {- it(- "always renders the Layout group, and opening it closes whichever other group was open",- async () => {- const { host, root } = await renderPanel(true);- // Text group is open by default for the base text-editable fixture.- expect(host.querySelector('[data-flat-group-open="true"]')?.textContent).toContain("Text");-- const layoutCollapsedRow = Array.from(- host.querySelectorAll('[data-flat-group-collapsed="true"]'),- ).find((el) => el.textContent?.includes("Layout"));- if (!layoutCollapsedRow) throw new Error("expected a collapsed Layout row");- act(() => layoutCollapsedRow.dispatchEvent(new MouseEvent("click", { bubbles: true })));-- const openGroup = host.querySelector('[data-flat-group-open="true"]');- expect(openGroup?.textContent).toContain("Layout");- expect(openGroup?.textContent).toContain("X");- expect(openGroup?.textContent).not.toContain("Ask agent"); // sanity: not matching the footer- act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ it("always renders the Layout group, and opening it closes whichever other group was open", async () => {+ const { host, root } = await renderPanel(true);+ // Text group is open by default for the base text-editable fixture.+ expect(host.querySelector('[data-flat-group-open="true"]')?.textContent).toContain("Text");++ const layoutCollapsedRow = Array.from(+ host.querySelectorAll('[data-flat-group-collapsed="true"]'),+ ).find((el) => el.textContent?.includes("Layout"));+ if (!layoutCollapsedRow) throw new Error("expected a collapsed Layout row");+ act(() => layoutCollapsedRow.dispatchEvent(new MouseEvent("click", { bubbles: true })));++ const openGroup = host.querySelector('[data-flat-group-open="true"]');+ expect(openGroup?.textContent).toContain("Layout");+ expect(openGroup?.textContent).toContain("X");+ expect(openGroup?.textContent).not.toContain("Ask agent"); // sanity: not matching the footer+ act(() => root.unmount());+ });- it(- "renders Flex exactly once on the flat path (flat Layout only, legacy suppressed)",- async () => {- const { host, root } = await renderPanel(true, flexElement());- const layoutCollapsedRow = Array.from(- host.querySelectorAll('[data-flat-group-collapsed="true"]'),- ).find((el) => el.textContent?.includes("Layout"));- if (!layoutCollapsedRow) throw new Error("expected a collapsed Layout row");- act(() => layoutCollapsedRow.dispatchEvent(new MouseEvent("click", { bubbles: true })));-- // The legacy StyleSections Flex `Section` (data-panel-section="flex") must- // NOT render on the flat path — the only two Flex renderers are the legacy- // Section and the flat LayoutFlexBlock, so its absence + the flat block's- // presence proves Flex renders exactly once (not twice, not zero).- expect(host.querySelector('[data-panel-section="flex"]')).toBeNull();- const openGroup = host.querySelector('[data-flat-group-open="true"]');- expect(openGroup?.textContent).toContain("Layout");- expect(openGroup?.textContent).toContain("Flex");- act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ it("renders Flex exactly once on the flat path (flat Layout only, legacy suppressed)", async () => {+ const { host, root } = await renderPanel(true, flexElement());+ const layoutCollapsedRow = Array.from(+ host.querySelectorAll('[data-flat-group-collapsed="true"]'),+ ).find((el) => el.textContent?.includes("Layout"));+ if (!layoutCollapsedRow) throw new Error("expected a collapsed Layout row");+ act(() => layoutCollapsedRow.dispatchEvent(new MouseEvent("click", { bubbles: true })));++ // The legacy StyleSections Flex `Section` (data-panel-section="flex") must+ // NOT render on the flat path — the only two Flex renderers are the legacy+ // Section and the flat LayoutFlexBlock, so its absence + the flat block's+ // presence proves Flex renders exactly once (not twice, not zero).+ expect(host.querySelector('[data-panel-section="flex"]')).toBeNull();+ const openGroup = host.querySelector('[data-flat-group-open="true"]');+ expect(openGroup?.textContent).toContain("Layout");+ expect(openGroup?.textContent).toContain("Flex");+ act(() => root.unmount());+ });});describe("PropertyPanel — Motion group (Plan 3b)", () => {- it(- "renders the Motion group with Timing, and opening it closes the previously open group (4-way exclusivity)",- async () => {- const { host, root } = await renderPanel(true, animatedElement());- // Text is open by default for the text-editable fixture.- expect(openGroupText(host)).toContain("Text");-- openFlatGroup(host, "Motion");- const openGroup = openGroupText(host);- expect(openGroup).toContain("Motion");- // FlatTimingRow (Start/End/Duration) renders inside the Motion group.- expect(openGroup).toContain("Start");- expect(openGroup).toContain("Duration");- // One-open accordion: opening Motion closed the Text group.- expect(openGroup).not.toContain("Text");-- // Reverse direction: opening Layout closes Motion.- openFlatGroup(host, "Layout");- const openAfter = openGroupText(host);- expect(openAfter).toContain("Layout");- expect(openAfter).not.toContain("Motion");- act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ it("renders the Motion group with Timing, and opening it closes the previously open group (4-way exclusivity)", async () => {+ const { host, root } = await renderPanel(true, animatedElement());+ // Text is open by default for the text-editable fixture.+ expect(openGroupText(host)).toContain("Text");++ openFlatGroup(host, "Motion");+ const openGroup = openGroupText(host);+ expect(openGroup).toContain("Motion");+ // FlatTimingRow (Start/End/Duration) renders inside the Motion group.+ expect(openGroup).toContain("Start");+ expect(openGroup).toContain("Duration");+ // One-open accordion: opening Motion closed the Text group.+ expect(openGroup).not.toContain("Text");++ // Reverse direction: opening Layout closes Motion.+ openFlatGroup(host, "Layout");+ const openAfter = openGroupText(host);+ expect(openAfter).toContain("Layout");+ expect(openAfter).not.toContain("Motion");+ act(() => root.unmount());+ });- it(- "hides the effect list (showEffects off) when the GSAP edit handlers are absent",- async () => {- // None of the five required edit handlers are supplied here, so the- // effect list stays closed — only the Timing row shows.- const { host, root } = await renderPanel(true, animatedElement());- openFlatGroup(host, "Motion");- const openGroup = openGroupText(host);- expect(openGroup).toContain("Motion");- expect(openGroup).toContain("Duration"); // Timing still shows- expect(openGroup).not.toContain("Add effect"); // effects gated off- act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ it("hides the effect list (showEffects off) when the GSAP edit handlers are absent", async () => {+ // None of the five required edit handlers are supplied here, so the+ // effect list stays closed — only the Timing row shows.+ const { host, root } = await renderPanel(true, animatedElement());+ openFlatGroup(host, "Motion");+ const openGroup = openGroupText(host);+ expect(openGroup).toContain("Motion");+ expect(openGroup).toContain("Duration"); // Timing still shows+ expect(openGroup).not.toContain("Add effect"); // effects gated off+ act(() => root.unmount());+ });- it(- "shows the effect list (showEffects on) when the flag and all five handlers are present",- async () => {- const { host, root } = await renderPanel(true, animatedElement(), {- onUpdateGsapProperty: vi.fn(),- onUpdateGsapMeta: vi.fn(),- onDeleteGsapAnimation: vi.fn(),- onAddGsapProperty: vi.fn(),- onAddGsapAnimation: vi.fn(),- });- openFlatGroup(host, "Motion");- expect(openGroupText(host)).toContain("Add effect");- act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ it("shows the effect list (showEffects on) when the flag and all five handlers are present", async () => {+ const { host, root } = await renderPanel(true, animatedElement(), {+ onUpdateGsapProperty: vi.fn(),+ onUpdateGsapMeta: vi.fn(),+ onDeleteGsapAnimation: vi.fn(),+ onAddGsapProperty: vi.fn(),+ onAddGsapAnimation: vi.fn(),+ });+ openFlatGroup(host, "Motion");+ expect(openGroupText(host)).toContain("Add effect");+ act(() => root.unmount());+ });});// Whole-plan coherence fix: Layout's keyframe-seek basis and Motion's Timing@@ -557,69 +506,55 @@ describe("PropertyPanel — Motion group (Plan 3b)", () => {// to a naive `duration ?? 1` while Motion correctly inferred the range from// the tween (position 2, duration 3 -> start 2 / duration 3 / end 5).describe("PropertyPanel — flat Layout/Motion timing agreement (whole-plan coherence fix)", () => {- it(- "Motion's Timing row shows the inferred start/end/duration for an element with animations but no explicit duration",- async () => {- const { host, root } = await renderPanel(true, inferredMotionElement(), {- gsapAnimations: [INFERRED_TIMING_ANIMATION],- });- openFlatGroup(host, "Motion");- const motionGroup = host.querySelector('[data-flat-group-open="true"]');- if (!motionGroup) throw new Error("expected the Motion group to be open");- expect(motionGroup.textContent).toContain("Inferred");- const inputs = motionGroup.querySelectorAll<HTMLInputElement>("input");- // FlatTimingRow renders Start, End, Duration in that order.- expect(inputs[0]?.value).toBe("2.00s");- expect(inputs[1]?.value).toBe("5.00s");- expect(inputs[2]?.value).toBe("3.00s");- act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ it("Motion's Timing row shows the inferred start/end/duration for an element with animations but no explicit duration", async () => {+ const { host, root } = await renderPanel(true, inferredMotionElement(), {+ gsapAnimations: [INFERRED_TIMING_ANIMATION],+ });+ openFlatGroup(host, "Motion");+ const motionGroup = host.querySelector('[data-flat-group-open="true"]');+ if (!motionGroup) throw new Error("expected the Motion group to be open");+ expect(motionGroup.textContent).toContain("Inferred");+ const inputs = motionGroup.querySelectorAll<HTMLInputElement>("input");+ // FlatTimingRow renders Start, End, Duration in that order.+ expect(inputs[0]?.value).toBe("2.00s");+ expect(inputs[1]?.value).toBe("5.00s");+ expect(inputs[2]?.value).toBe("3.00s");+ act(() => root.unmount());+ });- it(- "Layout's X-row keyframe gutter seeks to the SAME absolute time Motion's Timing row shows as the midpoint (50% of an inferred 2s-5s range = 3.5s)",- async () => {- const onSeekToTime = vi.fn();- // Seed the playhead at the clip's real start (t=2, the 0% keyframe's- // absolute time) — now that the follow-up fix also recomputes- // `currentPct` from the corrected elStart/elDuration basis, "current- // position is at the 0% keyframe" must be expressed as an actual t=2- // seek rather than relying on the store's untouched t=0 default (which,- // post-fix, resolves to a currentPct of -66.7% — well outside the 0%- // keyframe's tolerance window, and no longer "the case the coherence- // bug affected" that this test documents).- const { host, root } = await renderPanel(- true,- inferredMotionElement(),- { gsapAnimations: [INFERRED_TIMING_ANIMATION], onSeekToTime },- { currentTime: 2 },- );- openFlatGroup(host, "Layout");- const layoutGroup = host.querySelector('[data-flat-group-open="true"]');- if (!layoutGroup) throw new Error("expected the Layout group to be open");+ it("Layout's X-row keyframe gutter seeks to the SAME absolute time Motion's Timing row shows as the midpoint (50% of an inferred 2s-5s range = 3.5s)", async () => {+ const onSeekToTime = vi.fn();+ // The playhead sits at the clip's start (t=2, the 0% keyframe): the store's t=0 default+ // resolves to -66.7%, outside that keyframe's window.+ const { host, root } = await renderPanel(+ true,+ inferredMotionElement(),+ { gsapAnimations: [INFERRED_TIMING_ANIMATION], onSeekToTime },+ { currentTime: 2 },+ );+ openFlatGroup(host, "Layout");+ const layoutGroup = host.querySelector('[data-flat-group-open="true"]');+ if (!layoutGroup) throw new Error("expected the Layout group to be open");- const xRow = Array.from(layoutGroup.querySelectorAll<HTMLElement>(".group")).find(- (el) => el.querySelector("span")?.textContent === "X",- );- if (!xRow) throw new Error("expected an X row");- const gutter = xRow.querySelector('[data-flat-kf-gutter="true"]');- if (!gutter) throw new Error("expected a keyframe gutter on the X row");- // At currentPct=0 (playhead on the 0% keyframe) the prev arrow is- // disabled (no earlier keyframe) and the next arrow seeks to the 50%- // keyframe — exactly the case the coherence bug affected.- const nextArrow = Array.from(gutter.querySelectorAll<HTMLButtonElement>("button")).find(- (b) => b.title === "Next keyframe" && !b.disabled,- );- if (!nextArrow) throw new Error("expected an enabled next-keyframe arrow button");- act(() => nextArrow.dispatchEvent(new MouseEvent("click", { bubbles: true })));+ const xRow = Array.from(layoutGroup.querySelectorAll<HTMLElement>(".group")).find(+ (el) => el.querySelector("span")?.textContent === "X",+ );+ if (!xRow) throw new Error("expected an X row");+ const gutter = xRow.querySelector('[data-flat-kf-gutter="true"]');+ if (!gutter) throw new Error("expected a keyframe gutter on the X row");+ // At currentPct=0 (playhead on the 0% keyframe) the prev arrow is+ // disabled (no earlier keyframe) and the next arrow seeks to the 50%+ // keyframe — exactly the case the coherence bug affected.+ const nextArrow = Array.from(gutter.querySelectorAll<HTMLButtonElement>("button")).find(+ (b) => b.title === "Next keyframe" && !b.disabled,+ );+ if (!nextArrow) throw new Error("expected an enabled next-keyframe arrow button");+ act(() => nextArrow.dispatchEvent(new MouseEvent("click", { bubbles: true })));- // Same basis as the Timing row: start 2 + 50% * duration 3 = 3.5.- expect(onSeekToTime).toHaveBeenCalledWith(3.5);- act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ // Same basis as the Timing row: start 2 + 50% * duration 3 = 3.5.+ expect(onSeekToTime).toHaveBeenCalledWith(3.5);+ act(() => root.unmount());+ });});// Follow-up fix (review of 684ec4e87): the seek-basis fix above corrected@@ -631,80 +566,67 @@ describe("PropertyPanel — flat Layout/Motion timing agreement (whole-plan cohe// absolute time of the 50% keyframe (2 + 0.5*3 = 3.5) and confirm its diamond// renders "active" (title="Remove x keyframe"), not "inactive"/"ghost".describe("PropertyPanel — flat Layout currentPct basis (currentPct follow-up fix)", () => {- it(- "lights the X-row keyframe diamond as active when the playhead is seeked to that keyframe's real absolute time (inferred 2s-5s range, 50% keyframe = 3.5s)",- async () => {- const { host, root } = await renderPanel(- true,- inferredMotionElement(),- { gsapAnimations: [INFERRED_TIMING_ANIMATION] },- { currentTime: 3.5 },- );- openFlatGroup(host, "Layout");- const layoutGroup = host.querySelector('[data-flat-group-open="true"]');- if (!layoutGroup) throw new Error("expected the Layout group to be open");+ it("lights the X-row keyframe diamond as active when the playhead is seeked to that keyframe's real absolute time (inferred 2s-5s range, 50% keyframe = 3.5s)", async () => {+ const { host, root } = await renderPanel(+ true,+ inferredMotionElement(),+ { gsapAnimations: [INFERRED_TIMING_ANIMATION] },+ { currentTime: 3.5 },+ );+ openFlatGroup(host, "Layout");+ const layoutGroup = host.querySelector('[data-flat-group-open="true"]');+ if (!layoutGroup) throw new Error("expected the Layout group to be open");- const xRow = Array.from(layoutGroup.querySelectorAll<HTMLElement>(".group")).find(- (el) => el.querySelector("span")?.textContent === "X",- );- if (!xRow) throw new Error("expected an X row");- const gutter = xRow.querySelector('[data-flat-kf-gutter="true"]');- if (!gutter) throw new Error("expected a keyframe gutter on the X row");- // The diamond is the only gutter button that reports a pressed state;- // the prev/next arrows carry titles too, so `button[title]` is ambiguous.- const diamond = gutter.querySelector<HTMLButtonElement>("button[aria-pressed]");- if (!diamond) throw new Error("expected a keyframe diamond button");- // KeyframeDiamond's title mapping: active -> "Remove ... keyframe",- // inactive -> "Add ... keyframe", ghost -> "Convert ... to keyframes".- // Before this fix, currentPct was computed against the naive- // elStart=0/elDuration=1 basis, so t=3.5 produced currentPct=350% —- // nowhere near the 50% keyframe within KeyframeNavigation's tolerance —- // and the diamond stayed "inactive" even though the playhead was- // exactly on that keyframe's real time.- expect(diamond.title).toBe("Remove x keyframe");- act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ const xRow = Array.from(layoutGroup.querySelectorAll<HTMLElement>(".group")).find(+ (el) => el.querySelector("span")?.textContent === "X",+ );+ if (!xRow) throw new Error("expected an X row");+ const gutter = xRow.querySelector('[data-flat-kf-gutter="true"]');+ if (!gutter) throw new Error("expected a keyframe gutter on the X row");+ // The diamond is the only gutter button that reports a pressed state;+ // the prev/next arrows carry titles too, so `button[title]` is ambiguous.+ const diamond = gutter.querySelector<HTMLButtonElement>("button[aria-pressed]");+ if (!diamond) throw new Error("expected a keyframe diamond button");+ // "Remove" means active: on the naive 0..1 basis t=3.5 read as 350% and the diamond stayed+ // "Add" although the playhead sat on that keyframe.+ expect(diamond.title).toBe("Remove x keyframe");+ act(() => root.unmount());+ });- it(- "prev/next arrows re-center on the current keyframe once currentPct agrees with the corrected seek basis",- async () => {- const onSeekToTime = vi.fn();- const { host, root } = await renderPanel(- true,- inferredMotionElement(),- { gsapAnimations: [INFERRED_TIMING_ANIMATION], onSeekToTime },- { currentTime: 3.5 },- );- openFlatGroup(host, "Layout");- const layoutGroup = host.querySelector('[data-flat-group-open="true"]');- if (!layoutGroup) throw new Error("expected the Layout group to be open");+ it("prev/next arrows re-center on the current keyframe once currentPct agrees with the corrected seek basis", async () => {+ const onSeekToTime = vi.fn();+ const { host, root } = await renderPanel(+ true,+ inferredMotionElement(),+ { gsapAnimations: [INFERRED_TIMING_ANIMATION], onSeekToTime },+ { currentTime: 3.5 },+ );+ openFlatGroup(host, "Layout");+ const layoutGroup = host.querySelector('[data-flat-group-open="true"]');+ if (!layoutGroup) throw new Error("expected the Layout group to be open");- const xRow = Array.from(layoutGroup.querySelectorAll<HTMLElement>(".group")).find(- (el) => el.querySelector("span")?.textContent === "X",- );- if (!xRow) throw new Error("expected an X row");- const gutter = xRow.querySelector('[data-flat-kf-gutter="true"]');- if (!gutter) throw new Error("expected a keyframe gutter on the X row");- const buttons = Array.from(gutter.querySelectorAll<HTMLButtonElement>("button"));- const [prevArrow, , nextArrow] = buttons;- if (!prevArrow || !nextArrow) throw new Error("expected prev/next arrow buttons");- // At the 50% keyframe (t=3.5), prev should target the 0% keyframe- // (absolute t=2) and next should target the 100% keyframe (absolute- // t=5) — both only resolvable once currentPct agrees with elStart=2/- // elDuration=3, the same basis the seek fix already uses.- expect(prevArrow.disabled).toBe(false);- act(() => prevArrow.dispatchEvent(new MouseEvent("click", { bubbles: true })));- expect(onSeekToTime).toHaveBeenLastCalledWith(2);-- expect(nextArrow.disabled).toBe(false);- act(() => nextArrow.dispatchEvent(new MouseEvent("click", { bubbles: true })));- expect(onSeekToTime).toHaveBeenLastCalledWith(5);- act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ const xRow = Array.from(layoutGroup.querySelectorAll<HTMLElement>(".group")).find(+ (el) => el.querySelector("span")?.textContent === "X",+ );+ if (!xRow) throw new Error("expected an X row");+ const gutter = xRow.querySelector('[data-flat-kf-gutter="true"]');+ if (!gutter) throw new Error("expected a keyframe gutter on the X row");+ const buttons = Array.from(gutter.querySelectorAll<HTMLButtonElement>("button"));+ const [prevArrow, , nextArrow] = buttons;+ if (!prevArrow || !nextArrow) throw new Error("expected prev/next arrow buttons");+ // At the 50% keyframe (t=3.5), prev should target the 0% keyframe+ // (absolute t=2) and next should target the 100% keyframe (absolute+ // t=5) — both only resolvable once currentPct agrees with elStart=2/+ // elDuration=3, the same basis the seek fix already uses.+ expect(prevArrow.disabled).toBe(false);+ act(() => prevArrow.dispatchEvent(new MouseEvent("click", { bubbles: true })));+ expect(onSeekToTime).toHaveBeenLastCalledWith(2);++ expect(nextArrow.disabled).toBe(false);+ act(() => nextArrow.dispatchEvent(new MouseEvent("click", { bubbles: true })));+ expect(onSeekToTime).toHaveBeenLastCalledWith(5);+ act(() => root.unmount());+ });});// Media fixtures (Plan 4 Task 7): the three tag values resolveEditingSections@@ -760,126 +682,97 @@ function flatGroupTitles(host: HTMLElement): string[] {}describe("PropertyPanel — Grade group (flag on)", () => {- it(- "renders the Grade group with its accessory for a grade-editable (video) element",- async () => {- const { host, root } = await renderPanel(true, {- ...baseElement(),- tagName: "video",- textFields: [],- });- const gradeCollapsedOrOpen =- host.querySelector('[data-flat-group-collapsed="true"]') ||- host.querySelector('[data-flat-group-open="true"]');- expect(host.textContent).toContain("Grade");- expect(gradeCollapsedOrOpen).not.toBeNull();- act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ it("renders the Grade group with its accessory for a grade-editable (video) element", async () => {+ const { host, root } = await renderPanel(true, {+ ...baseElement(),+ tagName: "video",+ textFields: [],+ });+ const gradeCollapsedOrOpen =+ host.querySelector('[data-flat-group-collapsed="true"]') ||+ host.querySelector('[data-flat-group-open="true"]');+ expect(host.textContent).toContain("Grade");+ expect(gradeCollapsedOrOpen).not.toBeNull();+ act(() => root.unmount());+ });- it(- "does not render the legacy Style/Grade Section duplicates for a style-and-grade-editable element",- async () => {- // A <video> with no text fields is both style-editable (inherited- // capabilities.canEditStyles: true) and grade-editable (tag === "video"),- // so both the flat Style and Grade groups render — the exact shape that- // used to also mount the legacy ColorGradingSection + StyleSections below- // them (the hybrid-duplication bug this task retires).- const { host, root } = await renderPanel(true, {- ...baseElement(),- tagName: "video",- textFields: [],- });- expect(host.textContent).toContain("Style");- expect(host.textContent).toContain("Grade");- // The legacy `Section` primitive (propertyPanelStyleSections.tsx /- // propertyPanelColorGradingSection.tsx) renders a `<section- // data-panel-section="<slugified-title>">` for each of its sections. A- // bare textContent check can't tell a legacy Section title apart from a- // flat row label with the same word — "Fill" is both the legacy Fill- // `Section` title AND a row label inside FlatStyleSection, which is- // supposed to still be there — so assert on the legacy Section's actual- // DOM shape instead of a substring match.- for (const slug of [- "radius",- "stroke",- "effects",- "clip",- "transparency",- "fill",- "color-grading",- ]) {- expect(host.querySelector(`[data-panel-section="${slug}"]`)).toBeNull();- }- act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ it("does not render the legacy Style/Grade Section duplicates for a style-and-grade-editable element", async () => {+ // A <video> with no text fields is both style- and grade-editable: the shape that also+ // mounted the legacy ColorGradingSection and StyleSections below the flat groups.+ const { host, root } = await renderPanel(true, {+ ...baseElement(),+ tagName: "video",+ textFields: [],+ });+ expect(host.textContent).toContain("Style");+ expect(host.textContent).toContain("Grade");+ // Each legacy Section renders `<section data-panel-section="<slug>">`; text alone cannot tell+ // it from a flat row of the same name ("Fill" is both), so match that shape.+ for (const slug of [+ "radius",+ "stroke",+ "effects",+ "clip",+ "transparency",+ "fill",+ "color-grading",+ ]) {+ expect(host.querySelector(`[data-panel-section="${slug}"]`)).toBeNull();+ }+ act(() => root.unmount());+ });});describe("PropertyPanel — Media group (Plan 4)", () => {- it(- "renders the flat Media group and not the legacy MediaSection, for a video element",- async () => {- const { host, root } = await renderPanel(true, videoElement() as never);- // A Media FlatGroup exists (open or collapsed).- expect(flatGroupTitles(host)).toContain("Media");- // The legacy MediaSection renders its rows inside a `Section` whose- // data-panel-section slug is the media title ("video"/"image"/"audio").- // On the flat path it's fully replaced, so none of those may appear.- expect(host.querySelector('[data-panel-section="video"]')).toBeNull();- expect(host.querySelector('[data-panel-section="image"]')).toBeNull();- expect(host.querySelector('[data-panel-section="audio"]')).toBeNull();- act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ it("renders the flat Media group and not the legacy MediaSection, for a video element", async () => {+ const { host, root } = await renderPanel(true, videoElement() as never);+ // A Media FlatGroup exists (open or collapsed).+ expect(flatGroupTitles(host)).toContain("Media");+ // The legacy MediaSection renders its rows inside a `Section` whose+ // data-panel-section slug is the media title ("video"/"image"/"audio").+ // On the flat path it's fully replaced, so none of those may appear.+ expect(host.querySelector('[data-panel-section="video"]')).toBeNull();+ expect(host.querySelector('[data-panel-section="image"]')).toBeNull();+ expect(host.querySelector('[data-panel-section="audio"]')).toBeNull();+ act(() => root.unmount());+ });- it(- "one-open accordion: opening Media closes whichever other group was open, and vice versa (5-way exclusivity)",- async () => {- // videoElement() has canEditStyles: true and no text fields, so Style is- // the default-open group; Layout and Media render collapsed alongside it.- const { host, root } = await renderPanel(true, videoElement() as never);- expect(openGroupText(host)).toContain("Style");-- // Opening Media closes Style.- openFlatGroup(host, "Media");- const afterMedia = openGroupText(host);- expect(afterMedia).toContain("Media");- expect(afterMedia).not.toContain("Style");-- // Reverse direction: opening Layout closes Media — same shared openGroupId.- openFlatGroup(host, "Layout");- const afterLayout = openGroupText(host);- expect(afterLayout).toContain("Layout");- expect(afterLayout).not.toContain("Media");- act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ it("one-open accordion: opening Media closes whichever other group was open, and vice versa (5-way exclusivity)", async () => {+ // videoElement() has canEditStyles: true and no text fields, so Style is+ // the default-open group; Layout and Media render collapsed alongside it.+ const { host, root } = await renderPanel(true, videoElement() as never);+ expect(openGroupText(host)).toContain("Style");++ // Opening Media closes Style.+ openFlatGroup(host, "Media");+ const afterMedia = openGroupText(host);+ expect(afterMedia).toContain("Media");+ expect(afterMedia).not.toContain("Style");++ // Reverse direction: opening Layout closes Media — same shared openGroupId.+ openFlatGroup(host, "Layout");+ const afterLayout = openGroupText(host);+ expect(afterLayout).toContain("Layout");+ expect(afterLayout).not.toContain("Media");+ act(() => root.unmount());+ });- it(- "gates the Media group exactly like the legacy MediaSection: present for video/img/audio, absent for a plain div/text element",- async () => {- for (const fixture of [videoElement, imageElement, audioElement]) {- const { host, root } = await renderPanel(true, fixture() as never);- expect(flatGroupTitles(host)).toContain("Media");- act(() => root.unmount());- }-- // baseElement() is a plain <div> with text — sections.media is false, so- // no Media group (flat or legacy) may render.- const { host, root } = await renderPanel(true);- expect(flatGroupTitles(host)).not.toContain("Media");- expect(host.querySelector('[data-panel-section="video"]')).toBeNull();- expect(host.querySelector('[data-panel-section="image"]')).toBeNull();- expect(host.querySelector('[data-panel-section="audio"]')).toBeNull();+ it("gates the Media group exactly like the legacy MediaSection: present for video/img/audio, absent for a plain div/text element", async () => {+ for (const fixture of [videoElement, imageElement, audioElement]) {+ const { host, root } = await renderPanel(true, fixture() as never);+ expect(flatGroupTitles(host)).toContain("Media");act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ }++ // baseElement() is a plain <div> with text — sections.media is false, so+ // no Media group (flat or legacy) may render.+ const { host, root } = await renderPanel(true);+ expect(flatGroupTitles(host)).not.toContain("Media");+ expect(host.querySelector('[data-panel-section="video"]')).toBeNull();+ expect(host.querySelector('[data-panel-section="image"]')).toBeNull();+ expect(host.querySelector('[data-panel-section="audio"]')).toBeNull();+ act(() => root.unmount());+ });});// design_handoff scrollable-open-section: collapsed headers before/after the@@ -891,135 +784,118 @@ describe("PropertyPanel — Media group (Plan 4)", () => {// renders as an open header + scrollable body, grade/effects/media render as fixed// collapsed headers after it — in exactly that DOM order, nothing sticky.describe("PropertyPanel — fixed headers + scrollable open section (Plan 11)", () => {- it(- "renders before-open headers, the open group (header + scrollable body), then after-open headers, in that exact order, with nothing sticky",- async () => {- const { host, root } = await renderPanel(true, sixGroupElement());- // sixGroupElement() opens Text by default; open Motion (index 3) to- // match the worked example.- openFlatGroup(host, "Motion");- expect(openGroupText(host)).toContain("Motion");-- const body = host.querySelector('[data-flat-panel-body="true"]');- if (!body) throw new Error("expected the flat panel body container");-- // Titles in DOM order: each child is either a collapsed header button- // (before/after the open group) or the open-group wrapper div.- const titles = Array.from(body.children).map((child) => {- if (child.matches('[data-flat-group-collapsed="true"]')) return child.textContent ?? "";- if (child.matches('[data-flat-group-open="true"]')) return child.textContent ?? "";- return null;- });- // Filter to just the group entries (drop any non-group nulls).- const groupTitles = titles.filter((t): t is string => t !== null);- expect(groupTitles).toHaveLength(7);- expect(groupTitles[0]).toContain("Text");- expect(groupTitles[1]).toContain("Style");- expect(groupTitles[2]).toContain("Layout");- expect(groupTitles[3]).toContain("Motion");- expect(groupTitles[4]).toContain("Grade");- expect(groupTitles[5]).toContain("Effects");- expect(groupTitles[6]).toContain("Media");-- // The open group (Motion, index 3) is the one wrapped in- // data-flat-group-open, sitting between the before/after collapsed- // headers — and it must contain a dedicated scrollable body.- const openWrapper = host.querySelector('[data-flat-group-open="true"]');- if (!openWrapper) throw new Error("expected the open-group wrapper");- expect(openWrapper.textContent).toContain("Motion");- expect(openWrapper.querySelector(".overflow-y-auto")).not.toBeNull();-- // Nothing anywhere in the panel body carries inline sticky positioning- // — the entire sticky-stacking mechanism is gone.- const stickyEls = Array.from(body.querySelectorAll<HTMLElement>("[style]")).filter(- (el) => el.style.position === "sticky",- );- expect(stickyEls).toHaveLength(0);- act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ it("renders before-open headers, the open group (header + scrollable body), then after-open headers, in that exact order, with nothing sticky", async () => {+ const { host, root } = await renderPanel(true, sixGroupElement());+ // sixGroupElement() opens Text by default; open Motion (index 3) to+ // match the worked example.+ openFlatGroup(host, "Motion");+ expect(openGroupText(host)).toContain("Motion");++ const body = host.querySelector('[data-flat-panel-body="true"]');+ if (!body) throw new Error("expected the flat panel body container");++ // Titles in DOM order: each child is either a collapsed header button+ // (before/after the open group) or the open-group wrapper div.+ const titles = Array.from(body.children).map((child) => {+ if (child.matches('[data-flat-group-collapsed="true"]')) return child.textContent ?? "";+ if (child.matches('[data-flat-group-open="true"]')) return child.textContent ?? "";+ return null;+ });+ // Filter to just the group entries (drop any non-group nulls).+ const groupTitles = titles.filter((t): t is string => t !== null);+ expect(groupTitles).toHaveLength(7);+ expect(groupTitles[0]).toContain("Text");+ expect(groupTitles[1]).toContain("Style");+ expect(groupTitles[2]).toContain("Layout");+ expect(groupTitles[3]).toContain("Motion");+ expect(groupTitles[4]).toContain("Grade");+ expect(groupTitles[5]).toContain("Effects");+ expect(groupTitles[6]).toContain("Media");++ // The open group (Motion, index 3) is the one wrapped in+ // data-flat-group-open, sitting between the before/after collapsed+ // headers — and it must contain a dedicated scrollable body.+ const openWrapper = host.querySelector('[data-flat-group-open="true"]');+ if (!openWrapper) throw new Error("expected the open-group wrapper");+ expect(openWrapper.textContent).toContain("Motion");+ expect(openWrapper.querySelector(".overflow-y-auto")).not.toBeNull();++ // Nothing anywhere in the panel body carries inline sticky positioning+ // — the entire sticky-stacking mechanism is gone.+ const stickyEls = Array.from(body.querySelectorAll<HTMLElement>("[style]")).filter(+ (el) => el.style.position === "sticky",+ );+ expect(stickyEls).toHaveLength(0);+ act(() => root.unmount());+ });- it(- "renders every group as a plain collapsed header with no scrollable middle region when nothing is open",- async () => {- const { host, root } = await renderPanel(true, sixGroupElement());- // Collapse the default-open Text group so openGroupId becomes "".- const collapseButton = host.querySelector<HTMLButtonElement>(- '[data-flat-group-open="true"] button[title="Collapse"]',- );- act(() => collapseButton?.dispatchEvent(new MouseEvent("click", { bubbles: true })));- expect(host.querySelector('[data-flat-group-open="true"]')).toBeNull();+ it("renders every group as a plain collapsed header with no scrollable middle region when nothing is open", async () => {+ const { host, root } = await renderPanel(true, sixGroupElement());+ // Collapse the default-open Text group so openGroupId becomes "".+ const collapseButton = host.querySelector<HTMLButtonElement>(+ '[data-flat-group-open="true"] button[title="Collapse"]',+ );+ act(() => collapseButton?.dispatchEvent(new MouseEvent("click", { bubbles: true })));+ expect(host.querySelector('[data-flat-group-open="true"]')).toBeNull();- const collapsedRows = Array.from(- host.querySelectorAll<HTMLButtonElement>('[data-flat-group-collapsed="true"]'),- );- expect(collapsedRows).toHaveLength(7);- const titlesInOrder = collapsedRows.map((el) => el.textContent ?? "");- expect(titlesInOrder[0]).toContain("Text");- expect(titlesInOrder[1]).toContain("Style");- expect(titlesInOrder[2]).toContain("Layout");- expect(titlesInOrder[3]).toContain("Motion");- expect(titlesInOrder[4]).toContain("Grade");- expect(titlesInOrder[5]).toContain("Effects");- expect(titlesInOrder[6]).toContain("Media");-- const body = host.querySelector('[data-flat-panel-body="true"]');- expect(body?.querySelector(".overflow-y-auto")).toBeNull();- for (const row of collapsedRows) {- expect(row.style.position).toBe("");- }- act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ const collapsedRows = Array.from(+ host.querySelectorAll<HTMLButtonElement>('[data-flat-group-collapsed="true"]'),+ );+ expect(collapsedRows).toHaveLength(7);+ const titlesInOrder = collapsedRows.map((el) => el.textContent ?? "");+ expect(titlesInOrder[0]).toContain("Text");+ expect(titlesInOrder[1]).toContain("Style");+ expect(titlesInOrder[2]).toContain("Layout");+ expect(titlesInOrder[3]).toContain("Motion");+ expect(titlesInOrder[4]).toContain("Grade");+ expect(titlesInOrder[5]).toContain("Effects");+ expect(titlesInOrder[6]).toContain("Media");++ const body = host.querySelector('[data-flat-panel-body="true"]');+ expect(body?.querySelector(".overflow-y-auto")).toBeNull();+ for (const row of collapsedRows) {+ expect(row.style.position).toBe("");+ }+ act(() => root.unmount());+ });});describe("PropertyPanel — flat group entrance animation scoping (fix round)", () => {- it(- "animates only the opening group and the implicitly-closed group on a non-adjacent toggle, never untouched siblings",- async () => {- const { host, root } = await renderPanel(true, sixGroupElement());- // sixGroupElement() opens Text by default; jump straight to Motion- // (skipping over Style/Layout) first, matching the Plan 11 worked- // example, then jump back to Text — non-adjacent from Motion, again- // skipping over Style/Layout. This is the exact array-slice-position-- // shift scenario the justToggledIds mechanism exists to guard: Style- // and Layout shift position in the before/after-open slices on both- // toggles even though neither of them is the group being toggled.- openFlatGroup(host, "Motion");- expect(openGroupText(host)).toContain("Motion");- openFlatGroup(host, "Text");- expect(openGroupText(host)).toContain("Text");-- const collapsedRowByTitle = (title: string) => {- const row = Array.from(host.querySelectorAll('[data-flat-group-collapsed="true"]')).find(- (el) => el.textContent?.includes(title),- );- if (!row) throw new Error(`expected a collapsed ${title} row`);- return row;- };-- // Untouched, non-adjacent siblings must NOT receive the entrance class,- // even though they shifted position in the collapsed-header list.- expect(collapsedRowByTitle("Style").classList.contains("hf-flat-group-enter")).toBe(false);- expect(collapsedRowByTitle("Layout").classList.contains("hf-flat-group-enter")).toBe(false);- expect(collapsedRowByTitle("Grade").classList.contains("hf-flat-group-enter")).toBe(false);- expect(collapsedRowByTitle("Media").classList.contains("hf-flat-group-enter")).toBe(false);-- // Motion — open a moment ago, just implicitly closed by the click on- // Text — must still play its own collapse-entrance animation (Finding 1).- expect(collapsedRowByTitle("Motion").classList.contains("hf-flat-group-enter")).toBe(true);-- // Text — the group actually clicked open — must animate too.- const openWrapper = host.querySelector('[data-flat-group-open="true"]');- if (!openWrapper) throw new Error("expected the open-group wrapper");- expect(openWrapper.querySelector(".hf-flat-group-enter")).not.toBeNull();-- act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ it("animates only the opening group and the implicitly-closed group on a non-adjacent toggle, never untouched siblings", async () => {+ const { host, root } = await renderPanel(true, sixGroupElement());+ // Text opens by default; jumping to Motion and back skips Style and Layout both ways, so they+ // shift position in the open slices without being toggled: what justToggledIds guards.+ openFlatGroup(host, "Motion");+ expect(openGroupText(host)).toContain("Motion");+ openFlatGroup(host, "Text");+ expect(openGroupText(host)).toContain("Text");++ const collapsedRowByTitle = (title: string) => {+ const row = Array.from(host.querySelectorAll('[data-flat-group-collapsed="true"]')).find(+ (el) => el.textContent?.includes(title),+ );+ if (!row) throw new Error(`expected a collapsed ${title} row`);+ return row;+ };++ // Untouched, non-adjacent siblings must NOT receive the entrance class,+ // even though they shifted position in the collapsed-header list.+ expect(collapsedRowByTitle("Style").classList.contains("hf-flat-group-enter")).toBe(false);+ expect(collapsedRowByTitle("Layout").classList.contains("hf-flat-group-enter")).toBe(false);+ expect(collapsedRowByTitle("Grade").classList.contains("hf-flat-group-enter")).toBe(false);+ expect(collapsedRowByTitle("Media").classList.contains("hf-flat-group-enter")).toBe(false);++ // Motion — open a moment ago, just implicitly closed by the click on+ // Text — must still play its own collapse-entrance animation (Finding 1).+ expect(collapsedRowByTitle("Motion").classList.contains("hf-flat-group-enter")).toBe(true);++ // Text — the group actually clicked open — must animate too.+ const openWrapper = host.querySelector('[data-flat-group-open="true"]');+ if (!openWrapper) throw new Error("expected the open-group wrapper");+ expect(openWrapper.querySelector(".hf-flat-group-enter")).not.toBeNull();++ act(() => root.unmount());+ });});describe("PropertyPanel — Motion is for things that move", () => {@@ -1033,148 +909,124 @@ describe("PropertyPanel — Motion is for things that move", () => {return element;},],- ])(- "recognizes %s through the shared audio predicate",- async (_label, makeElement) => {- const fixture = {- ...audioClipElement(),- element: makeElement(),- tagName: "div",- };- const { host, root } = await renderPanel(true, fixture);- const titles = Array.from(- host.querySelectorAll<HTMLElement>("[data-flat-group-collapsed], [data-flat-group-open]"),- ).map((node) => node.textContent ?? "");- expect(titles.some((title) => title.includes("Motion"))).toBe(false);- expect(titles.some((title) => title.includes("Timing"))).toBe(true);- act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ ])("recognizes %s through the shared audio predicate", async (_label, makeElement) => {+ const fixture = {+ ...audioClipElement(),+ element: makeElement(),+ tagName: "div",+ };+ const { host, root } = await renderPanel(true, fixture);+ const titles = Array.from(+ host.querySelectorAll<HTMLElement>("[data-flat-group-collapsed], [data-flat-group-open]"),+ ).map((node) => node.textContent ?? "");+ expect(titles.some((title) => title.includes("Motion"))).toBe(false);+ expect(titles.some((title) => title.includes("Timing"))).toBe(true);+ act(() => root.unmount());+ });- it(- "calls the section Timing on an audio clip, and offers no tween editor",- async () => {- const { host, root } = await renderPanel(true, audioClipElement());- const titles = Array.from(- host.querySelectorAll<HTMLElement>("[data-flat-group-collapsed], [data-flat-group-open]"),- ).map((el) => el.textContent ?? "");- // The clip's placement survives — it is still a clip on a track.- expect(titles.some((t) => t.includes("Timing"))).toBe(true);- // "Motion" named the tween editor, which an <audio> element has no- // transform, opacity or box for. Showing it was the panel gating on- // handler presence rather than on the element.- expect(titles.some((t) => t.includes("Motion"))).toBe(false);- act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ it("calls the section Timing on an audio clip, and offers no tween editor", async () => {+ const { host, root } = await renderPanel(true, audioClipElement());+ const titles = Array.from(+ host.querySelectorAll<HTMLElement>("[data-flat-group-collapsed], [data-flat-group-open]"),+ ).map((el) => el.textContent ?? "");+ // The clip's placement survives — it is still a clip on a track.+ expect(titles.some((t) => t.includes("Timing"))).toBe(true);+ // "Motion" named the tween editor, which an <audio> element has no+ // transform, opacity or box for. Showing it was the panel gating on+ // handler presence rather than on the element.+ expect(titles.some((t) => t.includes("Motion"))).toBe(false);+ act(() => root.unmount());+ });- it(- "offers a mute on an audible audio clip and toggles it through the timeline",- async () => {- const onToggleElementHidden = vi.fn();- const { host, root } = await renderPanel(- true,- audioClipElement(),- { onToggleElementHidden },- { selectedElementId: "vo-1" },- );- act(() => host.querySelector<HTMLElement>('button[aria-label="Mute element"]')!.click());- expect(onToggleElementHidden).toHaveBeenCalledWith("vo-1", true);- act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ it("offers a mute on an audible audio clip and toggles it through the timeline", async () => {+ const onToggleElementHidden = vi.fn();+ const { host, root } = await renderPanel(+ true,+ audioClipElement(),+ { onToggleElementHidden },+ { selectedElementId: "vo-1" },+ );+ act(() => host.querySelector<HTMLElement>('button[aria-label="Mute element"]')!.click());+ expect(onToggleElementHidden).toHaveBeenCalledWith("vo-1", true);+ act(() => root.unmount());+ });// A bus has no timeline row, so the panel is its only mute; it must go both ways.- it(- "mutes, unmutes and mutes an audio group from the panel header",- async () => {- const bus = (hidden: boolean) => {- const element = audioBusElement();- return {- ...element,- dataAttributes: { ...element.dataAttributes, ...(hidden ? { hidden: "" } : {}) },- };- };- let hidden = true;- const onSetAudioGroupAttributeQuiet = vi.fn(- async (_id: string, _attr: string, value: string | null, _label: string) => {- hidden = value !== null;- },- );- // The panel re-reads its selection after the write; nothing else re-renders it here.- const { host, root, render } = await renderPanel(- true,- bus(true),- {},- {- timelineEdit: { onSetAudioGroupAttributeQuiet },- selectionRef: { current: bus(true) },- refreshSelection: () => render(bus(hidden)),- },- );- const press = async (label: string) => {- const button = host.querySelector<HTMLElement>(`button[aria-label="${label}"]`);- if (!button) throw new Error(`Expected a "${label}" button`);- await act(async () => button.click());+ it("mutes, unmutes and mutes an audio group from the panel header", async () => {+ const bus = (hidden: boolean) => {+ const element = audioBusElement();+ return {+ ...element,+ dataAttributes: { ...element.dataAttributes, ...(hidden ? { hidden: "" } : {}) },};- await press("Unmute element");- await press("Mute element");- await press("Unmute element");- expect(onSetAudioGroupAttributeQuiet.mock.calls).toEqual([- ["voiceover", "data-hidden", null, "Unmute element"],- ["voiceover", "data-hidden", "", "Mute element"],- ["voiceover", "data-hidden", null, "Unmute element"],- ]);- act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ };+ let hidden = true;+ const onSetAudioGroupAttributeQuiet = vi.fn(+ async (_id: string, _attr: string, value: string | null, _label: string) => {+ hidden = value !== null;+ },+ );+ // The panel re-reads its selection after the write; nothing else re-renders it here.+ const { host, root, render } = await renderPanel(+ true,+ bus(true),+ {},+ {+ timelineEdit: { onSetAudioGroupAttributeQuiet },+ selectionRef: { current: bus(true) },+ refreshSelection: () => render(bus(hidden)),+ },+ );+ const press = async (label: string) => {+ const button = host.querySelector<HTMLElement>(`button[aria-label="${label}"]`);+ if (!button) throw new Error(`Expected a "${label}" button`);+ await act(async () => button.click());+ };+ await press("Unmute element");+ await press("Mute element");+ await press("Unmute element");+ expect(onSetAudioGroupAttributeQuiet.mock.calls).toEqual([+ ["voiceover", "data-hidden", null, "Unmute element"],+ ["voiceover", "data-hidden", "", "Mute element"],+ ["voiceover", "data-hidden", null, "Unmute element"],+ ]);+ act(() => root.unmount());+ });- it(- "re-reads the current selection, not the muted bus, once the write lands",- async () => {- let land = () => {};- const onSetAudioGroupAttributeQuiet = vi.fn(- () => new Promise<void>((resolve) => (land = resolve)),- );- const selectionRef: { current: unknown } = { current: audioBusElement() };- const refreshSelection = vi.fn();- const { host, root } = await renderPanel(- true,- audioBusElement(),- {},- {- timelineEdit: { onSetAudioGroupAttributeQuiet },- selectionRef,- refreshSelection,- },- );- act(() => host.querySelector<HTMLElement>('button[aria-label="Mute element"]')!.click());- const next = audioClipElement();- selectionRef.current = next;- await act(async () => land());- expect(refreshSelection.mock.calls).toEqual([[next]]);- act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ it("re-reads the current selection, not the muted bus, once the write lands", async () => {+ let land = () => {};+ const onSetAudioGroupAttributeQuiet = vi.fn(+ () => new Promise<void>((resolve) => (land = resolve)),+ );+ const selectionRef: { current: unknown } = { current: audioBusElement() };+ const refreshSelection = vi.fn();+ const { host, root } = await renderPanel(+ true,+ audioBusElement(),+ {},+ {+ timelineEdit: { onSetAudioGroupAttributeQuiet },+ selectionRef,+ refreshSelection,+ },+ );+ act(() => host.querySelector<HTMLElement>('button[aria-label="Mute element"]')!.click());+ const next = audioClipElement();+ selectionRef.current = next;+ await act(async () => land());+ expect(refreshSelection.mock.calls).toEqual([[next]]);+ act(() => root.unmount());+ });- it(- "offers a bus neither — it has no clip range to edit",- async () => {- const { host, root } = await renderPanel(true, audioBusElement());- const titles = Array.from(- host.querySelectorAll<HTMLElement>("[data-flat-group-collapsed], [data-flat-group-open]"),- ).map((el) => el.textContent ?? "");- expect(titles.some((t) => t.includes("Motion"))).toBe(false);- expect(titles.some((t) => t.includes("Timing"))).toBe(false);- // It is still a mixer bus: the reason to select one at all.- expect(titles.some((t) => t.includes("Audio FX"))).toBe(true);- act(() => root.unmount());- },- RENDER_TIMEOUT_MS,- );+ it("offers a bus neither — it has no clip range to edit", async () => {+ const { host, root } = await renderPanel(true, audioBusElement());+ const titles = Array.from(+ host.querySelectorAll<HTMLElement>("[data-flat-group-collapsed], [data-flat-group-open]"),+ ).map((el) => el.textContent ?? "");+ expect(titles.some((t) => t.includes("Motion"))).toBe(false);+ expect(titles.some((t) => t.includes("Timing"))).toBe(false);+ // It is still a mixer bus: the reason to select one at all.+ expect(titles.some((t) => t.includes("Audio FX"))).toBe(true);+ act(() => root.unmount());+ });});diff --git a/packages/studio/src/components/editor/anchoredResizeCommitFeedsOffset.test.ts b/packages/studio/src/components/editor/anchoredResizeCommitFeedsOffset.test.tsindex 908275e01c..fd6bf6e0a8 100644--- a/packages/studio/src/components/editor/anchoredResizeCommitFeedsOffset.test.ts+++ b/packages/studio/src/components/editor/anchoredResizeCommitFeedsOffset.test.ts@@ -142,6 +142,7 @@ function buildHarness(const iframe = document.createElement("iframe");const opts: UseDomEditOverlayGesturesOptions = {+ activeCompositionPathRef: { current: null },overlayRef: ref<HTMLDivElement | null>(overlayEl),iframeRef: ref<HTMLIFrameElement | null>(iframe),boxRef: ref<HTMLDivElement | null>(document.createElement("div")),@@ -159,6 +160,7 @@ function buildHarness(gestureRef: ref<GestureState | null>(null),groupGestureRef: ref(null),blockedMoveRef: ref(null),+ waitingPressRef: ref(null),rafPausedRef: ref(false),suppressNextBoxClickRef: ref(false),setOverlayRect: () => {},diff --git a/packages/studio/src/components/editor/domEditOverlayGeometry.ts b/packages/studio/src/components/editor/domEditOverlayGeometry.tsindex 5055dd4cfe..4b3d58924a 100644--- a/packages/studio/src/components/editor/domEditOverlayGeometry.ts+++ b/packages/studio/src/components/editor/domEditOverlayGeometry.ts@@ -18,16 +18,16 @@ export interface OverlayRect {height: number;editScaleX: number;editScaleY: number;- /**- * The element's live transform rotation in DEGREES (screen/CSS convention, CW- * positive), decomposed from its computed transform matrix. Present so the- * selection chrome can render as an oriented bounding box (OBB) that co-rotates- * with the element. Omitted (treated as 0) for group/union rects and when the- * transform is unmeasurable — those render axis-aligned exactly as before.- */+ /** Live screen-space rotation; omitted for axis-aligned group bounds. */angle?: number;}+export const shiftedOverlayRect = (rect: OverlayRect, dx: number, dy: number): OverlayRect => ({+ ...rect,+ left: rect.left + dx,+ top: rect.top + dy,+});+export interface GroupOverlayItem {key: string;selection: DomEditSelection;diff --git a/packages/studio/src/components/editor/domEditOverlayGestures.ts b/packages/studio/src/components/editor/domEditOverlayGestures.tsindex fd3f0a2ce6..5c3645622c 100644--- a/packages/studio/src/components/editor/domEditOverlayGestures.ts+++ b/packages/studio/src/components/editor/domEditOverlayGestures.ts@@ -121,6 +121,22 @@ export interface BlockedMoveState {startY: number;}+/** Marks the selection box while its press waits for a reload: it is drawn at the pointer, not at the element. */+export const PRESS_WAITING_ATTR = "data-dom-edit-press-waiting";++/** A press that landed while the preview reloads: it starts once the new preview shows what it pressed. */+export interface WaitingPressState {+ pointerId: number;+ startX: number;+ startY: number;+ draw: ((dx: number, dy: number) => void) | null;+ frame: number;+ moved: React.PointerEvent<HTMLDivElement> | null;+ released: React.PointerEvent<HTMLDivElement> | null;+ after: WaitingPressState | null;+ ended: boolean;+}+export type FocusableDomEditOverlay = {focus(options?: FocusOptions): void;};@@ -245,6 +261,7 @@ export interface DomEditGroupPathOffsetCommit {// Refs are stable across renders; values are read via .current.export type UseDomEditOverlayGesturesOptions = {+ activeCompositionPathRef: RefObject<string | null>;overlayRef: RefObject<HTMLDivElement | null>;iframeRef: RefObject<HTMLIFrameElement | null>;boxRef: RefObject<HTMLDivElement | null>;@@ -255,6 +272,7 @@ export type UseDomEditOverlayGesturesOptions = {gestureRef: RefObject<GestureState | null>;groupGestureRef: RefObject<GroupGestureState | null>;blockedMoveRef: RefObject<BlockedMoveState | null>;+ waitingPressRef: RefObject<WaitingPressState | null>;rafPausedRef: RefObject<boolean>;suppressNextBoxClickRef: RefObject<boolean>;setOverlayRect: (next: OverlayRect | null) => void;diff --git a/packages/studio/src/components/editor/domEditOverlayStartGesture.blocked.test.ts b/packages/studio/src/components/editor/domEditOverlayStartGesture.blocked.test.tsindex 4a02bed8a0..659522dba5 100644--- a/packages/studio/src/components/editor/domEditOverlayStartGesture.blocked.test.ts+++ b/packages/studio/src/components/editor/domEditOverlayStartGesture.blocked.test.ts@@ -30,6 +30,7 @@ it("a drag press the layer cannot take gets the notice, counts as handled, and lsnapGuidesRef: ref(null),groupGestureRef: ref(null),blockedMoveRef: ref(null),+ waitingPressRef: ref(null),setOverlayRect: vi.fn(),suppressNextBoxClickRef: ref(false),hoverSelectionRef: ref(null),diff --git a/packages/studio/src/components/editor/domEditOverlayStartGesture.test.ts b/packages/studio/src/components/editor/domEditOverlayStartGesture.test.tsindex 37998fbe7e..dabc6f8d57 100644--- a/packages/studio/src/components/editor/domEditOverlayStartGesture.test.ts+++ b/packages/studio/src/components/editor/domEditOverlayStartGesture.test.ts@@ -47,6 +47,7 @@ function pressOptions(element: HTMLElement) {snapGuidesRef: ref(null),groupGestureRef: ref(null),blockedMoveRef: ref(null),+ waitingPressRef: ref(null),setOverlayRect: vi.fn(),suppressNextBoxClickRef: ref(false),hoverSelectionRef: ref(null),@@ -169,6 +170,7 @@ describe("a rotate on a page that loads GSAP", () => {gestureRef: ref<GestureState | null>(null),groupGestureRef: ref(null),blockedMoveRef: ref(null),+ waitingPressRef: ref(null),rafPausedRef: ref(false),onCanvasPointerMoveRef: ref(vi.fn()),};@@ -222,6 +224,7 @@ describe("a rotate press on an element a GSAP tween turns", () => {iframeRef: ref(null),gestureRef: ref<GestureState | null>(null),rafPausedRef: ref(false),+ waitingPressRef: ref(null),};const press = {clientX: 25,diff --git a/packages/studio/src/components/editor/domEditOverlayStartGesture.ts b/packages/studio/src/components/editor/domEditOverlayStartGesture.tsindex fc4d76df61..66db7736f7 100644--- a/packages/studio/src/components/editor/domEditOverlayStartGesture.ts+++ b/packages/studio/src/components/editor/domEditOverlayStartGesture.ts@@ -3,6 +3,7 @@* These are pure "start a new gesture" operations — no draft rect updates.*/import { type DomEditSelection } from "./domEditing";+import type { EditMoment } from "./manualEditsTypes";import {applyManualOffsetDragDraft,createManualOffsetDragMember,@@ -49,6 +50,7 @@ export function notifyBlockedPress(export function startGroupDrag(e: React.PointerEvent<HTMLElement>,opts: UseDomEditOverlayGesturesOptions,+ at?: EditMoment,): boolean {const items = opts.groupOverlayItemsRef.current;if (items.length <= 1) return false;@@ -73,6 +75,7 @@ export function startGroupDrag(element: item.element,rect: item.rect,gesture: "drag",+ at,});if (!result.ok) {restoreManualOffsetDragMembers(members);@@ -144,8 +147,10 @@ export function startGesture(selection?: DomEditSelection;rect?: OverlayRect | null;resizeHandle?: ResizeHandle;+ at?: EditMoment;},): boolean {+ const at = options?.at;const sel = options?.selection ?? opts.selectionRef.current;const rect = options?.rect ?? opts.overlayRectRef.current;const box = opts.boxRef.current;@@ -196,6 +201,7 @@ export function startGesture(element: sel.element,rect,gesture: "drag",+ at,});if (!result.ok) {opts.onBlockedMoveRef.current(result.selection, result.reason);@@ -217,6 +223,7 @@ export function startGesture(element: sel.element,rect,gesture: "resize",+ at,});if (result.ok) {pathOffsetMember = result.member;@@ -225,12 +232,13 @@ export function startGesture(// Hold a % translate as the same px now, so a growing box can't drag it along mid-frame.if (result.member.plainTranslate) applyManualOffsetDragDraft(result.member, 0, 0);} else {- manualEditDragToken = beginStudioManualEditGesture(sel.element, "resize");+ manualEditDragToken = beginStudioManualEditGesture(sel.element, "resize", at);}} else {manualEditDragToken = beginStudioManualEditGesture(sel.element,kind === "rotate" ? "rotate" : "resize",+ at,);}}diff --git a/packages/studio/src/components/editor/dragUndoPaint.test.ts b/packages/studio/src/components/editor/dragUndoPaint.test.tsindex 4a36fd34ee..5ca32b3077 100644--- a/packages/studio/src/components/editor/dragUndoPaint.test.ts+++ b/packages/studio/src/components/editor/dragUndoPaint.test.ts@@ -68,6 +68,7 @@ function dragWithSaveRunning(save: Promise<void> | (() => Promise<void>)) {snapGuidesRef: ref(null),groupGestureRef: ref(null),blockedMoveRef: ref(null),+ waitingPressRef: ref(null),setOverlayRect: vi.fn(),suppressNextBoxClickRef: ref(false),hoverSelectionRef: ref(null),@@ -127,6 +128,7 @@ function gestureWithSaveRunning(kind: "resize" | "rotate", save: Promise<void>)snapGuidesRef: ref(null),groupGestureRef: ref(null),blockedMoveRef: ref(null),+ waitingPressRef: ref(null),setOverlayRect: vi.fn(),suppressNextBoxClickRef: ref(false),hoverSelectionRef: ref(null),diff --git a/packages/studio/src/components/editor/gestureHoldsPreviewReload.test.tsx b/packages/studio/src/components/editor/gestureHoldsPreviewReload.test.tsxindex b98574d4ea..c1f457df15 100644--- a/packages/studio/src/components/editor/gestureHoldsPreviewReload.test.tsx+++ b/packages/studio/src/components/editor/gestureHoldsPreviewReload.test.tsx@@ -17,30 +17,55 @@ import "./domEditOverlayTestMocks";import { DomEditOverlay } from "./DomEditOverlay";import { PreviewReadOnlyProvider } from "./previewReadOnlyContext";import { STUDIO_MANUAL_EDIT_GESTURE_ATTR } from "./manualEditsTypes";+import { PRESS_WAITING_ATTR } from "./domEditOverlayGestures";+import { PRESS_WAIT_MAX_MS } from "./previewGestureStarts";+import { readDragStamp } from "../../hooks/draggedGsapPosition";+import { usePlayerStore } from "../../player/store/playerStore";+import { whileScriptWrites } from "../../player/previewReloading";+import { cancelNewestStudioWaitingPress } from "../../utils/studioPendingEdits";(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;const layout = vi.hoisted(() => ({group: [] as unknown[],+ rafPaused: { current: false } as { current: boolean },rect: { left: 100, top: 100, width: 200, height: 100, editScaleX: 1, editScaleY: 1 },}));vi.mock("./useDomEditOverlayRects", () => ({- useDomEditOverlayRects: () => {+ useDomEditOverlayRects: (options: { rafPausedRef: { current: boolean } }) => {+ layout.rafPaused = options.rafPausedRef;const { rect, group } = layout;+ const [overlayRect, setOverlayRect] = React.useState(rect);+ const overlayRectRef = React.useRef(overlayRect);+ overlayRectRef.current = overlayRect;const groupOverlayItemsRef = { current: group };const noop = () => undefined;return {- overlayRect: rect,- overlayRectRef: { current: rect },+ overlayRect,+ overlayRectRef,groupOverlayItems: group,groupOverlayItemsRef,hoverRect: null,childRects: [],- setOverlayRect: noop,+ setOverlayRect,setGroupOverlayItems: noop,};},}));+vi.mock("./domEditOverlayGeometry", async (importOriginal) => ({+ ...(await importOriginal<typeof import("./domEditOverlayGeometry")>()),+ orientedGroupAwareOverlayRect: (_overlay: unknown, _iframe: unknown, element: HTMLElement) => {+ const [x = 0, y = 0] = element.style+ .getPropertyValue("translate")+ .split(" ")+ .map(Number.parseFloat);+ return {+ ...layout.rect,+ left: 100 + (Number.isFinite(x) ? x : 0),+ top: 100 + (Number.isFinite(y) ? y : 0),+ };+ },+}));vi.mock("../../utils/gsapSoftReload", async (importOriginal) => ({...(await importOriginal<typeof import("../../utils/gsapSoftReload")>()),ensureMotionPathPluginLoaded: vi.fn(),@@ -65,6 +90,14 @@ const marked = (doc: Document) => doc.querySelectorAll(`[${STUDIO_MANUAL_EDIT_GEconst byId = (iframe: HTMLIFrameElement | null, id: string) =>iframe!.contentDocument!.getElementById(id) as HTMLElement;const api = (): TimelinePlayerApi => player.getApi();+/** The south-east resize handle. */+const corner = (overlay: HTMLElement) =>+ [...overlay.querySelectorAll<HTMLElement>("div.h-4.w-4")].reduce((a, b) =>+ parseFloat(b.style.left) + parseFloat(b.style.top) >+ parseFloat(a.style.left) + parseFloat(a.style.top)+ ? b+ : a,+ );function pointer(target: Element,@@ -105,6 +138,7 @@ function mountEditor(const write = (sel: DomEditSelection, next: { x: number; y: number }) =>saveStyle(sel, `translate: ${next.x}px ${next.y}px`);const onPathOffsetCommit = vi.fn(write);+ const onCanvasMouseDown = vi.fn();const onGroupPathOffsetCommit = vi.fn(async (updates: { selection: DomEditSelection; next: { x: number; y: number } }[]) => {for (const { selection, next } of updates) await write(selection, next);@@ -112,17 +146,17 @@ function mountEditor();const host = document.body.appendChild(document.createElement("div"));overlayRoot = createRoot(host);- const render = (readOnly: boolean) =>+ const render = (readOnly: boolean, selection = selections[0]!) =>act(() =>overlayRoot.render(<PreviewReadOnlyProvider readOnly={readOnly}><DomEditOverlayiframeRef={api().iframeRef}activeCompositionPath={null}- selection={group ? null : selections[0]!}+ selection={group ? null : selection}groupSelections={group ? selections : []}hoverSelection={null}- onCanvasMouseDown={() => undefined}+ onCanvasMouseDown={onCanvasMouseDown}onCanvasPointerMove={() => Promise.resolve(null)}onCanvasPointerLeave={() => undefined}onSelectionChange={() => undefined}@@ -138,7 +172,14 @@ function mountEditor();render(false);const overlay = host.querySelector('[aria-label="Composition canvas"]') as HTMLElement;- return { live, overlay, box: overlay.querySelector(BOX)!, onPathOffsetCommit, render };+ return {+ live,+ overlay,+ box: overlay.querySelector(BOX)!,+ onPathOffsetCommit,+ onCanvasMouseDown,+ render,+ };}/** A reload whose shadow paints while the gesture is still live. */@@ -149,6 +190,9 @@ async function reloadMidGesture() {return { shadow, gen };}+/** Polls inside act, as testing-library's waitFor does, so a replayed press's renders are flushed. */+const waitFor = (check: () => void) => act(() => vi.waitFor(check));+async function settle() {await act(async () => {for (let tick = 0; tick < 10; tick++) await Promise.resolve();@@ -160,7 +204,11 @@ beforeEach(() => {HTMLElement.prototype.releasePointerCapture = () => undefined;});+// Writes a test leaves out would hold every later press in the file.+const stuckWrites: Array<() => void> = [];+afterEach(() => {+ for (const land of stuckWrites.splice(0)) land();act(() => overlayRoot?.unmount());act(() => player?.root.unmount());layout.group = [];@@ -199,13 +247,6 @@ describe("a reload during a drag", () => {);const handle = (overlay: HTMLElement, selector: string) => overlay.querySelector(selector)!;- const corner = (overlay: HTMLElement) =>- [...overlay.querySelectorAll<HTMLElement>("div.h-4.w-4")].reduce((a, b) =>- parseFloat(b.style.left) + parseFloat(b.style.top) >- parseFloat(a.style.left) + parseFloat(a.style.top)- ? b- : a,- );// Each edit presses at `from`, drags to `to`, and releases on `on`.const edits = {move: (o: HTMLElement) => ({ press: handle(o, BOX), on: o, from: [150, 150], to: [190, 170] }),@@ -268,6 +309,354 @@ describe("a reload during a drag", () => {});});+describe("a press while the preview reloads", () => {+ it("drags its element on the reloaded preview, at the time it was pressed", async () => {+ const editor = mountEditor(false);+ act(() => usePlayerStore.setState({ currentTime: 2 }));+ act(() => api().refreshPlayer());+ pointer(editor.box, "pointerdown", 150, 150);+ pointer(editor.overlay, "pointermove", 190, 170);+ expect(marked(editor.live.contentDocument!), "the page being replaced").toHaveLength(0);+ expect(editor.box.hasAttribute(PRESS_WAITING_ATTR), "drawn at the pointer").toBe(true);+ pointer(editor.overlay, "pointerup", 190, 170);+ act(() => usePlayerStore.setState({ currentTime: 3 }));+ let pressedAt: number | undefined;+ const save = editor.onPathOffsetCommit.getMockImplementation()!;+ editor.onPathOffsetCommit.mockImplementationOnce((sel, ...rest) => {+ pressedAt = readDragStamp(sel.element).at?.time;+ return save(sel, ...rest);+ });++ const shown = served("?_t=1");+ await paintShadow(api, shown);+ editor.render(false, makeSelection("title", byId(shown, "title")));+ await waitFor(() => expect(file.title).toBe("translate: 40px 20px"));+ expect(byId(shown, "title").style.getPropertyValue("translate")).toBe("40px 20px");+ expect(pressedAt).toBe(2);+ });+});++describe("a press while a script write is out", () => {+ it("waits for the write to land, then drags", async () => {+ const editor = mountEditor(false);+ let land: () => void = () => {};+ const write = whileScriptWrites(() => new Promise<void>((resolve) => (land = resolve)));+ pointer(editor.box, "pointerdown", 150, 150);+ pointer(editor.overlay, "pointermove", 190, 170);+ pointer(editor.overlay, "pointerup", 190, 170);+ expect(marked(editor.live.contentDocument!), "no drag before the write lands").toHaveLength(0);+ expect(editor.onPathOffsetCommit).not.toHaveBeenCalled();++ await act(async () => {+ land();+ await write;+ });+ await waitFor(() => expect(file.title).toBe("translate: 40px 20px"));+ });++ it("keeps a released press when the browser releases pointer capture", async () => {+ const editor = mountEditor(false);+ let land: () => void = () => {};+ const write = whileScriptWrites(() => new Promise<void>((resolve) => (land = resolve)));+ pointer(editor.box, "pointerdown", 150, 150);+ pointer(editor.overlay, "pointermove", 190, 170);+ pointer(editor.overlay, "pointerup", 190, 170);+ pointer(editor.box, "lostpointercapture", 190, 170);+ act(() => void editor.box.dispatchEvent(new MouseEvent("click", { bubbles: true })));+ expect(editor.onCanvasMouseDown).not.toHaveBeenCalled();++ await act(async () => {+ land();+ await write;+ });+ await waitFor(() => expect(file.title).toBe("translate: 40px 20px"));+ expect(editor.onPathOffsetCommit).toHaveBeenCalledTimes(1);+ });++ it("keeps the released waiting box still while the pointer moves to the next handle", async () => {+ const editor = mountEditor(false);+ let land: () => void = () => {};+ const write = whileScriptWrites(() => new Promise<void>((resolve) => (land = resolve)));+ pointer(editor.box, "pointerdown", 150, 150);+ pointer(editor.overlay, "pointermove", 190, 170);+ pointer(editor.overlay, "pointerup", 190, 170);+ expect((editor.box as HTMLElement).style.left).toBe("140px");+ expect((editor.box as HTMLElement).style.top).toBe("120px");+ pointer(editor.overlay, "pointermove", 340, 220, { buttons: 0 });+ expect((editor.box as HTMLElement).style.left).toBe("140px");+ expect((editor.box as HTMLElement).style.top).toBe("120px");++ await act(async () => {+ land();+ await write;+ });+ await waitFor(() => expect(file.title).toBe("translate: 40px 20px"));+ });++ it("keeps the newest waiting box in place when an earlier press replays", async () => {+ const editor = mountEditor(false);+ let land: () => void = () => {};+ let landFirst: () => void = () => {};+ const write = whileScriptWrites(() => new Promise<void>((resolve) => (land = resolve)));+ const firstSaved = new Promise<void>((resolve) => (landFirst = resolve));+ const commit = editor.onPathOffsetCommit.getMockImplementation()!;+ editor.onPathOffsetCommit.mockImplementationOnce((...args) =>+ whileScriptWrites(async () => {+ await firstSaved;+ return commit(...args);+ }),+ );+ pointer(editor.box, "pointerdown", 150, 150);+ pointer(editor.overlay, "pointermove", 190, 170);+ pointer(editor.overlay, "pointerup", 190, 170);+ pointer(editor.box, "pointerdown", 190, 170);+ pointer(editor.overlay, "pointermove", 210, 180);+ pointer(editor.overlay, "pointerup", 210, 180);+ expect((editor.box as HTMLElement).style.left).toBe("160px");+ await act(async () => {+ land();+ await write;+ });+ await waitFor(() => expect(editor.onPathOffsetCommit).toHaveBeenCalledTimes(1));+ expect((editor.box as HTMLElement).style.left).toBe("160px");+ expect((editor.box as HTMLElement).style.top).toBe("130px");+ await act(async () => {+ landFirst();+ await firstSaved;+ });+ await waitFor(() => expect(file.title).toBe("translate: 60px 30px"));+ });++ it("runs a second press after the first one, never instead of it", async () => {+ const editor = mountEditor(false);+ let land: () => void = () => {};+ const write = whileScriptWrites(() => new Promise<void>((resolve) => (land = resolve)));+ pointer(editor.box, "pointerdown", 150, 150);+ pointer(editor.overlay, "pointermove", 190, 170);+ pointer(editor.overlay, "pointerup", 190, 170);+ pointer(editor.box, "pointerdown", 150, 150);+ pointer(editor.overlay, "pointermove", 160, 150);+ pointer(editor.overlay, "pointerup", 160, 150);++ await act(async () => {+ land();+ await write;+ });+ await waitFor(() => expect(editor.onPathOffsetCommit).toHaveBeenCalledTimes(2));+ expect(editor.onPathOffsetCommit.mock.calls.map((call) => call[1])).toEqual([+ { x: 40, y: 20 },+ { x: 50, y: 20 },+ ]);+ });++ it("moves the element it pressed, even when another is selected before the write lands", async () => {+ const editor = mountEditor(false);+ let land: () => void = () => {};+ const write = whileScriptWrites(() => new Promise<void>((resolve) => (land = resolve)));+ pointer(editor.box, "pointerdown", 150, 150);+ pointer(editor.overlay, "pointermove", 190, 170);+ pointer(editor.overlay, "pointerup", 190, 170);+ editor.render(false, makeSelection("sub", byId(editor.live, "sub")));++ await act(async () => {+ land();+ await write;+ });+ await waitFor(() => expect(file.title).toBe("translate: 40px 20px"));+ expect(file.sub).toBe("");+ });++ it("draws a waiting resize at the size it saves", async () => {+ const editor = mountEditor(false);+ let land: () => void = () => {};+ const write = whileScriptWrites(() => new Promise<void>((resolve) => (land = resolve)));+ pointer(corner(editor.overlay), "pointerdown", 300, 200);+ pointer(editor.overlay, "pointermove", 340, 200);+ pointer(editor.overlay, "pointerup", 340, 200);+ const box = editor.box as HTMLElement;+ const drawn = [box.style.width, box.style.height].map(Number.parseFloat);++ await act(async () => {+ land();+ await write;+ });+ await waitFor(() => expect(file.title).toMatch(/^width: /));+ const saved = Number.parseFloat(file.title.slice("width: ".length));+ // The save rounds to whole px.+ expect(drawn[0]).toBeCloseTo(saved, 0);+ expect(drawn[1]).toBeCloseTo((saved * RECT.height) / RECT.width, 0);+ });++ it("stops waiting on a write that never lands, and runs on the page shown", async () => {+ vi.useFakeTimers({ toFake: ["requestAnimationFrame", "cancelAnimationFrame", "performance"] });+ let land: () => void = () => {};+ const write = whileScriptWrites(() => new Promise<void>((resolve) => (land = resolve)));+ try {+ const editor = mountEditor(false);+ pointer(editor.box, "pointerdown", 150, 150);+ pointer(editor.overlay, "pointermove", 190, 170);+ pointer(editor.overlay, "pointerup", 190, 170);+ await act(async () => void vi.advanceTimersByTime(PRESS_WAIT_MAX_MS - 100));+ expect(editor.onPathOffsetCommit, "still waiting").not.toHaveBeenCalled();+ await act(async () => void vi.advanceTimersByTime(200));+ expect(editor.onPathOffsetCommit.mock.calls.map((call) => call[1])).toEqual([+ { x: 40, y: 20 },+ ]);++ pointer(editor.box, "pointerdown", 190, 170);+ expect(editor.box.hasAttribute(PRESS_WAITING_ATTR), "no second wait on the same write").toBe(+ false,+ );+ pointer(editor.overlay, "pointerup", 190, 170);+ } finally {+ vi.useRealTimers();+ await act(async () => {+ land();+ await write;+ });+ }+ });++ it("is what Cmd+Z undoes while it waits, so it never runs", async () => {+ const editor = mountEditor(false);+ let land: () => void = () => {};+ const write = whileScriptWrites(() => new Promise<void>((resolve) => (land = resolve)));+ pointer(editor.box, "pointerdown", 150, 150);+ pointer(editor.overlay, "pointermove", 190, 170);+ pointer(editor.overlay, "pointerup", 190, 170);++ let cancelled = false;+ act(() => void (cancelled = cancelNewestStudioWaitingPress()));+ expect(cancelled, "the waiting press is the newest edit").toBe(true);+ expect((editor.box as HTMLElement).style.left, "the outline goes back").toBe("100px");+ expect(editor.box.hasAttribute(PRESS_WAITING_ATTR)).toBe(false);++ await act(async () => {+ land();+ await write;+ });+ await settle();+ expect(editor.onPathOffsetCommit).not.toHaveBeenCalled();+ expect(file.title).toBe("");+ });++ /** Two presses wait on a write; the first runs and starts its own write, so the second still waits. */+ function queuedBehindOneThatRan() {+ const editor = mountEditor(false);+ let land: () => void = () => {};+ let landFirst: () => void = () => {};+ const write = whileScriptWrites(() => new Promise<void>((resolve) => (land = resolve)));+ const firstSaved = new Promise<void>((resolve) => (landFirst = resolve));+ stuckWrites.push(+ () => land(),+ () => landFirst(),+ );+ const commit = editor.onPathOffsetCommit.getMockImplementation()!;+ editor.onPathOffsetCommit.mockImplementationOnce((...args) =>+ whileScriptWrites(async () => {+ await firstSaved;+ return commit(...args);+ }),+ );+ pointer(editor.box, "pointerdown", 150, 150);+ pointer(editor.overlay, "pointermove", 190, 170);+ pointer(editor.overlay, "pointerup", 190, 170);+ pointer(editor.box, "pointerdown", 190, 170);+ pointer(editor.overlay, "pointermove", 210, 180);+ const ran = async () => {+ await act(async () => {+ land();+ await write;+ });+ await waitFor(() => expect(editor.onPathOffsetCommit).toHaveBeenCalledTimes(1));+ };+ const landFirstSave = () =>+ act(async () => {+ landFirst();+ await firstSaved;+ });+ return { editor, ran, landFirstSave };+ }++ it("leaves Cmd+Z to history once the press it could take back has run", async () => {+ const editor = mountEditor(false);+ let land: () => void = () => {};+ const write = whileScriptWrites(() => new Promise<void>((resolve) => (land = resolve)));+ stuckWrites.push(() => land());+ pointer(editor.box, "pointerdown", 150, 150);+ pointer(editor.overlay, "pointermove", 190, 170);+ pointer(editor.overlay, "pointerup", 190, 170);+ await act(async () => {+ land();+ await write;+ });+ await waitFor(() => expect(file.title).toBe("translate: 40px 20px"));+ expect(cancelNewestStudioWaitingPress()).toBe(false);+ });++ it("takes back a press queued behind one that ran, and leaves nothing waiting", async () => {+ const { editor, ran, landFirstSave } = queuedBehindOneThatRan();+ pointer(editor.overlay, "pointerup", 210, 180);+ await ran();+ expect(editor.box.hasAttribute(PRESS_WAITING_ATTR), "the second press waits").toBe(true);++ act(() => void cancelNewestStudioWaitingPress());+ expect(editor.box.hasAttribute(PRESS_WAITING_ATTR)).toBe(false);+ expect(cancelNewestStudioWaitingPress(), "the following Cmd+Z steps history").toBe(false);+ await landFirstSave();+ await settle();+ expect(editor.onPathOffsetCommit).toHaveBeenCalledTimes(1);+ });++ it("drops a held press queued behind one that ran on blur, and leaves nothing waiting", async () => {+ const { editor, ran, landFirstSave } = queuedBehindOneThatRan();+ await ran();+ act(() => void window.dispatchEvent(new Event("blur")));+ expect(editor.box.hasAttribute(PRESS_WAITING_ATTR)).toBe(false);+ expect(cancelNewestStudioWaitingPress()).toBe(false);+ await landFirstSave();+ });++ it("lands a released drag when the window loses focus before the write does", async () => {+ const editor = mountEditor(false);+ let land: () => void = () => {};+ const write = whileScriptWrites(() => new Promise<void>((resolve) => (land = resolve)));+ pointer(editor.box, "pointerdown", 150, 150);+ pointer(editor.overlay, "pointermove", 190, 170);+ pointer(editor.overlay, "pointerup", 190, 170);+ act(() => void window.dispatchEvent(new Event("blur")));+ expect(layout.rafPaused.current, "the box does not re-measure under a waiting press").toBe(+ true,+ );++ await act(async () => {+ land();+ await write;+ });+ await waitFor(() => expect(file.title).toBe("translate: 40px 20px"));+ });++ it("drops only the press still held when the window loses focus", async () => {+ const editor = mountEditor(false);+ let land: () => void = () => {};+ const write = whileScriptWrites(() => new Promise<void>((resolve) => (land = resolve)));+ pointer(editor.box, "pointerdown", 150, 150);+ pointer(editor.overlay, "pointermove", 190, 170);+ pointer(editor.overlay, "pointerup", 190, 170);+ pointer(editor.box, "pointerdown", 190, 170);+ pointer(editor.overlay, "pointermove", 220, 170);+ act(() => void window.dispatchEvent(new Event("blur")));+ expect((editor.box as HTMLElement).style.left, "back to the released drop").toBe("140px");++ await act(async () => {+ land();+ await write;+ });+ await waitFor(() => expect(file.title).toBe("translate: 40px 20px"));+ expect(editor.onPathOffsetCommit).toHaveBeenCalledTimes(1);+ });+});+describe("a drag moves only with its own pointer pressed", () => {it.each([["no button held, as Chromium sends after a layout change", { buttons: 0 }],@@ -289,6 +678,34 @@ describe("a drag moves only with its own pointer pressed", () => {);});+describe("a press while the preview swaps scenes in place", () => {+ it("waits for the swap and moves the swapped-in node", async () => {+ const { live, overlay, box } = mountEditor(false);+ Object.assign(live.contentWindow!, {+ __hfSwapScenes: (html: string) => {+ live.contentDocument!.body.innerHTML = html.replace(/^[\s\S]*<body>|<\/body>[\s\S]*$/g, "");+ },+ });+ let reply: (r: Response) => void = () => {};+ vi.stubGlobal("fetch", () => new Promise<Response>((resolve) => (reply = resolve)));+ try {+ const replaced = byId(live, "title");+ act(() => api().refreshPlayer());+ pointer(box, "pointerdown", 150, 150);+ pointer(overlay, "pointermove", 190, 170);+ pointer(overlay, "pointerup", 190, 170);+ expect(box.hasAttribute(PRESS_WAITING_ATTR), "held until the new scenes show").toBe(true);++ reply(new Response(served("").contentDocument!.documentElement.outerHTML));+ await waitFor(() => expect(file.title).toBe("translate: 40px 20px"));+ expect(byId(live, "title")).not.toBe(replaced);+ expect(byId(live, "title").style.getPropertyValue("translate")).toBe("40px 20px");+ } finally {+ vi.unstubAllGlobals();+ }+ });+});+describe("an outside change during a drag, on a preview that can swap scenes in place", () => {it("leaves the dragged node in place and shows the change after the drop, loaded fresh", async () => {const { live, overlay, box } = mountEditor(false);diff --git a/packages/studio/src/components/editor/groupDropKeepsSelection.test.ts b/packages/studio/src/components/editor/groupDropKeepsSelection.test.tsindex 3fc95b6742..9f63486d73 100644--- a/packages/studio/src/components/editor/groupDropKeepsSelection.test.ts+++ b/packages/studio/src/components/editor/groupDropKeepsSelection.test.ts@@ -37,6 +37,7 @@ describe("dropping a dragged group eats the click that follows", () => {gestureRef: { current: null },groupGestureRef,blockedMoveRef: { current: null },+ waitingPressRef: { current: null },rafPausedRef: { current: false },suppressNextBoxClickRef,setOverlayRect: vi.fn(),diff --git a/packages/studio/src/components/editor/manualEditsDom.ts b/packages/studio/src/components/editor/manualEditsDom.tsindex 0b9f6e1851..086eee467c 100644--- a/packages/studio/src/components/editor/manualEditsDom.ts+++ b/packages/studio/src/components/editor/manualEditsDom.ts@@ -6,6 +6,8 @@ import {STUDIO_ROTATION_PROP,STUDIO_PATH_OFFSET_ATTR,STUDIO_MANUAL_EDIT_GESTURE_ATTR,+ STUDIO_EDIT_MOMENT_ATTR,+ type EditMoment,STUDIO_BOX_SIZE_ATTR,STUDIO_ROTATION_ATTR,STUDIO_ORIGINAL_TRANSLATE_ATTR,@@ -52,10 +54,13 @@ const GESTURE_DRAWS: Record<StudioGestureDraws, readonly string[]> = {export function beginStudioManualEditGesture(element: HTMLElement,draws: StudioGestureDraws,+ at?: EditMoment,): string {studioManualEditGestureId += 1;const token = `gesture-${studioManualEditGestureId}:${draws}`;element.setAttribute(STUDIO_MANUAL_EDIT_GESTURE_ATTR, token);+ if (at) element.setAttribute(STUDIO_EDIT_MOMENT_ATTR, JSON.stringify(at));+ else element.removeAttribute(STUDIO_EDIT_MOMENT_ATTR);return token;}@@ -65,6 +70,7 @@ export function endStudioManualEditGesture(element: HTMLElement, token?: string)if (token && element.getAttribute(STUDIO_MANUAL_EDIT_GESTURE_ATTR) !== token) return;if (!element.hasAttribute(STUDIO_MANUAL_EDIT_GESTURE_ATTR)) return;element.removeAttribute(STUDIO_MANUAL_EDIT_GESTURE_ATTR);+ element.removeAttribute(STUDIO_EDIT_MOMENT_ATTR);const doc = element.ownerDocument;doc.dispatchEvent(new (doc.defaultView?.Event ?? Event)(GESTURE_ENDED));}@@ -132,13 +138,7 @@ export function readStudioPathOffset(element: HTMLElement): { x: number; y: numb};}-/**- * The path offset ACTUALLY applied right now. The `--hf-studio-offset` vars can- * linger after GSAP re-bakes the element's transform (`translate:"none"`), so the- * raw var isn't a safe drag base — using it re-commits a phantom offset and flings- * the element off-screen. The offset only counts when the inline `translate` is the- * studio var-translate; otherwise it's dormant and the applied offset is zero.- */+// GSAP can leave dormant offset vars behind; only the live var-translate counts.export function readAppliedStudioPathOffset(element: HTMLElement): { x: number; y: number } {return (element.style.translate || "").includes(STUDIO_OFFSET_X_PROP)? readStudioPathOffset(element)diff --git a/packages/studio/src/components/editor/manualEditsTypes.ts b/packages/studio/src/components/editor/manualEditsTypes.tsindex 9c12ee0ac4..063b1d0a80 100644--- a/packages/studio/src/components/editor/manualEditsTypes.ts+++ b/packages/studio/src/components/editor/manualEditsTypes.ts@@ -10,6 +10,11 @@ export const STUDIO_ROTATION_PROP = "--hf-studio-rotation";/* ── Internal DOM attribute names ─────────────────────────────────── */export const STUDIO_PATH_OFFSET_ATTR = "data-hf-studio-path-offset";+export const STUDIO_EDIT_MOMENT_ATTR = "data-hf-studio-edit-at";+export interface EditMoment {+ time: number;+ keyframePct: number | null;+}export const STUDIO_BOX_SIZE_ATTR = "data-hf-studio-box-size";export const STUDIO_ROTATION_ATTR = "data-hf-studio-rotation";export const STUDIO_ORIGINAL_TRANSLATE_ATTR = "data-hf-studio-original-translate";diff --git a/packages/studio/src/components/editor/manualOffsetDrag.test.ts b/packages/studio/src/components/editor/manualOffsetDrag.test.tsindex 3bd3cd48e3..0ea1b5882f 100644--- a/packages/studio/src/components/editor/manualOffsetDrag.test.ts+++ b/packages/studio/src/components/editor/manualOffsetDrag.test.ts@@ -452,6 +452,29 @@ describe("GSAP-element drag — dot-a flies regressions", () => {});});+describe("a drag that starts while an earlier gesture is still saving", () => {+ it("keeps the timelines paused until the later drag ends", () => {+ const { element, member } = makeGsapDot();+ let paused = false;+ const timeline = {+ pause: () => (paused = true),+ paused: (v?: boolean) => (paused = v ?? paused),+ };+ (element.ownerDocument.defaultView as unknown as { __timelines: unknown }).__timelines = {+ main: timeline,+ };+ const earlier = member();+ applyManualOffsetDragCommit(earlier, -50, 0);+ const later = member();++ endManualOffsetDragMembers([earlier]);++ expect(paused).toBe(true);+ endManualOffsetDragMembers([later]);+ expect(paused).toBe(false);+ });+});+describe("sub-pixel drags", () => {it("draft and commit both land the exact fractional position", () => {const { element, sets, member } = makeGsapDot();diff --git a/packages/studio/src/components/editor/manualOffsetDrag.ts b/packages/studio/src/components/editor/manualOffsetDrag.tsindex 9db1f5c296..70957f361d 100644--- a/packages/studio/src/components/editor/manualOffsetDrag.ts+++ b/packages/studio/src/components/editor/manualOffsetDrag.ts@@ -7,10 +7,12 @@ import {captureStudioPathOffset,clearStudioPathOffset,endStudioManualEditGesture,+ isStudioManualEditGestureCurrent,readAppliedStudioPathOffset,restoreStudioPathOffset,type StudioPathOffsetSnapshot,} from "./manualEdits";+import type { EditMoment } from "./manualEditsTypes";import { computeDraggedGsapPosition } from "../../hooks/draggedGsapPosition";import { editsPlainCss } from "../../hooks/gsapRuntimeKeyframes";import { readTranslatePx, UNREADABLE_TRANSLATE, writeTranslatePx } from "./plainTranslate";@@ -315,6 +317,7 @@ export function createManualOffsetDragMember(input: {element: HTMLElement;rect: ManualOffsetDragRect;gesture?: "drag" | "nudge" | "resize"; // resize: the anchor that keeps its centre planted+ at?: EditMoment;}): ManualOffsetDragMemberResult {const plainTranslate =!!input.gesture && editsPlainCss(input.element, input.gesture === "resize" ? "resize" : "move");@@ -357,6 +360,7 @@ export function createManualOffsetDragMember(input: {const gestureToken = beginStudioManualEditGesture(input.element,input.gesture === "resize" ? "resize" : "move",+ input.at,);const measured = measureManualOffsetDragScreenToOffsetMatrix(input.element, initialOffset, {scaleX: input.rect.editScaleX,@@ -531,6 +535,7 @@ function settleDraftTranslate(element: HTMLElement, gsapOwnsPosition: boolean):/** Teardown after a COMMITTED drag. */export function endManualOffsetDragMembers(members: ManualOffsetDragMember[]): void {for (const member of members) {+ if (!isStudioManualEditGestureCurrent(member.element, member.gestureToken)) continue;endStudioManualEditGesture(member.element, member.gestureToken);member.element.removeAttribute("data-hf-drag-initial-offset-x");member.element.removeAttribute("data-hf-drag-initial-offset-y");diff --git a/packages/studio/src/components/editor/previewGestureStarts.ts b/packages/studio/src/components/editor/previewGestureStarts.tsnew file mode 100644index 0000000000..d793e7ee9c--- /dev/null+++ b/packages/studio/src/components/editor/previewGestureStarts.ts@@ -0,0 +1,284 @@+import {+ orientedGroupAwareOverlayRect,+ shiftedOverlayRect,+ type OverlayRect,+} from "./domEditOverlayGeometry";+import { findElementForSelection, type DomEditSelection } from "./domEditing";+import { computeOverlayRootScale } from "./domEditOverlayBasis";+import { resolveCenterResizeScale } from "./domEditResizeLocal";+import {+ PRESS_WAITING_ATTR,+ type WaitingPressState,+ type GestureKind,+ type ResizeHandle,+ type UseDomEditOverlayGesturesOptions,+} from "./domEditOverlayGestures";+import {+ startGesture as _startGesture,+ startGroupDrag as _startGroupDrag,+} from "./domEditOverlayStartGesture";+import { giveUpOnPreviewChange, isPreviewChanging } from "../../player/previewReloading";+import { setStudioWaitingPressCancel } from "../../utils/studioPendingEdits";+import { playheadMoment } from "../../hooks/editMoment";+import type { EditMoment } from "./manualEditsTypes";++const MAX_SETTLED_WAIT_FRAMES = 60;+export const PRESS_WAIT_MAX_MS = 10_000;++export function createPreviewGestureStarts(+ opts: UseDomEditOverlayGesturesOptions,+ moveActiveGesture: (e: React.PointerEvent<HTMLDivElement>) => void,+ releaseActiveGesture: (e: React.PointerEvent<HTMLDivElement>) => void,+) {+ /** Points Cmd+Z at the newest released press still waiting, if any. */+ const offerUndo = () => {+ let p = opts.waitingPressRef.current;+ while (p && !p.released) p = p.after;+ const press = p;+ setStudioWaitingPressCancel(press && (() => dropPress(press)));+ };++ const clearWaitingMark = () => {+ opts.boxRef.current?.removeAttribute(PRESS_WAITING_ATTR);+ opts.rafPausedRef.current = false;+ };++ /** Points the press queued right behind `press` at `next` instead. */+ const unlink = (press: WaitingPressState, next: WaitingPressState | null) => {+ for (let p = opts.waitingPressRef.current; p; p = p.after)+ if (p.after === press) p.after = next;+ };++ const endWaitingPress = (press: WaitingPressState | null = opts.waitingPressRef.current) => {+ for (let p = press; p && !p.ended; p = p.after) {+ p.ended = true;+ cancelAnimationFrame(p.frame);+ }+ if (press === opts.waitingPressRef.current) {+ opts.waitingPressRef.current = null;+ clearWaitingMark();+ }+ // A press queued behind this one keeps waiting, on nothing that has ended.+ else if (press) unlink(press, null);+ offerUndo();+ };++ /** The newest press goes: the outline shows the press before it, or the box before this one. */+ const showPressBefore = (press: WaitingPressState) => {+ const before = press.after;+ opts.waitingPressRef.current = before;+ const shown = before ?? press;+ const at = before?.moved;+ const [dx, dy] = at ? [at.clientX - shown.startX, at.clientY - shown.startY] : [0, 0];+ shown.draw?.(dx, dy);+ if (!before) clearWaitingMark();+ };++ /** Takes one press out of the queue. */+ const dropPress = (press: WaitingPressState): boolean => {+ if (press.ended) return false;+ press.ended = true;+ cancelAnimationFrame(press.frame);+ if (press === opts.waitingPressRef.current) showPressBefore(press);+ else unlink(press, press.after);+ offerUndo();+ return true;+ };++ /** Ends the press still held, if any; presses already released are finished edits and still land. */+ const endHeldPress = () => {+ const held = opts.waitingPressRef.current;+ if (held && !held.released) dropPress(held);+ };++ const releaseWaitingPress = (press: WaitingPressState, e: React.PointerEvent<HTMLDivElement>) => {+ press.released = e;+ offerUndo();+ };++ const drawPressedBox = (origin: OverlayRect | null): WaitingPressState["draw"] =>+ origin && ((dx, dy) => opts.setOverlayRect(shiftedOverlayRect(origin, dx, dy)));++ // A corner resize scales about the element's centre by the pointer's distance from it, as the resize does.+ const drawResizedBox = (+ origin: OverlayRect | null,+ press: { x: number; y: number },+ ): WaitingPressState["draw"] => {+ if (!origin) return null;+ const bounds = opts.overlayRef.current?.getBoundingClientRect();+ const centre = {+ x: (bounds?.left ?? 0) + origin.left + origin.width / 2,+ y: (bounds?.top ?? 0) + origin.top + origin.height / 2,+ };+ return (dx, dy) => {+ const pointer = { x: press.x + dx, y: press.y + dy };+ const scale = resolveCenterResizeScale({ pointer, pointerStart: press, centerStart: centre });+ const [width, height] = [origin.width * scale, origin.height * scale];+ opts.setOverlayRect({+ ...origin,+ left: origin.left + (origin.width - width) / 2,+ top: origin.top + (origin.height - height) / 2,+ width,+ height,+ });+ };+ };++ // A press on the page a reload is replacing would edit it by its old rules: it starts on the new page instead.+ const startOnShownPreview = (+ e: React.PointerEvent<HTMLElement>,+ pressed: () => HTMLElement[],+ start: (e: React.PointerEvent<HTMLElement>, at: EditMoment, waited: boolean) => boolean,+ draw: WaitingPressState["draw"] = null,+ ): boolean => {+ const at = playheadMoment();+ if (!isPreviewChanging() && !opts.waitingPressRef.current) return start(e, at, false);+ e.preventDefault();+ e.stopPropagation();+ e.currentTarget.setPointerCapture(e.pointerId);+ // The press already holds the pointer, which may be up by the time the gesture starts.+ const held = { setPointerCapture() {} };+ const down = { ...e, currentTarget: held, preventDefault() {}, stopPropagation() {} };+ const press: WaitingPressState = {+ pointerId: e.pointerId,+ startX: e.clientX,+ startY: e.clientY,+ draw,+ frame: 0,+ moved: null,+ released: null,+ after: opts.waitingPressRef.current,+ ended: false,+ };+ opts.waitingPressRef.current = press;+ opts.boxRef.current?.setAttribute(PRESS_WAITING_ATTR, "true");+ opts.rafPausedRef.current = true;+ let shownFrames = 0;+ let settledFrames = 0;+ const since = performance.now();+ /** Counts this frame toward the shown and settled streaks; returns how many pressed elements remain. */+ const countFrame = () => {+ const elements = pressed();+ const live = opts.iframeRef.current?.contentDocument;+ const settled = !isPreviewChanging();+ const shown = settled && elements.every((el) => el.ownerDocument === live);+ shownFrames = shown ? shownFrames + 1 : 0;+ settledFrames = settled ? settledFrames + 1 : 0;+ return elements.length;+ };+ const waitStep = (): "wait" | "lost" | "run" => {+ if (press.after && !press.after.ended) return "wait";+ const found = countFrame();+ // A change that never ends (a save with no reply) would hold every press: run on the page shown.+ const overdue = performance.now() - since > PRESS_WAIT_MAX_MS;+ if (overdue) giveUpOnPreviewChange();+ // The waiting outline stays drawn while replay measures the live element separately.+ if (found === 0 || settledFrames > MAX_SETTLED_WAIT_FRAMES) return "lost";+ return overdue || shownFrames >= 2 ? "run" : "wait";+ };+ const poll = () => {+ if (press.ended) return;+ const step = waitStep();+ if (step === "wait") {+ press.frame = requestAnimationFrame(poll);+ return;+ }+ endWaitingPress(press);+ if (step === "lost" || !start(down as unknown as React.PointerEvent<HTMLElement>, at, true))+ return;+ if (press.moved) moveActiveGesture(press.moved);+ if (press.released) releaseActiveGesture(press.released);+ };+ press.frame = requestAnimationFrame(poll);+ return true;+ };++ const shownSelection = (selection: DomEditSelection) => {+ const doc = opts.iframeRef.current?.contentDocument;+ if (!doc) return null;+ const element = findElementForSelection(doc, selection, opts.activeCompositionPathRef.current);+ return element && { ...selection, element };+ };+ const shownRect = (element: HTMLElement) => {+ const overlay = opts.overlayRef.current;+ const iframe = opts.iframeRef.current;+ return overlay && iframe && orientedGroupAwareOverlayRect(overlay, iframe, element);+ };++ const startGroupDrag = (e: React.PointerEvent<HTMLElement>) => {+ const items = opts.groupOverlayItemsRef.current;+ return startOnShownPreview(+ e,+ () =>+ items.flatMap((item) => {+ const selection = shownSelection(item.selection);+ return selection ? [selection.element] : [];+ }),+ (pressed, at, waited) => {+ if (!waited) return _startGroupDrag(pressed, opts, at);+ const overlay = opts.overlayRef.current;+ const iframe = opts.iframeRef.current;+ if (!overlay || !iframe) return false;+ const scale = computeOverlayRootScale(overlay, iframe, iframe.contentDocument);+ const measured = items.flatMap((item) => {+ const selection = shownSelection(item.selection);+ const rect =+ selection && orientedGroupAwareOverlayRect(overlay, iframe, selection.element, scale);+ return selection && rect+ ? [{ ...item, selection, element: selection.element, rect }]+ : [];+ });+ if (measured.length !== items.length) return false;+ return _startGroupDrag(+ pressed,+ { ...opts, groupOverlayItemsRef: { current: measured } },+ at,+ );+ },+ (dx, dy) =>+ opts.setGroupOverlayItems(+ items.map((item) => ({ ...item, rect: shiftedOverlayRect(item.rect, dx, dy) })),+ ),+ );+ };+ const startGesture = (+ kind: GestureKind,+ e: React.PointerEvent<HTMLElement>,+ options?: {+ selection?: DomEditSelection;+ rect?: OverlayRect | null;+ resizeHandle?: ResizeHandle;+ },+ ) => {+ // A replay edits what was pressed, though another element may be selected by then.+ const target = options?.selection ?? opts.selectionRef.current;+ let draw: WaitingPressState["draw"] = null;+ if (kind === "drag") draw = drawPressedBox(opts.overlayRectRef.current);+ if (kind === "resize")+ draw = drawResizedBox(opts.overlayRectRef.current, { x: e.clientX, y: e.clientY });+ return startOnShownPreview(+ e,+ () => {+ const shown = target && shownSelection(target);+ return shown ? [shown.element] : [];+ },+ (pressed, at, waited) => {+ if (!waited) return _startGesture(kind, pressed, opts, { ...options, at });+ const selection = target && shownSelection(target);+ const rect = selection && shownRect(selection.element);+ return (+ !!(selection && rect) &&+ _startGesture(kind, pressed, opts, {+ selection,+ rect,+ resizeHandle: options?.resizeHandle,+ at,+ })+ );+ },+ draw,+ );+ };++ return { startGesture, startGroupDrag, endWaitingPress, endHeldPress, releaseWaitingPress };+}diff --git a/packages/studio/src/components/editor/rotateInlineSave.test.ts b/packages/studio/src/components/editor/rotateInlineSave.test.tsindex a24191800d..e9f2289162 100644--- a/packages/studio/src/components/editor/rotateInlineSave.test.ts+++ b/packages/studio/src/components/editor/rotateInlineSave.test.ts@@ -62,6 +62,7 @@ async function rotateWord(before: (word: HTMLElement) => void = () => {}) {gestureRef: ref<GestureState | null>(null),groupGestureRef: ref(null),blockedMoveRef: ref(null),+ waitingPressRef: ref(null),rafPausedRef: ref(false),suppressNextBoxClickRef: ref(false),setOverlayRect: () => {},diff --git a/packages/studio/src/components/editor/shiftDragAxisLock.test.tsx b/packages/studio/src/components/editor/shiftDragAxisLock.test.tsxindex 2e4f9782cc..823197e44a 100644--- a/packages/studio/src/components/editor/shiftDragAxisLock.test.tsx+++ b/packages/studio/src/components/editor/shiftDragAxisLock.test.tsx@@ -19,6 +19,7 @@ function gestureHarness(gesture: Partial<GestureState> | null, group: GroupGestuhoverSelectionRef: { current: null },boxRef: { current: null },blockedMoveRef: { current: null },+ waitingPressRef: { current: null },rafPausedRef: { current: false },suppressNextBoxClickRef: { current: false },snapGuidesRef: { current: null },diff --git a/packages/studio/src/components/editor/useDomEditOverlayGestures.ts b/packages/studio/src/components/editor/useDomEditOverlayGestures.tsindex 1477126f5d..e4bea97162 100644--- a/packages/studio/src/components/editor/useDomEditOverlayGestures.ts+++ b/packages/studio/src/components/editor/useDomEditOverlayGestures.ts@@ -1,3 +1,4 @@+import { createPreviewGestureStarts } from "./previewGestureStarts";import { trackPreviewEditResult } from "../../utils/previewFeatureUsage";// fallow-ignore-file code-duplication/**@@ -28,13 +29,12 @@ import {type GroupOverlayItem,type OverlayRect,orientedOverlayRect,+ shiftedOverlayRect,} from "./domEditOverlayGeometry";import {BLOCKED_MOVE_THRESHOLD_PX,- type GestureKind,type GestureState,type GroupGestureState,- type ResizeHandle,type UseDomEditOverlayGesturesOptions,ROTATED_SNAP_BYPASS_DEGREES,hasDomEditRotationChanged,@@ -44,11 +44,7 @@ import {} from "./domEditOverlayGestures";import { resolveCenterResizeSize } from "./domEditResizeLocal";import { resolveResizeDraftRect } from "./resizeDraft";-import {- notifyBlockedPress,- startGesture as _startGesture,- startGroupDrag as _startGroupDrag,-} from "./domEditOverlayStartGesture";+import { notifyBlockedPress } from "./domEditOverlayStartGesture";import { hugRectForElement } from "./domEditOverlayCrop";import {resolveSnapAdjustment,@@ -76,7 +72,7 @@ function logGestureCommitFailure(message: string, error: unknown): void {export function createDomEditOverlayGestureHandlers(opts: UseDomEditOverlayGesturesOptions) {const setDraftOverlayRect = (next: OverlayRect) => {- opts.setOverlayRect(next);+ if (!opts.waitingPressRef.current) opts.setOverlayRect(next);};const restoreGestureOverlayRect = (g: GestureState) => {setDraftOverlayRect({@@ -86,14 +82,12 @@ export function createDomEditOverlayGestureHandlers(opts: UseDomEditOverlayGestuheight: g.originHeight,editScaleX: g.editScaleX,editScaleY: g.editScaleY,- // Every draft rect must carry the element's rotation: the rotation wrapper- // renders rotate(overlayRect.angle), so an omitted angle straightens the- // chrome for the duration of the draft (the "straightens while moving" bug).+ // Rotation keeps the chrome aligned with the element during its draft.angle: g.actualRotation,});};const setDraftGroupOverlayItems = (next: GroupOverlayItem[]) => {- opts.setGroupOverlayItems(next);+ if (!opts.waitingPressRef.current) opts.setGroupOverlayItems(next);};const restoreGroupPathOffsets = (g: GroupGestureState) => {@@ -101,16 +95,12 @@ export function createDomEditOverlayGestureHandlers(opts: UseDomEditOverlayGestusetDraftGroupOverlayItems(g.originItems);};- const startGroupDrag = (e: React.PointerEvent<HTMLElement>) => _startGroupDrag(e, opts);- const startGesture = (- kind: GestureKind,- e: React.PointerEvent<HTMLElement>,- options?: {- selection?: DomEditSelection;- rect?: OverlayRect | null;- resizeHandle?: ResizeHandle;- },- ) => _startGesture(kind, e, opts, options);+ const { startGesture, startGroupDrag, endWaitingPress, endHeldPress, releaseWaitingPress } =+ createPreviewGestureStarts(+ opts,+ (event) => moveActiveGesture(event),+ (event) => releaseActiveGesture(event),+ );// A press on a box that cannot move says why at once.const startBlockedMove = (e: React.PointerEvent<HTMLElement>, selection: DomEditSelection) => {@@ -123,12 +113,23 @@ export function createDomEditOverlayGestureHandlers(opts: UseDomEditOverlayGestuconst moveGroupDrag = createGroupDragMover(opts, setDraftGroupOverlayItems);- // fallow-ignore-next-line complexityconst onPointerMove = (e: React.PointerEvent<HTMLDivElement>) => {+ const waiting = opts.waitingPressRef.current;+ if (waiting && waiting.pointerId === e.pointerId) {+ if (waiting.released || !movesGesture(waiting, e)) return;+ waiting.moved = e;+ waiting.draw?.(e.clientX - waiting.startX, e.clientY - waiting.startY);+ return;+ }+ moveActiveGesture(e);+ };++ // fallow-ignore-next-line complexity+ const moveActiveGesture = (e: React.PointerEvent<HTMLDivElement>) => {const g = opts.gestureRef.current;const groupG = opts.groupGestureRef.current;const sel = g?.selection ?? opts.selectionRef.current;- const box = opts.boxRef.current;+ const box = opts.waitingPressRef.current ? null : opts.boxRef.current;const blockedMove = opts.blockedMoveRef.current;if (!blockedMove && !g && !groupG) {opts.onCanvasPointerMoveRef.current(e, { preferClipAncestor: false });@@ -248,18 +249,7 @@ export function createDomEditOverlayGestureHandlers(opts: UseDomEditOverlayGestu}if (g.pathOffsetMember) applyManualOffsetDragDraft(g.pathOffsetMember, dx, dy);} else {- if (!box) return;-- // CENTER-ANCHORED size (CapCut model): the element scales proportionally- // about its CENTER — the scale is the pointer's RADIAL distance from the- // element center now over its distance at gesture start. Rotation-invariant- // (a distance ignores the angle) and continuous, so all four corners behave- // identically and there is no per-axis projection or edge-snapping. Base size- // is the element-local px size at gesture start (actualWidth/Height,- // GSAP-scale-aware). Corner drag is ALWAYS proportional; there is no- // free-form stretch gesture. Edge-snapping is intentionally NOT applied:- // with center anchoring both edges move symmetrically, so the corner-anchored- // snap math no longer holds — CapCut does not edge-snap during scale either.+ // Corner resize scales proportionally about the center, without edge snapping.const nextSize = resolveCenterResizeSize({baseWidth: g.actualWidth,baseHeight: g.actualHeight,@@ -288,33 +278,41 @@ export function createDomEditOverlayGestureHandlers(opts: UseDomEditOverlayGestudraftRect,liveInlineStyle: sel.element.getAttribute("style"),});- box.style.left = `${draftRect.left}px`;- box.style.top = `${draftRect.top}px`;- box.style.width = `${draftRect.width}px`;- box.style.height = `${draftRect.height}px`;+ if (box) {+ box.style.left = `${draftRect.left}px`;+ box.style.top = `${draftRect.top}px`;+ box.style.width = `${draftRect.width}px`;+ box.style.height = `${draftRect.height}px`;+ }setDraftOverlayRect(draftRect);}};- // fallow-ignore-next-line complexityconst onPointerUp = (e: React.PointerEvent<HTMLDivElement>) => {+ const waiting = opts.waitingPressRef.current;+ if (waiting && waiting.pointerId === e.pointerId) {+ releaseWaitingPress(waiting, e);+ opts.suppressNextBoxClickRef.current = true;+ return;+ }+ releaseActiveGesture(e);+ };++ // fallow-ignore-next-line complexity+ const releaseActiveGesture = (e: React.PointerEvent<HTMLDivElement>) => {opts.snapGuidesRef.current = null;const g = opts.gestureRef.current;const groupG = opts.groupGestureRef.current;const sel = g?.selection ?? opts.selectionRef.current;- const box = opts.boxRef.current;+ const box = opts.waitingPressRef.current ? null : opts.boxRef.current;opts.blockedMoveRef.current = null;+ opts.rafPausedRef.current = opts.waitingPressRef.current !== null;if (groupG) {opts.groupGestureRef.current = null;- opts.rafPausedRef.current = false;const rawDx = e.clientX - groupG.startX;const rawDy = e.clientY - groupG.startY;- // The click that trails every pointerup has to be eaten either way. The- // gesture ref is already cleared above, so by the time it arrives the box- // no longer looks busy, and handleBoxClick hands it to the canvas as an- // ordinary click — which lands between the members, resolves to nothing,- // and deselects the group the drag just moved.+ // Consume the release click so it cannot deselect the moved group.opts.suppressNextBoxClickRef.current = true;if (isTap(groupG, e)) {restoreGroupPathOffsets(groupG);@@ -331,7 +329,7 @@ export function createDomEditOverlayGestureHandlers(opts: UseDomEditOverlayGestusetDraftGroupOverlayItems(groupG.originItems.map((item) => ({...item,- rect: { ...item.rect, left: item.rect.left + dx, top: item.rect.top + dy },+ rect: shiftedOverlayRect(item.rect, dx, dy),})),);const updates = groupG.members.map((member) => ({@@ -367,23 +365,15 @@ export function createDomEditOverlayGestureHandlers(opts: UseDomEditOverlayGestu.finally(() => {logDrag("committed", { at: readDragPositions(groupG.members) });endManualOffsetDragMembers(groupG.members);- // The gesture teardown resumes the paused timelines and re-seeks the- // player, which re-renders from whatever the preview currently holds.- // If the reloaded source has not landed yet that is the OLD position,- // so this is where a snap-back would show.+ // Teardown re-seeks the player, exposing any stale preview position.logDragSettle("settle", groupG.members);});groupEdit.settle(groupSaved);return;}- if (!g || !sel) {- opts.gestureRef.current = null;- opts.rafPausedRef.current = false;- return;- }opts.gestureRef.current = null;- opts.rafPausedRef.current = false;+ if (!g || !sel) return;const movedDistance = Math.hypot(e.clientX - g.startX, e.clientY - g.startY);if (g.kind === "drag" && isTap(g, e)) {@@ -457,10 +447,7 @@ export function createDomEditOverlayGestureHandlers(opts: UseDomEditOverlayGestu.finally(() => endStudioManualEditGesture(sel.element, g.manualEditDragToken));edit.settle(saved);} else if (g.kind === "drag") {- // A moved drag (taps returned earlier) must not let the release click- // re-select whatever now sits under the pointer — dropping over a- // higher-z element should keep the dragged element selected, not select- // the drop target. Mirrors the resize branch below.+ // A release over another layer must keep this dragged layer selected.opts.suppressNextBoxClickRef.current = true;const dx = g.lastSnappedDx ?? e.clientX - g.startX;const dy = g.lastSnappedDy ?? e.clientY - g.startY;@@ -509,12 +496,7 @@ export function createDomEditOverlayGestureHandlers(opts: UseDomEditOverlayGestuopts.suppressNextBoxClickRef.current = true;const finalSize = readStudioBoxSize(sel.element);applyStudioBoxSize(sel.element, finalSize);- // Anchored corner resize (NW/NE/SW) also moved the element to keep the- // center planted. Land the size AND the anchor offset in a SINGLE- // box-size commit (one persist, one undo entry). The prior two-commit- // sequence re-stamped the element from source after the size-only persist- // but before the offset persist landed — that one frame (new size, old- // offset) was the release "jump". SE has no anchor member → size only.+ // Save size and center-preserving offset together under one undo entry.const member = g.pathOffsetMember;const anchor = g.lastResizeAnchor;const finalOffset =@@ -554,8 +536,14 @@ export function createDomEditOverlayGestureHandlers(opts: UseDomEditOverlayGestu}};+ /** `dropQueued`: released presses still waiting go too, as when the overlay leaves or turns read-only. */// fallow-ignore-next-line complexity- const clearPointerState = (selectionRef: RefObject<DomEditSelection | null>) => {+ const clearPointerState = (+ selectionRef: RefObject<DomEditSelection | null>,+ dropQueued = false,+ ) => {+ if (dropQueued) endWaitingPress();+ else endHeldPress();opts.snapGuidesRef.current = null;const groupG = opts.groupGestureRef.current;if (groupG) restoreGroupPathOffsets(groupG);@@ -586,7 +574,14 @@ export function createDomEditOverlayGestureHandlers(opts: UseDomEditOverlayGestuopts.blockedMoveRef.current = null;opts.groupGestureRef.current = null;opts.gestureRef.current = null;- opts.rafPausedRef.current = false;+ opts.rafPausedRef.current = opts.waitingPressRef.current !== null;+ };++ const onLostPointerCapture = (e: React.PointerEvent<HTMLDivElement>) => {+ const waiting = opts.waitingPressRef.current;+ // Pointerup releases capture normally; the queued edit still has to land.+ if (waiting?.pointerId === e.pointerId && waiting.released) return;+ clearPointerState(opts.selectionRef);};return {@@ -595,6 +590,7 @@ export function createDomEditOverlayGestureHandlers(opts: UseDomEditOverlayGestustartBlockedMove,onPointerMove,onPointerUp,+ onLostPointerCapture,clearPointerState,};}diff --git a/packages/studio/src/components/nle/NLEContext.test.ts b/packages/studio/src/components/nle/NLEContext.test.tsindex 591acf3861..e33cbf610c 100644--- a/packages/studio/src/components/nle/NLEContext.test.ts+++ b/packages/studio/src/components/nle/NLEContext.test.ts@@ -5,6 +5,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";import { shouldDisableTimelineWhileCompositionLoading, NLEProvider } from "./NLEContext";import { useAssetPreviewStore } from "../../utils/assetPreviewStore";import { installReactActEnvironment } from "../../hooks/domSelectionTestHarness";+import { isPreviewChanging, requestPreviewReload } from "../../player/previewReloading";installReactActEnvironment();@@ -143,3 +144,28 @@ describe("NLEProvider — composition source-map scoping", () => {host.remove();});});++describe("NLEProvider — a requested reload", () => {+ beforeEach(() => {+ vi.stubGlobal(+ "fetch",+ vi.fn(() => Promise.reject(new Error("no network in tests"))),+ );+ });++ afterEach(() => {+ vi.unstubAllGlobals();+ });++ it("stops counting as a preview change once the refresh begins, so later presses do not wait", async () => {+ const { host, root } = await mountNleProvider({ projectId: "p", refreshKey: 0 });+ requestPreviewReload();+ expect(isPreviewChanging()).toBe(true);++ await renderNleProvider(root, { projectId: "p", refreshKey: 1 });+ expect(isPreviewChanging()).toBe(false);++ act(() => root.unmount());+ host.remove();+ });+});diff --git a/packages/studio/src/components/nle/NLEContext.tsx b/packages/studio/src/components/nle/NLEContext.tsxindex 9528368c16..a2eaf5cbfb 100644--- a/packages/studio/src/components/nle/NLEContext.tsx+++ b/packages/studio/src/components/nle/NLEContext.tsx@@ -10,6 +10,7 @@ import { ensureMotionPathPluginLoaded } from "../../utils/gsapSoftReload";import { useAssetPreviewStore } from "../../utils/assetPreviewStore";import { createStableContext } from "../../utils/hmrStableContext";import { studioApiFetch } from "../../utils/studioApiFetch";+import { previewReloadBegun } from "../../player/previewReloading";export function shouldDisableTimelineWhileCompositionLoading(compositionLoading: boolean): boolean {return compositionLoading;@@ -130,9 +131,13 @@ export function NLEProvider({// Lightweight reload: change iframe src instead of destroying the Player.const prevRefreshKeyRef = useRef(refreshKey);useEffect(() => {- if (refreshKey === prevRefreshKeyRef.current) return;- prevRefreshKeyRef.current = refreshKey;- refreshPlayer();+ try {+ if (refreshKey === prevRefreshKeyRef.current) return;+ prevRefreshKeyRef.current = refreshKey;+ refreshPlayer();+ } finally {+ previewReloadBegun();+ }}, [refreshKey, refreshPlayer]);// Steps that follow every load of the live iframe, including a reload promoted in place.diff --git a/packages/studio/src/hooks/draggedGsapPosition.ts b/packages/studio/src/hooks/draggedGsapPosition.tsindex 8d496ed78e..de84f55b31 100644--- a/packages/studio/src/hooks/draggedGsapPosition.ts+++ b/packages/studio/src/hooks/draggedGsapPosition.ts@@ -1,4 +1,5 @@import { roundTo3 } from "../utils/rounding";+import { STUDIO_EDIT_MOMENT_ATTR, type EditMoment } from "../components/editor/manualEditsTypes";/*** Drag → GSAP position math, shared by the commit path@@ -41,6 +42,7 @@ export interface DragStamp {origY: number;baseX: number;baseY: number;+ at?: EditMoment;frozen?: boolean;}@@ -52,9 +54,15 @@ export function readDragStamp(element: HTMLElement): DragStamp {origY: read("data-hf-drag-initial-offset-y") || 0,baseX: read("data-hf-drag-gsap-base-x"),baseY: read("data-hf-drag-gsap-base-y"),+ at: readEditMoment(element),};}+function readEditMoment(element: HTMLElement): EditMoment | undefined {+ const raw = element.getAttribute(STUDIO_EDIT_MOMENT_ATTR);+ return raw ? (JSON.parse(raw) as EditMoment) : undefined;+}+/** A gesture's stamp read at its release, for commits that finish after the next gesture re-stamps the element. */export const freezeDragStamp = (element: HTMLElement): DragStamp => ({...readDragStamp(element),diff --git a/packages/studio/src/hooks/editMoment.ts b/packages/studio/src/hooks/editMoment.tsnew file mode 100644index 0000000000..6417b10f57--- /dev/null+++ b/packages/studio/src/hooks/editMoment.ts@@ -0,0 +1,13 @@+import { usePlayerStore } from "../player/store/playerStore";+import type { EditMoment } from "../components/editor/manualEditsTypes";+import type { DragStamp } from "./draggedGsapPosition";++export function playheadMoment(): EditMoment {+ const { currentTime, activeKeyframePct } = usePlayerStore.getState();+ return { time: currentTime, keyframePct: activeKeyframePct };+}++/** The playhead an edit writes at: its gesture's press, else the playhead now. */+export function editMoment(stamp?: DragStamp): EditMoment {+ return stamp?.at ?? playheadMoment();+}diff --git a/packages/studio/src/hooks/gsapDragCommit.ts b/packages/studio/src/hooks/gsapDragCommit.tsindex 9efd5190ce..59c6e574a8 100644--- a/packages/studio/src/hooks/gsapDragCommit.ts+++ b/packages/studio/src/hooks/gsapDragCommit.ts@@ -56,8 +56,9 @@ function newTweenTarget(selection: DomEditSelection): string | null {export function computeCurrentPercentage(selection: DomEditSelection,animation?: GsapAnimation,+ time = usePlayerStore.getState().currentTime,): number {- return computeElementPercentage(usePlayerStore.getState().currentTime, selection, animation);+ return computeElementPercentage(time, selection, animation);}// When a drag edits a SELECTED keyframe, park the playhead on that keyframe's exactdiff --git a/packages/studio/src/hooks/gsapDragPositionCommit.ts b/packages/studio/src/hooks/gsapDragPositionCommit.tsindex b4b0fd5789..8a02e199d2 100644--- a/packages/studio/src/hooks/gsapDragPositionCommit.ts+++ b/packages/studio/src/hooks/gsapDragPositionCommit.ts@@ -21,6 +21,8 @@ import {} from "./gsapDragCommit";import type { GsapEditOutcome } from "./gsapEditOutcome";import { commitValueAtPlayhead, planValueEdit } from "./gsapValueAtPlayhead";+import { editMoment } from "./editMoment";+import type { EditMoment } from "../components/editor/manualEditsTypes";/*** The tween's keyframes with one inserted at `percentage`. Any existing keyframe@@ -95,6 +97,7 @@ export function gsapPositionFromDragOutcome(studioOffset: { x: number; y: number },gsapPos: { x: number; y: number },iframe: HTMLIFrameElement | null,+ moment?: EditMoment,): GsapEditOutcome {if (anim.arcPath?.enabled) return { status: "persisted" };const { newX, newY, baseGsapX, baseGsapY } = computeDraggedGsapPosition(@@ -104,6 +107,7 @@ export function gsapPositionFromDragOutcome();const plan = planValueEdit(selection, anim, { x: newX, y: newY }, iframe, {backfill: { x: baseGsapX, y: baseGsapY },+ moment,});return plan.ok? { status: "persisted" }@@ -132,7 +136,8 @@ export async function commitGsapPositionFromDrag(const restoreOffset = () => restoreDragOffset(el, stamp);if (anim.arcPath?.enabled) {- const { activeKeyframePct, currentTime, setActiveKeyframePct } = usePlayerStore.getState();+ const { keyframePct: activeKeyframePct, time: currentTime } = editMoment(stamp);+ const { setActiveKeyframePct } = usePlayerStore.getState();const tweenStart = resolveTweenStart(anim);const tweenDuration = resolveTweenDuration(anim);if (@@ -165,7 +170,7 @@ export async function commitGsapPositionFromDrag();return { status: "persisted" };}- const pct = activeKeyframePct ?? computeCurrentPercentage(selection, anim);+ const pct = activeKeyframePct ?? computeCurrentPercentage(selection, anim, currentTime);const keyframes = anim.keyframes?.keyframes ?? [];// A drag counts as on a waypoint when it plays within KEYFRAME_PCT_MATCH of it,// so landing a fraction of a percent off an authored waypoint updates that point@@ -212,9 +217,16 @@ export async function commitGsapPositionFromDrag();return { status: "persisted" };}- return commitValueAtPlayhead(selection, anim, { x: newX, y: newY }, iframe, callbacks, {- label: "Move layer",- backfill: { x: baseGsapX, y: baseGsapY },- beforeReload: restoreOffset,- });+ return commitValueAtPlayhead(+ selection,+ anim,+ { x: newX, y: newY },+ iframe,+ { ...callbacks, stamp },+ {+ label: "Move layer",+ backfill: { x: baseGsapX, y: baseGsapY },+ beforeReload: restoreOffset,+ },+ );}diff --git a/packages/studio/src/hooks/gsapPositionDetection.ts b/packages/studio/src/hooks/gsapPositionDetection.tsindex 39105a6ee2..854218976b 100644--- a/packages/studio/src/hooks/gsapPositionDetection.ts+++ b/packages/studio/src/hooks/gsapPositionDetection.ts@@ -44,9 +44,9 @@ function animHasPosition(anim: GsapAnimation): boolean {export function findGsapPositionAnimation(animations: GsapAnimation[],selector?: string,+ currentTime = usePlayerStore.getState().currentTime,): GsapAnimation | null {if (animations.length === 0) return null;- const currentTime = usePlayerStore.getState().currentTime;const scored = animations.filter(animHasPosition).map((a) => {let score = 0;@@ -87,9 +87,11 @@ function statesValueAt(anim: GsapAnimation, time: number): boolean {* playhead (the later one, which renders, if both do), then most keyframes.*/// fallow-ignore-next-line complexity-export function pickClosestToPlayhead(anims: GsapAnimation[]): GsapAnimation | null {+export function pickClosestToPlayhead(+ anims: GsapAnimation[],+ ct = usePlayerStore.getState().currentTime,+): GsapAnimation | null {if (anims.length <= 1) return anims[0] ?? null;- const ct = usePlayerStore.getState().currentTime;return anims.reduce((best, a) => {const dist = playheadDistance(a, ct);const bestDist = playheadDistance(best, ct);diff --git a/packages/studio/src/hooks/gsapResizeIntercept.ts b/packages/studio/src/hooks/gsapResizeIntercept.tsindex 920ad0bfa3..5b0e3f5dc3 100644--- a/packages/studio/src/hooks/gsapResizeIntercept.ts+++ b/packages/studio/src/hooks/gsapResizeIntercept.ts@@ -33,6 +33,7 @@ import {type DragStamp,} from "./draggedGsapPosition";import { pickClosestToPlayhead, readGsapPositionFromIframe } from "./gsapPositionDetection";+import { editMoment } from "./editMoment";import { commitWholePropertyOffset } from "./gsapWholePropertyOffsetCommit";import { commitGsapPositionFromDrag } from "./gsapDragPositionCommit";import { resolveTweenDuration } from "../utils/globalTimeCompiler";@@ -141,8 +142,9 @@ function firstSizeKey(size: { width: number; height: number },resizeGroup: PropertyGroupName,animations: GsapAnimation[],+ currentTime: number,): Record<string, unknown> | null {- const { autoKeyframeEnabled, currentTime } = usePlayerStore.getState();+ const { autoKeyframeEnabled } = usePlayerStore.getState();const keyframed = animations.some((a) => a.keyframes && animationWritesAnyProperty(a, MOVED_OR_SIZED),);@@ -180,6 +182,7 @@ export async function tryGsapResizeIntercept(draw: <T>(run: () => T) => T = (run) => run(),stamp?: DragStamp,): Promise<GsapEditOutcome> {+ const moment = editMoment(stamp);const fetchedAnimations = fetchFallbackAnimations ? await fetchFallbackAnimations() : [];const outcome = preflightGsapResizeIntercept(selection, animations, iframe, fetchedAnimations);if (outcome.status === "blocked") return outcome;@@ -199,6 +202,7 @@ export async function tryGsapResizeIntercept(selection,commitMutation,postSplitFetch,+ moment.time,);const anim =@@ -218,7 +222,7 @@ export async function tryGsapResizeIntercept(animationWritesAnyProperty(a, SIZE_PROPS),);if (!scriptWritesSize) {- const firstKey = firstSizeKey(selection, sized, resizeGroup, workingAnimations);+ const firstKey = firstSizeKey(selection, sized, resizeGroup, workingAnimations, moment.time);if (!firstKey) return { status: "element-size" };await commitMutation(selection, firstKey, { label: "Resize", softReload: true });return handOverDraftSize(selection, { status: "persisted" }, sized, draw);@@ -249,6 +253,7 @@ export async function tryGsapResizeIntercept(resolveTweenDuration(a) > 0 &&animationWritesAnyProperty(a, resizeProperties),),+ moment.time,);if (animatedTween) {logResize("intercept-route", { route: "keyframed-size", tweenId: animatedTween.id });@@ -284,8 +289,9 @@ export async function tryGsapResizeIntercept(return { status: "blocked", reason: "source-uneditable", detail: "zero-duration-tween" };}- const { activeKeyframePct, setActiveKeyframePct } = usePlayerStore.getState();- const pct = activeKeyframePct ?? computeCurrentPercentage(selection, anim);+ const { setActiveKeyframePct } = usePlayerStore.getState();+ const activeKeyframePct = moment.keyframePct;+ const pct = activeKeyframePct ?? computeCurrentPercentage(selection, anim, moment.time);const selector = selectorFromSelection(selection);let resizeProps: Record<string, number>;@@ -473,6 +479,7 @@ export async function tryGsapResizeIntercept(currentAnimations.filter((a) => a.propertyGroup === "position" && !isInstantHold(a) && resolveTweenDuration(a) > 0,),+ moment.time,);if (positionTween) {logResize("scale-finalize", { route: "position-keyframe", tweenId: positionTween.id });diff --git a/packages/studio/src/hooks/gsapRuntimeBridge.ts b/packages/studio/src/hooks/gsapRuntimeBridge.tsindex b071e0f910..8abb258470 100644--- a/packages/studio/src/hooks/gsapRuntimeBridge.ts+++ b/packages/studio/src/hooks/gsapRuntimeBridge.ts@@ -31,7 +31,9 @@ import { tweenReach, tweensForThisElement } from "./gsapTweenReach";import { resolveTweenDuration } from "../utils/globalTimeCompiler";import { roundTo3 } from "../utils/rounding";import type { GsapDragCommitCallbacks } from "./gsapDragCommit";-import type { DragStamp } from "./draggedGsapPosition";+import { readDragStamp, type DragStamp } from "./draggedGsapPosition";+import { editMoment } from "./editMoment";+import type { EditMoment } from "../components/editor/manualEditsTypes";import { isInstantHold, selectorFromSelection, writeTargetSelector } from "./gsapShared";import {findGsapPositionAnimation,@@ -66,12 +68,13 @@ export async function resolveGroupTween(_selection: DomEditSelection,_commitMutation: GsapDragCommitCallbacks["commitMutation"],fetchFallbackAnimations?: () => Promise<GsapAnimation[]>,+ time?: number,): Promise<{ anim: GsapAnimation; animations: GsapAnimation[] } | null> {const inGroup = (list: GsapAnimation[]) => {const tagged = list.filter((a) => a.propertyGroup === group);const props = new Set(PROPERTY_GROUPS[group]);const mixed = list.filter((a) => !a.propertyGroup && animationWritesAnyProperty(a, props));- return pickClosestToPlayhead(tagged.length > 0 ? tagged : mixed);+ return pickClosestToPlayhead(tagged.length > 0 ? tagged : mixed, time);};const anim = inGroup(animations);if (anim) return { anim, animations };@@ -205,6 +208,7 @@ async function planDrag(allAnimations: GsapAnimation[],iframe: HTMLIFrameElement | null,options: { altKey?: boolean },+ moment: EditMoment,): Promise<GsapEditOutcome> {const selector = selectorFromSelection(selection);if (!selector) return { status: "blocked", reason: "no-selector" };@@ -213,8 +217,15 @@ async function planDrag(const animations = keeper? own.filter((a) => a === keeper || !isPositionWriteOf(selector)(a)): own;- const resolved = await resolveGroupTween("position", animations, selection, async () => {});- const posAnim = resolved?.anim ?? findGsapPositionAnimation(animations, selector);+ const resolved = await resolveGroupTween(+ "position",+ animations,+ selection,+ async () => {},+ undefined,+ moment.time,+ );+ const posAnim = resolved?.anim ?? findGsapPositionAnimation(animations, selector, moment.time);const route = dragRoute(posAnim, iframe, selector, options.altKey);if (route === "static") return { status: "persisted" };if (!posAnim) {@@ -227,7 +238,7 @@ async function planDrag(: { status: "persisted" };}const gsapPos = readGsapPositionFromIframe(iframe, selector) ?? { x: 0, y: 0 };- return gsapPositionFromDragOutcome(selection, posAnim, offset, gsapPos, iframe);+ return gsapPositionFromDragOutcome(selection, posAnim, offset, gsapPos, iframe, moment);}/** Commits a drag through the GSAP script. Callers reject `blocked` (the gesture layer@@ -247,6 +258,9 @@ export async function tryGsapDragIntercept(stamp?: DragStamp;},): Promise<GsapEditOutcome> {+ const stamp = options?.stamp ?? readDragStamp(selection.element);+ const moment = editMoment(stamp);+ const time = moment.time;if (!options?.preflightPassed) {const preflight = await preflightGsapDragIntercept(selection,@@ -258,7 +272,7 @@ export async function tryGsapDragIntercept(if (preflight.status !== "persisted") return preflight;if (options?.preflightOnly) {return options.group- ? planDrag(selection, offset, allAnimations, iframe, options)+ ? planDrag(selection, offset, allAnimations, iframe, options, moment): preflight;}}@@ -302,16 +316,17 @@ export async function tryGsapDragIntercept(selection,commitMutation,fetchFallbackAnimations,+ time,);let posAnim = resolved?.anim ?? null;let resolvedAnimations = resolved?.animations ?? workingAnimations;if (!posAnim) {- posAnim = findGsapPositionAnimation(workingAnimations, selector);+ posAnim = findGsapPositionAnimation(workingAnimations, selector, time);if (!posAnim && fetchFallbackAnimations) {const fresh = await fetchFallbackAnimations();resolvedAnimations = fresh;- posAnim = findGsapPositionAnimation(fresh, selector);+ posAnim = findGsapPositionAnimation(fresh, selector, time);}}@@ -349,13 +364,14 @@ export async function tryGsapDragIntercept(a.propertyGroup === posAnim!.propertyGroup &&isXYPositionWrite(a) === isXYPositionWrite(posAnim!),),+ time,);if (freshMatch && freshMatch.id !== posAnim.id) {posAnim = freshMatch;}}- const cbs = { commitMutation, fetchAnimations: fetchFallbackAnimations, stamp: options?.stamp };+ const cbs = { commitMutation, fetchAnimations: fetchFallbackAnimations, stamp };if (route === "whole-path") {await commitWholePathOffset(selection, posAnim, offset, gsapPos, iframe, selector, cbs);} else {@@ -412,7 +428,9 @@ export async function tryGsapRotationIntercept(iframe: HTMLIFrameElement | null,commitMutation: GsapDragCommitCallbacks["commitMutation"],fetchFallbackAnimations?: () => Promise<GsapAnimation[]>,+ stamp?: DragStamp,): Promise<GsapEditOutcome> {+ const time = editMoment(stamp).time;const fetchedAnimations = fetchFallbackAnimations ? await fetchFallbackAnimations() : [];const outcome = preflightGsapRotationIntercept(selection, animations, iframe, fetchedAnimations);if (outcome.status === "blocked") return outcome;@@ -429,6 +447,7 @@ export async function tryGsapRotationIntercept(selection,commitMutation,postSplitFetch,+ time,);const resolvedAnimations = resolved?.animations ?? workingAnimations;@@ -440,6 +459,7 @@ export async function tryGsapRotationIntercept(if (!anim) {anim = pickClosestToPlayhead(workingAnimations.filter((a) => animationWritesAnyProperty(a, ROTATION_CHANNEL_SET)),+ time,);}@@ -462,7 +482,7 @@ export async function tryGsapRotationIntercept(return { status: "persisted" };}- const pct = computeCurrentPercentage(selection, anim);+ const pct = computeCurrentPercentage(selection, anim, time);// With auto-keyframe off (#1808), a rotation tween already exists for this// element (checked above) so nudge it as a whole rather than adding a@@ -485,7 +505,7 @@ export async function tryGsapRotationIntercept(anim,{ rotation: newRotation },iframe,- { commitMutation, fetchAnimations: fetchFallbackAnimations },+ { commitMutation, fetchAnimations: fetchFallbackAnimations, stamp },{ label: "Rotate", backfill: { rotation: newRotation }, holdFromStart: true },);}diff --git a/packages/studio/src/hooks/gsapValueAtPlayhead.test.ts b/packages/studio/src/hooks/gsapValueAtPlayhead.test.tsindex 667e75b956..02e73ac2eb 100644--- a/packages/studio/src/hooks/gsapValueAtPlayhead.test.ts+++ b/packages/studio/src/hooks/gsapValueAtPlayhead.test.ts@@ -8,6 +8,7 @@ import { boxSteps, liveTween, previewWith, tween } from "./gsapParsedTween.test-import { tryGsapResizeIntercept } from "./gsapResizeIntercept";import { tryGsapDragIntercept, tryGsapRotationIntercept } from "./gsapRuntimeBridge";import { planValueAtPlayhead, planValueEdit, type PlayheadEdit } from "./gsapValueAtPlayhead";+import { STUDIO_EDIT_MOMENT_ATTR } from "../components/editor/manualEditsTypes";let el: HTMLElement;let selection: DomEditSelection;@@ -181,6 +182,20 @@ describe("a move on a GSAP-animated layer, at the playhead", () => {]);});+ it("keys the time the drag was pressed at, wherever the playhead is when it commits", async () => {+ const { keys, live } = boxSteps([+ [2, { x: 60 }],+ [1, { x: 120 }],+ ]);+ el.setAttribute(STUDIO_EDIT_MOMENT_ATTR, JSON.stringify({ time: 1, keyframePct: null }));+ const { mutations } = await drag([keys], [live(el)], { time: 2, base: [30, 0], dx: 10 });+ expect(mutations[0].keyframes[0]).toEqual({+ percentage: 33.333,+ properties: { x: 40, y: 0 },+ ease: "none",+ });+ });+it("never writes x and y into a tween that only animates size", async () => {const size = tween({id: "#box-to-0-size",diff --git a/packages/studio/src/hooks/gsapValueAtPlayhead.ts b/packages/studio/src/hooks/gsapValueAtPlayhead.tsindex 083cc8f45a..9748a62588 100644--- a/packages/studio/src/hooks/gsapValueAtPlayhead.ts+++ b/packages/studio/src/hooks/gsapValueAtPlayhead.ts@@ -1,6 +1,8 @@import type { GsapAnimation } from "@hyperframes/core/gsap-parser";import type { DomEditSelection } from "../components/editor/domEditingTypes";import { usePlayerStore } from "../player/store/playerStore";+import type { EditMoment } from "../components/editor/manualEditsTypes";+import { editMoment, playheadMoment } from "./editMoment";import { resolveTweenDuration, resolveTweenStart } from "../utils/globalTimeCompiler";import { ARRAY_STEP_EASE, PERCENTAGE_SEGMENT_EASE, runEaseOf } from "../utils/gsapKeyframeEases";import { roundTo3 } from "../utils/rounding";@@ -287,11 +289,15 @@ export function planValueEdit(anim: GsapAnimation,values: Record<string, number>,iframe: HTMLIFrameElement | null,- { backfill, holdFromStart }: Pick<PlayheadEdit, "backfill" | "holdFromStart"> = {},+ {+ backfill,+ holdFromStart,+ moment = playheadMoment(),+ }: Pick<PlayheadEdit, "backfill" | "holdFromStart"> & { moment?: EditMoment } = {},): PlayheadEditPlan {// One keyframe of a tween its siblings share would move them all.if (tweenReach(anim, selection.element) === "shared") return refuse("shared-tween");- const { activeKeyframePct, currentTime } = usePlayerStore.getState();+ const { keyframePct: activeKeyframePct, time: currentTime } = moment;const tween = findParsedTween(iframe, selection.element, anim);const timed = withExactStepTimes(anim, tween);return planValueAtPlayhead({@@ -321,11 +327,12 @@ export async function commitValueAtPlayhead(},): Promise<GsapEditOutcome> {await materializeIfDynamic(anim, iframe, callbacks.commitMutation, selection);- const { activeKeyframePct, setActiveKeyframePct } = usePlayerStore.getState();+ const moment = editMoment(callbacks.stamp);+ const { setActiveKeyframePct } = usePlayerStore.getState();const tween = findParsedTween(iframe, selection.element, anim);const parkAt =- activeKeyframePct == null ? null : exactKeyframePct(anim, tween, activeKeyframePct);- const plan = planValueEdit(selection, anim, values, iframe, options);+ moment.keyframePct == null ? null : exactKeyframePct(anim, tween, moment.keyframePct);+ const plan = planValueEdit(selection, anim, values, iframe, { ...options, moment });if (!plan.ok) return { status: "blocked", reason: "keyframes-uneditable", detail: plan.reason };await callbacks.commitMutation(selection, plan.mutation, {label: options.label,diff --git a/packages/studio/src/hooks/useDomSelection.test.ts b/packages/studio/src/hooks/useDomSelection.test.tsindex 27c0b0c4b0..1f65bfd51e 100644--- a/packages/studio/src/hooks/useDomSelection.test.ts+++ b/packages/studio/src/hooks/useDomSelection.test.ts@@ -22,7 +22,7 @@ interface TimelineSpies {function renderHarness(initialProps: HarnessProps,- options: { timelineElements?: TimelineElement[] } = {},+ options: { timelineElements?: TimelineElement[]; previewDoc?: Document } = {},): {current: () => ReturnType<typeof useDomSelection>;rerender: (props: HarnessProps) => void;@@ -49,7 +49,11 @@ function renderHarness(isMasterView: false,compIdToSrc: new Map(),captionEditMode: false,- previewIframeRef: { current: null },+ previewIframeRef: {+ current: options.previewDoc+ ? ({ contentDocument: options.previewDoc } as HTMLIFrameElement)+ : null,+ },timelineElements: options.timelineElements ?? [],getTimelineSelectionSet: () => publishedSet,setSelectedTimelineElementId: timeline.setSelectedTimelineElementId,@@ -307,6 +311,21 @@ describe("useDomSelection", () => {harness.cleanup();});+ it("drops the selection when the reloaded preview no longer has its element", async () => {+ const selection = makeSelection("Headline", document.createElement("div"));+ const harness = renderHarness(+ { activeCompPath: "index.html", projectId: "project-1", refreshKey: 0 },+ { previewDoc: document.implementation.createHTMLDocument("") },+ );+ act(() => harness.current().applyDomSelection(selection));++ await act(() => harness.current().refreshDomEditSelectionFromPreview(selection));++ expect(harness.current().domEditSelection).toBeNull();+ expect(harness.timeline.setSelectedTimelineElementId).toHaveBeenLastCalledWith(null);+ harness.cleanup();+ });+it("clears a committed selection when the active composition path changes", () => {const { selection, harness } = setupSelectedHarness();expect(harness.current().domEditSelection).toBe(selection);diff --git a/packages/studio/src/hooks/useEditHistoryActions.test.tsx b/packages/studio/src/hooks/useEditHistoryActions.test.tsxindex 4271a188d9..019a0d8f09 100644--- a/packages/studio/src/hooks/useEditHistoryActions.test.tsx+++ b/packages/studio/src/hooks/useEditHistoryActions.test.tsx@@ -9,6 +9,7 @@ import {beginStudioPendingEdit,isStudioEditSaving,setStudioPendingEditClaimClock,+ setStudioWaitingPressCancel,trackStudioPendingEdit,} from "../utils/studioPendingEdits";@@ -18,6 +19,7 @@ let root: Root | null = null;afterEach(() => {act(() => root?.unmount());setStudioPendingEditClaimClock(null);+ setStudioWaitingPressCancel(null);});type RestoreFiles = Record<string, { previous: string; restored: string }>;@@ -71,6 +73,24 @@ const PREDICTED = { id: "e1", files: { "index.html": { previous: "B", restored:const SERVER_FILES = { "index.html": { previous: "B", restored: "A2" } };describe("useEditHistoryActions", () => {+ it("takes back a canvas press still waiting to run, with no history step", async () => {+ const { deps, actions } = mount({ ok: true, label: "Undid: Move" });+ const cancel = vi.fn(() => (setStudioWaitingPressCancel(null), true));+ setStudioWaitingPressCancel(cancel);+ const revert = vi.fn(() => () => {});+ const saving = beginStudioPendingEdit(revert);+ await act(() => actions.redo());+ expect(cancel, "redo leaves the press").not.toHaveBeenCalled();+ await act(() => actions.undo());+ expect(cancel).toHaveBeenCalledTimes(1);+ expect(revert, "the press is newer than any edit still saving").not.toHaveBeenCalled();+ expect(deps.editHistory.undo).not.toHaveBeenCalled();++ await act(() => actions.undo());+ expect(revert, "the following Cmd+Z takes back the edit still saving").toHaveBeenCalledTimes(1);+ saving.settle();+ });+it("asks for the edit claimed after the key's claim count only when an edit was saving at the key", async () => {const { deps, actions } = mount({ ok: false, reason: "empty" });await act(() => actions.undo());diff --git a/packages/studio/src/hooks/useEditHistoryActions.ts b/packages/studio/src/hooks/useEditHistoryActions.tsindex 2e4655c5c9..73cb4c7327 100644--- a/packages/studio/src/hooks/useEditHistoryActions.ts+++ b/packages/studio/src/hooks/useEditHistoryActions.ts@@ -5,6 +5,7 @@ import { serializeStudioFileMutations } from "../utils/studioFileMutationCoordinimport type { RestoreFiles } from "../utils/gsapUndoRestore";import {beginStudioShownRestore,+ cancelNewestStudioWaitingPress,hasStudioPendingEdits,paintBackNewestStudioPendingEdit,} from "../utils/studioPendingEdits";@@ -79,6 +80,7 @@ export function useEditHistoryActions({const apply = useCallback(async (direction: "undo" | "redo") => {const noun = direction === "undo" ? "Undo" : "Redo";+ if (direction === "undo" && cancelNewestStudioWaitingPress()) return;// An edit still saving is newer than any step this tab predicts, so it paints back first.const pendingEditShown = direction === "undo" ? paintBackNewestStudioPendingEdit() : null;const predicted = pendingEditShown ? null : (editHistory.predict?.(direction) ?? null);diff --git a/packages/studio/src/hooks/useGsapAwareEditing.test.tsx b/packages/studio/src/hooks/useGsapAwareEditing.test.tsxindex 5775316e76..c08d59ed24 100644--- a/packages/studio/src/hooks/useGsapAwareEditing.test.tsx+++ b/packages/studio/src/hooks/useGsapAwareEditing.test.tsx@@ -42,6 +42,7 @@ vi.mock("./useSafeGsapCommitMutation", () => ({}));import { useGsapAwareEditing } from "./useGsapAwareEditing";+import { isPreviewChanging } from "../player/previewReloading";import { tryGsapRotationIntercept } from "./gsapRuntimeBridge";afterEach(() => {@@ -235,6 +236,43 @@ describe("useGsapAwareEditing keeps the route a gesture chose at press", () => {});});+describe("useGsapAwareEditing holds a canvas press while a drop saves", () => {+ it.each([+ ["a move through the script", false, "move"],+ ["a group move through the script", false, "group"],+ ["a move saved as CSS", true, "move"],+ ])("%s", async (_, plainTranslate, kind) => {+ let land: () => void = () => {};+ const landed = new Promise<void>((resolve) => (land = resolve));+ mocks.drag.mockImplementation(async () => {+ await landed;+ return { status: "persisted" };+ });+ const save = vi.fn().mockReturnValue(landed);+ const stageElementPositionOffset = vi.fn(() => ({ save, rollback: vi.fn() }));+ const { pathOffsetCommit, groupCommit, root } = mountGroupHandler({+ stageElementPositionOffset,+ });+ const box = { element: document.createElement("div"), id: "box", selector: "#box" };+ const selection = box as unknown as DomEditSelection;+ const to = { x: 40, y: 20 };+ let saved!: Promise<unknown>;+ act(() => {+ saved =+ kind === "group"+ ? groupCommit([{ selection, next: to, plainTranslate }])+ : pathOffsetCommit(selection, to, { plainTranslate });+ });+ expect(isPreviewChanging(), "from the drop").toBe(!plainTranslate);+ await act(async () => {+ land();+ await saved;+ });+ expect(isPreviewChanging()).toBe(false);+ act(() => root.unmount());+ });+});+describe("useGsapAwareEditing keeps the box route a resize chose at press", () => {it.each([["the CSS route, on an element GSAP has since taken over", true],diff --git a/packages/studio/src/hooks/useGsapAwareEditing.ts b/packages/studio/src/hooks/useGsapAwareEditing.tsindex d0bd73c18f..11f992667c 100644--- a/packages/studio/src/hooks/useGsapAwareEditing.ts+++ b/packages/studio/src/hooks/useGsapAwareEditing.ts@@ -17,6 +17,7 @@ import type { DomEditSelection } from "../components/editor/domEditingTypes";import { tryGsapDragIntercept, tryGsapRotationIntercept } from "./gsapRuntimeBridge";import { tryGsapResizeIntercept } from "./gsapResizeIntercept";import { computeDraggedGsapPosition, freezeDragStamp } from "./draggedGsapPosition";+import { whileScriptWrites } from "../player/previewReloading";import { readGsapPositionFromIframe } from "./gsapPositionDetection";import { selectorFromSelection } from "./gsapShared";import { useAnimatedPropertyCommit } from "./useAnimatedPropertyCommit";@@ -153,7 +154,10 @@ export function useGsapAwareEditing({const result = await stageElementPositionOffset(selection, next, true).save();return writes.finish(result?.changed === true);}- if (writes.commit) {+ const writer = writes.commit;+ if (!writer) return;+ return whileScriptWrites(async () => {+ const stamp = freezeDragStamp(selection.element);try {const ownedAnimations = getGsapAnimationsForSelection(selection);const targetAnimations = Array.isArray(ownedAnimations)@@ -164,9 +168,9 @@ export function useGsapAwareEditing({next,targetAnimations,previewIframeRef.current,- writes.commit,+ writer,makeFetchFallback(selection),- modifiers,+ { ...modifiers, stamp },);await saveMove(outcome, async () => {const staged = writes.drawKeepingUndone(() =>@@ -179,7 +183,7 @@ export function useGsapAwareEditing({trackGsapInteractionFailure(error, selection, "drag", "Move animated layer");throw error;}- }+ });},[gsapCommitMutation,@@ -209,149 +213,153 @@ export function useGsapAwareEditing({restore: () => void = () => undefined,route?: { plainTranslate: boolean },) => {- const stamp = freezeDragStamp(selection.element);const writes = observeGsapGesture(gsapCommitMutation);if (route?.plainTranslate ?? editsPlainCss(selection.element, "resize")) {const result = await handleDomBoxSizeCommit(selection, next, offset, restore);return writes.finish(result?.changed === true);}- let targetAnimations: GsapAnimation[];- try {- const ownedAnimations = getGsapAnimationsForSelection(selection);- targetAnimations = Array.isArray(ownedAnimations) ? ownedAnimations : await ownedAnimations;- } catch (error) {- restore();- trackGsapInteractionFailure(error, selection, "resize", "Resize animated layer");- throw error;- }- const scaleRoute = targetAnimations.some((anim) => anim.propertyGroup === "scale");- const selector = selectorFromSelection(selection);- const hasLivePositionTween = selector- ? hasNonHoldTweenForElement(- previewIframeRef.current,- selector,- undefined,- POSITION_CHANNELS,- )- : false;- logResize("commit-route", {- next,- offset: offset ?? null,- scaleRoute,- animCount: targetAnimations.length,- animGroups: targetAnimations.map((a) => `${a.propertyGroup}:${a.method}`),- });- let anchorMove: ReturnType<typeof stageElementPositionOffset> | null = null;- const stageCrop = prepareCropResize(selection.element);- let cropUndoKey: string | null = null;- const saveResizeAnchor = async (- ownsDragOffset: boolean,- commitMutation: CommitMutation,- coalesceKey: string,- ) => {- if (offset && !ownsDragOffset) {- const dragOutcome = await tryGsapDragIntercept(- selection,- offset,- targetAnimations,- previewIframeRef.current,- commitMutation,- makeFetchFallback(selection),- { stamp },- );- // Saved after the size, under its undo key, so the two are one step.- await saveMove(dragOutcome, async () => {- const plainAfterSettle = editsPlainCss(selection.element, "move");- anchorMove = writes.drawKeepingUndone(() =>- stageElementPositionOffset(selection, offset, plainAfterSettle, coalesceKey),- );- });+ return whileScriptWrites(async () => {+ const stamp = freezeDragStamp(selection.element);+ let targetAnimations: GsapAnimation[];+ try {+ const ownedAnimations = getGsapAnimationsForSelection(selection);+ targetAnimations = Array.isArray(ownedAnimations)+ ? ownedAnimations+ : await ownedAnimations;+ } catch (error) {+ restore();+ trackGsapInteractionFailure(error, selection, "resize", "Resize animated layer");+ throw error;}- };- await runGestureTransaction({- element: selection.element,- label: "Resize layer",- draw: writes.drawKeepingUndone,- settle: () => {- // Scale resize settles its center-scale residual after the scale commit- // renders. Width/height can settle its anchored position immediately.- if (!offset || scaleRoute || !selector) return;- writes.drawKeepingUndone(() => {- const gsapPos = readGsapPositionFromIframe(previewIframeRef.current, selector) ?? {- x: 0,- y: 0,- };- const { newX, newY } = computeDraggedGsapPosition(- selection.element,+ const scaleRoute = targetAnimations.some((anim) => anim.propertyGroup === "scale");+ const selector = selectorFromSelection(selection);+ const hasLivePositionTween = selector+ ? hasNonHoldTweenForElement(+ previewIframeRef.current,+ selector,+ undefined,+ POSITION_CHANNELS,+ )+ : false;+ logResize("commit-route", {+ next,+ offset: offset ?? null,+ scaleRoute,+ animCount: targetAnimations.length,+ animGroups: targetAnimations.map((a) => `${a.propertyGroup}:${a.method}`),+ });+ let anchorMove: ReturnType<typeof stageElementPositionOffset> | null = null;+ const stageCrop = prepareCropResize(selection.element);+ let cropUndoKey: string | null = null;+ const saveResizeAnchor = async (+ ownsDragOffset: boolean,+ commitMutation: CommitMutation,+ coalesceKey: string,+ ) => {+ if (offset && !ownsDragOffset) {+ const dragOutcome = await tryGsapDragIntercept(+ selection,offset,- gsapPos,- stamp,+ targetAnimations,+ previewIframeRef.current,+ commitMutation,+ makeFetchFallback(selection),+ { stamp },);- logResize("sync-settle", { gsapPos, offset, newX, newY });- setElementGsapPosition(selection.element, newX, newY);- });- },- persist: async (commit, coalesceKey) => {- if (writes.commit) {- const commitMutation = commit(writes.commit);- try {- const outcome = await tryGsapResizeIntercept(- selection,- next,- targetAnimations,- previewIframeRef.current,- commitMutation,- makeFetchFallback(selection),+ // Saved after the size, under its undo key, so the two are one step.+ await saveMove(dragOutcome, async () => {+ const plainAfterSettle = editsPlainCss(selection.element, "move");+ anchorMove = writes.drawKeepingUndone(() =>+ stageElementPositionOffset(selection, offset, plainAfterSettle, coalesceKey),+ );+ });+ }+ };+ await runGestureTransaction({+ element: selection.element,+ label: "Resize layer",+ draw: writes.drawKeepingUndone,+ settle: () => {+ // Scale resize settles its center-scale residual after the scale commit+ // renders. Width/height can settle its anchored position immediately.+ if (!offset || scaleRoute || !selector) return;+ writes.drawKeepingUndone(() => {+ const gsapPos = readGsapPositionFromIframe(previewIframeRef.current, selector) ?? {+ x: 0,+ y: 0,+ };+ const { newX, newY } = computeDraggedGsapPosition(+ selection.element,offset,- writes.drawKeepingUndone,+ gsapPos,stamp,);- assertGsapEditPersisted(outcome);- // Saved before the buffered GSAP writes, so their reload stays the gesture's last render.- if (outcome.status === "element-size") {- const result = await writes.drawKeepingUndone(() =>- handleDomBoxSizeCommit(selection, next, undefined, undefined, coalesceKey),+ logResize("sync-settle", { gsapPos, offset, newX, newY });+ setElementGsapPosition(selection.element, newX, newY);+ });+ },+ persist: async (commit, coalesceKey) => {+ if (writes.commit) {+ const commitMutation = commit(writes.commit);+ try {+ const outcome = await tryGsapResizeIntercept(+ selection,+ next,+ targetAnimations,+ previewIframeRef.current,+ commitMutation,+ makeFetchFallback(selection),+ offset,+ writes.drawKeepingUndone,+ stamp,);- writes.recordDomResult(result);- } else cropUndoKey = coalesceKey;- // What the resize did, not what its tweens suggest: a scale hold still commits a size.- const ownsDragOffset =- outcome.status === "persisted" && outcome.ownsDragOffset === true;- logResize("intercept-handled", {- scaleRoute,- ownsDragOffset,- willForwardOffset: !!(offset && !ownsDragOffset),- });- // A resize that moved the element itself has already written- // where it landed. Everything else leaves the anchor to the drag.- await saveResizeAnchor(ownsDragOffset, commitMutation, coalesceKey);- logResizeSettle(selection.element, ownsDragOffset ? "gsap-scale" : "gsap-size");- return;- } catch (error) {- trackGsapInteractionFailure(error, selection, "resize", "Resize animated layer");- throw error;+ assertGsapEditPersisted(outcome);+ // Saved before the buffered GSAP writes, so their reload stays the gesture's last render.+ if (outcome.status === "element-size") {+ const result = await writes.drawKeepingUndone(() =>+ handleDomBoxSizeCommit(selection, next, undefined, undefined, coalesceKey),+ );+ writes.recordDomResult(result);+ } else cropUndoKey = coalesceKey;+ // What the resize did, not what its tweens suggest: a scale hold still commits a size.+ const ownsDragOffset =+ outcome.status === "persisted" && outcome.ownsDragOffset === true;+ logResize("intercept-handled", {+ scaleRoute,+ ownsDragOffset,+ willForwardOffset: !!(offset && !ownsDragOffset),+ });+ // A resize that moved the element itself has already written+ // where it landed. Everything else leaves the anchor to the drag.+ await saveResizeAnchor(ownsDragOffset, commitMutation, coalesceKey);+ logResizeSettle(selection.element, ownsDragOffset ? "gsap-scale" : "gsap-size");+ return;+ } catch (error) {+ trackGsapInteractionFailure(error, selection, "resize", "Resize animated layer");+ throw error;+ }}- }- throw new Error("Resize of a GSAP-owned box has no GSAP writer");- },- afterBufferedCommitsSaved: async () => {- const anchorResult = await anchorMove?.save();- writes.recordDomResult(anchorResult);- // Only now is the size live for every caller, drag or not.- if (cropUndoKey) {- const cropResult = await writes.drawKeepingUndone(() =>- saveCropResize(stageCrop, selection, commitPositionPatchToHtml, cropUndoKey!),- );- writes.recordDomResult(cropResult);- }- },- restore: () => {- anchorMove?.rollback();- restore();- },- skipPixelAssert: hasLivePositionTween,+ throw new Error("Resize of a GSAP-owned box has no GSAP writer");+ },+ afterBufferedCommitsSaved: async () => {+ const anchorResult = await anchorMove?.save();+ writes.recordDomResult(anchorResult);+ // Only now is the size live for every caller, drag or not.+ if (cropUndoKey) {+ const cropResult = await writes.drawKeepingUndone(() =>+ saveCropResize(stageCrop, selection, commitPositionPatchToHtml, cropUndoKey!),+ );+ writes.recordDomResult(cropResult);+ }+ },+ restore: () => {+ anchorMove?.rollback();+ restore();+ },+ skipPixelAssert: hasLivePositionTween,+ });+ return writes.finish();});- return writes.finish();},[handleDomBoxSizeCommit,@@ -372,7 +380,10 @@ export function useGsapAwareEditing({const result = await handleDomRotationCommit(selection, next);return writes.finish(result?.changed === true);}- if (writes.commit) {+ const writer = writes.commit;+ if (!writer) return;+ return whileScriptWrites(async () => {+ const stamp = freezeDragStamp(selection.element);try {const targetAnimations = await getGsapAnimationsForSelection(selection);// A keyframe or a tl.set; a computed source rejects, so the gesture restores its draft.@@ -381,8 +392,9 @@ export function useGsapAwareEditing({next.angle,targetAnimations,previewIframeRef.current,- writes.commit,+ writer,makeFetchFallback(selection),+ stamp,);assertGsapEditPersisted(outcome);return writes.finish();@@ -390,7 +402,7 @@ export function useGsapAwareEditing({trackGsapInteractionFailure(error, selection, "rotation", "Rotate animated layer");throw error;}- }+ });},[gsapCommitMutation,diff --git a/packages/studio/src/hooks/useGsapAwareGroupMove.ts b/packages/studio/src/hooks/useGsapAwareGroupMove.tsindex 1c2eae4f1c..948c1abef1 100644--- a/packages/studio/src/hooks/useGsapAwareGroupMove.ts+++ b/packages/studio/src/hooks/useGsapAwareGroupMove.ts@@ -8,8 +8,11 @@ import { observeGsapGesture } from "./gsapGestureOutcome";import { editsPlainCss } from "./gsapRuntimeKeyframes";import { refuseGsapTakeover } from "./elementOffsetStager";import { tryGsapDragIntercept } from "./gsapRuntimeBridge";+import { freezeDragStamp } from "./draggedGsapPosition";import { assertGsapEditPersisted } from "./gsapEditOutcome";import { firstPreflightFailure } from "./gsapGroupPreflight";+import { whileScriptWrites } from "../player/previewReloading";+import type { GeometryCommitResult } from "../utils/previewFeatureUsage";// A distinct key keeps consecutive group drags in separate undo entries.let groupDragCommitCounter = 0;@@ -36,131 +39,141 @@ export function useGsapAwareGroupMove({async (updates: DomEditGroupPathOffsetCommit[],options: { refusalToast?: boolean } = {},- ): Promise<import("../utils/previewFeatureUsage").GeometryCommitResult> => {+ ): Promise<GeometryCommitResult> => {const writes = observeGsapGesture(gsapCommitMutation);const writer = writes.commit;if (!writer) return { ok: true, changed: false };- const toastRefusal = options.refusalToast !== false;- // One coalesce key across slow writes keeps the group drag in one undo entry.- const coalesceKey = `group-drag:${++groupDragCommitCounter}`;- // Hold the render until every member is saved, or unwritten members snap back.- let renderOnCommit = false;- const previewFallbackLatch = { pending: false };- const withGroupOptions = (options: CommitMutationOptions): CommitMutationOptions => ({- ...options,- coalesceKey,- coalesceMs: Number.POSITIVE_INFINITY,- deferPreviewSync: !renderOnCommit,- previewFallbackLatch,- });- // Batch members in the same file to avoid repeating its read, parse, write and preview patch.- const queued: CommitMutationCall[] = [];- const flushQueued = async () => {- if (queued.length === 0) return;- const calls = queued.splice(0, queued.length);- if (!writer.batch) {- for (const call of calls) {- await writer(call.selection, call.mutation, call.options);- }- return;- }- await writer.batch(calls, {- ...(calls.at(-1)?.options ?? { label: "Move animated layer (group)" }),- label: "Move animated layer (group)",+ const scripted = updates.some(+ ({ selection, plainTranslate }) =>+ !(plainTranslate ?? editsPlainCss(selection.element, "move")),+ );+ const commitGroup = async (): Promise<GeometryCommitResult> => {+ const stamps = new Map(+ updates.map((u) => [u.selection, freezeDragStamp(u.selection.element)]),+ );+ const toastRefusal = options.refusalToast !== false;+ // One coalesce key across slow writes keeps the group drag in one undo entry.+ const coalesceKey = `group-drag:${++groupDragCommitCounter}`;+ // Hold the render until every member is saved, or unwritten members snap back.+ let renderOnCommit = false;+ const previewFallbackLatch = { pending: false };+ const withGroupOptions = (options: CommitMutationOptions): CommitMutationOptions => ({+ ...options,+ coalesceKey,+ coalesceMs: Number.POSITIVE_INFINITY,+ deferPreviewSync: !renderOnCommit,+ previewFallbackLatch,});- };- const coalescedCommit: typeof gsapCommitMutation = (selection, mutation, options) => {- queued.push({ selection, mutation, options: withGroupOptions(options) });- return Promise.resolve();- };- const preflightAnimations = new Map<DomEditSelection, GsapAnimation[]>();- // Members saved on themselves, each with its route: true for its CSS translate.- const offsetMembers = new Map<DomEditSelection, boolean>();- // Editability is user-atomic: prove every member can be written before the first source- // mutation, so a blocked member never leaves earlier siblings partially moved. Preflights- // write nothing and share one in-flight parse per file, so they run together.- const preflightResults = await Promise.allSettled(- updates.map(async ({ selection, next, plainTranslate }) => {- if (plainTranslate ?? editsPlainCss(selection.element, "move")) {- refuseGsapTakeover(selection.element, toastRefusal ? showToast : () => {});- return void offsetMembers.set(selection, true);+ // Batch members in the same file to avoid repeating its read, parse, write and preview patch.+ const queued: CommitMutationCall[] = [];+ const flushQueued = async () => {+ if (queued.length === 0) return;+ const calls = queued.splice(0, queued.length);+ if (!writer.batch) {+ for (const call of calls) {+ await writer(call.selection, call.mutation, call.options);+ }+ return;}- const animations = await makeFetchFallback(selection, { failOnFetchError: true })();- preflightAnimations.set(selection, animations);- const outcome = await tryGsapDragIntercept(- selection,- next,- animations,- previewIframeRef.current,- coalescedCommit,- undefined,- { preflightOnly: true, group: true },- );- if (outcome.status === "element-offset") offsetMembers.set(selection, false);- assertGsapEditPersisted(outcome);- }),- );- const preflightFailure = firstPreflightFailure(- preflightResults,- updates,- offsetMembers,- activeCompPath,- );- if (preflightFailure) {- trackGsapInteractionFailure(- preflightFailure.error,- preflightFailure.selection,- "drag",- "Move animated layer (group)",- toastRefusal,+ await writer.batch(calls, {+ ...(calls.at(-1)?.options ?? { label: "Move animated layer (group)" }),+ label: "Move animated layer (group)",+ });+ };+ const coalescedCommit: typeof gsapCommitMutation = (selection, mutation, options) => {+ queued.push({ selection, mutation, options: withGroupOptions(options) });+ return Promise.resolve();+ };+ const preflightAnimations = new Map<DomEditSelection, GsapAnimation[]>();+ // Members saved on themselves, each with its route: true for its CSS translate.+ const offsetMembers = new Map<DomEditSelection, boolean>();+ // Editability is user-atomic: prove every member can be written before the first source+ // mutation, so a blocked member never leaves earlier siblings partially moved. Preflights+ // write nothing and share one in-flight parse per file, so they run together.+ const preflightResults = await Promise.allSettled(+ updates.map(async ({ selection, next, plainTranslate }) => {+ if (plainTranslate ?? editsPlainCss(selection.element, "move")) {+ refuseGsapTakeover(selection.element, toastRefusal ? showToast : () => {});+ return void offsetMembers.set(selection, true);+ }+ const animations = await makeFetchFallback(selection, { failOnFetchError: true })();+ preflightAnimations.set(selection, animations);+ const outcome = await tryGsapDragIntercept(+ selection,+ next,+ animations,+ previewIframeRef.current,+ coalescedCommit,+ undefined,+ { preflightOnly: true, group: true },+ );+ if (outcome.status === "element-offset") offsetMembers.set(selection, false);+ assertGsapEditPersisted(outcome);+ }),);- throw preflightFailure.error;- }- const lastScriptWrite = updates.findLastIndex(- ({ selection }) => !offsetMembers.has(selection),- );- for (const [index, { selection, next }] of updates.entries()) {- renderOnCommit = index === lastScriptWrite;- const plain = offsetMembers.get(selection);- if (plain !== undefined) {- const staged = writes.drawKeepingUndone(() =>- stageElementPositionOffset(selection, next, plain, coalesceKey),+ const preflightFailure = firstPreflightFailure(+ preflightResults,+ updates,+ offsetMembers,+ activeCompPath,+ );+ if (preflightFailure) {+ trackGsapInteractionFailure(+ preflightFailure.error,+ preflightFailure.selection,+ "drag",+ "Move animated layer (group)",+ toastRefusal,);- const result = await staged.save();- writes.recordDomResult(result);- continue;+ throw preflightFailure.error;+ }+ const lastScriptWrite = updates.findLastIndex(+ ({ selection }) => !offsetMembers.has(selection),+ );+ for (const [index, { selection, next }] of updates.entries()) {+ renderOnCommit = index === lastScriptWrite;+ const plain = offsetMembers.get(selection);+ if (plain !== undefined) {+ const staged = writes.drawKeepingUndone(() =>+ stageElementPositionOffset(selection, next, plain, coalesceKey),+ );+ const result = await staged.save();+ writes.recordDomResult(result);+ continue;+ }+ try {+ const outcome = await tryGsapDragIntercept(+ selection,+ next,+ preflightAnimations.get(selection) ?? [],+ previewIframeRef.current,+ coalescedCommit,+ // The intercept re-reads the file to resolve a stale or shared tween.+ // Anything already queued has to be on disk before that read, or it+ // resolves against a file missing writes it is about to build on.+ async () => {+ await flushQueued();+ return makeFetchFallback(selection, { fresh: true })();+ },+ { preflightPassed: true, stamp: stamps.get(selection) },+ );+ assertGsapEditPersisted(outcome);+ } catch (error) {+ trackGsapInteractionFailure(error, selection, "drag", "Move animated layer (group)");+ throw error;+ }}try {- const outcome = await tryGsapDragIntercept(- selection,- next,- preflightAnimations.get(selection) ?? [],- previewIframeRef.current,- coalescedCommit,- // The intercept re-reads the file to resolve a stale or shared tween.- // Anything already queued has to be on disk before that read, or it- // resolves against a file missing writes it is about to build on.- async () => {- await flushQueued();- return makeFetchFallback(selection, { fresh: true })();- },- { preflightPassed: true },- );- assertGsapEditPersisted(outcome);+ await flushQueued();+ return writes.finish();} catch (error) {- trackGsapInteractionFailure(error, selection, "drag", "Move animated layer (group)");+ // The aggregate write has no uniquely failing member; do not misattribute+ // its telemetry to whichever member happened to be last in the array.+ trackGsapInteractionFailure(error, null, "drag", "Move animated layer (group)");throw error;}- }- try {- await flushQueued();- return writes.finish();- } catch (error) {- // The aggregate write has no uniquely failing member; do not misattribute- // its telemetry to whichever member happened to be last in the array.- trackGsapInteractionFailure(error, null, "drag", "Move animated layer (group)");- throw error;- }+ };+ return scripted ? whileScriptWrites(commitGroup) : commitGroup();},[gsapCommitMutation,diff --git a/packages/studio/src/hooks/useGsapScriptCommits.ts b/packages/studio/src/hooks/useGsapScriptCommits.tsindex 3082f97a2e..7838973c97 100644--- a/packages/studio/src/hooks/useGsapScriptCommits.ts+++ b/packages/studio/src/hooks/useGsapScriptCommits.ts@@ -45,6 +45,7 @@ import {useSafeGsapCommitMutation,} from "./useSafeGsapCommitMutation";import { requestGsapMutation } from "./gsapMutationClient";+import { whileScriptWrites } from "../player/previewReloading";async function mutateGsapScript(projectId: string,@@ -373,7 +374,7 @@ export function useGsapScriptCommits({ projectIdRef, activeCompPath, previewIfra});}, [projectIdRef, previewIframeRef, reloadPreview, onCacheInvalidate, onFileContentChanged, forceReloadSdkSession, recordMutationEdit]);- const runCommit = useCallback(async (pid: string, compositionPath: string | null, targetPath: string, selection: DomEditSelection, mutation: Record<string, unknown>, options: CommitMutationOptions) => {+ const runCommit = useCallback((pid: string, compositionPath: string | null, targetPath: string, selection: DomEditSelection, mutation: Record<string, unknown>, options: CommitMutationOptions) => whileScriptWrites(async () => {const result = await runMutationRequest([mutation], options, showToast, () =>mutateGsapScript(pid, "gsap-mutations", targetPath, mutation),);@@ -381,9 +382,9 @@ export function useGsapScriptCommits({ projectIdRef, activeCompPath, previewIfratrackKeyframeCommit([mutation], result, options);options.onResult?.(result);await finalizeSuccessfulMutation(pid, compositionPath, selection, mutation, targetPath, result, options);- }, [showToast, finalizeSuccessfulMutation]);+ }), [showToast, finalizeSuccessfulMutation]);- const runBatchCommit = useCallback(async (pid: string, compositionPath: string | null, targetPath: string, calls: CommitMutationCall[], options: CommitMutationOptions) => {+ const runBatchCommit = useCallback((pid: string, compositionPath: string | null, targetPath: string, calls: CommitMutationCall[], options: CommitMutationOptions) => whileScriptWrites(async () => {const first = calls[0];const last = calls.at(-1);if (!first || !last) return;@@ -402,7 +403,7 @@ export function useGsapScriptCommits({ projectIdRef, activeCompPath, previewIfraconst { instantPatch: _instantPatch, ...batchOptions } = options;const allPatched = instantPatches.length === calls.length;await finalizeSuccessfulMutation(pid, compositionPath, last.selection, last.mutation, targetPath, result, allPatched ? { ...batchOptions, instantPatches } : batchOptions);- }, [showToast, finalizeSuccessfulMutation]);+ }), [showToast, finalizeSuccessfulMutation]);// Every GSAP-script commit is a read-modify-write of one file. Overlapping// commits to the SAME file (any op type, any animation) interleave server-side,diff --git a/packages/studio/src/hooks/usePreviewPersistence.history.test.tsx b/packages/studio/src/hooks/usePreviewPersistence.history.test.tsxindex c199235714..42750b2619 100644--- a/packages/studio/src/hooks/usePreviewPersistence.history.test.tsx+++ b/packages/studio/src/hooks/usePreviewPersistence.history.test.tsx@@ -19,10 +19,11 @@ afterEach(() => {});describe("undo that reloads the preview", () => {- it("keeps the timeline's clips until the reloaded preview reports its own", async () => {+ it("keeps the timeline's clips and selection until the reloaded preview reports its own", async () => {const clips = [{ id: "a" }, { id: "b" }] as unknown as TimelineElement[];usePlayerStore.getState().setElements(clips);usePlayerStore.getState().setTimelineReady(true);+ usePlayerStore.getState().setSelectedElementId("a");const reloadPreview = vi.fn();let sync: ReturnType<typeof usePreviewPersistence>["syncHistoryPreviewAfterApply"] | null =null;@@ -46,7 +47,11 @@ describe("undo that reloads the preview", () => {expect(reloadPreview).toHaveBeenCalledTimes(1);const player = usePlayerStore.getState();- expect([player.elements, player.timelineReady]).toEqual([clips, true]);+ expect([player.elements, player.timelineReady, player.selectedElementId]).toEqual([+ clips,+ true,+ "a",+ ]);});});diff --git a/packages/studio/src/hooks/usePreviewPersistence.ts b/packages/studio/src/hooks/usePreviewPersistence.tsindex e77006882d..4f7a4ac5ce 100644--- a/packages/studio/src/hooks/usePreviewPersistence.ts+++ b/packages/studio/src/hooks/usePreviewPersistence.ts@@ -248,10 +248,7 @@ export function usePreviewPersistence({reloadPreview,nestedFiles,);- if (strategy === "full") {- usePlayerStore.getState().setSelectedElementId(null);- return;- }+ if (strategy === "full") return;// A soft restore patched the reverted attributes onto the live preview, but the// player store keeps its own copy and that copy is what the automation lanes// draw — so without this an undone envelope edit stayed invisible until adiff --git a/packages/studio/src/index.ts b/packages/studio/src/index.tsindex 1c1696b710..009f8ed09a 100644--- a/packages/studio/src/index.ts+++ b/packages/studio/src/index.ts@@ -160,6 +160,7 @@ export type {// can race a write still in flight (see useTrackPendingTimelineEdit.ts).export { flushStudioPendingEdits } from "./utils/studioPendingEdits";export { revertNewestStudioPendingEdit } from "./utils/studioPendingEdits";+export { cancelNewestStudioWaitingPress } from "./utils/studioPendingEdits";export type { StudioPendingEditsDrainResult } from "./utils/studioPendingEdits";export type {CanEditTimelineElement,diff --git a/packages/studio/src/player/hooks/useShadowPreviewReload.ts b/packages/studio/src/player/hooks/useShadowPreviewReload.tsindex 7856d1c635..ea9e3a7199 100644--- a/packages/studio/src/player/hooks/useShadowPreviewReload.ts+++ b/packages/studio/src/player/hooks/useShadowPreviewReload.ts@@ -18,7 +18,7 @@ import {type UseTimelineSyncCallbacksParams,} from "./useTimelineSyncCallbacks";import type { IframeWindow, PlaybackAdapter } from "../lib/playbackTypes";-import { thumbnailScheduler } from "../lib/thumbnailScheduler";+import { setPreviewReloading } from "../previewReloading";import { announcePreviewPromoted } from "../sceneSwap";import { afterStudioPendingEdits, isStudioEditSaving } from "../../utils/studioPendingEdits";import { usePlayerStore } from "../store/playerStore";@@ -110,7 +110,7 @@ export function useShadowPreviewReload({isRefreshingRef.current = false;pendingSeekRef.current = null;setPreviewSlots(planShadowDiscard);- thumbnailScheduler.setPreviewReloading(false);+ setPreviewReloading(false);const message = `The preview did not reload (${cause}). The previous preview is still showing.`;logReload("shadow-failed", { cause });console.error(`[studio] ${message}`);@@ -188,7 +188,7 @@ export function useShadowPreviewReload({if (liveTime != null) handOverPlaybackRef.current(liveTime, playing);announcePreviewPromoted({ retired, live: shadow });onPromotedRef.current?.();- thumbnailScheduler.setPreviewReloading(false);+ setPreviewReloading(false);},[stopPendingShadow,@@ -285,7 +285,7 @@ export function useShadowPreviewReload({armReadyTimer(gen);setPreviewSlots((prev) => planShadowReload(prev, gen, url));// Thumbnails of the edit wait for the new preview instead of competing with it.- thumbnailScheduler.setPreviewReloading(true);+ setPreviewReloading(true);},[stopPendingShadow, armReadyTimer, gestureSavesOnScreen],);@@ -300,7 +300,7 @@ export function useShadowPreviewReload({pendingSeekRef.current = null;usePlayerStore.getState().setTimelineReady(false);setPreviewSlots(planShadowDiscard);- thumbnailScheduler.setPreviewReloading(false);+ setPreviewReloading(false);}, [stopPendingShadow, isRefreshingRef, pendingSeekRef]);// Hiding the tab pauses the budget; showing it again restarts the full budget for a pending shadow.@@ -317,7 +317,7 @@ export function useShadowPreviewReload({return () => {document.removeEventListener("visibilitychange", onVisibilityChange);stopPendingShadow();- thumbnailScheduler.setPreviewReloading(false);+ setPreviewReloading(false);};});diff --git a/packages/studio/src/player/hooks/useTimelinePlayer.shadowReload.test.ts b/packages/studio/src/player/hooks/useTimelinePlayer.shadowReload.test.tsindex df958b9406..55e93d0e0f 100644--- a/packages/studio/src/player/hooks/useTimelinePlayer.shadowReload.test.ts+++ b/packages/studio/src/player/hooks/useTimelinePlayer.shadowReload.test.ts@@ -6,6 +6,7 @@ import { createRoot } from "react-dom/client";import { afterEach, describe, expect, it, vi } from "vitest";import { SHADOW_READY_BUDGETS, SHADOW_READY_TIMEOUT_MS } from "./useShadowPreviewReload";import { usePlayerStore } from "../store/playerStore";+import { isPreviewChanging } from "../previewReloading";import { NLEProvider, useNLEContext, type NLEContextValue } from "../../components/nle/NLEContext";import {makeAdapterWindow,@@ -752,6 +753,19 @@ describe("useTimelinePlayer scene swap", () => {expect(roles(getApi())).toEqual(["live"]);});+ it("counts as a preview change until the swap lands, so a canvas press waits for the new scenes", async () => {+ let reply: (r: Response) => void = () => {};+ vi.spyOn(globalThis, "fetch").mockImplementation(+ () => new Promise<Response>((resolve) => (reply = resolve)),+ );+ const { getApi } = liveFilm(vi.fn(async () => {}));+ act(() => getApi().refreshPlayer());+ expect(isPreviewChanging()).toBe(true);+ reply(new Response("<html>v2</html>"));+ await settle();+ expect(isPreviewChanging()).toBe(false);+ });+it("falls back to the full reload when the preview refuses the swap", async () => {vi.spyOn(globalThis, "fetch").mockResolvedValue(new Response("<html>v2</html>"));const { getApi } = liveFilm(async () => {diff --git a/packages/studio/src/player/hooks/useTimelinePlayer.ts b/packages/studio/src/player/hooks/useTimelinePlayer.tsindex 5076efefbe..c5a57fb155 100644--- a/packages/studio/src/player/hooks/useTimelinePlayer.ts+++ b/packages/studio/src/player/hooks/useTimelinePlayer.ts@@ -43,6 +43,7 @@ import { createPreviewMessageHandler } from "./previewMessageRouter";import { timelineElementsChanged } from "./timelinePlayerSync";import { safeContentDocument } from "./timelineSyncHydration";import { sceneSwapFor } from "../sceneSwap";+import { whileScriptWrites } from "../previewReloading";export interface UseTimelinePlayerOptions {/** Runs right after a reloaded preview becomes the live iframe. */@@ -504,11 +505,13 @@ export function useTimelinePlayer({!!iframe.contentDocument && isStudioManualEditGestureLiveIn(iframe.contentDocument);if (!swap || isRefreshingRef.current || swapWouldReplaceGestureNode)return reloadWholeFilm(url.toString());- swap(url.toString(), isCurrent, cancel.signal).catch((error: unknown) => {- if (!isCurrent()) return;- logReload("scene-swap-refused", { reason: String(error) });- reloadWholeFilm(url.toString());- });+ whileScriptWrites(() => swap(url.toString(), isCurrent, cancel.signal)).catch(+ (error: unknown) => {+ if (!isCurrent()) return;+ logReload("scene-swap-refused", { reason: String(error) });+ reloadWholeFilm(url.toString());+ },+ );}, [reloadWholeFilm, previewGeneration]);const pauseRef = useRef(pause);pauseRef.current = pause;diff --git a/packages/studio/src/player/previewReloading.test.ts b/packages/studio/src/player/previewReloading.test.tsnew file mode 100644index 0000000000..7cbe5e05b2--- /dev/null+++ b/packages/studio/src/player/previewReloading.test.ts@@ -0,0 +1,48 @@+import { afterEach, describe, expect, it } from "vitest";+import {+ giveUpOnPreviewChange,+ isPreviewChanging,+ previewReloadBegun,+ requestPreviewReload,+ setPreviewReloading,+ whileScriptWrites,+} from "./previewReloading";++afterEach(() => {+ previewReloadBegun();+ setPreviewReloading(false);+});++describe("the preview is changing", () => {+ it("from a script write's send until it lands", async () => {+ let land: () => void = () => {};+ const write = whileScriptWrites(() => new Promise<void>((resolve) => (land = resolve)));+ expect(isPreviewChanging()).toBe(true);+ land();+ await write;+ expect(isPreviewChanging()).toBe(false);+ });++ it("until a write that fails gives up, so a press never hangs on it", async () => {+ await expect(whileScriptWrites(() => Promise.reject(new Error("rejected")))).rejects.toThrow();+ expect(isPreviewChanging()).toBe(false);+ });++ it("from a reload's request until it has begun", () => {+ requestPreviewReload();+ expect(isPreviewChanging()).toBe(true);+ previewReloadBegun();+ expect(isPreviewChanging()).toBe(false);+ });++ it("stops counting a change a press gave up on, until the preview goes idle", async () => {+ let land: () => void = () => {};+ const stuck = whileScriptWrites(() => new Promise<void>((resolve) => (land = resolve)));+ giveUpOnPreviewChange();+ expect(isPreviewChanging()).toBe(false);+ land();+ await stuck;+ requestPreviewReload();+ expect(isPreviewChanging(), "the next change counts again").toBe(true);+ });+});diff --git a/packages/studio/src/player/previewReloading.ts b/packages/studio/src/player/previewReloading.tsnew file mode 100644index 0000000000..3577cebd84--- /dev/null+++ b/packages/studio/src/player/previewReloading.ts@@ -0,0 +1,48 @@+import { thumbnailScheduler } from "./lib/thumbnailScheduler";++let reloading = false;+let reloadRequested = false;+let scriptWrites = 0;+// A press gave up on the change in progress (a save that never returns); later ones do not wait on it again.+let givenUp = false;++const changing = () => reloading || reloadRequested || scriptWrites > 0;+const noteIdle = () => {+ if (!changing()) givenUp = false;+};++export function giveUpOnPreviewChange(): void {+ givenUp = changing();+}++export function setPreviewReloading(next: boolean): void {+ reloading = next;+ thumbnailScheduler.setPreviewReloading(next);+ noteIdle();+}++/** Studio asked for a reload that has not begun yet; `previewReloadBegun` closes that gap. */+export function requestPreviewReload(): void {+ reloadRequested = true;+}++export function previewReloadBegun(): void {+ reloadRequested = false;+ noteIdle();+}++/** A script write or scene swap counts from its send until its preview update is applied, or it fails. */+export async function whileScriptWrites<T>(write: () => Promise<T>): Promise<T> {+ scriptWrites += 1;+ try {+ return await write();+ } finally {+ scriptWrites -= 1;+ noteIdle();+ }+}++/** The one owner of "the preview is about to change": a canvas press waits for it. */+export function isPreviewChanging(): boolean {+ return changing() && !givenUp;+}diff --git a/packages/studio/src/utils/studioPendingEdits.test.ts b/packages/studio/src/utils/studioPendingEdits.test.tsindex a0c47d3c9a..15785bc93c 100644--- a/packages/studio/src/utils/studioPendingEdits.test.ts+++ b/packages/studio/src/utils/studioPendingEdits.test.ts@@ -5,15 +5,42 @@ import {adoptingStudioPendingEdit,beginStudioPendingEdit,flushStudioPendingEdits,+ afterStudioPendingEdits,hasStudioPendingEdits,isStudioEditSaving,paintBackNewestStudioPendingEdit,+ setStudioWaitingPressCancel,trackStudioPendingEdit,trackedStudioEdit,} from "./studioPendingEdits";import { StudioFileConflictError } from "./studioSaveDiagnostics";import { revertNewestStudioPendingEdit as hostRevert } from "../index";+describe("a canvas press still waiting to run", () => {+ it("is not what a host's revert takes back, since the host steps history after it", () => {+ const cancel = vi.fn(() => true);+ setStudioWaitingPressCancel(cancel);+ try {+ expect(hostRevert()).toBeNull();+ expect(cancel).not.toHaveBeenCalled();+ } finally {+ setStudioWaitingPressCancel(null);+ }+ });++ it("is never a pending edit, since a reload waits for those and the press waits for the reload", () => {+ setStudioWaitingPressCancel(() => true);+ const reload = vi.fn();+ try {+ afterStudioPendingEdits(reload);+ expect(reload).toHaveBeenCalledOnce();+ expect(hasStudioPendingEdits()).toBe(false);+ } finally {+ setStudioWaitingPressCancel(null);+ }+ });+});+describe("studio pending edit flush", () => {it("waits for mounted panels to persist pending local edits", async () => {const persist = vi.fn(async () => undefined);diff --git a/packages/studio/src/utils/studioPendingEdits.ts b/packages/studio/src/utils/studioPendingEdits.tsindex 16566798cb..e03c7618be 100644--- a/packages/studio/src/utils/studioPendingEdits.ts+++ b/packages/studio/src/utils/studioPendingEdits.ts@@ -34,6 +34,15 @@ export function setStudioPendingEditClaimClock(read: (() => number) | null): voihistoryClaims = read ?? (() => 0);}const NOT_SAVED = () => Promise.resolve(false);+let cancelWaitingPress: (() => boolean) | null = null;++export function setStudioWaitingPressCancel(cancel: (() => boolean) | null): void {+ cancelWaitingPress = cancel;+}++export function cancelNewestStudioWaitingPress(): boolean {+ return cancelWaitingPress?.() ?? false;+}let adopting: StudioEditInFlight | null = null;export function adoptingStudioPendingEdit(): StudioEditInFlight | null {diff --git a/packages/studio/tests/e2e/edit-accuracy/baseline.json b/packages/studio/tests/e2e/edit-accuracy/baseline.jsonindex 9e5c1cbbe2..ad8a87806a 100644--- a/packages/studio/tests/e2e/edit-accuracy/baseline.json+++ b/packages/studio/tests/e2e/edit-accuracy/baseline.json@@ -1988,6 +1988,9 @@"seqab-none-pct-r0-root-z100": {"smooth":true,"tracking":0.05,"pressJump":0,"teleport":true,"teleportPx":0.01,"drop":0,"reload":0,"render":0.03,"undo":true,"dropped":0,"controlDropped":0,"workMax":7.63,"frameP95":18.1},"seqab-none-px-r0-nested-z100": {"smooth":true,"tracking":0.07,"pressJump":0,"teleport":true,"teleportPx":0.01,"drop":0,"reload":0,"render":0.03,"undo":true,"dropped":0,"controlDropped":0,"workMax":6.02,"frameP95":19.3},"seqab-none-px-r0-root-z100": {"smooth":true,"tracking":0.03,"pressJump":0,"teleport":true,"teleportPx":0.01,"drop":0,"reload":0,"render":0.03,"undo":true,"dropped":0,"controlDropped":0,"workMax":6.61,"frameP95":19.3},+ "seqfastkeys-none-px-r0-root-z100": {"smooth":false,"tracking":0.06,"pressJump":0.05,"teleport":true,"teleportPx":0.05,"drop":0,"reload":0,"render":0.02,"undo":true,"dropped":3,"controlDropped":0,"workMax":18.72,"frameP95":19.2},+ "seqheldtwice-tlhold-px-r0-nested-z100": {"smooth":false,"tracking":0.24,"pressJump":0.11,"teleport":true,"teleportPx":0.28,"drop":0.17,"reload":0.17,"render":0.02,"undo":true,"dropped":4,"controlDropped":0,"workMax":18.28,"frameP95":21.3},+ "seqheldtwice-tlhold-px-r0-root-z100": {"smooth":false,"tracking":0.27,"pressJump":0.11,"teleport":true,"teleportPx":0.3,"drop":0.21,"reload":0.21,"render":0.02,"undo":true,"dropped":3,"controlDropped":0,"workMax":23.49,"frameP95":20},"seqinflight-none-center-r0-nested-z100": {"smooth":true,"tracking":0.03,"pressJump":0,"teleport":true,"teleportPx":0.01,"drop":0,"reload":0,"render":0.02,"undo":true,"dropped":0,"controlDropped":0,"workMax":7.11,"frameP95":19},"seqinflight-none-center-r0-root-z100": {"smooth":false,"tracking":0.03,"pressJump":0,"teleport":true,"teleportPx":0.01,"drop":0,"reload":0,"render":0.02,"undo":true,"dropped":0,"controlDropped":0,"workMax":8.49,"frameP95":18.4},"seqinflight-none-pct-r0-nested-z100": {"smooth":true,"tracking":0.03,"pressJump":0,"teleport":true,"teleportPx":0.01,"drop":0,"reload":0,"render":0.02,"undo":true,"dropped":0,"controlDropped":0,"workMax":5.93,"frameP95":18.5},@@ -2038,7 +2041,7 @@"seqresizeundo-none-pct-r0-root-z100": {"smooth":true,"tracking":0.26,"pressJump":0,"teleport":true,"teleportPx":0.24,"drop":0,"reload":0,"render":0.03,"undo":true,"dropped":0,"controlDropped":0,"workMax":6.05,"frameP95":18.7},"seqresizeundo-none-px-r0-nested-z100": {"smooth":true,"tracking":0.21,"pressJump":0,"teleport":true,"teleportPx":0.24,"drop":0,"reload":0,"render":0.03,"undo":true,"dropped":0,"controlDropped":0,"workMax":5.5,"frameP95":18.3},"seqresizeundo-none-px-r0-root-z100": {"smooth":true,"tracking":0.23,"pressJump":0,"teleport":true,"teleportPx":0.24,"drop":0,"reload":0,"render":0.03,"undo":true,"dropped":0,"controlDropped":0,"workMax":5.92,"frameP95":19.7},- "seqresizeundodrag-tween-px-r0-nested-z100": {"smooth":false,"tracking":312.36,"pressJump":0,"teleport":false,"teleportPx":312.36,"drop":0,"reload":0,"render":0.02,"undo":false,"dropped":5,"controlDropped":0,"workMax":16.05,"frameP95":25.2,"undoTimeout":"undo lost"},+ "seqresizeundodrag-tween-px-r0-nested-z100": {"smooth":false,"tracking":0.22,"pressJump":0,"teleport":true,"teleportPx":0.24,"drop":0,"reload":0,"render":0.02,"undo":true,"dropped":3,"controlDropped":0,"workMax":11.81,"frameP95":23.3},"seqresizeundodrag-tween-px-r0-root-z100": {"smooth":false,"tracking":0.26,"pressJump":0,"teleport":true,"teleportPx":0.24,"drop":0,"reload":0,"render":0.02,"undo":true,"dropped":1,"controlDropped":0,"workMax":8.23,"frameP95":18.3},"seqrotatenudge-none-center-r0-nested-z100": {"smooth":false,"tracking":0.02,"pressJump":0,"teleport":true,"teleportPx":0.01,"drop":0,"reload":0,"render":0.05,"undo":true,"dropped":2,"controlDropped":0,"workMax":6.14,"frameP95":22.1},"seqrotatenudge-none-center-r0-root-z100": {"smooth":true,"tracking":0.02,"pressJump":0,"teleport":true,"teleportPx":0.01,"drop":0,"reload":0,"render":0.05,"undo":true,"dropped":0,"controlDropped":0,"workMax":4.38,"frameP95":21.3},diff --git a/packages/studio/tests/e2e/edit-accuracy/case.mjs b/packages/studio/tests/e2e/edit-accuracy/case.mjsindex dce030f612..deb0df0b55 100644--- a/packages/studio/tests/e2e/edit-accuracy/case.mjs+++ b/packages/studio/tests/e2e/edit-accuracy/case.mjs@@ -307,7 +307,7 @@ export async function openStudio(ctx) {return settled(ctx);}-async function seekTo(ctx, time) {+export async function seekTo(ctx, time) {const seek = await ctx.page.evaluate((t) => window.__editBench.call("studio_seek", { time: t }),time,@@ -517,6 +517,15 @@ async function cropOutline(ctx, map) {return (await contentQuad(h)).map(map.toComp);}+/** Holds every save request `ms` before it is sent, so a later press lands while it is still in flight. */+function slowSaves(ms) {+ const send = window.fetch;+ window.fetch = (url, init) =>+ /\/file-mutations\/patch-|gsap-mutations/.test(String(url))+ ? new Promise((resolve) => setTimeout(resolve, ms)).then(() => send(url, init))+ : send(url, init);+}+/** Screen path (one point per frame) and the per-frame tracking error for each pointer gesture. */function plan(gesture, pre, pressComp) {const at = (p) => pre.map.toScreen(p);@@ -527,10 +536,10 @@ function plan(gesture, pre, pressComp) {dist([s.p[0] - s0.p[0], s.p[1] - s0.p[1]], [s.c[0] - s0.c[0], s.c[1] - s0.c[1]]),});if (gesture === "move") {- const local = quadToLocal(pre.quad, pre.size, pressComp);+ const local = quadToLocal(pre.quad, { width: 1, height: 1 }, pressComp);return {path: steps.map((k) => at([pressComp[0] + MOVE_BY[0] * k, pressComp[1] + MOVE_BY[1] * k])),- ...follow((m) => localToQuad(m.quad, m.size, local)),+ ...follow((m) => localToQuad(m.quad, { width: 1, height: 1 }, local)),};}if (gesture === "resize") {@@ -567,10 +576,20 @@ function plan(gesture, pre, pressComp) {};}+// A press made while the preview reloads waits for it: Studio draws its box at the pointer meanwhile.+async function waitingQuad(page, map) {+ const waiting = await page.$("[data-dom-edit-press-waiting]");+ const quad = waiting && (await contentQuad(waiting)).map(map.toComp);+ await waiting?.dispose();+ return quad;+}+async function sample(ctx, gesture, point, pointerScreen) {const m = await measure(ctx);if (gesture === "crop") m.outline = await cropOutline(ctx, m.map);- return { m, p: point(m), c: m.map.toComp(pointerScreen) };+ const waiting = await waitingQuad(ctx.page, m.map);+ const shown = waiting ? { ...m, quad: waiting, visible: waiting } : m;+ return { m: shown, actual: m.visible, p: point(shown), c: m.map.toComp(pointerScreen) };}const TRACE_CATEGORIES = ["toplevel", "devtools.timeline", "blink.user_timing"];@@ -725,6 +744,8 @@ async function strayMove(page, [x, y]) {* `{ pause }` holds still; `{ stray }`: see strayMove. */// fallow-ignore-next-line complexityexport async function pointerGesture(ctx, gesture, pre, route) {+ const quad = await waitingQuad(ctx.page, pre.map);+ if (quad) pre = { ...pre, quad, visible: quad };const press = await handlePoint(ctx, pre, gesture);const pressComp = pre.map.toComp(press);const g = { ...plan(gesture, pre, pressComp), ...(route && { path: route(press) }) };@@ -769,6 +790,8 @@ export async function pointerGesture(ctx, gesture, pre, route) {smooth,diag: {hit,+ actualAtRelease: last.actual,+ shownAtRelease: lastQuad,grabOffset: gesture === "rotate" ? 0 : dist(s0.p, s0.c),errors: errors.map((e) => Math.round(e * 1000) / 1000),},@@ -826,6 +849,7 @@ export async function serveFixtureAssetsLocally(page) {* Studio open on the case in a fresh browser context, snapping off, at the case's zoom, target selected;* `drive` measures the rest. A failure keeps a screenshot, and the context always closes.*/+// fallow-ignore-next-line complexityexport async function inStudio({ browser, spec, dir, files, url, evidence }, drive) {const context = await browser.createBrowserContext();const page = await context.newPage();@@ -847,6 +871,7 @@ export async function inStudio({ browser, spec, dir, files, url, evidence }, driawait page.setViewport(VIEWPORT);await page.evaluateOnNewDocument(installWebMcpHost, "__editBench");await page.evaluateOnNewDocument(instrumentPage);+ if (spec.slowSaves) await page.evaluateOnNewDocument(slowSaves, spec.slowSaves);await page.evaluateOnNewDocument(frameSamplerScript);await page.goto(url);let pre = await openStudio(ctx);diff --git a/packages/studio/tests/e2e/edit-accuracy/drags.mjs b/packages/studio/tests/e2e/edit-accuracy/drags.mjsindex f7801e7510..acc2d4e6df 100644--- a/packages/studio/tests/e2e/edit-accuracy/drags.mjs+++ b/packages/studio/tests/e2e/edit-accuracy/drags.mjs@@ -43,12 +43,31 @@ const PLAIN_TO_KEYS = [{ do: "seek", time: 1 },];+/** Add keyframe, then moves pressed before its tween reaches the preview: each must key where it is let go. */+const FAST_KEYS = [+ { do: "drag", gesture: "move", by: [90, -40] },+ { do: "autokey" },+ { do: "addkey" },+ { do: "seek", time: 2 },+ { do: "drag", gesture: "move", by: [60, -30] },+ { do: "seek", time: 3 },+ { do: "drag", gesture: "move", by: [-50, 20] },+];+/** On a GSAP-tweened box: a resize, then a drag (with or without an undo between) must save where it is let go. */const GSAP_SEQUENCES = {resizeundodrag: [{ do: "drag", gesture: "resize" }, { do: "undo" }, MOVE],resizedrag: [{ do: "drag", gesture: "resize" }, MOVE],};+/** A box a timeline set holds: a second resize and drag after the first pair must save too. */+const HELD_TWICE = [+ { do: "drag", gesture: "resize" },+ MOVE,+ { do: "drag", gesture: "resize" },+ { ...MOVE, by: [-90, -60] },+];+/** Text in place: a double press opens it, Enter commits; `select` first double-clicks a word to replace. */const TEXT = {edit: [{ do: "text", word: "Teleport" }],@@ -93,6 +112,12 @@ export function dragCases() {keyRender: 3,})),);+ const fastKeys = [row("seqfastkeys", pxRoot(), FAST_KEYS)];+ // Saves slowed as on a busy machine: each press lands before the previous save does.+ const heldTwice = ["root", "nested"].map((nesting) => ({+ ...row("seqheldtwice", pxRoot({ nesting }), HELD_TWICE, "tlhold"),+ slowSaves: 800,+ }));// Settled: a resize on a tween saves its size and its anchor separately, still one undo.const gsapSequences = Object.entries(GSAP_SEQUENCES).flatMap(([name, steps]) =>["root", "nested"].map((nesting) => ({@@ -108,5 +133,14 @@ export function dragCases() {other: false,})),);- return [...paths, ...sequences, ...plainToKeys, ...gsapSequences, ...texts, ...centred];+ return [+ ...paths,+ ...sequences,+ ...plainToKeys,+ ...fastKeys,+ ...heldTwice,+ ...gsapSequences,+ ...texts,+ ...centred,+ ];}diff --git a/packages/studio/tests/e2e/edit-accuracy/grid.mjs b/packages/studio/tests/e2e/edit-accuracy/grid.mjsindex 32ff260951..08dfc17f85 100644--- a/packages/studio/tests/e2e/edit-accuracy/grid.mjs+++ b/packages/studio/tests/e2e/edit-accuracy/grid.mjs@@ -178,6 +178,11 @@ function gsapLines(spec) {if (spec.gsap === "idle") return [`tl.to("#other", { x: 120, duration: 4, ease: "none" }, 0);`];const percent = spec.placement === "xpercent" ? ", xPercent: -50, yPercent: -50" : "";if (spec.gsap === "hold") return [`gsap.set("#target", { x: 40, y: 20${percent} });`];+ if (spec.gsap === "tlhold")+ return [+ `tl.to("#other", { x: 120, duration: 10 }, 0);`,+ `tl.set("#target", { x: 40, y: 20 }, 0);`,+ ];const lines = [`tl.to("#target", { x: 120, y: 60, duration: 4, ease: "none" }, 0);`];if (percent) lines.unshift(`gsap.set("#target", { ${percent.slice(2)} });`);return lines;diff --git a/packages/studio/tests/e2e/edit-accuracy/history.test.mjs b/packages/studio/tests/e2e/edit-accuracy/history.test.mjsnew file mode 100644index 0000000000..f10db9ef93--- /dev/null+++ b/packages/studio/tests/e2e/edit-accuracy/history.test.mjs@@ -0,0 +1,42 @@+import { describe, expect, it } from "vitest";+import { historyGroups } from "./sequences.mjs";++const claim = (id, status = 200) => ({ claim: id, status, readable: true });+const undid = (undoes, status = 200) => ({ id: `u-${undoes}`, undoes, status });++describe("historyGroups", () => {+ it("counts a resize's size and position writes as one group", () => {+ expect(historyGroups([claim("g1"), claim("g1"), claim("g2")])).toEqual({+ stack: ["g1", "g2"],+ faults: [],+ });+ });++ it("keeps a resize split across two groups as two, which one gesture cannot owe", () => {+ expect(historyGroups([claim("g1"), claim("g2")]).stack).toEqual(["g1", "g2"]);+ });++ it("pops the newest group on undo, and faults an undo of any other", () => {+ expect(historyGroups([claim("g1"), undid("g1"), claim("g2")])).toEqual({+ stack: ["g2"],+ faults: [],+ });+ expect(historyGroups([claim("g1"), claim("g2"), undid("g1")]).faults).toEqual([+ "undid g1, not the newest group g2",+ ]);+ });++ it("faults two gestures sharing a group, a refused claim, and an unreadable reply", () => {+ expect(historyGroups([claim("g1"), claim("g2"), claim("g1")]).faults).toEqual([+ "two gestures share a group",+ ]);+ expect(historyGroups([claim(null, 409)]).faults).toEqual(["history reply 409"]);+ expect(historyGroups([{ claim: null, status: 200, readable: false }]).faults).toEqual([+ "history reply 200",+ ]);+ });++ it("opens no group for a claim with nothing to keep", () => {+ expect(historyGroups([claim(null)])).toEqual({ stack: [], faults: [] });+ });+});diff --git a/packages/studio/tests/e2e/edit-accuracy/report.mjs b/packages/studio/tests/e2e/edit-accuracy/report.mjsindex ade849a651..5f8a3018bf 100644--- a/packages/studio/tests/e2e/edit-accuracy/report.mjs+++ b/packages/studio/tests/e2e/edit-accuracy/report.mjs@@ -86,6 +86,7 @@ export function score(spec, r) {render: r.render !== null && r.render <= LIMIT_PX,undo:!r.undoTimeout &&+ r.undo.groups !== false &&r.undo.bytes &&r.undo.redoBytes &&Math.max(r.undo.box, r.undo.redoBox) <= LIMIT_PX &&diff --git a/packages/studio/tests/e2e/edit-accuracy/run.mjs b/packages/studio/tests/e2e/edit-accuracy/run.mjsindex 5ea5866b33..c196e224c8 100644--- a/packages/studio/tests/e2e/edit-accuracy/run.mjs+++ b/packages/studio/tests/e2e/edit-accuracy/run.mjs@@ -124,7 +124,8 @@ async function runOne(spec, browser, decoder, port) {});await stopServer(server);server = null;- result = await withRender(dir, decoder, measured, evidence, spec.playhead);+ const at = measured.reloaded?.time ?? spec.playhead;+ result = await withRender(dir, decoder, measured, evidence, at);if (keyRender) result.renderKey = await renderKeyframe(dir, decoder, keyRender);} catch (error) {result = errorResult(error, log);diff --git a/packages/studio/tests/e2e/edit-accuracy/sequences.mjs b/packages/studio/tests/e2e/edit-accuracy/sequences.mjsindex 7e84c8eb21..9fa6288a17 100644--- a/packages/studio/tests/e2e/edit-accuracy/sequences.mjs+++ b/packages/studio/tests/e2e/edit-accuracy/sequences.mjs@@ -19,6 +19,7 @@ import {selectTarget,settled,saveFault,+ seekTo,sleep,smoothness,timedWrite,@@ -115,6 +116,54 @@ export function watchVersions(dir, files) {return { versions, stop: () => watchers.forEach((w) => w.close()) };}+/** Studio's own history replies in arrival order: each claim's group, each undo or redo's entry and what it reverts. */+function watchHistory(page) {+ const replies = [];+ const read = (response) => {+ const kind = /\/history\/(claim|step|undo)$/.exec(new URL(response.url()).pathname)?.[1];+ if (!kind || response.request().method() !== "POST") return;+ const status = response.status();+ replies.push(+ response+ .json()+ .catch(() => null)+ // fallow-ignore-next-line complexity+ .then((body) =>+ kind === "claim"+ ? { claim: body?.claimed?.id ?? null, status, readable: Boolean(body) }+ : { id: body?.entry?.id ?? null, undoes: body?.entry?.undoes ?? null, status },+ ),+ );+ };+ page.on("response", read);+ return { replies, stop: () => page.off("response", read) };+}++/** The groups left to undo, oldest first: a claim opens one unless it names the newest (one gesture writing+ * twice), an undo must revert the newest. Anything else is a fault: one gesture, one group, one undo. */+// fallow-ignore-next-line complexity+export function historyGroups(replies) {+ const [stack, faults] = [[], []];+ for (const r of replies) {+ if (r.status !== 200 || r.readable === false) faults.push(`history reply ${r.status}`);+ else if ("claim" in r) {+ if (r.claim && r.claim !== stack.at(-1)) stack.push(r.claim);+ } else if (r.undoes && r.undoes === stack.at(-1)) stack.pop();+ else faults.push(`undid ${r.undoes}, not the newest group ${stack.at(-1)}`);+ }+ if (new Set(stack).size !== stack.length) faults.push("two gestures share a group");+ return { stack, faults };+}++/** The first undo or redo reply after `seen`, or null when none arrives. */+async function steppedAfter(history, seen) {+ for (const deadline = Date.now() + 5000; Date.now() < deadline; await sleep(20)) {+ const found = (await Promise.all(history.replies.slice(seen))).find((r) => "undoes" in r);+ if (found) return found;+ }+ return null;+}+function mergeSmooth(parts) {const intervals = parts.flatMap((s) => s.intervals);return {@@ -136,17 +185,27 @@ function mergeSmooth(parts) {export const slowest = (writes = []) =>writes.length ? Math.max(...writes.map((w) => w.ms ?? 0)) : null;-/** Undo (or redo) once per entry, each landing on that entry's file; stops at the first write that never lands. */+/**+ * Undo (or redo) once per entry: its reply must revert the entry's group and, where the entry knows its+ * bytes, its write must land on them. Stops at the first write that never lands.+ */// fallow-ignore-next-line complexity-async function walk(ctx, keys, entries, current) {- const [landed, writes] = [[], []];+async function walk(ctx, keys, entries, current, history) {+ const [landed, writes, stepped] = [[], [], []];for (const want of entries) {await blurPreview(ctx.page);- const since = Date.now();+ const [since, seen] = [Date.now(), history.replies.length];await chord(ctx.page, keys);const w = await timedWrite(ctx, current, since);+ const step = w.reached ? await steppedAfter(history, seen) : null;writes.push(w);- landed.push(w.reached && Boolean(want) && sameFiles(w.files, want));+ stepped.push(step?.id ?? null);+ landed.push(+ w.reached &&+ Boolean(want.undoes) &&+ step?.undoes === want.undoes &&+ (!want.files || sameFiles(w.files, want.files)),+ );current = w.files;if (!w.reached) break;}@@ -154,6 +213,7 @@ async function walk(ctx, keys, entries, current) {ok: landed.length === entries.length && landed.every(Boolean),landed,writes,+ stepped,current,};}@@ -360,19 +420,21 @@ const boxError = (state, m) =>export async function runSequence(args) {const drags = args.spec.steps.some((s) => s.do === "drag");const control = await controlDrag(args.browser, drags ? "move" : "nudge");- let watcher = null;+ let [watcher, history] = [null, null];try {return await inStudio(args, (session) => {watcher = watchVersions(args.dir, args.files);- return measureSequence(args, session, control, watcher);+ history = watchHistory(session.page);+ return measureSequence(args, session, control, watcher, history);});} finally {watcher?.stop();+ history?.stop();}}// fallow-ignore-next-line complexity-async function measureSequence({ spec, dir, files, evidence }, session, control, watcher) {+async function measureSequence({ spec, dir, files, evidence }, session, control, watcher, history) {const { page, pre, zoom, shoot, consoleErrors } = session;const ctx = { A: session.ctx, B: { ...session.ctx, handles: null, selector: "#other" } };const state = {@@ -397,7 +459,14 @@ async function measureSequence({ spec, dir, files, evidence }, session, control,const collect = async () => {const open = steps.filter((s) => s.do === "drag" && !s.teleport);const windows = open.length ? await stopFrames(page) : [];- open.forEach((s, i) => (s.teleport = scoreTeleport(s.gesture, windows[i] ?? [])));+ open.forEach((s, i) => {+ const frames = windows[i] ?? [];+ s.teleport = scoreTeleport(s.gesture, frames);+ s.elementTeleport = scoreTeleport(+ s.gesture,+ frames.map((f) => ({ ...f, waitingQuad: undefined })),+ ).max;+ });};for (const step of spec.steps) {if (step.do !== "drag") await collect();@@ -415,6 +484,19 @@ async function measureSequence({ spec, dir, files, evidence }, session, control,backSince = back ? (backSince ?? Date.now()) : null;if (backSince !== null && Date.now() - backSince >= UNDONE_QUIET_MS) break;}+ await page.waitForFunction(+ () => {+ if (document.querySelector("[data-dom-edit-press-waiting]")) return false;+ const frames = Array.from(document.querySelectorAll("iframe, hyperframes-player")).flatMap(+ (host) =>+ host.shadowRoot ? Array.from(host.shadowRoot.querySelectorAll("iframe")) : [host],+ );+ return frames.every(+ (frame) => !frame.contentDocument?.querySelector("[data-hf-studio-manual-edit-gesture]"),+ );+ },+ { timeout: 20_000 },+ );await waitForFiles(ctx.A, { timeout: 5000 });watcher.stop();const versions = watcher.versions;@@ -427,28 +509,45 @@ async function measureSequence({ spec, dir, files, evidence }, session, control,const committedFiles = readFiles(dir, files);evidence.files = committedFiles;- // The undo stack the steps imply: each saving step pushes (before, after), an undo pops. A settled- // case knows where each step's saves ended, so one action is one undo even when it wrote twice.+ // The groups the history took, against the steps: each gesture one group, each undo the newest.+ const groups = historyGroups(await Promise.all(history.replies));+ const ids = groups.stack.toReversed();+ const groupsOk = !groups.faults.length && groups.stack.length === state.depth;+ // A settled case knows each step's bytes (its saves ended before the next step); a fast one only+ // where all are undone and all redone, since one gesture may write more than once.const stack = [];let vi = 0;spec.steps.forEach((s, i) => {- if (!saves(s)) return;- const next = spec.settle ? steps[i].saves : vi + 1;+ if (!spec.settle || !saves(s)) return;if (s.do === "undo") stack.pop();- else stack.push({ before: versions[vi], after: versions[next] });- vi = next;+ else stack.push({ before: versions[vi], after: versions[steps[i].saves] });+ vi = steps[i].saves;});- const undo = await walk(ctx.A, "Control+z", stack.map((e) => e.before).reverse(), committedFiles);+ const last = (i) => i === state.depth - 1;+ const undo = await walk(+ ctx.A,+ "Control+z",+ Array.from({ length: state.depth }, (_, i) => ({+ undoes: ids[i],+ files: spec.settle ? stack.at(-1 - i).before : last(i) ? versions[0] : undefined,+ })),+ committedFiles,+ history,+ );// The file the steps should have left: the last surviving save's, or the original when all were undone.- const expected = stack.length ? stack.at(-1).after : versions[0];+ const expected = spec.settle ? (stack.at(-1)?.after ?? versions[0]) : versions.at(-1);const undone = await settled(ctx.A);await shoot("undone");const redo = undo.ok? await walk(ctx.A,"Control+Shift+z",- stack.map((e) => e.after),+ undo.stepped.toReversed().map((undoes, i) => ({+ undoes,+ files: spec.settle ? stack[i].after : last(i) ? committedFiles : undefined,+ })),undo.current,+ history,): { ok: false, landed: [] };const redone = undo.ok ? await settled(ctx.A) : null;@@ -456,7 +555,9 @@ async function measureSequence({ spec, dir, files, evidence }, session, control,await waitForFiles(ctx.A, { timeout: 15_000 });await page.reload();- const reloaded = await openStudio(ctx.A);+ // The reload opens at the case's playhead; the steps may have left it elsewhere.+ const opened = await openStudio(ctx.A);+ const reloaded = state.time === ctx.A.playhead ? opened : await seekTo(ctx.A, state.time);await shoot("reloaded");const shown = state.text && (await ctx.A.handles.target.evaluate((e) => e.textContent));const drags = steps.filter((s) => s.do === "drag");@@ -505,8 +606,9 @@ async function measureSequence({ spec, dir, files, evidence }, session, control,text.shown &&(!text.select || (text.selection?.editing && text.selection.text.trim().length > 0)),},- reloaded,+ reloaded: { ...reloaded, time: state.time },undo: {+ groups: groupsOk,bytes: undo.ok && sameFiles(committedFiles, expected ?? {}),box: quadDistance(undone.visible, pre.visible),redoBytes: redo.ok,@@ -527,6 +629,7 @@ async function measureSequence({ spec, dir, files, evidence }, session, control,})),diag: {saves: { seen: versions.length - 1, owed },+ history: { ...groups, owed: state.depth, undid: undo.stepped ?? [] },undoWalk: undo.landed,redoWalk: redo.landed,traces: Object.fromEntries(diff --git a/packages/studio/tests/e2e/edit-accuracy/teleport.mjs b/packages/studio/tests/e2e/edit-accuracy/teleport.mjsindex 3e8c177de4..96e3d40c92 100644--- a/packages/studio/tests/e2e/edit-accuracy/teleport.mjs+++ b/packages/studio/tests/e2e/edit-accuracy/teleport.mjs@@ -144,10 +144,12 @@ function frameSampler() {// A page with no preview (the blank-page control) holds its element itself.return best?.el ?? document.querySelector(selector);};+ // fallow-ignore-next-line complexityconst read = () => {const el = findElement(rec.selector);const root = el?.ownerDocument.querySelector('[data-composition-id="main"]');const outline = document.querySelector("[data-dom-edit-crop-frame] > div.border-dashed");+ const waiting = document.querySelector("[data-dom-edit-press-waiting]");rec.samples.push({t: performance.now(),pointer: rec.pointer,@@ -159,6 +161,7 @@ function frameSampler() {clip: el.ownerDocument.defaultView.getComputedStyle(el).clipPath,}),...(outline && { outline: quadOf(outline) }),+ ...(waiting && { waitingQuad: quadOf(waiting) }),});};// ResizeObserver runs after every document's rAF callbacks and layout, just before paint, so it reads@@ -211,6 +214,10 @@ export async function stopFrames(page) {const boxOf = (s, map) => {const quad = s.quad.map(map.toComp);const size = { width: s.size[0], height: s.size[1] };+ if (s.waitingQuad) {+ const shown = s.waitingQuad.map(map.toComp);+ return { quad: shown, size, visible: shown };+ }return { quad, size, visible: visibleQuad(quad, size, parseInset(s.clip)) };};@@ -231,10 +238,10 @@ function trackers(gesture, first, p0) {};return [follow(edge), { grab: (s) => centre(boxOf(s, s.map).quad), implied: () => c0 }];}- const local = quadToLocal(b.quad, b.size, p0);+ const local = quadToLocal(b.quad, { width: 1, height: 1 }, p0);const grab = (s) => {const m = boxOf(s, s.map);- return localToQuad(m.quad, m.size, local);+ return localToQuad(m.quad, { width: 1, height: 1 }, local);};if (gesture !== "rotate") return [follow(grab)];const c = centre(b.visible);diff --git a/packages/studio/tests/e2e/edit-accuracy/teleport.test.mjs b/packages/studio/tests/e2e/edit-accuracy/teleport.test.mjsindex 4ac24395f3..21e2494618 100644--- a/packages/studio/tests/e2e/edit-accuracy/teleport.test.mjs+++ b/packages/studio/tests/e2e/edit-accuracy/teleport.test.mjs@@ -35,6 +35,20 @@ const drag = [];describe("scoreTeleport", () => {+ const waitingDrag = drag.map((f) => ({ ...f, quad: box(0), waitingQuad: f.quad }));+ it("tracks the waiting outline until the element catches up after release", () => {+ expect(scoreTeleport("move", [...waitingDrag, frame(50, false)])).toMatchObject({+ max: 0,+ pass: true,+ });+ });+ it("rejects a jumping outline while the element waits", () => {+ const jumped = waitingDrag.map((f, i) => (i === 4 ? { ...f, waitingQuad: box(f.t + 37) } : f));+ expect(scoreTeleport("move", [...jumped, frame(50, false)]).pass).toBe(false);+ });+ it("rejects an element that lands away from the outline after waiting", () => {+ expect(scoreTeleport("move", [...waitingDrag, frame(50, false, 55)]).pass).toBe(false);+ });it("passes a box that follows the pointer every frame", () => {expect(scoreTeleport("move", drag)).toMatchObject({ max: 0, pass: true });});