@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
package/dist/player.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperframes/studio",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.66",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -64,12 +64,12 @@
|
|
|
64
64
|
"dockview-react": "8.3.1",
|
|
65
65
|
"gsap": "^3.13.0",
|
|
66
66
|
"mediabunny": "^1.66.0",
|
|
67
|
-
"@hyperframes/core": "0.9.
|
|
68
|
-
"@hyperframes/
|
|
69
|
-
"@hyperframes/
|
|
70
|
-
"@hyperframes/
|
|
71
|
-
"@hyperframes/
|
|
72
|
-
"@hyperframes/
|
|
67
|
+
"@hyperframes/core": "0.9.66",
|
|
68
|
+
"@hyperframes/player": "0.9.66",
|
|
69
|
+
"@hyperframes/sdk": "0.9.66",
|
|
70
|
+
"@hyperframes/shader-transitions": "0.9.66",
|
|
71
|
+
"@hyperframes/parsers": "0.9.66",
|
|
72
|
+
"@hyperframes/studio-server": "0.9.66"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"vite": "^6.4.5",
|
|
87
87
|
"vitest": "^4.1.12",
|
|
88
88
|
"zustand": "^5.0.0",
|
|
89
|
-
"@hyperframes/producer": "0.9.
|
|
89
|
+
"@hyperframes/producer": "0.9.66"
|
|
90
90
|
},
|
|
91
91
|
"peerDependencies": {
|
|
92
92
|
"react": "19",
|
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
import { act, createElement, Fragment, useRef } from "react";
|
|
3
3
|
import { createRoot } from "react-dom/client";
|
|
4
4
|
import { afterEach, expect, it, vi } from "vitest";
|
|
5
|
-
// The frame's real runtime agent, serving the opaque frame from this document.
|
|
6
|
-
import { installMarkedEditingAgent } from "../../../../core/src/runtime/editingAgent.test-helpers";
|
|
7
5
|
import { installReactActEnvironment } from "../../hooks/domSelectionTestHarness";
|
|
8
|
-
import {
|
|
6
|
+
import { sealedPreviewFrame } from "../../player/lib/sealedPreviewFrame.test-helpers";
|
|
9
7
|
import { previewRequest } from "../../player/lib/previewChannel";
|
|
10
8
|
import { usePreviewIframeStore } from "../../player/store/previewIframeStore";
|
|
11
9
|
import { useCaptionDetection } from "../../hooks/useCaptionDetection";
|
|
@@ -39,14 +37,6 @@ type PortRequest = { id?: unknown; kind?: unknown; params?: unknown };
|
|
|
39
37
|
|
|
40
38
|
/** A frame Studio cannot read, whose runtime is the real editing agent over this document. */
|
|
41
39
|
function opaqueFrame() {
|
|
42
|
-
const frame: Record<string, unknown> = {};
|
|
43
|
-
const iframe = detachedFakeIframe(frame);
|
|
44
|
-
Object.defineProperty(iframe, "contentDocument", { value: null });
|
|
45
|
-
Object.defineProperty(frame, "document", {
|
|
46
|
-
get: () => {
|
|
47
|
-
throw new DOMException("blocked", "SecurityError");
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
40
|
let pick: ((request: PortRequest) => boolean) | null = null;
|
|
51
41
|
const heldIds = new Set<unknown>();
|
|
52
42
|
const held: Array<() => void> = [];
|
|
@@ -67,20 +57,7 @@ function opaqueFrame() {
|
|
|
67
57
|
};
|
|
68
58
|
return end as unknown as MessagePort;
|
|
69
59
|
};
|
|
70
|
-
const
|
|
71
|
-
postMessage: (data: unknown, _origin: string, ports: MessagePort[]) =>
|
|
72
|
-
window.dispatchEvent(
|
|
73
|
-
new MessageEvent("message", {
|
|
74
|
-
source: frame as unknown as Window,
|
|
75
|
-
data,
|
|
76
|
-
ports: ports.map(tap),
|
|
77
|
-
}),
|
|
78
|
-
),
|
|
79
|
-
} as unknown as Window;
|
|
80
|
-
const agent = installMarkedEditingAgent(parent);
|
|
81
|
-
frame.postMessage = (data: unknown) =>
|
|
82
|
-
window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
|
|
83
|
-
closers.push(() => agent.dispose());
|
|
60
|
+
const { iframe } = sealedPreviewFrame({ wrapHandedOverPort: tap });
|
|
84
61
|
iframe.style.width = "1920px";
|
|
85
62
|
iframe.getBoundingClientRect = () => new DOMRect(0, 0, 1920, 1080);
|
|
86
63
|
/** Keeps the answers to the requests `match` picks; the returned call hands them to Studio. */
|
|
@@ -3,16 +3,14 @@
|
|
|
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.
|
|
7
|
-
import { installMarkedEditingAgent } from "../../../../core/src/runtime/editingAgent.test-helpers";
|
|
8
6
|
import { installReactActEnvironment } from "../../hooks/domSelectionTestHarness";
|
|
9
|
-
import { detachedFakeIframe } from "../../player/hooks/timelinePlayerTestHarness";
|
|
10
7
|
import { usePreviewIframeStore } from "../../player/store/previewIframeStore";
|
|
11
8
|
import type { DomEditSelection } from "./domEditing";
|
|
12
9
|
import { LayersPanel } from "./LayersPanel";
|
|
13
10
|
import { announcePreviewDocumentLoaded } from "../../player/sceneSwap";
|
|
14
11
|
import { describePreviewElements, queryPreviewElements } from "../../player/lib/previewElements";
|
|
15
12
|
import { standInFor } from "./previewSelection";
|
|
13
|
+
import { sealedPreviewFrame } from "../../player/lib/sealedPreviewFrame.test-helpers";
|
|
16
14
|
|
|
17
15
|
installReactActEnvironment();
|
|
18
16
|
|
|
@@ -75,35 +73,12 @@ afterEach(() => {
|
|
|
75
73
|
document.body.innerHTML = "";
|
|
76
74
|
});
|
|
77
75
|
|
|
78
|
-
/** A frame Studio cannot read, whose runtime is the real editing agent over this document. */
|
|
79
|
-
function opaqueFrame() {
|
|
80
|
-
const frame: Record<string, unknown> = {};
|
|
81
|
-
const iframe = detachedFakeIframe(frame);
|
|
82
|
-
Object.defineProperty(iframe, "contentDocument", { value: null });
|
|
83
|
-
Object.defineProperty(frame, "document", {
|
|
84
|
-
get: () => {
|
|
85
|
-
throw new DOMException("blocked", "SecurityError");
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
const parent = {
|
|
89
|
-
postMessage: (data: unknown, _origin: string, ports: MessagePort[]) =>
|
|
90
|
-
window.dispatchEvent(
|
|
91
|
-
new MessageEvent("message", { source: frame as unknown as Window, data, ports }),
|
|
92
|
-
),
|
|
93
|
-
} as unknown as Window;
|
|
94
|
-
const agent = installMarkedEditingAgent(parent);
|
|
95
|
-
frame.postMessage = (data: unknown) =>
|
|
96
|
-
window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
|
|
97
|
-
closers.push(() => agent.dispose());
|
|
98
|
-
return iframe;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
76
|
it("lists an opaque frame's layers, selects a row, and drills into a group row", async () => {
|
|
102
77
|
document.body.innerHTML = `<main data-composition-id="main">
|
|
103
78
|
<div id="card"><h1 id="title">Hi</h1></div>
|
|
104
79
|
<div id="pair" data-hf-group="pair"><i id="a"></i></div>
|
|
105
80
|
<div id="host" data-composition-src="compositions/intro-card.html"></div></main>`;
|
|
106
|
-
const iframe =
|
|
81
|
+
const iframe = sealedPreviewFrame().iframe;
|
|
107
82
|
mocks.previewIframeRef.current = iframe;
|
|
108
83
|
usePreviewIframeStore.setState({ iframe });
|
|
109
84
|
const host = document.createElement("div");
|
|
@@ -149,7 +124,7 @@ function renderPanel(iframe: HTMLIFrameElement) {
|
|
|
149
124
|
it("leaves a drill-in whose group a reload took, rather than list the whole page under it", async () => {
|
|
150
125
|
document.body.innerHTML = `<main data-composition-id="main">
|
|
151
126
|
<div id="card"></div><div id="pair" data-hf-group="pair"><i id="a"></i></div></main>`;
|
|
152
|
-
const iframe =
|
|
127
|
+
const iframe = sealedPreviewFrame().iframe;
|
|
153
128
|
const [pair] = (await queryPreviewElements(iframe, "#pair"))!.matches;
|
|
154
129
|
const [described] = (await describePreviewElements(iframe, [pair!.handle]))!;
|
|
155
130
|
mocks.activeGroupElement = standInFor(iframe, described!);
|
|
@@ -163,7 +138,7 @@ it("reads the layers once more when a refresh lands while a read is in flight",
|
|
|
163
138
|
document.body.innerHTML = `<main data-composition-id="main"><div id="card"></div></main>`;
|
|
164
139
|
let release!: () => void;
|
|
165
140
|
mocks.hold = new Promise<void>((resolve) => (release = resolve));
|
|
166
|
-
const iframe =
|
|
141
|
+
const iframe = sealedPreviewFrame().iframe;
|
|
167
142
|
const rows = renderPanel(iframe);
|
|
168
143
|
await vi.waitFor(() => expect(mocks.answered).toBe(1));
|
|
169
144
|
// Past the panel's settle timer, so only the announced refresh can bring the new layer.
|
|
@@ -7,6 +7,9 @@ import {
|
|
|
7
7
|
type ClipPathInsetSides,
|
|
8
8
|
type ParsedInsetClipPathSides,
|
|
9
9
|
} from "./clipPathHelpers";
|
|
10
|
+
import { MAX_DRAFT_PX, MAX_ELEMENT_VALUE } from "@hyperframes/core/runtime/editing-port";
|
|
11
|
+
import { previewRequest } from "../../player/lib/previewChannel";
|
|
12
|
+
import { previewStandIn } from "./previewDrafts";
|
|
10
13
|
|
|
11
14
|
export type CropEdge = "top" | "right" | "bottom" | "left";
|
|
12
15
|
|
|
@@ -38,7 +41,11 @@ export function cropRectFromInsets(
|
|
|
38
41
|
|
|
39
42
|
// A selected croppable element shows uncropped so the crop UI can dim what is cut away. A rule keyed on its
|
|
40
43
|
// identity does that, so the element's own clip-path stays the one record undo, redo and panel edits rewrite.
|
|
41
|
-
|
|
44
|
+
// A sealed preview's lift is that rule in the frame (core `editing/cropLift.ts`), and `rule` is null.
|
|
45
|
+
// A frame lift is kept until the frame says it is gone, so a lost reply never leaves the crop hidden there.
|
|
46
|
+
type CropLift = { rule: HTMLStyleElement | null; sheetClip?: string; dropped?: boolean };
|
|
47
|
+
const cropLifts = new WeakMap<HTMLElement, CropLift>();
|
|
48
|
+
const UNLIFT_TRIES = 3;
|
|
42
49
|
|
|
43
50
|
function liftSelector(element: HTMLElement): string | null {
|
|
44
51
|
const quote = (value: string) => `"${value.replace(/["\\]/g, "\\$&")}"`;
|
|
@@ -47,7 +54,38 @@ function liftSelector(element: HTMLElement): string | null {
|
|
|
47
54
|
return element.id ? `[id=${quote(element.id)}]` : null;
|
|
48
55
|
}
|
|
49
56
|
|
|
57
|
+
function unliftInFrame(element: HTMLElement, record: CropLift, tries = UNLIFT_TRIES): void {
|
|
58
|
+
const target = previewStandIn(element);
|
|
59
|
+
if (!target) return;
|
|
60
|
+
void previewRequest(target.iframe, "crop-lift", { handle: target.handle, lift: false }).then(
|
|
61
|
+
(reply) => {
|
|
62
|
+
if (cropLifts.get(element) !== record) return;
|
|
63
|
+
if (reply?.lifted === false) cropLifts.delete(element);
|
|
64
|
+
else if (tries > 1) unliftInFrame(element, record, tries - 1);
|
|
65
|
+
},
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function liftInFrame(element: HTMLElement): boolean {
|
|
70
|
+
const target = previewStandIn(element);
|
|
71
|
+
if (!target) return false;
|
|
72
|
+
// Until the frame answers, the clip it last reported is the one under the lift.
|
|
73
|
+
const record: CropLift = { rule: null, sheetClip: frameClipPaths.get(element)?.computed ?? "" };
|
|
74
|
+
cropLifts.set(element, record);
|
|
75
|
+
void previewRequest(target.iframe, "crop-lift", { handle: target.handle, lift: true }).then(
|
|
76
|
+
(reply) => {
|
|
77
|
+
if (cropLifts.get(element) !== record || !reply) return;
|
|
78
|
+
if (!reply.lifted) cropLifts.delete(element);
|
|
79
|
+
else if (typeof reply.clipPath === "string" && reply.clipPath.length <= MAX_ELEMENT_VALUE)
|
|
80
|
+
record.sheetClip = reply.clipPath.trim();
|
|
81
|
+
},
|
|
82
|
+
);
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
|
|
50
86
|
export function liftElementCrop(element: HTMLElement): void {
|
|
87
|
+
const held = cropLifts.get(element);
|
|
88
|
+
if ((held && !held.dropped) || liftInFrame(element)) return;
|
|
51
89
|
const selector = liftSelector(element);
|
|
52
90
|
if (!selector || cropLifts.has(element)) return;
|
|
53
91
|
const doc = element.ownerDocument;
|
|
@@ -58,37 +96,62 @@ export function liftElementCrop(element: HTMLElement): void {
|
|
|
58
96
|
}
|
|
59
97
|
|
|
60
98
|
export function dropElementCropLift(element: HTMLElement): void {
|
|
61
|
-
cropLifts.get(element)
|
|
62
|
-
|
|
99
|
+
const lift = cropLifts.get(element);
|
|
100
|
+
if (!lift || lift.dropped) return;
|
|
101
|
+
if (lift.rule) {
|
|
102
|
+
lift.rule.remove();
|
|
103
|
+
cropLifts.delete(element);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
lift.dropped = true;
|
|
107
|
+
unliftInFrame(element, lift);
|
|
63
108
|
}
|
|
64
109
|
|
|
65
110
|
export function isElementCropLifted(element: HTMLElement): boolean {
|
|
66
|
-
|
|
111
|
+
const lift = cropLifts.get(element);
|
|
112
|
+
return !!lift && !lift.dropped;
|
|
67
113
|
}
|
|
68
114
|
|
|
69
|
-
|
|
70
|
-
|
|
115
|
+
// A sealed preview's stand-in has no styles of its own: its clip-path is the one the frame reported.
|
|
116
|
+
const frameClipPaths = new WeakMap<Element, { inline: string; computed: string }>();
|
|
71
117
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (
|
|
118
|
+
export function rememberFrameClipPath(element: HTMLElement, inline: string, computed: string) {
|
|
119
|
+
frameClipPaths.set(element, { inline: inline.trim(), computed: computed.trim() });
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const computedClipPath = (element: HTMLElement) => {
|
|
123
|
+
const view = element.ownerDocument.defaultView;
|
|
124
|
+
if (!view) return frameClipPaths.get(element)?.computed ?? "";
|
|
125
|
+
return view.getComputedStyle(element).clipPath.trim();
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/** The stylesheet's clip under a lift, read once per lift: only inline writes happen while selected. */
|
|
129
|
+
function sheetClipUnder(element: HTMLElement, lift: CropLift): string {
|
|
130
|
+
if (lift.sheetClip === undefined && lift.rule) {
|
|
79
131
|
const { parentNode, nextSibling } = lift.rule;
|
|
80
132
|
lift.rule.remove();
|
|
81
133
|
lift.sheetClip = computedClipPath(element);
|
|
82
134
|
parentNode?.insertBefore(lift.rule, nextSibling);
|
|
83
135
|
}
|
|
84
|
-
return lift.sheetClip;
|
|
136
|
+
return lift.sheetClip ?? "";
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** The element's clip-path, inline first, then the stylesheet's as it is without the lift. */
|
|
140
|
+
function readElementClipPath(element: HTMLElement): string {
|
|
141
|
+
const inline =
|
|
142
|
+
element.style.getPropertyValue("clip-path").trim() || frameClipPaths.get(element)?.inline;
|
|
143
|
+
if (inline) return inline;
|
|
144
|
+
const lift = cropLifts.get(element);
|
|
145
|
+
return lift && !lift.dropped ? sheetClipUnder(element, lift) : computedClipPath(element);
|
|
85
146
|
}
|
|
86
147
|
|
|
87
148
|
/** Zeros = no clip yet. `null` = a clip this tool cannot represent (circle/polygon/non-px inset):
|
|
88
149
|
* croppers must not lift, edit, or restore it, or deselect silently replaces or destroys it. */
|
|
89
150
|
function parseCropClipPath(value: string): ParsedInsetClipPathSides | null {
|
|
90
151
|
if (!value || value === "none") return { top: 0, right: 0, bottom: 0, left: 0, radius: 0 };
|
|
91
|
-
|
|
152
|
+
const sides = parseInsetClipPathSides(value);
|
|
153
|
+
const sane = sides && Object.values(sides).every((side) => Math.abs(side) <= MAX_DRAFT_PX);
|
|
154
|
+
return sane ? sides : null;
|
|
92
155
|
}
|
|
93
156
|
|
|
94
157
|
export function readElementCropInsets(element: HTMLElement): ParsedInsetClipPathSides | null {
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import {
|
|
4
|
+
dropElementCropLift,
|
|
5
|
+
isElementCropLifted,
|
|
6
|
+
liftElementCrop,
|
|
7
|
+
readElementCropInsets,
|
|
8
|
+
} from "./domEditOverlayCrop";
|
|
9
|
+
|
|
10
|
+
const sent: Array<{ lift: boolean; answer: (reply: unknown) => void }> = [];
|
|
11
|
+
vi.mock("../../player/lib/previewChannel", () => ({
|
|
12
|
+
previewRequest: (_iframe: unknown, _kind: string, params: { lift: boolean }) =>
|
|
13
|
+
new Promise((answer) => sent.push({ lift: params.lift, answer })),
|
|
14
|
+
}));
|
|
15
|
+
vi.mock("./previewDrafts", () => ({
|
|
16
|
+
previewStandIn: () => ({ iframe: {}, handle: "hf-1" }),
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
sent.length = 0;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const settle = () => new Promise((done) => setTimeout(done, 0));
|
|
24
|
+
|
|
25
|
+
async function lifted(clipPath = "inset(10px)") {
|
|
26
|
+
const el = document.createElement("div");
|
|
27
|
+
liftElementCrop(el);
|
|
28
|
+
sent.at(-1)!.answer({ lifted: true, clipPath });
|
|
29
|
+
await settle();
|
|
30
|
+
return el;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
describe("a crop lift in a frame Studio cannot script", () => {
|
|
34
|
+
it("is kept when the lift's reply is lost, so deselecting still asks the frame to drop it", async () => {
|
|
35
|
+
const el = document.createElement("div");
|
|
36
|
+
liftElementCrop(el);
|
|
37
|
+
sent[0]!.answer(null);
|
|
38
|
+
await settle();
|
|
39
|
+
expect(isElementCropLifted(el)).toBe(true);
|
|
40
|
+
dropElementCropLift(el);
|
|
41
|
+
expect(sent.map((request) => request.lift)).toEqual([true, false]);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("asks again until the frame says the lift is gone, and only then forgets it", async () => {
|
|
45
|
+
const el = await lifted();
|
|
46
|
+
dropElementCropLift(el);
|
|
47
|
+
sent[1]!.answer(null);
|
|
48
|
+
await settle();
|
|
49
|
+
expect(sent.map((request) => request.lift)).toEqual([true, false, false]);
|
|
50
|
+
sent[2]!.answer({ lifted: false, clipPath: null });
|
|
51
|
+
await settle();
|
|
52
|
+
expect(sent).toHaveLength(3);
|
|
53
|
+
expect(isElementCropLifted(el)).toBe(false);
|
|
54
|
+
liftElementCrop(el);
|
|
55
|
+
expect(sent.map((request) => request.lift)).toEqual([true, false, false, true]);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("ignores a clip-path past the element value cap, and an inset past the draft limit", async () => {
|
|
59
|
+
expect(readElementCropInsets(await lifted(`inset(5px) ${"x".repeat(3000)}`))).toMatchObject({
|
|
60
|
+
top: 0,
|
|
61
|
+
});
|
|
62
|
+
expect(readElementCropInsets(await lifted("inset(200000px 0px 0px 0px)"))).toBeNull();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -3,15 +3,12 @@
|
|
|
3
3
|
import { gsap } from "gsap";
|
|
4
4
|
import { parseGsapScriptAcorn } from "@hyperframes/parsers/gsap-parser-acorn";
|
|
5
5
|
import { afterEach, expect, it, vi } from "vitest";
|
|
6
|
-
// The frame's real runtime agent, serving the opaque frame from this document.
|
|
7
|
-
import { installMarkedEditingAgent } from "../../../../core/src/runtime/editingAgent.test-helpers";
|
|
8
6
|
import { makeSelection } from "../../hooks/domSelectionTestHarness";
|
|
9
7
|
import { freezeDragStamp } from "../../hooks/draggedGsapPosition";
|
|
10
8
|
import { settleGsapSnapshot } from "../../hooks/gsapFrameSnapshot";
|
|
11
9
|
import { tryGsapDragIntercept } from "../../hooks/gsapRuntimeBridge";
|
|
12
10
|
import { watchPreviewFrame } from "../../player/lib/bridgePlayback";
|
|
13
11
|
import { describePreviewElements, queryPreviewElements } from "../../player/lib/previewElements";
|
|
14
|
-
import { detachedFakeIframe } from "../../player/hooks/timelinePlayerTestHarness";
|
|
15
12
|
import { usePlayerStore } from "../../player/store/playerStore";
|
|
16
13
|
import type { UseDomEditOverlayGesturesOptions } from "./domEditOverlayGestures";
|
|
17
14
|
import { startGesture } from "./domEditOverlayStartGesture";
|
|
@@ -22,6 +19,7 @@ import {
|
|
|
22
19
|
} from "./manualOffsetDrag";
|
|
23
20
|
import { measurePreviewGestureStart } from "./previewGestureStartRead";
|
|
24
21
|
import { standInFor } from "./previewSelection";
|
|
22
|
+
import { sealedPreviewFrame } from "../../player/lib/sealedPreviewFrame.test-helpers";
|
|
25
23
|
|
|
26
24
|
const timeline = (tweens: string) => `var tl = gsap.timeline({ paused: true });
|
|
27
25
|
${tweens}
|
|
@@ -52,7 +50,6 @@ function drawnAt(box: HTMLElement) {
|
|
|
52
50
|
const mainTimeline = () =>
|
|
53
51
|
(window as unknown as { __timelines?: Record<string, gsap.core.Timeline> }).__timelines?.main;
|
|
54
52
|
|
|
55
|
-
const closers: Array<() => void> = [];
|
|
56
53
|
function mount(script: string, extra = "") {
|
|
57
54
|
document.body.innerHTML = `<div data-composition-id="main" data-width="1920" data-height="1080"><div id="box"></div>${extra}</div>`;
|
|
58
55
|
const box = document.getElementById("box")!;
|
|
@@ -76,7 +73,6 @@ function mount(script: string, extra = "") {
|
|
|
76
73
|
usePlayerStore.setState({ currentTime: 0.5, isPlaying: false, autoKeyframeEnabled: true });
|
|
77
74
|
}
|
|
78
75
|
afterEach(() => {
|
|
79
|
-
closers.splice(0).forEach((close) => close());
|
|
80
76
|
mainTimeline()?.kill();
|
|
81
77
|
document.body.innerHTML = "";
|
|
82
78
|
for (const name of ["gsap", "__timelines"]) Reflect.deleteProperty(window, name);
|
|
@@ -91,24 +87,8 @@ function sized<T extends Element>(element: T, [x, y, width, height]: number[]):
|
|
|
91
87
|
|
|
92
88
|
/** A frame Studio cannot read, whose runtime is the real editing agent over this document. */
|
|
93
89
|
function opaqueFrame() {
|
|
94
|
-
const
|
|
95
|
-
const iframe = sized(
|
|
96
|
-
Object.defineProperty(iframe, "contentDocument", { value: null });
|
|
97
|
-
Object.defineProperty(frame, "document", {
|
|
98
|
-
get: () => {
|
|
99
|
-
throw new DOMException("blocked", "SecurityError");
|
|
100
|
-
},
|
|
101
|
-
});
|
|
102
|
-
const parent = {
|
|
103
|
-
postMessage: (data: unknown, _origin: string, ports: MessagePort[]) =>
|
|
104
|
-
window.dispatchEvent(
|
|
105
|
-
new MessageEvent("message", { source: frame as unknown as Window, data, ports }),
|
|
106
|
-
),
|
|
107
|
-
} as unknown as Window;
|
|
108
|
-
const agent = installMarkedEditingAgent(parent);
|
|
109
|
-
frame.postMessage = (data: unknown) =>
|
|
110
|
-
window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
|
|
111
|
-
closers.push(() => agent.dispose());
|
|
90
|
+
const { iframe: sealed, frame } = sealedPreviewFrame();
|
|
91
|
+
const iframe = sized(sealed, [100, 50, 960, 540]) as HTMLIFrameElement;
|
|
112
92
|
watchPreviewFrame(iframe);
|
|
113
93
|
window.dispatchEvent(
|
|
114
94
|
new MessageEvent("message", {
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
// @vitest-environment happy-dom
|
|
2
2
|
|
|
3
3
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
4
|
-
|
|
5
|
-
import { installMarkedEditingAgent } from "../../../../core/src/runtime/editingAgent.test-helpers";
|
|
6
|
-
import { detachedFakeIframe } from "../../player/hooks/timelinePlayerTestHarness";
|
|
4
|
+
import { sealedPreviewFrame } from "../../player/lib/sealedPreviewFrame.test-helpers";
|
|
7
5
|
import { describePreviewElements, queryPreviewElements } from "../../player/lib/previewElements";
|
|
8
6
|
import { resolvePreviewSelection, standInFor } from "./previewSelection";
|
|
9
7
|
import { manualOffsetMoveRevert } from "./gestureUndoRevert";
|
|
@@ -35,38 +33,14 @@ vi.mock("../../player/lib/previewChannel", async (importOriginal) => {
|
|
|
35
33
|
const draftRequests = () =>
|
|
36
34
|
vi.mocked(previewRequest).mock.calls.filter(([, kind]) => kind === "draft");
|
|
37
35
|
|
|
38
|
-
const closers: Array<() => void> = [];
|
|
39
36
|
beforeEach(() => {
|
|
40
37
|
document.body.innerHTML = `<main data-composition-id="main"><div id="card" style="width: 200px; height: 100px"></div><div id="chip" style="translate: 30px 0px"></div><div id="centred" style="width: 200px; height: 100px; translate: -50% -50%"></div><div id="moved" data-hf-studio-original-inline-translate="" style="translate: 10px 20px"></div></main>`;
|
|
41
38
|
});
|
|
42
39
|
afterEach(() => {
|
|
43
|
-
closers.splice(0).forEach((close) => close());
|
|
44
40
|
document.body.innerHTML = "";
|
|
45
41
|
});
|
|
46
42
|
|
|
47
43
|
/** A frame whose window refuses every read, as a cross-origin one does; its runtime serves this document. */
|
|
48
|
-
function opaqueFrame(): HTMLIFrameElement {
|
|
49
|
-
const blocked = () => {
|
|
50
|
-
throw new DOMException("blocked", "SecurityError");
|
|
51
|
-
};
|
|
52
|
-
const target: Record<string, unknown> = {};
|
|
53
|
-
const frame = new Proxy(target, {
|
|
54
|
-
get: (_, key) => (key === "postMessage" ? target.postMessage : blocked()),
|
|
55
|
-
});
|
|
56
|
-
const iframe = detachedFakeIframe(frame);
|
|
57
|
-
Object.defineProperty(iframe, "contentDocument", { value: null });
|
|
58
|
-
const parent = {
|
|
59
|
-
postMessage: (data: unknown, _origin: string, ports: MessagePort[]) =>
|
|
60
|
-
window.dispatchEvent(
|
|
61
|
-
new MessageEvent("message", { source: frame as unknown as Window, data, ports }),
|
|
62
|
-
),
|
|
63
|
-
} as unknown as Window;
|
|
64
|
-
const agent = installMarkedEditingAgent(parent);
|
|
65
|
-
target.postMessage = (data: unknown) =>
|
|
66
|
-
window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
|
|
67
|
-
closers.push(() => agent.dispose());
|
|
68
|
-
return iframe;
|
|
69
|
-
}
|
|
70
44
|
|
|
71
45
|
async function described(iframe: HTMLIFrameElement, selector: string) {
|
|
72
46
|
const handle = (await queryPreviewElements(iframe, selector))!.matches[0]!.handle;
|
|
@@ -106,7 +80,7 @@ const shown = (element: HTMLElement) =>
|
|
|
106
80
|
|
|
107
81
|
describe("gesture drafts on an opaque frame", () => {
|
|
108
82
|
it("moves the frame's element with a drag, and puts it back when the drag is cancelled", async () => {
|
|
109
|
-
const member = dragMember(await standIn(
|
|
83
|
+
const member = dragMember(await standIn(sealedPreviewFrame().iframe, "#card"));
|
|
110
84
|
applyManualOffsetDragDraft(member, 10, 0);
|
|
111
85
|
applyManualOffsetDragDraft(member, 40, 20);
|
|
112
86
|
await vi.waitFor(() => expect(shown(card())).toEqual([80, 40]));
|
|
@@ -117,7 +91,7 @@ describe("gesture drafts on an opaque frame", () => {
|
|
|
117
91
|
});
|
|
118
92
|
|
|
119
93
|
it("holds a saved drag where it was dropped, and the next drag starts from there", async () => {
|
|
120
|
-
const element = await standIn(
|
|
94
|
+
const element = await standIn(sealedPreviewFrame().iframe, "#card");
|
|
121
95
|
const first = dragMember(element);
|
|
122
96
|
applyManualOffsetDragCommit(first, 40, 20);
|
|
123
97
|
endManualOffsetDragMembers([first]);
|
|
@@ -128,7 +102,7 @@ describe("gesture drafts on an opaque frame", () => {
|
|
|
128
102
|
});
|
|
129
103
|
|
|
130
104
|
it("draws a drag that grabs the layer again before the last save settles from where that one left it", async () => {
|
|
131
|
-
const element = await standIn(
|
|
105
|
+
const element = await standIn(sealedPreviewFrame().iframe, "#card");
|
|
132
106
|
const first = dragMember(element);
|
|
133
107
|
applyManualOffsetDragCommit(first, 40, 20);
|
|
134
108
|
await vi.waitFor(() => expect(shown(card())).toEqual([80, 40]));
|
|
@@ -143,7 +117,7 @@ describe("gesture drafts on an opaque frame", () => {
|
|
|
143
117
|
});
|
|
144
118
|
|
|
145
119
|
it("puts a move back on the frame when an undo painted over it does not go through", async () => {
|
|
146
|
-
const member = dragMember(await standIn(
|
|
120
|
+
const member = dragMember(await standIn(sealedPreviewFrame().iframe, "#card"));
|
|
147
121
|
applyManualOffsetDragCommit(member, 40, 20);
|
|
148
122
|
await vi.waitFor(() => expect(shown(card())).toEqual([80, 40]));
|
|
149
123
|
const putBack = manualOffsetMoveRevert([member])();
|
|
@@ -155,7 +129,7 @@ describe("gesture drafts on an opaque frame", () => {
|
|
|
155
129
|
});
|
|
156
130
|
|
|
157
131
|
it("moves a % translate from the px the frame renders it at, and keeps the author's value to reset to", async () => {
|
|
158
|
-
const iframe =
|
|
132
|
+
const iframe = sealedPreviewFrame().iframe;
|
|
159
133
|
const options = { activeCompositionPath: "index.html", isMasterView: false };
|
|
160
134
|
const selection = await resolvePreviewSelection(
|
|
161
135
|
iframe,
|
|
@@ -175,7 +149,7 @@ describe("gesture drafts on an opaque frame", () => {
|
|
|
175
149
|
});
|
|
176
150
|
|
|
177
151
|
it("refuses to move a % translate it has no rendered px for, rather than drop it", async () => {
|
|
178
|
-
const element = await standIn(
|
|
152
|
+
const element = await standIn(sealedPreviewFrame().iframe, "#centred");
|
|
179
153
|
const made = createManualOffsetDragMember({
|
|
180
154
|
key: "k",
|
|
181
155
|
selection: { element } as DomEditSelection,
|
|
@@ -187,13 +161,13 @@ describe("gesture drafts on an opaque frame", () => {
|
|
|
187
161
|
});
|
|
188
162
|
|
|
189
163
|
it("keeps the translate the author had before Studio moved the layer as the one to reset to", async () => {
|
|
190
|
-
const element = await standIn(
|
|
164
|
+
const element = await standIn(sealedPreviewFrame().iframe, "#moved");
|
|
191
165
|
applyManualOffsetDragCommit(dragMember(element), 40, 0);
|
|
192
166
|
expect(element.getAttribute(STUDIO_ORIGINAL_INLINE_TRANSLATE_ATTR)).toBe("");
|
|
193
167
|
});
|
|
194
168
|
|
|
195
169
|
it("starts a drag on a freshly loaded frame from the translate its element has", async () => {
|
|
196
|
-
const member = dragMember(await standIn(
|
|
170
|
+
const member = dragMember(await standIn(sealedPreviewFrame().iframe, "#chip"));
|
|
197
171
|
expect(member.initialOffset).toEqual({ x: 30, y: 0 });
|
|
198
172
|
expect(applyManualOffsetDragCommit(member, 40, 0)).toEqual({ x: 110, y: 0 });
|
|
199
173
|
const chip = document.getElementById("chip")!;
|
|
@@ -201,7 +175,7 @@ describe("gesture drafts on an opaque frame", () => {
|
|
|
201
175
|
});
|
|
202
176
|
|
|
203
177
|
it("sends one request at a time and draws only the latest of the moves that waited", async () => {
|
|
204
|
-
const member = dragMember(await standIn(
|
|
178
|
+
const member = dragMember(await standIn(sealedPreviewFrame().iframe, "#card"));
|
|
205
179
|
vi.mocked(previewRequest).mockClear();
|
|
206
180
|
for (let dx = 2; dx <= 40; dx += 2) applyManualOffsetDragDraft(member, dx, 0);
|
|
207
181
|
await vi.waitFor(() => expect(shown(card())).toEqual([80, 0]));
|
|
@@ -209,7 +183,7 @@ describe("gesture drafts on an opaque frame", () => {
|
|
|
209
183
|
});
|
|
210
184
|
|
|
211
185
|
it("grows a resized box about its centre without measuring the frame, and draws it there", async () => {
|
|
212
|
-
const iframe =
|
|
186
|
+
const iframe = sealedPreviewFrame().iframe;
|
|
213
187
|
const element = await standIn(iframe, "#card");
|
|
214
188
|
const g = {
|
|
215
189
|
...{ originLeft: 10, originTop: 20, originWidth: 100, originHeight: 50 },
|
|
@@ -230,7 +204,7 @@ describe("gesture drafts on an opaque frame", () => {
|
|
|
230
204
|
});
|
|
231
205
|
|
|
232
206
|
it("keeps a saved resize with no offset member on the frame when a later restore runs", async () => {
|
|
233
|
-
const iframe =
|
|
207
|
+
const iframe = sealedPreviewFrame().iframe;
|
|
234
208
|
const element = await standIn(iframe, "#card");
|
|
235
209
|
const before = captureStudioBoxSize(element);
|
|
236
210
|
const token = beginStudioManualEditGesture(element, "resize");
|
|
@@ -258,6 +232,6 @@ describe("gesture drafts on an opaque frame", () => {
|
|
|
258
232
|
});
|
|
259
233
|
|
|
260
234
|
it("reports a timeline rebind it cannot reach, so the caller syncs the preview another way", () => {
|
|
261
|
-
expect(applySoftReloadFinalization(
|
|
235
|
+
expect(applySoftReloadFinalization(sealedPreviewFrame().iframe, 1)).toBe(false);
|
|
262
236
|
});
|
|
263
237
|
});
|
|
@@ -30,6 +30,8 @@ export function registerPreviewStandIn(
|
|
|
30
30
|
standIns.set(standIn, { iframe, handle });
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
+
export const previewStandIn = (standIn: Element) => standIns.get(standIn);
|
|
34
|
+
|
|
33
35
|
function queueFor(iframe: HTMLIFrameElement): Queue {
|
|
34
36
|
let queue = queues.get(iframe);
|
|
35
37
|
if (!queue) {
|