@hyperframes/studio 0.9.37 → 0.9.39
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/{codec-BP7F-7Jx.js → codec-CY6KnWXa.js} +1 -1
- package/dist/assets/{hyperframes-player-_QnPoHup.js → hyperframes-player-B9-CuG_h.js} +1 -1
- package/dist/assets/{index-BJTCbv8z.css → index-4VGEAZyf.css} +1 -1
- package/dist/assets/{index-D6ePWUpc.js → index-Bjz2UaYv.js} +1 -1
- package/dist/assets/{index-tjhfci4N.js → index-_pkzoYYF.js} +166 -166
- package/dist/assets/{pausedVideoDecoder-B7U86zDa.js → pausedVideoDecoder-Dr7nKUUu.js} +1 -1
- package/dist/{chunk-63DH4LRB.js → chunk-44VRMER6.js} +2 -11
- package/dist/{chunk-45KKBU63.js → chunk-ATDO3YLX.js} +1 -1
- package/dist/chunk-FQ3VRKMC.js +148 -0
- package/dist/{chunk-YKBN653R.js → chunk-NBULUIWH.js} +252 -1
- package/dist/{domEditingLayers-7Q56QAU5.js → domEditingLayers-FRVHP6IB.js} +2 -2
- package/dist/index.d.ts +3 -85
- package/dist/index.html +2 -2
- package/dist/index.js +379 -400
- package/dist/keys-CaWcxUST.d.ts +86 -0
- package/dist/keys.d.ts +1 -0
- package/dist/keys.js +11 -0
- package/dist/player.js +2 -2
- package/dist/styles.css +1 -1
- package/package.json +12 -8
- package/src/components/editor/DomEditGestureReadout.test.tsx +204 -20
- package/src/components/editor/DomEditGestureReadout.tsx +36 -18
- package/src/components/editor/InlineTextToolbar.tsx +2 -2
- package/src/components/editor/domEditGestureReadoutPlacement.ts +144 -0
- package/src/components/editor/domEditGestureReadoutState.ts +18 -8
- package/src/components/editor/domEditingDom.ts +2 -15
- package/src/components/editor/propertyPanelFlatMediaSection.test.tsx +7 -36
- package/src/components/editor/propertyPanelFlatMediaSection.tsx +9 -32
- package/src/components/editor/useDomEditCompositionRect.ts +13 -4
- package/src/components/editor/useDomEditOverlayGestures.ts +1 -1
- package/src/components/editor/usePreviewCompositionRect.test.tsx +39 -0
- package/src/components/editor/useVolumeAutomation.test.tsx +0 -69
- package/src/components/editor/useVolumeAutomation.ts +0 -4
- package/src/hooks/elementPickerStyles.ts +53 -0
- package/src/hooks/gsapScriptCommitTypes.ts +2 -6
- package/src/hooks/timelineEditingHelpers.test.ts +39 -0
- package/src/hooks/timelineEditingHelpers.ts +13 -0
- package/src/hooks/useDomEditCommits.ts +4 -9
- package/src/hooks/useDomEditPersist.ts +2 -12
- package/src/hooks/useElementPicker.test.ts +83 -3
- package/src/hooks/useElementPicker.ts +27 -66
- package/src/hooks/useGsapScriptCommits.test.tsx +21 -0
- package/src/hooks/useGsapScriptCommits.ts +7 -3
- package/src/keys.test.ts +53 -0
- package/src/keys.ts +11 -0
- package/src/player/components/Player.test.ts +15 -0
- package/src/player/components/Player.tsx +6 -4
- package/src/player/components/audioGainApply.test.ts +13 -0
- package/src/player/components/audioGainApply.ts +0 -3
- package/src/player/components/studioKeyDefaults.ts +68 -0
- package/src/player/components/studioShortcuts.ts +2 -67
- package/src/player/hooks/playbackAdapterResolution.ts +15 -0
- package/src/player/hooks/previewMessageRouter.manifest.test.ts +67 -0
- package/src/player/hooks/previewMessageRouter.ts +38 -8
- package/src/player/hooks/timelinePlayerTestHarness.ts +27 -1
- package/src/player/hooks/useShadowPreviewReload.ts +24 -6
- package/src/player/hooks/useTimelinePlayer.shadowReload.test.ts +46 -0
- package/src/player/hooks/useTimelinePlayer.ts +5 -9
- package/src/player/lib/bridgePlayback.ts +156 -0
- package/src/player/lib/previewChannel.test.ts +260 -0
- package/src/player/lib/previewChannel.ts +100 -0
- package/src/player/sceneSwap.test.ts +12 -0
- package/src/player/sceneSwap.ts +2 -0
- package/src/utils/studioFileHistory.test.ts +29 -1
- package/src/utils/studioFileHistory.ts +24 -1
|
@@ -5,6 +5,7 @@ import { ensureHfIds } from "@hyperframes/parsers/hf-ids";
|
|
|
5
5
|
import { runtimeProtocolMetadata } from "@hyperframes/core/runtime/protocol";
|
|
6
6
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
7
7
|
import { useElementPicker } from "./useElementPicker";
|
|
8
|
+
import { serveEditingRequests } from "../player/hooks/timelinePlayerTestHarness";
|
|
8
9
|
|
|
9
10
|
// As the host leaves it on disk: hf-ids pinned, no element ids.
|
|
10
11
|
const SAVED = ensureHfIds(`<!doctype html><html><body>
|
|
@@ -20,12 +21,13 @@ afterEach(() => {
|
|
|
20
21
|
vi.restoreAllMocks();
|
|
21
22
|
});
|
|
22
23
|
|
|
23
|
-
// The runtime's element-picked message, posted by `from
|
|
24
|
-
const picked = (from: Window | null, selector: string) =>
|
|
24
|
+
// The runtime's element-picked message, posted by `from`, from this page's origin unless told otherwise.
|
|
25
|
+
const picked = (from: Window | null, selector: string, origin = window.location.origin) =>
|
|
25
26
|
act(() => {
|
|
26
27
|
window.dispatchEvent(
|
|
27
28
|
new MessageEvent("message", {
|
|
28
29
|
source: from,
|
|
30
|
+
origin,
|
|
29
31
|
data: {
|
|
30
32
|
source: "hf-preview",
|
|
31
33
|
type: "element-picked",
|
|
@@ -36,11 +38,16 @@ const picked = (from: Window | null, selector: string) =>
|
|
|
36
38
|
);
|
|
37
39
|
});
|
|
38
40
|
|
|
39
|
-
const pickerMessage = (
|
|
41
|
+
const pickerMessage = (
|
|
42
|
+
from: Window | null,
|
|
43
|
+
data: Record<string, unknown>,
|
|
44
|
+
origin = window.location.origin,
|
|
45
|
+
) =>
|
|
40
46
|
act(() => {
|
|
41
47
|
window.dispatchEvent(
|
|
42
48
|
new MessageEvent("message", {
|
|
43
49
|
source: from,
|
|
50
|
+
origin,
|
|
44
51
|
data: {
|
|
45
52
|
source: "hf-preview",
|
|
46
53
|
...data,
|
|
@@ -483,3 +490,76 @@ describe("a pick across a reload that swaps the preview frame", () => {
|
|
|
483
490
|
expect(picker().pickedElement).toBeNull();
|
|
484
491
|
});
|
|
485
492
|
});
|
|
493
|
+
|
|
494
|
+
describe("messages from the picked frame's origin only", () => {
|
|
495
|
+
it("ignores a pick posted by the preview's window from an origin it cannot have", () => {
|
|
496
|
+
const { iframe, picker } = mountPicker({ "index.html": SAVED });
|
|
497
|
+
picked(iframe.contentWindow, "h1.foreign", "https://elsewhere.example");
|
|
498
|
+
picked(iframe.contentWindow, "h1.opaque", "null");
|
|
499
|
+
expect(picker().pickedElement?.selector).toBe("h1");
|
|
500
|
+
});
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
describe("a pick in a frame Studio cannot read", () => {
|
|
504
|
+
/** A sandboxed frame: its window refuses reads, and its runtime answers editing requests. */
|
|
505
|
+
function opaquePreview(answer: (kind: string, params: unknown) => unknown) {
|
|
506
|
+
const frame: Record<string, unknown> = {};
|
|
507
|
+
Object.defineProperty(frame, "document", {
|
|
508
|
+
get: () => {
|
|
509
|
+
throw new DOMException("blocked", "SecurityError");
|
|
510
|
+
},
|
|
511
|
+
});
|
|
512
|
+
const iframe = document.createElement("iframe");
|
|
513
|
+
iframe.setAttribute("sandbox", "allow-scripts");
|
|
514
|
+
Object.defineProperty(iframe, "contentWindow", { value: frame });
|
|
515
|
+
Object.defineProperty(iframe, "contentDocument", { value: null });
|
|
516
|
+
const close = serveEditingRequests(frame, answer);
|
|
517
|
+
let api: ReturnType<typeof useElementPicker> | null = null;
|
|
518
|
+
function Harness() {
|
|
519
|
+
api = useElementPicker({ current: iframe });
|
|
520
|
+
return null;
|
|
521
|
+
}
|
|
522
|
+
root = createRoot(document.createElement("div"));
|
|
523
|
+
act(() => root?.render(React.createElement(Harness)));
|
|
524
|
+
return { frame: frame as unknown as Window, close, picker: () => api! };
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
it("takes the picked element's computed styles from its runtime", async () => {
|
|
528
|
+
const asked: unknown[] = [];
|
|
529
|
+
const { frame, close, picker } = opaquePreview((kind, params) => {
|
|
530
|
+
asked.push({ kind, params });
|
|
531
|
+
return { styles: { color: "rgb(1, 2, 3)", opacity: "0.5", injected: "x" } };
|
|
532
|
+
});
|
|
533
|
+
try {
|
|
534
|
+
picked(frame, "h1.title", "null");
|
|
535
|
+
expect(picker().pickedElement?.computedStyles).toEqual({});
|
|
536
|
+
await vi.waitFor(() =>
|
|
537
|
+
expect(picker().pickedElement?.computedStyles).toEqual({
|
|
538
|
+
color: "rgb(1, 2, 3)",
|
|
539
|
+
opacity: "0.5",
|
|
540
|
+
}),
|
|
541
|
+
);
|
|
542
|
+
expect(asked).toEqual([
|
|
543
|
+
{
|
|
544
|
+
kind: "computed-styles",
|
|
545
|
+
params: {
|
|
546
|
+
selector: "h1.title",
|
|
547
|
+
properties: expect.arrayContaining(["color", "opacity"]),
|
|
548
|
+
},
|
|
549
|
+
},
|
|
550
|
+
]);
|
|
551
|
+
} finally {
|
|
552
|
+
close();
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
it("ignores a pick from the frame's window that does not come from an opaque origin", () => {
|
|
557
|
+
const { frame, close, picker } = opaquePreview(() => ({ styles: {} }));
|
|
558
|
+
try {
|
|
559
|
+
picked(frame, "h1", window.location.origin);
|
|
560
|
+
expect(picker().pickedElement).toBeNull();
|
|
561
|
+
} finally {
|
|
562
|
+
close();
|
|
563
|
+
}
|
|
564
|
+
});
|
|
565
|
+
});
|
|
@@ -12,7 +12,10 @@ import {
|
|
|
12
12
|
postRuntimeControlMessage,
|
|
13
13
|
} from "../player/lib/runtimeProtocol";
|
|
14
14
|
import { compositionPathOfPreviewUrl } from "../player/components/CompositionThumbnail";
|
|
15
|
-
import {
|
|
15
|
+
import { frameOrigins } from "../player/lib/bridgePlayback";
|
|
16
|
+
import { previewComputedStyles, previewFrameOpaque } from "../player/lib/previewChannel";
|
|
17
|
+
import { PICKED_STYLE_PROPERTIES, readComputedStyles } from "./elementPickerStyles";
|
|
18
|
+
import { getSourceFileForElement } from "../components/editor/domEditingDom";
|
|
16
19
|
import {
|
|
17
20
|
createElementPickerHoverLabel,
|
|
18
21
|
type ElementPickerHoverInfo,
|
|
@@ -173,7 +176,19 @@ function useElementPickerSession(
|
|
|
173
176
|
setPickedElement(null);
|
|
174
177
|
}, []);
|
|
175
178
|
|
|
176
|
-
const
|
|
179
|
+
const originsOfWindowsThatWerePrimary = useRef(new WeakMap<MessageEventSource, string[]>());
|
|
180
|
+
|
|
181
|
+
const showPicked = useCallback((next: PickedElement, iframe: HTMLIFrameElement) => {
|
|
182
|
+
pickedElementRef.current = next;
|
|
183
|
+
setPickedElement(next);
|
|
184
|
+
if (!previewFrameOpaque(iframe)) return;
|
|
185
|
+
void previewComputedStyles(iframe, next.selector, PICKED_STYLE_PROPERTIES).then((styles) => {
|
|
186
|
+
if (!styles || pickedElementRef.current !== next) return;
|
|
187
|
+
const filled = { ...next, computedStyles: styles };
|
|
188
|
+
pickedElementRef.current = filled;
|
|
189
|
+
setPickedElement(filled);
|
|
190
|
+
});
|
|
191
|
+
}, []);
|
|
177
192
|
|
|
178
193
|
useEffect(() => {
|
|
179
194
|
if (!isPickMode) return;
|
|
@@ -204,13 +219,14 @@ function useElementPickerSession(
|
|
|
204
219
|
const activeIframe = getActiveIframe();
|
|
205
220
|
if (!activeIframe) return;
|
|
206
221
|
if (!e.source) return;
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
222
|
+
const primary = iframeRef.current;
|
|
223
|
+
if (primary && e.source === primary.contentWindow)
|
|
224
|
+
originsOfWindowsThatWerePrimary.current.set(e.source, frameOrigins(primary));
|
|
225
|
+
const origins =
|
|
226
|
+
e.source === activeIframe.contentWindow
|
|
227
|
+
? frameOrigins(activeIframe)
|
|
228
|
+
: originsOfWindowsThatWerePrimary.current.get(e.source);
|
|
229
|
+
if (!origins?.includes(e.origin)) return;
|
|
214
230
|
|
|
215
231
|
if (data.type === "element-hovered") {
|
|
216
232
|
if (e.source !== activeIframe.contentWindow || !isPickModeRef.current) return;
|
|
@@ -220,9 +236,7 @@ function useElementPickerSession(
|
|
|
220
236
|
}
|
|
221
237
|
|
|
222
238
|
if (data.type === "element-picked" && data.elementInfo) {
|
|
223
|
-
|
|
224
|
-
pickedElementRef.current = next;
|
|
225
|
-
setPickedElement(next);
|
|
239
|
+
showPicked(toPickedElement(data.elementInfo, activeIframe), activeIframe);
|
|
226
240
|
pickStartSelectionRef.current = undefined;
|
|
227
241
|
isPickModeRef.current = false;
|
|
228
242
|
clearHover();
|
|
@@ -230,11 +244,7 @@ function useElementPickerSession(
|
|
|
230
244
|
} else if (data.type === "element-pick-candidates") {
|
|
231
245
|
// Multiple candidates at click point — pick the first one
|
|
232
246
|
const el = data.candidates?.[data.selectedIndex ?? 0];
|
|
233
|
-
if (el)
|
|
234
|
-
const next = toPickedElement(el, activeIframe);
|
|
235
|
-
pickedElementRef.current = next;
|
|
236
|
-
setPickedElement(next);
|
|
237
|
-
}
|
|
247
|
+
if (el) showPicked(toPickedElement(el, activeIframe), activeIframe);
|
|
238
248
|
}
|
|
239
249
|
|
|
240
250
|
if (data.type === "pick-mode-cancelled") {
|
|
@@ -549,52 +559,3 @@ function patchByHfId(
|
|
|
549
559
|
const before = path ? files[path] : undefined;
|
|
550
560
|
return path && before ? { path, before, after: applyPatchByTarget(before, { hfId }, op) } : null;
|
|
551
561
|
}
|
|
552
|
-
|
|
553
|
-
/** Read a subset of computed styles from an element in the iframe */
|
|
554
|
-
function readComputedStyles(iframe: HTMLIFrameElement, selector: string): Record<string, string> {
|
|
555
|
-
const styles: Record<string, string> = {};
|
|
556
|
-
try {
|
|
557
|
-
const doc = iframe.contentDocument;
|
|
558
|
-
const el = doc?.querySelector(selector);
|
|
559
|
-
if (!el) return styles;
|
|
560
|
-
const computed = iframe.contentWindow?.getComputedStyle(el);
|
|
561
|
-
if (!computed) return styles;
|
|
562
|
-
|
|
563
|
-
const props = [
|
|
564
|
-
"position",
|
|
565
|
-
"top",
|
|
566
|
-
"left",
|
|
567
|
-
"right",
|
|
568
|
-
"bottom",
|
|
569
|
-
"width",
|
|
570
|
-
"height",
|
|
571
|
-
"margin-top",
|
|
572
|
-
"margin-right",
|
|
573
|
-
"margin-bottom",
|
|
574
|
-
"margin-left",
|
|
575
|
-
"padding-top",
|
|
576
|
-
"padding-right",
|
|
577
|
-
"padding-bottom",
|
|
578
|
-
"padding-left",
|
|
579
|
-
"font-size",
|
|
580
|
-
"font-weight",
|
|
581
|
-
"font-family",
|
|
582
|
-
"color",
|
|
583
|
-
"background-color",
|
|
584
|
-
"background",
|
|
585
|
-
"opacity",
|
|
586
|
-
"border-radius",
|
|
587
|
-
"transform",
|
|
588
|
-
"z-index",
|
|
589
|
-
];
|
|
590
|
-
|
|
591
|
-
for (const prop of props) {
|
|
592
|
-
const val =
|
|
593
|
-
prop === "opacity" ? getLogicalOpacity(el, computed) : computed.getPropertyValue(prop);
|
|
594
|
-
if (val) styles[prop] = val;
|
|
595
|
-
}
|
|
596
|
-
} catch {
|
|
597
|
-
/* cross-origin */
|
|
598
|
-
}
|
|
599
|
-
return styles;
|
|
600
|
-
}
|
|
@@ -898,6 +898,27 @@ describe("runCommit — instantPatch wiring", () => {
|
|
|
898
898
|
expect(deps.reloadPreview).not.toHaveBeenCalled();
|
|
899
899
|
});
|
|
900
900
|
|
|
901
|
+
it("files a gsap move under the layer it moved, by identity and by the name the person saw", async () => {
|
|
902
|
+
applySoftReload.mockReturnValue("applied");
|
|
903
|
+
mockFetchResult();
|
|
904
|
+
const deps = renderCommitHook();
|
|
905
|
+
|
|
906
|
+
await act(async () => {
|
|
907
|
+
await deps.api.commitMutation(
|
|
908
|
+
{ ...selection, label: "Title" },
|
|
909
|
+
{ x: 10 },
|
|
910
|
+
{ label: "Move layer", softReload: true },
|
|
911
|
+
);
|
|
912
|
+
});
|
|
913
|
+
|
|
914
|
+
expect(deps.recordEdit).toHaveBeenCalledWith(
|
|
915
|
+
expect.objectContaining({
|
|
916
|
+
label: "Move layer",
|
|
917
|
+
targets: [{ file: "index.html", id: "a", selector: "#a", name: "Title" }],
|
|
918
|
+
}),
|
|
919
|
+
);
|
|
920
|
+
});
|
|
921
|
+
|
|
901
922
|
it("batch capability posts ordered mutations and finalizes the result once", async () => {
|
|
902
923
|
applySoftReload.mockReturnValue("applied");
|
|
903
924
|
mockFetchResult();
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { useCallback, useMemo, useRef } from "react";
|
|
2
2
|
import { findUnsafeMutationValues } from "@hyperframes/core/studio-api/finite-mutation";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
editContextTarget,
|
|
5
|
+
readProjectFileContent as readSharedProjectFileContent,
|
|
6
|
+
} from "../utils/studioFileHistory";
|
|
4
7
|
import type { DomEditSelection } from "../components/editor/domEditingTypes";
|
|
5
8
|
import { usePlayerStore } from "../player/store/playerStore";
|
|
6
9
|
import {
|
|
@@ -323,12 +326,13 @@ export function useGsapScriptCommits({ projectIdRef, activeCompPath, previewIfra
|
|
|
323
326
|
// the same animationId so their POSTs can't interleave. Held in a ref so the
|
|
324
327
|
// chain survives re-renders.
|
|
325
328
|
const serializerRef = useRef(createKeyedSerializer());
|
|
326
|
-
const recordMutationEdit = useCallback(async (targetPath: string, result: MutationResult, options: CommitMutationOptions) => {
|
|
329
|
+
const recordMutationEdit = useCallback(async (targetPath: string, selection: DomEditSelection, result: MutationResult, options: CommitMutationOptions) => {
|
|
327
330
|
if (result.before == null || result.after == null) return;
|
|
328
331
|
await editHistory.recordEdit({
|
|
329
332
|
label: options.label,
|
|
330
333
|
coalesceKey: options.coalesceKey,
|
|
331
334
|
coalesceMs: options.coalesceMs,
|
|
335
|
+
targets: [editContextTarget(targetPath, selection)],
|
|
332
336
|
files: { [targetPath]: { before: result.before, after: result.after } },
|
|
333
337
|
});
|
|
334
338
|
}, [editHistory]);
|
|
@@ -348,7 +352,7 @@ export function useGsapScriptCommits({ projectIdRef, activeCompPath, previewIfra
|
|
|
348
352
|
}
|
|
349
353
|
return;
|
|
350
354
|
}
|
|
351
|
-
await recordMutationEdit(targetPath, result, options);
|
|
355
|
+
await recordMutationEdit(targetPath, selection, result, options);
|
|
352
356
|
const nestedFiles = await settleNestedReads(
|
|
353
357
|
result.scriptText
|
|
354
358
|
? readNestedFiles(previewIframeRef.current, result.scriptText, (path) =>
|
package/src/keys.test.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
import { describe, expect, it } from "vitest";
|
|
5
|
+
|
|
6
|
+
const src = import.meta.dirname;
|
|
7
|
+
|
|
8
|
+
/** Every file `entry` reaches through static imports and re-exports, with any package it names. */
|
|
9
|
+
function importGraph(entry: string): { files: string[]; packages: string[] } {
|
|
10
|
+
const files = new Set<string>();
|
|
11
|
+
const packages = new Set<string>();
|
|
12
|
+
const visit = (file: string) => {
|
|
13
|
+
if (files.has(file)) return;
|
|
14
|
+
files.add(file);
|
|
15
|
+
for (const { fileName } of ts.preProcessFile(readFileSync(file, "utf8")).importedFiles) {
|
|
16
|
+
if (!fileName.startsWith(".")) {
|
|
17
|
+
packages.add(fileName);
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
const base = resolve(dirname(file), fileName);
|
|
21
|
+
visit(
|
|
22
|
+
[`${base}.ts`, `${base}.tsx`, join(base, "index.ts")].find((f) => ts.sys.fileExists(f))!,
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
visit(join(src, entry));
|
|
27
|
+
return {
|
|
28
|
+
files: [...files].map((f) => relative(src, f).split(sep).join("/")).sort(),
|
|
29
|
+
packages: [...packages],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
describe("@hyperframes/studio/keys", () => {
|
|
34
|
+
it("imports only the key helpers: no package and no editor module", () => {
|
|
35
|
+
expect(importGraph("keys.ts")).toEqual({
|
|
36
|
+
files: [
|
|
37
|
+
"keys.ts",
|
|
38
|
+
"player/components/studioCombo.ts",
|
|
39
|
+
"player/components/studioKeyDefaults.ts",
|
|
40
|
+
],
|
|
41
|
+
packages: [],
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("is a published subpath sharing the defaults the root entry exports", async () => {
|
|
46
|
+
const pkg = JSON.parse(readFileSync(join(src, "../package.json"), "utf8"));
|
|
47
|
+
expect(pkg.exports["./keys"].import).toBe("./src/keys.ts");
|
|
48
|
+
expect(pkg.publishConfig.exports["./keys"].import).toBe("./dist/keys.js");
|
|
49
|
+
const keys = await import("./keys");
|
|
50
|
+
const shortcuts = await import("./player/components/studioShortcuts");
|
|
51
|
+
expect(keys.DEFAULT_STUDIO_KEYS).toBe(shortcuts.DEFAULT_STUDIO_KEYS);
|
|
52
|
+
});
|
|
53
|
+
});
|
package/src/keys.ts
ADDED
|
@@ -129,6 +129,21 @@ describe("preview errors", () => {
|
|
|
129
129
|
root = null;
|
|
130
130
|
});
|
|
131
131
|
|
|
132
|
+
it("leaves a callback ref alone on unmount, so a frame its owner made live since is kept", async () => {
|
|
133
|
+
// A shadow reload's promotion makes its frame the live one without calling the live Player's ref.
|
|
134
|
+
const ref = vi.fn();
|
|
135
|
+
const { player } = await mountPlayer({ ref } as Partial<PlayerProps>);
|
|
136
|
+
const frame = ref.mock.calls[0]?.[0] as HTMLIFrameElement;
|
|
137
|
+
player.shadowRoot!.append(frame); // where <hyperframes-player> keeps its frame
|
|
138
|
+
expect(frame.isConnected).toBe(true);
|
|
139
|
+
|
|
140
|
+
act(() => root?.unmount());
|
|
141
|
+
root = null;
|
|
142
|
+
|
|
143
|
+
expect(ref).toHaveBeenCalledTimes(1);
|
|
144
|
+
expect(frame.isConnected).toBe(false);
|
|
145
|
+
});
|
|
146
|
+
|
|
132
147
|
it("puts the preview on the player's once-a-second paused heartbeat", async () => {
|
|
133
148
|
const { player } = await mountPlayer();
|
|
134
149
|
expect(player.hasAttribute("low-power-idle")).toBe(true);
|
|
@@ -8,6 +8,7 @@ import { HyperframesLoader } from "../../components/ui";
|
|
|
8
8
|
import { usePlayerStore } from "../store/playerStore";
|
|
9
9
|
import { announcePreviewDocumentLoaded } from "../sceneSwap";
|
|
10
10
|
import type { IframeWindow } from "../lib/playbackTypes";
|
|
11
|
+
import { watchPreviewFrame } from "../lib/bridgePlayback";
|
|
11
12
|
// Importing "@hyperframes/player" registers a class extending HTMLElement at
|
|
12
13
|
// module load, which throws under SSR, hence the dynamic import behind a
|
|
13
14
|
// `typeof window` guard. Kicking it here rather than in the mount effect puts
|
|
@@ -353,6 +354,7 @@ export const Player = forwardRef<HTMLIFrameElement, PlayerProps>(
|
|
|
353
354
|
loadIdRef.current += 1;
|
|
354
355
|
player.setAttribute("src", src);
|
|
355
356
|
container.appendChild(player);
|
|
357
|
+
watchPreviewFrame(iframe);
|
|
356
358
|
|
|
357
359
|
enableInteractiveIframe(player);
|
|
358
360
|
|
|
@@ -377,11 +379,11 @@ export const Player = forwardRef<HTMLIFrameElement, PlayerProps>(
|
|
|
377
379
|
// During crossfade refreshes the retiring Player unmounts after the
|
|
378
380
|
// new Player has already assigned its iframe to the same ref — blindly
|
|
379
381
|
// nulling it would break seeking in the new Player.
|
|
380
|
-
// Callback refs are
|
|
381
|
-
//
|
|
382
|
-
//
|
|
382
|
+
// Callback refs are left alone: a shadow reload's promotion repoints
|
|
383
|
+
// the live frame without calling them, so a null here would wipe it.
|
|
384
|
+
// Their owners check `isConnected` instead (useShadowPreviewReload).
|
|
383
385
|
if (typeof ref === "function") {
|
|
384
|
-
// no-op
|
|
386
|
+
// no-op
|
|
385
387
|
} else if (ref) {
|
|
386
388
|
const mutableRef = ref as React.MutableRefObject<HTMLIFrameElement | null>;
|
|
387
389
|
if (mutableRef.current === iframe) {
|
|
@@ -52,6 +52,19 @@ describe("normalizeClipsLoudness", () => {
|
|
|
52
52
|
});
|
|
53
53
|
|
|
54
54
|
describe("writeClipGains", () => {
|
|
55
|
+
it("writes data-volume on a clip with a volume lane, which the gain stacks on", async () => {
|
|
56
|
+
const onSetElementAttributeQuiet = vi.fn(async () => ({ status: "saved" as const }));
|
|
57
|
+
await writeClipGains([{ element: clip("vo", { automation: volumeLane }), gain: 2 }], {
|
|
58
|
+
onSetElementAttributeQuiet,
|
|
59
|
+
});
|
|
60
|
+
expect(onSetElementAttributeQuiet).toHaveBeenCalledWith(
|
|
61
|
+
expect.objectContaining({ id: "vo" }),
|
|
62
|
+
"data-volume",
|
|
63
|
+
"2",
|
|
64
|
+
"Audio Gain",
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
|
|
55
68
|
it("stops at the first refused single save", async () => {
|
|
56
69
|
const onSetElementAttributeQuiet = vi.fn(async () => ({
|
|
57
70
|
status: "refused" as const,
|
|
@@ -22,9 +22,6 @@ export async function writeClipGains(
|
|
|
22
22
|
writers: VolumeWriters,
|
|
23
23
|
label = AUDIO_GAIN_LABEL,
|
|
24
24
|
): Promise<void> {
|
|
25
|
-
if (edits.some(({ element }) => volumeLaneOwnsGain(element))) {
|
|
26
|
-
throw new Error(VOLUME_LANE_REFUSAL);
|
|
27
|
-
}
|
|
28
25
|
const values = edits.map(({ element, gain }) => ({ element, value: formatAudioGain(gain) }));
|
|
29
26
|
if (values.length > 1 && writers.onSetElementsAttributeQuiet) {
|
|
30
27
|
throwUnlessSaved(await writers.onSetElementsAttributeQuiet(values, "data-volume", label));
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** Every single-character bare key Studio answers, by action. */
|
|
2
|
+
export const DEFAULT_STUDIO_KEYS = {
|
|
3
|
+
fullscreen: "f",
|
|
4
|
+
split: "s",
|
|
5
|
+
record: "r",
|
|
6
|
+
addKeyframe: "k",
|
|
7
|
+
audioGain: "g",
|
|
8
|
+
zoomSelection: "z",
|
|
9
|
+
mute: "m",
|
|
10
|
+
pause: "k",
|
|
11
|
+
shuttleBack: "j",
|
|
12
|
+
shuttleForward: "l",
|
|
13
|
+
inPoint: "i",
|
|
14
|
+
outPoint: "o",
|
|
15
|
+
seekToIn: "a",
|
|
16
|
+
seekToOut: "e",
|
|
17
|
+
selectTool: "v",
|
|
18
|
+
razorTool: "b",
|
|
19
|
+
selectLeftward: "[",
|
|
20
|
+
selectRightward: "]",
|
|
21
|
+
exitRazor: "a",
|
|
22
|
+
snap: "s",
|
|
23
|
+
grid: "g",
|
|
24
|
+
timelineSnap: "n",
|
|
25
|
+
playPause: "Space",
|
|
26
|
+
frameBack: "ArrowLeft",
|
|
27
|
+
frameForward: "ArrowRight",
|
|
28
|
+
frameBackTen: "shift+ArrowLeft",
|
|
29
|
+
frameForwardTen: "shift+ArrowRight",
|
|
30
|
+
loop: "shift+l",
|
|
31
|
+
clearInPoint: "shift+i",
|
|
32
|
+
clearOutPoint: "shift+o",
|
|
33
|
+
undo: "mod+z",
|
|
34
|
+
redo: "mod+shift+z",
|
|
35
|
+
redoAlt: "ctrl+y",
|
|
36
|
+
tabCompositions: "mod+1",
|
|
37
|
+
tabAssets: "mod+2",
|
|
38
|
+
group: "mod+g",
|
|
39
|
+
ungroup: "mod+shift+g",
|
|
40
|
+
copy: "mod+c",
|
|
41
|
+
paste: "mod+v",
|
|
42
|
+
cut: "mod+x",
|
|
43
|
+
duplicate: "mod+d",
|
|
44
|
+
linkToggle: "mod+l",
|
|
45
|
+
detachAudio: "alt+shift+d",
|
|
46
|
+
deleteLinked: "alt+Backspace",
|
|
47
|
+
deleteLinkedAlt: "alt+Delete",
|
|
48
|
+
deleteSelected: "Delete",
|
|
49
|
+
deleteSelectedAlt: "Backspace",
|
|
50
|
+
resetKeyframes: "Backspace",
|
|
51
|
+
nudgeLeft: "ArrowLeft",
|
|
52
|
+
nudgeRight: "ArrowRight",
|
|
53
|
+
nudgeUp: "ArrowUp",
|
|
54
|
+
nudgeDown: "ArrowDown",
|
|
55
|
+
nudgeLeftTen: "shift+ArrowLeft",
|
|
56
|
+
nudgeRightTen: "shift+ArrowRight",
|
|
57
|
+
nudgeUpTen: "shift+ArrowUp",
|
|
58
|
+
nudgeDownTen: "shift+ArrowDown",
|
|
59
|
+
captionSelectAll: "mod+a",
|
|
60
|
+
pickupClip: "Space",
|
|
61
|
+
pickupUp: "ArrowUp",
|
|
62
|
+
pickupDown: "ArrowDown",
|
|
63
|
+
pickupDrop: "Enter",
|
|
64
|
+
cancel: "Escape",
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export type StudioKeyAction = keyof typeof DEFAULT_STUDIO_KEYS;
|
|
68
|
+
export type StudioKeys = Readonly<Record<StudioKeyAction, string>>;
|
|
@@ -8,74 +8,9 @@ import {
|
|
|
8
8
|
parseCombo,
|
|
9
9
|
} from "./studioCombo";
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
export const DEFAULT_STUDIO_KEYS = {
|
|
13
|
-
fullscreen: "f",
|
|
14
|
-
split: "s",
|
|
15
|
-
record: "r",
|
|
16
|
-
addKeyframe: "k",
|
|
17
|
-
audioGain: "g",
|
|
18
|
-
zoomSelection: "z",
|
|
19
|
-
mute: "m",
|
|
20
|
-
pause: "k",
|
|
21
|
-
shuttleBack: "j",
|
|
22
|
-
shuttleForward: "l",
|
|
23
|
-
inPoint: "i",
|
|
24
|
-
outPoint: "o",
|
|
25
|
-
seekToIn: "a",
|
|
26
|
-
seekToOut: "e",
|
|
27
|
-
selectTool: "v",
|
|
28
|
-
razorTool: "b",
|
|
29
|
-
selectLeftward: "[",
|
|
30
|
-
selectRightward: "]",
|
|
31
|
-
exitRazor: "a",
|
|
32
|
-
snap: "s",
|
|
33
|
-
grid: "g",
|
|
34
|
-
timelineSnap: "n",
|
|
35
|
-
playPause: "Space",
|
|
36
|
-
frameBack: "ArrowLeft",
|
|
37
|
-
frameForward: "ArrowRight",
|
|
38
|
-
frameBackTen: "shift+ArrowLeft",
|
|
39
|
-
frameForwardTen: "shift+ArrowRight",
|
|
40
|
-
loop: "shift+l",
|
|
41
|
-
clearInPoint: "shift+i",
|
|
42
|
-
clearOutPoint: "shift+o",
|
|
43
|
-
undo: "mod+z",
|
|
44
|
-
redo: "mod+shift+z",
|
|
45
|
-
redoAlt: "ctrl+y",
|
|
46
|
-
tabCompositions: "mod+1",
|
|
47
|
-
tabAssets: "mod+2",
|
|
48
|
-
group: "mod+g",
|
|
49
|
-
ungroup: "mod+shift+g",
|
|
50
|
-
copy: "mod+c",
|
|
51
|
-
paste: "mod+v",
|
|
52
|
-
cut: "mod+x",
|
|
53
|
-
duplicate: "mod+d",
|
|
54
|
-
linkToggle: "mod+l",
|
|
55
|
-
detachAudio: "alt+shift+d",
|
|
56
|
-
deleteLinked: "alt+Backspace",
|
|
57
|
-
deleteLinkedAlt: "alt+Delete",
|
|
58
|
-
deleteSelected: "Delete",
|
|
59
|
-
deleteSelectedAlt: "Backspace",
|
|
60
|
-
resetKeyframes: "Backspace",
|
|
61
|
-
nudgeLeft: "ArrowLeft",
|
|
62
|
-
nudgeRight: "ArrowRight",
|
|
63
|
-
nudgeUp: "ArrowUp",
|
|
64
|
-
nudgeDown: "ArrowDown",
|
|
65
|
-
nudgeLeftTen: "shift+ArrowLeft",
|
|
66
|
-
nudgeRightTen: "shift+ArrowRight",
|
|
67
|
-
nudgeUpTen: "shift+ArrowUp",
|
|
68
|
-
nudgeDownTen: "shift+ArrowDown",
|
|
69
|
-
captionSelectAll: "mod+a",
|
|
70
|
-
pickupClip: "Space",
|
|
71
|
-
pickupUp: "ArrowUp",
|
|
72
|
-
pickupDown: "ArrowDown",
|
|
73
|
-
pickupDrop: "Enter",
|
|
74
|
-
cancel: "Escape",
|
|
75
|
-
};
|
|
11
|
+
import { DEFAULT_STUDIO_KEYS, type StudioKeyAction, type StudioKeys } from "./studioKeyDefaults";
|
|
76
12
|
|
|
77
|
-
export type StudioKeyAction
|
|
78
|
-
export type StudioKeys = Readonly<Record<StudioKeyAction, string>>;
|
|
13
|
+
export { DEFAULT_STUDIO_KEYS, type StudioKeyAction, type StudioKeys } from "./studioKeyDefaults";
|
|
79
14
|
|
|
80
15
|
const SHARED_BY_DESIGN: ReadonlyArray<readonly [StudioKeyAction, StudioKeyAction]> = [
|
|
81
16
|
["pause", "addKeyframe"],
|
|
@@ -11,6 +11,9 @@ import {
|
|
|
11
11
|
type StaticSeekCacheEntry,
|
|
12
12
|
} from "../lib/playbackAdapter";
|
|
13
13
|
import { readTimelineDurationFromDocument } from "../lib/timelineDOM";
|
|
14
|
+
import { attachPausedVideoProvider } from "../lib/pausedVideoProvider";
|
|
15
|
+
import { previewFrameOpaque } from "../lib/previewChannel";
|
|
16
|
+
import { bridgePlaybackAdapter } from "../lib/bridgePlayback";
|
|
14
17
|
|
|
15
18
|
/**
|
|
16
19
|
* Timeline-based adapters (`__timeline`, then `__timelines`): `match` is the first that covers
|
|
@@ -96,3 +99,15 @@ export function resolvePlaybackAdapter(
|
|
|
96
99
|
|
|
97
100
|
return bestAdapter;
|
|
98
101
|
}
|
|
102
|
+
|
|
103
|
+
/** A frame Studio cannot script (opaque origin) is driven over the control bridge. */
|
|
104
|
+
export function resolveFramePlaybackAdapter(
|
|
105
|
+
iframe: HTMLIFrameElement,
|
|
106
|
+
refs: StaticSeekRefs,
|
|
107
|
+
): PlaybackAdapter | null {
|
|
108
|
+
if (previewFrameOpaque(iframe)) return bridgePlaybackAdapter(iframe);
|
|
109
|
+
const win = iframe.contentWindow as IframeWindow | null;
|
|
110
|
+
if (!win) return null;
|
|
111
|
+
attachPausedVideoProvider(iframe, win);
|
|
112
|
+
return resolvePlaybackAdapter(iframe, win, refs);
|
|
113
|
+
}
|