mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-25 08:32:45 +00:00
fix(studio): a sealed resize of a size-tweened layer saves a keyframe and stays where dropped (#8799)
* fix(studio): a sealed resize of a layer whose tween writes its size saves a keyframe * fix(core): a sealed resize saves a CSS-translated layer's position as GSAP reads it * fix(studio): a sealed resize handed to GSAP starts from the x/y GSAP reads at the press * fix(core): a sealed GSAP move or resize clears the CSS translate its saved x/y carries * fix(core): a save landing under a newer drag leaves that drag's drawn translate alone * test(core): a save under a sealed draft leaves translate none, not empty * fix(core): a sealed resize saved to GSAP x/y no longer draws its translate twice after the drop * test(core): the GSAP-held draft mock folds a CSS translate the way real GSAP does * refactor(core): name the keep-size translate drop for what it keeps off * fix(core): a sealed resize's end keeps the translate of a layer GSAP never moved * fix(core): a sealed GSAP-route resize keeps the translate GSAP folded off when it ends * fix(studio): a sealed resize picks its route only after the frame's GSAP snapshot arrives * fix(core): a sealed GSAP-route end settles the translate the way an open preview does * fix(studio): only a sealed resize press waits for the frame's GSAP snapshot
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { gsap as realGsap } from "gsap";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { drawDrafts } from "../editingDraft";
|
||||
import { handleFor } from "../editingHandles";
|
||||
import { gsapSet, parseGsapSet } from "./gsapSet";
|
||||
|
||||
@@ -45,4 +47,22 @@ describe("gsap-set", () => {
|
||||
expect(parseGsapSet({ handle: "#box", props: { x: 1 } })).toBeNull();
|
||||
expect(parseGsapSet({ handle, props: { x: 1 }, extra: true })).toBeNull();
|
||||
});
|
||||
|
||||
// fails without the fix: the draft's end put the layer's CSS translate back under the x/y committed from it, so a
|
||||
// sealed resize handed to GSAP drew 50 px off (translate 40px 30px) where an open preview leaves translate none.
|
||||
it.each(["keep-size", "restore"] as const)(
|
||||
"leaves the CSS translate GSAP's committed x/y now carry cleared when the draft ends (%s)",
|
||||
(end) => {
|
||||
Object.assign(window, { gsap: realGsap });
|
||||
const el = box();
|
||||
el.style.translate = "40px 30px";
|
||||
const handle = handleFor(el);
|
||||
drawDrafts([{ handle, translate: { x: -10, y: -4, route: "gsap" }, size: null }]);
|
||||
|
||||
gsapSet({ handle, props: { x: -10.073, y: -3.715 } });
|
||||
drawDrafts([{ handle, end }]);
|
||||
|
||||
expect(el.style.translate).toBe("none");
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -170,7 +170,7 @@ describe("patch-tweens ending a gesture's draft", () => {
|
||||
|
||||
expect(reply).toEqual({ patched: true });
|
||||
expect(set).toHaveBeenCalledExactlyOnceWith(element, { x: 130, y: 80 });
|
||||
expect(element.style.translate).toBe("");
|
||||
expect(element.style.translate).toBe("none");
|
||||
});
|
||||
|
||||
it("leaves a live draft alone when the patch ends none", () => {
|
||||
|
||||
@@ -6,6 +6,7 @@ import { handleFor } from "./editingHandles";
|
||||
|
||||
afterEach(() => {
|
||||
document.body.innerHTML = "";
|
||||
document.head.innerHTML = "";
|
||||
delete (window as { gsap?: unknown }).gsap;
|
||||
});
|
||||
|
||||
@@ -182,10 +183,20 @@ describe("moves through GSAP", () => {
|
||||
function gsapHeld() {
|
||||
const { element, handle } = card("translate: 4px 2px; width: 50px");
|
||||
const position = { x: 40, y: 30 };
|
||||
(window as { gsap?: unknown }).gsap = {
|
||||
getProperty: (_: Element, axis: "x" | "y") => position[axis],
|
||||
// Like real GSAP, the first read folds the CSS translate into x/y and leaves translate none.
|
||||
const gsap = {
|
||||
getProperty: (target: HTMLElement, axis: "x" | "y") => {
|
||||
if (target.style.translate !== "none") {
|
||||
const [x = 0, y = 0] = shown(target);
|
||||
Object.assign(position, { x: position.x + x, y: position.y + y });
|
||||
target.style.setProperty("translate", "none");
|
||||
}
|
||||
return position[axis];
|
||||
},
|
||||
set: (_: Element, props: Partial<typeof position>) => Object.assign(position, props),
|
||||
};
|
||||
(window as { gsap?: unknown }).gsap = gsap;
|
||||
gsap.getProperty(element, "x"); // the press reads GSAP's x/y before any draft draws
|
||||
const move = (x: number, y: number) =>
|
||||
drawDrafts([{ handle, translate: { x, y, route: "gsap" }, size: null }]);
|
||||
return { element, handle, position, move };
|
||||
@@ -202,14 +213,59 @@ describe("moves through GSAP", () => {
|
||||
const { element, handle, position, move } = gsapHeld();
|
||||
move(30, 36);
|
||||
drawDrafts([{ handle, end: "restore" }]);
|
||||
expect([position, element.style.translate]).toEqual([{ x: 40, y: 30 }, "4px 2px"]);
|
||||
expect([position, element.style.translate]).toEqual([{ x: 44, y: 32 }, "none"]);
|
||||
});
|
||||
|
||||
it("leaves GSAP where the drag drew it when the draft ends keeping its size", () => {
|
||||
const { element, handle, position, move } = gsapHeld();
|
||||
move(30, 36);
|
||||
drawDrafts([{ handle, end: "keep-size" }]);
|
||||
expect([position, element.style.translate]).toEqual([{ x: 30, y: 36 }, "4px 2px"]);
|
||||
expect([position, element.style.translate]).toEqual([{ x: 30, y: 36 }, "none"]);
|
||||
});
|
||||
|
||||
// fails without the fix: a sealed resize saved as GSAP x/y over a stylesheet translate drew 50 px off after the
|
||||
// drop, because the end put back the press's empty inline translate over the none GSAP's soft reload had set.
|
||||
it("keeps the translate GSAP folded off when a soft reload set it before the end", () => {
|
||||
document.head.innerHTML = "<style>#card { translate: 40px 30px }</style>";
|
||||
const { element, handle } = card("width: 50px");
|
||||
(window as { gsap?: unknown }).gsap = { getProperty: () => 0, set: () => {} };
|
||||
drawDrafts([{ handle, translate: { x: -50, y: -33 }, size: { width: 80, height: 40 } }]);
|
||||
element.style.setProperty("translate", "none");
|
||||
|
||||
drawDrafts([{ handle, end: "keep-size" }]);
|
||||
|
||||
expect([getComputedStyle(element).translate, element.style.width]).toEqual(["none", "80px"]);
|
||||
});
|
||||
|
||||
it("puts back a CSS-placed layer's translate when GSAP is loaded but never moved it", () => {
|
||||
document.head.innerHTML = "<style>#card { translate: 40px 30px }</style>";
|
||||
const { element, handle } = card("width: 50px");
|
||||
(window as { gsap?: unknown }).gsap = { getProperty: () => 0, set: () => {} };
|
||||
drawDrafts([{ handle, translate: { x: -50, y: -33 }, size: { width: 80, height: 40 } }]);
|
||||
|
||||
drawDrafts([{ handle, end: "keep-size" }]);
|
||||
|
||||
expect([getComputedStyle(element).translate, element.style.width]).toEqual([
|
||||
"40px 30px",
|
||||
"80px",
|
||||
]);
|
||||
});
|
||||
|
||||
it("keeps translate none after a GSAP-route draft when GSAP folded a stylesheet translate", () => {
|
||||
document.head.innerHTML = "<style>#card { translate: 40px 30px }</style>";
|
||||
const { element, handle } = card("width: 50px");
|
||||
const fold = (target: HTMLElement) => target.style.setProperty("translate", "none");
|
||||
(window as { gsap?: unknown }).gsap = {
|
||||
getProperty: (t: HTMLElement) => (fold(t), 0),
|
||||
set: () => {},
|
||||
};
|
||||
drawDrafts([
|
||||
{ handle, translate: { x: 10, y: 0, route: "gsap" }, size: { width: 80, height: 40 } },
|
||||
]);
|
||||
|
||||
drawDrafts([{ handle, end: "keep-size" }]);
|
||||
|
||||
expect(getComputedStyle(element).translate).toBe("none");
|
||||
});
|
||||
|
||||
// fails without the fix: restore compared GSAP's x/y with the drawn one, so a later set to that same value, or one
|
||||
@@ -234,7 +290,7 @@ describe("moves through GSAP", () => {
|
||||
move(30, 36);
|
||||
gsapSet({ handle, props: { x: 25 } });
|
||||
drawDrafts([{ handle, end: "restore" }]);
|
||||
expect(position).toEqual({ x: 25, y: 30 });
|
||||
expect(position).toEqual({ x: 25, y: 32 });
|
||||
});
|
||||
|
||||
// fails without the fix: the hold dropped only when the whole batch landed, so a restore after a batch with a missed
|
||||
|
||||
@@ -30,6 +30,7 @@ interface Before {
|
||||
/** GSAP's rotation before the first GSAP turn drawn, to put back on "restore". */
|
||||
gsapRotation?: number;
|
||||
gsapPosition?: { x: number; y: number };
|
||||
drawnTranslate?: string;
|
||||
drewTransform?: boolean;
|
||||
propsSet?: string[];
|
||||
putMarkBack?: () => void;
|
||||
@@ -134,23 +135,31 @@ export function movedTranslate(
|
||||
|
||||
type DraftTranslate = NonNullable<Extract<EditingDraft, { translate: unknown }>["translate"]>;
|
||||
|
||||
function writeDrawnTranslate(element: Styled, saved: Before, value: string): void {
|
||||
element.style.setProperty("translate", value);
|
||||
saved.drawnTranslate = element.style.getPropertyValue("translate");
|
||||
}
|
||||
|
||||
function drawTranslate(element: Styled, offset: DraftTranslate): void {
|
||||
const saved = beforeOf(element);
|
||||
if (offset.route !== "gsap")
|
||||
return void element.style.setProperty("translate", movedTranslate(saved.translate, offset));
|
||||
return writeDrawnTranslate(element, saved, movedTranslate(saved.translate, offset));
|
||||
const gsap = frameGsap();
|
||||
const read = (axis: string) => Number(gsap?.getProperty?.(element, axis)) || 0;
|
||||
saved.gsapPosition ??= { x: read("x"), y: read("y") };
|
||||
element.style.setProperty("translate", "none");
|
||||
writeDrawnTranslate(element, saved, "none");
|
||||
gsap?.set?.(element, { x: offset.x, y: offset.y });
|
||||
}
|
||||
|
||||
export function rebaseDrawnPosition(element: Element, props: Record<string, unknown>): void {
|
||||
const position = before.get(element)?.gsapPosition;
|
||||
for (const axis of ["x", "y"] as const) {
|
||||
const value = props[axis];
|
||||
if (position && typeof value === "number" && Number.isFinite(value)) position[axis] = value;
|
||||
}
|
||||
const saved = before.get(element);
|
||||
const moved = (["x", "y"] as const).filter((axis) => Number.isFinite(props[axis]));
|
||||
if (!moved.length || !isStylableElement(element)) return;
|
||||
if (!saved) element.style.setProperty("translate", "none");
|
||||
for (const entry of saved?.inline ?? [])
|
||||
if (entry[0] === "translate") [entry[1], entry[2]] = ["none", ""];
|
||||
for (const axis of moved)
|
||||
if (saved?.gsapPosition) saved.gsapPosition[axis] = props[axis] as number;
|
||||
}
|
||||
|
||||
function restoreGsapPosition(element: Styled): void {
|
||||
@@ -227,6 +236,18 @@ function clearProps(element: Styled, saved: Before): void {
|
||||
putLiveDraftsBack();
|
||||
}
|
||||
|
||||
function settleTranslateUnderGsap(element: Styled): void {
|
||||
restore(element, ["translate"]);
|
||||
const under = getComputedStyle(element).getPropertyValue("translate");
|
||||
if (under && under !== "none") element.style.setProperty("translate", "none");
|
||||
}
|
||||
|
||||
function dropDrawnTranslate(element: Styled, saved: Before): void {
|
||||
if (saved.gsapPosition !== undefined) return settleTranslateUnderGsap(element);
|
||||
if (element.style.getPropertyValue("translate") === saved.drawnTranslate)
|
||||
restore(element, ["translate"]);
|
||||
}
|
||||
|
||||
function end(element: Styled, ending: EditingDraftEnd): boolean {
|
||||
const saved = before.get(element);
|
||||
if (!saved || ("draft" in ending && ending.draft !== saved.draft)) return false;
|
||||
@@ -237,7 +258,7 @@ function end(element: Styled, ending: EditingDraftEnd): boolean {
|
||||
restoreGsapPosition(element);
|
||||
restoreGsapRotation(element);
|
||||
}
|
||||
if (ending.end === "keep-size") restore(element, ["translate"]);
|
||||
if (ending.end === "keep-size") dropDrawnTranslate(element, saved);
|
||||
before.delete(element);
|
||||
return ending.end === "restore";
|
||||
}
|
||||
|
||||
@@ -159,13 +159,15 @@ describe("gesture start", () => {
|
||||
expect(card.getAttribute("style")).toBe("translate: 10px 20px;");
|
||||
});
|
||||
|
||||
it("leaves GSAP out of an element it does not move, without asking it for x", () => {
|
||||
// fails without the fix: a sealed resize handed to GSAP started a layer GSAP does not move at x/y 0, 0.
|
||||
it("reads GSAP's x/y for an element it does not move, without GSAP taking it over", () => {
|
||||
const card = turnedCard("");
|
||||
const getProperty = gsapWith([tween(document.body, { x: 10 }, 1)]);
|
||||
gsapWith([tween(document.body, { x: 10 }, 1)], { x: 40, y: 30 });
|
||||
const [start] = gestureStart([handleFor(card)]).elements;
|
||||
expect(start!.gsap).toBeNull();
|
||||
expect(getProperty).not.toHaveBeenCalled();
|
||||
expect(start!.gsapAt).toEqual({ x: 40, y: 30 });
|
||||
expect(card.getAttribute("style")).toBe("");
|
||||
expect("_gsap" in card).toBe(false);
|
||||
});
|
||||
|
||||
it.each<[string, (card: HTMLElement) => Tween, boolean]>([
|
||||
|
||||
@@ -29,8 +29,9 @@ export interface EditingGestureStart extends EditingElementGeometry {
|
||||
move: { a: number; b: number; c: number; d: number } | null;
|
||||
/** Frame px its centre moves per px of drawn width, `a, b`, and height, `c, d`; null when it has no box. */
|
||||
grow: { a: number; b: number; c: number; d: number } | null;
|
||||
/** Set when GSAP owns its position: its x/y now, and whether a tween with a duration moves it. */
|
||||
/** Set when GSAP owns its position: x/y, whether a tween moves it. `gsapAt`: read when null; 0, 0 with no GSAP. */
|
||||
gsap: { x: number; y: number; moving: boolean; drawsTranslate: true } | null;
|
||||
gsapAt: { x: number; y: number };
|
||||
/** GSAP's rotation now when it owns the element's turn; null when it turns by its own CSS `rotate`. */
|
||||
gsapRotation: number | null;
|
||||
cssRotation: CssRotationStart | null;
|
||||
@@ -263,6 +264,10 @@ export function gestureStart(handles: readonly EditingElementHandle[]): {
|
||||
move: measureMoveResponse(element),
|
||||
grow: measureGrowResponse(element, geometry.layout),
|
||||
gsap: gsapPosition(element),
|
||||
gsapAt: withoutGsapTakeover(element, () => ({
|
||||
x: readGsap(element, "x"),
|
||||
y: readGsap(element, "y"),
|
||||
})),
|
||||
gsapRotation: rotation,
|
||||
cssRotation: rotation === null ? readCssRotationStart(element as HTMLElement) : null,
|
||||
planar: planarOf(element),
|
||||
|
||||
@@ -575,7 +575,7 @@ it("a sealed move's save ends its draft in the same frame message, and the teard
|
||||
const { iframe } = await dragBoxOnSealedFrame(SCRIPT, undefined, undefined, async (frame) => {
|
||||
await savePosition({ kind: "global-set", props: { x: 110, y: 40 } })(frame);
|
||||
const box = document.getElementById("box")!;
|
||||
expect([box.style.translate, drawnAt(box)]).toEqual(["", { x: 110, y: 40 }]);
|
||||
expect([box.style.translate, drawnAt(box)]).toEqual(["none", { x: 110, y: 40 }]);
|
||||
});
|
||||
const [[, , params]] = patchRequests() as unknown as [
|
||||
[unknown, unknown, { endsDrafts?: unknown[] }],
|
||||
@@ -662,7 +662,7 @@ describe("a newer gesture that takes the element before the older save lands", (
|
||||
await dragBoxOnSealedFrame(later, undefined, regrab(7), async (iframe, standIn) => {
|
||||
await savePosition({ kind: "global-set", props: { x: 110, y: 40 } })(iframe);
|
||||
endPreviewDraft(standIn, "restore");
|
||||
await vi.waitFor(() => expect(box().style.translate).toBe(""));
|
||||
await vi.waitFor(() => expect(box().style.translate).toBe("none"));
|
||||
expect(drawnAt(box())).toEqual({ x: 110, y: 40 });
|
||||
});
|
||||
});
|
||||
@@ -705,7 +705,7 @@ describe("a newer gesture that takes the element before the older save lands", (
|
||||
armPreviewDraftEnd(standIn, "#box");
|
||||
await savePosition({ kind: "global-set", props: { x: 110, y: 40 } })(iframe);
|
||||
expect(savedEnds()).toEqual([expect.objectContaining({ end: "keep-size" })]);
|
||||
expect([box().style.translate, drawnAt(box())]).toEqual(["", { x: 110, y: 40 }]);
|
||||
expect([box().style.translate, drawnAt(box())]).toEqual(["none", { x: 110, y: 40 }]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -340,7 +340,7 @@ export function createManualOffsetDragMember(input: {
|
||||
}): ManualOffsetDragMemberResult {
|
||||
const { start, gesture } = input;
|
||||
const plainTranslate = start
|
||||
? !start.gsap
|
||||
? !start.gsap && (gesture !== "resize" || editsPlainCss(input.element, "resize"))
|
||||
: !!gesture && editsPlainCss(input.element, gesture === "resize" ? "resize" : "move");
|
||||
// The APPLIED offset, never a dormant var, so a stale one can't fling the element off-screen.
|
||||
const initialOffset = plainTranslate
|
||||
@@ -357,7 +357,8 @@ export function createManualOffsetDragMember(input: {
|
||||
// getProperty makes GSAP bake the CSS translate into its transform, so a plain move never reads it.
|
||||
const gsapX = (!plainTranslate && win?.gsap?.getProperty?.(input.element, "x")) || 0;
|
||||
const gsapY = (!plainTranslate && win?.gsap?.getProperty?.(input.element, "y")) || 0;
|
||||
const baseGsap = start?.gsap ? { x: start.gsap.x, y: start.gsap.y } : { x: gsapX, y: gsapY };
|
||||
const atPress = start ? (start.gsap ?? start.gsapAt) : undefined;
|
||||
const baseGsap = atPress ? { x: atPress.x, y: atPress.y } : { x: gsapX, y: gsapY };
|
||||
const moving = start?.gsap?.moving === true;
|
||||
const gsapOwnsPosition = !plainTranslate && Boolean(start ?? getOffsetDragGsap(input.element));
|
||||
const frameDraftRoute = gsapOwnsPosition && start?.gsap?.drawsTranslate ? "gsap" : undefined;
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { gsap } from "gsap";
|
||||
import { afterEach, expect, it, vi } from "vitest";
|
||||
import { makeSelection } from "../../hooks/domSelectionTestHarness";
|
||||
|
||||
const snapshot = vi.hoisted(() => ({ answers: true }));
|
||||
vi.mock("../../hooks/gsapFrameSnapshot", async (load) => {
|
||||
const real = await load<typeof import("../../hooks/gsapFrameSnapshot")>();
|
||||
const settle: typeof real.settleGsapSnapshot = (iframe) =>
|
||||
snapshot.answers ? real.settleGsapSnapshot(iframe) : Promise.resolve(false);
|
||||
return { ...real, settleGsapSnapshot: settle };
|
||||
});
|
||||
import { watchPreviewFrame } from "../../player/lib/bridgePlayback";
|
||||
import { describePreviewElements, queryPreviewElements } from "../../player/lib/previewElements";
|
||||
import { sealedPreviewFrame } from "../../player/lib/sealedPreviewFrame.test-helpers";
|
||||
import { usePlayerStore } from "../../player/store/playerStore";
|
||||
import { createManualOffsetDragMember } from "./manualOffsetDrag";
|
||||
import { askShownGestureStarts, UNANSWERED } from "./previewGestureStartRead";
|
||||
import { standInFor } from "./previewSelection";
|
||||
|
||||
// The edit accuracy bench's size layer: a tween writes its width and height, nothing moves it.
|
||||
const SIZES_BOX = `var tl = gsap.timeline({ paused: true });
|
||||
tl.to("#box", { width: 300, height: 200, duration: 2, ease: "none" }, 0);
|
||||
window.__timelines["main"] = tl;`;
|
||||
|
||||
const sized = <T extends Element>(element: T, [x, y, width, height]: number[]): T => {
|
||||
element.getBoundingClientRect = () =>
|
||||
({ x, y, width, height, left: x, top: y, right: x + width, bottom: y + height }) as DOMRect;
|
||||
return element;
|
||||
};
|
||||
|
||||
function mount() {
|
||||
document.body.innerHTML = `<div data-composition-id="main" data-width="1920" data-height="1080"><div id="box" style="translate: 40px 30px"></div></div>`;
|
||||
sized(document.getElementById("box")!, [300, 200, 100, 50]);
|
||||
// happy-dom computes no translate; this GSAP reads it as Chrome's does, for both previews.
|
||||
const getProperty = (el: Element, prop: string) =>
|
||||
prop === "x" ? 40 : prop === "y" ? 30 : gsap.getProperty(el, prop);
|
||||
const frameGsap = Object.assign(Object.create(gsap), { getProperty });
|
||||
Object.assign(window, { gsap: frameGsap, __timelines: {} });
|
||||
new Function("gsap", "window", SIZES_BOX)(frameGsap, window);
|
||||
usePlayerStore.setState({ currentTime: 1, isPlaying: false });
|
||||
}
|
||||
afterEach(() => {
|
||||
snapshot.answers = true;
|
||||
document.body.innerHTML = "";
|
||||
for (const name of ["gsap", "__timelines"]) Reflect.deleteProperty(window, name);
|
||||
usePlayerStore.setState({ currentTime: 0, isPlaying: false });
|
||||
});
|
||||
|
||||
async function pressSealedBox(routeFromSnapshot = true) {
|
||||
const { iframe: sealed, frame } = sealedPreviewFrame();
|
||||
const iframe = sized(sealed, [100, 50, 960, 540]) as HTMLIFrameElement;
|
||||
watchPreviewFrame(iframe);
|
||||
window.dispatchEvent(
|
||||
new MessageEvent("message", {
|
||||
source: frame as unknown as Window,
|
||||
origin: window.location.origin,
|
||||
data: { source: "hf-preview", type: "stage-size", width: 1920, height: 1080 },
|
||||
}),
|
||||
);
|
||||
const handle = (await queryPreviewElements(iframe, "#box"))!.matches[0]!.handle;
|
||||
const standIn = standInFor(iframe, (await describePreviewElements(iframe, [handle]))![0]!);
|
||||
const overlay = sized(document.createElement("div"), [20, 10, 1200, 800]);
|
||||
// The press's own read, with no GSAP snapshot of the frame held yet: the first resize after a load.
|
||||
const pressed = { ...makeSelection("box", standIn), id: "box", handle };
|
||||
return askShownGestureStarts(iframe, overlay, "index.html", [pressed], routeFromSnapshot);
|
||||
}
|
||||
|
||||
async function sealedResizeMember() {
|
||||
const read = await pressSealedBox();
|
||||
if (!read || read === UNANSWERED) throw new Error(`press read: ${String(read)}`);
|
||||
const { selection, rect, start } = read.shown[0]!;
|
||||
return createManualOffsetDragMember({
|
||||
key: "box",
|
||||
selection,
|
||||
element: selection.element,
|
||||
rect,
|
||||
gesture: "resize",
|
||||
start,
|
||||
});
|
||||
}
|
||||
|
||||
function openResizeMember() {
|
||||
const box = document.getElementById("box")!;
|
||||
const rect = { left: 300, top: 200, width: 100, height: 50, editScaleX: 1, editScaleY: 1 };
|
||||
return createManualOffsetDragMember({
|
||||
key: "box",
|
||||
selection: { ...makeSelection("box", box), id: "box" },
|
||||
element: box,
|
||||
rect,
|
||||
gesture: "resize",
|
||||
});
|
||||
}
|
||||
|
||||
// fails without the fix: sealed, a resize took its route from the press read's GSAP position alone, so a layer whose
|
||||
// tween writes only its size was resized as plain CSS: an inline width and height in the file, no keyframe.
|
||||
it.each(["unsealed", "sealed"])(
|
||||
"resizes a layer whose tween writes its size on GSAP's route, %s",
|
||||
async (mode) => {
|
||||
mount();
|
||||
const result = mode === "sealed" ? await sealedResizeMember() : openResizeMember();
|
||||
|
||||
expect(result.ok && result.member.plainTranslate).toBe(false);
|
||||
},
|
||||
);
|
||||
|
||||
// fails without the fix: the press chose its route before the frame's GSAP snapshot arrived, so it could not tell.
|
||||
it("does not start a sealed resize when the frame's GSAP snapshot does not arrive", async () => {
|
||||
mount();
|
||||
snapshot.answers = false;
|
||||
|
||||
expect(await pressSealedBox()).toBe(UNANSWERED);
|
||||
});
|
||||
|
||||
// fails without the fix: every sealed press waited on the snapshot, so a move, rotate or nudge failed with it.
|
||||
it("starts a sealed press that does not route from the snapshot when the snapshot does not arrive", async () => {
|
||||
mount();
|
||||
snapshot.answers = false;
|
||||
|
||||
const read = await pressSealedBox(false);
|
||||
|
||||
expect(read !== UNANSWERED && read?.shown.length).toBe(1);
|
||||
});
|
||||
|
||||
// fails without the fix: sealed, the press took a layer GSAP does not move at GSAP x/y 0, 0, so a resize handed to
|
||||
// GSAP saved a CSS-translated layer 50 px off (translate 40px 30px).
|
||||
it.each(["unsealed", "sealed"])(
|
||||
"starts a resize handed to GSAP from the x/y GSAP reads for a CSS-translated layer, %s",
|
||||
async (mode) => {
|
||||
mount();
|
||||
const result = mode === "sealed" ? await sealedResizeMember() : openResizeMember();
|
||||
|
||||
expect(result.ok && result.member.baseGsap).toEqual({ x: 40, y: 30 });
|
||||
},
|
||||
);
|
||||
@@ -217,6 +217,7 @@ describe("a gesture's start on an opaque frame", () => {
|
||||
layout: { width: 200, height: 100 },
|
||||
screenToOffset: { a: -2, b: 0, c: 0, d: 2 },
|
||||
gsap: { x: 200, y: 5, moving: false, drawsTranslate: true },
|
||||
gsapAt: { x: 200, y: 5 },
|
||||
gsapRotation: 0,
|
||||
grow: { a: -0.25, b: 0, c: 0, d: 0.25 },
|
||||
cssRotation: null,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/** A gesture on a frame Studio cannot script starts from one `gesture-start` read (core `editingGestureStart.ts`). */
|
||||
import type { EditingGestureStart } from "@hyperframes/core/runtime/editing-port";
|
||||
import { settleGsapSnapshot } from "../../hooks/gsapFrameSnapshot";
|
||||
import { previewGestureStart } from "../../player/lib/previewElements";
|
||||
import { previewRootHasNoSize, whenPreviewStageSized } from "../../player/lib/bridgePlayback";
|
||||
import { computeOverlayRootScale } from "./domEditOverlayBasis";
|
||||
@@ -18,6 +19,7 @@ export interface PreviewGestureStart {
|
||||
screenToOffset: ManualOffsetDragMatrix | null;
|
||||
/** GSAP's x/y when it owns the element's position, and whether a tween with a duration moves it. */
|
||||
gsap: { x: number; y: number; moving: boolean; drawsTranslate?: true } | null;
|
||||
gsapAt?: { x: number; y: number };
|
||||
gsapRotation?: number | null;
|
||||
grow?: { a: number; b: number; c: number; d: number };
|
||||
cssRotation?: EditingGestureStart["cssRotation"];
|
||||
@@ -73,6 +75,7 @@ export async function measurePreviewGestureStart(
|
||||
layout: start.layout,
|
||||
screenToOffset: screenToOffset(start.move),
|
||||
gsap: start.gsap,
|
||||
gsapAt: start.gsapAt,
|
||||
gsapRotation: start.gsapRotation,
|
||||
grow: start.grow
|
||||
? {
|
||||
@@ -109,6 +112,7 @@ export async function askShownGestureStarts(
|
||||
overlay: HTMLDivElement | null,
|
||||
path: string | null,
|
||||
selections: DomEditSelection[],
|
||||
routeFromSnapshot = false,
|
||||
): Promise<OverChannel | null | typeof UNANSWERED> {
|
||||
const found = await Promise.all(
|
||||
selections.map((selection) => findPreviewElementForSelection(iframe, selection, path)),
|
||||
@@ -117,8 +121,11 @@ export async function askShownGestureStarts(
|
||||
const handles = found.map((element) => element?.handle);
|
||||
if (!overlay || !handles.length || !handles.every(Boolean)) return null;
|
||||
await whenPreviewStageSized(iframe, PRESS_WAIT_MAX_MS);
|
||||
const read = await measurePreviewGestureStart(iframe, overlay, handles as string[]);
|
||||
if (!read) return UNANSWERED;
|
||||
const [read, gsapRouteReadable] = await Promise.all([
|
||||
measurePreviewGestureStart(iframe, overlay, handles as string[]),
|
||||
routeFromSnapshot ? settleGsapSnapshot(iframe) : true,
|
||||
]);
|
||||
if (!read || !gsapRouteReadable) return UNANSWERED;
|
||||
const shown = selections.flatMap((selection, i) => {
|
||||
const start = read.elements[i];
|
||||
const onFrame = found[i];
|
||||
|
||||
@@ -161,6 +161,7 @@ export function createPreviewGestureStarts(
|
||||
start: ShownStart,
|
||||
draw: WaitingPressState["draw"] = null,
|
||||
targets: () => DomEditSelection[] = () => [],
|
||||
routeFromSnapshot = false,
|
||||
): boolean => {
|
||||
const at = playheadMoment();
|
||||
const iframe = opts.iframeRef.current;
|
||||
@@ -219,6 +220,7 @@ export function createPreviewGestureStarts(
|
||||
opts.overlayRef.current,
|
||||
opts.activeCompositionPathRef.current,
|
||||
targets(),
|
||||
routeFromSnapshot,
|
||||
).then((answer) => {
|
||||
if (askedOf !== frame) return;
|
||||
overChannel = answer;
|
||||
@@ -387,6 +389,7 @@ export function createPreviewGestureStarts(
|
||||
},
|
||||
draw,
|
||||
() => (target ? [target] : []),
|
||||
kind === "resize",
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -289,16 +289,17 @@ const isCssRotation = (value: unknown) =>
|
||||
|
||||
export type ReadGestureStart = Omit<
|
||||
EditingGestureStart,
|
||||
"gsapRotation" | "cssRotation" | "planar" | "grow"
|
||||
"gsapRotation" | "cssRotation" | "planar" | "grow" | "gsapAt"
|
||||
> & {
|
||||
gsapRotation?: number | null;
|
||||
gsapAt?: EditingGestureStart["gsapAt"];
|
||||
grow?: EditingGestureStart["grow"];
|
||||
cssRotation?: EditingGestureStart["cssRotation"];
|
||||
};
|
||||
|
||||
const readGestureStart = (value: unknown): ReadGestureStart | null => {
|
||||
if (!readGeometry(value) || !isFields(value)) return null;
|
||||
const { move, gsap, gsapRotation, grow, cssRotation } = value;
|
||||
const { move, gsap, gsapAt, gsapRotation, grow, cssRotation } = value;
|
||||
const valid = [
|
||||
move === null || isFiniteFields(move, ["a", "b", "c", "d"]),
|
||||
gsap === null || (isFields(gsap) && isFiniteFields(gsap, ["x", "y"]) && isFlag(gsap.moving)),
|
||||
@@ -307,6 +308,7 @@ const readGestureStart = (value: unknown): ReadGestureStart | null => {
|
||||
const { planar: _planar, ...start } = value as unknown as EditingGestureStart;
|
||||
return {
|
||||
...start,
|
||||
gsapAt: kept(start.gsapAt, isFiniteFields(gsapAt, ["x", "y"])),
|
||||
gsapRotation: kept(start.gsapRotation, isTurnOrNull(gsapRotation)),
|
||||
grow: kept(start.grow, isFiniteFields(grow, ["a", "b", "c", "d"])),
|
||||
cssRotation: kept(start.cssRotation, isCssRotation(cssRotation)),
|
||||
|
||||
Reference in New Issue
Block a user