@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
@@ -0,0 +1,247 @@
1
+ // @vitest-environment happy-dom
2
+
3
+ import { gsap } from "gsap";
4
+ import { parseGsapScriptAcorn } from "@hyperframes/parsers/gsap-parser-acorn";
5
+ import { afterEach, expect, it, vi } from "vitest";
6
+ import { makeSelection } from "../../hooks/domSelectionTestHarness";
7
+ import { freezeDragStamp } from "../../hooks/draggedGsapPosition";
8
+ import { settleGsapSnapshot } from "../../hooks/gsapFrameSnapshot";
9
+ import { tryGsapDragIntercept } from "../../hooks/gsapRuntimeBridge";
10
+ import { watchPreviewFrame } from "../../player/lib/bridgePlayback";
11
+ import { describePreviewElements, queryPreviewElements } from "../../player/lib/previewElements";
12
+ import { usePlayerStore } from "../../player/store/playerStore";
13
+ import type { UseDomEditOverlayGesturesOptions } from "./domEditOverlayGestures";
14
+ import { startGesture } from "./domEditOverlayStartGesture";
15
+ import {
16
+ applyManualOffsetDragCommit,
17
+ applyManualOffsetDragDraft,
18
+ endManualOffsetDragMembers,
19
+ } from "./manualOffsetDrag";
20
+ import { measurePreviewGestureStart } from "./previewGestureStartRead";
21
+ import { standInFor } from "./previewSelection";
22
+ import { sealedPreviewFrame } from "../../player/lib/sealedPreviewFrame.test-helpers";
23
+
24
+ const timeline = (tweens: string) => `var tl = gsap.timeline({ paused: true });
25
+ ${tweens}
26
+ window.__timelines["main"] = tl;`;
27
+ const MOVES_BOX = `tl.to("#box", { x: 200, y: 80, duration: 1, ease: "none" }, 0);`;
28
+ const SCRIPT = timeline(MOVES_BOX);
29
+ // Split-text output: more tween targets than the frame's GSAP snapshot carries, so Studio gets none.
30
+ const SPLIT_TEXT = `tl.to(".c", { opacity: 0, stagger: 0.001 }, 0);`;
31
+ const SPANS = '<span class="c"></span>'.repeat(600);
32
+
33
+ /** Frame px of a translate the draft drew, e.g. "calc(0px + 20px) calc(0px + 0px)". */
34
+ const drawnTranslate = (box: HTMLElement) =>
35
+ box.style.translate
36
+ .split(/ (?![^(]*\))/)
37
+ .map((axis) =>
38
+ [...axis.matchAll(/-?[\d.]+px/g)].reduce((sum, [px]) => sum + Number.parseFloat(px), 0),
39
+ );
40
+
41
+ /** Where the box is drawn in the frame: the translate GSAP's transform starts with, plus any translate on top. */
42
+ function drawnAt(box: HTMLElement) {
43
+ const [tx = 0, ty = 0] = drawnTranslate(box);
44
+ const [gx = 0, gy = 0] = (/translate(?:3d)?\(([^)]*)\)/.exec(box.style.transform)?.[1] ?? "")
45
+ .split(",")
46
+ .map((part) => Number.parseFloat(part) || 0);
47
+ return { x: gx + tx, y: gy + ty };
48
+ }
49
+
50
+ const mainTimeline = () =>
51
+ (window as unknown as { __timelines?: Record<string, gsap.core.Timeline> }).__timelines?.main;
52
+
53
+ function mount(script: string, extra = "") {
54
+ document.body.innerHTML = `<div data-composition-id="main" data-width="1920" data-height="1080"><div id="box"></div>${extra}</div>`;
55
+ const box = document.getElementById("box")!;
56
+ box.getBoundingClientRect = () => {
57
+ const { x, y } = drawnAt(box);
58
+ return {
59
+ x: 300 + x,
60
+ y: 200 + y,
61
+ width: 100,
62
+ height: 50,
63
+ left: 300 + x,
64
+ top: 200 + y,
65
+ } as DOMRect;
66
+ };
67
+ Object.defineProperty(box, "offsetWidth", { value: 100 });
68
+ Object.defineProperty(box, "offsetHeight", { value: 50 });
69
+ Object.assign(window, { gsap, __timelines: {} });
70
+ new Function("gsap", "window", script)(gsap, window);
71
+ // The preview paused half way through the tween: GSAP has the box at 100, 40.
72
+ mainTimeline()?.seek(0.5);
73
+ usePlayerStore.setState({ currentTime: 0.5, isPlaying: false, autoKeyframeEnabled: true });
74
+ }
75
+ afterEach(() => {
76
+ mainTimeline()?.kill();
77
+ document.body.innerHTML = "";
78
+ for (const name of ["gsap", "__timelines"]) Reflect.deleteProperty(window, name);
79
+ usePlayerStore.setState({ currentTime: 0, isPlaying: false });
80
+ });
81
+
82
+ function sized<T extends Element>(element: T, [x, y, width, height]: number[]): T {
83
+ element.getBoundingClientRect = () =>
84
+ ({ x, y, width, height, left: x, top: y, right: x + width, bottom: y + height }) as DOMRect;
85
+ return element;
86
+ }
87
+
88
+ /** A frame Studio cannot read, whose runtime is the real editing agent over this document. */
89
+ function opaqueFrame() {
90
+ const { iframe: sealed, frame } = sealedPreviewFrame();
91
+ const iframe = sized(sealed, [100, 50, 960, 540]) as HTMLIFrameElement;
92
+ watchPreviewFrame(iframe);
93
+ window.dispatchEvent(
94
+ new MessageEvent("message", {
95
+ source: frame as unknown as Window,
96
+ origin: window.location.origin,
97
+ data: { source: "hf-preview", type: "stage-size", width: 1920, height: 1080 },
98
+ }),
99
+ );
100
+ return iframe;
101
+ }
102
+
103
+ function gestureOpts(iframe: HTMLIFrameElement) {
104
+ const ref = <T>(current: T) => ({ current });
105
+ const overlayEl = sized(document.createElement("div"), [20, 10, 1200, 800]);
106
+ return {
107
+ selectionRef: ref(null),
108
+ overlayRectRef: ref(null),
109
+ boxRef: ref(document.createElement("div")),
110
+ overlayRef: ref(overlayEl),
111
+ iframeRef: ref(iframe),
112
+ gestureRef: ref(null),
113
+ groupGestureRef: ref(null),
114
+ groupOverlayItemsRef: ref([]),
115
+ rafPausedRef: ref(false),
116
+ onManualDragStartRef: ref(vi.fn()),
117
+ onBlockedMoveRef: ref(vi.fn()),
118
+ } as unknown as UseDomEditOverlayGesturesOptions;
119
+ }
120
+
121
+ const press = () =>
122
+ ({
123
+ clientX: 10,
124
+ clientY: 10,
125
+ pointerId: 1,
126
+ button: 0,
127
+ preventDefault() {},
128
+ stopPropagation() {},
129
+ currentTarget: { setPointerCapture() {} },
130
+ }) as unknown as React.PointerEvent<HTMLElement>;
131
+
132
+ /** Presses the box on a sealed frame, drags it 10 page px right and lets go, as the overlay does. */
133
+ async function dragBoxOnSealedFrame(
134
+ script: string,
135
+ beforePress?: (iframe: HTMLIFrameElement) => void,
136
+ ) {
137
+ const box = document.getElementById("box")!;
138
+ const iframe = opaqueFrame();
139
+ beforePress?.(iframe);
140
+ const handle = (await queryPreviewElements(iframe, "#box"))!.matches[0]!.handle;
141
+ const standIn = standInFor(iframe, (await describePreviewElements(iframe, [handle]))![0]!);
142
+ const selection = { ...makeSelection("box", standIn), id: "box", handle };
143
+ const opts = gestureOpts(iframe);
144
+ const read = await measurePreviewGestureStart(iframe, opts.overlayRef.current!, [handle]);
145
+ const { rect, start } = read!.elements[0]!;
146
+ const started = startGesture("drag", press(), opts, { selection, rect, start, snap: read!.snap });
147
+ expect(opts.onBlockedMoveRef.current).not.toHaveBeenCalled();
148
+ const member = opts.gestureRef.current!.pathOffsetMember!;
149
+
150
+ // A page px is two frame px: the frame shows 1920 px in 960.
151
+ applyManualOffsetDragDraft(member, 10, 0);
152
+ await vi.waitFor(() => expect(drawnAt(box)).toEqual({ x: 120, y: 40 }));
153
+
154
+ const offset = applyManualOffsetDragCommit(member, 10, 0);
155
+ const commit = vi.fn(async () => undefined);
156
+ const [anim] = parseGsapScriptAcorn(script).animations;
157
+ const outcome = await tryGsapDragIntercept(
158
+ selection,
159
+ offset,
160
+ [anim!],
161
+ iframe,
162
+ commit,
163
+ undefined,
164
+ {
165
+ stamp: freezeDragStamp(standIn),
166
+ },
167
+ );
168
+ endManualOffsetDragMembers([member]);
169
+ return { started, start, anim: anim!, outcome, commit };
170
+ }
171
+
172
+ // fails without the fix: a sealed preview refused to drag a layer its animation moves.
173
+ it("drags a layer its tween moves in a sealed preview: it moves live and saves a keyframe there", async () => {
174
+ mount(SCRIPT);
175
+ const { started, start, anim, outcome, commit } = await dragBoxOnSealedFrame(SCRIPT);
176
+
177
+ expect(start.gsap).toEqual({ x: 100, y: 40, moving: true });
178
+ expect(started).toBe(true);
179
+ expect(outcome).toEqual({ status: "persisted" });
180
+ expect(commit).toHaveBeenCalledTimes(1);
181
+ // The keyframe a same-origin preview writes for the same move: GSAP's 100, 40 plus the drag's 20.
182
+ expect(commit.mock.calls[0]![1]).toEqual({
183
+ type: "replace-with-keyframes",
184
+ animationId: anim.id,
185
+ targetSelector: "#box",
186
+ position: 0,
187
+ duration: 1,
188
+ keyframes: [
189
+ { percentage: 50, properties: { x: 120, y: 40 } },
190
+ { percentage: 100, properties: { x: 200, y: 80 } },
191
+ ],
192
+ easeEach: "none",
193
+ });
194
+ });
195
+
196
+ it("saves the keyframe of a drag pressed right after two quick seeks", async () => {
197
+ mount(SCRIPT);
198
+ const seek = (time: number) => {
199
+ mainTimeline()?.seek(time);
200
+ usePlayerStore.setState({ currentTime: time });
201
+ };
202
+ const { outcome, commit } = await dragBoxOnSealedFrame(SCRIPT, (iframe) => {
203
+ seek(0.3);
204
+ void settleGsapSnapshot(iframe);
205
+ seek(0.4);
206
+ seek(0.5);
207
+ });
208
+
209
+ expect(outcome).toEqual({ status: "persisted" });
210
+ expect(commit.mock.calls.map(([, mutation]) => mutation)).toMatchObject([
211
+ {
212
+ type: "replace-with-keyframes",
213
+ keyframes: [{ percentage: 50, properties: { x: 120, y: 40 } }, {}],
214
+ },
215
+ ]);
216
+ });
217
+
218
+ it("saves nothing for a moving layer when the sealed preview's tweens can't be read", async () => {
219
+ const script = timeline(`${MOVES_BOX}\n${SPLIT_TEXT}`);
220
+ mount(script, SPANS);
221
+ const { start, outcome, commit } = await dragBoxOnSealedFrame(script);
222
+
223
+ expect(start.gsap).toEqual({ x: 100, y: 40, moving: true });
224
+ // Routed without the frame's tweens, the move would save a `set` that pins the layer.
225
+ expect(outcome).toEqual({
226
+ status: "blocked",
227
+ reason: "source-uneditable",
228
+ detail: "frame-tweens-unreadable",
229
+ });
230
+ expect(commit).not.toHaveBeenCalled();
231
+ });
232
+
233
+ it("still saves a layer GSAP only holds when the sealed preview's tweens can't be read", async () => {
234
+ const script = timeline(`tl.set("#box", { x: 100, y: 40 }, 0);\n${SPLIT_TEXT}`);
235
+ mount(script, SPANS);
236
+ const { start, outcome, commit } = await dragBoxOnSealedFrame(script);
237
+
238
+ expect(start.gsap).toEqual({ x: 100, y: 40, moving: false });
239
+ expect(outcome).toEqual({ status: "persisted" });
240
+ expect(commit).toHaveBeenCalledTimes(1);
241
+ // The hold's own `set` takes the new place, as when the frame's tweens are read.
242
+ expect(commit.mock.calls[0]![1]).toEqual({
243
+ type: "update-properties",
244
+ animationId: "#box-set-0-position",
245
+ properties: { x: 120, y: 40 },
246
+ });
247
+ });
@@ -37,6 +37,7 @@ import {
37
37
  STUDIO_ROTATION_DRAFT_ATTR,
38
38
  } from "./manualEditsTypes";
39
39
  import { endPreviewDraft } from "./previewDrafts";
40
+ import { DRAG_MOVING_ATTR } from "../../hooks/draggedGsapPosition";
40
41
  import type {
41
42
  StudioBoxSizeSnapshot,
42
43
  StudioRotationSnapshot,
@@ -218,6 +219,7 @@ export function restoreStudioPathOffsetStyles(
218
219
  }
219
220
  element.removeAttribute("data-hf-drag-gsap-base-x");
220
221
  element.removeAttribute("data-hf-drag-gsap-base-y");
222
+ element.removeAttribute(DRAG_MOVING_ATTR);
221
223
  }
222
224
  }
223
225
 
@@ -14,7 +14,11 @@ import {
14
14
  type StudioPathOffsetSnapshot,
15
15
  } from "./manualEdits";
16
16
  import type { EditMoment } from "./manualEditsTypes";
17
- import { computeDraggedGsapPosition } from "../../hooks/draggedGsapPosition";
17
+ import {
18
+ computeDraggedGsapPosition,
19
+ DRAG_MOVING_ATTR,
20
+ stampGestureBase,
21
+ } from "../../hooks/draggedGsapPosition";
18
22
  import { editsPlainCss } from "../../hooks/gsapRuntimeKeyframes";
19
23
  import { readTranslatePx, UNREADABLE_TRANSLATE, writeTranslatePx } from "./plainTranslate";
20
24
  import { drawPreviewDraft, endPreviewDraft } from "./previewDrafts";
@@ -94,6 +98,8 @@ export interface ManualOffsetDragMember {
94
98
  * making the element accelerate away ("flies"). See applyOffsetDragDraftViaGsap.
95
99
  */
96
100
  baseGsap: { x: number; y: number };
101
+ /** The sealed preview's gesture start reported a tween moving it. */
102
+ moving?: true;
97
103
  initialPathOffset: StudioPathOffsetSnapshot;
98
104
  gestureToken: string;
99
105
  screenToOffset: ManualOffsetDragMatrix;
@@ -344,7 +350,8 @@ export function createManualOffsetDragMember(input: {
344
350
  const gsapX = (!plainTranslate && win?.gsap?.getProperty?.(input.element, "x")) || 0;
345
351
  const gsapY = (!plainTranslate && win?.gsap?.getProperty?.(input.element, "y")) || 0;
346
352
  const baseGsap = start?.gsap ? { x: start.gsap.x, y: start.gsap.y } : { x: gsapX, y: gsapY };
347
- if (!plainTranslate) stampGestureBase(input.element, initialOffset, baseGsap);
353
+ const moving = start?.gsap?.moving === true;
354
+ if (!plainTranslate) stampGestureBase(input.element, initialOffset, baseGsap, moving);
348
355
 
349
356
  if (win?.__timelines) {
350
357
  const paused: string[] = [];
@@ -390,6 +397,7 @@ export function createManualOffsetDragMember(input: {
390
397
  initialOffset,
391
398
  plainTranslate,
392
399
  baseGsap,
400
+ ...(moving && { moving }),
393
401
  initialPathOffset,
394
402
  gestureToken,
395
403
  screenToOffset: start?.screenToOffset ?? { a: w / scaleX, b: 0, c: 0, d: w / scaleY },
@@ -407,6 +415,7 @@ export function createManualOffsetDragMember(input: {
407
415
  initialOffset,
408
416
  plainTranslate,
409
417
  baseGsap,
418
+ ...(moving && { moving }),
410
419
  initialPathOffset,
411
420
  gestureToken,
412
421
  screenToOffset: measured.matrix,
@@ -452,27 +461,12 @@ export function applyManualOffsetDragDraft(
452
461
  return offset;
453
462
  }
454
463
 
455
- /**
456
- * Re-stamp the STABLE gesture-start base/offset before the source commit reads
457
- * them. A mid-gesture re-render can wipe these attrs; the commit converts the
458
- * drop offset → gsap x/y via computeDraggedGsapPosition, which without the base
459
- * falls back to the live (already-dragged) transform and re-adds the delta — so
460
- * the element flies off-screen the instant you drop it. The member holds the
461
- * true gesture-start values in JS, immune to the re-render.
462
- */
463
- export function stampGestureBase(el: HTMLElement, initialOffset: Point, baseGsap: Point): void {
464
- el.setAttribute("data-hf-drag-gsap-base-x", String(baseGsap.x));
465
- el.setAttribute("data-hf-drag-gsap-base-y", String(baseGsap.y));
466
- el.setAttribute("data-hf-drag-initial-offset-x", String(initialOffset.x));
467
- el.setAttribute("data-hf-drag-initial-offset-y", String(initialOffset.y));
468
- }
469
-
470
464
  function applyManualOffsetCommitValue(
471
465
  member: ManualOffsetDragMember,
472
466
  offset: { x: number; y: number },
473
467
  ): { x: number; y: number } {
474
468
  if (!member.plainTranslate)
475
- stampGestureBase(member.element, member.initialOffset, member.baseGsap);
469
+ stampGestureBase(member.element, member.initialOffset, member.baseGsap, !!member.moving);
476
470
  drawMemberOffset(member, offset, true);
477
471
  return offset;
478
472
  }
@@ -552,6 +546,7 @@ export function endManualOffsetDragMembers(members: ManualOffsetDragMember[]): v
552
546
  member.element.removeAttribute("data-hf-drag-initial-offset-y");
553
547
  member.element.removeAttribute("data-hf-drag-gsap-base-x");
554
548
  member.element.removeAttribute("data-hf-drag-gsap-base-y");
549
+ member.element.removeAttribute(DRAG_MOVING_ATTR);
555
550
  // Do NOT clearProps:"transform" — that nukes the committed GSAP position
556
551
  // and causes a visual snap-back before the soft reload re-applies it.
557
552
  const gsapOwnsPosition = !member.plainTranslate && Boolean(getOffsetDragGsap(member.element));
@@ -1,6 +1,10 @@
1
1
  // @vitest-environment happy-dom
2
2
  import { describe, expect, it, vi } from "vitest";
3
- import { readTranslatePx, readTranslatePxLeavingPercent } from "./plainTranslate";
3
+ import {
4
+ readTranslatePx,
5
+ readTranslatePxLeavingPercent,
6
+ rememberFrameTranslate,
7
+ } from "./plainTranslate";
4
8
 
5
9
  function box(style: string): HTMLElement {
6
10
  const element = document.createElement("div");
@@ -94,4 +98,21 @@ describe("readTranslatePxLeavingPercent", () => {
94
98
  vi.restoreAllMocks();
95
99
  el.remove();
96
100
  });
101
+
102
+ // fails without the fix: a sealed preview's stand-in has no window, so Add keyframe seeded 0,0 and the layer jumped.
103
+ it("seeds from the inline translate of a layer with no window, like a sealed preview's stand-in", () => {
104
+ const standIn = document.implementation.createHTMLDocument("").createElement("div");
105
+ standIn.style.setProperty("translate", "319.893px -75.508px");
106
+
107
+ expect(readTranslatePxLeavingPercent(standIn)).toEqual({ x: 319.893, y: -75.508 });
108
+ });
109
+
110
+ it("seeds a stand-in from the translate its frame renders, a stylesheet's included, until a move rewrites it", () => {
111
+ const standIn = document.implementation.createHTMLDocument("").createElement("div");
112
+ rememberFrameTranslate(standIn, { x: 40, y: 30 }, "40px 30px");
113
+
114
+ expect(readTranslatePxLeavingPercent(standIn)).toEqual({ x: 40, y: 30 });
115
+ standIn.style.setProperty("translate", "70px 10px");
116
+ expect(readTranslatePxLeavingPercent(standIn)).toEqual({ x: 70, y: 10 });
117
+ });
97
118
  });
@@ -102,10 +102,10 @@ export function translatePx(value: string, read?: ComputedRead): Point {
102
102
  };
103
103
  }
104
104
 
105
- const frameTranslates = new WeakMap<Element, { inline: string; px: Point }>();
105
+ const frameTranslates = new WeakMap<Element, { inline: string; px: Point; computed: string }>();
106
106
 
107
- export function rememberFrameTranslate(el: HTMLElement, px: Point): void {
108
- frameTranslates.set(el, { inline: el.style.getPropertyValue("translate"), px });
107
+ export function rememberFrameTranslate(el: HTMLElement, px: Point, computed: string): void {
108
+ frameTranslates.set(el, { inline: el.style.getPropertyValue("translate"), px, computed });
109
109
  }
110
110
 
111
111
  /** The element's CSS `translate` in px, as it renders now. */
@@ -120,7 +120,11 @@ export function readTranslatePx(el: HTMLElement): Point {
120
120
  }
121
121
 
122
122
  export function readTranslatePxLeavingPercent(el: HTMLElement): Point {
123
- const value = el.ownerDocument.defaultView?.getComputedStyle(el).translate || "none";
123
+ const cs = el.ownerDocument.defaultView?.getComputedStyle(el);
124
+ const inline = el.style.getPropertyValue("translate");
125
+ const frame = cs ? undefined : frameTranslates.get(el);
126
+ const computed = frame?.inline === inline ? frame.computed : cs?.translate;
127
+ const value = computed || inline || "none";
124
128
  const [x = "0px", y = "0px"] = value === "none" ? [] : splitTopLevelWhitespace(value);
125
129
  const px = (part: string) => roundTo3(evaluateLength(part, 0)) || 0;
126
130
  return { x: px(x), y: px(y) };
@@ -128,8 +132,6 @@ export function readTranslatePxLeavingPercent(el: HTMLElement): Point {
128
132
 
129
133
  export const UNREADABLE_TRANSLATE =
130
134
  "Studio can't read this layer's translate. Move it in the Code tab.";
131
- export const MOVING_LAYER_UNREADABLE =
132
- "This preview can't save a move of a layer its animation moves yet. Move it in the Code tab.";
133
135
 
134
136
  /** Plain px only: GSAP's CSSPlugin splits `translate` on spaces and drops a calc(). */
135
137
  function formatTranslatePx(p: Point): string {
@@ -1,9 +1,7 @@
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";
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(opaqueFrame(), "#card"));
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(opaqueFrame(), "#card");
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(opaqueFrame(), "#card");
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(opaqueFrame(), "#card"));
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 = opaqueFrame();
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(opaqueFrame(), "#centred");
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(opaqueFrame(), "#moved");
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(opaqueFrame(), "#chip"));
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(opaqueFrame(), "#card"));
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 = opaqueFrame();
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 = opaqueFrame();
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(opaqueFrame(), 1)).toBe(false);
235
+ expect(applySoftReloadFinalization(sealedPreviewFrame().iframe, 1)).toBe(false);
262
236
  });
263
237
  });
@@ -20,6 +20,8 @@ interface Queue {
20
20
  const standIns = new WeakMap<Element, { iframe: HTMLIFrameElement; handle: string }>();
21
21
  const queues = new WeakMap<HTMLIFrameElement, Queue>();
22
22
 
23
+ export const previewStandInHandle = (standIn: Element) => standIns.get(standIn)?.handle;
24
+
23
25
  export function registerPreviewStandIn(
24
26
  standIn: Element,
25
27
  iframe: HTMLIFrameElement,
@@ -28,6 +30,8 @@ export function registerPreviewStandIn(
28
30
  standIns.set(standIn, { iframe, handle });
29
31
  }
30
32
 
33
+ export const previewStandIn = (standIn: Element) => standIns.get(standIn);
34
+
31
35
  function queueFor(iframe: HTMLIFrameElement): Queue {
32
36
  let queue = queues.get(iframe);
33
37
  if (!queue) {