Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/core/src/runtime/editingGestureStart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,17 @@ describe("gestureBase", () => {
expect(gestureBase(handleFor(card))).toEqual({ x: 12, y: -4, opacity: 0.5, scale: 1.5 });
});

it("answers null without GSAP, or for an element this load does not have", () => {
// fails without the fix: a page without GSAP answered null, so a sealed recording refused to start where the
// unsealed recorder starts from x 0, y 0, opacity 1 and scale 1.
it("answers the values at rest on a page without GSAP, as the unsealed recorder starts", () => {
const card = turnedCard("");
expect(gestureBase(handleFor(card))).toBeNull();
expect(gestureBase(handleFor(card))).toEqual({ x: 0, y: 0, opacity: 1, scale: 1 });
});

it("answers null for an element this load does not have", () => {
gsapWith([]);
expect(gestureBase("0123456789abcdef:999")).toBeNull();
Reflect.deleteProperty(window, "gsap");
expect(gestureBase("0123456789abcdef:999")).toBeNull();
});
});
3 changes: 2 additions & 1 deletion packages/core/src/runtime/editingGestureStart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ export type EditingGestureBase = { x: number; y: number; opacity: number; scale:
export function gestureBase(handle: EditingElementHandle): EditingGestureBase | null {
const element = elementForHandle(handle);
const gsap = (window as GsapWindow).gsap;
if (!element || !gsap?.getProperty) return null;
if (!element) return null;
if (!gsap?.getProperty) return { x: 0, y: 0, opacity: 1, scale: 1 };
const read = (property: string) => Number(gsap.getProperty?.(element, property));
const base = { x: read("x"), y: read("y"), opacity: read("opacity"), scale: read("scaleX") };
return Object.values(base).every(Number.isFinite) ? base : null;
Expand Down
Loading