mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
fix(studio): GSAP keyframe and 3D previews stop throwing on a sealed preview (#7833)
This commit is contained in:
@@ -106,3 +106,22 @@ it.each([
|
||||
expect(props).toEqual(read);
|
||||
},
|
||||
);
|
||||
|
||||
/** A preview on an opaque origin: every read of its window but postMessage throws, as a browser's does. */
|
||||
function sealedPreview(): HTMLIFrameElement {
|
||||
const iframe = document.createElement("iframe");
|
||||
const win = new Proxy({} as Record<string, unknown>, {
|
||||
get: (_target, key) => {
|
||||
if (key === "postMessage") return () => undefined;
|
||||
throw new DOMException(`blocked read of ${String(key)}`, "SecurityError");
|
||||
},
|
||||
});
|
||||
Object.defineProperty(iframe, "contentWindow", { value: win });
|
||||
Object.defineProperty(iframe, "contentDocument", { value: null });
|
||||
return iframe;
|
||||
}
|
||||
|
||||
it("draws nothing on a sealed preview, whose window refuses the read", () => {
|
||||
const preview = createGsapLivePreview({ current: sealedPreview() });
|
||||
expect(() => preview({ id: "card" } as DomEditSelection, { x: 10 })).not.toThrow();
|
||||
});
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { DomEditSelection } from "./domEditingTypes";
|
||||
import { findPreviewNode } from "./domEditingElement";
|
||||
import { previewFrameOpaque } from "../../player/lib/previewChannel";
|
||||
|
||||
/**
|
||||
* Build the "live preview" callback the 3D-transform sub-view fires while a
|
||||
@@ -12,6 +13,7 @@ import { findPreviewNode } from "./domEditingElement";
|
||||
export function createGsapLivePreview(iframeRef: { readonly current: HTMLIFrameElement | null }) {
|
||||
return (el: DomEditSelection, props: Record<string, number>) => {
|
||||
const iframe = iframeRef.current;
|
||||
if (!iframe || previewFrameOpaque(iframe)) return;
|
||||
const win = iframe?.contentWindow as
|
||||
| { gsap?: { set: (t: Element, v: Record<string, number>) => void } }
|
||||
| null
|
||||
|
||||
@@ -60,3 +60,22 @@ describe("findParsedTween", () => {
|
||||
timeline.kill();
|
||||
});
|
||||
});
|
||||
|
||||
/** A preview on an opaque origin: every read of its window but postMessage throws, as a browser's does. */
|
||||
function sealedPreview(): HTMLIFrameElement {
|
||||
const iframe = document.createElement("iframe");
|
||||
const win = new Proxy({} as Record<string, unknown>, {
|
||||
get: (_target, key) => {
|
||||
if (key === "postMessage") return () => undefined;
|
||||
throw new DOMException(`blocked read of ${String(key)}`, "SecurityError");
|
||||
},
|
||||
});
|
||||
Object.defineProperty(iframe, "contentWindow", { value: win });
|
||||
Object.defineProperty(iframe, "contentDocument", { value: null });
|
||||
return iframe;
|
||||
}
|
||||
|
||||
it("finds no tween in a sealed preview, whose window refuses the read", () => {
|
||||
const edit = tween({ method: "to", properties: { x: 300 }, resolvedStart: 0, duration: 2 });
|
||||
expect(findParsedTween(sealedPreview(), document.createElement("div"), edit)).toBeNull();
|
||||
});
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { GsapAnimation } from "@hyperframes/core/gsap-parser";
|
||||
import { elementTargets } from "../utils/elementGsap";
|
||||
import { resolveTweenStart } from "../utils/globalTimeCompiler";
|
||||
import { KEYFRAME_PCT_MATCH } from "./gsapShared";
|
||||
import { previewFrameOpaque } from "../player/lib/previewChannel";
|
||||
import type { ImplicitEndValue } from "./gsapValueAtPlayhead";
|
||||
import type { ReadTween } from "./gsapRuntimeKeyframes";
|
||||
|
||||
@@ -81,7 +82,8 @@ export function findParsedTween(
|
||||
element: Element,
|
||||
anim: GsapAnimation,
|
||||
): ParsedTween | null {
|
||||
const win = iframe?.contentWindow as GsapWindow | null;
|
||||
if (!iframe || previewFrameOpaque(iframe)) return null;
|
||||
const win = iframe.contentWindow as GsapWindow | null;
|
||||
const start = resolveTweenStart(anim);
|
||||
if (!win?.__timelines || start == null) return null;
|
||||
const steps = anim.keyframes?.keyframes.map((kf) => kf.properties) ?? [anim.properties];
|
||||
|
||||
Reference in New Issue
Block a user