@hyperframes/studio 0.9.65 → 0.9.66
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-VGx6ow_e.js +573 -0
- package/dist/assets/{index-tvLrzMBv.js → index-B8Xt_Oyw.js} +180 -180
- package/dist/assets/{index-CAjz3b83.js → index-BH18TdX9.js} +1 -1
- package/dist/assets/{pausedVideoDecoder-xC5IGkfB.js → pausedVideoDecoder-Bx3fGNkU.js} +1 -1
- package/dist/{chunk-VDDEXNVX.js → chunk-ESTBKVCB.js} +8 -0
- package/dist/index.html +1 -1
- package/dist/index.js +355 -142
- package/dist/player.js +1 -1
- package/package.json +8 -8
- package/src/captions/components/CaptionOverlay.sealed.test.ts +2 -25
- package/src/components/editor/LayersPanel.opaque.test.ts +4 -29
- package/src/components/editor/domEditOverlayCrop.ts +78 -15
- package/src/components/editor/domEditOverlayCropFrameLift.test.ts +64 -0
- package/src/components/editor/gsapMoveSealedPreview.test.ts +3 -23
- package/src/components/editor/previewDrafts.test.ts +13 -39
- package/src/components/editor/previewDrafts.ts +2 -0
- package/src/components/editor/previewGestureStartRead.test.ts +59 -21
- package/src/components/editor/previewGestureStartRead.ts +9 -0
- package/src/components/editor/previewLayers.test.ts +3 -20
- package/src/components/editor/previewOverlayRects.test.ts +3 -20
- package/src/components/editor/previewPointerTargets.test.ts +3 -20
- package/src/components/editor/previewSelection.test.ts +51 -35
- package/src/components/editor/previewSelection.ts +17 -0
- package/src/components/editor/useColorGradingController.sealed.test.ts +5 -30
- package/src/components/editor/useMotionPathData.sealed.test.ts +2 -29
- package/src/components/nle/NLEContext.drillDown.test.ts +85 -0
- package/src/components/nle/NLEContext.tsx +21 -23
- package/src/components/nle/NLEPreview.test.ts +18 -3
- package/src/components/nle/NLEPreview.tsx +10 -1
- package/src/components/nle/audioSealedPreview.test.ts +5 -32
- package/src/hooks/appHotkeysDispatch.ts +38 -1
- package/src/hooks/domEditCommits.sealed.test.ts +191 -0
- package/src/hooks/domStyleCommit.ts +18 -7
- package/src/hooks/gsapResizeIntercept.ts +7 -2
- package/src/hooks/useAppHotkeys.previewForwarding.test.tsx +134 -0
- package/src/hooks/useAppHotkeys.ts +36 -1
- package/src/hooks/useDomEditAttributeCommits.ts +43 -19
- package/src/hooks/useEnableKeyframes.sealed.test.ts +2 -29
- package/src/hooks/useSlideshowTabState.test.ts +47 -3
- package/src/hooks/useSlideshowTabState.ts +32 -16
- package/src/player/hooks/timelinePlayerTestHarness.ts +2 -1
- package/src/player/hooks/usePlaybackKeyboard.ts +1 -1
- package/src/player/hooks/useTimelineSyncCallbacks.sealed.test.ts +2 -29
- package/src/player/lib/previewChannel.test.ts +10 -0
- package/src/player/lib/previewChannel.ts +9 -0
- package/src/player/lib/previewElements.test.ts +34 -1
- package/src/player/lib/previewElements.ts +99 -16
- package/src/player/lib/sealedPreviewFrame.test-helpers.ts +38 -0
- package/src/player/lib/timelineIframeHelpers.ts +1 -1
- package/src/utils/blockInstaller.test.ts +82 -48
- package/src/utils/blockInstaller.ts +6 -14
- package/src/utils/previewCompositionSize.test.ts +61 -0
- package/src/utils/previewCompositionSize.ts +21 -1
- package/dist/assets/hyperframes-player-Dscc6yHD.js +0 -573
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
// @vitest-environment happy-dom
|
|
2
2
|
|
|
3
3
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
4
|
-
import
|
|
4
|
+
import {
|
|
5
|
+
MAX_ELEMENT_ENTRIES,
|
|
6
|
+
MAX_ELEMENT_TEXT,
|
|
7
|
+
MAX_ELEMENT_VALUE,
|
|
8
|
+
type EditingElementDescription,
|
|
9
|
+
} from "@hyperframes/core/runtime/editing-port";
|
|
5
10
|
import {
|
|
6
11
|
describePreviewElements,
|
|
7
12
|
previewElementSelectorIndex,
|
|
@@ -93,6 +98,34 @@ describe("readPreviewElement", () => {
|
|
|
93
98
|
expect(readPreviewElement(bad)).toBeNull();
|
|
94
99
|
}
|
|
95
100
|
});
|
|
101
|
+
|
|
102
|
+
it("refuses a description longer anywhere than the runtime ever sends one", () => {
|
|
103
|
+
const value = "x".repeat(MAX_ELEMENT_VALUE);
|
|
104
|
+
const atLimit = described(1, { selector: value, id: value, attributes: [["src", value]] });
|
|
105
|
+
expect(readPreviewElement(atLimit)).toEqual(atLimit);
|
|
106
|
+
const over = `${value}x`;
|
|
107
|
+
const text = "y".repeat(MAX_ELEMENT_TEXT + 1);
|
|
108
|
+
const many = Array.from({ length: MAX_ELEMENT_ENTRIES + 1 }, (_, i) => [`data-${i}`, ""]);
|
|
109
|
+
for (const bad of [
|
|
110
|
+
described(1, { selector: over }),
|
|
111
|
+
described(1, { id: over }),
|
|
112
|
+
described(1, { tag: over }),
|
|
113
|
+
described(1, { label: over }),
|
|
114
|
+
described(1, { attributes: [["src", over]] }),
|
|
115
|
+
described(1, { attributes: [[`data-${over}`, "1"]] }),
|
|
116
|
+
described(1, { attributes: many as never }),
|
|
117
|
+
described(1, { inlineStyles: { left: over } }),
|
|
118
|
+
described(1, { inlineStyles: { [`--${over}`]: "1" } }),
|
|
119
|
+
described(1, { source: { ...NO_SOURCE, file: over } }),
|
|
120
|
+
described(1, { source: { ...NO_SOURCE, compositionId: over } }),
|
|
121
|
+
described(1, { source: { ...NO_SOURCE, originalCompositionId: over } }),
|
|
122
|
+
described(1, { matchesBefore: [{ source: { ...NO_SOURCE, file: over }, count: 1 }] }),
|
|
123
|
+
described(1, { text }),
|
|
124
|
+
described(1, { children: [{ text }] }),
|
|
125
|
+
]) {
|
|
126
|
+
expect(readPreviewElement(bad)).toBeNull();
|
|
127
|
+
}
|
|
128
|
+
});
|
|
96
129
|
});
|
|
97
130
|
|
|
98
131
|
describe("element requests over an opaque frame's port", () => {
|
|
@@ -5,10 +5,13 @@
|
|
|
5
5
|
import {
|
|
6
6
|
EDITING_ELEMENT_HANDLE,
|
|
7
7
|
MAX_DESCRIBE_HANDLES,
|
|
8
|
+
MAX_DRAFT_PX,
|
|
8
9
|
MAX_ELEMENT_ENTRIES,
|
|
10
|
+
MAX_ELEMENT_TEXT,
|
|
9
11
|
MAX_ELEMENT_VALUE,
|
|
10
12
|
MAX_GEOMETRY_CHILDREN,
|
|
11
13
|
MAX_SNAP_TARGETS,
|
|
14
|
+
MAX_SOURCE_GROUPS,
|
|
12
15
|
type EditingElementBox,
|
|
13
16
|
type EditingElementDescription,
|
|
14
17
|
type EditingElementGeometry,
|
|
@@ -32,29 +35,38 @@ export const isFields = (value: unknown): value is Fields =>
|
|
|
32
35
|
export const isHandle = (value: unknown) =>
|
|
33
36
|
typeof value === "string" && EDITING_ELEMENT_HANDLE.test(value);
|
|
34
37
|
const isText = (value: unknown) => typeof value === "string";
|
|
35
|
-
const
|
|
38
|
+
const isValue = (value: unknown) => isText(value) && (value as string).length <= MAX_ELEMENT_VALUE;
|
|
39
|
+
const isLongText = (value: unknown) =>
|
|
40
|
+
isText(value) && (value as string).length <= MAX_ELEMENT_TEXT;
|
|
41
|
+
const isValueOrNull = (value: unknown) => value === null || isValue(value);
|
|
42
|
+
const isEntries = (value: unknown): value is unknown[] =>
|
|
43
|
+
Array.isArray(value) && value.length <= MAX_ELEMENT_ENTRIES;
|
|
36
44
|
const isCount = (value: unknown) => Number.isSafeInteger(value) && (value as number) >= 0;
|
|
37
45
|
|
|
38
46
|
const isSource = (value: unknown): value is EditingElementSource =>
|
|
39
47
|
isFields(value) &&
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
48
|
+
isValueOrNull(value.file) &&
|
|
49
|
+
isValueOrNull(value.compositionId) &&
|
|
50
|
+
isValueOrNull(value.originalCompositionId);
|
|
43
51
|
|
|
44
|
-
const
|
|
52
|
+
const isStyles = (value: unknown) =>
|
|
53
|
+
isFields(value) &&
|
|
54
|
+
isEntries(Object.keys(value)) &&
|
|
55
|
+
Object.entries(value).every(([name, style]) => isValue(name) && isValue(style));
|
|
45
56
|
|
|
46
57
|
function hasPlainFields(value: Fields): boolean {
|
|
47
58
|
const { matchesBefore, attributes, children } = value;
|
|
48
59
|
const groupsOk =
|
|
49
60
|
matchesBefore === null ||
|
|
50
61
|
(Array.isArray(matchesBefore) &&
|
|
62
|
+
matchesBefore.length <= MAX_SOURCE_GROUPS &&
|
|
51
63
|
matchesBefore.every((g) => isFields(g) && isSource(g.source) && isCount(g.count)));
|
|
52
64
|
const attributesOk =
|
|
53
|
-
|
|
54
|
-
attributes.every((a) => Array.isArray(a) && a.length === 2 && a.every(
|
|
65
|
+
isEntries(attributes) &&
|
|
66
|
+
attributes.every((a) => Array.isArray(a) && a.length === 2 && a.every(isValue));
|
|
55
67
|
const childrenOk =
|
|
56
|
-
|
|
57
|
-
children.every((c) => isFields(c) && (isHandle(c.handle) ||
|
|
68
|
+
isEntries(children) &&
|
|
69
|
+
children.every((c) => isFields(c) && (isHandle(c.handle) || isLongText(c.text)));
|
|
58
70
|
return groupsOk && attributesOk && childrenOk && typeof value.truncated === "boolean";
|
|
59
71
|
}
|
|
60
72
|
|
|
@@ -62,7 +74,7 @@ const isRect = (value: unknown) =>
|
|
|
62
74
|
isFields(value) && [value.x, value.y, value.width, value.height].every(Number.isFinite);
|
|
63
75
|
|
|
64
76
|
function readHit(value: unknown): PreviewElementHit | null {
|
|
65
|
-
if (!isFields(value) || !isHandle(value.handle) || !
|
|
77
|
+
if (!isFields(value) || !isHandle(value.handle) || !isValue(value.tag)) return null;
|
|
66
78
|
return isRect(value.rect) ? (value as unknown as PreviewElementHit) : null;
|
|
67
79
|
}
|
|
68
80
|
|
|
@@ -70,10 +82,10 @@ function readHit(value: unknown): PreviewElementHit | null {
|
|
|
70
82
|
export function readPreviewElement(value: unknown): PreviewElement | null {
|
|
71
83
|
if (!readHit(value) || !isFields(value)) return null;
|
|
72
84
|
if (value.parent !== null && !isHandle(value.parent)) return null;
|
|
73
|
-
if (value.label !== undefined && !
|
|
74
|
-
if (!
|
|
85
|
+
if (value.label !== undefined && !isValue(value.label)) return null;
|
|
86
|
+
if (!isValueOrNull(value.id) || !isValueOrNull(value.selector)) return null;
|
|
75
87
|
if (!isSource(value.source) || typeof value.locked !== "boolean") return null;
|
|
76
|
-
if (!
|
|
88
|
+
if (!isStyles(value.inlineStyles) || !isLongText(value.text)) return null;
|
|
77
89
|
return hasPlainFields(value) ? (value as unknown as PreviewElement) : null;
|
|
78
90
|
}
|
|
79
91
|
|
|
@@ -182,8 +194,7 @@ const isSourceBox = (value: unknown) =>
|
|
|
182
194
|
isSizeOrNull(value.declaredWidth) &&
|
|
183
195
|
isSizeOrNull(value.declaredHeight));
|
|
184
196
|
|
|
185
|
-
const isClipPath =
|
|
186
|
-
value === null || (isText(value) && (value as string).length <= MAX_ELEMENT_VALUE);
|
|
197
|
+
const isClipPath = isValueOrNull;
|
|
187
198
|
|
|
188
199
|
const isBox = (value: unknown): value is EditingElementBox =>
|
|
189
200
|
isFields(value) &&
|
|
@@ -233,11 +244,17 @@ const isFlag = (value: unknown) => typeof value === "boolean";
|
|
|
233
244
|
const isFiniteFields = (value: unknown, keys: string[]) =>
|
|
234
245
|
isFields(value) && keys.every((key) => Number.isFinite(value[key]));
|
|
235
246
|
|
|
247
|
+
const isLayout = (value: unknown) =>
|
|
248
|
+
isFields(value) &&
|
|
249
|
+
[value.width, value.height].every(
|
|
250
|
+
(side) => Number.isFinite(side) && (side as number) >= 0 && (side as number) <= MAX_DRAFT_PX,
|
|
251
|
+
);
|
|
252
|
+
|
|
236
253
|
const readGestureStart = (value: unknown): EditingGestureStart | null => {
|
|
237
254
|
if (!readGeometry(value) || !isFields(value)) return null;
|
|
238
255
|
const { layout, move, gsap } = value;
|
|
239
256
|
const valid = [
|
|
240
|
-
|
|
257
|
+
isLayout(layout),
|
|
241
258
|
move === null || isFiniteFields(move, ["a", "b", "c", "d"]),
|
|
242
259
|
gsap === null || (isFields(gsap) && isFiniteFields(gsap, ["x", "y"]) && isFlag(gsap.moving)),
|
|
243
260
|
];
|
|
@@ -293,3 +310,69 @@ export async function previewLayers(
|
|
|
293
310
|
if (typeof missingGroup !== "boolean") return null;
|
|
294
311
|
return layers.every(isLayer) ? { layers, truncated, missingGroup } : null;
|
|
295
312
|
}
|
|
313
|
+
|
|
314
|
+
type EditEntry = [name: string, value: string | null];
|
|
315
|
+
type StyleEntry = [name: string, value: string | null, priority?: "important"];
|
|
316
|
+
const isEditEntries = (value: unknown, priority = false): value is StyleEntry[] =>
|
|
317
|
+
Array.isArray(value) &&
|
|
318
|
+
value.every(
|
|
319
|
+
(entry) =>
|
|
320
|
+
Array.isArray(entry) &&
|
|
321
|
+
isText(entry[0]) &&
|
|
322
|
+
(entry[1] === null || isText(entry[1])) &&
|
|
323
|
+
(entry.length === 2 || (priority && entry.length === 3 && entry[2] === "important")),
|
|
324
|
+
);
|
|
325
|
+
|
|
326
|
+
export interface PreviewElementEdit {
|
|
327
|
+
drawn: Promise<boolean>;
|
|
328
|
+
restore(names?: readonly string[]): void;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/** Draws inline `styles` and `attributes` on the frame's element, null removing one. */
|
|
332
|
+
const latestWriters = new WeakMap<HTMLIFrameElement, Map<string, symbol>>();
|
|
333
|
+
|
|
334
|
+
export function editPreviewElement(
|
|
335
|
+
iframe: HTMLIFrameElement,
|
|
336
|
+
handle: string,
|
|
337
|
+
edit: { styles?: EditEntry[]; attributes?: EditEntry[] },
|
|
338
|
+
): PreviewElementEdit {
|
|
339
|
+
const send = (styles: StyleEntry[], attributes: EditEntry[]) =>
|
|
340
|
+
previewRequest(iframe, "edit-element", { handle, styles, attributes });
|
|
341
|
+
const writers = latestWriters.get(iframe) ?? new Map<string, symbol>();
|
|
342
|
+
latestWriters.set(iframe, writers);
|
|
343
|
+
const self = Symbol("edit");
|
|
344
|
+
const key = (part: string, name: string) => `${handle} ${part} ${name}`;
|
|
345
|
+
for (const [name] of edit.styles ?? []) writers.set(key("style", name), self);
|
|
346
|
+
for (const [name] of edit.attributes ?? []) writers.set(key("attr", name), self);
|
|
347
|
+
const reply = send(edit.styles ?? [], edit.attributes ?? []);
|
|
348
|
+
return {
|
|
349
|
+
drawn: reply.then((before) => before?.applied === true),
|
|
350
|
+
restore(names) {
|
|
351
|
+
// Checked when the old values go back: a later edit of a name owns it by then.
|
|
352
|
+
const owns = (part: string, name: string) =>
|
|
353
|
+
(!names || names.includes(name)) && writers.get(key(part, name)) === self;
|
|
354
|
+
void reply.then((before) => {
|
|
355
|
+
if (!before?.applied || !isEditEntries(before.styles, true)) return;
|
|
356
|
+
if (!isEditEntries(before.attributes)) return;
|
|
357
|
+
const styles = before.styles.filter(([name]) => owns("style", name));
|
|
358
|
+
const attributes = before.attributes.filter(([name]) => owns("attr", name));
|
|
359
|
+
if (styles.length || attributes.length) void send(styles, attributes);
|
|
360
|
+
});
|
|
361
|
+
},
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
const SEALED_DRAW_WAIT_MS = 300;
|
|
366
|
+
|
|
367
|
+
/** Saves a live edit at once; a sealed one once the frame says it drew it, else after the wait. */
|
|
368
|
+
export function afterSealedDraw<T>(edit: PreviewElementEdit | null, save: (drawn: boolean) => T) {
|
|
369
|
+
if (!edit) return save(true);
|
|
370
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
371
|
+
const late = new Promise<boolean>((resolve) => {
|
|
372
|
+
timer = setTimeout(resolve, SEALED_DRAW_WAIT_MS, false);
|
|
373
|
+
});
|
|
374
|
+
return Promise.race([edit.drawn, late]).then((drawn) => {
|
|
375
|
+
clearTimeout(timer);
|
|
376
|
+
return save(drawn);
|
|
377
|
+
});
|
|
378
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// A preview frame Studio cannot script, served by the frame's real runtime agent over this document.
|
|
2
|
+
import { onTestFinished } from "vitest";
|
|
3
|
+
import { installMarkedEditingAgent } from "../../../../core/src/runtime/editingAgent.test-helpers";
|
|
4
|
+
import { detachedFakeIframe } from "../hooks/timelinePlayerTestHarness";
|
|
5
|
+
|
|
6
|
+
/** A browser's postMessage: delivered on a later task, to every listener present then. */
|
|
7
|
+
function postLater(init: MessageEventInit): void {
|
|
8
|
+
setTimeout(() => window.dispatchEvent(new MessageEvent("message", init)));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface SealedPreviewFrame {
|
|
12
|
+
iframe: HTMLIFrameElement;
|
|
13
|
+
/** The frame's window as Studio sees it: only `postMessage` answers, and it reaches the runtime. */
|
|
14
|
+
frame: Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function sealedPreviewFrame(
|
|
18
|
+
options: { wrapHandedOverPort?: (port: MessagePort) => MessagePort } = {},
|
|
19
|
+
): SealedPreviewFrame {
|
|
20
|
+
const target: Record<string, unknown> = {};
|
|
21
|
+
const frame = new Proxy(target, {
|
|
22
|
+
get: (_, key) => {
|
|
23
|
+
if (key === "postMessage") return target.postMessage;
|
|
24
|
+
throw new DOMException("blocked", "SecurityError");
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
const iframe = detachedFakeIframe(frame);
|
|
28
|
+
Object.defineProperty(iframe, "contentDocument", { value: null });
|
|
29
|
+
const wrap = options.wrapHandedOverPort ?? ((port: MessagePort) => port);
|
|
30
|
+
const parent = {
|
|
31
|
+
postMessage: (data: unknown, _origin: string, ports: MessagePort[]) =>
|
|
32
|
+
postLater({ source: frame as unknown as Window, data, ports: ports.map(wrap) }),
|
|
33
|
+
} as unknown as Window;
|
|
34
|
+
const agent = installMarkedEditingAgent(parent);
|
|
35
|
+
frame.postMessage = (data: unknown) => postLater({ source: parent, data });
|
|
36
|
+
onTestFinished(() => agent.dispose());
|
|
37
|
+
return { iframe, frame };
|
|
38
|
+
}
|
|
@@ -101,7 +101,7 @@ function isPreviewPlayerHost(value: unknown): value is PreviewPlayerHost {
|
|
|
101
101
|
return value instanceof HTMLElement;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
function resolvePreviewPlayerHost(iframe: HTMLIFrameElement): PreviewPlayerHost | null {
|
|
104
|
+
export function resolvePreviewPlayerHost(iframe: HTMLIFrameElement): PreviewPlayerHost | null {
|
|
105
105
|
const root = iframe.getRootNode();
|
|
106
106
|
if (
|
|
107
107
|
typeof ShadowRoot !== "undefined" &&
|
|
@@ -1,64 +1,74 @@
|
|
|
1
1
|
// @vitest-environment happy-dom
|
|
2
2
|
|
|
3
3
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
import { previewRequest } from "../player/lib/previewChannel";
|
|
4
5
|
import { addBlockToProject } from "./blockInstaller";
|
|
5
6
|
|
|
7
|
+
vi.mock("../player/lib/previewChannel", async (importOriginal) => {
|
|
8
|
+
const actual = await importOriginal<typeof import("../player/lib/previewChannel")>();
|
|
9
|
+
return { ...actual, previewRequest: vi.fn(async () => null) };
|
|
10
|
+
});
|
|
11
|
+
|
|
6
12
|
afterEach(() => {
|
|
7
13
|
vi.unstubAllGlobals();
|
|
8
14
|
});
|
|
9
15
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
},
|
|
39
|
-
}),
|
|
16
|
+
async function addHud(extra: Partial<Parameters<typeof addBlockToProject>[0]> = {}) {
|
|
17
|
+
const componentPath = "compositions/camcorder-hud.html";
|
|
18
|
+
const targetPath = "compositions/scene.html";
|
|
19
|
+
const files = new Map([
|
|
20
|
+
[
|
|
21
|
+
componentPath,
|
|
22
|
+
`<body><div data-composition-id="camcorder-hud"><div class="hud"></div></div></body>`,
|
|
23
|
+
],
|
|
24
|
+
[
|
|
25
|
+
targetPath,
|
|
26
|
+
`<main data-composition-id="scene" data-duration="10" data-width="1920" data-height="1080"></main>`,
|
|
27
|
+
],
|
|
28
|
+
]);
|
|
29
|
+
vi.stubGlobal(
|
|
30
|
+
"fetch",
|
|
31
|
+
vi.fn().mockResolvedValue({
|
|
32
|
+
ok: true,
|
|
33
|
+
json: async () => ({
|
|
34
|
+
written: [componentPath],
|
|
35
|
+
block: {
|
|
36
|
+
name: "camcorder-hud",
|
|
37
|
+
title: "Camcorder HUD",
|
|
38
|
+
description: "HUD",
|
|
39
|
+
type: "hyperframes:block",
|
|
40
|
+
files: [],
|
|
41
|
+
dimensions: { width: 1920, height: 1080 },
|
|
42
|
+
duration: 4,
|
|
43
|
+
},
|
|
40
44
|
}),
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
}),
|
|
46
|
+
);
|
|
47
|
+
const writeProjectFile = vi.fn(async (path: string, content: string) => {
|
|
48
|
+
files.set(path, content);
|
|
49
|
+
});
|
|
45
50
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
51
|
+
const result = await addBlockToProject({
|
|
52
|
+
projectId: "project",
|
|
53
|
+
blockName: "camcorder-hud",
|
|
54
|
+
activeCompPath: targetPath,
|
|
55
|
+
placement: { start: 2.5, duration: 4.25, track: 3 },
|
|
56
|
+
timelineElements: [],
|
|
57
|
+
readProjectFile: async (path) => files.get(path) ?? "",
|
|
58
|
+
writeProjectFile,
|
|
59
|
+
recordEdit: vi.fn().mockResolvedValue(undefined),
|
|
60
|
+
refreshFileTree: vi.fn().mockResolvedValue(undefined),
|
|
61
|
+
reloadPreview: vi.fn(),
|
|
62
|
+
showToast: vi.fn(),
|
|
63
|
+
...extra,
|
|
64
|
+
});
|
|
65
|
+
return { result, source: files.get(targetPath) };
|
|
66
|
+
}
|
|
59
67
|
|
|
68
|
+
describe("addBlockToProject", () => {
|
|
69
|
+
it("uses an explicit selected-media duration and track for a Registry overlay block", async () => {
|
|
70
|
+
const { result, source } = await addHud();
|
|
60
71
|
expect(result?.block.name).toBe("camcorder-hud");
|
|
61
|
-
const source = files.get(targetPath);
|
|
62
72
|
expect(source).toContain('data-composition-src="compositions/camcorder-hud.html"');
|
|
63
73
|
expect(source).toContain('data-start="2.5"');
|
|
64
74
|
expect(source).toContain('data-duration="4.25"');
|
|
@@ -68,4 +78,28 @@ describe("addBlockToProject", () => {
|
|
|
68
78
|
expect(result?.hostKey).toBe("compositions/scene.html#camcorder-hud");
|
|
69
79
|
expect(source).toContain('id="camcorder-hud"');
|
|
70
80
|
});
|
|
81
|
+
|
|
82
|
+
it("stacks the block above everything a sealed preview paints, read over its editing port", async () => {
|
|
83
|
+
const iframe = document.createElement("iframe");
|
|
84
|
+
Object.defineProperty(iframe, "contentDocument", {
|
|
85
|
+
get() {
|
|
86
|
+
throw new DOMException(
|
|
87
|
+
"Blocked a frame from accessing a cross-origin frame.",
|
|
88
|
+
"SecurityError",
|
|
89
|
+
);
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
vi.mocked(previewRequest).mockResolvedValueOnce({ zIndex: 41 });
|
|
93
|
+
const { source } = await addHud({ previewIframe: iframe });
|
|
94
|
+
expect(vi.mocked(previewRequest)).toHaveBeenCalledWith(iframe, "max-z-index", {});
|
|
95
|
+
expect(source).toContain("z-index: 42");
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("stacks at 1 when the preview's z-index is not a whole number of zero or more", async () => {
|
|
99
|
+
for (const zIndex of [-5, 0.5, 1e308]) {
|
|
100
|
+
vi.mocked(previewRequest).mockResolvedValueOnce({ zIndex });
|
|
101
|
+
const { source } = await addHud({ previewIframe: document.createElement("iframe") });
|
|
102
|
+
expect(source).toContain('z-index: 1"');
|
|
103
|
+
}
|
|
104
|
+
});
|
|
71
105
|
});
|
|
@@ -13,20 +13,11 @@ import { serializeStudioFileMutation } from "./studioFileMutationCoordinator";
|
|
|
13
13
|
import { extendRootDurationInSource } from "./rootDuration";
|
|
14
14
|
import { deriveTimelineStoreKeyForDomId } from "../player/lib/timelineElementHelpers";
|
|
15
15
|
import { studioApiFetch } from "./studioApiFetch";
|
|
16
|
+
import { previewRequest } from "../player/lib/previewChannel";
|
|
16
17
|
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (!doc) return 0;
|
|
21
|
-
let max = 0;
|
|
22
|
-
for (const el of doc.body.querySelectorAll("*")) {
|
|
23
|
-
const z = parseInt(getComputedStyle(el).zIndex, 10);
|
|
24
|
-
if (Number.isFinite(z) && z > max) max = z;
|
|
25
|
-
}
|
|
26
|
-
return max;
|
|
27
|
-
} catch {
|
|
28
|
-
return 0;
|
|
29
|
-
}
|
|
18
|
+
async function previewMaxZIndex(iframe: HTMLIFrameElement | null): Promise<number> {
|
|
19
|
+
const zIndex = iframe ? (await previewRequest(iframe, "max-z-index", {}))?.zIndex : undefined;
|
|
20
|
+
return Number.isSafeInteger(zIndex) && (zIndex as number) >= 0 ? (zIndex as number) : 0;
|
|
30
21
|
}
|
|
31
22
|
|
|
32
23
|
interface AddBlockOptions {
|
|
@@ -214,6 +205,7 @@ export async function addBlockToProject(
|
|
|
214
205
|
timelineElements: relevantElements,
|
|
215
206
|
currentTime: opts.currentTime ?? 0,
|
|
216
207
|
});
|
|
208
|
+
const zIndex = (await previewMaxZIndex(opts.previewIframe ?? null)) + 1;
|
|
217
209
|
let hostId = "";
|
|
218
210
|
const insertHost = (originalContent: string) => {
|
|
219
211
|
const { width, height } = resolveTimelineAssetCompositionSize(originalContent);
|
|
@@ -228,7 +220,7 @@ export async function addBlockToProject(
|
|
|
228
220
|
height,
|
|
229
221
|
left: visualPosition ? Math.round(visualPosition.left) : 0,
|
|
230
222
|
top: visualPosition ? Math.round(visualPosition.top) : 0,
|
|
231
|
-
zIndex
|
|
223
|
+
zIndex,
|
|
232
224
|
});
|
|
233
225
|
return extendRootDurationInSource(
|
|
234
226
|
insertTimelineAssetIntoSource(originalContent, subComposition),
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
|
|
3
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
4
|
+
import { readPreviewCompositionSize } from "./previewCompositionSize";
|
|
5
|
+
|
|
6
|
+
type Player = HTMLElement & {
|
|
7
|
+
ready?: boolean;
|
|
8
|
+
compositionWidth?: number;
|
|
9
|
+
compositionHeight?: number;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/** A frame in a player's shadow root, as <hyperframes-player> holds it; a sealed one refuses its document. */
|
|
13
|
+
function frameInPlayer(sealed: boolean, player: Partial<Player>) {
|
|
14
|
+
const host = Object.assign(document.createElement("div"), player) as Player;
|
|
15
|
+
document.body.append(host);
|
|
16
|
+
const iframe = document.createElement("iframe");
|
|
17
|
+
host.attachShadow({ mode: "open" }).append(iframe);
|
|
18
|
+
if (sealed) {
|
|
19
|
+
const refusing = {
|
|
20
|
+
get document(): Document {
|
|
21
|
+
throw new DOMException("Blocked a frame with origin", "SecurityError");
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(iframe, "contentWindow", { get: () => refusing });
|
|
25
|
+
Object.defineProperty(iframe, "contentDocument", { get: () => null });
|
|
26
|
+
}
|
|
27
|
+
return iframe;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
afterEach(() => document.body.replaceChildren());
|
|
31
|
+
|
|
32
|
+
describe("readPreviewCompositionSize", () => {
|
|
33
|
+
it("reads a sealed frame's size from its player once the player is ready", () => {
|
|
34
|
+
const iframe = frameInPlayer(true, {
|
|
35
|
+
ready: true,
|
|
36
|
+
compositionWidth: 1080,
|
|
37
|
+
compositionHeight: 1920,
|
|
38
|
+
});
|
|
39
|
+
expect(readPreviewCompositionSize(iframe)).toEqual({ width: 1080, height: 1920 });
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("reads no size from a sealed frame's player before it is ready, whose numbers are only defaults", () => {
|
|
43
|
+
const iframe = frameInPlayer(true, {
|
|
44
|
+
ready: false,
|
|
45
|
+
compositionWidth: 1920,
|
|
46
|
+
compositionHeight: 1080,
|
|
47
|
+
});
|
|
48
|
+
expect(readPreviewCompositionSize(iframe)).toBeNull();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("reads a frame Studio can script from its document, not its player", () => {
|
|
52
|
+
const iframe = frameInPlayer(false, {
|
|
53
|
+
ready: true,
|
|
54
|
+
compositionWidth: 1920,
|
|
55
|
+
compositionHeight: 1080,
|
|
56
|
+
});
|
|
57
|
+
iframe.contentDocument!.body.innerHTML =
|
|
58
|
+
'<div data-composition-id="main" data-width="720" data-height="1280"></div>';
|
|
59
|
+
expect(readPreviewCompositionSize(iframe)).toEqual({ width: 720, height: 1280 });
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -1,13 +1,33 @@
|
|
|
1
|
+
import { previewFrameOpaque } from "../player/lib/previewChannel";
|
|
2
|
+
import { resolvePreviewPlayerHost } from "../player/lib/timelineIframeHelpers";
|
|
3
|
+
|
|
1
4
|
export interface PreviewCompositionSize {
|
|
2
5
|
width: number;
|
|
3
6
|
height: number;
|
|
4
7
|
}
|
|
5
8
|
|
|
6
|
-
|
|
9
|
+
type SizedPlayer = HTMLElement & {
|
|
10
|
+
ready?: boolean;
|
|
11
|
+
compositionWidth?: number;
|
|
12
|
+
compositionHeight?: number;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const isPositive = (value: unknown): value is number =>
|
|
16
|
+
typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
17
|
+
|
|
18
|
+
function readyPlayerCompositionSize(iframe: HTMLIFrameElement): PreviewCompositionSize | null {
|
|
19
|
+
const player = resolvePreviewPlayerHost(iframe) as SizedPlayer | null;
|
|
20
|
+
if (!player?.ready) return null;
|
|
21
|
+
const { compositionWidth: width, compositionHeight: height } = player;
|
|
22
|
+
return isPositive(width) && isPositive(height) ? { width, height } : null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The root composition's authored size, from the preview document, or from its player when the frame is sealed. */
|
|
7
26
|
// fallow-ignore-next-line complexity
|
|
8
27
|
export function readPreviewCompositionSize(
|
|
9
28
|
iframe: HTMLIFrameElement | null,
|
|
10
29
|
): PreviewCompositionSize | null {
|
|
30
|
+
if (iframe && previewFrameOpaque(iframe)) return readyPlayerCompositionSize(iframe);
|
|
11
31
|
try {
|
|
12
32
|
const doc = iframe?.contentDocument;
|
|
13
33
|
const root =
|