@hyperframes/studio 0.9.39 → 0.9.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{codec-CY6KnWXa.js → codec-B_mpbc4w.js} +1 -1
- package/dist/assets/{hyperframes-player-B9-CuG_h.js → hyperframes-player-Dvi3I_mv.js} +1 -1
- package/dist/assets/{index-_pkzoYYF.js → index-B5ExwsOp.js} +146 -146
- package/dist/assets/{index-Bjz2UaYv.js → index-BrFm9Y5k.js} +1 -1
- package/dist/assets/{pausedVideoDecoder-Dr7nKUUu.js → pausedVideoDecoder-MHQ57yZ6.js} +1 -1
- package/dist/{chunk-NBULUIWH.js → chunk-4QQMX4BX.js} +17 -8
- package/dist/{chunk-ATDO3YLX.js → chunk-GVW7AU57.js} +190 -254
- package/dist/{chunk-44VRMER6.js → chunk-VHV2ZDKY.js} +17 -97
- package/dist/{domEditingLayers-FRVHP6IB.js → domEditingLayers-SA5KLSSS.js} +4 -2
- package/dist/index.d.ts +4 -0
- package/dist/index.html +1 -1
- package/dist/index.js +898 -551
- package/dist/player.js +2 -2
- package/package.json +8 -8
- package/src/components/editor/DomEditOverlay.tsx +3 -15
- package/src/components/editor/clickAfterPreventedPress.test.tsx +17 -1
- package/src/components/editor/domEditOverlayBasis.ts +7 -2
- package/src/components/editor/domEditOverlayCrop.test.ts +1 -1
- package/src/components/editor/domEditOverlayCrop.ts +17 -3
- package/src/components/editor/domEditOverlayGeometry.ts +64 -139
- package/src/components/editor/domEditSelectionRules.ts +138 -0
- package/src/components/editor/domEditing.test.ts +6 -28
- package/src/components/editor/domEditingDom.preview.test.ts +3 -3
- package/src/components/editor/domEditingDom.ts +24 -165
- package/src/components/editor/domEditingElement.ts +19 -240
- package/src/components/editor/domEditingGroups.ts +0 -31
- package/src/components/editor/domEditingLayers.ts +95 -100
- package/src/components/editor/domEditingRootLayer.ts +35 -30
- package/src/components/editor/domEditingTypes.ts +4 -0
- package/src/components/editor/previewGestureStarts.ts +73 -10
- package/src/components/editor/previewOverlayRects.test.ts +316 -0
- package/src/components/editor/previewOverlayRects.ts +123 -0
- package/src/components/editor/previewPointerTargets.test.ts +260 -0
- package/src/components/editor/previewSelection.test.ts +481 -0
- package/src/components/editor/previewSelection.ts +472 -0
- package/src/components/editor/probeSourceElement.ts +19 -1
- package/src/components/editor/propertyPanelFill.tsx +5 -1
- package/src/components/editor/useDomEditOverlayRects.ts +80 -1
- package/src/components/editor/useInlineTextEditing.tsx +1 -6
- package/src/hooks/domSelectionTestHarness.ts +1 -1
- package/src/hooks/useDomEditSession.test.tsx +23 -1
- package/src/hooks/useDomEditSession.ts +2 -1
- package/src/hooks/useDomSelection.ts +61 -47
- package/src/hooks/useGsapSelectionHandlers.test.tsx +17 -0
- package/src/hooks/useGsapSelectionHandlers.ts +2 -1
- package/src/hooks/usePreviewInteraction.test.ts +10 -2
- package/src/hooks/usePreviewInteraction.ts +5 -4
- package/src/hooks/useStudioSelectionPublisher.test.tsx +50 -0
- package/src/hooks/useStudioSelectionPublisher.ts +9 -7
- package/src/player/lib/previewChannel.ts +26 -10
- package/src/player/lib/previewElements.test.ts +167 -0
- package/src/player/lib/previewElements.ts +226 -0
- package/src/styles/hex-baseline.json +1 -2
- package/src/utils/studioHelpers.ts +0 -13
- package/src/utils/studioPreviewHelpers.test.ts +8 -8
- package/src/utils/studioPreviewHelpers.ts +26 -242
- package/src/components/editor/domEditOverlayTransform.ts +0 -126
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
|
|
3
|
+
import React, { act } from "react";
|
|
4
|
+
import { createRoot } from "react-dom/client";
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
6
|
+
// The frame's real runtime agent, serving the opaque frame from this document.
|
|
7
|
+
import { installEditingAgent } from "../../../../core/src/runtime/editingAgent";
|
|
8
|
+
import {
|
|
9
|
+
getAllPreviewTargetsFromPointer,
|
|
10
|
+
getPreviewTargetFromPointer,
|
|
11
|
+
} from "../../utils/studioPreviewHelpers";
|
|
12
|
+
import {
|
|
13
|
+
elementWithin,
|
|
14
|
+
findPointerTarget,
|
|
15
|
+
findPointerTargets,
|
|
16
|
+
pointerMayHitElement,
|
|
17
|
+
selectionDataAttribute,
|
|
18
|
+
} from "./previewSelection";
|
|
19
|
+
import type { PreviewElement } from "../../player/lib/previewElements";
|
|
20
|
+
import { detachedFakeIframe } from "../../player/hooks/timelinePlayerTestHarness";
|
|
21
|
+
import { installReactActEnvironment } from "../../hooks/domSelectionTestHarness";
|
|
22
|
+
import { useDomSelection } from "../../hooks/useDomSelection";
|
|
23
|
+
import type { TimelineElement } from "../../player";
|
|
24
|
+
|
|
25
|
+
installReactActEnvironment();
|
|
26
|
+
|
|
27
|
+
const FIXTURE = `
|
|
28
|
+
<main data-composition-id="main" data-width="1920" data-height="1080">
|
|
29
|
+
<section id="block"><div id="mask" style="overflow: hidden"><h1 id="title">Launch</h1></div></section>
|
|
30
|
+
<div id="ghost" style="pointer-events: none"><p id="under-ghost">hidden from clicks</p></div>
|
|
31
|
+
<div id="backdrop" style="background: #111"></div>
|
|
32
|
+
<p data-hf-id="note">Note</p>
|
|
33
|
+
<div id="pair" data-hf-group="pair"><i id="a" style="background: red"></i><i data-hf-id="b-hf" style="background: blue"></i></div>
|
|
34
|
+
</main>`;
|
|
35
|
+
const RECTS: Record<string, number[]> = {
|
|
36
|
+
title: [44, 44, 220, 48],
|
|
37
|
+
mask: [40, 40, 260, 64],
|
|
38
|
+
block: [30, 30, 300, 100],
|
|
39
|
+
"under-ghost": [500, 40, 200, 60],
|
|
40
|
+
ghost: [500, 40, 200, 60],
|
|
41
|
+
backdrop: [0, 0, 1920, 1080],
|
|
42
|
+
pair: [0, 0, 1, 1],
|
|
43
|
+
a: [1000, 600, 100, 100],
|
|
44
|
+
"b-hf": [1300, 800, 100, 100],
|
|
45
|
+
};
|
|
46
|
+
/** Frame points, in the composition's pixels, and what lies under each, topmost first. */
|
|
47
|
+
const STACKS: Array<[x: number, y: number, ids: string[]]> = [
|
|
48
|
+
[60, 60, ["title", "mask", "block", "backdrop"]],
|
|
49
|
+
[560, 60, ["under-ghost", "ghost", "backdrop"]],
|
|
50
|
+
[900, 500, ["backdrop"]],
|
|
51
|
+
[1200, 700, ["backdrop"]],
|
|
52
|
+
[1050, 650, ["a", "pair", "backdrop"]],
|
|
53
|
+
];
|
|
54
|
+
const FRAME = [100, 50, 960, 540];
|
|
55
|
+
|
|
56
|
+
function sized(element: Element, [x, y, width, height]: number[]) {
|
|
57
|
+
element.getBoundingClientRect = () =>
|
|
58
|
+
({ x, y, width, height, left: x, top: y, right: x + width, bottom: y + height }) as DOMRect;
|
|
59
|
+
return element;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const at = (x: number, y: number) => STACKS.find(([px, py]) => px === x && py === y)?.[2] ?? [];
|
|
63
|
+
const byId = (id: string) =>
|
|
64
|
+
document.getElementById(id) ?? document.querySelector(`[data-hf-id="${id}"]`);
|
|
65
|
+
|
|
66
|
+
const closers: Array<() => void> = [];
|
|
67
|
+
beforeEach(() => {
|
|
68
|
+
document.body.innerHTML = FIXTURE;
|
|
69
|
+
sized(document.querySelector("main")!, [0, 0, 1920, 1080]);
|
|
70
|
+
for (const [id, rect] of Object.entries(RECTS)) sized(byId(id)!, rect);
|
|
71
|
+
const stack = (x: number, y: number) => at(Math.round(x), Math.round(y)).map((id) => byId(id)!);
|
|
72
|
+
Object.assign(document, {
|
|
73
|
+
elementsFromPoint: stack,
|
|
74
|
+
elementFromPoint: (x: number, y: number) => stack(x, y)[0] ?? null,
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
afterEach(() => {
|
|
78
|
+
closers.splice(0).forEach((close) => close());
|
|
79
|
+
document.body.innerHTML = "";
|
|
80
|
+
delete (document as { elementsFromPoint?: unknown }).elementsFromPoint;
|
|
81
|
+
delete (document as { elementFromPoint?: unknown }).elementFromPoint;
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
/** A frame Studio scripts directly; its document is this one. */
|
|
85
|
+
function liveFrame(): HTMLIFrameElement {
|
|
86
|
+
const iframe = detachedFakeIframe({});
|
|
87
|
+
Object.defineProperty(iframe, "contentDocument", { value: document });
|
|
88
|
+
return sized(iframe, FRAME) as HTMLIFrameElement;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** A frame Studio cannot read, whose runtime is the real editing agent over this document. */
|
|
92
|
+
function opaqueFrame(): HTMLIFrameElement {
|
|
93
|
+
const frame: Record<string, unknown> = {};
|
|
94
|
+
const iframe = sized(detachedFakeIframe(frame), FRAME) as HTMLIFrameElement;
|
|
95
|
+
Object.defineProperty(iframe, "contentDocument", { value: null });
|
|
96
|
+
Object.defineProperty(frame, "document", {
|
|
97
|
+
get: () => {
|
|
98
|
+
throw new DOMException("blocked", "SecurityError");
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
const parent = {
|
|
102
|
+
postMessage: (data: unknown, _origin: string, ports: MessagePort[]) =>
|
|
103
|
+
window.dispatchEvent(
|
|
104
|
+
new MessageEvent("message", { source: frame as unknown as Window, data, ports }),
|
|
105
|
+
),
|
|
106
|
+
} as unknown as Window;
|
|
107
|
+
const agent = installEditingAgent(parent);
|
|
108
|
+
frame.postMessage = (data: unknown) =>
|
|
109
|
+
window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
|
|
110
|
+
closers.push(() => agent.dispose());
|
|
111
|
+
return iframe;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** The client point over frame point (x, y): the frame shows the composition at half size. */
|
|
115
|
+
const client = (x: number, y: number) => [FRAME[0]! + x / 2, FRAME[1]! + y / 2] as const;
|
|
116
|
+
const nameOf = (element: HTMLElement | PreviewElement | null | undefined) => {
|
|
117
|
+
if (!element) return null;
|
|
118
|
+
if ("handle" in element)
|
|
119
|
+
return element.id ?? element.attributes.find(([k]) => k === "data-hf-id")?.[1];
|
|
120
|
+
return element.id || element.getAttribute("data-hf-id");
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
describe("canvas hit-tests on an opaque frame match same-origin ones", () => {
|
|
124
|
+
it.each(STACKS.map(([x, y]) => [x, y]))("at (%d, %d)", async (x, y) => {
|
|
125
|
+
const [cx, cy] = client(x, y);
|
|
126
|
+
const live = liveFrame();
|
|
127
|
+
const opaque = opaqueFrame();
|
|
128
|
+
const pick = nameOf(getPreviewTargetFromPointer(live, cx, cy));
|
|
129
|
+
expect(nameOf(await findPointerTarget(opaque, cx, cy))).toBe(pick);
|
|
130
|
+
const stack = getAllPreviewTargetsFromPointer(live, cx, cy).map(nameOf);
|
|
131
|
+
expect((await findPointerTargets(opaque, cx, cy)).map(nameOf)).toEqual(stack);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("picks what each rule decides: the leaf, not a pointer-events:none layer, not a backdrop, a group's gap", async () => {
|
|
135
|
+
const opaque = opaqueFrame();
|
|
136
|
+
const picks = [];
|
|
137
|
+
for (const [x, y] of STACKS)
|
|
138
|
+
picks.push(nameOf(await findPointerTarget(opaque, ...client(x, y))));
|
|
139
|
+
expect(picks).toEqual(["title", null, null, "pair", "a"]);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("knows whether a press lands on an element only where the frame last answered", async () => {
|
|
143
|
+
const opaque = opaqueFrame();
|
|
144
|
+
const title = client(60, 60);
|
|
145
|
+
const empty = client(900, 500);
|
|
146
|
+
expect(pointerMayHitElement(opaque, ...empty)).toBe(true);
|
|
147
|
+
await findPointerTarget(opaque, ...empty);
|
|
148
|
+
expect(pointerMayHitElement(opaque, ...empty)).toBe(false);
|
|
149
|
+
expect(pointerMayHitElement(opaque, ...title)).toBe(true);
|
|
150
|
+
await findPointerTarget(opaque, ...title);
|
|
151
|
+
expect(pointerMayHitElement(opaque, ...title)).toBe(true);
|
|
152
|
+
expect(pointerMayHitElement(liveFrame(), ...empty)).toBe(false);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("says it cannot tell when the frame has no editing agent", async () => {
|
|
156
|
+
vi.useFakeTimers();
|
|
157
|
+
try {
|
|
158
|
+
const iframe = sized(detachedFakeIframe({}), FRAME) as HTMLIFrameElement;
|
|
159
|
+
Object.defineProperty(iframe, "contentDocument", { value: null });
|
|
160
|
+
Object.defineProperty(iframe.contentWindow!, "document", {
|
|
161
|
+
get: () => {
|
|
162
|
+
throw new DOMException("blocked", "SecurityError");
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
const found = findPointerTarget(iframe, ...client(60, 60));
|
|
166
|
+
await vi.advanceTimersByTimeAsync(2_000);
|
|
167
|
+
expect(await found).toBeUndefined();
|
|
168
|
+
} finally {
|
|
169
|
+
vi.useRealTimers();
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
describe("useDomSelection over an opaque frame's canvas", () => {
|
|
175
|
+
function renderSelection(iframe: HTMLIFrameElement) {
|
|
176
|
+
let hook: ReturnType<typeof useDomSelection> | null = null;
|
|
177
|
+
function Harness() {
|
|
178
|
+
hook = useDomSelection({
|
|
179
|
+
projectId: null,
|
|
180
|
+
activeCompPath: "index.html",
|
|
181
|
+
isMasterView: true,
|
|
182
|
+
compIdToSrc: new Map(),
|
|
183
|
+
captionEditMode: false,
|
|
184
|
+
previewIframeRef: { current: iframe },
|
|
185
|
+
timelineElements: [],
|
|
186
|
+
getTimelineSelectionSet: () => new Set(),
|
|
187
|
+
setSelectedTimelineElementId: vi.fn(),
|
|
188
|
+
setTimelineSelectionSet: vi.fn(),
|
|
189
|
+
setRightCollapsed: vi.fn(),
|
|
190
|
+
setRightPanelTab: vi.fn(),
|
|
191
|
+
previewIframe: iframe,
|
|
192
|
+
refreshKey: 0,
|
|
193
|
+
rightPanelTab: "design",
|
|
194
|
+
});
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
const root = createRoot(document.createElement("div"));
|
|
198
|
+
act(() => root.render(React.createElement(Harness)));
|
|
199
|
+
closers.push(() => act(() => root.unmount()));
|
|
200
|
+
return () => hook!;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
it("selects the clicked element and keeps a hover on it", async () => {
|
|
204
|
+
const hook = renderSelection(opaqueFrame());
|
|
205
|
+
const point = client(60, 60);
|
|
206
|
+
const picked = await act(() => hook().resolveDomSelectionFromPreviewPoint(...point));
|
|
207
|
+
expect(picked).toMatchObject({ id: "title", selector: "#title" });
|
|
208
|
+
act(() => hook().updateDomEditHoverSelection(picked));
|
|
209
|
+
expect(hook().domEditHoverSelection).toBe(picked);
|
|
210
|
+
const cycle = await act(() => hook().resolveAllDomSelectionsFromPreviewPoint(...point));
|
|
211
|
+
expect(cycle.map((selection) => selection.id)).toEqual(["title", "mask", "block"]);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("takes a hover of the same element from a reloaded frame, whose handle is new", async () => {
|
|
215
|
+
const hook = renderSelection(opaqueFrame());
|
|
216
|
+
const picked = (await act(() =>
|
|
217
|
+
hook().resolveDomSelectionFromPreviewPoint(...client(60, 60)),
|
|
218
|
+
))!;
|
|
219
|
+
act(() => hook().updateDomEditHoverSelection(picked));
|
|
220
|
+
const reloaded = { ...picked, handle: "0123456789abcdef:1" };
|
|
221
|
+
act(() => hook().updateDomEditHoverSelection(reloaded));
|
|
222
|
+
expect(hook().domEditHoverSelection).toBe(reloaded);
|
|
223
|
+
act(() => hook().updateDomEditHoverSelection({ ...reloaded }));
|
|
224
|
+
expect(hook().domEditHoverSelection).toBe(reloaded);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it("drills into a group and stays in it while selecting its members", async () => {
|
|
228
|
+
const hook = renderSelection(opaqueFrame());
|
|
229
|
+
const group = (await act(() =>
|
|
230
|
+
hook().resolveDomSelectionFromPreviewPoint(...client(1200, 700)),
|
|
231
|
+
))!;
|
|
232
|
+
expect(selectionDataAttribute(group, "data-hf-group")).toBe("pair");
|
|
233
|
+
expect(group.element.hasAttribute("data-hf-group")).toBe(false);
|
|
234
|
+
act(() => hook().setActiveGroupElement(group.element));
|
|
235
|
+
const member = (await act(() =>
|
|
236
|
+
hook().resolveDomSelectionFromPreviewPoint(...client(1050, 650), {
|
|
237
|
+
activeGroupElement: group.element,
|
|
238
|
+
}),
|
|
239
|
+
))!;
|
|
240
|
+
expect(member.id).toBe("a");
|
|
241
|
+
expect(elementWithin(group.element, member.element)).toBe(true);
|
|
242
|
+
expect(elementWithin(member.element, group.element)).toBe(false);
|
|
243
|
+
act(() => hook().applyDomSelection(member));
|
|
244
|
+
expect(hook().activeGroupElement).toBe(group.element);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it("selects a timeline clip the frame knows only by its clip id", async () => {
|
|
248
|
+
const hook = renderSelection(opaqueFrame());
|
|
249
|
+
const clip = (id: string) => ({ id, key: `index.html:${id}:0` }) as unknown as TimelineElement;
|
|
250
|
+
await act(() => hook().handleTimelineElementSelect(clip("title")));
|
|
251
|
+
expect(hook().domEditSelection).toMatchObject({ id: "title" });
|
|
252
|
+
await act(() => hook().handleTimelineElementSelect(clip("note")));
|
|
253
|
+
expect(hook().domEditSelection).toMatchObject({ hfId: "note" });
|
|
254
|
+
await act(() => hook().handleTimelineElementSelect(clip("nowhere")));
|
|
255
|
+
expect(hook().domEditSelection).toBeNull();
|
|
256
|
+
const moved = { ...clip("title"), selector: "#renamed" } as TimelineElement;
|
|
257
|
+
await act(() => hook().handleTimelineElementSelect(moved));
|
|
258
|
+
expect(hook().domEditSelection).toBeNull();
|
|
259
|
+
});
|
|
260
|
+
});
|