@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
|
@@ -3,7 +3,10 @@ import type { HistoryListItem, HistoryResult } from "@hyperframes/studio-server"
|
|
|
3
3
|
import { studioFileContentVersion, studioWriteHeaders } from "../utils/studioFileVersion";
|
|
4
4
|
import type { RestoreFiles } from "../utils/gsapUndoRestore";
|
|
5
5
|
import { studioApiFetch } from "../utils/studioApiFetch";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
setStudioPendingEditClaimClock,
|
|
8
|
+
setStudioPendingEditsSettled,
|
|
9
|
+
} from "../utils/studioPendingEdits";
|
|
7
10
|
import type { RecordEditInput } from "../utils/studioFileHistory";
|
|
8
11
|
import { generateId } from "../utils/generateId";
|
|
9
12
|
|
|
@@ -41,6 +44,7 @@ interface HistoryView {
|
|
|
41
44
|
forward: NextStep | null;
|
|
42
45
|
}
|
|
43
46
|
|
|
47
|
+
const APP_KEEPS_NO_HISTORY = 404;
|
|
44
48
|
const EMPTY: HistoryView = { entries: [], back: null, forward: null };
|
|
45
49
|
/** ponytail: the newest entries' content is kept; older ones step through the server only. */
|
|
46
50
|
const OWN_ENTRIES_KEPT = 100;
|
|
@@ -201,12 +205,28 @@ function redoneAt(view: HistoryView): number | null {
|
|
|
201
205
|
return view.entries.find((entry) => entry.id === undo?.undoes)?.endedAt ?? null;
|
|
202
206
|
}
|
|
203
207
|
|
|
208
|
+
function closeHeldClaimWithAClaimOfNothing(
|
|
209
|
+
projectId: string,
|
|
210
|
+
heldClaimRef: { current: { paths: string[]; at: number } | null },
|
|
211
|
+
refresh: () => Promise<void>,
|
|
212
|
+
): Promise<void> {
|
|
213
|
+
if (!heldClaimRef.current) return Promise.resolve();
|
|
214
|
+
heldClaimRef.current = null;
|
|
215
|
+
return post(historyUrl(projectId, "/claim"), { label: "Edited in Studio", paths: [] }).then(
|
|
216
|
+
(reply) => {
|
|
217
|
+
if (reply.ok) void refresh();
|
|
218
|
+
},
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
204
222
|
/** Studio's undo over the server's project history: an edit claims what it wrote; Cmd+Z steps the person's. */
|
|
223
|
+
// fallow-ignore-next-line complexity
|
|
205
224
|
export function usePersistentEditHistory({ projectId }: UsePersistentEditHistoryOptions) {
|
|
206
225
|
const [view, setView] = useState<HistoryView>(EMPTY);
|
|
207
226
|
const [loaded, setLoaded] = useState(false);
|
|
208
227
|
// A coalescing claim the server just took, until `refresh()` brings its entry into `view`.
|
|
209
228
|
const heldClaimRef = useRef<{ paths: string[]; at: number } | null>(null);
|
|
229
|
+
const claimsAfterTheClose = useRef<Promise<void>>(Promise.resolve());
|
|
210
230
|
const projectIdRef = useRef(projectId);
|
|
211
231
|
projectIdRef.current = projectId;
|
|
212
232
|
const [own] = useState(createOwnHistory);
|
|
@@ -239,11 +259,24 @@ export function usePersistentEditHistory({ projectId }: UsePersistentEditHistory
|
|
|
239
259
|
return () => setStudioPendingEditClaimClock(null);
|
|
240
260
|
}, [own]);
|
|
241
261
|
|
|
262
|
+
useEffect(() => {
|
|
263
|
+
if (!projectId) return;
|
|
264
|
+
setStudioPendingEditsSettled(() => {
|
|
265
|
+
claimsAfterTheClose.current = closeHeldClaimWithAClaimOfNothing(
|
|
266
|
+
projectId,
|
|
267
|
+
heldClaimRef,
|
|
268
|
+
refresh,
|
|
269
|
+
);
|
|
270
|
+
});
|
|
271
|
+
return () => setStudioPendingEditsSettled(null);
|
|
272
|
+
}, [projectId, refresh]);
|
|
273
|
+
|
|
242
274
|
const recordEdit = useCallback(
|
|
243
275
|
async ({ label, coalesceKey, coalesceMs, files, targets, created = [] }: RecordEditInput) => {
|
|
244
276
|
if (!projectId) return;
|
|
245
277
|
const paths = [...Object.keys(files), ...created];
|
|
246
278
|
own.overtake();
|
|
279
|
+
await claimsAfterTheClose.current;
|
|
247
280
|
const reply = await post(historyUrl(projectId, "/claim"), {
|
|
248
281
|
label,
|
|
249
282
|
paths,
|
|
@@ -286,8 +319,8 @@ export function usePersistentEditHistory({ projectId }: UsePersistentEditHistory
|
|
|
286
319
|
);
|
|
287
320
|
heldClaimRef.current = null;
|
|
288
321
|
void refresh();
|
|
289
|
-
|
|
290
|
-
|
|
322
|
+
if (!posted.ok && posted.status === APP_KEEPS_NO_HISTORY)
|
|
323
|
+
return { ok: false, reason: "empty" };
|
|
291
324
|
if (!posted.ok) return { ok: false, reason: "failed", message: posted.error };
|
|
292
325
|
const reply = posted.body as HistoryResult;
|
|
293
326
|
if (!reply.ok) {
|
|
@@ -190,6 +190,27 @@ describe("useRenderClipContent", () => {
|
|
|
190
190
|
if (isValidElement(content)) expect(content.type).toBe(AudioWaveform);
|
|
191
191
|
});
|
|
192
192
|
|
|
193
|
+
it("decodes a file from outside the project only when it is short and its length is known", () => {
|
|
194
|
+
const remote = (sourceDuration?: number) =>
|
|
195
|
+
renderClipContent({
|
|
196
|
+
id: "talk",
|
|
197
|
+
tag: "audio",
|
|
198
|
+
start: 0,
|
|
199
|
+
duration: 4,
|
|
200
|
+
track: 1,
|
|
201
|
+
src: "https://cdn.example.com/talk.mp3",
|
|
202
|
+
sourceDuration,
|
|
203
|
+
});
|
|
204
|
+
const audioUrlOf = (content: ReactNode) =>
|
|
205
|
+
isValidElement<{ audioUrl: string; waveformUrl?: string }>(content)
|
|
206
|
+
? [content.props.audioUrl, content.props.waveformUrl]
|
|
207
|
+
: null;
|
|
208
|
+
|
|
209
|
+
expect(audioUrlOf(remote(180))).toEqual(["https://cdn.example.com/talk.mp3", undefined]);
|
|
210
|
+
expect(audioUrlOf(remote(62 * 60))).toEqual(["", undefined]);
|
|
211
|
+
expect(audioUrlOf(remote())).toEqual(["", undefined]);
|
|
212
|
+
});
|
|
213
|
+
|
|
193
214
|
it("routes root-relative iframe media back through the active project", () => {
|
|
194
215
|
usePlayerStore.setState({ thumbnailMode: "adaptive" });
|
|
195
216
|
const resolvedRootMedia = `${window.location.origin}/assets/clip.mp4`;
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
import { usePlayerStore } from "../player/store/playerStore";
|
|
26
26
|
import { thumbnailRevisionOf } from "../player/store/thumbnailSlice";
|
|
27
27
|
import { effectiveThumbnailMode } from "../player/lib/thumbnailPolicy";
|
|
28
|
+
import { fitsBeatAnalysis } from "../utils/timelineInspector";
|
|
28
29
|
|
|
29
30
|
export function normalizeCompositionSrc(
|
|
30
31
|
compSrc: string,
|
|
@@ -84,8 +85,9 @@ function renderAudioClip(
|
|
|
84
85
|
? buildProjectApiPath(pid, `/waveform/${encodedRelative}`)
|
|
85
86
|
: undefined;
|
|
86
87
|
const { start, end } = trimFractions(el);
|
|
88
|
+
const serverPeaksOrShortFile = waveformUrl !== undefined || fitsBeatAnalysis(el);
|
|
87
89
|
const waveform = createElement(AudioWaveform, {
|
|
88
|
-
audioUrl,
|
|
90
|
+
audioUrl: serverPeaksOrShortFile ? audioUrl : "",
|
|
89
91
|
waveformUrl,
|
|
90
92
|
label: "",
|
|
91
93
|
labelColor,
|
package/src/index.ts
CHANGED
|
@@ -62,6 +62,7 @@ export {
|
|
|
62
62
|
findPreviewElementForTimelineElement,
|
|
63
63
|
readable,
|
|
64
64
|
standInFor,
|
|
65
|
+
standInHandle,
|
|
65
66
|
} from "./components/editor/previewSelection";
|
|
66
67
|
export { PREVIEW_QUALITY_LEVELS, type PreviewQuality } from "@hyperframes/core/preview-quality";
|
|
67
68
|
export type {
|
|
@@ -116,6 +117,7 @@ export { ImageThumbnail } from "./player/components/ImageThumbnail";
|
|
|
116
117
|
export type { ImageThumbnailProps } from "./player/components/ImageThumbnail";
|
|
117
118
|
export { useRenderClipContent } from "./hooks/useRenderClipContent";
|
|
118
119
|
export { useThumbnailStill } from "./hooks/useThumbnailStill";
|
|
120
|
+
export { fetchParsedAnimations, getAnimationsForElement } from "./hooks/useGsapTweenCache";
|
|
119
121
|
export type { ThumbnailStill, UseThumbnailStillOptions } from "./hooks/useThumbnailStill";
|
|
120
122
|
export type { UseRenderClipContentOptions } from "./hooks/useRenderClipContent";
|
|
121
123
|
export type { ThumbnailPriority } from "./player/lib/thumbnailScheduler";
|
|
@@ -86,6 +86,11 @@ function shadowPagePhase(iframe: HTMLIFrameElement | null): string {
|
|
|
86
86
|
const pageGotTo = (iframe: HTMLIFrameElement | null) =>
|
|
87
87
|
shadowPlayerReachable(iframe) ? "" : ` Its page had got to: ${shadowPagePhase(iframe)}.`;
|
|
88
88
|
|
|
89
|
+
function hyperframesPlayerOf(iframe: HTMLIFrameElement): Element | null {
|
|
90
|
+
const root = iframe.getRootNode();
|
|
91
|
+
return root instanceof ShadowRoot ? root.host : null;
|
|
92
|
+
}
|
|
93
|
+
|
|
89
94
|
function isDocumentHidden(): boolean {
|
|
90
95
|
return typeof document !== "undefined" && document.visibilityState === "hidden";
|
|
91
96
|
}
|
|
@@ -293,6 +298,7 @@ export function useShadowPreviewReload({
|
|
|
293
298
|
// The store takes the new document's timeline only now that it is the one on screen, and reads it there.
|
|
294
299
|
const retired = iframeRef.current;
|
|
295
300
|
iframeRef.current = shadow;
|
|
301
|
+
hyperframesPlayerOf(shadow)?.toggleAttribute("inert", false);
|
|
296
302
|
pending.commit();
|
|
297
303
|
shadowIframeRef.current = null;
|
|
298
304
|
attachIframeShortcutListeners();
|
|
@@ -403,6 +409,7 @@ export function useShadowPreviewReload({
|
|
|
403
409
|
|
|
404
410
|
const setShadowIframeNode = useCallback((node: HTMLIFrameElement | null) => {
|
|
405
411
|
shadowIframeRef.current = node;
|
|
412
|
+
if (node) hyperframesPlayerOf(node)?.toggleAttribute("inert", true);
|
|
406
413
|
const gen = budgetGenRef.current;
|
|
407
414
|
if (!node || !shadowFrameLeftPageRef.current || gen == null || gen !== shadowGenRef.current)
|
|
408
415
|
return;
|
|
@@ -227,6 +227,26 @@ describe("shadow reload readiness and failure", () => {
|
|
|
227
227
|
unmount(root);
|
|
228
228
|
});
|
|
229
229
|
|
|
230
|
+
// The player turns pointer events back on for its frame, so a reload's frame would take the live one's clicks.
|
|
231
|
+
it("keeps a reload's player out of clicks and focus until it is promoted, then gives them back", () => {
|
|
232
|
+
const { getApi, gen, root } = beginReload();
|
|
233
|
+
const shadow = makeShadowWithSpies();
|
|
234
|
+
const player = document.createElement("hyperframes-player");
|
|
235
|
+
player.attachShadow({ mode: "open" }).append(shadow.iframe);
|
|
236
|
+
document.body.append(player);
|
|
237
|
+
|
|
238
|
+
act(() => getApi().setShadowIframeNode(shadow.iframe));
|
|
239
|
+
expect(player.hasAttribute("inert")).toBe(true);
|
|
240
|
+
|
|
241
|
+
act(() => {
|
|
242
|
+
getApi().onShadowIframeLoad(gen);
|
|
243
|
+
getApi().onShadowReadyChange(gen, true);
|
|
244
|
+
});
|
|
245
|
+
expect(getApi().iframeRef.current).toBe(shadow.iframe);
|
|
246
|
+
expect(player.hasAttribute("inert")).toBe(false);
|
|
247
|
+
unmount(root);
|
|
248
|
+
});
|
|
249
|
+
|
|
230
250
|
it("keeps a playing film playing through a reload, from where the live frame had reached", () => {
|
|
231
251
|
const { getApi, root } = renderTimelinePlayerHarness();
|
|
232
252
|
const { adapter: liveAdapter, win } = makeAdapterWindow();
|
|
@@ -50,6 +50,7 @@ function described(n: number, extra: Partial<EditingElementDescription> = {}) {
|
|
|
50
50
|
handle: h(n),
|
|
51
51
|
parent: null,
|
|
52
52
|
tag: "div",
|
|
53
|
+
label: "Text",
|
|
53
54
|
id: null,
|
|
54
55
|
selector: null,
|
|
55
56
|
matchesBefore: null,
|
|
@@ -68,6 +69,8 @@ function described(n: number, extra: Partial<EditingElementDescription> = {}) {
|
|
|
68
69
|
describe("readPreviewElement", () => {
|
|
69
70
|
it("takes a description with the wire shape and refuses anything off it", () => {
|
|
70
71
|
expect(readPreviewElement(described(1))).toEqual(described(1));
|
|
72
|
+
const { label: _label, ...fromAnOlderRuntime } = described(1);
|
|
73
|
+
expect(readPreviewElement(fromAnOlderRuntime)).toEqual(fromAnOlderRuntime);
|
|
71
74
|
for (const bad of [
|
|
72
75
|
null,
|
|
73
76
|
[],
|
|
@@ -77,6 +80,7 @@ describe("readPreviewElement", () => {
|
|
|
77
80
|
described(1, { handle: `${LOAD.toUpperCase()}:1` }),
|
|
78
81
|
described(1, { parent: "x" }),
|
|
79
82
|
described(1, { tag: 1 as never }),
|
|
83
|
+
described(1, { label: 1 as never }),
|
|
80
84
|
described(1, { source: { file: 1 } as never }),
|
|
81
85
|
described(1, { locked: "yes" as never }),
|
|
82
86
|
described(1, { attributes: [["a"]] as never }),
|
|
@@ -70,6 +70,7 @@ function readHit(value: unknown): PreviewElementHit | null {
|
|
|
70
70
|
export function readPreviewElement(value: unknown): PreviewElement | null {
|
|
71
71
|
if (!readHit(value) || !isFields(value)) return null;
|
|
72
72
|
if (value.parent !== null && !isHandle(value.parent)) return null;
|
|
73
|
+
if (value.label !== undefined && !isText(value.label)) return null;
|
|
73
74
|
if (!isTextOrNull(value.id) || !isTextOrNull(value.selector)) return null;
|
|
74
75
|
if (!isSource(value.source) || typeof value.locked !== "boolean") return null;
|
|
75
76
|
if (!isTextRecord(value.inlineStyles) || !isText(value.text)) return null;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
|
|
3
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
|
|
5
|
+
const channel = vi.hoisted(() => ({ request: vi.fn() }));
|
|
6
|
+
vi.mock("../player/lib/previewChannel", () => ({
|
|
7
|
+
previewFrameOpaque: () => true,
|
|
8
|
+
previewRequest: channel.request,
|
|
9
|
+
}));
|
|
10
|
+
import { applyUndoRestoreToPreview } from "./gsapUndoRestore";
|
|
11
|
+
|
|
12
|
+
const page = (body: string) => `<html><body>${body}</body></html>`;
|
|
13
|
+
const box = (left: number) => `<div data-hf-id="box" style="left: ${left}px">t</div>`;
|
|
14
|
+
const script = (text: string) => `<script>gsap.timeline().to("#t", ${text});</script>`;
|
|
15
|
+
|
|
16
|
+
function undo(previous: string, restored: string) {
|
|
17
|
+
const reload = vi.fn();
|
|
18
|
+
const iframe = document.createElement("iframe");
|
|
19
|
+
const files = { "index.html": { previous: page(previous), restored: page(restored) } };
|
|
20
|
+
return { reload, strategy: applyUndoRestoreToPreview(iframe, null, files, 2, reload), iframe };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const settled = () => new Promise((resolve) => setTimeout(resolve, 0));
|
|
24
|
+
|
|
25
|
+
beforeEach(() => channel.request.mockReset());
|
|
26
|
+
|
|
27
|
+
describe("undo on a sealed preview", () => {
|
|
28
|
+
it("sends the restored attributes to the frame instead of reloading", async () => {
|
|
29
|
+
channel.request.mockResolvedValue({ applied: true });
|
|
30
|
+
const { reload, strategy, iframe } = undo(box(90), box(0));
|
|
31
|
+
expect(strategy).toBe("soft");
|
|
32
|
+
expect(channel.request).toHaveBeenCalledWith(iframe, "restore-attributes", {
|
|
33
|
+
scopes: [
|
|
34
|
+
{
|
|
35
|
+
file: null,
|
|
36
|
+
elements: [
|
|
37
|
+
{
|
|
38
|
+
key: "hf:box",
|
|
39
|
+
attributes: [
|
|
40
|
+
["data-hf-id", "box"],
|
|
41
|
+
["style", "left: 0px"],
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
scripted: false,
|
|
48
|
+
time: 2,
|
|
49
|
+
});
|
|
50
|
+
await settled();
|
|
51
|
+
expect(reload).not.toHaveBeenCalled();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("reloads when the frame refuses or does not answer", async () => {
|
|
55
|
+
for (const reply of [{ applied: false }, null]) {
|
|
56
|
+
channel.request.mockResolvedValue(reply);
|
|
57
|
+
const { reload } = undo(box(90), box(0));
|
|
58
|
+
await settled();
|
|
59
|
+
expect(reload).toHaveBeenCalledOnce();
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("says the files keep a GSAP script, and reloads at once when the script itself changed", () => {
|
|
64
|
+
channel.request.mockResolvedValue({ applied: true });
|
|
65
|
+
undo(box(90) + script("{ x: 1 }"), box(0) + script("{ x: 1 }"));
|
|
66
|
+
expect(channel.request.mock.calls[0]![2]).toMatchObject({ scripted: true });
|
|
67
|
+
channel.request.mockReset();
|
|
68
|
+
const { reload, strategy } = undo(box(90) + script("{ x: 1 }"), box(0) + script("{ x: 2 }"));
|
|
69
|
+
expect(strategy).toBe("full");
|
|
70
|
+
expect(reload).toHaveBeenCalledOnce();
|
|
71
|
+
expect(channel.request).not.toHaveBeenCalled();
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -15,6 +15,8 @@ import { ensureHfIds, isCompositionTemplate } from "@hyperframes/parsers/hf-ids"
|
|
|
15
15
|
import { findAuthoredElement, parseSavedSource } from "./authoredSource";
|
|
16
16
|
import { STUDIO_EDIT_ATTRS } from "../components/editor/manualEditsSeekReapply";
|
|
17
17
|
import { markScenesStale } from "../player/sceneSwap";
|
|
18
|
+
import { previewFrameOpaque, previewRequest } from "../player/lib/previewChannel";
|
|
19
|
+
import type { EditingParams } from "@hyperframes/core/runtime/editing-port";
|
|
18
20
|
import { STUDIO_ORIGINAL_INLINE_TRANSLATE_ATTR } from "../components/editor/manualEditsTypes";
|
|
19
21
|
import { countStudioPreviewChange, studioGestureDraws } from "../components/editor/manualEditsDom";
|
|
20
22
|
|
|
@@ -356,6 +358,68 @@ function repaintWhileReloading(win: PreviewWindow, doc: Document, restored?: str
|
|
|
356
358
|
);
|
|
357
359
|
}
|
|
358
360
|
|
|
361
|
+
type SealedRestore = Omit<EditingParams<"restore-attributes">, "time">;
|
|
362
|
+
|
|
363
|
+
const restoredAttributes = (el: Element): [string, string][] =>
|
|
364
|
+
el.getAttributeNames().map((name) => [name, el.getAttribute(name) ?? ""]);
|
|
365
|
+
|
|
366
|
+
// The preview server stamps data-hf-id on every page it serves.
|
|
367
|
+
const stamped = (html: string) => (html.includes("data-hf-id") ? html : ensureHfIds(html));
|
|
368
|
+
|
|
369
|
+
type SealedFile = { scripted: boolean; elements: SealedRestore["scopes"][number]["elements"] };
|
|
370
|
+
|
|
371
|
+
/** One file's changed elements with their restored attributes, or null when it needs a reload. */
|
|
372
|
+
function sealedFile(file: UndoRestoreFile, isActive: boolean): SealedFile | null {
|
|
373
|
+
// A changed script is re-run in the frame, which a sealed preview cannot be asked to do yet.
|
|
374
|
+
if (extractGsapScriptText(file.restored) !== extractGsapScriptText(file.previous)) return null;
|
|
375
|
+
const prevDoc = parseRestoreSource(stamped(file.previous));
|
|
376
|
+
const nextDoc = parseRestoreSource(stamped(file.restored));
|
|
377
|
+
const scripted = restoreScripted(prevDoc, nextDoc, isActive);
|
|
378
|
+
const keys = diffRestoreDocs(prevDoc, nextDoc);
|
|
379
|
+
const restoredByKey = identityElementMap(nextDoc);
|
|
380
|
+
if (scripted === null || !keys || !restoredByKey) return null;
|
|
381
|
+
const elements = keys.map((key) => ({
|
|
382
|
+
key,
|
|
383
|
+
attributes: restoredAttributes(restoredByKey.get(key)!),
|
|
384
|
+
}));
|
|
385
|
+
return { scripted, elements };
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/** A sealed preview's in-place restore from the files alone, or null when it needs a reload. */
|
|
389
|
+
function sealedRestore(activeDocPath: string, files: RestoreFiles): SealedRestore | null {
|
|
390
|
+
const restore: SealedRestore = { scopes: [], scripted: false };
|
|
391
|
+
for (const [path, file] of Object.entries(files)) {
|
|
392
|
+
const isActive = path === activeDocPath;
|
|
393
|
+
const found = sealedFile(file, isActive);
|
|
394
|
+
if (!found) return null;
|
|
395
|
+
restore.scripted ||= found.scripted;
|
|
396
|
+
if (found.elements.length)
|
|
397
|
+
restore.scopes.push({ file: isActive ? null : path, elements: found.elements });
|
|
398
|
+
}
|
|
399
|
+
return restore.scopes.length ? restore : null;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/** Sends the restore to a sealed preview; a refusal, or no answer, reloads it. */
|
|
403
|
+
function applySealedRestore(
|
|
404
|
+
iframe: HTMLIFrameElement,
|
|
405
|
+
activeDocPath: string,
|
|
406
|
+
files: RestoreFiles,
|
|
407
|
+
currentTime: number,
|
|
408
|
+
reloadPreview: () => void,
|
|
409
|
+
): "soft" | "full" {
|
|
410
|
+
const restore = sealedRestore(activeDocPath, files);
|
|
411
|
+
if (!restore) {
|
|
412
|
+
reloadPreview();
|
|
413
|
+
return "full";
|
|
414
|
+
}
|
|
415
|
+
void previewRequest(iframe, "restore-attributes", { ...restore, time: currentTime }).then(
|
|
416
|
+
(reply) => {
|
|
417
|
+
if (!reply?.applied) reloadPreview();
|
|
418
|
+
},
|
|
419
|
+
);
|
|
420
|
+
return "soft";
|
|
421
|
+
}
|
|
422
|
+
|
|
359
423
|
/**
|
|
360
424
|
* Soft-apply an undo/redo restore to the live preview WITHOUT a full iframe
|
|
361
425
|
* remount (which blanks the frame black and re-flashes the WebGL context). Eligible
|
|
@@ -402,6 +466,8 @@ export function applyUndoRestoreToPreview(
|
|
|
402
466
|
markScenesStale(iframe, paths);
|
|
403
467
|
reload();
|
|
404
468
|
};
|
|
469
|
+
if (iframe && files && previewFrameOpaque(iframe))
|
|
470
|
+
return applySealedRestore(iframe, activeDocPath, files, currentTime, reloadPreview);
|
|
405
471
|
const doc = iframe?.contentDocument;
|
|
406
472
|
const win = iframe?.contentWindow as PreviewWindow | null;
|
|
407
473
|
const plan = doc && files && win ? planRestoreTargets(doc, activeDocPath, files) : null;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// @vitest-environment jsdom
|
|
2
2
|
import { describe, expect, it, vi } from "vitest";
|
|
3
3
|
import {
|
|
4
|
+
setStudioPendingEditsSettled,
|
|
4
5
|
addStudioPendingEditFlushListener,
|
|
5
6
|
adoptingStudioPendingEdit,
|
|
6
7
|
beginStudioPendingEdit,
|
|
@@ -514,3 +515,22 @@ it("counts an edit whose later write failed as saved once an earlier write lande
|
|
|
514
515
|
const shown = paintBackNewestStudioPendingEdit()!;
|
|
515
516
|
await expect(shown.landed()).resolves.toBe(true);
|
|
516
517
|
});
|
|
518
|
+
|
|
519
|
+
describe("every pending edit settled", () => {
|
|
520
|
+
it("is told once, when the last of two overlapping edits settles", async () => {
|
|
521
|
+
const told = vi.fn();
|
|
522
|
+
setStudioPendingEditsSettled(told);
|
|
523
|
+
try {
|
|
524
|
+
const first = beginStudioPendingEdit(null);
|
|
525
|
+
const second = beginStudioPendingEdit(null);
|
|
526
|
+
first.settle();
|
|
527
|
+
await Promise.resolve();
|
|
528
|
+
await Promise.resolve();
|
|
529
|
+
expect(told).not.toHaveBeenCalled();
|
|
530
|
+
second.settle();
|
|
531
|
+
await vi.waitFor(() => expect(told).toHaveBeenCalledOnce());
|
|
532
|
+
} finally {
|
|
533
|
+
setStudioPendingEditsSettled(null);
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
});
|
|
@@ -33,6 +33,12 @@ let historyClaims: () => number = () => 0;
|
|
|
33
33
|
export function setStudioPendingEditClaimClock(read: (() => number) | null): void {
|
|
34
34
|
historyClaims = read ?? (() => 0);
|
|
35
35
|
}
|
|
36
|
+
|
|
37
|
+
let allSettled: (() => void) | null = null;
|
|
38
|
+
|
|
39
|
+
export function setStudioPendingEditsSettled(run: (() => void) | null): void {
|
|
40
|
+
allSettled = run;
|
|
41
|
+
}
|
|
36
42
|
const NOT_SAVED = () => Promise.resolve(false);
|
|
37
43
|
let cancelWaitingPress: (() => boolean) | null = null;
|
|
38
44
|
|
|
@@ -119,10 +125,11 @@ export function trackStudioPendingEdit(
|
|
|
119
125
|
showAgain: null,
|
|
120
126
|
claimsAtBegin: historyClaims(),
|
|
121
127
|
});
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
()
|
|
125
|
-
|
|
128
|
+
const done = () => {
|
|
129
|
+
pendingEdits.delete(promise);
|
|
130
|
+
if (!pendingEdits.size) allSettled?.();
|
|
131
|
+
};
|
|
132
|
+
promise.then(done, done);
|
|
126
133
|
return promise;
|
|
127
134
|
}
|
|
128
135
|
|
|
@@ -5,7 +5,9 @@ import {
|
|
|
5
5
|
isAudioDomElement,
|
|
6
6
|
isAudioTimelineElement,
|
|
7
7
|
isMusicSourceElement,
|
|
8
|
+
fitsBeatAnalysis,
|
|
8
9
|
isMusicTrack,
|
|
10
|
+
MAX_BEAT_SOURCE_SECONDS,
|
|
9
11
|
resolveBeatSourceTrack,
|
|
10
12
|
} from "./timelineInspector";
|
|
11
13
|
import type { TimelineElement } from "../player";
|
|
@@ -15,12 +17,28 @@ function el(
|
|
|
15
17
|
overrides: Partial<
|
|
16
18
|
Pick<
|
|
17
19
|
TimelineElement,
|
|
18
|
-
|
|
20
|
+
| "tag"
|
|
21
|
+
| "src"
|
|
22
|
+
| "id"
|
|
23
|
+
| "domId"
|
|
24
|
+
| "timelineRole"
|
|
25
|
+
| "duration"
|
|
26
|
+
| "sourceDuration"
|
|
27
|
+
| "hasAudio"
|
|
28
|
+
| "muted"
|
|
19
29
|
>
|
|
20
30
|
>,
|
|
21
31
|
): Pick<
|
|
22
32
|
TimelineElement,
|
|
23
|
-
|
|
33
|
+
| "tag"
|
|
34
|
+
| "src"
|
|
35
|
+
| "id"
|
|
36
|
+
| "domId"
|
|
37
|
+
| "timelineRole"
|
|
38
|
+
| "duration"
|
|
39
|
+
| "sourceDuration"
|
|
40
|
+
| "hasAudio"
|
|
41
|
+
| "muted"
|
|
24
42
|
> {
|
|
25
43
|
return {
|
|
26
44
|
tag: "audio",
|
|
@@ -29,6 +47,7 @@ function el(
|
|
|
29
47
|
domId: "el-1",
|
|
30
48
|
timelineRole: undefined,
|
|
31
49
|
duration: 10,
|
|
50
|
+
sourceDuration: 120,
|
|
32
51
|
...overrides,
|
|
33
52
|
};
|
|
34
53
|
}
|
|
@@ -127,6 +146,22 @@ describe("resolveBeatSourceTrack", () => {
|
|
|
127
146
|
expect(resolveBeatSourceTrack([sfx, vo])).toBeNull();
|
|
128
147
|
});
|
|
129
148
|
|
|
149
|
+
it("falls back to a song over a longer clip whose file's length is not known yet", () => {
|
|
150
|
+
const unread = el({ id: "unread", domId: "unread", duration: 300, sourceDuration: undefined });
|
|
151
|
+
const song = el({ id: "song", domId: "song", duration: 180, sourceDuration: 180 });
|
|
152
|
+
expect(resolveBeatSourceTrack([unread, song])!.element).toBe(song);
|
|
153
|
+
const looped = el({ id: "loop", domId: "loop", duration: 1200, sourceDuration: 180 });
|
|
154
|
+
expect(resolveBeatSourceTrack([looped])!.element).toBe(looped);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("never falls back to a clip, or a clip's file, longer than a song", () => {
|
|
158
|
+
const talk = el({ id: "talk", domId: "talk", duration: 3720, sourceDuration: 3720 });
|
|
159
|
+
const excerpt = el({ id: "cut", domId: "cut", duration: 180, sourceDuration: 3720 });
|
|
160
|
+
expect(resolveBeatSourceTrack([talk, excerpt])).toBeNull();
|
|
161
|
+
const song = el({ id: "song", domId: "song", duration: 200, sourceDuration: 200 });
|
|
162
|
+
expect(resolveBeatSourceTrack([talk, song])!.element).toBe(song);
|
|
163
|
+
});
|
|
164
|
+
|
|
130
165
|
it("returns isFallback=true for an untagged clip with a non-music id", () => {
|
|
131
166
|
const clip = el({ id: "my_audio_file", domId: "my_audio_file", timelineRole: undefined });
|
|
132
167
|
const result = resolveBeatSourceTrack([clip]);
|
|
@@ -184,3 +219,15 @@ describe("beat source from a video with sound", () => {
|
|
|
184
219
|
expect(resolveBeatSourceTrack([short, long, muted])?.element).toBe(long);
|
|
185
220
|
});
|
|
186
221
|
});
|
|
222
|
+
|
|
223
|
+
describe("fitsBeatAnalysis", () => {
|
|
224
|
+
it("fits a file whose length is known and no longer than a song, however long its clip runs", () => {
|
|
225
|
+
expect(fitsBeatAnalysis({ sourceDuration: 180 })).toBe(true);
|
|
226
|
+
expect(fitsBeatAnalysis({ sourceDuration: MAX_BEAT_SOURCE_SECONDS })).toBe(true);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it("refuses a file past the cap and a file whose length is unknown", () => {
|
|
230
|
+
expect(fitsBeatAnalysis({ sourceDuration: 3720 })).toBe(false);
|
|
231
|
+
expect(fitsBeatAnalysis({})).toBe(false);
|
|
232
|
+
});
|
|
233
|
+
});
|
|
@@ -80,6 +80,16 @@ export function isMusicTrack(
|
|
|
80
80
|
return MUSIC_ID_RE.test(id);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
/** Past a song's length a track is speech or a mix, and beat analysis decodes its whole file (62 min: 1.4 GB). */
|
|
84
|
+
export const MAX_BEAT_SOURCE_SECONDS = 15 * 60;
|
|
85
|
+
|
|
86
|
+
/** The decode reads the whole file, so a source fits once its file's length is known and within the cap. */
|
|
87
|
+
export function fitsBeatAnalysis({
|
|
88
|
+
sourceDuration,
|
|
89
|
+
}: Pick<TimelineElement, "sourceDuration">): boolean {
|
|
90
|
+
return sourceDuration != null && sourceDuration <= MAX_BEAT_SOURCE_SECONDS;
|
|
91
|
+
}
|
|
92
|
+
|
|
83
93
|
/**
|
|
84
94
|
* Resolve the best audio source for beat analysis. An explicitly tagged or
|
|
85
95
|
* named music track wins; when none is present (e.g. an audio file dropped
|
|
@@ -94,18 +104,27 @@ export function isMusicTrack(
|
|
|
94
104
|
export function resolveBeatSourceTrack(
|
|
95
105
|
elements: readonly Pick<
|
|
96
106
|
TimelineElement,
|
|
97
|
-
|
|
107
|
+
| "tag"
|
|
108
|
+
| "src"
|
|
109
|
+
| "id"
|
|
110
|
+
| "domId"
|
|
111
|
+
| "timelineRole"
|
|
112
|
+
| "duration"
|
|
113
|
+
| "sourceDuration"
|
|
114
|
+
| "hasAudio"
|
|
115
|
+
| "muted"
|
|
98
116
|
>[],
|
|
99
117
|
): { element: (typeof elements)[number]; isFallback: boolean } | null {
|
|
100
118
|
const explicit = elements.find(isMusicTrack);
|
|
101
119
|
if (explicit) return { element: explicit, isFallback: false };
|
|
102
120
|
|
|
103
121
|
// Fallback: pick the longest audio clip (skipping explicitly non-music roles
|
|
104
|
-
// like "sfx" or "voiceover"
|
|
122
|
+
// like "sfx" or "voiceover", and anything longer than a song, so none is beat-analysed).
|
|
105
123
|
let best: (typeof elements)[number] | null = null;
|
|
106
124
|
for (const el of elements) {
|
|
107
125
|
if (!isMusicSourceElement(el)) continue;
|
|
108
126
|
if (el.timelineRole && el.timelineRole !== "music") continue;
|
|
127
|
+
if (!fitsBeatAnalysis(el)) continue;
|
|
109
128
|
if (!best || el.duration > best.duration) best = el;
|
|
110
129
|
}
|
|
111
130
|
return best ? { element: best, isFallback: true } : null;
|