@hyperframes/studio 0.9.58 → 0.9.61
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-Cm0hYGm2.js +573 -0
- package/dist/assets/{index-D7ICtobF.js → index-BGrNWeLK.js} +199 -199
- package/dist/assets/{index-ww7-RmuM.js → index-REqr_dLu.js} +1 -1
- package/dist/assets/{pausedVideoDecoder-Dbe8Cmab.js → pausedVideoDecoder-DqLDSq8J.js} +1 -1
- package/dist/{chunk-5EEM5WO4.js → chunk-3KCEIESB.js} +1 -1
- package/dist/{chunk-G6FJSL7X.js → chunk-JTUKMELR.js} +34 -6
- package/dist/index.d.ts +29 -1
- package/dist/index.html +1 -1
- package/dist/index.js +734 -217
- package/dist/player.js +2 -2
- package/dist/ui.js +1 -1
- package/package.json +8 -8
- package/src/captions/components/CaptionOverlay.sealed.test.ts +273 -0
- package/src/captions/components/CaptionOverlay.tsx +112 -57
- package/src/captions/components/CaptionOverlayUtils.ts +319 -33
- package/src/captions/components/CaptionPropertyPanel.tsx +17 -0
- package/src/components/editor/LayersPanel.opaque.test.ts +2 -2
- package/src/components/editor/previewDrafts.test.ts +2 -2
- package/src/components/editor/previewGestureStartRead.test.ts +2 -2
- package/src/components/editor/previewLayers.test.ts +2 -2
- package/src/components/editor/previewOverlayRects.test.ts +2 -2
- package/src/components/editor/previewPointerTargets.test.ts +2 -2
- package/src/components/editor/previewSelection.test.ts +2 -2
- package/src/components/editor/useColorGradingController.sealed.test.ts +165 -0
- package/src/components/editor/useColorGradingController.ts +20 -1
- package/src/components/editor/useColorGradingPreviews.ts +127 -43
- package/src/components/nle/NLEPreview.test.ts +24 -0
- package/src/components/nle/NLEPreview.tsx +2 -6
- package/src/components/nle/previewStage.ts +11 -1
- package/src/components/panels/VariablesPanel.test.tsx +90 -1
- package/src/components/panels/VariablesPanel.tsx +41 -17
- package/src/components/panels/renderHandoff.test.ts +86 -0
- package/src/components/panels/renderHandoff.ts +28 -0
- package/src/components/ui/Menu.test.tsx +77 -0
- package/src/components/ui/Menu.tsx +47 -4
- package/src/components/ui/Popover.tsx +5 -2
- package/src/elementAnimations.test.ts +13 -0
- package/src/hooks/useCaptionDetection.ts +175 -54
- package/src/hooks/useMusicBeatAnalysis.test.tsx +131 -0
- package/src/hooks/useMusicBeatAnalysis.ts +51 -66
- package/src/hooks/usePersistentEditHistory.test.ts +84 -0
- package/src/hooks/usePersistentEditHistory.ts +36 -3
- package/src/hooks/useRenderClipContent.test.ts +21 -0
- package/src/hooks/useRenderClipContent.ts +3 -1
- package/src/index.ts +2 -0
- package/src/player/hooks/useShadowPreviewReload.ts +7 -0
- package/src/player/hooks/useTimelinePlayer.shadowReload.test.ts +20 -0
- package/src/player/lib/previewElements.test.ts +4 -0
- package/src/player/lib/previewElements.ts +1 -0
- package/src/sealedPreviewExports.test.ts +1 -0
- package/src/utils/gsapUndoRestore.sealed.test.ts +73 -0
- package/src/utils/gsapUndoRestore.ts +66 -0
- package/src/utils/studioPendingEdits.test.ts +20 -0
- package/src/utils/studioPendingEdits.ts +11 -4
- package/src/utils/timelineInspector.test.ts +49 -2
- package/src/utils/timelineInspector.ts +21 -2
- package/dist/assets/hyperframes-player-B78JDyI_.js +0 -565
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
|
|
3
|
+
import React, { act } from "react";
|
|
4
|
+
import { createRoot } from "react-dom/client";
|
|
5
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
import { normalizeHfColorGrading } from "@hyperframes/core/color-grading";
|
|
7
|
+
// The frame's real runtime agent, serving the opaque frame from this document.
|
|
8
|
+
import { installMarkedEditingAgent } from "../../../../core/src/runtime/editingAgent.test-helpers";
|
|
9
|
+
import { installReactActEnvironment } from "../../hooks/domSelectionTestHarness";
|
|
10
|
+
import { detachedFakeIframe } from "../../player/hooks/timelinePlayerTestHarness";
|
|
11
|
+
import type { DomEditSelection } from "./domEditing";
|
|
12
|
+
import { useColorGradingController } from "./useColorGradingController";
|
|
13
|
+
|
|
14
|
+
installReactActEnvironment();
|
|
15
|
+
|
|
16
|
+
const closers: Array<() => void> = [];
|
|
17
|
+
afterEach(() => {
|
|
18
|
+
closers.splice(0).forEach((close) => close());
|
|
19
|
+
delete (window as { __hf?: unknown }).__hf;
|
|
20
|
+
document.body.innerHTML = "";
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
/** A frame Studio cannot read, whose runtime is the real editing agent over this document. */
|
|
24
|
+
function opaqueFrame(): HTMLIFrameElement {
|
|
25
|
+
const frame: Record<string, unknown> = {};
|
|
26
|
+
const iframe = detachedFakeIframe(frame);
|
|
27
|
+
Object.defineProperty(iframe, "contentDocument", { value: null });
|
|
28
|
+
Object.defineProperty(frame, "document", {
|
|
29
|
+
get: () => {
|
|
30
|
+
throw new DOMException("blocked", "SecurityError");
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
const parent = {
|
|
34
|
+
postMessage: (data: unknown, _origin: string, ports: MessagePort[]) =>
|
|
35
|
+
window.dispatchEvent(
|
|
36
|
+
new MessageEvent("message", { source: frame as unknown as Window, data, ports }),
|
|
37
|
+
),
|
|
38
|
+
} as unknown as Window;
|
|
39
|
+
const agent = installMarkedEditingAgent(parent);
|
|
40
|
+
frame.postMessage = (data: unknown) =>
|
|
41
|
+
window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
|
|
42
|
+
closers.push(() => agent.dispose());
|
|
43
|
+
return iframe;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The frame's colour grading runtime, on the window the agent serves. */
|
|
47
|
+
function installFrameGrading() {
|
|
48
|
+
const stopPlayback = vi.fn();
|
|
49
|
+
const grading = {
|
|
50
|
+
getStatus: vi.fn(() => ({ state: "active", message: "Shader active" })),
|
|
51
|
+
renderPreviews: vi.fn(async (_target: unknown, candidates: Array<{ id: string }>) => ({
|
|
52
|
+
width: 160,
|
|
53
|
+
height: 90,
|
|
54
|
+
images: candidates.map(({ id }) => ({
|
|
55
|
+
id,
|
|
56
|
+
dataUrl: id === "neutral" ? "https://example.com/x.png" : `data:image/png;base64,${id}`,
|
|
57
|
+
})),
|
|
58
|
+
})),
|
|
59
|
+
startPreviewPlayback: vi.fn(() => stopPlayback),
|
|
60
|
+
};
|
|
61
|
+
Object.assign(window, { __hf: { colorGrading: grading } });
|
|
62
|
+
return { grading, stopPlayback };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const element = {
|
|
66
|
+
element: document.createElement("video"),
|
|
67
|
+
id: "s1-bg",
|
|
68
|
+
hfId: "hf-bg",
|
|
69
|
+
selector: "#s1-bg",
|
|
70
|
+
selectorIndex: 0,
|
|
71
|
+
tagName: "video",
|
|
72
|
+
sourceFile: "index.html",
|
|
73
|
+
dataAttributes: {},
|
|
74
|
+
} as unknown as DomEditSelection;
|
|
75
|
+
const target = { id: "s1-bg", hfId: "hf-bg", selector: "#s1-bg", selectorIndex: 0 };
|
|
76
|
+
|
|
77
|
+
function renderController(iframe: HTMLIFrameElement) {
|
|
78
|
+
let latest: ReturnType<typeof useColorGradingController> | undefined;
|
|
79
|
+
const previewIframeRef = { current: iframe };
|
|
80
|
+
const onSetAttributeLive = vi.fn();
|
|
81
|
+
function Host() {
|
|
82
|
+
latest = useColorGradingController({
|
|
83
|
+
projectId: "proj",
|
|
84
|
+
element,
|
|
85
|
+
previewIframeRef,
|
|
86
|
+
onSetAttributeLive,
|
|
87
|
+
});
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
const root = createRoot(document.body.appendChild(document.createElement("div")));
|
|
91
|
+
act(() => root.render(React.createElement(Host)));
|
|
92
|
+
closers.unshift(() => act(() => root.unmount()));
|
|
93
|
+
return () => {
|
|
94
|
+
if (!latest) throw new Error("hook did not render");
|
|
95
|
+
return latest;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Each poll flushes React's queued updates first; a check inside one act would never see them.
|
|
100
|
+
const settle = (check: () => void) =>
|
|
101
|
+
vi.waitFor(
|
|
102
|
+
async () => {
|
|
103
|
+
await act(async () => {});
|
|
104
|
+
check();
|
|
105
|
+
},
|
|
106
|
+
{ timeout: 3_000 },
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
describe("grade preview sealed", () => {
|
|
110
|
+
it("reads the frame's grading status over the editing port", async () => {
|
|
111
|
+
const { grading } = installFrameGrading();
|
|
112
|
+
const state = renderController(opaqueFrame());
|
|
113
|
+
|
|
114
|
+
await settle(() =>
|
|
115
|
+
expect(state().runtimeStatus).toEqual({ state: "active", message: "Shader active" }),
|
|
116
|
+
);
|
|
117
|
+
expect(grading.getStatus).toHaveBeenCalledWith(target);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("draws preset cards the frame renders, and drops any that are not image data", async () => {
|
|
121
|
+
const { grading } = installFrameGrading();
|
|
122
|
+
const state = renderController(opaqueFrame());
|
|
123
|
+
|
|
124
|
+
act(() => state().requestPresetPreviews());
|
|
125
|
+
await settle(() => expect(state().presetPreviews.images["bright-pop"]).toBeDefined());
|
|
126
|
+
|
|
127
|
+
const [renderedFor, candidates, options] = grading.renderPreviews.mock.calls[0]!;
|
|
128
|
+
expect(renderedFor).toEqual(target);
|
|
129
|
+
expect(candidates).toHaveLength(18);
|
|
130
|
+
expect(options).toMatchObject({ maxDimension: 160 });
|
|
131
|
+
expect(state().presetPreviews).toMatchObject({ width: 160, height: 90 });
|
|
132
|
+
expect(state().presetPreviews.images["bright-pop"]).toBe("data:image/png;base64,bright-pop");
|
|
133
|
+
expect(state().presetPreviews.images.neutral).toBeUndefined();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("plays the hovered card in the frame and stops it when the hover ends", async () => {
|
|
137
|
+
const { grading, stopPlayback } = installFrameGrading();
|
|
138
|
+
const state = renderController(opaqueFrame());
|
|
139
|
+
const look = normalizeHfColorGrading({ preset: "bright-pop", intensity: 1 })!;
|
|
140
|
+
|
|
141
|
+
act(() =>
|
|
142
|
+
state().previewColorGrading(look, { animatedPreview: { kind: "presets", id: "bright-pop" } }),
|
|
143
|
+
);
|
|
144
|
+
await settle(() => expect(grading.renderPreviews).toHaveBeenCalled());
|
|
145
|
+
expect(grading.startPreviewPlayback).toHaveBeenCalledWith(target);
|
|
146
|
+
expect(grading.renderPreviews.mock.calls[0]![2]).toEqual({
|
|
147
|
+
maxDimension: 160,
|
|
148
|
+
useMediaTime: true,
|
|
149
|
+
});
|
|
150
|
+
await settle(() =>
|
|
151
|
+
expect(state().presetPreviews.images["bright-pop"]).toBe("data:image/png;base64,bright-pop"),
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
act(() => state().previewColorGrading(null));
|
|
155
|
+
await settle(() => expect(stopPlayback).toHaveBeenCalledTimes(1));
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("captures a graded frame from the frame", async () => {
|
|
159
|
+
installFrameGrading();
|
|
160
|
+
const state = renderController(opaqueFrame());
|
|
161
|
+
|
|
162
|
+
const frame = await act(() => state().captureGradedFrame());
|
|
163
|
+
expect(frame).toEqual({ dataUrl: "data:image/png;base64,capture", width: 160, height: 90 });
|
|
164
|
+
});
|
|
165
|
+
});
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
postRuntimeControlMessage,
|
|
25
25
|
} from "../../player/lib/runtimeProtocol";
|
|
26
26
|
import {
|
|
27
|
+
readSealedColorGradingStatus,
|
|
27
28
|
useColorGradingPreviews,
|
|
28
29
|
type ColorGradingCapturedFrame,
|
|
29
30
|
type ColorGradingPresetPreviews,
|
|
@@ -31,6 +32,7 @@ import {
|
|
|
31
32
|
} from "./useColorGradingPreviews";
|
|
32
33
|
import { studioApiFetch } from "../../utils/studioApiFetch";
|
|
33
34
|
import { authoredSrcPath } from "../../player/components/thumbnailUtils";
|
|
35
|
+
import { previewFrameOpaque } from "../../player/lib/previewChannel";
|
|
34
36
|
|
|
35
37
|
export type { ColorGradingPresetPreviews, ColorGradingPreviewOptions };
|
|
36
38
|
|
|
@@ -279,8 +281,9 @@ export function useColorGradingController({
|
|
|
279
281
|
[element.hfId, element.id, element.selector, element.selectorIndex],
|
|
280
282
|
);
|
|
281
283
|
|
|
284
|
+
const statusReadRef = useRef(0);
|
|
282
285
|
const refreshRuntimeStatus = useCallback(() => {
|
|
283
|
-
|
|
286
|
+
refreshStatus(previewIframeRef?.current, target, statusReadRef, setRuntimeStatus);
|
|
284
287
|
}, [previewIframeRef, target]);
|
|
285
288
|
|
|
286
289
|
useEffect(() => {
|
|
@@ -568,3 +571,19 @@ export function useColorGradingController({
|
|
|
568
571
|
},
|
|
569
572
|
};
|
|
570
573
|
}
|
|
574
|
+
|
|
575
|
+
function refreshStatus(
|
|
576
|
+
iframe: HTMLIFrameElement | null | undefined,
|
|
577
|
+
target: HfColorGradingTarget,
|
|
578
|
+
reads: { current: number },
|
|
579
|
+
apply: (status: RuntimeColorGradingStatus) => void,
|
|
580
|
+
): void {
|
|
581
|
+
if (!iframe || !previewFrameOpaque(iframe)) {
|
|
582
|
+
apply(readRuntimeColorGradingStatus(iframe, target));
|
|
583
|
+
return;
|
|
584
|
+
}
|
|
585
|
+
const read = ++reads.current;
|
|
586
|
+
void readSealedColorGradingStatus(iframe, target).then((status) => {
|
|
587
|
+
if (read === reads.current) apply(status);
|
|
588
|
+
});
|
|
589
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { useLivePreviewIframe } from "../../player/store/previewIframeStore";
|
|
2
|
+
import { previewFrameOpaque, previewRequest } from "../../player/lib/previewChannel";
|
|
3
|
+
import type { EditingResult } from "@hyperframes/core/runtime/editing-port";
|
|
2
4
|
import { useCallback, useEffect, useRef, useState, type RefObject } from "react";
|
|
3
5
|
import {
|
|
4
6
|
HF_COLOR_GRADING_ACTIVE_EFFECT_KEYS,
|
|
@@ -29,19 +31,23 @@ export interface ColorGradingPreviewOptions {
|
|
|
29
31
|
animatedPreview: { kind: ColorGradingPreviewKind; id: string };
|
|
30
32
|
}
|
|
31
33
|
|
|
34
|
+
type PreviewBatch = {
|
|
35
|
+
width: number;
|
|
36
|
+
height: number;
|
|
37
|
+
images: Array<{ id: string; dataUrl: string | null }>;
|
|
38
|
+
};
|
|
39
|
+
|
|
32
40
|
type RuntimeColorGradingPreview = {
|
|
33
41
|
renderPreviews: (
|
|
34
42
|
target: HfColorGradingTarget,
|
|
35
43
|
candidates: Array<{ id: string; grading: unknown }>,
|
|
36
44
|
options: { maxDimension: number; useMediaTime?: boolean },
|
|
37
|
-
) => Promise<
|
|
38
|
-
width: number;
|
|
39
|
-
height: number;
|
|
40
|
-
images: Array<{ id: string; dataUrl: string | null }>;
|
|
41
|
-
} | null>;
|
|
45
|
+
) => Promise<PreviewBatch | null>;
|
|
42
46
|
startPreviewPlayback?: (target: HfColorGradingTarget) => (() => void) | null;
|
|
43
47
|
};
|
|
44
48
|
|
|
49
|
+
type AnimatedSession = { stopPlayback: () => void; timer: number | null };
|
|
50
|
+
|
|
45
51
|
type PreviewRequest = {
|
|
46
52
|
kind: ColorGradingPreviewKind;
|
|
47
53
|
version: number;
|
|
@@ -74,6 +80,79 @@ function readRuntime(
|
|
|
74
80
|
}
|
|
75
81
|
}
|
|
76
82
|
|
|
83
|
+
const PORT_PREVIEW_TIMEOUT_MS = 15_000;
|
|
84
|
+
|
|
85
|
+
const isImageData = (value: unknown): value is string =>
|
|
86
|
+
typeof value === "string" && value.startsWith("data:image/");
|
|
87
|
+
|
|
88
|
+
function portBatch(batch: unknown): PreviewBatch | null {
|
|
89
|
+
if (typeof batch !== "object" || batch === null) return null;
|
|
90
|
+
const { width, height, images } = batch as Record<string, unknown>;
|
|
91
|
+
if (!Number.isFinite(width) || !Number.isFinite(height) || !Array.isArray(images)) return null;
|
|
92
|
+
return {
|
|
93
|
+
width: width as number,
|
|
94
|
+
height: height as number,
|
|
95
|
+
images: images.map((image: unknown) => {
|
|
96
|
+
const { id, dataUrl } = (image ?? {}) as { id?: unknown; dataUrl?: unknown };
|
|
97
|
+
return { id: String(id), dataUrl: isImageData(dataUrl) ? dataUrl : null };
|
|
98
|
+
}),
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function portRuntime(iframe: HTMLIFrameElement): RuntimeColorGradingPreview {
|
|
103
|
+
return {
|
|
104
|
+
renderPreviews: async (target, candidates, { maxDimension, useMediaTime = false }) => {
|
|
105
|
+
const params = { target, candidates, maxDimension, useMediaTime };
|
|
106
|
+
const reply = await previewRequest(
|
|
107
|
+
iframe,
|
|
108
|
+
"color-grading-previews",
|
|
109
|
+
params,
|
|
110
|
+
PORT_PREVIEW_TIMEOUT_MS,
|
|
111
|
+
);
|
|
112
|
+
return portBatch(reply?.batch);
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function previewRuntime(
|
|
118
|
+
iframe: HTMLIFrameElement | null | undefined,
|
|
119
|
+
): RuntimeColorGradingPreview | null {
|
|
120
|
+
return iframe && previewFrameOpaque(iframe) ? portRuntime(iframe) : readRuntime(iframe);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function playInSealedFrame(
|
|
124
|
+
iframe: HTMLIFrameElement | null | undefined,
|
|
125
|
+
target: HfColorGradingTarget,
|
|
126
|
+
sessionRef: { current: AnimatedSession | null },
|
|
127
|
+
animate: (runtime: RuntimeColorGradingPreview, session: AnimatedSession) => void,
|
|
128
|
+
): boolean {
|
|
129
|
+
if (!iframe || !previewFrameOpaque(iframe)) return false;
|
|
130
|
+
const stopPlayback = () =>
|
|
131
|
+
void previewRequest(iframe, "color-grading-playback", { target: null });
|
|
132
|
+
const session: AnimatedSession = { stopPlayback, timer: null };
|
|
133
|
+
sessionRef.current = session;
|
|
134
|
+
void previewRequest(iframe, "color-grading-playback", { target }).then((reply) => {
|
|
135
|
+
if (sessionRef.current !== session) return;
|
|
136
|
+
if (reply?.started) animate(portRuntime(iframe), session);
|
|
137
|
+
else sessionRef.current = null;
|
|
138
|
+
});
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
type ColorGradingStatus = NonNullable<EditingResult<"color-grading-status">["status"]>;
|
|
143
|
+
const STATUS_STATES = new Set(["missing", "inactive", "pending", "active", "unavailable"]);
|
|
144
|
+
|
|
145
|
+
export async function readSealedColorGradingStatus(
|
|
146
|
+
iframe: HTMLIFrameElement,
|
|
147
|
+
target: HfColorGradingTarget,
|
|
148
|
+
): Promise<ColorGradingStatus> {
|
|
149
|
+
const reply = await previewRequest(iframe, "color-grading-status", { target });
|
|
150
|
+
const { state, message } = (reply?.status ?? {}) as Partial<Record<string, unknown>>;
|
|
151
|
+
return STATUS_STATES.has(state as string) && typeof message === "string"
|
|
152
|
+
? { state: state as ColorGradingStatus["state"], message }
|
|
153
|
+
: { state: "pending", message: "Waiting for runtime" };
|
|
154
|
+
}
|
|
155
|
+
|
|
77
156
|
function previewMaxDimension(): number {
|
|
78
157
|
return Math.min(320, Math.ceil(160 * Math.max(1, window.devicePixelRatio || 1)));
|
|
79
158
|
}
|
|
@@ -149,7 +228,7 @@ export function useColorGradingPreviews({
|
|
|
149
228
|
previews: emptyPreviews(),
|
|
150
229
|
}));
|
|
151
230
|
const [request, setRequest] = useState<PreviewRequest | null>(null);
|
|
152
|
-
const animatedRef = useRef<
|
|
231
|
+
const animatedRef = useRef<AnimatedSession | null>(null);
|
|
153
232
|
if (state.identityKey !== identityKey) {
|
|
154
233
|
setState({ identityKey, previews: emptyPreviews() });
|
|
155
234
|
setRequest(null);
|
|
@@ -186,7 +265,7 @@ export function useColorGradingPreviews({
|
|
|
186
265
|
|
|
187
266
|
const attempt = async () => {
|
|
188
267
|
if (cancelled || complete || inFlight) return;
|
|
189
|
-
const runtime =
|
|
268
|
+
const runtime = previewRuntime(iframe);
|
|
190
269
|
if (!runtime) return;
|
|
191
270
|
inFlight = true;
|
|
192
271
|
try {
|
|
@@ -270,45 +349,50 @@ export function useColorGradingPreviews({
|
|
|
270
349
|
stopAnimatedPreview();
|
|
271
350
|
postColorGrading(next ?? gradingRef.current);
|
|
272
351
|
if (!next || !options) return;
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
[options.animatedPreview.id]: image,
|
|
352
|
+
const animate = (runtime: RuntimeColorGradingPreview, session: AnimatedSession) => {
|
|
353
|
+
const renderFrame = async () => {
|
|
354
|
+
try {
|
|
355
|
+
const batch = await runtime.renderPreviews(
|
|
356
|
+
target,
|
|
357
|
+
[{ id: options.animatedPreview.id, grading: toPreviewColorGrading(next) }],
|
|
358
|
+
{ maxDimension: previewMaxDimension(), useMediaTime: true },
|
|
359
|
+
);
|
|
360
|
+
const image = batch?.images[0]?.dataUrl;
|
|
361
|
+
if (animatedRef.current !== session || !batch || !image) return;
|
|
362
|
+
setState((current) => ({
|
|
363
|
+
...current,
|
|
364
|
+
previews: {
|
|
365
|
+
...current.previews,
|
|
366
|
+
[options.animatedPreview.kind]: {
|
|
367
|
+
...current.previews[options.animatedPreview.kind],
|
|
368
|
+
status: "ready",
|
|
369
|
+
images: {
|
|
370
|
+
...current.previews[options.animatedPreview.kind].images,
|
|
371
|
+
[options.animatedPreview.id]: image,
|
|
372
|
+
},
|
|
373
|
+
width: batch.width,
|
|
374
|
+
height: batch.height,
|
|
297
375
|
},
|
|
298
|
-
width: batch.width,
|
|
299
|
-
height: batch.height,
|
|
300
376
|
},
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
377
|
+
}));
|
|
378
|
+
} catch {
|
|
379
|
+
// A later frame can recover after media/runtime readiness races.
|
|
380
|
+
} finally {
|
|
381
|
+
if (animatedRef.current === session) {
|
|
382
|
+
session.timer = window.setTimeout(() => void renderFrame(), 100);
|
|
383
|
+
}
|
|
308
384
|
}
|
|
309
|
-
}
|
|
385
|
+
};
|
|
386
|
+
void renderFrame();
|
|
310
387
|
};
|
|
311
|
-
|
|
388
|
+
const iframe = previewIframeRef?.current;
|
|
389
|
+
if (playInSealedFrame(iframe, target, animatedRef, animate)) return;
|
|
390
|
+
const runtime = readRuntime(iframe);
|
|
391
|
+
const stopPlayback = runtime?.startPreviewPlayback?.(target);
|
|
392
|
+
if (!runtime || !stopPlayback) return;
|
|
393
|
+
const session = { stopPlayback, timer: null as number | null };
|
|
394
|
+
animatedRef.current = session;
|
|
395
|
+
animate(runtime, session);
|
|
312
396
|
},
|
|
313
397
|
[gradingRef, postColorGrading, previewIframeRef, stopAnimatedPreview, target],
|
|
314
398
|
);
|
|
@@ -336,7 +420,7 @@ export function useColorGradingPreviews({
|
|
|
336
420
|
}: {
|
|
337
421
|
grading?: NormalizedHfColorGrading;
|
|
338
422
|
} = {}): Promise<ColorGradingCapturedFrame | null> => {
|
|
339
|
-
const runtime =
|
|
423
|
+
const runtime = previewRuntime(previewIframeRef?.current);
|
|
340
424
|
if (!runtime) return null;
|
|
341
425
|
const batch = await runtime.renderPreviews(
|
|
342
426
|
target,
|
|
@@ -590,6 +590,30 @@ describe("NLEPreview", () => {
|
|
|
590
590
|
},
|
|
591
591
|
);
|
|
592
592
|
|
|
593
|
+
// Chrome stops rendering a hidden or clipped cross-origin frame, and a sealed one is cross-origin.
|
|
594
|
+
it.each([
|
|
595
|
+
["opaque" as const, ["opacity: 0"], ["visibility", "clip-path", "z-index"]],
|
|
596
|
+
[undefined, ["visibility: hidden", "clip-path: inset(100%)"], ["opacity"]],
|
|
597
|
+
])(
|
|
598
|
+
"keeps a reload's preview out of sight, and a sealed one rendering (%s)",
|
|
599
|
+
(sandboxOrigin, present, absent) => {
|
|
600
|
+
const view = renderPreview(
|
|
601
|
+
[
|
|
602
|
+
{ gen: 0, role: "live" },
|
|
603
|
+
{ gen: 1, role: "shadow", url: "/api/projects/p/preview?_t=1" },
|
|
604
|
+
],
|
|
605
|
+
{ sandboxOrigin },
|
|
606
|
+
);
|
|
607
|
+
const shadow = [...view.stage.querySelectorAll('[data-testid="mock-player"]')]
|
|
608
|
+
.map((player) => player.getAttribute("style") ?? "")
|
|
609
|
+
.filter((style) => style.includes("pointer-events: none"));
|
|
610
|
+
expect(shadow).toHaveLength(1);
|
|
611
|
+
for (const rule of present) expect(shadow[0]).toContain(rule);
|
|
612
|
+
for (const rule of absent) expect(shadow[0]).not.toContain(rule);
|
|
613
|
+
view.cleanup();
|
|
614
|
+
},
|
|
615
|
+
);
|
|
616
|
+
|
|
593
617
|
it("covers the live preview with the cached frame-0 poster until it is ready to show", () => {
|
|
594
618
|
const view = renderPreview();
|
|
595
619
|
const poster = () =>
|
|
@@ -29,11 +29,7 @@ import {
|
|
|
29
29
|
} from "./previewZoom";
|
|
30
30
|
import { RULER_GUTTER_PX, usePreviewGuidesStore } from "../editor/previewGuidesStore";
|
|
31
31
|
import { PreviewZoomOverlay, usePreviewZoomOverlay } from "./PreviewZoomOverlay";
|
|
32
|
-
import {
|
|
33
|
-
PREVIEW_STAGE_INSET_PX,
|
|
34
|
-
resolvePreviewStageSize,
|
|
35
|
-
SHADOW_IFRAME_STYLE,
|
|
36
|
-
} from "./previewStage";
|
|
32
|
+
import { PREVIEW_STAGE_INSET_PX, resolvePreviewStageSize, shadowIframeStyle } from "./previewStage";
|
|
37
33
|
import { usePreviewFirstFrameTelemetry } from "../../player/hooks/usePreviewFirstFrameTelemetry";
|
|
38
34
|
import { PreviewPoster, usePreviewPoster } from "./PreviewPoster";
|
|
39
35
|
interface NLEPreviewProps extends Pick<
|
|
@@ -534,7 +530,7 @@ export const NLEPreview = memo(function NLEPreview({
|
|
|
534
530
|
suppressLoadingOverlay
|
|
535
531
|
noLoadTimeout
|
|
536
532
|
sandboxOrigin={sandboxOrigin}
|
|
537
|
-
style={
|
|
533
|
+
style={shadowIframeStyle(sandboxOrigin)}
|
|
538
534
|
/>
|
|
539
535
|
),
|
|
540
536
|
)}
|
|
@@ -6,7 +6,7 @@ export const PREVIEW_STAGE_INSET_PX = 8;
|
|
|
6
6
|
|
|
7
7
|
// clip-path as well as visibility: the player's loading overlay sets its own
|
|
8
8
|
// visibility:visible and would otherwise paint over the live frame.
|
|
9
|
-
|
|
9
|
+
const SHADOW_IFRAME_STYLE: CSSProperties = {
|
|
10
10
|
position: "absolute",
|
|
11
11
|
inset: 0,
|
|
12
12
|
visibility: "hidden",
|
|
@@ -14,6 +14,16 @@ export const SHADOW_IFRAME_STYLE: CSSProperties = {
|
|
|
14
14
|
pointerEvents: "none",
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
+
const RENDERING_SHADOW_IFRAME_STYLE: CSSProperties = {
|
|
18
|
+
position: "absolute",
|
|
19
|
+
inset: 0,
|
|
20
|
+
opacity: 0,
|
|
21
|
+
pointerEvents: "none",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const shadowIframeStyle = (sandboxOrigin: "opaque" | undefined): CSSProperties =>
|
|
25
|
+
sandboxOrigin === "opaque" ? RENDERING_SHADOW_IFRAME_STYLE : SHADOW_IFRAME_STYLE;
|
|
26
|
+
|
|
17
27
|
export function resolvePreviewStageSize(
|
|
18
28
|
viewportWidth: number,
|
|
19
29
|
viewportHeight: number,
|
|
@@ -24,11 +24,20 @@ const shell = {
|
|
|
24
24
|
activeCompPath: "index.html" as string | null,
|
|
25
25
|
compositions: ["index.html", "scene.html"],
|
|
26
26
|
};
|
|
27
|
+
const showToast = vi.fn();
|
|
28
|
+
const copyTextToClipboard = vi.fn(async (_text: string) => true);
|
|
27
29
|
|
|
28
30
|
vi.mock("../../contexts/StudioContext", () => ({
|
|
29
|
-
useStudioShellContext: () => ({
|
|
31
|
+
useStudioShellContext: () => ({
|
|
32
|
+
projectId: "demo",
|
|
33
|
+
activeCompPath: shell.activeCompPath,
|
|
34
|
+
showToast,
|
|
35
|
+
}),
|
|
30
36
|
useStudioPlaybackContext: () => ({ refreshKey: 0 }),
|
|
31
37
|
}));
|
|
38
|
+
vi.mock("../../utils/clipboard", () => ({
|
|
39
|
+
copyTextToClipboard: (text: string) => copyTextToClipboard(text),
|
|
40
|
+
}));
|
|
32
41
|
vi.mock("../../contexts/DomEditContext", () => ({
|
|
33
42
|
useDomEditContext: () => ({ domEditSelection: null }),
|
|
34
43
|
}));
|
|
@@ -47,8 +56,29 @@ afterEach(() => {
|
|
|
47
56
|
act(() => root?.unmount());
|
|
48
57
|
root = null;
|
|
49
58
|
document.body.innerHTML = "";
|
|
59
|
+
showToast.mockClear();
|
|
60
|
+
copyTextToClipboard.mockClear();
|
|
61
|
+
vi.unstubAllGlobals();
|
|
50
62
|
});
|
|
51
63
|
|
|
64
|
+
async function renderPanel(html: string): Promise<HTMLElement> {
|
|
65
|
+
const host = document.createElement("div");
|
|
66
|
+
document.body.append(host);
|
|
67
|
+
root = createRoot(host);
|
|
68
|
+
const session = await openComposition(html, { history: false });
|
|
69
|
+
await act(async () => {
|
|
70
|
+
root?.render(
|
|
71
|
+
<VariablesPanel
|
|
72
|
+
sdkSession={session}
|
|
73
|
+
publishSdkSession={vi.fn()}
|
|
74
|
+
reloadPreview={vi.fn()}
|
|
75
|
+
recordEdit={vi.fn(async () => {})}
|
|
76
|
+
/>,
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
return host;
|
|
80
|
+
}
|
|
81
|
+
|
|
52
82
|
async function renderOtherCompositions(sessionPath: string): Promise<string> {
|
|
53
83
|
const host = document.createElement("div");
|
|
54
84
|
document.body.append(host);
|
|
@@ -84,3 +114,62 @@ describe("VariablesPanel other compositions", () => {
|
|
|
84
114
|
expect(await renderOtherCompositions("main.html")).not.toContain("main.html");
|
|
85
115
|
});
|
|
86
116
|
});
|
|
117
|
+
|
|
118
|
+
// A shared project's author writes these, so they reach the copied command as hostile text.
|
|
119
|
+
const HOSTILE = `x'; calc.exe; '" & calc.exe | calc.exe \\ $(id) %PATH%`;
|
|
120
|
+
const withHostileDefault = `<!DOCTYPE html>
|
|
121
|
+
<html data-composition-variables='${JSON.stringify([
|
|
122
|
+
{ id: "title", type: "string", label: "Title", default: HOSTILE },
|
|
123
|
+
]).replace(/'/g, "'")}'>
|
|
124
|
+
<body><div data-composition-id="main" data-hf-id="hf-stage" data-hf-root data-duration="5"></div></body>
|
|
125
|
+
</html>`;
|
|
126
|
+
|
|
127
|
+
const button = (host: HTMLElement, label: string) =>
|
|
128
|
+
[...host.querySelectorAll("button")].find((b) => b.textContent === label);
|
|
129
|
+
|
|
130
|
+
describe("VariablesPanel render command", () => {
|
|
131
|
+
it("does not let a hostile variable default into the copied render command", async () => {
|
|
132
|
+
shell.activeCompPath = "compositions/intro.html";
|
|
133
|
+
const fetch = vi.fn(async (_url: string, _init?: RequestInit) => new Response("{}"));
|
|
134
|
+
vi.stubGlobal("fetch", fetch);
|
|
135
|
+
const host = await renderPanel(withHostileDefault);
|
|
136
|
+
const expected =
|
|
137
|
+
"npx hyperframes render -c compositions/intro.html --variables-file .hyperframes/render-variables.json";
|
|
138
|
+
|
|
139
|
+
expect(host.querySelector("code")?.textContent).toBe(expected);
|
|
140
|
+
await act(async () => button(host, "Copy render command")?.click());
|
|
141
|
+
|
|
142
|
+
expect(copyTextToClipboard).toHaveBeenCalledWith(expected);
|
|
143
|
+
await vi.waitFor(() => expect(showToast).toHaveBeenCalledWith("Render command copied", "info"));
|
|
144
|
+
const [url, init] = fetch.mock.calls[0]!;
|
|
145
|
+
expect(url).toBe("/api/projects/demo/render-variables");
|
|
146
|
+
expect(JSON.parse(String(init?.body))).toEqual({ title: HOSTILE });
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("says the values were not saved when the server refuses them", async () => {
|
|
150
|
+
shell.activeCompPath = "index.html";
|
|
151
|
+
vi.stubGlobal(
|
|
152
|
+
"fetch",
|
|
153
|
+
vi.fn(async () => new Response("{}", { status: 403 })),
|
|
154
|
+
);
|
|
155
|
+
const host = await renderPanel(withHostileDefault);
|
|
156
|
+
|
|
157
|
+
await act(async () => button(host, "Copy render command")?.click());
|
|
158
|
+
|
|
159
|
+
await vi.waitFor(() =>
|
|
160
|
+
expect(showToast).toHaveBeenCalledWith(
|
|
161
|
+
"Couldn't save the values to .hyperframes/render-variables.json",
|
|
162
|
+
"error",
|
|
163
|
+
),
|
|
164
|
+
);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("offers no render command for a composition whose name a shell reads as syntax", async () => {
|
|
168
|
+
shell.activeCompPath = "x';calc;'.html";
|
|
169
|
+
const host = await renderPanel(withHostileDefault);
|
|
170
|
+
|
|
171
|
+
expect(button(host, "Copy render command")).toBeUndefined();
|
|
172
|
+
expect(button(host, "Copy values JSON")).toBeDefined();
|
|
173
|
+
expect(host.textContent).not.toContain("npx hyperframes render");
|
|
174
|
+
});
|
|
175
|
+
});
|