@hyperframes/studio 0.9.64 → 0.9.66
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/hyperframes-player-VGx6ow_e.js +573 -0
- package/dist/assets/{index-CVmmHGol.js → index-B8Xt_Oyw.js} +190 -186
- package/dist/assets/{index-DN167Uqf.js → index-BH18TdX9.js} +1 -1
- package/dist/assets/{pausedVideoDecoder-C8rhpGPx.js → pausedVideoDecoder-Bx3fGNkU.js} +1 -1
- package/dist/{chunk-VDDEXNVX.js → chunk-ESTBKVCB.js} +8 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.html +1 -1
- package/dist/index.js +1580 -882
- package/dist/player.js +1 -1
- package/package.json +8 -8
- package/src/captions/components/CaptionOverlay.sealed.test.ts +2 -25
- package/src/captions/hooks/useCaptionSync.ts +4 -1
- package/src/components/editor/LayersPanel.opaque.test.ts +4 -29
- package/src/components/editor/MotionPathOverlay.sealed.test.tsx +85 -0
- package/src/components/editor/MotionPathOverlay.tsx +26 -12
- package/src/components/editor/domEditOverlayCrop.ts +78 -15
- package/src/components/editor/domEditOverlayCropFrameLift.test.ts +64 -0
- package/src/components/editor/domEditOverlayStartGesture.ts +0 -14
- package/src/components/editor/gestureUndoRevert.ts +3 -6
- package/src/components/editor/gsapMoveSealedPreview.test.ts +247 -0
- package/src/components/editor/manualEditsSnapshot.ts +2 -0
- package/src/components/editor/manualOffsetDrag.ts +13 -18
- package/src/components/editor/plainTranslate.test.ts +22 -1
- package/src/components/editor/plainTranslate.ts +8 -6
- package/src/components/editor/previewDrafts.test.ts +13 -39
- package/src/components/editor/previewDrafts.ts +4 -0
- package/src/components/editor/previewGestureStartRead.test.ts +59 -32
- package/src/components/editor/previewGestureStartRead.ts +9 -0
- package/src/components/editor/previewLayers.test.ts +3 -20
- package/src/components/editor/previewOverlayRects.test.ts +3 -20
- package/src/components/editor/previewPointerTargets.test.ts +3 -20
- package/src/components/editor/previewSelection.test.ts +51 -35
- package/src/components/editor/previewSelection.ts +18 -0
- package/src/components/editor/useColorGradingController.sealed.test.ts +5 -30
- package/src/components/editor/useMotionPathData.reply.test.ts +40 -0
- package/src/components/editor/useMotionPathData.sealed.test.ts +57 -0
- package/src/components/editor/useMotionPathData.test.tsx +1 -1
- package/src/components/editor/useMotionPathData.ts +83 -33
- package/src/components/nle/CompositionBreadcrumb.tsx +2 -5
- package/src/components/nle/NLEContext.drillDown.test.ts +85 -0
- package/src/components/nle/NLEContext.tsx +21 -23
- package/src/components/nle/NLEPreview.test.ts +18 -3
- package/src/components/nle/NLEPreview.tsx +10 -1
- package/src/components/nle/audioSealedPreview.test.ts +5 -32
- package/src/components/panels/motionBlurPanelModel.sealed.test.ts +30 -0
- package/src/components/panels/motionBlurPanelModel.ts +37 -7
- package/src/hooks/appHotkeysDispatch.ts +38 -1
- package/src/hooks/domEditCommits.sealed.test.ts +191 -0
- package/src/hooks/domStyleCommit.ts +18 -7
- package/src/hooks/draggedGsapPosition.ts +20 -0
- package/src/hooks/gsapEditOutcome.ts +3 -0
- package/src/hooks/gsapFrameSnapshot.test.ts +113 -0
- package/src/hooks/gsapFrameSnapshot.ts +246 -0
- package/src/hooks/gsapParsedTween.ts +16 -9
- package/src/hooks/gsapResizeIntercept.ts +7 -2
- package/src/hooks/gsapRuntimeBridge.ts +4 -0
- package/src/hooks/gsapRuntimeKeyframes.ts +23 -15
- package/src/hooks/gsapShared.ts +4 -0
- package/src/hooks/gsapSnapshotReply.ts +105 -0
- package/src/hooks/useAppHotkeys.previewForwarding.test.tsx +134 -0
- package/src/hooks/useAppHotkeys.ts +36 -1
- package/src/hooks/useDomEditAttributeCommits.ts +43 -19
- package/src/hooks/useDomEditCommits.test.tsx +1 -1
- package/src/hooks/useDomEditPreviewSync.test.ts +36 -1
- package/src/hooks/useDomEditPreviewSync.ts +3 -3
- package/src/hooks/useEditorSave.ts +2 -1
- package/src/hooks/useEnableKeyframes.sealed.test.ts +70 -0
- package/src/hooks/useEnableKeyframes.ts +9 -2
- package/src/hooks/useGsapTweenCache.ts +9 -3
- package/src/hooks/usePreviewPersistence.ts +18 -11
- package/src/hooks/useSdkSession.lifecycle.test.tsx +1 -0
- package/src/hooks/useSdkSession.ts +2 -0
- package/src/hooks/useSlideshowTabState.test.ts +47 -3
- package/src/hooks/useSlideshowTabState.ts +32 -16
- package/src/player/hooks/timelinePlayerTestHarness.ts +2 -1
- package/src/player/hooks/usePlaybackKeyboard.ts +1 -1
- package/src/player/hooks/useTimelineSyncCallbacks.sealed.test.ts +2 -29
- package/src/player/lib/previewChannel.test.ts +10 -0
- package/src/player/lib/previewChannel.ts +9 -0
- package/src/player/lib/previewElements.test.ts +34 -1
- package/src/player/lib/previewElements.ts +101 -18
- package/src/player/lib/sealedPreviewFrame.test-helpers.ts +38 -0
- package/src/player/lib/timelineIframeHelpers.ts +1 -1
- package/src/telemetry/client.ts +4 -2
- package/src/telemetry/eventShape.test.ts +189 -0
- package/src/telemetry/eventShape.ts +192 -0
- package/src/utils/blockInstaller.test.ts +82 -48
- package/src/utils/blockInstaller.ts +6 -14
- package/src/utils/domEditSaveQueue.test.ts +12 -2
- package/src/utils/domEditSaveQueue.ts +4 -4
- package/src/utils/previewCompositionSize.test.ts +61 -0
- package/src/utils/previewCompositionSize.ts +21 -1
- package/src/utils/sdkEditTransaction.ts +6 -2
- package/src/utils/sdkResolverShadow.ts +16 -15
- package/src/utils/studioSaveDiagnostics.test.ts +21 -3
- package/src/utils/studioSaveDiagnostics.ts +71 -6
- package/src/utils/studioTelemetry.ts +6 -1
- package/dist/assets/hyperframes-player-mSF_GvRs.js +0 -573
- package/src/components/editor/motionPathHome.ts +0 -75
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { act, createElement, useRef } from "react";
|
|
3
|
+
import { createRoot } from "react-dom/client";
|
|
4
|
+
import { afterEach, beforeEach, expect, it, vi } from "vitest";
|
|
5
|
+
import { usePlayerStore } from "../../player/store/playerStore";
|
|
6
|
+
import { resetOverlayFrameLoopForTests } from "./overlayFrameLoop";
|
|
7
|
+
import { useMotionPathData } from "./useMotionPathData";
|
|
8
|
+
import { sealedPreviewFrame } from "../../player/lib/sealedPreviewFrame.test-helpers";
|
|
9
|
+
|
|
10
|
+
Reflect.set(globalThis, "IS_REACT_ACT_ENVIRONMENT", true);
|
|
11
|
+
|
|
12
|
+
const originalRaf = window.requestAnimationFrame;
|
|
13
|
+
let frames: Array<() => void> = [];
|
|
14
|
+
const runFrames = () =>
|
|
15
|
+
act(() => {
|
|
16
|
+
const batch = frames;
|
|
17
|
+
frames = [];
|
|
18
|
+
for (const frame of batch) frame();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
window.requestAnimationFrame = ((callback: FrameRequestCallback) =>
|
|
23
|
+
frames.push(() => callback(performance.now()))) as typeof window.requestAnimationFrame;
|
|
24
|
+
// Armed, so the hook measures the layer before there is a path to draw.
|
|
25
|
+
usePlayerStore.setState({ previewBooted: true, motionPathArmed: true });
|
|
26
|
+
});
|
|
27
|
+
afterEach(() => {
|
|
28
|
+
resetOverlayFrameLoopForTests();
|
|
29
|
+
window.requestAnimationFrame = originalRaf;
|
|
30
|
+
usePlayerStore.setState({ previewBooted: false, motionPathArmed: false });
|
|
31
|
+
document.body.innerHTML = "";
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// fails without the fix: the hook read the layer from the frame's document, which a sealed frame keeps.
|
|
35
|
+
it("finds a sealed preview's layer home, so its motion path draws from the layer", async () => {
|
|
36
|
+
document.body.innerHTML = `<main data-composition-id="main"><div id="box"></div></main>`;
|
|
37
|
+
const box = document.getElementById("box")!;
|
|
38
|
+
const layout = { offsetLeft: 100, offsetTop: 50, offsetWidth: 200, offsetHeight: 100 };
|
|
39
|
+
for (const [key, value] of Object.entries(layout)) Object.defineProperty(box, key, { value });
|
|
40
|
+
const iframe = sealedPreviewFrame().iframe;
|
|
41
|
+
let home: unknown = null;
|
|
42
|
+
function Probe() {
|
|
43
|
+
const ref = useRef(iframe);
|
|
44
|
+
home = useMotionPathData(ref, "#box").home;
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
const root = createRoot(document.body.appendChild(document.createElement("div")));
|
|
48
|
+
try {
|
|
49
|
+
act(() => root.render(createElement(Probe)));
|
|
50
|
+
await vi.waitFor(() => {
|
|
51
|
+
runFrames();
|
|
52
|
+
expect(home).toEqual({ x: 200, y: 100, w: 200, h: 100, ax: 0, ay: 0 });
|
|
53
|
+
});
|
|
54
|
+
} finally {
|
|
55
|
+
act(() => root.unmount());
|
|
56
|
+
}
|
|
57
|
+
});
|
|
@@ -3,7 +3,7 @@ import { gsap } from "gsap";
|
|
|
3
3
|
import { act, useRef } from "react";
|
|
4
4
|
import { createRoot } from "react-dom/client";
|
|
5
5
|
import { afterEach, beforeEach, expect, it, vi } from "vitest";
|
|
6
|
-
import { elementHome } from "
|
|
6
|
+
import { elementHome } from "@hyperframes/core/runtime/editing-port";
|
|
7
7
|
import { useMotionPathData } from "./useMotionPathData";
|
|
8
8
|
import { resetOverlayFrameLoopForTests } from "./overlayFrameLoop";
|
|
9
9
|
import { usePlayerStore } from "../../player/store/playerStore";
|
|
@@ -2,32 +2,19 @@ import { useEffect, useRef, useState, type RefObject } from "react";
|
|
|
2
2
|
import { isHtmlElement } from "@hyperframes/core/runtime/dom-realm";
|
|
3
3
|
import { readRuntimeKeyframes } from "../../hooks/gsapRuntimeKeyframes";
|
|
4
4
|
import { readGsapPositionFromIframe } from "../../hooks/gsapPositionDetection";
|
|
5
|
+
import { elementHome, transformWDivisor } from "@hyperframes/core/runtime/editing-port";
|
|
5
6
|
import { isElementVisibleForOverlay } from "./domEditOverlayGeometry";
|
|
6
7
|
import {
|
|
7
8
|
buildMotionPathGeometry,
|
|
8
9
|
type MotionPathGeometry,
|
|
9
10
|
type MotionPathHome,
|
|
10
11
|
} from "./motionPathGeometry";
|
|
11
|
-
import { elementHome } from "./motionPathHome";
|
|
12
12
|
import { subscribeOverlayFrame } from "./overlayFrameLoop";
|
|
13
13
|
import { usePlayerStore } from "../../player/store/playerStore";
|
|
14
|
+
import { previewFrameOpaque, previewRequest } from "../../player/lib/previewChannel";
|
|
14
15
|
|
|
15
16
|
type Rect = { left: number; top: number; width: number; height: number };
|
|
16
17
|
|
|
17
|
-
// Perspective foreshortening of the element's OWN transform (matrix3d m44). A
|
|
18
|
-
// depth element (translateZ toward the viewer) renders 1/m44× larger, so its
|
|
19
|
-
// animated x/y offsets travel 1/m44× further on screen than the flat preview
|
|
20
|
-
// scale implies. Returns 1 for 2D transforms. The motion path magnifies its
|
|
21
|
-
// offset points by 1/m44 (and de-magnifies pointer→offset) so the drawn path and
|
|
22
|
-
// its draggable nodes track the projected element instead of drifting off it.
|
|
23
|
-
export function transformWDivisor(el: HTMLElement): number {
|
|
24
|
-
const t = el.ownerDocument?.defaultView?.getComputedStyle(el).transform;
|
|
25
|
-
if (!t || !t.startsWith("matrix3d(")) return 1;
|
|
26
|
-
const v = t.slice("matrix3d(".length, -1).split(",");
|
|
27
|
-
const w = Number.parseFloat(v[15] ?? "");
|
|
28
|
-
return Number.isFinite(w) && w > 0 ? w : 1;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
18
|
function rectsClose(a: Rect, b: Rect): boolean {
|
|
32
19
|
return (
|
|
33
20
|
Math.abs(a.left - b.left) < 0.5 &&
|
|
@@ -37,7 +24,10 @@ function rectsClose(a: Rect, b: Rect): boolean {
|
|
|
37
24
|
);
|
|
38
25
|
}
|
|
39
26
|
|
|
27
|
+
const sealedPlugins = new WeakMap<HTMLIFrameElement, boolean>();
|
|
28
|
+
|
|
40
29
|
export function hasMotionPathPlugin(iframe: HTMLIFrameElement | null): boolean {
|
|
30
|
+
if (iframe && previewFrameOpaque(iframe)) return sealedPlugins.get(iframe) ?? false;
|
|
41
31
|
try {
|
|
42
32
|
return Boolean(
|
|
43
33
|
(iframe?.contentWindow as unknown as { MotionPathPlugin?: unknown })?.MotionPathPlugin,
|
|
@@ -47,6 +37,40 @@ export function hasMotionPathPlugin(iframe: HTMLIFrameElement | null): boolean {
|
|
|
47
37
|
}
|
|
48
38
|
}
|
|
49
39
|
|
|
40
|
+
type SealedHome = { visible: boolean; home: MotionPathHome | null; perspective: number };
|
|
41
|
+
|
|
42
|
+
const sameHome = (a: MotionPathHome, b: MotionPathHome) =>
|
|
43
|
+
Math.abs(a.x - b.x) < 0.5 &&
|
|
44
|
+
Math.abs(a.y - b.y) < 0.5 &&
|
|
45
|
+
a.w === b.w &&
|
|
46
|
+
a.h === b.h &&
|
|
47
|
+
a.ax === b.ax &&
|
|
48
|
+
a.ay === b.ay;
|
|
49
|
+
|
|
50
|
+
const HOME_FIELDS = ["x", "y", "w", "h", "ax", "ay"] as const;
|
|
51
|
+
|
|
52
|
+
/** The reply is frame data, so its shape is checked. */
|
|
53
|
+
function readHome(value: unknown): MotionPathHome | null {
|
|
54
|
+
if (typeof value !== "object" || value === null) return null;
|
|
55
|
+
const fields = value as Record<string, unknown>;
|
|
56
|
+
const ok = HOME_FIELDS.every((name) => Number.isFinite(fields[name]));
|
|
57
|
+
return ok ? (Object.fromEntries(HOME_FIELDS.map((n) => [n, fields[n]])) as MotionPathHome) : null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Where a sealed frame's first match of `selector` draws its path from; null when it cannot say. */
|
|
61
|
+
export async function sealedMotionPathHome(
|
|
62
|
+
iframe: HTMLIFrameElement,
|
|
63
|
+
selector: string,
|
|
64
|
+
): Promise<(SealedHome & { plugin: boolean }) | null> {
|
|
65
|
+
const reply = await previewRequest(iframe, "motion-path-home", { selector });
|
|
66
|
+
if (!reply || typeof reply.plugin !== "boolean" || typeof reply.visible !== "boolean")
|
|
67
|
+
return null;
|
|
68
|
+
sealedPlugins.set(iframe, reply.plugin);
|
|
69
|
+
const perspective =
|
|
70
|
+
Number.isFinite(reply.perspective) && reply.perspective > 0 ? reply.perspective : 1;
|
|
71
|
+
return { visible: reply.visible, home: readHome(reply.home), perspective, plugin: reply.plugin };
|
|
72
|
+
}
|
|
73
|
+
|
|
50
74
|
export function useMotionPathData(
|
|
51
75
|
iframeRef: RefObject<HTMLIFrameElement | null>,
|
|
52
76
|
selector: string | null,
|
|
@@ -91,6 +115,10 @@ export function useMotionPathData(
|
|
|
91
115
|
height: r.height,
|
|
92
116
|
};
|
|
93
117
|
setRect((prev) => (prev && rectsClose(prev, next) ? prev : next));
|
|
118
|
+
if (previewFrameOpaque(el)) {
|
|
119
|
+
askSealed(el);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
94
122
|
let target: Element | null = null;
|
|
95
123
|
try {
|
|
96
124
|
target = el.contentDocument?.querySelector(selector) ?? null;
|
|
@@ -98,29 +126,51 @@ export function useMotionPathData(
|
|
|
98
126
|
/* cross-origin guard */
|
|
99
127
|
}
|
|
100
128
|
const live = isHtmlElement(target) ? target : null;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
setHome((prev) =>
|
|
106
|
-
prev &&
|
|
107
|
-
Math.abs(prev.x - h.x) < 0.5 &&
|
|
108
|
-
Math.abs(prev.y - h.y) < 0.5 &&
|
|
109
|
-
prev.w === h.w &&
|
|
110
|
-
prev.h === h.h &&
|
|
111
|
-
prev.ax === h.ax &&
|
|
112
|
-
prev.ay === h.ay
|
|
113
|
-
? prev
|
|
114
|
-
: h,
|
|
115
|
-
);
|
|
116
|
-
const ps = 1 / transformWDivisor(live);
|
|
117
|
-
setPScale((p) => (Math.abs(p - ps) < 0.001 ? p : ps));
|
|
129
|
+
if (!live) apply({ visible: true, home: null, perspective: 1 });
|
|
130
|
+
else {
|
|
131
|
+
const visible = isElementVisibleForOverlay(live);
|
|
132
|
+
apply({ visible, home: elementHome(live), perspective: 1 / transformWDivisor(live) });
|
|
118
133
|
}
|
|
119
134
|
}
|
|
120
135
|
};
|
|
121
|
-
|
|
136
|
+
const apply = ({ visible, home: h, perspective: ps }: SealedHome) => {
|
|
137
|
+
setVisibleInPreview((prev) => (prev === visible ? prev : visible));
|
|
138
|
+
if (!h) return;
|
|
139
|
+
setHome((prev) => (prev && sameHome(prev, h) ? prev : h));
|
|
140
|
+
setPScale((p) => (Math.abs(p - ps) < 0.001 ? p : ps));
|
|
141
|
+
};
|
|
142
|
+
// One request at a time; a tick while it is out skips, the next one after it asks again.
|
|
143
|
+
let asking = false;
|
|
144
|
+
let stopped = false;
|
|
145
|
+
const askSealed = (frame: HTMLIFrameElement) => {
|
|
146
|
+
if (asking) return;
|
|
147
|
+
asking = true;
|
|
148
|
+
void sealedMotionPathHome(frame, selector).then((reply) => {
|
|
149
|
+
asking = false;
|
|
150
|
+
if (reply && !stopped) apply(reply);
|
|
151
|
+
});
|
|
152
|
+
};
|
|
153
|
+
const stop = subscribeOverlayFrame(tick);
|
|
154
|
+
return () => {
|
|
155
|
+
stopped = true;
|
|
156
|
+
stop();
|
|
157
|
+
};
|
|
122
158
|
}, [selector, iframeRef, drawn]);
|
|
123
159
|
|
|
160
|
+
// A sealed frame says whether it has the plugin only when asked; re-render once it has.
|
|
161
|
+
const [, notePlugin] = useState(false);
|
|
162
|
+
useEffect(() => {
|
|
163
|
+
const frame = iframeRef.current;
|
|
164
|
+
if (!selector || !frame || !previewFrameOpaque(frame)) return;
|
|
165
|
+
let current = true;
|
|
166
|
+
void sealedMotionPathHome(frame, selector).then((reply) => {
|
|
167
|
+
if (current && reply) notePlugin(reply.plugin);
|
|
168
|
+
});
|
|
169
|
+
return () => {
|
|
170
|
+
current = false;
|
|
171
|
+
};
|
|
172
|
+
}, [selector, iframeRef]);
|
|
173
|
+
|
|
124
174
|
useEffect(() => {
|
|
125
175
|
if (!selector) {
|
|
126
176
|
setGeometry(null);
|
|
@@ -27,10 +27,7 @@ export function CompositionBreadcrumb({ stack, onNavigate }: CompositionBreadcru
|
|
|
27
27
|
<button
|
|
28
28
|
type="button"
|
|
29
29
|
onClick={() => {
|
|
30
|
-
trackStudioEvent("navigation", {
|
|
31
|
-
action: "back",
|
|
32
|
-
target: stack[stack.length - 2]?.label,
|
|
33
|
-
});
|
|
30
|
+
trackStudioEvent("navigation", { action: "back", level: stack.length - 2 });
|
|
34
31
|
onNavigate(stack.length - 2);
|
|
35
32
|
}}
|
|
36
33
|
className="flex items-center gap-1 px-1.5 py-0.5 rounded-sm text-xs text-text-3 hover:text-text-0 hover:bg-hover active:scale-[0.98] transition-colors"
|
|
@@ -52,7 +49,7 @@ export function CompositionBreadcrumb({ stack, onNavigate }: CompositionBreadcru
|
|
|
52
49
|
<button
|
|
53
50
|
type="button"
|
|
54
51
|
onClick={() => {
|
|
55
|
-
trackStudioEvent("navigation", { action: "breadcrumb",
|
|
52
|
+
trackStudioEvent("navigation", { action: "breadcrumb", level: i });
|
|
56
53
|
onNavigate(i);
|
|
57
54
|
}}
|
|
58
55
|
className="text-xs text-text-3 hover:text-text-1 transition-colors"
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
|
|
3
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { previewRequest } from "../../player/lib/previewChannel";
|
|
5
|
+
import { hostCompositionSrc } from "./NLEContext";
|
|
6
|
+
|
|
7
|
+
vi.mock("../../player/lib/previewChannel", async (importOriginal) => {
|
|
8
|
+
const actual = await importOriginal<typeof import("../../player/lib/previewChannel")>();
|
|
9
|
+
return { ...actual, previewRequest: vi.fn(async () => null) };
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
afterEach(() => vi.mocked(previewRequest).mockReset());
|
|
13
|
+
|
|
14
|
+
const HANDLE = "0123456789abcdef:1";
|
|
15
|
+
const NO_SOURCE = { file: null, compositionId: null, originalCompositionId: null };
|
|
16
|
+
|
|
17
|
+
function sealedPreview(): HTMLIFrameElement {
|
|
18
|
+
const iframe = document.createElement("iframe");
|
|
19
|
+
Object.defineProperty(iframe, "contentDocument", {
|
|
20
|
+
get() {
|
|
21
|
+
throw new DOMException(
|
|
22
|
+
"Blocked a frame from accessing a cross-origin frame.",
|
|
23
|
+
"SecurityError",
|
|
24
|
+
);
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
return iframe;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function preview(attributes: unknown) {
|
|
31
|
+
vi.mocked(previewRequest).mockImplementation((async (_frame: HTMLIFrameElement, kind: string) =>
|
|
32
|
+
kind === "query"
|
|
33
|
+
? { matches: [{ handle: HANDLE, source: NO_SOURCE }], truncated: false }
|
|
34
|
+
: {
|
|
35
|
+
elements: [
|
|
36
|
+
{
|
|
37
|
+
handle: HANDLE,
|
|
38
|
+
parent: null,
|
|
39
|
+
tag: "div",
|
|
40
|
+
id: "intro",
|
|
41
|
+
selector: null,
|
|
42
|
+
matchesBefore: null,
|
|
43
|
+
source: NO_SOURCE,
|
|
44
|
+
locked: false,
|
|
45
|
+
attributes,
|
|
46
|
+
inlineStyles: {},
|
|
47
|
+
text: "",
|
|
48
|
+
children: [],
|
|
49
|
+
rect: { x: 0, y: 0, width: 1, height: 1 },
|
|
50
|
+
truncated: false,
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
}) as unknown as typeof previewRequest);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
describe("hostCompositionSrc", () => {
|
|
57
|
+
it("reads a sealed preview's host for the composition over its editing port", async () => {
|
|
58
|
+
const iframe = sealedPreview();
|
|
59
|
+
preview([
|
|
60
|
+
["data-composition-id", "intro"],
|
|
61
|
+
["data-composition-src", "compositions/intro.html"],
|
|
62
|
+
]);
|
|
63
|
+
await expect(hostCompositionSrc(iframe, 'in"tro')).resolves.toBe("compositions/intro.html");
|
|
64
|
+
expect(vi.mocked(previewRequest)).toHaveBeenCalledWith(iframe, "query", {
|
|
65
|
+
selector: `[data-composition-id="in\\"tro"][data-composition-src]`,
|
|
66
|
+
});
|
|
67
|
+
expect(vi.mocked(previewRequest)).toHaveBeenCalledWith(iframe, "describe", {
|
|
68
|
+
handles: [HANDLE],
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("answers nothing for a reply the frame got wrong, rather than passing it on", async () => {
|
|
73
|
+
preview([["data-composition-src", { evil: 1 }]]);
|
|
74
|
+
await expect(hostCompositionSrc(sealedPreview(), "intro")).resolves.toBeUndefined();
|
|
75
|
+
preview("x");
|
|
76
|
+
await expect(hostCompositionSrc(sealedPreview(), "intro")).resolves.toBeUndefined();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("answers nothing when the preview has no such host or cannot answer", async () => {
|
|
80
|
+
vi.mocked(previewRequest).mockResolvedValue(null);
|
|
81
|
+
await expect(hostCompositionSrc(sealedPreview(), "intro")).resolves.toBeUndefined();
|
|
82
|
+
vi.mocked(previewRequest).mockResolvedValue({ matches: [], truncated: false });
|
|
83
|
+
await expect(hostCompositionSrc(sealedPreview(), "intro")).resolves.toBeUndefined();
|
|
84
|
+
});
|
|
85
|
+
});
|
|
@@ -11,6 +11,19 @@ import { useAssetPreviewStore } from "../../utils/assetPreviewStore";
|
|
|
11
11
|
import { createStableContext } from "../../utils/hmrStableContext";
|
|
12
12
|
import { studioApiFetch } from "../../utils/studioApiFetch";
|
|
13
13
|
import { previewReloadBegun } from "../../player/previewReloading";
|
|
14
|
+
import { describePreviewElements, queryPreviewElements } from "../../player/lib/previewElements";
|
|
15
|
+
|
|
16
|
+
/** The `data-composition-src` of the preview's host for composition `compId`, read over its editing port. */
|
|
17
|
+
export async function hostCompositionSrc(
|
|
18
|
+
iframe: HTMLIFrameElement,
|
|
19
|
+
compId: string,
|
|
20
|
+
): Promise<string | undefined> {
|
|
21
|
+
const selector = `[data-composition-id="${CSS.escape(compId)}"][data-composition-src]`;
|
|
22
|
+
const handle = (await queryPreviewElements(iframe, selector))?.matches[0]?.handle;
|
|
23
|
+
if (!handle) return undefined;
|
|
24
|
+
const [host] = (await describePreviewElements(iframe, [handle])) ?? [];
|
|
25
|
+
return host?.attributes.find(([name]) => name === "data-composition-src")?.[1] || undefined;
|
|
26
|
+
}
|
|
14
27
|
|
|
15
28
|
export function shouldDisableTimelineWhileCompositionLoading(compositionLoading: boolean): boolean {
|
|
16
29
|
return compositionLoading;
|
|
@@ -171,35 +184,20 @@ export function NLEProvider({
|
|
|
171
184
|
onCompositionChange,
|
|
172
185
|
});
|
|
173
186
|
|
|
174
|
-
//
|
|
187
|
+
// Drill into a sub-composition: its src from compIdToSrc, else from its host in the preview, else the clip's own.
|
|
175
188
|
const iframeRef_ = iframeRef;
|
|
176
189
|
const handleDrillDown = useCallback(
|
|
177
190
|
(element: TimelineElement) => {
|
|
178
191
|
if (!element.compositionSrc) return;
|
|
179
192
|
usePlayerStore.getState().setSelectedElementId(null);
|
|
180
|
-
// Check compIdToSrc map first; then scan iframe DOM; then fall through to drillDown
|
|
181
193
|
const compId = element.id;
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
);
|
|
190
|
-
if (host) {
|
|
191
|
-
resolvedPath = host.getAttribute("data-composition-src") || undefined;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
} catch {
|
|
195
|
-
/* cross-origin */
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
// Delegate with the resolved compositionSrc (may be same as original)
|
|
199
|
-
drillDown({
|
|
200
|
-
id: compId,
|
|
201
|
-
compositionSrc: resolvedPath ?? element.compositionSrc,
|
|
202
|
-
});
|
|
194
|
+
const known = compIdToSrc.get(compId);
|
|
195
|
+
const iframe = iframeRef_.current;
|
|
196
|
+
const resolve =
|
|
197
|
+
known || !iframe ? Promise.resolve(known) : hostCompositionSrc(iframe, compId);
|
|
198
|
+
void resolve.then((resolvedPath) =>
|
|
199
|
+
drillDown({ id: compId, compositionSrc: resolvedPath ?? element.compositionSrc }),
|
|
200
|
+
);
|
|
203
201
|
},
|
|
204
202
|
[compIdToSrc, drillDown, iframeRef_],
|
|
205
203
|
);
|
|
@@ -34,9 +34,8 @@ vi.mock("../../player", async () => {
|
|
|
34
34
|
ref: React.ForwardedRef<HTMLIFrameElement>,
|
|
35
35
|
) {
|
|
36
36
|
if (!props.suppressLoadingOverlay) livePlayerProps = props;
|
|
37
|
-
React.
|
|
38
|
-
|
|
39
|
-
}, [props]);
|
|
37
|
+
const onLoad = React.useRef(props.onLoad);
|
|
38
|
+
React.useEffect(() => onLoad.current?.(), []);
|
|
40
39
|
React.useState(() => playerMounts.push(props.suppressLoadingOverlay ? "shadow" : "live"));
|
|
41
40
|
|
|
42
41
|
return React.createElement("div", {
|
|
@@ -556,6 +555,22 @@ describe("NLEPreview", () => {
|
|
|
556
555
|
}
|
|
557
556
|
});
|
|
558
557
|
|
|
558
|
+
it("takes a sealed preview's size once its film is ready to show, after the frame has loaded", () => {
|
|
559
|
+
const box = { width: 800, height: 600 };
|
|
560
|
+
const sealed = renderPreview(undefined, { box, sandboxOrigin: "opaque" });
|
|
561
|
+
try {
|
|
562
|
+
expect([sealed.stage.style.width, sealed.stage.style.height]).toEqual(["784px", "441px"]);
|
|
563
|
+
measured.size = { width: 1080, height: 1920 };
|
|
564
|
+
act(() => livePlayerProps.onReadyToShowChange?.(true));
|
|
565
|
+
const shape = parseFloat(sealed.stage.style.width) / parseFloat(sealed.stage.style.height);
|
|
566
|
+
expect(shape).toBeCloseTo(1080 / 1920, 3);
|
|
567
|
+
expect(sealed.stage.style.height).toBe("584px");
|
|
568
|
+
} finally {
|
|
569
|
+
measured.size = null;
|
|
570
|
+
sealed.cleanup();
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
|
|
559
574
|
it("clips a shadow reload so its own loading overlay cannot paint over the live frame", () => {
|
|
560
575
|
const view = renderPreview([
|
|
561
576
|
{ gen: 0, role: "live" },
|
|
@@ -180,6 +180,15 @@ export const NLEPreview = memo(function NLEPreview({
|
|
|
180
180
|
onCompositionSizeChangeRef.current?.(compositionSize);
|
|
181
181
|
}, [compositionSize]);
|
|
182
182
|
|
|
183
|
+
const showLive = poster.onLiveReadyToShowChange;
|
|
184
|
+
const onLiveReadyToShowChange = useCallback(
|
|
185
|
+
(ready: boolean) => {
|
|
186
|
+
showLive(ready);
|
|
187
|
+
if (ready) updateCompositionSizeFromPreview();
|
|
188
|
+
},
|
|
189
|
+
[showLive, updateCompositionSizeFromPreview],
|
|
190
|
+
);
|
|
191
|
+
|
|
183
192
|
const setPreviewIframeRef = useCallback(
|
|
184
193
|
(node: HTMLIFrameElement | null) => {
|
|
185
194
|
previewIframeRef.current = node;
|
|
@@ -503,7 +512,7 @@ export const NLEPreview = memo(function NLEPreview({
|
|
|
503
512
|
applyInitialZoom();
|
|
504
513
|
}}
|
|
505
514
|
onCompositionLoadingChange={onCompositionLoadingChange}
|
|
506
|
-
onReadyToShowChange={
|
|
515
|
+
onReadyToShowChange={onLiveReadyToShowChange}
|
|
507
516
|
onPreviewError={poster.onPreviewError}
|
|
508
517
|
onPainted={(details) => reportPreviewFirstFrame(slot, details)}
|
|
509
518
|
portrait={portrait}
|
|
@@ -3,25 +3,22 @@
|
|
|
3
3
|
import { act, createElement } from "react";
|
|
4
4
|
import { createRoot, type Root } from "react-dom/client";
|
|
5
5
|
import { afterEach, beforeEach, expect, it, vi } from "vitest";
|
|
6
|
-
// The frame's real runtime agent, serving the opaque frame from this document.
|
|
7
|
-
import { installMarkedEditingAgent } from "../../../../core/src/runtime/editingAgent.test-helpers";
|
|
8
6
|
import { usePlayerStore, type TimelineElement } from "../../player";
|
|
9
7
|
import { ClipMenuAudioItems } from "../../player/components/clipMenuAudioItems";
|
|
10
8
|
import { usePreviewIframeStore } from "../../player/store/previewIframeStore";
|
|
11
9
|
import { TimelineEditProvider } from "../../contexts/TimelineEditContext";
|
|
12
10
|
import { createAudioGroupAndAssignMembers } from "../../hooks/timelineAudioGroupCreate";
|
|
13
11
|
import { mintGroupId } from "../editor/useFxCarveGrouping";
|
|
14
|
-
import { detachedFakeIframe } from "../../player/hooks/timelinePlayerTestHarness";
|
|
15
12
|
import { useAudioMetersVisible } from "../../utils/audioMeterVisibility";
|
|
16
13
|
import { useSetAudioGroupAttribute } from "../../hooks/timelineAudioGroupVolume";
|
|
17
14
|
import { previewDocumentCopy } from "../../player/lib/previewChannel";
|
|
18
15
|
import { AudioMeterStrip } from "./AudioMeterStrip";
|
|
16
|
+
import { sealedPreviewFrame } from "../../player/lib/sealedPreviewFrame.test-helpers";
|
|
19
17
|
|
|
20
18
|
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
21
19
|
|
|
22
20
|
type MeterWindow = Window & { __hf?: Record<string, unknown> };
|
|
23
21
|
|
|
24
|
-
const closers: Array<() => void> = [];
|
|
25
22
|
const roots: Root[] = [];
|
|
26
23
|
let frames: FrameRequestCallback[] = [];
|
|
27
24
|
const tick = () => {
|
|
@@ -38,7 +35,6 @@ beforeEach(() => {
|
|
|
38
35
|
});
|
|
39
36
|
afterEach(() => {
|
|
40
37
|
act(() => roots.splice(0).forEach((root) => root.unmount()));
|
|
41
|
-
closers.splice(0).forEach((close) => close());
|
|
42
38
|
delete (window as MeterWindow).__hf;
|
|
43
39
|
vi.unstubAllGlobals();
|
|
44
40
|
usePlayerStore.getState().reset();
|
|
@@ -46,29 +42,6 @@ afterEach(() => {
|
|
|
46
42
|
document.body.innerHTML = "";
|
|
47
43
|
});
|
|
48
44
|
|
|
49
|
-
/** A frame Studio cannot read, whose runtime is the real editing agent over this document. */
|
|
50
|
-
function opaqueFrame() {
|
|
51
|
-
const frame: Record<string, unknown> = {};
|
|
52
|
-
const iframe = detachedFakeIframe(frame);
|
|
53
|
-
Object.defineProperty(iframe, "contentDocument", { value: null });
|
|
54
|
-
Object.defineProperty(frame, "document", {
|
|
55
|
-
get: () => {
|
|
56
|
-
throw new DOMException("blocked", "SecurityError");
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
const parent = {
|
|
60
|
-
postMessage: (data: unknown, _origin: string, ports: MessagePort[]) =>
|
|
61
|
-
window.dispatchEvent(
|
|
62
|
-
new MessageEvent("message", { source: frame as unknown as Window, data, ports }),
|
|
63
|
-
),
|
|
64
|
-
} as unknown as Window;
|
|
65
|
-
const agent = installMarkedEditingAgent(parent);
|
|
66
|
-
frame.postMessage = (data: unknown) =>
|
|
67
|
-
window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
|
|
68
|
-
closers.push(() => agent.dispose());
|
|
69
|
-
return iframe;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
45
|
const member = (domId: string): TimelineElement => ({
|
|
73
46
|
id: domId,
|
|
74
47
|
key: `compositions/voices.html#${domId}`,
|
|
@@ -112,7 +85,7 @@ it("meter moves + group volume sealed", async () => {
|
|
|
112
85
|
};
|
|
113
86
|
(window as MeterWindow).__hf = { audioMeter: meter };
|
|
114
87
|
usePlayerStore.getState().setElements([member("voice-1")]);
|
|
115
|
-
const iframe =
|
|
88
|
+
const iframe = sealedPreviewFrame().iframe;
|
|
116
89
|
|
|
117
90
|
const host = document.createElement("div");
|
|
118
91
|
document.body.append(host);
|
|
@@ -168,7 +141,7 @@ it("groups clips in a sealed preview, and unwinds the preview when the save fail
|
|
|
168
141
|
document.body.innerHTML = `<main data-composition-id="root">
|
|
169
142
|
<audio id="voice-1" data-audio-group="old"></audio><audio id="voice-2"></audio>
|
|
170
143
|
</main>`;
|
|
171
|
-
const iframe =
|
|
144
|
+
const iframe = sealedPreviewFrame().iframe;
|
|
172
145
|
const files = new Map([["index.html", document.body.innerHTML]]);
|
|
173
146
|
stubProjectFiles(files);
|
|
174
147
|
const elements = ["voice-1", "voice-2"].map((domId) => ({
|
|
@@ -210,7 +183,7 @@ it("groups clips in a sealed preview, and unwinds the preview when the save fail
|
|
|
210
183
|
|
|
211
184
|
it("reads a sealed preview's groups and ids off an inert copy", async () => {
|
|
212
185
|
document.body.innerHTML = `<audio id="voiceover"></audio><audio id="music" src="bed.wav"></audio>`;
|
|
213
|
-
const copy = await previewDocumentCopy(
|
|
186
|
+
const copy = await previewDocumentCopy(sealedPreviewFrame().iframe);
|
|
214
187
|
expect(copy).not.toBeNull();
|
|
215
188
|
expect(copy).not.toBe(document);
|
|
216
189
|
expect(mintGroupId(copy!)).toBe("voiceover-2");
|
|
@@ -222,7 +195,7 @@ it("offers Duck under voice for a bed in a sealed preview", async () => {
|
|
|
222
195
|
<audio id="music" src="bed.wav" data-start="0" data-duration="10"></audio>
|
|
223
196
|
<audio id="voiceover" src="vo.wav" data-start="1" data-duration="2"></audio>
|
|
224
197
|
</main>`;
|
|
225
|
-
const iframe =
|
|
198
|
+
const iframe = sealedPreviewFrame().iframe;
|
|
226
199
|
usePreviewIframeStore.setState({ iframe });
|
|
227
200
|
usePlayerStore.getState().beginTimelineSession("project-1");
|
|
228
201
|
const bed: TimelineElement = {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { MOTION_BLUR_ATTR } from "@hyperframes/core/motion-blur-settings";
|
|
3
|
+
import { expect, it, vi } from "vitest";
|
|
4
|
+
|
|
5
|
+
const SHUTTER = Object.values(MOTION_BLUR_ATTR)[0]!;
|
|
6
|
+
|
|
7
|
+
vi.mock("../../player/lib/previewChannel", async (importOriginal) => ({
|
|
8
|
+
...(await importOriginal<typeof import("../../player/lib/previewChannel")>()),
|
|
9
|
+
previewFrameOpaque: () => true,
|
|
10
|
+
}));
|
|
11
|
+
vi.mock("../../player/lib/previewElements", () => ({
|
|
12
|
+
queryPreviewElements: vi.fn(async () => ({ matches: [{ handle: "0123456789abcdef:1" }] })),
|
|
13
|
+
describePreviewElements: vi.fn(async () => [
|
|
14
|
+
{
|
|
15
|
+
attributes: [
|
|
16
|
+
["data-composition-id", "main"],
|
|
17
|
+
[SHUTTER, "0.5"],
|
|
18
|
+
],
|
|
19
|
+
},
|
|
20
|
+
]),
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
import { readPreviewRootAttributes } from "./motionBlurPanelModel";
|
|
24
|
+
|
|
25
|
+
it("reads a sealed preview's root blur settings through the editing port, and only those", async () => {
|
|
26
|
+
const iframe = document.createElement("iframe");
|
|
27
|
+
|
|
28
|
+
expect(readPreviewRootAttributes(iframe)).toBeNull();
|
|
29
|
+
await vi.waitFor(() => expect(readPreviewRootAttributes(iframe)).toEqual({ [SHUTTER]: "0.5" }));
|
|
30
|
+
});
|
|
@@ -8,6 +8,8 @@ import {
|
|
|
8
8
|
motionBlurAttributeEdits,
|
|
9
9
|
readMotionBlurSettings,
|
|
10
10
|
} from "@hyperframes/core/motion-blur-settings";
|
|
11
|
+
import { previewFrameOpaque } from "../../player/lib/previewChannel";
|
|
12
|
+
import { describePreviewElements, queryPreviewElements } from "../../player/lib/previewElements";
|
|
11
13
|
|
|
12
14
|
export interface CompositionRoot {
|
|
13
15
|
id: string;
|
|
@@ -50,20 +52,48 @@ export function withEdits(
|
|
|
50
52
|
|
|
51
53
|
/** The blur attributes on the live preview's composition root: what actually runs, after an undo or an outside edit too. */
|
|
52
54
|
export function readPreviewRootAttributes(iframe: HTMLIFrameElement | null): RootAttributes | null {
|
|
55
|
+
if (iframe && previewFrameOpaque(iframe)) {
|
|
56
|
+
void askSealedRoot(iframe);
|
|
57
|
+
return sealedRoots.get(iframe) ?? null;
|
|
58
|
+
}
|
|
53
59
|
try {
|
|
54
60
|
const root = iframe?.contentDocument?.querySelector("[data-composition-id]");
|
|
55
|
-
|
|
56
|
-
const found: Record<string, string> = {};
|
|
57
|
-
for (const name of Object.values(MOTION_BLUR_ATTR)) {
|
|
58
|
-
const value = root.getAttribute(name);
|
|
59
|
-
if (value !== null) found[name] = value;
|
|
60
|
-
}
|
|
61
|
-
return found;
|
|
61
|
+
return root ? blurAttributes((name) => root.getAttribute(name)) : null;
|
|
62
62
|
} catch {
|
|
63
63
|
return null;
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
function blurAttributes(read: (name: string) => string | null | undefined): RootAttributes {
|
|
68
|
+
const found: Record<string, string> = {};
|
|
69
|
+
for (const name of Object.values(MOTION_BLUR_ATTR)) {
|
|
70
|
+
const value = read(name);
|
|
71
|
+
if (typeof value === "string") found[name] = value;
|
|
72
|
+
}
|
|
73
|
+
return found;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const sealedRoots = new WeakMap<HTMLIFrameElement, RootAttributes>();
|
|
77
|
+
const askingRoot = new WeakSet<HTMLIFrameElement>();
|
|
78
|
+
|
|
79
|
+
/** A sealed frame's root, asked one request at a time; the polled read returns the last answer. */
|
|
80
|
+
async function askSealedRoot(iframe: HTMLIFrameElement): Promise<void> {
|
|
81
|
+
if (askingRoot.has(iframe)) return;
|
|
82
|
+
askingRoot.add(iframe);
|
|
83
|
+
try {
|
|
84
|
+
const [root] = (await queryPreviewElements(iframe, "[data-composition-id]"))?.matches ?? [];
|
|
85
|
+
const [found] = root ? ((await describePreviewElements(iframe, [root.handle])) ?? []) : [];
|
|
86
|
+
if (!found) sealedRoots.delete(iframe);
|
|
87
|
+
else
|
|
88
|
+
sealedRoots.set(
|
|
89
|
+
iframe,
|
|
90
|
+
blurAttributes((name) => new Map(found.attributes).get(name)),
|
|
91
|
+
);
|
|
92
|
+
} finally {
|
|
93
|
+
askingRoot.delete(iframe);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
67
97
|
export const sameAttributes = (a: RootAttributes | null, b: RootAttributes | null): boolean =>
|
|
68
98
|
a === b ||
|
|
69
99
|
(a !== null && b !== null && Object.keys({ ...a, ...b }).every((name) => a[name] === b[name]));
|