From f6c9d09de834acad406a2ea60aa9a2bdbbccf692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Wed, 18 Nov 2026 19:27:41 +0000 Subject: [PATCH] fix(studio): the property panel shows a sealed preview's animated values (#8203) * fix(studio): the property panel shows a sealed preview's animated values * fix(studio): a sealed preview's panel shows rotation and scale from tweens that only turn or grow --- .../src/components/editor/PropertyPanel.tsx | 4 +- .../editor/propertyPanelGsap.sealed.test.ts | 65 +++++++++++++++++++ .../components/editor/propertyPanelHelpers.ts | 26 ++++---- .../studio/src/hooks/gsapRuntimeKeyframes.ts | 19 +++++- 4 files changed, 100 insertions(+), 14 deletions(-) create mode 100644 packages/studio/src/components/editor/propertyPanelGsap.sealed.test.ts diff --git a/packages/studio/src/components/editor/PropertyPanel.tsx b/packages/studio/src/components/editor/PropertyPanel.tsx index 957606ffa5..947ab46ef6 100644 --- a/packages/studio/src/components/editor/PropertyPanel.tsx +++ b/packages/studio/src/components/editor/PropertyPanel.tsx @@ -1,3 +1,4 @@ +import { useGsapSnapshotVersion } from "../../hooks/gsapFrameSnapshot"; import { scopedElementKey } from "../../hooks/gsapKeyframeCacheHelpers"; import { memo, useMemo, useRef, useState } from "react"; import { Move } from "../../icons/SystemIcons"; @@ -134,13 +135,14 @@ export const PropertyPanel = memo(function PropertyPanel(props: PropertyPanelPro gsapAnimations?.[0]?.id ?? null) : null; + const sealedReads = useGsapSnapshotVersion(); const gsapRuntimeValues = useMemo( () => element ? readGsapRuntimeValuesForPanel(gsapAnimIdForMemo, gsapAnimations, element, iframeRef) : null, // eslint-disable-next-line react-hooks/exhaustive-deps -- iframeRef is stable; currentTime drives re-reads during playback - [gsapAnimIdForMemo, gsapAnimations, element, currentTime], + [gsapAnimIdForMemo, gsapAnimations, element, currentTime, sealedReads], ); const gsapBorderRadius = useMemo( () => diff --git a/packages/studio/src/components/editor/propertyPanelGsap.sealed.test.ts b/packages/studio/src/components/editor/propertyPanelGsap.sealed.test.ts new file mode 100644 index 0000000000..43b649bfd3 --- /dev/null +++ b/packages/studio/src/components/editor/propertyPanelGsap.sealed.test.ts @@ -0,0 +1,65 @@ +// @vitest-environment happy-dom + +import { gsap } from "gsap"; +import { parseGsapScriptAcorn } from "@hyperframes/parsers/gsap-parser-acorn"; +import { afterEach, expect, it } from "vitest"; +import { makeSelection } from "../../hooks/domSelectionTestHarness"; +import { settleGsapSnapshot } from "../../hooks/gsapFrameSnapshot"; +import { describePreviewElements, queryPreviewElements } from "../../player/lib/previewElements"; +import { usePlayerStore } from "../../player/store/playerStore"; +import { sealedPreviewFrame } from "../../player/lib/sealedPreviewFrame.test-helpers"; +import { standInFor } from "./previewSelection"; +import { readGsapRuntimeValuesForPanel } from "./propertyPanelHelpers"; + +const script = (vars: string) => `var tl = gsap.timeline({ paused: true }); +tl.to("#box", { ${vars}, duration: 1, ease: "none" }, 0); +window.__timelines["main"] = tl;`; + +const mainTimeline = () => + (window as unknown as { __timelines?: Record }).__timelines?.main; + +afterEach(() => { + mainTimeline()?.kill(); + document.body.innerHTML = ""; + for (const name of ["gsap", "__timelines", "__player"]) Reflect.deleteProperty(window, name); + usePlayerStore.setState({ currentTime: 0, isPlaying: false }); +}); + +/** The box half way through its tween, behind a frame Studio cannot read, selected by its stand-in. */ +async function sealedBox(source: string) { + document.body.innerHTML = `
`; + Object.assign(window, { gsap, __timelines: {}, __player: { getTime: () => 0.5 } }); + new Function("gsap", "window", source)(gsap, window); + mainTimeline()?.seek(0.5); + usePlayerStore.setState({ currentTime: 0.5, isPlaying: false }); + const { iframe } = sealedPreviewFrame(); + const handle = (await queryPreviewElements(iframe, "#box"))!.matches[0]!.handle; + const standIn = standInFor(iframe, (await describePreviewElements(iframe, [handle]))![0]!); + const selection = { ...makeSelection("box", standIn), id: "box", handle }; + await settleGsapSnapshot(iframe); + return { iframe, selection, animations: parseGsapScriptAcorn(source).animations }; +} + +it("shows a sealed preview's GSAP values for the selected layer, read at the playhead", async () => { + const { iframe, selection, animations } = await sealedBox(script("x: 200, y: 80")); + const values = readGsapRuntimeValuesForPanel(animations[0]!.id, animations, selection, { + current: iframe, + }); + expect(values).toMatchObject({ x: 100, y: 40 }); +}); + +it("leaves out GSAP's transform for a sealed layer its tweens do not move", async () => { + const { iframe, selection, animations } = await sealedBox(script("opacity: 0")); + const values = readGsapRuntimeValuesForPanel(animations[0]!.id, animations, selection, { + current: iframe, + }); + expect(values).toEqual({ opacity: 0.5 }); +}); + +it("shows a sealed layer's rotation and scale when its tweens only turn and grow it", async () => { + const { iframe, selection, animations } = await sealedBox(script("rotation: 90, scale: 2")); + const values = readGsapRuntimeValuesForPanel(animations[0]!.id, animations, selection, { + current: iframe, + }); + expect(values).toMatchObject({ rotation: 45, scale: 1.5 }); +}); diff --git a/packages/studio/src/components/editor/propertyPanelHelpers.ts b/packages/studio/src/components/editor/propertyPanelHelpers.ts index c91ffcfb49..ef1a7f8b2a 100644 --- a/packages/studio/src/components/editor/propertyPanelHelpers.ts +++ b/packages/studio/src/components/editor/propertyPanelHelpers.ts @@ -9,7 +9,13 @@ import { playbackStartAttributeForElement, readPlaybackStartAttributes, } from "../../player/lib/timelineElementHelpers"; -import { editsPlainCss, GSAP_TRANSFORM_KEYS } from "../../hooks/gsapRuntimeKeyframes"; +import { + editsPlainCss, + GSAP_TRANSFORM_KEYS, + sealedGsapRendersTransform, +} from "../../hooks/gsapRuntimeKeyframes"; +import { getIframeGsap } from "../../hooks/gsapShared"; +import { previewFrameOpaque } from "../../player/lib/previewChannel"; export type { BackgroundRemovalProgress, @@ -485,18 +491,16 @@ export function readGsapRuntimeValuesForPanel( ): Record | null { if (!gsapAnimId || gsapAnimations.length === 0) return null; const iframe = previewIframeRef?.current; - if (!iframe?.contentWindow) return null; + if (!iframe) return null; try { - const gsap = ( - iframe.contentWindow as unknown as { - gsap?: { getProperty: (el: Element, prop: string) => number | string }; - } - ).gsap; - if (!gsap?.getProperty) return null; - const el = findPreviewNode(iframe.contentDocument, element); - if (!el) return null; + const gsap = getIframeGsap(iframe); + const sealed = previewFrameOpaque(iframe); + const el = sealed ? element.element : findPreviewNode(iframe.contentDocument, element); + if (!gsap || !el) return null; const propKeys = collectPanelPropKeys(gsapAnimations); - const readsTransform = !editsPlainCss(el, "move"); + const readsTransform = sealed + ? sealedGsapRendersTransform(iframe, el) + : !editsPlainCss(el, "move"); const result: Record = {}; for (const prop of propKeys) { if (!readsTransform && GSAP_TRANSFORM_KEYS.has(prop)) continue; diff --git a/packages/studio/src/hooks/gsapRuntimeKeyframes.ts b/packages/studio/src/hooks/gsapRuntimeKeyframes.ts index 514b1f0c4e..64ef1d3408 100644 --- a/packages/studio/src/hooks/gsapRuntimeKeyframes.ts +++ b/packages/studio/src/hooks/gsapRuntimeKeyframes.ts @@ -19,7 +19,7 @@ import { withParsedStart } from "./gsapParsedTween"; import { BOX_SIZE_STYLE_PROPS } from "../components/editor/manualEditsDomPatches"; import { gsapRendersTransform } from "../components/editor/gsapAnimatesProperty"; import { previewFrameOpaque } from "../player/lib/previewChannel"; -import { frameQuery, frameTimelines } from "./gsapFrameSnapshot"; +import { frameQuery, frameTarget, frameTimelines } from "./gsapFrameSnapshot"; /** * A GSAP tween's `vars` object — intentionally open: it mixes channel values @@ -280,11 +280,26 @@ export const GSAP_TRANSFORM_KEYS = new Set( ",", ), ); +const TRANSFORM_CHANNELS = [...MOVE_CHANNELS, ...GSAP_TRANSFORM_KEYS]; + +/** Sealed `!editsPlainCss(el, "move")`: the frame snapshot's tweens move or transform `el`. */ +export function sealedGsapRendersTransform(iframe: HTMLIFrameElement, el: Element): boolean { + const target = frameTarget(iframe, el); + return !!target && timelinesWriteChannels(frameTimelines(iframe), target, TRANSFORM_CHANNELS); +} /** Whether a live timeline tween or hold writes any of `channels` on `el`. Sync, no fetch. */ export function gsapWritesChannels(el: Element, channels: string[]): boolean { const win = el.ownerDocument.defaultView as { __timelines?: Record }; - return Object.values(win?.__timelines ?? {}).some((tl) => + return timelinesWriteChannels(win?.__timelines ?? null, el, channels); +} + +function timelinesWriteChannels( + timelines: Record | null, + el: Element, + channels: string[], +): boolean { + return Object.values(timelines ?? {}).some((tl) => tweensTargeting(tl, el).some( (tween) => !!tween.vars &&