@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.
Files changed (54) hide show
  1. package/dist/assets/hyperframes-player-VGx6ow_e.js +573 -0
  2. package/dist/assets/{index-tvLrzMBv.js → index-B8Xt_Oyw.js} +180 -180
  3. package/dist/assets/{index-CAjz3b83.js → index-BH18TdX9.js} +1 -1
  4. package/dist/assets/{pausedVideoDecoder-xC5IGkfB.js → pausedVideoDecoder-Bx3fGNkU.js} +1 -1
  5. package/dist/{chunk-VDDEXNVX.js → chunk-ESTBKVCB.js} +8 -0
  6. package/dist/index.html +1 -1
  7. package/dist/index.js +355 -142
  8. package/dist/player.js +1 -1
  9. package/package.json +8 -8
  10. package/src/captions/components/CaptionOverlay.sealed.test.ts +2 -25
  11. package/src/components/editor/LayersPanel.opaque.test.ts +4 -29
  12. package/src/components/editor/domEditOverlayCrop.ts +78 -15
  13. package/src/components/editor/domEditOverlayCropFrameLift.test.ts +64 -0
  14. package/src/components/editor/gsapMoveSealedPreview.test.ts +3 -23
  15. package/src/components/editor/previewDrafts.test.ts +13 -39
  16. package/src/components/editor/previewDrafts.ts +2 -0
  17. package/src/components/editor/previewGestureStartRead.test.ts +59 -21
  18. package/src/components/editor/previewGestureStartRead.ts +9 -0
  19. package/src/components/editor/previewLayers.test.ts +3 -20
  20. package/src/components/editor/previewOverlayRects.test.ts +3 -20
  21. package/src/components/editor/previewPointerTargets.test.ts +3 -20
  22. package/src/components/editor/previewSelection.test.ts +51 -35
  23. package/src/components/editor/previewSelection.ts +17 -0
  24. package/src/components/editor/useColorGradingController.sealed.test.ts +5 -30
  25. package/src/components/editor/useMotionPathData.sealed.test.ts +2 -29
  26. package/src/components/nle/NLEContext.drillDown.test.ts +85 -0
  27. package/src/components/nle/NLEContext.tsx +21 -23
  28. package/src/components/nle/NLEPreview.test.ts +18 -3
  29. package/src/components/nle/NLEPreview.tsx +10 -1
  30. package/src/components/nle/audioSealedPreview.test.ts +5 -32
  31. package/src/hooks/appHotkeysDispatch.ts +38 -1
  32. package/src/hooks/domEditCommits.sealed.test.ts +191 -0
  33. package/src/hooks/domStyleCommit.ts +18 -7
  34. package/src/hooks/gsapResizeIntercept.ts +7 -2
  35. package/src/hooks/useAppHotkeys.previewForwarding.test.tsx +134 -0
  36. package/src/hooks/useAppHotkeys.ts +36 -1
  37. package/src/hooks/useDomEditAttributeCommits.ts +43 -19
  38. package/src/hooks/useEnableKeyframes.sealed.test.ts +2 -29
  39. package/src/hooks/useSlideshowTabState.test.ts +47 -3
  40. package/src/hooks/useSlideshowTabState.ts +32 -16
  41. package/src/player/hooks/timelinePlayerTestHarness.ts +2 -1
  42. package/src/player/hooks/usePlaybackKeyboard.ts +1 -1
  43. package/src/player/hooks/useTimelineSyncCallbacks.sealed.test.ts +2 -29
  44. package/src/player/lib/previewChannel.test.ts +10 -0
  45. package/src/player/lib/previewChannel.ts +9 -0
  46. package/src/player/lib/previewElements.test.ts +34 -1
  47. package/src/player/lib/previewElements.ts +99 -16
  48. package/src/player/lib/sealedPreviewFrame.test-helpers.ts +38 -0
  49. package/src/player/lib/timelineIframeHelpers.ts +1 -1
  50. package/src/utils/blockInstaller.test.ts +82 -48
  51. package/src/utils/blockInstaller.ts +6 -14
  52. package/src/utils/previewCompositionSize.test.ts +61 -0
  53. package/src/utils/previewCompositionSize.ts +21 -1
  54. package/dist/assets/hyperframes-player-Dscc6yHD.js +0 -573
@@ -1,10 +1,10 @@
1
1
  // @vitest-environment happy-dom
2
2
 
3
3
  import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
4
- // The frame's real runtime agent, serving the opaque frame from this document.
5
- import { installMarkedEditingAgent } from "../../../../core/src/runtime/editingAgent.test-helpers";
4
+ import type { GsapAnimation } from "@hyperframes/core/gsap-parser";
6
5
  import { makeSelection } from "../../hooks/domSelectionTestHarness";
7
6
  import { computeDraggedGsapPosition } from "../../hooks/draggedGsapPosition";
7
+ import { tryGsapResizeIntercept } from "../../hooks/gsapResizeIntercept";
8
8
  import { watchPreviewFrame } from "../../player/lib/bridgePlayback";
9
9
  import { describePreviewElements, queryPreviewElements } from "../../player/lib/previewElements";
10
10
  import { detachedFakeIframe } from "../../player/hooks/timelinePlayerTestHarness";
@@ -15,9 +15,14 @@ import {
15
15
  createManualOffsetDragMember,
16
16
  restoreManualOffsetDragMembers,
17
17
  } from "./manualOffsetDrag";
18
- import { measurePreviewGestureStart, type PreviewGestureStart } from "./previewGestureStartRead";
18
+ import {
19
+ gestureStartLayout,
20
+ measurePreviewGestureStart,
21
+ type PreviewGestureStart,
22
+ } from "./previewGestureStartRead";
19
23
  import { standInFor } from "./previewSelection";
20
24
  import { collectSnapContext } from "./snapTargetCollection";
25
+ import { sealedPreviewFrame } from "../../player/lib/sealedPreviewFrame.test-helpers";
21
26
 
22
27
  const FIXTURE = `
23
28
  <div data-composition-id="main" data-width="1920" data-height="1080">
@@ -85,24 +90,8 @@ function liveFrame() {
85
90
 
86
91
  /** A frame Studio cannot read, whose runtime is the real editing agent over this document. */
87
92
  function opaqueFrame() {
88
- const frame: Record<string, unknown> = {};
89
- const iframe = sized(detachedFakeIframe(frame), [100, 50, 960, 540]) as HTMLIFrameElement;
90
- Object.defineProperty(iframe, "contentDocument", { value: null });
91
- Object.defineProperty(frame, "document", {
92
- get: () => {
93
- throw new DOMException("blocked", "SecurityError");
94
- },
95
- });
96
- const parent = {
97
- postMessage: (data: unknown, _origin: string, ports: MessagePort[]) =>
98
- window.dispatchEvent(
99
- new MessageEvent("message", { source: frame as unknown as Window, data, ports }),
100
- ),
101
- } as unknown as Window;
102
- const agent = installMarkedEditingAgent(parent);
103
- frame.postMessage = (data: unknown) =>
104
- window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
105
- closers.push(() => agent.dispose());
93
+ const { iframe: sealed, frame } = sealedPreviewFrame();
94
+ const iframe = sized(sealed, [100, 50, 960, 540]) as HTMLIFrameElement;
106
95
  watchPreviewFrame(iframe);
107
96
  window.dispatchEvent(
108
97
  new MessageEvent("message", {
@@ -266,3 +255,52 @@ describe("starting a gesture from what an opaque frame read", () => {
266
255
  restoreManualOffsetDragMembers(g.members);
267
256
  });
268
257
  });
258
+
259
+ describe("a resize in a preview Studio cannot script", () => {
260
+ it.each([-5, 1e-9, 1e9])("keeps no start box for a frame-reported width of %s", async (width) => {
261
+ const iframe = opaqueFrame();
262
+ Object.defineProperty(document.querySelector("#last"), "offsetWidth", {
263
+ value: width,
264
+ configurable: true,
265
+ });
266
+ const handle = (await queryPreviewElements(iframe, "#last"))!.matches[0]!.handle;
267
+ await measurePreviewGestureStart(iframe, overlayEl(), [handle]);
268
+ expect(gestureStartLayout(handle)).toBeNull();
269
+ });
270
+
271
+ it("scales from the box its gesture started from, not a 200 px fallback", async () => {
272
+ const iframe = opaqueFrame();
273
+ const handle = (await queryPreviewElements(iframe, "#last"))!.matches[0]!.handle;
274
+ const standIn = standInFor(iframe, (await describePreviewElements(iframe, [handle]))![0]!);
275
+ await measurePreviewGestureStart(iframe, overlayEl(), [handle]);
276
+ const scaleKeys = {
277
+ id: "#last-scale",
278
+ targetSelector: "#last",
279
+ propertyGroup: "scale",
280
+ method: "to",
281
+ properties: { scale: 1 },
282
+ position: 0,
283
+ resolvedStart: 0,
284
+ duration: 1,
285
+ keyframes: {
286
+ keyframes: [
287
+ { percentage: 0, properties: { scale: 1 } },
288
+ { percentage: 100, properties: { scale: 1 } },
289
+ ],
290
+ },
291
+ } as unknown as GsapAnimation;
292
+ const commitMutation = vi.fn();
293
+
294
+ await tryGsapResizeIntercept(
295
+ { ...makeSelection("last", standIn), handle },
296
+ { width: 240, height: 120 },
297
+ [scaleKeys],
298
+ iframe,
299
+ commitMutation,
300
+ );
301
+
302
+ const scales = JSON.stringify(commitMutation.mock.calls.map((call) => call[1]));
303
+ // It measured 120 x 60 at the press, so 240 x 120 is a scale of 2; the 200 px fallback gave 1.2.
304
+ expect(scales).toMatch(/"scale":2\b/);
305
+ });
306
+ });
@@ -20,6 +20,10 @@ export interface PreviewGestureStarts {
20
20
  snap: SnapContext;
21
21
  }
22
22
 
23
+ const startLayouts = new Map<string, PreviewGestureStart["layout"]>();
24
+
25
+ export const gestureStartLayout = (handle: string) => startLayouts.get(handle) ?? null;
26
+
23
27
  /** Everything a gesture on `handles` reads from the frame, in one request; null when it cannot answer. */
24
28
  export async function measurePreviewGestureStart(
25
29
  iframe: HTMLIFrameElement,
@@ -27,6 +31,11 @@ export async function measurePreviewGestureStart(
27
31
  handles: string[],
28
32
  ): Promise<PreviewGestureStarts | null> {
29
33
  const reply = await previewGestureStart(iframe, handles);
34
+ startLayouts.clear();
35
+ reply?.elements.forEach((start, i) => {
36
+ const { width = 0, height = 0 } = start?.layout ?? {};
37
+ if (width >= 1 && height >= 1) startLayouts.set(handles[i]!, { width, height });
38
+ });
30
39
  const scale = reply && computeOverlayRootScale(overlayEl, iframe, null);
31
40
  if (!reply || !scale) return null;
32
41
  const { iframeRect, overlayRect, rootScaleX: sx, rootScaleY: sy } = scale;
@@ -4,8 +4,6 @@ import { act, createElement, useRef } from "react";
4
4
  import { MAX_QUERY_MATCHES } from "@hyperframes/core/runtime/editing-port";
5
5
  import { createRoot } from "react-dom/client";
6
6
  import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
7
- // The frame's real runtime agent, serving the opaque frame from this document.
8
- import { installMarkedEditingAgent } from "../../../../core/src/runtime/editingAgent.test-helpers";
9
7
  import { installReactActEnvironment } from "../../hooks/domSelectionTestHarness";
10
8
  import { watchPreviewFrame } from "../../player/lib/bridgePlayback";
11
9
  import { getElementZIndex } from "../../player/lib/layerOrdering";
@@ -21,6 +19,7 @@ import { useMarqueeGestures } from "./marqueeCommit";
21
19
  import { collectPreviewLayerItems, layerDataAttribute } from "./previewLayers";
22
20
  import { findPreviewElementForSelection, resolvePreviewSelection } from "./previewSelection";
23
21
  import { isLayerDraggable } from "./useLayerDrag";
22
+ import { sealedPreviewFrame } from "../../player/lib/sealedPreviewFrame.test-helpers";
24
23
 
25
24
  installReactActEnvironment();
26
25
  HTMLElement.prototype.setPointerCapture ??= () => {};
@@ -83,24 +82,8 @@ function liveFrame() {
83
82
 
84
83
  /** A frame Studio cannot read, whose runtime is the real editing agent over this document. */
85
84
  function opaqueFrame() {
86
- const frame: Record<string, unknown> = {};
87
- const iframe = sized(detachedFakeIframe(frame), FRAME) as HTMLIFrameElement;
88
- Object.defineProperty(iframe, "contentDocument", { value: null });
89
- Object.defineProperty(frame, "document", {
90
- get: () => {
91
- throw new DOMException("blocked", "SecurityError");
92
- },
93
- });
94
- const parent = {
95
- postMessage: (data: unknown, _origin: string, ports: MessagePort[]) =>
96
- window.dispatchEvent(
97
- new MessageEvent("message", { source: frame as unknown as Window, data, ports }),
98
- ),
99
- } as unknown as Window;
100
- const agent = installMarkedEditingAgent(parent);
101
- frame.postMessage = (data: unknown) =>
102
- window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
103
- closers.push(() => agent.dispose());
85
+ const { iframe: sealed, frame } = sealedPreviewFrame();
86
+ const iframe = sized(sealed, FRAME) as HTMLIFrameElement;
104
87
  watchPreviewFrame(iframe);
105
88
  window.dispatchEvent(
106
89
  new MessageEvent("message", {
@@ -3,8 +3,6 @@
3
3
  import React, { act } from "react";
4
4
  import { createRoot } from "react-dom/client";
5
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 { installMarkedEditingAgent } from "../../../../core/src/runtime/editingAgent.test-helpers";
8
6
  import { makeSelection, installReactActEnvironment } from "../../hooks/domSelectionTestHarness";
9
7
  import { watchPreviewFrame } from "../../player/lib/bridgePlayback";
10
8
  import { queryPreviewElements } from "../../player/lib/previewElements";
@@ -14,6 +12,7 @@ import { orientedGroupAwareOverlayRect, type OverlayRect } from "./domEditOverla
14
12
  import type { UseDomEditOverlayGesturesOptions } from "./domEditOverlayGestures";
15
13
  import { createPreviewGestureStarts } from "./previewGestureStarts";
16
14
  import { useDomEditOverlayRects } from "./useDomEditOverlayRects";
15
+ import { sealedPreviewFrame } from "../../player/lib/sealedPreviewFrame.test-helpers";
17
16
 
18
17
  const frames = vi.hoisted(() => new Set<() => void>());
19
18
  vi.mock("./overlayFrameLoop", () => ({
@@ -117,24 +116,8 @@ function liveFrame() {
117
116
 
118
117
  /** A frame Studio cannot read, whose runtime is the real editing agent over this document. */
119
118
  function opaqueFrame() {
120
- const frame: Record<string, unknown> = {};
121
- const iframe = sized(detachedFakeIframe(frame), [100, 50, 960, 540]) as HTMLIFrameElement;
122
- Object.defineProperty(iframe, "contentDocument", { value: null });
123
- Object.defineProperty(frame, "document", {
124
- get: () => {
125
- throw new DOMException("blocked", "SecurityError");
126
- },
127
- });
128
- const parent = {
129
- postMessage: (data: unknown, _origin: string, ports: MessagePort[]) =>
130
- window.dispatchEvent(
131
- new MessageEvent("message", { source: frame as unknown as Window, data, ports }),
132
- ),
133
- } as unknown as Window;
134
- const agent = installMarkedEditingAgent(parent);
135
- frame.postMessage = (data: unknown) =>
136
- window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
137
- closers.push(() => agent.dispose());
119
+ const { iframe: sealed, frame } = sealedPreviewFrame();
120
+ const iframe = sized(sealed, [100, 50, 960, 540]) as HTMLIFrameElement;
138
121
  // The size the runtime posts for its composition, as Studio mirrors it.
139
122
  watchPreviewFrame(iframe);
140
123
  window.dispatchEvent(
@@ -3,8 +3,6 @@
3
3
  import React, { act } from "react";
4
4
  import { createRoot } from "react-dom/client";
5
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 { installMarkedEditingAgent } from "../../../../core/src/runtime/editingAgent.test-helpers";
8
6
  import {
9
7
  getAllPreviewTargetsFromPointer,
10
8
  getPreviewTargetFromPointer,
@@ -23,6 +21,7 @@ import { useDomSelection } from "../../hooks/useDomSelection";
23
21
  import { usePreviewInteraction } from "../../hooks/usePreviewInteraction";
24
22
  import { useCanvasContextMenuState } from "./useCanvasContextMenuState";
25
23
  import type { TimelineElement } from "../../player";
24
+ import { sealedPreviewFrame } from "../../player/lib/sealedPreviewFrame.test-helpers";
26
25
 
27
26
  installReactActEnvironment();
28
27
 
@@ -92,24 +91,8 @@ function liveFrame(): HTMLIFrameElement {
92
91
 
93
92
  /** A frame Studio cannot read, whose runtime is the real editing agent over this document. */
94
93
  function opaqueFrame(): HTMLIFrameElement {
95
- const frame: Record<string, unknown> = {};
96
- const iframe = sized(detachedFakeIframe(frame), FRAME) as HTMLIFrameElement;
97
- Object.defineProperty(iframe, "contentDocument", { value: null });
98
- Object.defineProperty(frame, "document", {
99
- get: () => {
100
- throw new DOMException("blocked", "SecurityError");
101
- },
102
- });
103
- const parent = {
104
- postMessage: (data: unknown, _origin: string, ports: MessagePort[]) =>
105
- window.dispatchEvent(
106
- new MessageEvent("message", { source: frame as unknown as Window, data, ports }),
107
- ),
108
- } as unknown as Window;
109
- const agent = installMarkedEditingAgent(parent);
110
- frame.postMessage = (data: unknown) =>
111
- window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
112
- closers.push(() => agent.dispose());
94
+ const { iframe: sealed } = sealedPreviewFrame();
95
+ const iframe = sized(sealed, FRAME) as HTMLIFrameElement;
113
96
  return iframe;
114
97
  }
115
98
 
@@ -4,8 +4,6 @@ import React, { act } from "react";
4
4
  import { createRoot } from "react-dom/client";
5
5
  import { afterEach, describe, expect, it, vi } from "vitest";
6
6
  import { EDITING_ELEMENT_HANDLE, MAX_ELEMENT_TEXT } from "@hyperframes/core/runtime/editing-port";
7
- // The frame's real runtime agent, serving the opaque frame from this document.
8
- import { installMarkedEditingAgent } from "../../../../core/src/runtime/editingAgent.test-helpers";
9
7
  import {
10
8
  findElementForSelection,
11
9
  findElementForTimelineElement,
@@ -13,6 +11,7 @@ import {
13
11
  type DomEditSelection,
14
12
  } from "./domEditing";
15
13
  import { setCompositionSourceMap } from "./domEditingDom";
14
+ import { dropElementCropLift, liftElementCrop, readElementCropInsets } from "./domEditOverlayCrop";
16
15
  import { domEditSelectionToFacts } from "./domEditingLayers";
17
16
  import {
18
17
  findPreviewElementForSelection,
@@ -29,6 +28,7 @@ import { detachedFakeIframe } from "../../player/hooks/timelinePlayerTestHarness
29
28
  import { installReactActEnvironment } from "../../hooks/domSelectionTestHarness";
30
29
  import { useDomSelection } from "../../hooks/useDomSelection";
31
30
  import type { TimelineElement } from "../../player";
31
+ import { sealedPreviewFrame } from "../../player/lib/sealedPreviewFrame.test-helpers";
32
32
 
33
33
  installReactActEnvironment();
34
34
 
@@ -52,29 +52,6 @@ function liveFrame(): HTMLIFrameElement {
52
52
  return iframe;
53
53
  }
54
54
 
55
- /** A frame Studio cannot read, whose runtime is the real editing agent over this document. */
56
- function opaqueFrame(): HTMLIFrameElement {
57
- const frame: Record<string, unknown> = {};
58
- const iframe = detachedFakeIframe(frame);
59
- Object.defineProperty(iframe, "contentDocument", { value: null });
60
- Object.defineProperty(frame, "document", {
61
- get: () => {
62
- throw new DOMException("blocked", "SecurityError");
63
- },
64
- });
65
- const parent = {
66
- postMessage: (data: unknown, _origin: string, ports: MessagePort[]) =>
67
- window.dispatchEvent(
68
- new MessageEvent("message", { source: frame as unknown as Window, data, ports }),
69
- ),
70
- } as unknown as Window;
71
- const agent = installMarkedEditingAgent(parent);
72
- frame.postMessage = (data: unknown) =>
73
- window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
74
- closers.push(() => agent.dispose());
75
- return iframe;
76
- }
77
-
78
55
  const CONTEXT: PreviewSelectionOptions = {
79
56
  activeCompositionPath: "index.html",
80
57
  isMasterView: false,
@@ -101,7 +78,7 @@ async function describedOnOpaque(iframe: HTMLIFrameElement, element: Element) {
101
78
  }
102
79
 
103
80
  async function bothPaths(element: HTMLElement, options: PreviewSelectionOptions = CONTEXT) {
104
- const opaque = opaqueFrame();
81
+ const opaque = sealedPreviewFrame().iframe;
105
82
  const live = await resolveDomEditSelection(element, options);
106
83
  const remote = await resolvePreviewSelection(
107
84
  opaque,
@@ -183,7 +160,7 @@ describe("opaque frame selections match same-origin ones", () => {
183
160
  it("follows a drilled-into group: its nested group, then its children, else the top level", async () => {
184
161
  document.body.innerHTML = FIXTURE;
185
162
  const member = document.querySelector<HTMLElement>("[data-hf-id=m1]")!;
186
- const opaque = opaqueFrame();
163
+ const opaque = sealedPreviewFrame().iframe;
187
164
  const described = await describedOnOpaque(opaque, member);
188
165
  const outerLive = document.querySelector<HTMLElement>('[data-hf-group="outer"]')!;
189
166
  const innerLive = document.querySelector<HTMLElement>('[data-hf-group="inner"]')!;
@@ -224,7 +201,11 @@ describe("opaque frame selections match same-origin ones", () => {
224
201
  ])("finds an element for a selection %s", async (_name, selection) => {
225
202
  document.body.innerHTML = FIXTURE;
226
203
  const live = findElementForSelection(document, selection, "index.html");
227
- const found = await findPreviewElementForSelection(opaqueFrame(), selection, "index.html");
204
+ const found = await findPreviewElementForSelection(
205
+ sealedPreviewFrame().iframe,
206
+ selection,
207
+ "index.html",
208
+ );
228
209
  expect(live === null ? null : nameOf(live)).toBe(found === null ? null : found && named(found));
229
210
  if (selection.selector !== ".missing" && selection.selector !== "p[")
230
211
  expect(live).not.toBeNull();
@@ -243,7 +224,11 @@ describe("opaque frame selections match same-origin ones", () => {
243
224
  document.body.innerHTML = FIXTURE;
244
225
  const options = { activeCompositionPath: "index.html", isMasterView };
245
226
  const live = findElementForTimelineElement(document, element, options);
246
- const found = await findPreviewElementForTimelineElement(opaqueFrame(), element, options);
227
+ const found = await findPreviewElementForTimelineElement(
228
+ sealedPreviewFrame().iframe,
229
+ element,
230
+ options,
231
+ );
247
232
  expect(live && nameOf(live)).toBe(expected);
248
233
  expect(found && named(found)).toBe(expected);
249
234
  });
@@ -268,7 +253,7 @@ describe("opaque frame selection handles", () => {
268
253
 
269
254
  it("builds nothing for a removed element, and finds nothing the runtime cannot name", async () => {
270
255
  document.body.innerHTML = FIXTURE;
271
- const opaque = opaqueFrame();
256
+ const opaque = sealedPreviewFrame().iframe;
272
257
  const locked = document.querySelector("#locked")!;
273
258
  const described = await describedOnOpaque(opaque, locked);
274
259
  // A description whose parent is not the element its runtime names as the parent.
@@ -300,7 +285,7 @@ describe("opaque frame selection handles", () => {
300
285
  it("says it cannot tell when a capped query does not reach the index", async () => {
301
286
  document.body.innerHTML = "<i class='n'></i>".repeat(2_049);
302
287
  const found = await findPreviewElementForSelection(
303
- opaqueFrame(),
288
+ sealedPreviewFrame().iframe,
304
289
  { selector: ".n", selectorIndex: 2_048 },
305
290
  "index.html",
306
291
  );
@@ -357,7 +342,7 @@ describe("opaque frame selections read only what arrived whole", () => {
357
342
 
358
343
  it("builds nothing when the frame cannot read computed styles or the composition root", async () => {
359
344
  document.body.innerHTML = FIXTURE;
360
- const opaque = opaqueFrame();
345
+ const opaque = sealedPreviewFrame().iframe;
361
346
  const locked = await describedOnOpaque(opaque, document.querySelector("#locked")!);
362
347
  const bg = await describedOnOpaque(opaque, document.querySelector("#bg")!);
363
348
  expect(await resolvePreviewSelection(opaque, bg, CONTEXT)).not.toBeNull();
@@ -419,7 +404,7 @@ describe("useDomSelection on an opaque frame", () => {
419
404
  it("selects a timeline clip, refreshes it, and drops it once the frame no longer has it", async () => {
420
405
  document.body.innerHTML = FIXTURE;
421
406
  const liveHook = renderSelection(liveFrame());
422
- const hook = renderSelection(opaqueFrame());
407
+ const hook = renderSelection(sealedPreviewFrame().iframe);
423
408
  await act(() => liveHook().handleTimelineElementSelect(clip("#locked")));
424
409
  await act(() => hook().handleTimelineElementSelect(clip("#locked")));
425
410
  const selected = hook().domEditSelection!;
@@ -438,7 +423,7 @@ describe("useDomSelection on an opaque frame", () => {
438
423
 
439
424
  it("re-finds every group member on refresh", async () => {
440
425
  document.body.innerHTML = FIXTURE;
441
- const hook = renderSelection(opaqueFrame());
426
+ const hook = renderSelection(sealedPreviewFrame().iframe);
442
427
  await act(() => hook().handleTimelineElementSelect(clip("#locked")));
443
428
  const first = hook().domEditSelection!;
444
429
  await act(() => hook().handleTimelineElementSelect(clip("#plain")));
@@ -454,7 +439,7 @@ describe("useDomSelection on an opaque frame", () => {
454
439
 
455
440
  it("leaves a group the user changed while its refresh was reading the frame", async () => {
456
441
  document.body.innerHTML = FIXTURE;
457
- const hook = renderSelection(opaqueFrame());
442
+ const hook = renderSelection(sealedPreviewFrame().iframe);
458
443
  await act(() => hook().handleTimelineElementSelect(clip("#plain")));
459
444
  const plain = hook().domEditSelection!;
460
445
  await act(() => hook().handleTimelineElementSelect(clip("#locked")));
@@ -479,3 +464,34 @@ describe("useDomSelection on an opaque frame", () => {
479
464
  expect(hook().domEditGroupSelections.map((s) => s.id)).toEqual(["scene"]);
480
465
  });
481
466
  });
467
+
468
+ describe("an opaque frame selection's crop", () => {
469
+ it("reads the clip-path the frame renders, as a scriptable frame's does", async () => {
470
+ document.body.innerHTML = FIXTURE;
471
+ const plain = document.querySelector<HTMLElement>("#plain")!;
472
+ plain.style.clipPath = "inset(10px 20px 30px 40px)";
473
+ const { live, remote } = await bothPaths(plain);
474
+
475
+ expect(readElementCropInsets(remote!.element)).toEqual(readElementCropInsets(live!.element));
476
+ expect(readElementCropInsets(remote!.element)).toMatchObject({
477
+ top: 10,
478
+ right: 20,
479
+ bottom: 30,
480
+ left: 40,
481
+ });
482
+ });
483
+
484
+ it("shows the element uncropped in the frame while selected, and crops it again after", async () => {
485
+ document.body.innerHTML = FIXTURE;
486
+ const plain = document.querySelector<HTMLElement>("#plain")!;
487
+ plain.style.clipPath = "inset(10px 20px 30px 40px)";
488
+ const { remote } = await bothPaths(plain);
489
+ const shown = () => window.getComputedStyle(plain).clipPath;
490
+
491
+ liftElementCrop(remote!.element);
492
+ await vi.waitFor(() => expect(shown()).toBe("none"));
493
+ expect(readElementCropInsets(remote!.element)).toMatchObject({ top: 10, left: 40 });
494
+ dropElementCropLift(remote!.element);
495
+ await vi.waitFor(() => expect(shown()).toBe("inset(10px 20px 30px 40px)"));
496
+ });
497
+ });
@@ -26,8 +26,10 @@ import {
26
26
  previewElementSelectorIndex,
27
27
  previewPointerTargets,
28
28
  previewElementSourceFile,
29
+ editPreviewElement,
29
30
  queryPreviewElements,
30
31
  type PreviewElement,
32
+ type PreviewElementEdit,
31
33
  } from "../../player/lib/previewElements";
32
34
  import { coversCompositionRoot } from "./domEditingRootLayer";
33
35
  import {
@@ -72,6 +74,7 @@ import {
72
74
  STUDIO_WIDTH_PROP,
73
75
  } from "./manualEditsTypes";
74
76
  import { rememberFrameTranslate, TRANSLATE_PX_PROPERTIES, translatePx } from "./plainTranslate";
77
+ import { rememberFrameClipPath } from "./domEditOverlayCrop";
75
78
 
76
79
  let inertDocument: Document | undefined;
77
80
  const inert = () => (inertDocument ??= document.implementation.createHTMLDocument(""));
@@ -354,6 +357,11 @@ export async function resolvePreviewSelection(
354
357
  ]);
355
358
  if (!styles) return null;
356
359
  // The stand-in has no box to size a % or em against: a move starts from what the frame renders.
360
+ rememberFrameClipPath(
361
+ element,
362
+ current.inlineStyles["clip-path"] ?? "",
363
+ styles["clip-path"] ?? "",
364
+ );
357
365
  rememberFrameTranslate(
358
366
  element,
359
367
  translatePx(styles.translate ?? "none", (p) => styles[p] ?? ""),
@@ -512,6 +520,15 @@ export async function findPointerTargets(
512
520
  return (described ?? []).filter((element) => element !== null);
513
521
  }
514
522
 
523
+ export function editSealedSelection(
524
+ iframe: HTMLIFrameElement | null | undefined,
525
+ selection: DomEditSelection,
526
+ edit: Parameters<typeof editPreviewElement>[2],
527
+ ): PreviewElementEdit | null {
528
+ if (!iframe || !selection.handle || !previewFrameOpaque(iframe)) return null;
529
+ return editPreviewElement(iframe, selection.handle, edit);
530
+ }
531
+
515
532
  /** A stand-in is never connected: an opaque frame's selection stands until it is replaced. */
516
533
  export const selectionElementLive = (selection: DomEditSelection) =>
517
534
  selection.handle !== undefined || selection.element.isConnected;
@@ -4,12 +4,10 @@ import React, { act } from "react";
4
4
  import { createRoot } from "react-dom/client";
5
5
  import { afterEach, describe, expect, it, vi } from "vitest";
6
6
  import { normalizeHfColorGrading } from "@hyperframes/core/color-grading";
7
- // The frame's real runtime agent, serving the opaque frame from this document.
8
- import { installMarkedEditingAgent } from "../../../../core/src/runtime/editingAgent.test-helpers";
9
7
  import { installReactActEnvironment } from "../../hooks/domSelectionTestHarness";
10
- import { detachedFakeIframe } from "../../player/hooks/timelinePlayerTestHarness";
11
8
  import type { DomEditSelection } from "./domEditing";
12
9
  import { useColorGradingController } from "./useColorGradingController";
10
+ import { sealedPreviewFrame } from "../../player/lib/sealedPreviewFrame.test-helpers";
13
11
 
14
12
  installReactActEnvironment();
15
13
 
@@ -20,29 +18,6 @@ afterEach(() => {
20
18
  document.body.innerHTML = "";
21
19
  });
22
20
 
23
- /** A frame Studio cannot read, whose runtime is the real editing agent over this document. */
24
- function opaqueFrame(): HTMLIFrameElement {
25
- const frame: Record<string, unknown> = {};
26
- const iframe = detachedFakeIframe(frame);
27
- Object.defineProperty(iframe, "contentDocument", { value: null });
28
- Object.defineProperty(frame, "document", {
29
- get: () => {
30
- throw new DOMException("blocked", "SecurityError");
31
- },
32
- });
33
- const parent = {
34
- postMessage: (data: unknown, _origin: string, ports: MessagePort[]) =>
35
- window.dispatchEvent(
36
- new MessageEvent("message", { source: frame as unknown as Window, data, ports }),
37
- ),
38
- } as unknown as Window;
39
- const agent = installMarkedEditingAgent(parent);
40
- frame.postMessage = (data: unknown) =>
41
- window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
42
- closers.push(() => agent.dispose());
43
- return iframe;
44
- }
45
-
46
21
  /** The frame's colour grading runtime, on the window the agent serves. */
47
22
  function installFrameGrading() {
48
23
  const stopPlayback = vi.fn();
@@ -109,7 +84,7 @@ const settle = (check: () => void) =>
109
84
  describe("grade preview sealed", () => {
110
85
  it("reads the frame's grading status over the editing port", async () => {
111
86
  const { grading } = installFrameGrading();
112
- const state = renderController(opaqueFrame());
87
+ const state = renderController(sealedPreviewFrame().iframe);
113
88
 
114
89
  await settle(() =>
115
90
  expect(state().runtimeStatus).toEqual({ state: "active", message: "Shader active" }),
@@ -119,7 +94,7 @@ describe("grade preview sealed", () => {
119
94
 
120
95
  it("draws preset cards the frame renders, and drops any that are not image data", async () => {
121
96
  const { grading } = installFrameGrading();
122
- const state = renderController(opaqueFrame());
97
+ const state = renderController(sealedPreviewFrame().iframe);
123
98
 
124
99
  act(() => state().requestPresetPreviews());
125
100
  await settle(() => expect(state().presetPreviews.images["bright-pop"]).toBeDefined());
@@ -135,7 +110,7 @@ describe("grade preview sealed", () => {
135
110
 
136
111
  it("plays the hovered card in the frame and stops it when the hover ends", async () => {
137
112
  const { grading, stopPlayback } = installFrameGrading();
138
- const state = renderController(opaqueFrame());
113
+ const state = renderController(sealedPreviewFrame().iframe);
139
114
  const look = normalizeHfColorGrading({ preset: "bright-pop", intensity: 1 })!;
140
115
 
141
116
  act(() =>
@@ -157,7 +132,7 @@ describe("grade preview sealed", () => {
157
132
 
158
133
  it("captures a graded frame from the frame", async () => {
159
134
  installFrameGrading();
160
- const state = renderController(opaqueFrame());
135
+ const state = renderController(sealedPreviewFrame().iframe);
161
136
 
162
137
  const frame = await act(() => state().captureGradedFrame());
163
138
  expect(frame).toEqual({ dataUrl: "data:image/png;base64,capture", width: 160, height: 90 });
@@ -2,16 +2,13 @@
2
2
  import { act, createElement, useRef } from "react";
3
3
  import { createRoot } from "react-dom/client";
4
4
  import { afterEach, beforeEach, 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
- import { detachedFakeIframe } from "../../player/hooks/timelinePlayerTestHarness";
8
5
  import { usePlayerStore } from "../../player/store/playerStore";
9
6
  import { resetOverlayFrameLoopForTests } from "./overlayFrameLoop";
10
7
  import { useMotionPathData } from "./useMotionPathData";
8
+ import { sealedPreviewFrame } from "../../player/lib/sealedPreviewFrame.test-helpers";
11
9
 
12
10
  Reflect.set(globalThis, "IS_REACT_ACT_ENVIRONMENT", true);
13
11
 
14
- const closers: Array<() => void> = [];
15
12
  const originalRaf = window.requestAnimationFrame;
16
13
  let frames: Array<() => void> = [];
17
14
  const runFrames = () =>
@@ -28,43 +25,19 @@ beforeEach(() => {
28
25
  usePlayerStore.setState({ previewBooted: true, motionPathArmed: true });
29
26
  });
30
27
  afterEach(() => {
31
- closers.splice(0).forEach((close) => close());
32
28
  resetOverlayFrameLoopForTests();
33
29
  window.requestAnimationFrame = originalRaf;
34
30
  usePlayerStore.setState({ previewBooted: false, motionPathArmed: false });
35
31
  document.body.innerHTML = "";
36
32
  });
37
33
 
38
- /** A frame Studio cannot read, whose runtime is the real editing agent over this document. */
39
- function opaqueFrame() {
40
- const frame: Record<string, unknown> = {};
41
- const iframe = detachedFakeIframe(frame);
42
- Object.defineProperty(iframe, "contentDocument", { value: null });
43
- Object.defineProperty(frame, "document", {
44
- get: () => {
45
- throw new DOMException("blocked", "SecurityError");
46
- },
47
- });
48
- const parent = {
49
- postMessage: (data: unknown, _origin: string, ports: MessagePort[]) =>
50
- window.dispatchEvent(
51
- new MessageEvent("message", { source: frame as unknown as Window, data, ports }),
52
- ),
53
- } as unknown as Window;
54
- const agent = installMarkedEditingAgent(parent);
55
- frame.postMessage = (data: unknown) =>
56
- window.dispatchEvent(new MessageEvent("message", { source: parent, data }));
57
- closers.push(() => agent.dispose());
58
- return iframe;
59
- }
60
-
61
34
  // fails without the fix: the hook read the layer from the frame's document, which a sealed frame keeps.
62
35
  it("finds a sealed preview's layer home, so its motion path draws from the layer", async () => {
63
36
  document.body.innerHTML = `<main data-composition-id="main"><div id="box"></div></main>`;
64
37
  const box = document.getElementById("box")!;
65
38
  const layout = { offsetLeft: 100, offsetTop: 50, offsetWidth: 200, offsetHeight: 100 };
66
39
  for (const [key, value] of Object.entries(layout)) Object.defineProperty(box, key, { value });
67
- const iframe = opaqueFrame();
40
+ const iframe = sealedPreviewFrame().iframe;
68
41
  let home: unknown = null;
69
42
  function Probe() {
70
43
  const ref = useRef(iframe);