@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.
Files changed (99) hide show
  1. package/dist/assets/hyperframes-player-VGx6ow_e.js +573 -0
  2. package/dist/assets/{index-CVmmHGol.js → index-B8Xt_Oyw.js} +190 -186
  3. package/dist/assets/{index-DN167Uqf.js → index-BH18TdX9.js} +1 -1
  4. package/dist/assets/{pausedVideoDecoder-C8rhpGPx.js → pausedVideoDecoder-Bx3fGNkU.js} +1 -1
  5. package/dist/{chunk-VDDEXNVX.js → chunk-ESTBKVCB.js} +8 -0
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.html +1 -1
  8. package/dist/index.js +1580 -882
  9. package/dist/player.js +1 -1
  10. package/package.json +8 -8
  11. package/src/captions/components/CaptionOverlay.sealed.test.ts +2 -25
  12. package/src/captions/hooks/useCaptionSync.ts +4 -1
  13. package/src/components/editor/LayersPanel.opaque.test.ts +4 -29
  14. package/src/components/editor/MotionPathOverlay.sealed.test.tsx +85 -0
  15. package/src/components/editor/MotionPathOverlay.tsx +26 -12
  16. package/src/components/editor/domEditOverlayCrop.ts +78 -15
  17. package/src/components/editor/domEditOverlayCropFrameLift.test.ts +64 -0
  18. package/src/components/editor/domEditOverlayStartGesture.ts +0 -14
  19. package/src/components/editor/gestureUndoRevert.ts +3 -6
  20. package/src/components/editor/gsapMoveSealedPreview.test.ts +247 -0
  21. package/src/components/editor/manualEditsSnapshot.ts +2 -0
  22. package/src/components/editor/manualOffsetDrag.ts +13 -18
  23. package/src/components/editor/plainTranslate.test.ts +22 -1
  24. package/src/components/editor/plainTranslate.ts +8 -6
  25. package/src/components/editor/previewDrafts.test.ts +13 -39
  26. package/src/components/editor/previewDrafts.ts +4 -0
  27. package/src/components/editor/previewGestureStartRead.test.ts +59 -32
  28. package/src/components/editor/previewGestureStartRead.ts +9 -0
  29. package/src/components/editor/previewLayers.test.ts +3 -20
  30. package/src/components/editor/previewOverlayRects.test.ts +3 -20
  31. package/src/components/editor/previewPointerTargets.test.ts +3 -20
  32. package/src/components/editor/previewSelection.test.ts +51 -35
  33. package/src/components/editor/previewSelection.ts +18 -0
  34. package/src/components/editor/useColorGradingController.sealed.test.ts +5 -30
  35. package/src/components/editor/useMotionPathData.reply.test.ts +40 -0
  36. package/src/components/editor/useMotionPathData.sealed.test.ts +57 -0
  37. package/src/components/editor/useMotionPathData.test.tsx +1 -1
  38. package/src/components/editor/useMotionPathData.ts +83 -33
  39. package/src/components/nle/CompositionBreadcrumb.tsx +2 -5
  40. package/src/components/nle/NLEContext.drillDown.test.ts +85 -0
  41. package/src/components/nle/NLEContext.tsx +21 -23
  42. package/src/components/nle/NLEPreview.test.ts +18 -3
  43. package/src/components/nle/NLEPreview.tsx +10 -1
  44. package/src/components/nle/audioSealedPreview.test.ts +5 -32
  45. package/src/components/panels/motionBlurPanelModel.sealed.test.ts +30 -0
  46. package/src/components/panels/motionBlurPanelModel.ts +37 -7
  47. package/src/hooks/appHotkeysDispatch.ts +38 -1
  48. package/src/hooks/domEditCommits.sealed.test.ts +191 -0
  49. package/src/hooks/domStyleCommit.ts +18 -7
  50. package/src/hooks/draggedGsapPosition.ts +20 -0
  51. package/src/hooks/gsapEditOutcome.ts +3 -0
  52. package/src/hooks/gsapFrameSnapshot.test.ts +113 -0
  53. package/src/hooks/gsapFrameSnapshot.ts +246 -0
  54. package/src/hooks/gsapParsedTween.ts +16 -9
  55. package/src/hooks/gsapResizeIntercept.ts +7 -2
  56. package/src/hooks/gsapRuntimeBridge.ts +4 -0
  57. package/src/hooks/gsapRuntimeKeyframes.ts +23 -15
  58. package/src/hooks/gsapShared.ts +4 -0
  59. package/src/hooks/gsapSnapshotReply.ts +105 -0
  60. package/src/hooks/useAppHotkeys.previewForwarding.test.tsx +134 -0
  61. package/src/hooks/useAppHotkeys.ts +36 -1
  62. package/src/hooks/useDomEditAttributeCommits.ts +43 -19
  63. package/src/hooks/useDomEditCommits.test.tsx +1 -1
  64. package/src/hooks/useDomEditPreviewSync.test.ts +36 -1
  65. package/src/hooks/useDomEditPreviewSync.ts +3 -3
  66. package/src/hooks/useEditorSave.ts +2 -1
  67. package/src/hooks/useEnableKeyframes.sealed.test.ts +70 -0
  68. package/src/hooks/useEnableKeyframes.ts +9 -2
  69. package/src/hooks/useGsapTweenCache.ts +9 -3
  70. package/src/hooks/usePreviewPersistence.ts +18 -11
  71. package/src/hooks/useSdkSession.lifecycle.test.tsx +1 -0
  72. package/src/hooks/useSdkSession.ts +2 -0
  73. package/src/hooks/useSlideshowTabState.test.ts +47 -3
  74. package/src/hooks/useSlideshowTabState.ts +32 -16
  75. package/src/player/hooks/timelinePlayerTestHarness.ts +2 -1
  76. package/src/player/hooks/usePlaybackKeyboard.ts +1 -1
  77. package/src/player/hooks/useTimelineSyncCallbacks.sealed.test.ts +2 -29
  78. package/src/player/lib/previewChannel.test.ts +10 -0
  79. package/src/player/lib/previewChannel.ts +9 -0
  80. package/src/player/lib/previewElements.test.ts +34 -1
  81. package/src/player/lib/previewElements.ts +101 -18
  82. package/src/player/lib/sealedPreviewFrame.test-helpers.ts +38 -0
  83. package/src/player/lib/timelineIframeHelpers.ts +1 -1
  84. package/src/telemetry/client.ts +4 -2
  85. package/src/telemetry/eventShape.test.ts +189 -0
  86. package/src/telemetry/eventShape.ts +192 -0
  87. package/src/utils/blockInstaller.test.ts +82 -48
  88. package/src/utils/blockInstaller.ts +6 -14
  89. package/src/utils/domEditSaveQueue.test.ts +12 -2
  90. package/src/utils/domEditSaveQueue.ts +4 -4
  91. package/src/utils/previewCompositionSize.test.ts +61 -0
  92. package/src/utils/previewCompositionSize.ts +21 -1
  93. package/src/utils/sdkEditTransaction.ts +6 -2
  94. package/src/utils/sdkResolverShadow.ts +16 -15
  95. package/src/utils/studioSaveDiagnostics.test.ts +21 -3
  96. package/src/utils/studioSaveDiagnostics.ts +71 -6
  97. package/src/utils/studioTelemetry.ts +6 -1
  98. package/dist/assets/hyperframes-player-mSF_GvRs.js +0 -573
  99. package/src/components/editor/motionPathHome.ts +0 -75
package/dist/player.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Player
3
- } from "./chunk-VDDEXNVX.js";
3
+ } from "./chunk-ESTBKVCB.js";
4
4
  import "./chunk-JTUKMELR.js";
5
5
  import "./chunk-YQ3ZAXXY.js";
6
6
  import "./chunk-MLKGABMK.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/studio",
3
- "version": "0.9.64",
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.64",
68
- "@hyperframes/parsers": "0.9.64",
69
- "@hyperframes/player": "0.9.64",
70
- "@hyperframes/sdk": "0.9.64",
71
- "@hyperframes/studio-server": "0.9.64",
72
- "@hyperframes/shader-transitions": "0.9.64"
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.64"
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 { detachedFakeIframe } from "../../player/hooks/timelinePlayerTestHarness";
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 parent = {
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. */
@@ -118,7 +118,10 @@ export function useCaptionSync(projectId: string | null) {
118
118
  .catch((error: unknown) => {
119
119
  // Caption auto-save is a data-loss path: surface it to the user, not
120
120
  // just telemetry. pendingRef stays true so beforeunload still warns.
121
- trackEvent("studio_caption_autosave_failed", { error: String(error) });
121
+ trackEvent("studio_caption_autosave_failed", {
122
+ error_name: error instanceof Error ? error.name : typeof error,
123
+ error: String(error),
124
+ });
122
125
  useCaptionStore.getState().setSyncError(held ?? "Caption changes couldn't be saved");
123
126
  });
124
127
  }, []);
@@ -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 = opaqueFrame();
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 = opaqueFrame();
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 = opaqueFrame();
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.
@@ -0,0 +1,85 @@
1
+ // @vitest-environment jsdom
2
+ import { act } from "react";
3
+ import { createRoot } from "react-dom/client";
4
+ import { expect, it, vi } from "vitest";
5
+ import { MotionPathOverlay } from "./MotionPathOverlay";
6
+ import { usePlayerStore } from "../../player/store/playerStore";
7
+ import { usePreviewIframeStore } from "../../player/store/previewIframeStore";
8
+ import type { DomEditSelection } from "./domEditing";
9
+ import { commitCreatePath } from "./motionPathCommit";
10
+
11
+ Reflect.set(globalThis, "IS_REACT_ACT_ENVIRONMENT", true);
12
+
13
+ const POLLED = { x: 0, y: 0, w: 100, h: 50, ax: 0.5, ay: 0.5 };
14
+ const AT_CLICK = { x: 500, y: 300, w: 100, h: 50, ax: 0.5, ay: 0.5 };
15
+
16
+ vi.mock("../../contexts/DomEditContext", () => ({
17
+ useDomEditContext: () => ({ selectedGsapAnimations: [] }),
18
+ }));
19
+ vi.mock("../../player/lib/previewChannel", async (importOriginal) => ({
20
+ ...(await importOriginal<typeof import("../../player/lib/previewChannel")>()),
21
+ previewFrameOpaque: () => true,
22
+ }));
23
+ vi.mock("./motionPathCommit", async (importOriginal) => ({
24
+ ...(await importOriginal<typeof import("./motionPathCommit")>()),
25
+ commitCreatePath: vi.fn(),
26
+ }));
27
+ vi.mock("./motionPathSelection", () => ({
28
+ selectorFor: () => "#box",
29
+ editableAnimationId: () => null,
30
+ }));
31
+ vi.mock("./useMotionPathData", async (importOriginal) => ({
32
+ ...(await importOriginal<typeof import("./useMotionPathData")>()),
33
+ hasMotionPathPlugin: () => true,
34
+ sealedMotionPathHome: vi.fn(async () => ({
35
+ home: AT_CLICK,
36
+ perspective: 1,
37
+ visible: true,
38
+ plugin: true,
39
+ })),
40
+ useMotionPathData: () => ({
41
+ rect: { left: 0, top: 0, width: 1920, height: 1080 },
42
+ geometry: null,
43
+ geometryResolved: true,
44
+ visibleInPreview: true,
45
+ home: POLLED,
46
+ pScale: 1,
47
+ }),
48
+ }));
49
+
50
+ // fails without the fix: a sealed click placed the path from the last poll's home, maybe the previous playhead's.
51
+ it("places a sealed preview's new path from the layer's home read at the click", async () => {
52
+ const host = document.createElement("div");
53
+ const surface = document.createElement("div");
54
+ surface.setAttribute("data-preview-pan-surface", "");
55
+ const frame = document.createElement("iframe");
56
+ document.body.append(host, surface, frame);
57
+ frame.getBoundingClientRect = () => new DOMRect(0, 0, 1920, 1080);
58
+ const root = createRoot(host);
59
+ const selection = { element: document.createElement("div") } as unknown as DomEditSelection;
60
+ try {
61
+ act(() => usePreviewIframeStore.getState().setIframe(frame));
62
+ act(() =>
63
+ root.render(
64
+ <MotionPathOverlay
65
+ iframeRef={{ current: frame }}
66
+ selection={selection}
67
+ compositionSize={{ width: 1920, height: 1080 }}
68
+ isPlaying={false}
69
+ />,
70
+ ),
71
+ );
72
+ act(() => usePlayerStore.getState().setMotionPathArmed(true));
73
+ const press = { bubbles: true, button: 0, clientX: 600, clientY: 400 };
74
+ await act(async () => void surface.dispatchEvent(new PointerEvent("pointerdown", press)));
75
+
76
+ expect(vi.mocked(commitCreatePath).mock.calls[0]?.slice(0, 4)).toEqual(["#box", 0, 100, 100]);
77
+ } finally {
78
+ act(() => usePlayerStore.getState().setMotionPathArmed(false));
79
+ act(() => root.unmount());
80
+ usePreviewIframeStore.setState({ iframe: null });
81
+ host.remove();
82
+ surface.remove();
83
+ frame.remove();
84
+ }
85
+ });
@@ -7,7 +7,12 @@ import { useGsapInteractionFailureTelemetry } from "../../hooks/useGsapInteracti
7
7
  import { usePlayerStore } from "../../player/store/playerStore";
8
8
  import { useLivePreviewIframe } from "../../player/store/previewIframeStore";
9
9
  import { parkPlayheadOnKeyframe } from "../../hooks/gsapDragCommit";
10
- import { nearestPointOnPath, nodeCentre, type MotionNodeRef } from "./motionPathGeometry";
10
+ import {
11
+ nearestPointOnPath,
12
+ nodeCentre,
13
+ type MotionNodeRef,
14
+ type MotionPathHome,
15
+ } from "./motionPathGeometry";
11
16
  import { editableAnimationId, selectorFor } from "./motionPathSelection";
12
17
  import { controlForNode, controlUnder, pressControl } from "./motionPathLayerNode";
13
18
  import { readGsapPositionFromIframe } from "../../hooks/gsapPositionDetection";
@@ -26,8 +31,9 @@ import {
26
31
  commitRemoveWaypoint,
27
32
  nodeDropLabel,
28
33
  } from "./motionPathCommit";
29
- import { elementHome } from "./motionPathHome";
30
- import { hasMotionPathPlugin, transformWDivisor, useMotionPathData } from "./useMotionPathData";
34
+ import { elementHome, transformWDivisor } from "@hyperframes/core/runtime/editing-port";
35
+ import { hasMotionPathPlugin, sealedMotionPathHome, useMotionPathData } from "./useMotionPathData";
36
+ import { previewFrameOpaque } from "../../player/lib/previewChannel";
31
37
 
32
38
  interface MotionPathOverlayProps {
33
39
  iframeRef: RefObject<HTMLIFrameElement | null>;
@@ -196,20 +202,28 @@ export const MotionPathOverlay = memo(function MotionPathOverlay({
196
202
  }
197
203
  // Resolve the element LIVE from the current iframe document — the selected
198
204
  // node may be detached after a soft-reload, which would skew home.
199
- const live = frame.contentDocument?.querySelector(createSelector);
200
- if (!isHtmlElement(live)) return;
205
+ const sealed = previewFrameOpaque(frame);
206
+ const live = sealed ? null : frame.contentDocument?.querySelector(createSelector);
207
+ if (!isHtmlElement(live) && !(sealed && home)) return;
201
208
  e.stopPropagation();
202
209
  e.preventDefault();
203
210
  const sc = r.width / compW;
204
- const elHome = elementHome(live);
211
+ const t = Math.round(usePlayerStore.getState().currentTime * 100) / 100;
205
212
  // De-magnify: the click lands on the projected (1/m44-magnified) path, so
206
213
  // divide the home-relative offset by the perspective factor to recover the
207
214
  // stored composition offset (inverse of the `* pScale` applied at draw).
208
- const ps = 1 / transformWDivisor(live);
209
- const px = Math.round(((e.clientX - r.left) / sc - elHome.x) / ps);
210
- const py = Math.round(((e.clientY - r.top) / sc - elHome.y) / ps);
211
- const t = Math.round(usePlayerStore.getState().currentTime * 100) / 100;
212
- void commitCreatePath(createSelector, t, px, py, commitMutation);
215
+ const place = (elHome: MotionPathHome, ps: number) => {
216
+ const px = Math.round(((e.clientX - r.left) / sc - elHome.x) / ps);
217
+ const py = Math.round(((e.clientY - r.top) / sc - elHome.y) / ps);
218
+ void commitCreatePath(createSelector, t, px, py, commitMutation);
219
+ };
220
+ if (isHtmlElement(live)) place(elementHome(live), 1 / transformWDivisor(live));
221
+ else {
222
+ // A frame that cannot answer at the click falls back to the polled home, which may be a seek behind.
223
+ void sealedMotionPathHome(frame, createSelector).then((read) =>
224
+ place(read?.home ?? home!, read?.home ? read.perspective : pScale),
225
+ );
226
+ }
213
227
  setMotionPathArmed(false);
214
228
  };
215
229
  surface.addEventListener("pointerdown", onDown, true);
@@ -217,7 +231,7 @@ export const MotionPathOverlay = memo(function MotionPathOverlay({
217
231
  surface.removeEventListener("pointerdown", onDown, true);
218
232
  surface.style.cursor = prevCursor;
219
233
  };
220
- }, [armed, createSelector, compW, iframeRef, commitMutation, setMotionPathArmed]);
234
+ }, [armed, createSelector, compW, iframeRef, commitMutation, setMotionPathArmed, home, pScale]);
221
235
 
222
236
  if (!rect || rect.width <= 0 || !compositionSize || compositionSize.width <= 0) return null;
223
237
  // Hide the whole overlay (path + create hint) when the element isn't painted —
@@ -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
- const cropLifts = new WeakMap<HTMLElement, { rule: HTMLStyleElement; sheetClip?: string }>();
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)?.rule.remove();
62
- cropLifts.delete(element);
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
- return cropLifts.has(element);
111
+ const lift = cropLifts.get(element);
112
+ return !!lift && !lift.dropped;
67
113
  }
68
114
 
69
- const computedClipPath = (element: HTMLElement) =>
70
- element.ownerDocument.defaultView?.getComputedStyle(element).clipPath.trim() || "";
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
- /** The element's clip-path, inline first, then the stylesheet's as it is without the lift. */
73
- function readElementClipPath(element: HTMLElement): string {
74
- const inline = element.style.getPropertyValue("clip-path").trim();
75
- const lift = cropLifts.get(element);
76
- if (inline || !lift) return inline || computedClipPath(element);
77
- // Only inline writes happen while selected, so the stylesheet's clip is read once per lift.
78
- if (lift.sheetClip === undefined) {
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
- return parseInsetClipPathSides(value);
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
+ });
@@ -35,7 +35,6 @@ import {
35
35
  type UseDomEditOverlayGesturesOptions,
36
36
  } from "./domEditOverlayGestures";
37
37
  import { collectSnapContext, buildExcludeElements, type SnapContext } from "./snapTargetCollection";
38
- import { MOVING_LAYER_UNREADABLE } from "./plainTranslate";
39
38
  import type { PreviewGestureStart } from "./previewGestureStartRead";
40
39
  import { editsPlainCss } from "../../hooks/gsapRuntimeKeyframes";
41
40
  import { logResize, resetResizeMoveLog } from "../../utils/resizeDebug";
@@ -68,14 +67,6 @@ export function startGroupDrag(
68
67
  notifyBlockedPress(e, opts, blockedSelection);
69
68
  return false;
70
69
  }
71
- const moving = items.find((item) => item.start?.gsap?.moving)?.selection;
72
- if (moving) {
73
- e.preventDefault();
74
- e.stopPropagation();
75
- opts.onBlockedMoveRef.current(moving, MOVING_LAYER_UNREADABLE);
76
- return false;
77
- }
78
-
79
70
  opts.onManualDragStartRef.current?.();
80
71
  const dragItems = filterNestedDomEditGroupItems(items);
81
72
  const members: ManualOffsetDragMember[] = [];
@@ -212,11 +203,6 @@ export function startGesture(
212
203
  let pathOffsetMember: ManualOffsetDragMember | undefined;
213
204
 
214
205
  if (kind === "drag") {
215
- if (start?.gsap?.moving) {
216
- opts.onBlockedMoveRef.current(sel, MOVING_LAYER_UNREADABLE);
217
- e.preventDefault();
218
- return false;
219
- }
220
206
  opts.onManualDragStartRef.current?.();
221
207
  const result = createManualOffsetDragMember({
222
208
  key: selectionCacheKey(sel),
@@ -6,11 +6,8 @@ import {
6
6
  } from "./manualEdits";
7
7
  import { readTranslatePx } from "./plainTranslate";
8
8
  import { drawPreviewDraft } from "./previewDrafts";
9
- import {
10
- getOffsetDragGsap,
11
- stampGestureBase,
12
- type ManualOffsetDragMember,
13
- } from "./manualOffsetDrag";
9
+ import { getOffsetDragGsap, type ManualOffsetDragMember } from "./manualOffsetDrag";
10
+ import { stampGestureBase } from "../../hooks/draggedGsapPosition";
14
11
  import type { StudioEditRevert } from "../../utils/studioPendingEdits";
15
12
 
16
13
  interface MemberPosition {
@@ -49,7 +46,7 @@ function showMemberPosition(member: ManualOffsetDragMember, position: MemberPosi
49
46
  if (position.gsap) getOffsetDragGsap(member.element)?.set(member.element, { ...position.gsap });
50
47
  // The restore drops the gesture's base stamps; its save still reads them.
51
48
  if (!member.plainTranslate)
52
- stampGestureBase(member.element, member.initialOffset, member.baseGsap);
49
+ stampGestureBase(member.element, member.initialOffset, member.baseGsap, !!member.moving);
53
50
  }
54
51
 
55
52
  function redrawMemberOnFrame(member: ManualOffsetDragMember): void {