@hyperframes/studio 0.9.61 → 0.9.64
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 → hyperframes-player-mSF_GvRs.js} +1 -1
- package/dist/assets/{index-BGrNWeLK.js → index-CVmmHGol.js} +168 -168
- package/dist/assets/{index-REqr_dLu.js → index-DN167Uqf.js} +1 -1
- package/dist/assets/{pausedVideoDecoder-DqLDSq8J.js → pausedVideoDecoder-C8rhpGPx.js} +1 -1
- package/dist/{chunk-UM4CLD4M.js → chunk-OJLNM6V5.js} +1 -1
- package/dist/{chunk-3KCEIESB.js → chunk-VDDEXNVX.js} +11 -1
- package/dist/{chunk-OOGQ5KCC.js → chunk-YQ3ZAXXY.js} +8 -27
- package/dist/{domEditingLayers-IHYA42AJ.js → domEditingLayers-YYHWRNF4.js} +2 -2
- package/dist/index.html +1 -1
- package/dist/index.js +1163 -1000
- package/dist/player.js +2 -2
- package/package.json +8 -8
- package/src/components/nle/AudioMeterStrip.tsx +63 -2
- package/src/components/nle/audioSealedPreview.test.ts +254 -0
- package/src/components/nle/zLaneGesture.test.ts +67 -0
- package/src/components/nle/zLaneGesture.ts +4 -0
- package/src/hooks/timelineAudioGroupCreate.ts +57 -7
- package/src/hooks/timelineAudioGroupVolume.ts +110 -34
- package/src/main.tsx +14 -11
- package/src/player/components/Timeline.newTrack.test.tsx +106 -0
- package/src/player/components/TimelineLanes.tsx +4 -2
- package/src/player/components/TimelineTrackHeader.tsx +12 -4
- package/src/player/components/clipMenuAudioItems.tsx +46 -3
- package/src/player/components/timelineRowKeys.test.ts +28 -0
- package/src/player/components/timelineRowKeys.ts +27 -0
- package/src/player/hooks/useTimelineSyncCallbacks.sealed.test.ts +98 -0
- package/src/player/hooks/useTimelineSyncCallbacks.ts +23 -8
- package/src/player/lib/playbackTypes.ts +0 -2
- package/src/player/lib/previewChannel.ts +10 -0
- package/src/player/lib/timelineElementHelpers.ts +7 -42
- package/src/player/lib/timelineIframeHelpers.test.ts +18 -137
- package/src/player/lib/timelineIframeHelpers.ts +15 -94
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
|
|
3
|
+
import { act, createElement } from "react";
|
|
4
|
+
import { createRoot } from "react-dom/client";
|
|
5
|
+
import { afterEach, expect, it, vi } from "vitest";
|
|
6
|
+
// The frame's real runtime agent, serving the opaque frame from this document as Studio's marked preview page.
|
|
7
|
+
import { installMarkedEditingAgent } from "../../../../core/src/runtime/editingAgent.test-helpers";
|
|
8
|
+
import type { TimelineElement } from "../store/playerStore";
|
|
9
|
+
import { detachedFakeIframe } from "./timelinePlayerTestHarness";
|
|
10
|
+
import { useTimelineSyncCallbacks } from "./useTimelineSyncCallbacks";
|
|
11
|
+
|
|
12
|
+
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
13
|
+
|
|
14
|
+
const closers: Array<() => void> = [];
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
closers.splice(0).forEach((close) => close());
|
|
17
|
+
document.body.innerHTML = "";
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
/** A frame Studio cannot read, whose runtime is the real editing agent over this document. */
|
|
21
|
+
function opaqueFrame() {
|
|
22
|
+
const frame: Record<string, unknown> = {};
|
|
23
|
+
const iframe = detachedFakeIframe(frame);
|
|
24
|
+
Object.defineProperty(iframe, "contentDocument", { value: null });
|
|
25
|
+
Object.defineProperty(frame, "document", {
|
|
26
|
+
get: () => {
|
|
27
|
+
throw new DOMException("blocked", "SecurityError");
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
const parent = {
|
|
31
|
+
postMessage: (data: unknown, _origin: string, ports: MessagePort[]) =>
|
|
32
|
+
window.dispatchEvent(
|
|
33
|
+
new MessageEvent("message", { source: frame as unknown as Window, data, ports }),
|
|
34
|
+
),
|
|
35
|
+
} as unknown as Window;
|
|
36
|
+
const agent = installMarkedEditingAgent(parent);
|
|
37
|
+
frame.postMessage = (data: unknown) =>
|
|
38
|
+
window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
|
|
39
|
+
closers.push(() => agent.dispose());
|
|
40
|
+
return iframe;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function processWith(iframe: HTMLIFrameElement) {
|
|
44
|
+
const sync = vi.fn<(els: TimelineElement[], duration?: number) => void>();
|
|
45
|
+
let callbacks: ReturnType<typeof useTimelineSyncCallbacks> | undefined;
|
|
46
|
+
function Harness() {
|
|
47
|
+
callbacks = useTimelineSyncCallbacks({
|
|
48
|
+
iframeRef: { current: iframe },
|
|
49
|
+
probeIntervalRef: { current: undefined },
|
|
50
|
+
pendingSeekRef: { current: null },
|
|
51
|
+
isRefreshingRef: { current: false },
|
|
52
|
+
getAdapter: () => null,
|
|
53
|
+
syncTimelineElements: sync,
|
|
54
|
+
setDuration: () => {},
|
|
55
|
+
setCurrentTime: () => {},
|
|
56
|
+
requestTimelineReady: () => {},
|
|
57
|
+
setIsPlaying: () => {},
|
|
58
|
+
attachIframeShortcutListeners: () => {},
|
|
59
|
+
applyPreviewAudioState: () => {},
|
|
60
|
+
});
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
const host = document.createElement("div");
|
|
64
|
+
act(() => createRoot(host).render(createElement(Harness)));
|
|
65
|
+
return { sync, process: callbacks!.processTimelineMessage };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const boxClip = {
|
|
69
|
+
id: "box",
|
|
70
|
+
label: "box",
|
|
71
|
+
start: 0,
|
|
72
|
+
duration: 2,
|
|
73
|
+
track: 0,
|
|
74
|
+
kind: "element" as const,
|
|
75
|
+
tagName: "div",
|
|
76
|
+
compositionId: null,
|
|
77
|
+
parentCompositionId: null,
|
|
78
|
+
compositionSrc: null,
|
|
79
|
+
assetUrl: null,
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// fails without the fix: a sealed frame's rows had no element behind them, so no id, source file or audio group.
|
|
83
|
+
it("binds a sealed preview's timeline row to its element, as an open preview does", async () => {
|
|
84
|
+
document.body.innerHTML = `<div data-composition-id="main" data-composition-file="index.html">
|
|
85
|
+
<div id="box" class="clip" data-start="0" data-duration="2" data-audio-group="voice"></div>
|
|
86
|
+
</div>`;
|
|
87
|
+
const { sync, process } = processWith(opaqueFrame());
|
|
88
|
+
|
|
89
|
+
process({ clips: [boxClip], durationInFrames: 60 });
|
|
90
|
+
|
|
91
|
+
await vi.waitFor(() => expect(sync.mock.calls.at(-1)?.[0][0]?.domId).toBe("box"));
|
|
92
|
+
const [row] = sync.mock.calls.at(-1)![0];
|
|
93
|
+
expect(row).toMatchObject({
|
|
94
|
+
key: "index.html#box",
|
|
95
|
+
sourceFile: "index.html",
|
|
96
|
+
audioGroup: "voice",
|
|
97
|
+
});
|
|
98
|
+
});
|
|
@@ -15,6 +15,7 @@ import type { PlaybackAdapter, IframeWindow } from "../lib/playbackTypes";
|
|
|
15
15
|
import { readTimelineDurationFromDocument } from "../lib/timelineDOM";
|
|
16
16
|
import { buildMissingCompositionElements } from "../lib/timelineIframeHelpers";
|
|
17
17
|
import { acceptedRuntimeMessageFps } from "../lib/runtimeProtocol";
|
|
18
|
+
import { previewDocumentCopy, previewFrameOpaque } from "../lib/previewChannel";
|
|
18
19
|
import { useLinkedClipPreferences } from "../../utils/linkedClipPreferences";
|
|
19
20
|
import {
|
|
20
21
|
buildTimelineElementsFromClips,
|
|
@@ -171,19 +172,13 @@ export function useTimelineSyncCallbacks({
|
|
|
171
172
|
hostOwnsDeadline,
|
|
172
173
|
}: UseTimelineSyncCallbacksParams) {
|
|
173
174
|
// Convert a runtime timeline message (from iframe postMessage) into TimelineElements
|
|
174
|
-
const
|
|
175
|
-
(data: RuntimeTimelineMessage) => {
|
|
176
|
-
if (!data.clips) return;
|
|
177
|
-
|
|
178
|
-
usePlayerStore.getState().setClipManifest(data.clips);
|
|
179
|
-
|
|
175
|
+
const applyTimelineMessage = useCallback(
|
|
176
|
+
(data: RuntimeTimelineMessage, iframeDoc: Document | null) => {
|
|
180
177
|
// Show root-level clips: no parentCompositionId, OR parent is a "phantom wrapper"
|
|
181
178
|
const clipCompositionIds = new Set(data.clips.map((c) => c.compositionId).filter(Boolean));
|
|
182
179
|
const filtered = data.clips.filter(
|
|
183
180
|
(clip) => !clip.parentCompositionId || !clipCompositionIds.has(clip.parentCompositionId),
|
|
184
181
|
);
|
|
185
|
-
const iframeDoc = safeContentDocument(iframeRef.current);
|
|
186
|
-
|
|
187
182
|
try {
|
|
188
183
|
const parentMap = clipTreeParentMap(iframeRef.current?.contentWindow ?? null);
|
|
189
184
|
const domClipChildren = collectSubCompositionDomChildren(iframeDoc, data.clips, parentMap);
|
|
@@ -219,6 +214,26 @@ export function useTimelineSyncCallbacks({
|
|
|
219
214
|
[iframeRef, syncTimelineElements],
|
|
220
215
|
);
|
|
221
216
|
|
|
217
|
+
const timelineReads = useRef(0);
|
|
218
|
+
const processTimelineMessage = useCallback(
|
|
219
|
+
(data: RuntimeTimelineMessage) => {
|
|
220
|
+
if (!data.clips) return;
|
|
221
|
+
usePlayerStore.getState().setClipManifest(data.clips);
|
|
222
|
+
const iframe = iframeRef.current;
|
|
223
|
+
const read = ++timelineReads.current;
|
|
224
|
+
if (!iframe || !previewFrameOpaque(iframe)) {
|
|
225
|
+
applyTimelineMessage(data, safeContentDocument(iframe));
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
// A sealed frame's rows bind to a copy of its document from the editing port; the newest read wins.
|
|
229
|
+
void previewDocumentCopy(iframe).then((doc) => {
|
|
230
|
+
if (read === timelineReads.current && iframeRef.current === iframe)
|
|
231
|
+
applyTimelineMessage(data, doc);
|
|
232
|
+
});
|
|
233
|
+
},
|
|
234
|
+
[iframeRef, applyTimelineMessage],
|
|
235
|
+
);
|
|
236
|
+
|
|
222
237
|
const enrichMissingCompositions = useCallback(() => {
|
|
223
238
|
try {
|
|
224
239
|
const iframe = iframeRef.current;
|
|
@@ -73,8 +73,6 @@ export type IframeWindow = Window & {
|
|
|
73
73
|
* Every member stays optional and is optional-called, so a runtime that
|
|
74
74
|
* predates the hook degrades to a no-op instead of throwing. */
|
|
75
75
|
__hf?: {
|
|
76
|
-
leasePausedMedia?: (el: HTMLMediaElement) => void;
|
|
77
|
-
releasePausedMedia?: (el: HTMLMediaElement) => void;
|
|
78
76
|
setPausedVideoFrameProvider?: (provider: PausedVideoFrameProvider | null) => void;
|
|
79
77
|
setLoopStart?: (seconds: number | null) => void;
|
|
80
78
|
};
|
|
@@ -124,3 +124,13 @@ export async function previewComputedStyles(
|
|
|
124
124
|
}
|
|
125
125
|
return read;
|
|
126
126
|
}
|
|
127
|
+
|
|
128
|
+
export async function previewDocumentCopy(iframe: HTMLIFrameElement): Promise<Document | null> {
|
|
129
|
+
const reply = await previewRequest(iframe, "document-markup", {});
|
|
130
|
+
if (typeof reply?.html !== "string" || typeof reply.baseURI !== "string") return null;
|
|
131
|
+
const doc = new DOMParser().parseFromString(reply.html, "text/html");
|
|
132
|
+
const base = doc.createElement("base");
|
|
133
|
+
base.setAttribute("href", reply.baseURI);
|
|
134
|
+
doc.head.prepend(base);
|
|
135
|
+
return doc;
|
|
136
|
+
}
|
|
@@ -10,6 +10,13 @@
|
|
|
10
10
|
import type { TimelineElement } from "../store/playerStore";
|
|
11
11
|
import { readTimelineText } from "./timelineText";
|
|
12
12
|
import type { ClipManifestClip } from "./playbackTypes";
|
|
13
|
+
import {
|
|
14
|
+
previewElementFinder,
|
|
15
|
+
previewElementSourceFile as getTimelineElementSourceFile,
|
|
16
|
+
} from "@hyperframes/core/studio-preview-mark";
|
|
17
|
+
|
|
18
|
+
export type { PreviewTarget } from "@hyperframes/core/studio-preview-mark";
|
|
19
|
+
export { getTimelineElementSourceFile, previewElementFinder };
|
|
13
20
|
import { isFinitePositive } from "./playbackAdapter";
|
|
14
21
|
import { getSourceScopedSelectorIndex } from "../../utils/sourceScopedSelectorIndex";
|
|
15
22
|
import { HF_AUDIO_GROUP_TAG } from "@hyperframes/core/audio-groups";
|
|
@@ -296,15 +303,6 @@ export function getTimelineElementSelector(el: Element): string | undefined {
|
|
|
296
303
|
return undefined;
|
|
297
304
|
}
|
|
298
305
|
|
|
299
|
-
export function getTimelineElementSourceFile(el: Element): string | undefined {
|
|
300
|
-
const ownerRoot = el.parentElement?.closest("[data-composition-id]");
|
|
301
|
-
return (
|
|
302
|
-
ownerRoot?.getAttribute("data-composition-file") ??
|
|
303
|
-
ownerRoot?.getAttribute("data-composition-src") ??
|
|
304
|
-
undefined
|
|
305
|
-
);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
306
|
export function getTimelineElementSelectorIndex(
|
|
309
307
|
doc: Document,
|
|
310
308
|
el: Element,
|
|
@@ -491,39 +489,6 @@ function findInClipScope(
|
|
|
491
489
|
return lone;
|
|
492
490
|
}
|
|
493
491
|
|
|
494
|
-
export type PreviewTarget = Pick<TimelineElement, "hfId" | "domId" | "id" | "sourceFile">;
|
|
495
|
-
|
|
496
|
-
/** Finds a row's preview element by `data-hf-id`, then id, preferring one in the row's own file: both repeat across
|
|
497
|
-
* files. Indexes the document once, so a pass over every row costs one scan. */
|
|
498
|
-
export function previewElementFinder(
|
|
499
|
-
doc: Document,
|
|
500
|
-
selector = "[data-hf-id], [id]",
|
|
501
|
-
): (target: PreviewTarget) => Element | null {
|
|
502
|
-
const byKey = new Map<string, Element[]>();
|
|
503
|
-
const add = (key: string, node: Element) => {
|
|
504
|
-
const nodes = byKey.get(key);
|
|
505
|
-
if (nodes) nodes.push(node);
|
|
506
|
-
else byKey.set(key, [node]);
|
|
507
|
-
};
|
|
508
|
-
for (const node of doc.querySelectorAll(selector)) {
|
|
509
|
-
const hfId = node.getAttribute("data-hf-id");
|
|
510
|
-
const id = node.getAttribute("id");
|
|
511
|
-
if (hfId) add(`hf:${hfId}`, node);
|
|
512
|
-
if (id) add(`id:${id}`, node);
|
|
513
|
-
}
|
|
514
|
-
return (target) => {
|
|
515
|
-
const matches = [
|
|
516
|
-
...((target.hfId && byKey.get(`hf:${target.hfId}`)) || []),
|
|
517
|
-
...(byKey.get(`id:${target.domId ?? target.id}`) ?? []),
|
|
518
|
-
];
|
|
519
|
-
return (
|
|
520
|
-
matches.find((node) => getTimelineElementSourceFile(node) === target.sourceFile) ??
|
|
521
|
-
matches[0] ??
|
|
522
|
-
null
|
|
523
|
-
);
|
|
524
|
-
};
|
|
525
|
-
}
|
|
526
|
-
|
|
527
492
|
export function findClipElementById(doc: Document, clip: ClipManifestClip): Element | null {
|
|
528
493
|
if (!clip.id) return null;
|
|
529
494
|
const first = doc.getElementById(clip.id);
|
|
@@ -211,145 +211,26 @@ describe("setPreviewMediaVolume", () => {
|
|
|
211
211
|
});
|
|
212
212
|
|
|
213
213
|
describe("scrubPreviewAudio", () => {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
iframe.
|
|
223
|
-
|
|
224
|
-
scrubPreviewAudio(iframe, 0.5, { id: "music" }, 0.4);
|
|
225
|
-
|
|
226
|
-
expect(audio.volume).toBeCloseTo(0.1);
|
|
227
|
-
stopScrubPreviewAudio();
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* The preview document is a different realm, so `instanceof HTMLAudioElement`
|
|
232
|
-
* is false for every node in it. That threw the `music` hint away and left
|
|
233
|
-
* the first `<audio>` in the document as the only route — and the first
|
|
234
|
-
* `<audio>` is often the voiceover, so scrubbing previewed the wrong track.
|
|
235
|
-
* Two elements, music second, is what tells the two paths apart: with one
|
|
236
|
-
* element the fallback reaches the right node by accident.
|
|
237
|
-
*/
|
|
238
|
-
it("previews the track named by the music row, not the first audio in the document", () => {
|
|
239
|
-
const iframe = document.createElement("iframe");
|
|
240
|
-
document.body.append(iframe);
|
|
241
|
-
const previewDoc = iframe.contentDocument;
|
|
242
|
-
if (!previewDoc?.body) throw new Error("expected an iframe document");
|
|
243
|
-
|
|
244
|
-
const voiceover = previewDoc.createElement("audio");
|
|
245
|
-
voiceover.id = "voiceover";
|
|
246
|
-
voiceover.play = vi.fn(async () => {});
|
|
247
|
-
voiceover.pause = vi.fn();
|
|
248
|
-
|
|
249
|
-
const music = previewDoc.createElement("audio");
|
|
250
|
-
music.id = "music-bed";
|
|
251
|
-
music.play = vi.fn(async () => {});
|
|
252
|
-
music.pause = vi.fn();
|
|
253
|
-
|
|
254
|
-
previewDoc.body.append(voiceover, music);
|
|
255
|
-
|
|
256
|
-
// The node really is cross-realm; this is the condition, not a contrivance.
|
|
257
|
-
expect(music instanceof HTMLAudioElement).toBe(false);
|
|
258
|
-
|
|
259
|
-
scrubPreviewAudio(iframe, 0.5, { id: "music-bed" }, 1);
|
|
260
|
-
|
|
261
|
-
expect(music.play).toHaveBeenCalled();
|
|
262
|
-
expect(voiceover.play).not.toHaveBeenCalled();
|
|
263
|
-
stopScrubPreviewAudio();
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
it("previews the music row's own track when a sub-composition repeats its id", () => {
|
|
267
|
-
const iframe = document.createElement("iframe");
|
|
268
|
-
document.body.append(iframe);
|
|
269
|
-
const previewDoc = iframe.contentDocument;
|
|
270
|
-
if (!previewDoc?.body) throw new Error("expected an iframe document");
|
|
271
|
-
previewDoc.body.innerHTML =
|
|
272
|
-
'<div data-composition-id="strip" data-composition-src="compositions/strip.html"><audio id="music"></audio></div>' +
|
|
273
|
-
'<audio id="music" class="root"></audio>';
|
|
274
|
-
const [inner, root] = Array.from(previewDoc.querySelectorAll("audio"));
|
|
275
|
-
for (const audio of [inner, root])
|
|
276
|
-
Object.assign(audio!, { play: vi.fn(async () => {}), pause: vi.fn() });
|
|
277
|
-
|
|
278
|
-
scrubPreviewAudio(iframe, 0.5, { id: "music" }, 1);
|
|
279
|
-
|
|
280
|
-
expect(root!.play).toHaveBeenCalled();
|
|
281
|
-
expect(inner!.play).not.toHaveBeenCalled();
|
|
282
|
-
stopScrubPreviewAudio();
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
/** An edit to a sub-composition rebuilds the media inside it, so the music row can
|
|
286
|
-
* name a track that is not in the preview for a moment. Auditioning whatever audio
|
|
287
|
-
* came first then previews the voiceover, which is not the track being scrubbed. */
|
|
288
|
-
it("previews nothing when the music row's own track is not in the preview", () => {
|
|
289
|
-
const iframe = document.createElement("iframe");
|
|
290
|
-
document.body.append(iframe);
|
|
291
|
-
const previewDoc = iframe.contentDocument;
|
|
292
|
-
if (!previewDoc?.body) throw new Error("expected an iframe document");
|
|
293
|
-
|
|
294
|
-
const voiceover = previewDoc.createElement("audio");
|
|
295
|
-
voiceover.id = "voiceover";
|
|
296
|
-
voiceover.play = vi.fn(async () => {});
|
|
297
|
-
voiceover.pause = vi.fn();
|
|
298
|
-
previewDoc.body.append(voiceover);
|
|
299
|
-
|
|
300
|
-
scrubPreviewAudio(iframe, 0.5, { id: "music-bed" }, 1);
|
|
301
|
-
|
|
302
|
-
expect(voiceover.play).not.toHaveBeenCalled();
|
|
303
|
-
expect(voiceover.volume).toBe(1);
|
|
304
|
-
stopScrubPreviewAudio();
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
it("still previews the track marked as the music when the row's own id is gone", () => {
|
|
308
|
-
const iframe = document.createElement("iframe");
|
|
309
|
-
document.body.append(iframe);
|
|
310
|
-
const previewDoc = iframe.contentDocument;
|
|
311
|
-
if (!previewDoc?.body) throw new Error("expected an iframe document");
|
|
312
|
-
previewDoc.body.innerHTML =
|
|
313
|
-
'<audio id="voiceover"></audio><audio id="bed" data-timeline-role="music"></audio>';
|
|
314
|
-
const [voiceover, bed] = Array.from(previewDoc.querySelectorAll("audio"));
|
|
315
|
-
for (const audio of [voiceover, bed])
|
|
316
|
-
Object.assign(audio!, { play: vi.fn(async () => {}), pause: vi.fn() });
|
|
317
|
-
|
|
318
|
-
scrubPreviewAudio(iframe, 0.5, { id: "music-bed" }, 1);
|
|
319
|
-
|
|
320
|
-
expect(bed!.play).toHaveBeenCalled();
|
|
321
|
-
expect(voiceover!.play).not.toHaveBeenCalled();
|
|
322
|
-
stopScrubPreviewAudio();
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
/** A scrub audition is media running under a paused clock, which the runtime now
|
|
326
|
-
* stops on sight. So it borrows the element. That a leased element survives the
|
|
327
|
-
* tick is asserted runtime-side in core's `transportPark.test.ts`; here the
|
|
328
|
-
* contract is that the hook is called with the right element and given back. */
|
|
329
|
-
it("borrows the element from the runtime for the audition and returns it on stop", () => {
|
|
330
|
-
const iframe = document.createElement("iframe");
|
|
331
|
-
document.body.append(iframe);
|
|
332
|
-
const previewDoc = iframe.contentDocument;
|
|
333
|
-
if (!previewDoc?.body) throw new Error("expected an iframe document");
|
|
334
|
-
|
|
335
|
-
const music = previewDoc.createElement("audio");
|
|
336
|
-
music.id = "music";
|
|
337
|
-
music.play = vi.fn(async () => {});
|
|
338
|
-
music.pause = vi.fn();
|
|
339
|
-
previewDoc.body.append(music);
|
|
340
|
-
|
|
341
|
-
const leasePausedMedia = vi.fn();
|
|
342
|
-
const releasePausedMedia = vi.fn();
|
|
343
|
-
(previewDoc.defaultView as IframeWindow).__hf = { leasePausedMedia, releasePausedMedia };
|
|
344
|
-
|
|
345
|
-
scrubPreviewAudio(iframe, 0.5, { id: "music" }, 1);
|
|
346
|
-
|
|
347
|
-
expect(leasePausedMedia).toHaveBeenCalledWith(music);
|
|
348
|
-
expect(releasePausedMedia).not.toHaveBeenCalled();
|
|
349
|
-
|
|
214
|
+
// fails without the fix: Studio played the track through the frame's document, which a sealed frame does not give it.
|
|
215
|
+
it("asks a sealed preview's runtime to play the music row's track, and to stop", () => {
|
|
216
|
+
const postMessage = vi.fn();
|
|
217
|
+
const iframe = {
|
|
218
|
+
contentDocument: null,
|
|
219
|
+
contentWindow: { postMessage },
|
|
220
|
+
} as unknown as HTMLIFrameElement;
|
|
221
|
+
|
|
222
|
+
scrubPreviewAudio(iframe, 0.5, { id: "music", hfId: "a1", sourceFile: "index.html" }, 0.4);
|
|
350
223
|
stopScrubPreviewAudio();
|
|
351
224
|
|
|
352
|
-
expect(
|
|
225
|
+
expect(postMessage.mock.calls.map(([message]) => message)).toEqual([
|
|
226
|
+
expect.objectContaining({
|
|
227
|
+
action: "scrub-audio",
|
|
228
|
+
time: 0.5,
|
|
229
|
+
volume: 0.4,
|
|
230
|
+
target: { id: "music", hfId: "a1", sourceFile: "index.html" },
|
|
231
|
+
}),
|
|
232
|
+
expect.objectContaining({ action: "scrub-audio", time: null }),
|
|
233
|
+
]);
|
|
353
234
|
});
|
|
354
235
|
});
|
|
355
236
|
|
|
@@ -208,73 +208,9 @@ export function resolveIframe(el: Element | null): HTMLIFrameElement | null {
|
|
|
208
208
|
// ---------------------------------------------------------------------------
|
|
209
209
|
// Audio scrubbing
|
|
210
210
|
// ---------------------------------------------------------------------------
|
|
211
|
-
//
|
|
212
|
-
// like an NLE scrub. Repeated calls keep playback alive; it auto-pauses shortly
|
|
213
|
-
// after scrubbing stops and restores the element's prior muted state.
|
|
211
|
+
// The preview's runtime plays the slice, so a sealed frame scrubs as an open one does.
|
|
214
212
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
let scrubAudioEl: HTMLAudioElement | null = null;
|
|
218
|
-
let scrubStopTimer: ReturnType<typeof setTimeout> | null = null;
|
|
219
|
-
let scrubPrevMuted: boolean | null = null;
|
|
220
|
-
let scrubPrevVolume: number | null = null;
|
|
221
|
-
|
|
222
|
-
// Resolve the SAME element the store identified as music: prefer that row's own
|
|
223
|
-
// element, then the role attribute, and only fall back to the first <audio>
|
|
224
|
-
// (which could be a voiceover, so the row hint matters).
|
|
225
|
-
/**
|
|
226
|
-
* `doc` is the preview iframe's document, so its `<audio>` nodes are instances of
|
|
227
|
-
* the IFRAME's `HTMLAudioElement`, never this module's. `instanceof
|
|
228
|
-
* HTMLAudioElement` here is false for every one of them, which silently threw the
|
|
229
|
-
* `music` hint away and fell through to "first `<audio>` in the document" — the
|
|
230
|
-
* very thing the comment above warns can be a voiceover. Ask what the node IS.
|
|
231
|
-
* Same rule and same reasoning as packages/core/src/runtime/domRealm.ts.
|
|
232
|
-
*/
|
|
233
|
-
function isAudioNode(node: Element | null): node is HTMLAudioElement {
|
|
234
|
-
return (
|
|
235
|
-
node !== null &&
|
|
236
|
-
node.namespaceURI === "http://www.w3.org/1999/xhtml" &&
|
|
237
|
-
node.localName === "audio"
|
|
238
|
-
);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
function resolveScrubAudioEl(doc: Document, music?: PreviewTarget | null): HTMLAudioElement | null {
|
|
242
|
-
if (music) {
|
|
243
|
-
const byId = previewElementFinder(doc, "audio")(music);
|
|
244
|
-
if (isAudioNode(byId)) return byId;
|
|
245
|
-
}
|
|
246
|
-
return doc.querySelector<HTMLAudioElement>("audio[data-timeline-role='music']");
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/** The runtime stops any media running under a paused clock, and a scrub audition
|
|
250
|
-
* IS media running under a paused clock, so it has to borrow the element. Every
|
|
251
|
-
* hop is optional: a runtime predating the hook must no-op, not throw. Wrapped in
|
|
252
|
-
* named calls so `applyScrub` does not carry the optional chains' branches. */
|
|
253
|
-
function leaseScrubElement(el: HTMLAudioElement): void {
|
|
254
|
-
(el.ownerDocument.defaultView as IframeWindow | null)?.__hf?.leasePausedMedia?.(el);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
function releaseScrubElement(el: HTMLAudioElement): void {
|
|
258
|
-
(el.ownerDocument.defaultView as IframeWindow | null)?.__hf?.releasePausedMedia?.(el);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
function applyScrub(el: HTMLAudioElement, audioFileTime: number, previewVolume: number): void {
|
|
262
|
-
if (scrubAudioEl && scrubAudioEl !== el) stopScrubPreviewAudio();
|
|
263
|
-
if (scrubPrevMuted === null) scrubPrevMuted = el.muted;
|
|
264
|
-
if (scrubPrevVolume === null) scrubPrevVolume = el.volume;
|
|
265
|
-
scrubAudioEl = el;
|
|
266
|
-
leaseScrubElement(el);
|
|
267
|
-
try {
|
|
268
|
-
el.muted = false;
|
|
269
|
-
el.volume = SCRUB_VOLUME * normalizePreviewVolume(previewVolume);
|
|
270
|
-
if (Math.abs(el.currentTime - audioFileTime) > 0.04) el.currentTime = audioFileTime;
|
|
271
|
-
if (el.paused) void el.play().catch(() => {});
|
|
272
|
-
} catch {
|
|
273
|
-
/* element not ready */
|
|
274
|
-
}
|
|
275
|
-
if (scrubStopTimer) clearTimeout(scrubStopTimer);
|
|
276
|
-
scrubStopTimer = setTimeout(stopScrubPreviewAudio, 140);
|
|
277
|
-
}
|
|
213
|
+
let scrubFrame: Window | null = null;
|
|
278
214
|
|
|
279
215
|
/**
|
|
280
216
|
* Scrub the preview music audio to `audioFileTime` (seconds into the source
|
|
@@ -291,37 +227,22 @@ export function scrubPreviewAudio(
|
|
|
291
227
|
stopScrubPreviewAudio();
|
|
292
228
|
return;
|
|
293
229
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
230
|
+
const frame = iframe.contentWindow;
|
|
231
|
+
if (scrubFrame && scrubFrame !== frame) stopScrubPreviewAudio();
|
|
232
|
+
scrubFrame = frame;
|
|
233
|
+
const target = music
|
|
234
|
+
? { id: music.id, hfId: music.hfId, domId: music.domId, sourceFile: music.sourceFile }
|
|
235
|
+
: null;
|
|
236
|
+
postRuntimeControlMessage(frame, "scrub-audio", {
|
|
237
|
+
target,
|
|
238
|
+
time: audioFileTime,
|
|
239
|
+
volume: normalizePreviewVolume(previewVolume),
|
|
240
|
+
});
|
|
303
241
|
}
|
|
304
242
|
|
|
305
243
|
export function stopScrubPreviewAudio(): void {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
scrubStopTimer = null;
|
|
309
|
-
}
|
|
310
|
-
const el = scrubAudioEl;
|
|
311
|
-
scrubAudioEl = null;
|
|
312
|
-
if (!el) return;
|
|
313
|
-
// `scrubStopTimer` guarantees this runs within ~140 ms of the last scrub, so
|
|
314
|
-
// the borrow cannot outlive the audition.
|
|
315
|
-
releaseScrubElement(el);
|
|
316
|
-
try {
|
|
317
|
-
el.pause();
|
|
318
|
-
if (scrubPrevMuted !== null) el.muted = scrubPrevMuted;
|
|
319
|
-
if (scrubPrevVolume !== null) el.volume = scrubPrevVolume;
|
|
320
|
-
} catch {
|
|
321
|
-
/* ignore */
|
|
322
|
-
}
|
|
323
|
-
scrubPrevMuted = null;
|
|
324
|
-
scrubPrevVolume = null;
|
|
244
|
+
postRuntimeControlMessage(scrubFrame, "scrub-audio", { time: null });
|
|
245
|
+
scrubFrame = null;
|
|
325
246
|
}
|
|
326
247
|
|
|
327
248
|
// ---------------------------------------------------------------------------
|