@hyperframes/studio 0.9.64 → 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-CVmmHGol.js → index-B8Xt_Oyw.js} +190 -186
- package/dist/assets/{index-DN167Uqf.js → index-BH18TdX9.js} +1 -1
- package/dist/assets/{pausedVideoDecoder-C8rhpGPx.js → pausedVideoDecoder-Bx3fGNkU.js} +1 -1
- package/dist/{chunk-VDDEXNVX.js → chunk-ESTBKVCB.js} +8 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.html +1 -1
- package/dist/index.js +1580 -882
- package/dist/player.js +1 -1
- package/package.json +8 -8
- package/src/captions/components/CaptionOverlay.sealed.test.ts +2 -25
- package/src/captions/hooks/useCaptionSync.ts +4 -1
- package/src/components/editor/LayersPanel.opaque.test.ts +4 -29
- package/src/components/editor/MotionPathOverlay.sealed.test.tsx +85 -0
- package/src/components/editor/MotionPathOverlay.tsx +26 -12
- package/src/components/editor/domEditOverlayCrop.ts +78 -15
- package/src/components/editor/domEditOverlayCropFrameLift.test.ts +64 -0
- package/src/components/editor/domEditOverlayStartGesture.ts +0 -14
- package/src/components/editor/gestureUndoRevert.ts +3 -6
- package/src/components/editor/gsapMoveSealedPreview.test.ts +247 -0
- package/src/components/editor/manualEditsSnapshot.ts +2 -0
- package/src/components/editor/manualOffsetDrag.ts +13 -18
- package/src/components/editor/plainTranslate.test.ts +22 -1
- package/src/components/editor/plainTranslate.ts +8 -6
- package/src/components/editor/previewDrafts.test.ts +13 -39
- package/src/components/editor/previewDrafts.ts +4 -0
- package/src/components/editor/previewGestureStartRead.test.ts +59 -32
- 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 +18 -0
- package/src/components/editor/useColorGradingController.sealed.test.ts +5 -30
- package/src/components/editor/useMotionPathData.reply.test.ts +40 -0
- package/src/components/editor/useMotionPathData.sealed.test.ts +57 -0
- package/src/components/editor/useMotionPathData.test.tsx +1 -1
- package/src/components/editor/useMotionPathData.ts +83 -33
- package/src/components/nle/CompositionBreadcrumb.tsx +2 -5
- 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/components/panels/motionBlurPanelModel.sealed.test.ts +30 -0
- package/src/components/panels/motionBlurPanelModel.ts +37 -7
- 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/draggedGsapPosition.ts +20 -0
- package/src/hooks/gsapEditOutcome.ts +3 -0
- package/src/hooks/gsapFrameSnapshot.test.ts +113 -0
- package/src/hooks/gsapFrameSnapshot.ts +246 -0
- package/src/hooks/gsapParsedTween.ts +16 -9
- package/src/hooks/gsapResizeIntercept.ts +7 -2
- package/src/hooks/gsapRuntimeBridge.ts +4 -0
- package/src/hooks/gsapRuntimeKeyframes.ts +23 -15
- package/src/hooks/gsapShared.ts +4 -0
- package/src/hooks/gsapSnapshotReply.ts +105 -0
- 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/useDomEditCommits.test.tsx +1 -1
- package/src/hooks/useDomEditPreviewSync.test.ts +36 -1
- package/src/hooks/useDomEditPreviewSync.ts +3 -3
- package/src/hooks/useEditorSave.ts +2 -1
- package/src/hooks/useEnableKeyframes.sealed.test.ts +70 -0
- package/src/hooks/useEnableKeyframes.ts +9 -2
- package/src/hooks/useGsapTweenCache.ts +9 -3
- package/src/hooks/usePreviewPersistence.ts +18 -11
- package/src/hooks/useSdkSession.lifecycle.test.tsx +1 -0
- package/src/hooks/useSdkSession.ts +2 -0
- 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 +101 -18
- package/src/player/lib/sealedPreviewFrame.test-helpers.ts +38 -0
- package/src/player/lib/timelineIframeHelpers.ts +1 -1
- package/src/telemetry/client.ts +4 -2
- package/src/telemetry/eventShape.test.ts +189 -0
- package/src/telemetry/eventShape.ts +192 -0
- package/src/utils/blockInstaller.test.ts +82 -48
- package/src/utils/blockInstaller.ts +6 -14
- package/src/utils/domEditSaveQueue.test.ts +12 -2
- package/src/utils/domEditSaveQueue.ts +4 -4
- package/src/utils/previewCompositionSize.test.ts +61 -0
- package/src/utils/previewCompositionSize.ts +21 -1
- package/src/utils/sdkEditTransaction.ts +6 -2
- package/src/utils/sdkResolverShadow.ts +16 -15
- package/src/utils/studioSaveDiagnostics.test.ts +21 -3
- package/src/utils/studioSaveDiagnostics.ts +71 -6
- package/src/utils/studioTelemetry.ts +6 -1
- package/dist/assets/hyperframes-player-mSF_GvRs.js +0 -573
- package/src/components/editor/motionPathHome.ts +0 -75
|
@@ -342,6 +342,7 @@ function disposeSdkSession(session: Composition): void {
|
|
|
342
342
|
session.dispose();
|
|
343
343
|
} catch (error) {
|
|
344
344
|
trackStudioEvent("sdk_session_dispose_failed", {
|
|
345
|
+
error_name: error instanceof Error ? error.name : typeof error,
|
|
345
346
|
error: error instanceof Error ? error.message : String(error),
|
|
346
347
|
});
|
|
347
348
|
}
|
|
@@ -510,6 +511,7 @@ export function useSdkSession(
|
|
|
510
511
|
// bucket was a network error wearing a parser's label.
|
|
511
512
|
trackStudioEvent("sdk_session_unavailable", {
|
|
512
513
|
stage: "open",
|
|
514
|
+
error_name: error instanceof Error ? error.name : typeof error,
|
|
513
515
|
error: error instanceof Error ? error.message : String(error),
|
|
514
516
|
});
|
|
515
517
|
}
|
|
@@ -2,9 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
import React, { act } from "react";
|
|
4
4
|
import { createRoot } from "react-dom/client";
|
|
5
|
-
import { afterEach, describe, expect, it } from "vitest";
|
|
5
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
import { previewClipManifest } from "../player/lib/previewChannel";
|
|
6
7
|
import { useSlideshowTabState } from "./useSlideshowTabState";
|
|
7
8
|
|
|
9
|
+
vi.mock("../player/lib/previewChannel", async (importOriginal) => {
|
|
10
|
+
const actual = await importOriginal<typeof import("../player/lib/previewChannel")>();
|
|
11
|
+
return { ...actual, previewClipManifest: vi.fn(async () => null) };
|
|
12
|
+
});
|
|
13
|
+
|
|
8
14
|
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
9
15
|
|
|
10
16
|
const SLIDESHOW_HTML = `<html><body><script type="application/hyperframes-slideshow+json">{"slides":[]}</script></body></html>`;
|
|
@@ -14,16 +20,21 @@ afterEach(() => {
|
|
|
14
20
|
document.body.innerHTML = "";
|
|
15
21
|
});
|
|
16
22
|
|
|
17
|
-
function renderHook(params: {
|
|
23
|
+
function renderHook(params: {
|
|
24
|
+
editingFileContent: string | null | undefined;
|
|
25
|
+
iframe?: HTMLIFrameElement | null;
|
|
26
|
+
}) {
|
|
18
27
|
const host = document.createElement("div");
|
|
19
28
|
document.body.append(host);
|
|
20
29
|
const root = createRoot(host);
|
|
21
30
|
let current: ReturnType<typeof useSlideshowTabState> | null = null;
|
|
31
|
+
// One ref for every render, as Studio's useRef gives.
|
|
32
|
+
const previewIframeRef = { current: params.iframe ?? null };
|
|
22
33
|
|
|
23
34
|
function Harness() {
|
|
24
35
|
current = useSlideshowTabState({
|
|
25
36
|
editingFileContent: params.editingFileContent,
|
|
26
|
-
previewIframeRef
|
|
37
|
+
previewIframeRef,
|
|
27
38
|
refreshKey: 0,
|
|
28
39
|
slideshowVisible: false,
|
|
29
40
|
});
|
|
@@ -71,4 +82,37 @@ describe("useSlideshowTabState", () => {
|
|
|
71
82
|
expect(harness.getState().isSlideshowComposition).toBe(true);
|
|
72
83
|
harness.unmount();
|
|
73
84
|
});
|
|
85
|
+
|
|
86
|
+
it("lists the scenes of a sealed preview, read over its editing port", async () => {
|
|
87
|
+
// A cross-origin frame's window refuses every property read.
|
|
88
|
+
const sealedWindow = new Proxy(
|
|
89
|
+
{},
|
|
90
|
+
{
|
|
91
|
+
get() {
|
|
92
|
+
throw new DOMException(
|
|
93
|
+
"Blocked a frame from accessing a cross-origin frame.",
|
|
94
|
+
"SecurityError",
|
|
95
|
+
);
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
);
|
|
99
|
+
const iframe = document.createElement("iframe");
|
|
100
|
+
Object.defineProperty(iframe, "contentWindow", { value: sealedWindow });
|
|
101
|
+
vi.mocked(previewClipManifest).mockResolvedValueOnce({
|
|
102
|
+
clips: [],
|
|
103
|
+
durationInFrames: 300,
|
|
104
|
+
scenes: [
|
|
105
|
+
null,
|
|
106
|
+
{ id: "s1", label: "Intro", start: 0, duration: 4 },
|
|
107
|
+
{ id: 2, label: "Bad id", start: 4, duration: 4 },
|
|
108
|
+
{ id: "s3", label: "No time", start: null, duration: 4 },
|
|
109
|
+
],
|
|
110
|
+
} as unknown as Awaited<ReturnType<typeof previewClipManifest>>);
|
|
111
|
+
const harness = renderHook({ editingFileContent: SLIDESHOW_HTML, iframe });
|
|
112
|
+
await act(async () => {});
|
|
113
|
+
expect(harness.getState().slideshowScenes).toEqual([
|
|
114
|
+
{ id: "s1", label: "Intro", start: 0, duration: 4 },
|
|
115
|
+
]);
|
|
116
|
+
harness.unmount();
|
|
117
|
+
});
|
|
74
118
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { useMemo, type MutableRefObject } from "react";
|
|
1
|
+
import { useEffect, useMemo, useState, type MutableRefObject } from "react";
|
|
2
2
|
import { SLIDESHOW_ISLAND_TYPE, slideshowIslandRegex } from "@hyperframes/core/slideshow";
|
|
3
3
|
import type { SceneInfo } from "../components/panels/SlideshowPanel";
|
|
4
|
-
import
|
|
4
|
+
import { previewClipManifest } from "../player/lib/previewChannel";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Derives whether the currently-edited composition is a slideshow (carries
|
|
@@ -10,6 +10,18 @@ import type { IframeWindow } from "../player/lib/playbackTypes";
|
|
|
10
10
|
* for the Slideshow panel. Extracted from StudioRightPanels to keep that file
|
|
11
11
|
* under the 600-LOC gate.
|
|
12
12
|
*/
|
|
13
|
+
/** The manifest is frame data: a scene entry must carry a string id and label and finite times. */
|
|
14
|
+
function isSceneEntry(value: unknown): value is SceneInfo {
|
|
15
|
+
if (!value || typeof value !== "object") return false;
|
|
16
|
+
const s = value as Record<string, unknown>;
|
|
17
|
+
return (
|
|
18
|
+
typeof s.id === "string" &&
|
|
19
|
+
typeof s.label === "string" &&
|
|
20
|
+
Number.isFinite(s.start) &&
|
|
21
|
+
Number.isFinite(s.duration)
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
13
25
|
export function useSlideshowTabState(params: {
|
|
14
26
|
editingFileContent: string | null | undefined;
|
|
15
27
|
previewIframeRef: MutableRefObject<HTMLIFrameElement | null>;
|
|
@@ -28,20 +40,24 @@ export function useSlideshowTabState(params: {
|
|
|
28
40
|
return slideshowIslandRegex("i").test(editingFileContent);
|
|
29
41
|
}, [editingFileContent]);
|
|
30
42
|
|
|
31
|
-
//
|
|
32
|
-
const slideshowScenes =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
// The scene list from the preview's live clip manifest, read over its editing port.
|
|
44
|
+
const [slideshowScenes, setSlideshowScenes] = useState<SceneInfo[]>([]);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
const iframe = previewIframeRef.current;
|
|
47
|
+
if (!iframe) return setSlideshowScenes([]);
|
|
48
|
+
let current = true;
|
|
49
|
+
void previewClipManifest(iframe).then((manifest) => {
|
|
50
|
+
if (!current) return;
|
|
51
|
+
const scenes: unknown[] = Array.isArray(manifest?.scenes) ? manifest.scenes : [];
|
|
52
|
+
setSlideshowScenes(
|
|
53
|
+
scenes
|
|
54
|
+
.filter(isSceneEntry)
|
|
55
|
+
.map((s) => ({ id: s.id, label: s.label, start: s.start, duration: s.duration })),
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
return () => {
|
|
59
|
+
current = false;
|
|
60
|
+
};
|
|
45
61
|
}, [previewIframeRef, slideshowVisible, refreshKey]);
|
|
46
62
|
|
|
47
63
|
return { isSlideshowComposition, slideshowScenes };
|
|
@@ -171,7 +171,8 @@ export function serveEditingRequests(
|
|
|
171
171
|
};
|
|
172
172
|
const handoff = { source: "hf-preview", type: "editing-port", v: 1 };
|
|
173
173
|
const source = frame as unknown as Window;
|
|
174
|
-
|
|
174
|
+
const init = { source, data: handoff, ports: [port2] };
|
|
175
|
+
setTimeout(() => window.dispatchEvent(new MessageEvent("message", init)));
|
|
175
176
|
};
|
|
176
177
|
return () => ports.forEach((port) => port.close());
|
|
177
178
|
}
|
|
@@ -3,43 +3,16 @@
|
|
|
3
3
|
import { act, createElement } from "react";
|
|
4
4
|
import { createRoot } from "react-dom/client";
|
|
5
5
|
import { afterEach, expect, it, vi } from "vitest";
|
|
6
|
-
// The frame's real runtime agent, serving the opaque frame from this document as Studio's marked preview page.
|
|
7
|
-
import { installMarkedEditingAgent } from "../../../../core/src/runtime/editingAgent.test-helpers";
|
|
8
6
|
import type { TimelineElement } from "../store/playerStore";
|
|
9
|
-
import { detachedFakeIframe } from "./timelinePlayerTestHarness";
|
|
10
7
|
import { useTimelineSyncCallbacks } from "./useTimelineSyncCallbacks";
|
|
8
|
+
import { sealedPreviewFrame } from "../lib/sealedPreviewFrame.test-helpers";
|
|
11
9
|
|
|
12
10
|
(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
13
11
|
|
|
14
|
-
const closers: Array<() => void> = [];
|
|
15
12
|
afterEach(() => {
|
|
16
|
-
closers.splice(0).forEach((close) => close());
|
|
17
13
|
document.body.innerHTML = "";
|
|
18
14
|
});
|
|
19
15
|
|
|
20
|
-
/** A frame Studio cannot read, whose runtime is the real editing agent over this document. */
|
|
21
|
-
function opaqueFrame() {
|
|
22
|
-
const frame: Record<string, unknown> = {};
|
|
23
|
-
const iframe = detachedFakeIframe(frame);
|
|
24
|
-
Object.defineProperty(iframe, "contentDocument", { value: null });
|
|
25
|
-
Object.defineProperty(frame, "document", {
|
|
26
|
-
get: () => {
|
|
27
|
-
throw new DOMException("blocked", "SecurityError");
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
const parent = {
|
|
31
|
-
postMessage: (data: unknown, _origin: string, ports: MessagePort[]) =>
|
|
32
|
-
window.dispatchEvent(
|
|
33
|
-
new MessageEvent("message", { source: frame as unknown as Window, data, ports }),
|
|
34
|
-
),
|
|
35
|
-
} as unknown as Window;
|
|
36
|
-
const agent = installMarkedEditingAgent(parent);
|
|
37
|
-
frame.postMessage = (data: unknown) =>
|
|
38
|
-
window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
|
|
39
|
-
closers.push(() => agent.dispose());
|
|
40
|
-
return iframe;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
16
|
function processWith(iframe: HTMLIFrameElement) {
|
|
44
17
|
const sync = vi.fn<(els: TimelineElement[], duration?: number) => void>();
|
|
45
18
|
let callbacks: ReturnType<typeof useTimelineSyncCallbacks> | undefined;
|
|
@@ -84,7 +57,7 @@ it("binds a sealed preview's timeline row to its element, as an open preview doe
|
|
|
84
57
|
document.body.innerHTML = `<div data-composition-id="main" data-composition-file="index.html">
|
|
85
58
|
<div id="box" class="clip" data-start="0" data-duration="2" data-audio-group="voice"></div>
|
|
86
59
|
</div>`;
|
|
87
|
-
const { sync, process } = processWith(
|
|
60
|
+
const { sync, process } = processWith(sealedPreviewFrame().iframe);
|
|
88
61
|
|
|
89
62
|
process({ clips: [boxClip], durationInFrames: 60 });
|
|
90
63
|
|
|
@@ -120,6 +120,16 @@ describe("previewEditingClient", () => {
|
|
|
120
120
|
expect(Date.now() - started).toBeLessThan(AGENT_PROBE_MS + 500);
|
|
121
121
|
});
|
|
122
122
|
|
|
123
|
+
it("answers a frame whose runtime never came at once, rather than after another probe", async () => {
|
|
124
|
+
const { iframe } = opaqueFrame();
|
|
125
|
+
const started = Date.now();
|
|
126
|
+
await previewSeekPainted(iframe, 15_000);
|
|
127
|
+
expect(Date.now() - started).toBeGreaterThanOrEqual(AGENT_PROBE_MS - 50);
|
|
128
|
+
const again = Date.now();
|
|
129
|
+
await previewSeekPainted(iframe, 15_000);
|
|
130
|
+
expect(Date.now() - again).toBeLessThan(100);
|
|
131
|
+
});
|
|
132
|
+
|
|
123
133
|
it("returns the runtime's manifest only when its reply has the manifest's shape", async () => {
|
|
124
134
|
const manifest = { clips: [], durationInFrames: 30, scenes: [] };
|
|
125
135
|
let reply: unknown = { clipManifest: manifest };
|
|
@@ -54,7 +54,15 @@ export function setFrameLoopStart(iframe: HTMLIFrameElement, seconds: number | n
|
|
|
54
54
|
|
|
55
55
|
export const AGENT_PROBE_MS = 1_000;
|
|
56
56
|
|
|
57
|
+
const agents = new WeakMap<EditingPortClient, boolean>();
|
|
58
|
+
|
|
57
59
|
async function agentConnected(client: EditingPortClient): Promise<boolean> {
|
|
60
|
+
const known = agents.get(client);
|
|
61
|
+
if (known !== undefined) return known;
|
|
62
|
+
client.ready.then(
|
|
63
|
+
() => agents.set(client, true),
|
|
64
|
+
() => agents.set(client, false),
|
|
65
|
+
);
|
|
58
66
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
59
67
|
const probe = new Promise<boolean>(
|
|
60
68
|
(resolve) => (timer = setTimeout(resolve, AGENT_PROBE_MS, false)),
|
|
@@ -67,6 +75,7 @@ async function agentConnected(client: EditingPortClient): Promise<boolean> {
|
|
|
67
75
|
probe,
|
|
68
76
|
]);
|
|
69
77
|
clearTimeout(timer);
|
|
78
|
+
if (!agents.has(client)) agents.set(client, connected);
|
|
70
79
|
return connected;
|
|
71
80
|
}
|
|
72
81
|
|
|
@@ -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,
|
|
@@ -27,34 +30,43 @@ export type PreviewElement = EditingElementDescription & { readonly [checked]: t
|
|
|
27
30
|
export type PreviewElementHit = EditingElementHit & { readonly [checked]: true };
|
|
28
31
|
|
|
29
32
|
type Fields = Record<string, unknown>;
|
|
30
|
-
const isFields = (value: unknown): value is Fields =>
|
|
33
|
+
export const isFields = (value: unknown): value is Fields =>
|
|
31
34
|
typeof value === "object" && value !== null && !Array.isArray(value);
|
|
32
|
-
const isHandle = (value: unknown) =>
|
|
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" &&
|
package/src/telemetry/client.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { browserTelemetryAllowed } from "./policy";
|
|
|
9
9
|
import { getBrowserSystemMeta } from "./system";
|
|
10
10
|
import { canaryEventProperties } from "./canary";
|
|
11
11
|
import { recordBreadcrumb } from "./breadcrumbs";
|
|
12
|
+
import { shapeEventProperties } from "./eventShape";
|
|
12
13
|
import { studioApiFetch } from "../utils/studioApiFetch";
|
|
13
14
|
|
|
14
15
|
// Write-only PostHog project key, safe to embed in client code.
|
|
@@ -41,7 +42,8 @@ export function trackEvent(event: string, properties: EventProperties = {}): voi
|
|
|
41
42
|
|
|
42
43
|
// Every studio event passes through here, so this is the one place that can
|
|
43
44
|
// build a repro trail without asking each call site to opt in.
|
|
44
|
-
|
|
45
|
+
const shaped = shapeEventProperties(event, properties);
|
|
46
|
+
recordBreadcrumb(event, shaped);
|
|
45
47
|
|
|
46
48
|
const sys = getBrowserSystemMeta();
|
|
47
49
|
eventQueue.push({
|
|
@@ -49,7 +51,7 @@ export function trackEvent(event: string, properties: EventProperties = {}): voi
|
|
|
49
51
|
// Canary assignments as `$feature/canary-<name>`, mirroring the CLI so a
|
|
50
52
|
// rollout spanning both surfaces reads as one flag in PostHog. Resolved
|
|
51
53
|
// after the shouldTrack guard, so opted-out users never pay for it.
|
|
52
|
-
properties: { ...
|
|
54
|
+
properties: { ...shaped, ...sys, ...canaryEventProperties() },
|
|
53
55
|
timestamp: new Date().toISOString(),
|
|
54
56
|
});
|
|
55
57
|
|