@hyperframes/studio 0.9.56 → 0.9.59
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-bya4hgms.js +573 -0
- package/dist/assets/{index-yuN1pZrv.js → index--dcfSUzI.js} +1 -1
- package/dist/assets/{index-CgyBYe2L.js → index-Bxh5lW0C.js} +178 -178
- package/dist/assets/{pausedVideoDecoder-DtvSF8bV.js → pausedVideoDecoder-BKym1jA6.js} +1 -1
- package/dist/index.d.ts +88 -3
- package/dist/index.html +1 -1
- package/dist/index.js +912 -814
- package/package.json +8 -8
- package/src/components/nle/NLEPreview.test.ts +35 -3
- package/src/components/nle/NLEPreview.tsx +5 -4
- package/src/hooks/gsapRuntimePatch.ts +2 -3
- package/src/hooks/gsapRuntimeReaders.test.ts +5 -40
- package/src/hooks/gsapRuntimeReaders.ts +3 -27
- package/src/hooks/useExternalFileChangeCoordinator.test.tsx +20 -0
- package/src/hooks/useExternalFileChangeCoordinator.ts +1 -1
- package/src/hooks/useMusicBeatAnalysis.test.tsx +131 -0
- package/src/hooks/useMusicBeatAnalysis.ts +51 -66
- package/src/hooks/useRenderClipContent.test.ts +21 -0
- package/src/hooks/useRenderClipContent.ts +3 -1
- package/src/index.ts +18 -0
- package/src/player/components/studioShortcuts.ts +3 -2
- package/src/player/hooks/timelinePlayerTestHarness.ts +2 -0
- package/src/player/hooks/timelineSyncHydration.test.ts +28 -2
- package/src/player/hooks/timelineSyncHydration.ts +3 -7
- package/src/player/hooks/usePlaybackKeyboard.test.ts +107 -2
- package/src/player/hooks/usePlaybackKeyboard.ts +38 -1
- package/src/player/hooks/useShadowPreviewReload.ts +131 -14
- package/src/player/hooks/useTimelinePlayer.reloadStill.test.ts +241 -0
- package/src/player/hooks/useTimelinePlayer.ts +13 -1
- package/src/player/hooks/useTimelineSyncCallbacks.ts +4 -0
- package/src/player/lib/previewElements.test.ts +4 -0
- package/src/player/lib/previewElements.ts +1 -0
- package/src/sealedPreviewExports.test.ts +21 -0
- package/src/utils/externalConflictStorage.test.ts +66 -14
- package/src/utils/externalConflictStorage.ts +36 -82
- package/src/utils/gsapSoftReload.ts +2 -14
- package/src/utils/timelineInspector.test.ts +49 -2
- package/src/utils/timelineInspector.ts +21 -2
- package/dist/assets/hyperframes-player-SRLbmEDB.js +0 -565
|
@@ -86,12 +86,13 @@ export function setStudioKeys(overrides: Partial<Record<StudioKeyAction, string>
|
|
|
86
86
|
export const getStudioKeys = (): StudioKeys => current;
|
|
87
87
|
export const getStudioKey = (action: StudioKeyAction): string => current[action];
|
|
88
88
|
|
|
89
|
-
function
|
|
89
|
+
export function subscribeStudioKeys(listener: () => void) {
|
|
90
90
|
listeners.add(listener);
|
|
91
91
|
return () => listeners.delete(listener);
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
export const useStudioKeys = (): StudioKeys =>
|
|
94
|
+
export const useStudioKeys = (): StudioKeys =>
|
|
95
|
+
useSyncExternalStore(subscribeStudioKeys, getStudioKeys);
|
|
95
96
|
|
|
96
97
|
export function useShortcutSections(host?: readonly ShortcutSection[]): readonly ShortcutSection[] {
|
|
97
98
|
const keys = useStudioKeys();
|
|
@@ -157,12 +157,14 @@ export async function paintShadow(getApi: () => TimelinePlayerApi, shadow: HTMLI
|
|
|
157
157
|
export function serveEditingRequests(
|
|
158
158
|
frame: Record<string, unknown>,
|
|
159
159
|
answer: (kind: string, params: unknown) => unknown,
|
|
160
|
+
onPort?: (port: MessagePort) => void,
|
|
160
161
|
): () => void {
|
|
161
162
|
const ports: MessagePort[] = [];
|
|
162
163
|
frame.postMessage = (message: { type?: string } | null) => {
|
|
163
164
|
if (message?.type !== "editing-connect") return;
|
|
164
165
|
const { port1, port2 } = new MessageChannel();
|
|
165
166
|
ports.push(port1);
|
|
167
|
+
onPort?.(port1);
|
|
166
168
|
port1.onmessage = (event: MessageEvent<{ id: number; kind: string; params: unknown }>) => {
|
|
167
169
|
const { id, kind, params } = event.data;
|
|
168
170
|
port1.postMessage({ v: 1, id, ok: true, result: answer(kind, params) });
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// @vitest-environment happy-dom
|
|
2
2
|
|
|
3
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { describe, expect, it, vi } from "vitest";
|
|
4
4
|
import {
|
|
5
5
|
collectSubCompositionDomChildren,
|
|
6
6
|
collectSubCompositionHostState,
|
|
7
|
+
hydrateTimelineFromPreview,
|
|
7
8
|
} from "./timelineSyncHydration";
|
|
8
|
-
import type { ClipManifestClip } from "../lib/playbackTypes";
|
|
9
|
+
import type { ClipManifestClip, PlaybackAdapter } from "../lib/playbackTypes";
|
|
9
10
|
|
|
10
11
|
const clip = (over: Partial<ClipManifestClip>): ClipManifestClip => ({
|
|
11
12
|
id: "x",
|
|
@@ -138,3 +139,28 @@ describe("collectSubCompositionHostState", () => {
|
|
|
138
139
|
expect(state.size).toBe(0);
|
|
139
140
|
});
|
|
140
141
|
});
|
|
142
|
+
|
|
143
|
+
describe("hydrateTimelineFromPreview", () => {
|
|
144
|
+
it("attaches the shortcut listeners to a frame whose document it cannot read", () => {
|
|
145
|
+
const frame = {};
|
|
146
|
+
Object.defineProperty(frame, "document", {
|
|
147
|
+
get: () => {
|
|
148
|
+
throw new DOMException("blocked", "SecurityError");
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
const iframe = document.createElement("iframe");
|
|
152
|
+
Object.defineProperty(iframe, "contentWindow", { value: frame });
|
|
153
|
+
Object.defineProperty(iframe, "contentDocument", { value: null });
|
|
154
|
+
const attachIframeShortcutListeners = vi.fn();
|
|
155
|
+
hydrateTimelineFromPreview({
|
|
156
|
+
iframe,
|
|
157
|
+
adapter: { getDuration: () => 1 } as unknown as PlaybackAdapter,
|
|
158
|
+
processTimelineMessage: vi.fn(),
|
|
159
|
+
enrichMissingCompositions: vi.fn(),
|
|
160
|
+
applyPreviewAudioState: vi.fn(),
|
|
161
|
+
attachIframeShortcutListeners,
|
|
162
|
+
syncTimelineElements: vi.fn(),
|
|
163
|
+
});
|
|
164
|
+
expect(attachIframeShortcutListeners).toHaveBeenCalledOnce();
|
|
165
|
+
});
|
|
166
|
+
});
|
|
@@ -419,15 +419,10 @@ export interface HydrateTimelineFromPreviewInput {
|
|
|
419
419
|
* cross-origin or mid-navigation frame, and none of them is worth failing the
|
|
420
420
|
* adapter's initialisation over.
|
|
421
421
|
*/
|
|
422
|
-
function normalizePreviewDom(
|
|
423
|
-
doc: Document | null,
|
|
424
|
-
iframeWin: IframeWindow | null,
|
|
425
|
-
attachIframeShortcutListeners: () => void,
|
|
426
|
-
): void {
|
|
422
|
+
function normalizePreviewDom(doc: Document | null, iframeWin: IframeWindow | null): void {
|
|
427
423
|
if (!doc || !iframeWin) return;
|
|
428
424
|
normalizePreviewViewport(doc, iframeWin);
|
|
429
425
|
autoHealMissingCompositionIds(doc);
|
|
430
|
-
attachIframeShortcutListeners();
|
|
431
426
|
}
|
|
432
427
|
|
|
433
428
|
/** Hand the runtime's own clip manifest to the timeline, if it published one. */
|
|
@@ -444,7 +439,8 @@ export function hydrateTimelineFromPreview(input: HydrateTimelineFromPreviewInpu
|
|
|
444
439
|
try {
|
|
445
440
|
const doc = safeContentDocument(iframe);
|
|
446
441
|
const iframeWin = (iframe?.contentWindow as IframeWindow | null) ?? null;
|
|
447
|
-
normalizePreviewDom(doc, iframeWin
|
|
442
|
+
normalizePreviewDom(doc, iframeWin);
|
|
443
|
+
input.attachIframeShortcutListeners();
|
|
448
444
|
applyRuntimeClipManifest(iframeWin, input.processTimelineMessage);
|
|
449
445
|
input.enrichMissingCompositions();
|
|
450
446
|
input.applyPreviewAudioState();
|
|
@@ -8,6 +8,7 @@ import { usePlaybackKeyboard } from "./usePlaybackKeyboard";
|
|
|
8
8
|
import { usePlayerStore } from "../store/playerStore";
|
|
9
9
|
import { setStudioKeys } from "../components/studioShortcuts";
|
|
10
10
|
import { useLinkedClipPreferences } from "../../utils/linkedClipPreferences";
|
|
11
|
+
import { detachedFakeIframe, serveEditingRequests } from "./timelinePlayerTestHarness";
|
|
11
12
|
|
|
12
13
|
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
|
13
14
|
|
|
@@ -28,10 +29,11 @@ interface Spies {
|
|
|
28
29
|
interface HookHandle {
|
|
29
30
|
dispatch: (event: KeyboardEvent) => void;
|
|
30
31
|
release: (event: KeyboardEvent) => void;
|
|
32
|
+
attach: () => void;
|
|
31
33
|
spies: Spies;
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
function setupHook(): HookHandle {
|
|
36
|
+
function setupHook(iframe: HTMLIFrameElement | null = null): HookHandle {
|
|
35
37
|
const spies: Spies = {
|
|
36
38
|
seek: vi.fn(),
|
|
37
39
|
play: vi.fn(),
|
|
@@ -42,7 +44,7 @@ function setupHook(): HookHandle {
|
|
|
42
44
|
let captured: ReturnType<typeof usePlaybackKeyboard> | null = null;
|
|
43
45
|
|
|
44
46
|
function Harness() {
|
|
45
|
-
const iframeRef = React.useRef<HTMLIFrameElement | null>(
|
|
47
|
+
const iframeRef = React.useRef<HTMLIFrameElement | null>(iframe);
|
|
46
48
|
const shuttleDirectionRef = React.useRef<"forward" | "backward" | null>(null);
|
|
47
49
|
const shuttleSpeedIndexRef = React.useRef(0);
|
|
48
50
|
const iframeShortcutCleanupRef = React.useRef<(() => void) | null>(null);
|
|
@@ -72,6 +74,7 @@ function setupHook(): HookHandle {
|
|
|
72
74
|
return {
|
|
73
75
|
dispatch: (event) => captured!.playbackKeyDownRef.current(event),
|
|
74
76
|
release: (event) => captured!.playbackKeyUpRef.current(event),
|
|
77
|
+
attach: () => captured!.attachIframeShortcutListeners(),
|
|
75
78
|
spies,
|
|
76
79
|
};
|
|
77
80
|
}
|
|
@@ -483,3 +486,105 @@ describe("usePlaybackKeyboard: modifier combos and named keys", () => {
|
|
|
483
486
|
expect(spies.playBackward).not.toHaveBeenCalled();
|
|
484
487
|
});
|
|
485
488
|
});
|
|
489
|
+
|
|
490
|
+
describe("usePlaybackKeyboard: a sealed preview frame", () => {
|
|
491
|
+
const closers: Array<() => void> = [];
|
|
492
|
+
afterEach(() => closers.splice(0).forEach((close) => close()));
|
|
493
|
+
|
|
494
|
+
function sealedFrame() {
|
|
495
|
+
const frame: Record<string, unknown> = {};
|
|
496
|
+
const iframe = detachedFakeIframe(frame);
|
|
497
|
+
Object.defineProperty(iframe, "contentDocument", { value: null });
|
|
498
|
+
Object.defineProperty(frame, "document", {
|
|
499
|
+
get: () => {
|
|
500
|
+
throw new DOMException("blocked", "SecurityError");
|
|
501
|
+
},
|
|
502
|
+
});
|
|
503
|
+
const watched: string[][] = [];
|
|
504
|
+
let port: MessagePort | null = null;
|
|
505
|
+
closers.push(
|
|
506
|
+
serveEditingRequests(
|
|
507
|
+
frame,
|
|
508
|
+
(kind, params) => {
|
|
509
|
+
if (kind !== "watch-keys") return null;
|
|
510
|
+
const { combos } = params as { combos: string[] };
|
|
511
|
+
watched.push(combos);
|
|
512
|
+
return { watching: combos.length };
|
|
513
|
+
},
|
|
514
|
+
(framePort) => (port = framePort),
|
|
515
|
+
),
|
|
516
|
+
);
|
|
517
|
+
const forward = (type: "keydown" | "keyup", key: string, code: string) =>
|
|
518
|
+
port!.postMessage({
|
|
519
|
+
v: 1,
|
|
520
|
+
event: "key",
|
|
521
|
+
key: {
|
|
522
|
+
type,
|
|
523
|
+
key,
|
|
524
|
+
code,
|
|
525
|
+
altKey: false,
|
|
526
|
+
ctrlKey: false,
|
|
527
|
+
metaKey: false,
|
|
528
|
+
shiftKey: false,
|
|
529
|
+
repeat: false,
|
|
530
|
+
},
|
|
531
|
+
});
|
|
532
|
+
return { iframe, watched, forward };
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
it("asks the frame for exactly the playback keys, and again when they are remapped", async () => {
|
|
536
|
+
const { iframe, watched } = sealedFrame();
|
|
537
|
+
setupHook(iframe).attach();
|
|
538
|
+
await vi.waitFor(() => expect(watched).toHaveLength(1));
|
|
539
|
+
expect(new Set(watched[0])).toEqual(
|
|
540
|
+
new Set([
|
|
541
|
+
"Space",
|
|
542
|
+
"ArrowLeft",
|
|
543
|
+
"ArrowRight",
|
|
544
|
+
"shift+ArrowLeft",
|
|
545
|
+
"shift+ArrowRight",
|
|
546
|
+
"m",
|
|
547
|
+
"shift+l",
|
|
548
|
+
"k",
|
|
549
|
+
"j",
|
|
550
|
+
"l",
|
|
551
|
+
"i",
|
|
552
|
+
"shift+i",
|
|
553
|
+
"o",
|
|
554
|
+
"shift+o",
|
|
555
|
+
"a",
|
|
556
|
+
"e",
|
|
557
|
+
]),
|
|
558
|
+
);
|
|
559
|
+
act(() => setStudioKeys({ playPause: "p" }));
|
|
560
|
+
await vi.waitFor(() => expect(watched).toHaveLength(2));
|
|
561
|
+
expect(watched[1]).toContain("p");
|
|
562
|
+
expect(watched[1]).not.toContain("Space");
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
it("plays and steps from the keys the frame forwards, keyups included", async () => {
|
|
566
|
+
const { iframe, watched, forward } = sealedFrame();
|
|
567
|
+
const { attach, spies } = setupHook(iframe);
|
|
568
|
+
attach();
|
|
569
|
+
await vi.waitFor(() => expect(watched).toHaveLength(1));
|
|
570
|
+
forward("keydown", " ", "Space");
|
|
571
|
+
await vi.waitFor(() => expect(spies.play).toHaveBeenCalledOnce());
|
|
572
|
+
forward("keydown", "k", "KeyK");
|
|
573
|
+
forward("keydown", "l", "KeyL");
|
|
574
|
+
await vi.waitFor(() => expect(spies.seek).toHaveBeenCalledOnce());
|
|
575
|
+
forward("keyup", "k", "KeyK");
|
|
576
|
+
forward("keydown", "l", "KeyL");
|
|
577
|
+
await vi.waitFor(() => expect(spies.play).toHaveBeenCalledTimes(2));
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
it("stops watching when its listeners are replaced", async () => {
|
|
581
|
+
const { iframe, watched } = sealedFrame();
|
|
582
|
+
const { attach } = setupHook(iframe);
|
|
583
|
+
attach();
|
|
584
|
+
await vi.waitFor(() => expect(watched).toHaveLength(1));
|
|
585
|
+
attach();
|
|
586
|
+
await vi.waitFor(() => expect(watched).toHaveLength(3));
|
|
587
|
+
expect(watched[1]).toEqual([]);
|
|
588
|
+
expect(watched[2]).toEqual(watched[0]);
|
|
589
|
+
});
|
|
590
|
+
});
|
|
@@ -15,7 +15,13 @@ import {
|
|
|
15
15
|
} from "../lib/playbackShortcuts";
|
|
16
16
|
import { canvasNudgeKeysClaimed } from "../../utils/canvasNudgeGate";
|
|
17
17
|
import { usePlayerStore } from "../store/playerStore";
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
getStudioKey,
|
|
20
|
+
matchesKey,
|
|
21
|
+
subscribeStudioKeys,
|
|
22
|
+
type StudioKeyAction,
|
|
23
|
+
} from "../components/studioShortcuts";
|
|
24
|
+
import { previewEditingClient, previewFrameOpaque } from "../lib/previewChannel";
|
|
19
25
|
import { resolveCanvasNudgeDelta } from "../../components/editor/domEditNudge";
|
|
20
26
|
import { stepFrameTime } from "../lib/time";
|
|
21
27
|
import { useLinkedClipPreferences } from "../../utils/linkedClipPreferences";
|
|
@@ -67,6 +73,28 @@ function ignoresPlaybackKey(e: KeyboardEvent): boolean {
|
|
|
67
73
|
});
|
|
68
74
|
}
|
|
69
75
|
|
|
76
|
+
type KeyHandlerRef = React.RefObject<(e: KeyboardEvent) => void>;
|
|
77
|
+
|
|
78
|
+
function forwardSealedFrameKeys(
|
|
79
|
+
iframe: HTMLIFrameElement,
|
|
80
|
+
keyDown: KeyHandlerRef,
|
|
81
|
+
keyUp: KeyHandlerRef,
|
|
82
|
+
): () => void {
|
|
83
|
+
const client = previewEditingClient(iframe);
|
|
84
|
+
const watch = (combos: string[]) => void client.request("watch-keys", { combos }).catch(() => {});
|
|
85
|
+
const watchPlayback = () => watch(PLAYBACK_ACTIONS.map(getStudioKey));
|
|
86
|
+
watchPlayback();
|
|
87
|
+
const stopRebinds = subscribeStudioKeys(watchPlayback);
|
|
88
|
+
const stopKeys = client.onKey((key) =>
|
|
89
|
+
(key.type === "keydown" ? keyDown : keyUp).current(new KeyboardEvent(key.type, key)),
|
|
90
|
+
);
|
|
91
|
+
return () => {
|
|
92
|
+
stopRebinds();
|
|
93
|
+
stopKeys();
|
|
94
|
+
watch([]);
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
70
98
|
function handleWorkAreaKey(
|
|
71
99
|
e: KeyboardEvent,
|
|
72
100
|
action: PlaybackAction,
|
|
@@ -198,6 +226,15 @@ export function usePlaybackKeyboard({
|
|
|
198
226
|
const attachIframeShortcutListeners = useCallback(() => {
|
|
199
227
|
iframeShortcutCleanupRef.current?.();
|
|
200
228
|
iframeShortcutCleanupRef.current = null;
|
|
229
|
+
const iframe = iframeRef.current;
|
|
230
|
+
if (iframe && previewFrameOpaque(iframe)) {
|
|
231
|
+
iframeShortcutCleanupRef.current = forwardSealedFrameKeys(
|
|
232
|
+
iframe,
|
|
233
|
+
playbackKeyDownRef,
|
|
234
|
+
playbackKeyUpRef,
|
|
235
|
+
);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
201
238
|
|
|
202
239
|
let iframeWin: Window | null = null;
|
|
203
240
|
let iframeDoc: Document | null = null;
|
|
@@ -12,6 +12,7 @@ import { refusedPreviewStatus } from "@hyperframes/core/studio-preview-mark";
|
|
|
12
12
|
import { logReload } from "../../utils/reloadDebug";
|
|
13
13
|
import {
|
|
14
14
|
useTimelineSyncCallbacks,
|
|
15
|
+
planShadowAlone,
|
|
15
16
|
planShadowReload,
|
|
16
17
|
planShadowPromotion,
|
|
17
18
|
planShadowDiscard,
|
|
@@ -33,6 +34,28 @@ import { READY_TIMEOUT_CAUSE, useShadowReloadRetry } from "./useShadowReloadRetr
|
|
|
33
34
|
export const SHADOW_READY_TIMEOUT_MS = 15_000;
|
|
34
35
|
// A busy machine can need more than one budget; the shadow keeps loading for this many before it is dropped.
|
|
35
36
|
export const SHADOW_READY_BUDGETS = 3;
|
|
37
|
+
const STILL_RELEASE_MAX_MS = 3_000;
|
|
38
|
+
|
|
39
|
+
type HeldStill = {
|
|
40
|
+
release: () => void;
|
|
41
|
+
time: number | null;
|
|
42
|
+
playing: boolean;
|
|
43
|
+
liveSlot: PreviewIframeSlot;
|
|
44
|
+
liveIframe: HTMLIFrameElement;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
function releaseAfterPaint(iframe: HTMLIFrameElement | null, release: () => void) {
|
|
48
|
+
let done = false;
|
|
49
|
+
const go = () => {
|
|
50
|
+
if (done) return;
|
|
51
|
+
done = true;
|
|
52
|
+
release();
|
|
53
|
+
};
|
|
54
|
+
setTimeout(go, STILL_RELEASE_MAX_MS);
|
|
55
|
+
void (restoreSeekPainted(iframe) ?? Promise.resolve()).then(() =>
|
|
56
|
+
requestAnimationFrame(() => requestAnimationFrame(go)),
|
|
57
|
+
);
|
|
58
|
+
}
|
|
36
59
|
|
|
37
60
|
function restoreSeekPainted(iframe: HTMLIFrameElement | null): Promise<void> | undefined {
|
|
38
61
|
if (!iframe) return undefined;
|
|
@@ -83,6 +106,8 @@ type UseShadowPreviewReloadParams = Omit<
|
|
|
83
106
|
onReloadFailed?: (message: string) => void;
|
|
84
107
|
/** Puts the promoted document at the live frame's time, playing if the live frame was. */
|
|
85
108
|
handOverPlayback: (time: number, playing: boolean) => void;
|
|
109
|
+
/** Covers the stage with the live frame so a reload holds one page; returns what drops it, null keeps two pages. */
|
|
110
|
+
holdStill?: (live: HTMLIFrameElement) => Promise<(() => void) | null>;
|
|
86
111
|
};
|
|
87
112
|
|
|
88
113
|
export function useShadowPreviewReload({
|
|
@@ -100,6 +125,7 @@ export function useShadowPreviewReload({
|
|
|
100
125
|
onPromoted,
|
|
101
126
|
onReloadFailed,
|
|
102
127
|
handOverPlayback,
|
|
128
|
+
holdStill,
|
|
103
129
|
}: UseShadowPreviewReloadParams) {
|
|
104
130
|
const shadowIframeRef = useRef<HTMLIFrameElement | null>(null);
|
|
105
131
|
const shadowProbeIntervalRef = useRef<ReturnType<typeof setInterval> | undefined>(undefined);
|
|
@@ -127,6 +153,38 @@ export function useShadowPreviewReload({
|
|
|
127
153
|
const retry = useShadowReloadRetry(shadowGenRef, shadowUrlRef, beginShadowReloadRef);
|
|
128
154
|
const promoteWhenReadyRef = useRef<(gen: number) => void>(() => {});
|
|
129
155
|
const [previewSlots, setPreviewSlots] = useState<PreviewIframeSlot[]>([{ gen: 0, role: "live" }]);
|
|
156
|
+
const slotsRef = useRef(previewSlots);
|
|
157
|
+
slotsRef.current = previewSlots;
|
|
158
|
+
const holdStillRef = useRef(holdStill);
|
|
159
|
+
holdStillRef.current = holdStill;
|
|
160
|
+
const heldRef = useRef<HeldStill | null>(null);
|
|
161
|
+
// The newest reload asked for while a still is being taken; it starts once the still is up.
|
|
162
|
+
const holdingUrlRef = useRef<string | null>(null);
|
|
163
|
+
const holdTokenRef = useRef(0);
|
|
164
|
+
|
|
165
|
+
const restoringRef = useRef<(() => void) | null>(null);
|
|
166
|
+
const dropRestoring = useCallback(() => {
|
|
167
|
+
const release = restoringRef.current;
|
|
168
|
+
restoringRef.current = null;
|
|
169
|
+
release?.();
|
|
170
|
+
}, []);
|
|
171
|
+
const restoreLive = useCallback(
|
|
172
|
+
(held: HeldStill) => {
|
|
173
|
+
dropRestoring();
|
|
174
|
+
setPreviewSlots([held.liveSlot]);
|
|
175
|
+
pendingSeekRef.current = held.time;
|
|
176
|
+
restoringRef.current = held.release;
|
|
177
|
+
setTimeout(() => {
|
|
178
|
+
if (restoringRef.current === held.release) dropRestoring();
|
|
179
|
+
}, SHADOW_READY_TIMEOUT_MS);
|
|
180
|
+
},
|
|
181
|
+
[pendingSeekRef, dropRestoring],
|
|
182
|
+
);
|
|
183
|
+
const onLiveLoaded = useCallback(() => {
|
|
184
|
+
const release = restoringRef.current;
|
|
185
|
+
restoringRef.current = null;
|
|
186
|
+
if (release) releaseAfterPaint(iframeRef.current, release);
|
|
187
|
+
}, [iframeRef]);
|
|
130
188
|
|
|
131
189
|
const stopPendingShadow = useCallback(() => {
|
|
132
190
|
clearTimeout(readyTimerRef.current);
|
|
@@ -153,7 +211,10 @@ export function useShadowPreviewReload({
|
|
|
153
211
|
shadowIframeRef.current = null;
|
|
154
212
|
isRefreshingRef.current = false;
|
|
155
213
|
pendingSeekRef.current = null;
|
|
156
|
-
|
|
214
|
+
const held = heldRef.current;
|
|
215
|
+
heldRef.current = null;
|
|
216
|
+
if (held) restoreLive(held);
|
|
217
|
+
else setPreviewSlots(planShadowDiscard);
|
|
157
218
|
setPreviewReloading(false);
|
|
158
219
|
const message = `The preview did not reload (${cause}). It was still waiting for ${waitingFor}.${got} The previous preview is still showing.`;
|
|
159
220
|
logReload("shadow-failed", { cause, waitingFor });
|
|
@@ -163,7 +224,7 @@ export function useShadowPreviewReload({
|
|
|
163
224
|
onReloadFailedRef.current?.(message);
|
|
164
225
|
retry.afterFailure(cause, failedGen);
|
|
165
226
|
},
|
|
166
|
-
[stopPendingShadow, retry, isRefreshingRef, pendingSeekRef],
|
|
227
|
+
[stopPendingShadow, retry, isRefreshingRef, pendingSeekRef, restoreLive],
|
|
167
228
|
);
|
|
168
229
|
|
|
169
230
|
const gestureSavesOnScreen = useCallback(() => {
|
|
@@ -195,11 +256,10 @@ export function useShadowPreviewReload({
|
|
|
195
256
|
return waitThenRetry(gen, "gesture", (retry) =>
|
|
196
257
|
afterStudioManualEditGestures(liveDoc, retry),
|
|
197
258
|
);
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
)
|
|
202
|
-
return false;
|
|
259
|
+
// Behind a still the live page is gone, so it has no saves to count; only the file revision tells.
|
|
260
|
+
const savesSame =
|
|
261
|
+
heldRef.current !== null || gestureSavesOnScreen() === savesAtRequestRef.current;
|
|
262
|
+
if (savesSame && studioFileRevision() === revisionAtRequestRef.current) return false;
|
|
203
263
|
if (isStudioEditSaving()) return waitThenRetry(gen, "save", afterStudioPendingEdits);
|
|
204
264
|
logReload("shadow-reloaded-after-gesture-save", { gen });
|
|
205
265
|
const url = new URL(shadowUrlRef.current, window.location.origin);
|
|
@@ -224,9 +284,11 @@ export function useShadowPreviewReload({
|
|
|
224
284
|
const { shadow, pending } = promotable;
|
|
225
285
|
stopPendingShadow();
|
|
226
286
|
// The live frame kept playing, stopped at the end or was seeked while the shadow loaded.
|
|
287
|
+
const held = heldRef.current;
|
|
288
|
+
heldRef.current = null;
|
|
227
289
|
const live = getAdapter();
|
|
228
|
-
const liveTime = live?.getTime();
|
|
229
|
-
const playing = usePlayerStore.getState().isPlaying;
|
|
290
|
+
const liveTime = held ? held.time : live?.getTime();
|
|
291
|
+
const playing = held ? held.playing : usePlayerStore.getState().isPlaying;
|
|
230
292
|
live?.pause();
|
|
231
293
|
// The store takes the new document's timeline only now that it is the one on screen, and reads it there.
|
|
232
294
|
const retired = iframeRef.current;
|
|
@@ -237,6 +299,7 @@ export function useShadowPreviewReload({
|
|
|
237
299
|
applyPreviewAudioState();
|
|
238
300
|
setPreviewSlots((prev) => planShadowPromotion(prev, gen));
|
|
239
301
|
if (liveTime != null) handOverPlaybackRef.current(liveTime, playing);
|
|
302
|
+
if (held) releaseAfterPaint(shadow, held.release);
|
|
240
303
|
announcePreviewPromoted({ retired, live: shadow });
|
|
241
304
|
onPromotedRef.current?.();
|
|
242
305
|
setPreviewReloading(false);
|
|
@@ -349,8 +412,8 @@ export function useShadowPreviewReload({
|
|
|
349
412
|
armReadyTimerRef.current(gen);
|
|
350
413
|
}, []);
|
|
351
414
|
|
|
352
|
-
const
|
|
353
|
-
(url: string) => {
|
|
415
|
+
const startShadowReload = useCallback(
|
|
416
|
+
(url: string, alone: boolean) => {
|
|
354
417
|
retry.started();
|
|
355
418
|
shadowGenRef.current += 1;
|
|
356
419
|
const gen = shadowGenRef.current;
|
|
@@ -361,12 +424,55 @@ export function useShadowPreviewReload({
|
|
|
361
424
|
savesAtRequestRef.current = gestureSavesOnScreen();
|
|
362
425
|
revisionAtRequestRef.current = studioFileRevision();
|
|
363
426
|
armReadyTimer(gen);
|
|
364
|
-
setPreviewSlots((prev) =>
|
|
427
|
+
setPreviewSlots((prev) =>
|
|
428
|
+
alone ? planShadowAlone(gen, url) : planShadowReload(prev, gen, url),
|
|
429
|
+
);
|
|
365
430
|
// Thumbnails of the edit wait for the new preview instead of competing with it.
|
|
366
431
|
setPreviewReloading(true);
|
|
367
432
|
},
|
|
368
433
|
[retry, stopPendingShadow, armReadyTimer, gestureSavesOnScreen],
|
|
369
434
|
);
|
|
435
|
+
|
|
436
|
+
const beginShadowReload = useCallback(
|
|
437
|
+
(url: string) => {
|
|
438
|
+
const live = iframeRef.current;
|
|
439
|
+
const take = holdStillRef.current;
|
|
440
|
+
if (heldRef.current || !take || !live?.isConnected) {
|
|
441
|
+
startShadowReload(url, heldRef.current !== null);
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
if (holdingUrlRef.current !== null) {
|
|
445
|
+
holdingUrlRef.current = url;
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
holdingUrlRef.current = url;
|
|
449
|
+
const token = ++holdTokenRef.current;
|
|
450
|
+
// Paused first, so the still is the frame the reload resumes from.
|
|
451
|
+
const playing = usePlayerStore.getState().isPlaying;
|
|
452
|
+
getAdapter()?.pause();
|
|
453
|
+
const time = getAdapter()?.getTime() ?? null;
|
|
454
|
+
const liveSlot = slotsRef.current.find((slot) => slot.role === "live");
|
|
455
|
+
void new Promise<(() => void) | null>((resolve) => resolve(take(live)))
|
|
456
|
+
// expected: a still that cannot be taken keeps both pages for this reload, as before
|
|
457
|
+
.catch(() => null)
|
|
458
|
+
.then((release) => {
|
|
459
|
+
if (token !== holdTokenRef.current) {
|
|
460
|
+
release?.();
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
const latest = holdingUrlRef.current ?? url;
|
|
464
|
+
holdingUrlRef.current = null;
|
|
465
|
+
if (release && liveSlot && iframeRef.current === live) {
|
|
466
|
+
heldRef.current = { release, time, playing, liveSlot, liveIframe: live };
|
|
467
|
+
} else {
|
|
468
|
+
release?.();
|
|
469
|
+
if (playing) getAdapter()?.play();
|
|
470
|
+
}
|
|
471
|
+
startShadowReload(latest, heldRef.current !== null);
|
|
472
|
+
});
|
|
473
|
+
},
|
|
474
|
+
[iframeRef, getAdapter, startShadowReload],
|
|
475
|
+
);
|
|
370
476
|
beginShadowReloadRef.current = beginShadowReload;
|
|
371
477
|
|
|
372
478
|
// Composition switch (not an edit reload): drop any in-flight shadow.
|
|
@@ -378,9 +484,15 @@ export function useShadowPreviewReload({
|
|
|
378
484
|
isRefreshingRef.current = false;
|
|
379
485
|
pendingSeekRef.current = null;
|
|
380
486
|
usePlayerStore.getState().setTimelineReady(false);
|
|
381
|
-
|
|
487
|
+
const held = heldRef.current;
|
|
488
|
+
heldRef.current = null;
|
|
489
|
+
holdingUrlRef.current = null;
|
|
490
|
+
holdTokenRef.current += 1;
|
|
491
|
+
dropRestoring();
|
|
492
|
+
setPreviewSlots(held ? [held.liveSlot] : planShadowDiscard);
|
|
493
|
+
held?.release();
|
|
382
494
|
setPreviewReloading(false);
|
|
383
|
-
}, [retry, stopPendingShadow, isRefreshingRef, pendingSeekRef]);
|
|
495
|
+
}, [retry, stopPendingShadow, isRefreshingRef, pendingSeekRef, dropRestoring]);
|
|
384
496
|
|
|
385
497
|
// Hiding the tab pauses the budget; showing it again restarts the full budget for a pending shadow.
|
|
386
498
|
useMountEffect(() => {
|
|
@@ -397,6 +509,10 @@ export function useShadowPreviewReload({
|
|
|
397
509
|
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
398
510
|
retry.cancel();
|
|
399
511
|
stopPendingShadow();
|
|
512
|
+
heldRef.current?.release();
|
|
513
|
+
heldRef.current = null;
|
|
514
|
+
holdTokenRef.current += 1;
|
|
515
|
+
dropRestoring();
|
|
400
516
|
setPreviewReloading(false);
|
|
401
517
|
};
|
|
402
518
|
});
|
|
@@ -410,5 +526,6 @@ export function useShadowPreviewReload({
|
|
|
410
526
|
beginShadowReload,
|
|
411
527
|
resetPreviewSlots,
|
|
412
528
|
previewGeneration,
|
|
529
|
+
onLiveLoaded,
|
|
413
530
|
};
|
|
414
531
|
}
|