@hyperframes/studio 0.8.143 → 0.8.144

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 (51) hide show
  1. package/dist/assets/{hyperframes-player-BXSuksFh.js → hyperframes-player-Bw_jIaSX.js} +3 -3
  2. package/dist/assets/{index-J7jpL4pj.js → index-BVM9NuWl.js} +141 -141
  3. package/dist/assets/{index-BgOVCqjo.js → index-Cj7W_c7p.js} +1 -1
  4. package/dist/assets/{index-FgyO_5Kv.js → index-DyH9dT7b.js} +1 -1
  5. package/dist/{chunk-TFLU2MGI.js → chunk-3GHTHPZD.js} +8 -1
  6. package/dist/chunk-3GHTHPZD.js.map +1 -0
  7. package/dist/{chunk-H2DUOXTF.js → chunk-G3EDKRZH.js} +3 -3
  8. package/dist/{chunk-UYWON5AX.js → chunk-PEAKCOUW.js} +7 -3
  9. package/dist/chunk-PEAKCOUW.js.map +1 -0
  10. package/dist/{chunk-LOVBLSMR.js → chunk-Y2OHHNM2.js} +35 -19
  11. package/dist/chunk-Y2OHHNM2.js.map +1 -0
  12. package/dist/{domEditingLayers-KBTPQKGA.js → domEditingLayers-PYST4G45.js} +3 -3
  13. package/dist/index.html +1 -1
  14. package/dist/index.js +139 -70
  15. package/dist/index.js.map +1 -1
  16. package/dist/player.js +3 -3
  17. package/dist/ui.d.ts +4 -5
  18. package/dist/ui.js +1 -1
  19. package/package.json +8 -8
  20. package/src/components/editor/DomEditSelectionChrome.test.tsx +103 -0
  21. package/src/components/editor/DomEditSelectionChrome.tsx +42 -16
  22. package/src/components/editor/anchoredResizeCommitFeedsOffset.test.ts +36 -0
  23. package/src/components/editor/domEditOverlayGestures.ts +1 -0
  24. package/src/components/editor/domEditOverlayStartGesture.ts +5 -0
  25. package/src/components/editor/domEditResizeLocal.test.ts +81 -1
  26. package/src/components/editor/domEditResizeLocal.ts +27 -3
  27. package/src/components/editor/domEditingLayers.ts +4 -1
  28. package/src/components/editor/domEditingTextFields.test.ts +18 -0
  29. package/src/components/editor/manualEditsDom.ts +12 -12
  30. package/src/components/editor/previewGestureStarts.ts +14 -5
  31. package/src/components/editor/resizeDraft.ts +13 -4
  32. package/src/components/editor/useDomEditOverlayGestures.ts +5 -3
  33. package/src/components/ui/Menu.test.tsx +67 -5
  34. package/src/components/ui/Menu.tsx +21 -4
  35. package/src/components/ui/Popover.tsx +11 -5
  36. package/src/hooks/gsapResizeIntercept.test.ts +46 -11
  37. package/src/hooks/gsapResizeIntercept.ts +25 -20
  38. package/src/hooks/useThumbnailStripSize.test.tsx +123 -0
  39. package/src/hooks/useThumbnailStripSize.ts +19 -8
  40. package/src/player/components/CompositionThumbnail.test.ts +3 -0
  41. package/src/player/components/ImageThumbnail.test.tsx +4 -1
  42. package/src/player/components/VideoThumbnail.test.tsx +13 -2
  43. package/src/player/hooks/timelineSyncHydration.ts +2 -1
  44. package/src/utils/authoredSource.test.ts +25 -0
  45. package/src/utils/authoredSource.ts +3 -5
  46. package/src/utils/rounding.ts +7 -0
  47. package/dist/chunk-LOVBLSMR.js.map +0 -1
  48. package/dist/chunk-TFLU2MGI.js.map +0 -1
  49. package/dist/chunk-UYWON5AX.js.map +0 -1
  50. /package/dist/{chunk-H2DUOXTF.js.map → chunk-G3EDKRZH.js.map} +0 -0
  51. /package/dist/{domEditingLayers-KBTPQKGA.js.map → domEditingLayers-PYST4G45.js.map} +0 -0
@@ -99,10 +99,10 @@ export function createPreviewGestureStarts(
99
99
  const drawPressedBox = (origin: OverlayRect | null): WaitingPressState["draw"] =>
100
100
  origin && ((dx, dy) => opts.setOverlayRect(shiftedOverlayRect(origin, dx, dy)));
101
101
 
102
- // A corner resize scales about the element's centre by the pointer's distance from it, as the resize does.
102
+ // A corner resize scales about the element's centre by the grabbed corner's distance from it, as the resize does.
103
103
  const drawResizedBox = (
104
104
  origin: OverlayRect | null,
105
- press: { x: number; y: number },
105
+ grabbed: { x: number; y: number },
106
106
  ): WaitingPressState["draw"] => {
107
107
  if (!origin) return null;
108
108
  const bounds = opts.overlayRef.current?.getBoundingClientRect();
@@ -111,8 +111,12 @@ export function createPreviewGestureStarts(
111
111
  y: (bounds?.top ?? 0) + origin.top + origin.height / 2,
112
112
  };
113
113
  return (dx, dy) => {
114
- const pointer = { x: press.x + dx, y: press.y + dy };
115
- const scale = resolveCenterResizeScale({ pointer, pointerStart: press, centerStart: centre });
114
+ const pointer = { x: grabbed.x + dx, y: grabbed.y + dy };
115
+ const scale = resolveCenterResizeScale({
116
+ pointer,
117
+ pointerStart: grabbed,
118
+ centerStart: centre,
119
+ });
116
120
  const [width, height] = [origin.width * scale, origin.height * scale];
117
121
  opts.setOverlayRect({
118
122
  ...origin,
@@ -248,6 +252,7 @@ export function createPreviewGestureStarts(
248
252
  selection?: DomEditSelection;
249
253
  rect?: OverlayRect | null;
250
254
  resizeHandle?: ResizeHandle;
255
+ resizeCorner?: { x: number; y: number };
251
256
  },
252
257
  ) => {
253
258
  // A replay edits what was pressed, though another element may be selected by then.
@@ -255,7 +260,10 @@ export function createPreviewGestureStarts(
255
260
  let draw: WaitingPressState["draw"] = null;
256
261
  if (kind === "drag") draw = drawPressedBox(opts.overlayRectRef.current);
257
262
  if (kind === "resize")
258
- draw = drawResizedBox(opts.overlayRectRef.current, { x: e.clientX, y: e.clientY });
263
+ draw = drawResizedBox(
264
+ opts.overlayRectRef.current,
265
+ options?.resizeCorner ?? { x: e.clientX, y: e.clientY },
266
+ );
259
267
  return startOnShownPreview(
260
268
  e,
261
269
  () => {
@@ -272,6 +280,7 @@ export function createPreviewGestureStarts(
272
280
  selection,
273
281
  rect,
274
282
  resizeHandle: options?.resizeHandle,
283
+ resizeCorner: options?.resizeCorner,
275
284
  at,
276
285
  })
277
286
  );
@@ -6,14 +6,15 @@ import {
6
6
  elementCornerOverlayPoints,
7
7
  overlayCornersCentroid,
8
8
  } from "./domEditOverlayGeometry";
9
- import { computeNextResizeAnchor } from "./domEditResizeLocal";
9
+ import { computeNextResizeAnchor, resizeRemainderShift } from "./domEditResizeLocal";
10
+ import type { ResizeDraftSizes } from "./domEditResizeLocal";
10
11
  import { applyManualOffsetDragDraft } from "./manualOffsetDrag";
11
12
 
12
13
  type Corners = ReturnType<typeof elementCornerOverlayPoints>;
13
14
 
14
15
  /**
15
16
  * The residual center-pin offset for this frame. With measurable corners and a
16
- * fixed-center start, accumulate `fixedStart - centerNow` onto the previous
17
+ * fixed-center start, accumulate `fixedStart + shift - centerNow` onto the previous
17
18
  * anchor so it CONVERGES rather than oscillating: `applyManualOffsetDragDraft`
18
19
  * treats its argument as the absolute offset, and `centerNow` (measured on the
19
20
  * live element) already carries the previous frame's offset, so the difference
@@ -25,10 +26,15 @@ function resolveResizeAnchor(
25
26
  g: GestureState,
26
27
  corners: Corners | null,
27
28
  measureOrientedRect: () => OverlayRect | null,
29
+ sizes: ResizeDraftSizes,
28
30
  ): { dx: number; dy: number } {
29
31
  const fixedStart = g.resizeFixedCenterStart;
30
32
  if (corners && fixedStart) {
31
- return computeNextResizeAnchor(g.lastResizeAnchor, fixedStart, overlayCornersCentroid(corners));
33
+ const press = g.resizePressFromCorner ?? { x: 0, y: 0 };
34
+ const grab = { x: g.startX - press.x - g.centerX, y: g.startY - press.y - g.centerY };
35
+ const shift = resizeRemainderShift(corners, grab, sizes);
36
+ const target = { x: fixedStart.x + shift.x, y: fixedStart.y + shift.y };
37
+ return computeNextResizeAnchor(g.lastResizeAnchor, target, overlayCornersCentroid(corners));
32
38
  }
33
39
  const fallbackRect = measureOrientedRect();
34
40
  return resolveResizeCenterAnchorOffset({
@@ -52,11 +58,12 @@ function resolveAnchoredResizeDraft(
52
58
  overlayEl: HTMLDivElement | null,
53
59
  iframe: HTMLIFrameElement | null,
54
60
  measureOrientedRect: () => OverlayRect | null,
61
+ sizes: ResizeDraftSizes,
55
62
  ): OverlayRect {
56
63
  // Measure real corners ONCE — reused for the anchor and the fallback size.
57
64
  const corners =
58
65
  overlayEl && iframe ? elementCornerOverlayPoints(overlayEl, iframe, element) : null;
59
- const anchor = resolveResizeAnchor(g, corners, measureOrientedRect);
66
+ const anchor = resolveResizeAnchor(g, corners, measureOrientedRect, sizes);
60
67
  g.lastResizeAnchor = anchor;
61
68
  applyManualOffsetDragDraft(member, anchor.dx, anchor.dy);
62
69
  // Re-measure AFTER the anchor translate so it hugs the element every frame.
@@ -80,6 +87,7 @@ export function resolveResizeDraftRect(
80
87
  overlayEl: HTMLDivElement | null,
81
88
  iframe: HTMLIFrameElement | null,
82
89
  measureOrientedRect: () => OverlayRect | null,
90
+ sizes: ResizeDraftSizes,
83
91
  ): OverlayRect {
84
92
  if (g.pathOffsetMember) {
85
93
  return resolveAnchoredResizeDraft(
@@ -89,6 +97,7 @@ export function resolveResizeDraftRect(
89
97
  overlayEl,
90
98
  iframe,
91
99
  measureOrientedRect,
100
+ sizes,
92
101
  );
93
102
  }
94
103
  // Re-measure the element's oriented box AFTER the size write. The size draft
@@ -250,14 +250,15 @@ export function createDomEditOverlayGestureHandlers(opts: UseDomEditOverlayGestu
250
250
  if (g.pathOffsetMember) applyManualOffsetDragDraft(g.pathOffsetMember, dx, dy);
251
251
  } else {
252
252
  // Corner resize scales proportionally about the center, without edge snapping.
253
+ const grab = g.resizePressFromCorner ?? { x: 0, y: 0 };
253
254
  const nextSize = resolveCenterResizeSize({
254
255
  baseWidth: g.actualWidth,
255
256
  baseHeight: g.actualHeight,
256
- pointer: { x: e.clientX, y: e.clientY },
257
- pointerStart: { x: g.startX, y: g.startY },
257
+ pointer: { x: e.clientX - grab.x, y: e.clientY - grab.y },
258
+ pointerStart: { x: g.startX - grab.x, y: g.startY - grab.y },
258
259
  centerStart: { x: g.centerX, y: g.centerY },
259
260
  });
260
- applyStudioBoxSizeDraft(sel.element, nextSize);
261
+ const writtenSize = applyStudioBoxSizeDraft(sel.element, nextSize);
261
262
 
262
263
  const overlayEl = opts.overlayRef.current;
263
264
  const iframe = opts.iframeRef.current;
@@ -270,6 +271,7 @@ export function createDomEditOverlayGestureHandlers(opts: UseDomEditOverlayGestu
270
271
  overlayEl,
271
272
  iframe,
272
273
  measureOrientedRect,
274
+ { wanted: nextSize, written: writtenSize },
273
275
  );
274
276
  logResizeMove({
275
277
  pointer: { x: e.clientX, y: e.clientY },
@@ -48,6 +48,13 @@ function clickWithMouse(target: Element): void {
48
48
  });
49
49
  }
50
50
 
51
+ function rightClick(target: Element): void {
52
+ const init = { bubbles: true, cancelable: true, composed: true };
53
+ act(() => {
54
+ target.dispatchEvent(new MouseEvent("contextmenu", init));
55
+ });
56
+ }
57
+
51
58
  function key(k: string, target: Element | null = document.activeElement): void {
52
59
  const init = { key: k, bubbles: true, cancelable: true, composed: true };
53
60
  act(() => {
@@ -241,11 +248,7 @@ describe("ContextMenu", () => {
241
248
  expect(trigger().textContent).toBe("clip");
242
249
  expect(popup()).toBeNull();
243
250
 
244
- act(() => {
245
- trigger().dispatchEvent(
246
- new MouseEvent("contextmenu", { bubbles: true, cancelable: true, composed: true }),
247
- );
248
- });
251
+ rightClick(trigger());
249
252
  await settle();
250
253
  expect(popup()).not.toBeNull();
251
254
 
@@ -257,6 +260,65 @@ describe("ContextMenu", () => {
257
260
  });
258
261
  });
259
262
 
263
+ describe("container={null}", () => {
264
+ /** Rendered inline means inside the trigger's own parent, not a portal on the body. */
265
+ function expectInlineBeside(menu: HTMLElement | null): void {
266
+ expect(menu).not.toBeNull();
267
+ expect(trigger().parentElement?.contains(menu)).toBe(true);
268
+ }
269
+
270
+ it("opens a Menu inline, next to its trigger, and closes on Escape", async () => {
271
+ render(
272
+ <div>
273
+ <Menu container={null} trigger={<button data-testid="trigger">Actions</button>}>
274
+ <MenuItem>Bring to front</MenuItem>
275
+ </Menu>
276
+ </div>,
277
+ );
278
+ clickWithMouse(trigger());
279
+ await settle();
280
+ expectInlineBeside(popup());
281
+
282
+ key("Escape");
283
+ await settle();
284
+ expect(popup()).toBeNull();
285
+ });
286
+
287
+ it("opens a ContextMenu inline, next to its area", async () => {
288
+ render(
289
+ <div>
290
+ <ContextMenu container={null} trigger={<div data-testid="trigger">clip</div>}>
291
+ <MenuItem>Split</MenuItem>
292
+ </ContextMenu>
293
+ </div>,
294
+ );
295
+ rightClick(trigger());
296
+ await settle();
297
+ expectInlineBeside(popup());
298
+ });
299
+
300
+ it("opens a Popover inline on its first render", async () => {
301
+ render(
302
+ <div>
303
+ <Popover
304
+ container={null}
305
+ defaultOpen
306
+ trigger={<button data-testid="trigger">Speed</button>}
307
+ >
308
+ <span>1x</span>
309
+ </Popover>
310
+ </div>,
311
+ );
312
+ await settle();
313
+ expectInlineBeside(document.querySelector<HTMLElement>("[role=dialog]"));
314
+ });
315
+
316
+ it("still portals to the body when no container is passed", async () => {
317
+ await openActionMenu();
318
+ expect(trigger().parentElement?.contains(popup())).toBe(false);
319
+ });
320
+ });
321
+
260
322
  describe("Popover", () => {
261
323
  it("leaves the keys of a text field inside it alone", async () => {
262
324
  // The Menu owns ArrowDown and typeahead; a Popover must not, or the rename
@@ -5,6 +5,7 @@
5
5
 
6
6
  import { ContextMenu as BaseContextMenu } from "@base-ui/react/context-menu";
7
7
  import { Menu as BaseMenu } from "@base-ui/react/menu";
8
+ import { useRef } from "react";
8
9
  import type { ComponentPropsWithoutRef, ElementType, ReactElement, ReactNode } from "react";
9
10
  import { cn } from "./cn";
10
11
 
@@ -20,7 +21,19 @@ type StyledProps<T extends ElementType> = Omit<ComponentPropsWithoutRef<T>, "cla
20
21
  export type PopupPreviewState = "open";
21
22
 
22
23
  /** Where the portal puts the popup. `null` keeps it inline, next to its trigger. */
23
- type PortalContainer = ComponentPropsWithoutRef<typeof BaseMenu.Portal>["container"];
24
+ export type PortalContainer = ComponentPropsWithoutRef<typeof BaseMenu.Portal>["container"];
25
+
26
+ const CONTENTS = { display: "contents" } as const;
27
+
28
+ /** Base UI reads a `null` container as "not resolved yet" and renders nothing, so give `null` a host by the trigger. */
29
+ export function useInlinePortal(container: PortalContainer) {
30
+ const host = useRef<HTMLSpanElement>(null);
31
+ if (container !== null) return { host: null, portal: { container } };
32
+ return {
33
+ host: <span ref={host} style={CONTENTS} />,
34
+ portal: { container: host, style: CONTENTS },
35
+ };
36
+ }
24
37
 
25
38
  /** Matches Tooltip's gap from its trigger, and its viewport margin. */
26
39
  const SIDE_OFFSET = 6;
@@ -77,7 +90,7 @@ interface PositionedProps {
77
90
  side?: "top" | "bottom" | "left" | "right";
78
91
  align?: "start" | "center" | "end";
79
92
  sideOffset?: number;
80
- /** Portal target. Pass the shadow root when the trigger lives in one. */
93
+ /** Portal target. Pass the shadow root when the trigger lives in one; `null` keeps it inline. */
81
94
  container?: PortalContainer;
82
95
  /** Names the popup for assistive tech. A menu with no name is unlabelled. */
83
96
  "aria-label"?: string;
@@ -109,10 +122,12 @@ export function Menu({
109
122
  "data-preview-state": previewState,
110
123
  ...root
111
124
  }: MenuProps) {
125
+ const inline = useInlinePortal(container);
112
126
  return (
113
127
  <BaseMenu.Root {...root}>
114
128
  <BaseMenu.Trigger render={trigger} />
115
- <BaseMenu.Portal container={container}>
129
+ {inline.host}
130
+ <BaseMenu.Portal {...inline.portal}>
116
131
  <BaseMenu.Positioner
117
132
  side={side}
118
133
  align={align}
@@ -153,10 +168,12 @@ export function ContextMenu({
153
168
  "data-preview-state": previewState,
154
169
  ...root
155
170
  }: Omit<ContextMenuProps, "side" | "align" | "sideOffset">) {
171
+ const inline = useInlinePortal(container);
156
172
  return (
157
173
  <BaseContextMenu.Root {...root}>
158
174
  <BaseContextMenu.Trigger render={trigger} />
159
- <BaseContextMenu.Portal container={container}>
175
+ {inline.host}
176
+ <BaseContextMenu.Portal {...inline.portal}>
160
177
  <BaseContextMenu.Positioner collisionPadding={VIEWPORT_MARGIN} className={POPUP_LAYER}>
161
178
  <BaseContextMenu.Popup
162
179
  aria-label={ariaLabel}
@@ -6,9 +6,13 @@
6
6
  import { Popover as BasePopover } from "@base-ui/react/popover";
7
7
  import type { ComponentPropsWithoutRef, ReactElement, ReactNode } from "react";
8
8
  import { cn } from "./cn";
9
- import { POPUP_LAYER, popupSurface, type PopupPreviewState } from "./Menu";
10
-
11
- type PortalContainer = ComponentPropsWithoutRef<typeof BasePopover.Portal>["container"];
9
+ import {
10
+ POPUP_LAYER,
11
+ popupSurface,
12
+ useInlinePortal,
13
+ type PopupPreviewState,
14
+ type PortalContainer,
15
+ } from "./Menu";
12
16
 
13
17
  /** Matches Menu's gap from its trigger, and its viewport margin. */
14
18
  const SIDE_OFFSET = 6;
@@ -33,7 +37,7 @@ interface PopoverProps extends Omit<ComponentPropsWithoutRef<typeof BasePopover.
33
37
  sideOffset?: number;
34
38
  /** Points the popup at its trigger. Off by default; the default gap from the trigger grows by the arrow's height. */
35
39
  arrow?: boolean;
36
- /** Portal target. Pass the shadow root when the trigger lives in one. */
40
+ /** Portal target. Pass the shadow root when the trigger lives in one; `null` keeps it inline. */
37
41
  container?: PortalContainer;
38
42
  /** Names the popup for assistive tech. */
39
43
  "aria-label"?: string;
@@ -60,10 +64,12 @@ export function Popover({
60
64
  "data-preview-state": previewState,
61
65
  ...root
62
66
  }: PopoverProps) {
67
+ const inline = useInlinePortal(container);
63
68
  return (
64
69
  <BasePopover.Root {...root}>
65
70
  <BasePopover.Trigger render={trigger} />
66
- <BasePopover.Portal container={container}>
71
+ {inline.host}
72
+ <BasePopover.Portal {...inline.portal}>
67
73
  <BasePopover.Positioner
68
74
  side={side}
69
75
  align={align}
@@ -455,10 +455,31 @@ it("does not mix the scale shorthand into a tween that speaks longhands", async
455
455
  * The fixture models the geometry the browser reported: a 630x252 element
456
456
  * dragged from x=432 to x=587 with its box drafted down to 320x128, dropped at
457
457
  * a committed scale of 0.837. Scaling about the centre puts it back on the drop
458
- * point at its pre-gesture position, so the correct persisted correction is
459
- * NONE.
458
+ * point at its pre-gesture position, so the persisted correction is only the
459
+ * drop's sub-pixel offset.
460
460
  */
461
- it("does not move a statically positioned element when a scale resize lands", async () => {
461
+ it.each([
462
+ {
463
+ name: "does not move a statically positioned element when a scale resize lands",
464
+ shift: { x: 0, y: 0 },
465
+ },
466
+ {
467
+ name: "puts a statically positioned element on a sub-pixel drop point",
468
+ shift: { x: 0.3, y: -0.2 },
469
+ writes: true,
470
+ },
471
+ {
472
+ name: "leaves a static position alone when the drop is off by less than the file's precision",
473
+ shift: { x: 0.0003, y: 0 },
474
+ writes: false,
475
+ },
476
+ {
477
+ name: "leaves an animated position alone for a sub-pixel drop point",
478
+ shift: { x: 0.3, y: -0.2 },
479
+ animated: true,
480
+ writes: false,
481
+ },
482
+ ])("$name", async ({ shift, animated, writes }) => {
462
483
  document.body.innerHTML = "";
463
484
  const el = document.createElement("div");
464
485
  el.id = "clip";
@@ -476,7 +497,7 @@ it("does not move a statically positioned element when a scale resize lands", as
476
497
  el.style.height = "128px";
477
498
  document.body.append(el);
478
499
 
479
- const pos = { x: 587, y: 235 };
500
+ const pos = { x: 587 + shift.x, y: 235 + shift.y };
480
501
  const scale = { x: 1.648, y: 1.648 };
481
502
  const [LEFT, TOP] = [120, 520];
482
503
  el.getBoundingClientRect = () => {
@@ -517,6 +538,15 @@ it("does not move a statically positioned element when a scale resize lands", as
517
538
  duration: 0,
518
539
  global: true,
519
540
  } as unknown as GsapAnimation;
541
+ const positionTween = {
542
+ ...positionHold,
543
+ id: "#clip-to-0-position",
544
+ method: "to",
545
+ properties: { x: 500 },
546
+ duration: 4,
547
+ global: false,
548
+ } as unknown as GsapAnimation;
549
+ const position = animated ? positionTween : positionHold;
520
550
  const selection = { id: "clip", selector: "#clip", element: el } as DomEditSelection;
521
551
  usePlayerStore.setState({ currentTime: 0.5 });
522
552
  const commitMutation = vi.fn();
@@ -524,22 +554,27 @@ it("does not move a statically positioned element when a scale resize lands", as
524
554
  await tryGsapResizeIntercept(
525
555
  selection,
526
556
  { width: 320, height: 128 },
527
- [keyframedScaleFixture(), positionHold],
557
+ [keyframedScaleFixture(), position],
528
558
  iframe,
529
559
  commitMutation,
530
- async () => [keyframedScaleFixture(), positionHold],
560
+ async () => [keyframedScaleFixture(), position],
531
561
  );
532
562
 
533
563
  const positionWrites = commitMutation.mock.calls
534
564
  .map((call) => call[1] as { properties?: Record<string, number> })
535
565
  .filter((mutation) => mutation.properties?.x != null || mutation.properties?.y != null);
536
- // Either it left the position alone, or it rewrote the same value.
566
+ // No position write, or one that moves the hold by exactly the drop's sub-pixel offset.
567
+ if (writes === false) expect(positionWrites).toEqual([]);
568
+ if (writes) expect(positionWrites.length).toBeGreaterThan(0);
537
569
  for (const write of positionWrites) {
538
- expect(write.properties?.x).toBe(432);
539
- expect(write.properties?.y).toBe(173);
570
+ expect(write.properties?.x).toBeCloseTo(432 + shift.x, 3);
571
+ expect(write.properties?.y).toBeCloseTo(173 + shift.y, 3);
540
572
  }
541
- // And the live element ends on the drop point, not a drag away from it.
542
- expect(el.getBoundingClientRect().x).toBeCloseTo(603.3, 0);
573
+ // And the live box is centred where it was dropped (left 120 + 587 + 160, top 520 + 235 + 64).
574
+ const landed = animated ? { x: 0, y: 0 } : shift;
575
+ const box = el.getBoundingClientRect();
576
+ expect(box.x + box.width / 2).toBeCloseTo(867 + landed.x, 3);
577
+ expect(box.y + box.height / 2).toBeCloseTo(819 + landed.y, 3);
543
578
  });
544
579
 
545
580
  function titleSelection(): DomEditSelection {
@@ -170,6 +170,11 @@ function tweenUsesScaleLonghands(anim: GsapAnimation | null): boolean {
170
170
 
171
171
  // ── Resize intercept ──────────────────────────────────────────────────────
172
172
 
173
+ // The resize is centre-anchored, so a scale that cannot reproduce the dragged size splits the gap evenly.
174
+ function rectCentre(rect: DOMRect): { x: number; y: number } {
175
+ return { x: rect.x + rect.width / 2, y: rect.y + rect.height / 2 };
176
+ }
177
+
173
178
  // fallow-ignore-next-line complexity
174
179
  export async function tryGsapResizeIntercept(
175
180
  selection: DomEditSelection,
@@ -371,15 +376,10 @@ export async function tryGsapResizeIntercept(
371
376
  committedScale = useScaleLonghands
372
377
  ? { x: newScaleX, y: newScaleY }
373
378
  : { x: newScaleX, y: newScaleX };
374
- // Where the user DROPPED the box: the draft (anchor-pinned to the
375
- // gesture-start top-left) is still applied here, so this rect is exactly
376
- // what the preview showed at release. The committed scale renders around
377
- // the element CENTER instead — the finalize step below measures that
378
- // difference and compensates, so release matches the drop pixel-for-pixel
379
- // regardless of live scale or repeat resizes.
379
+ // Where the user DROPPED the box: the draft is still applied, so this is what the preview showed
380
+ // at release. The finalize step below moves the committed scale's box onto it.
380
381
  if (el) {
381
- const dropRect = draw(() => el.getBoundingClientRect());
382
- scaleDraftDropPoint = { x: dropRect.x, y: dropRect.y };
382
+ scaleDraftDropPoint = draw(() => rectCentre(el.getBoundingClientRect()));
383
383
  }
384
384
  } else {
385
385
  resizeProps = {
@@ -396,8 +396,8 @@ export async function tryGsapResizeIntercept(
396
396
  // position (a `tl.set` hold or none) — a keyframed position path has no
397
397
  // single anchor to preserve, so it keeps the plain center-scale behavior.
398
398
  // The size route hands its draft to GSAP itself (handOverDraftSize).
399
- // ponytail: for a 3D-rotated element the rects are AABBs, so the anchor is
400
- // approximate rather than corner-exact.
399
+ // ponytail: the centre of an AABB is exact for any 2D transform; under
400
+ // perspective it is approximate.
401
401
  // fallow-ignore-next-line complexity
402
402
  const finalizeScaleResizeCommit = async (): Promise<boolean> => {
403
403
  // Only the scale route captures the element, so a null draft means this
@@ -428,15 +428,9 @@ export async function tryGsapResizeIntercept(
428
428
  );
429
429
  const base = { x: baseGsapX, y: baseGsapY };
430
430
  setElementGsapPosition(draftEl, base.x, base.y);
431
- const post = draftEl.getBoundingClientRect();
431
+ const post = rectCentre(draftEl.getBoundingClientRect());
432
432
  const residual = { x: dropPoint.x - post.x, y: dropPoint.y - post.y };
433
433
  if (!Number.isFinite(residual.x) || !Number.isFinite(residual.y)) return null;
434
- if (Math.abs(residual.x) < 0.5 && Math.abs(residual.y) < 0.5) {
435
- logResize("scale-finalize", { skipped: "already-on-drop-point", residual, base });
436
- // Settled, with nothing to write. Still ours: forwarding the drag offset
437
- // on top would move the box off the point it is already sitting on.
438
- return "settled" as const;
439
- }
440
434
  // The ONE corrected position — rounded once so the live runtime and the
441
435
  // persisted file agree exactly (commitStaticGsapPosition composes the same
442
436
  // rounded value from this delta).
@@ -444,9 +438,15 @@ export async function tryGsapResizeIntercept(
444
438
  x: roundTo3(base.x + residual.x),
445
439
  y: roundTo3(base.y + residual.y),
446
440
  };
441
+ if (corrected.x === roundTo3(base.x) && corrected.y === roundTo3(base.y)) {
442
+ logResize("scale-finalize", { skipped: "already-on-drop-point", residual, base });
443
+ // Settled, with nothing to write. Still ours: forwarding the drag offset
444
+ // on top would move the box off the point it is already sitting on.
445
+ return "settled" as const;
446
+ }
447
447
  logResize("scale-finalize", {
448
448
  dropPoint,
449
- post: { x: post.x, y: post.y },
449
+ post,
450
450
  residual,
451
451
  gsapPos,
452
452
  base,
@@ -455,11 +455,11 @@ export async function tryGsapResizeIntercept(
455
455
  // Correct the live box in the same task as the measurement, so no frame shows it off the drop
456
456
  // point while the position write is in flight.
457
457
  setElementGsapPosition(draftEl, corrected.x, corrected.y);
458
- return { base, corrected };
458
+ return { base, corrected, residual };
459
459
  });
460
460
  if (measured === null) return false;
461
461
  if (measured === "settled") return true;
462
- const { base, corrected } = measured;
462
+ const { base, corrected, residual } = measured;
463
463
  // Re-fetch: the scale commit above just rewrote the script, so the caller's
464
464
  // animation list (and its ids) may be stale for the position lookup.
465
465
  const currentAnimations = fetchFallbackAnimations
@@ -482,6 +482,11 @@ export async function tryGsapResizeIntercept(
482
482
  moment.time,
483
483
  );
484
484
  if (positionTween) {
485
+ // A sub-pixel correction is not worth a keyframe in an authored tween.
486
+ if (Math.abs(residual.x) < 0.5 && Math.abs(residual.y) < 0.5) {
487
+ draw(() => setElementGsapPosition(draftEl, base.x, base.y));
488
+ return true;
489
+ }
485
490
  logResize("scale-finalize", { route: "position-keyframe", tweenId: positionTween.id });
486
491
  assertGsapEditPersisted(
487
492
  await commitGsapPositionFromDrag(selection, positionTween, delta, base, iframe, {