Skip to content

Commit 74f5013

Browse files
fix(studio): a rotate without GSAP saves where you let go, nested too (#4802)
* fix(studio): a rotate GSAP does not own saves where you let go, as the element's own CSS rotate * fix(studio): a rotate keeps a transform-centred element in place * fix(studio): a plain rotate shows its angle in the panel and turns inline elements too * fix(studio): a rotate turns a mirrored or stretched centred element with the cursor * fix(studio): keep the rotate's panel readout within the comment budget after the move landed * fix(studio): an inline element's turn saves the inline-block it was drawn with The overlay passes the rotate target it read at press into the commit, so the save draws and patches exactly what the draft did instead of re-reading an element the draft already made inline-block. The GSAP-aware commit also routes on that press-time decision. * test(studio): bank the 27 rotate cases a GSAP-free rotate now passes baseline.json is the edit-accuracy-gate artifact of the CI run at cb75cc3, copied byte for byte: 530 to 557 passing, all rotate-none cases, none regressed. * fix(studio): a word an older Studio turned keeps its inline-block and whole angle on a new rotate Clearing the legacy rotation marks puts the element back to inline and drops their turn, so the save reads the target again instead of using the one the press read before the clear. A test also pins that a turn the press drew as CSS stays on the CSS writer. * test(studio): bank the edit accuracy baseline from the rebased rotate run
1 parent bb0d076 commit 74f5013

29 files changed

Lines changed: 1493 additions & 858 deletions

‎packages/studio/src/components/editor/DomEditOverlay.tsx‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { RotationCommit } from "./rotationDraft";
12
import { memo, useEffect, useMemo, useRef, type RefObject } from "react";
23
import { type DomEditSelection } from "./domEditing";
34
import type { PreviewMouseDownOptions } from "../../hooks/usePreviewInteraction";
@@ -91,10 +92,7 @@ export interface DomEditOverlayProps {
9192
offset?: { x: number; y: number },
9293
restore?: () => void,
9394
) => Promise<unknown> | void;
94-
onRotationCommit: (
95-
selection: DomEditSelection,
96-
next: { angle: number },
97-
) => Promise<unknown> | void;
95+
onRotationCommit: (selection: DomEditSelection, next: RotationCommit) => Promise<unknown> | void;
9896
onStyleCommit?: (property: string, value: string) => Promise<unknown> | void;
9997
recordingState?: GestureRecordingState;
10098
onToggleRecording?: () => void;

‎packages/studio/src/components/editor/PropertyPanel.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { memo, useMemo, useRef, useState } from "react";
33
import { Move } from "../../icons/SystemIcons";
44
import { InspectorHeaderActions } from "./InspectorHeaderActions";
55
import { useStudioShellContext } from "../../contexts/StudioContext";
6-
import { readStudioBoxSize, readStudioRotation } from "./manualEdits";
7-
import { readMoveOffset } from "./plainTranslate";
6+
import { readStudioBoxSize } from "./manualEdits";
7+
import { readMoveOffset, readShownRotation } from "./plainTranslate";
88
import {
99
buildElementInfoText,
1010
EMPTY_STYLES,
@@ -210,7 +210,7 @@ export const PropertyPanel = memo(function PropertyPanel(props: PropertyPanelPro
210210
manualSize.height > 0
211211
? manualSize.height
212212
: (parsePxMetricValue(styles.height ?? "") ?? element.boundingBox.height);
213-
const manualRotation = readStudioRotation(element.element);
213+
const manualRotation = readShownRotation(element.element);
214214

215215
const elStart = Number.parseFloat(element?.dataAttributes?.start ?? "0") || 0;
216216
const elDuration = Number.parseFloat(element?.dataAttributes?.duration ?? "1") || 0;

‎packages/studio/src/components/editor/domEditOverlayGestures.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {
66
StudioRotationSnapshot,
77
} from "./manualEdits";
88
import type { ManualOffsetDragMember } from "./manualOffsetDrag";
9+
import type { CssRotationTarget, RotationCommit } from "./rotationDraft";
910
import type { GroupOverlayItem, OverlayRect } from "./domEditOverlayGeometry";
1011
import type { SnapContext } from "./snapTargetCollection";
1112
import type { SnapGuidesState } from "./SnapGuideOverlay";
@@ -63,11 +64,12 @@ export interface GestureState {
6364
actualWidth: number;
6465
actualHeight: number;
6566
actualRotation: number;
67+
/** Null when GSAP owns the rotate; else where its CSS turn is drawn and saved, read at press. */
68+
plainRotation: CssRotationTarget | null;
6669
editScaleX: number;
6770
editScaleY: number;
68-
// Rendered-per-CSS-pixel factor of the element itself at gesture start (a GSAP
69-
// scale() transform makes this > 1) — the resize draft divides by it so the box
70-
// follows the cursor instead of overshooting by the live scale.
71+
// Rendered px per CSS px of the element at gesture start (> 1 under a GSAP scale()); the resize
72+
// draft divides by it so the box follows the cursor instead of overshooting by the live scale.
7173
contentScaleX: number;
7274
contentScaleY: number;
7375
manualEditDragToken?: string;
@@ -266,7 +268,7 @@ export type UseDomEditOverlayGesturesOptions = {
266268
) => Promise<unknown> | void
267269
>;
268270
onRotationCommitRef: RefObject<
269-
(s: DomEditSelection, n: { angle: number }) => Promise<unknown> | void
271+
(s: DomEditSelection, n: RotationCommit) => Promise<unknown> | void
270272
>;
271273
onCanvasPointerMoveRef: RefObject<
272274
(

‎packages/studio/src/components/editor/domEditOverlayStartGesture.test.ts‎

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,95 @@ describe("a group drag of elements without GSAP", () => {
146146
expect(updates.map((update) => update.plainTranslate)).toEqual([true, true]);
147147
});
148148
});
149+
150+
describe("a rotate on a page that loads GSAP", () => {
151+
it("never asks GSAP about an element it does not turn, and draws the turn as its CSS rotate", () => {
152+
const getProperty = vi.fn(() => 0);
153+
const set = vi.fn();
154+
const element = document.createElement("div");
155+
element.style.setProperty("rotate", "30deg");
156+
document.body.append(element);
157+
Object.assign(window, {
158+
gsap: { getProperty, set },
159+
__timelines: { main: { getChildren: () => [] } },
160+
});
161+
const selection = { element, capabilities: { canApplyManualRotation: true } };
162+
const ref = <T>(current: T) => ({ current });
163+
const opts = {
164+
selectionRef: ref(selection as unknown as DomEditSelection),
165+
overlayRectRef: ref({ left: 0, top: 0, width: 50, height: 40, editScaleX: 1, editScaleY: 1 }),
166+
boxRef: ref(document.createElement("div")),
167+
overlayRef: ref(null),
168+
iframeRef: ref(null),
169+
gestureRef: ref<GestureState | null>(null),
170+
groupGestureRef: ref(null),
171+
blockedMoveRef: ref(null),
172+
rafPausedRef: ref(false),
173+
onCanvasPointerMoveRef: ref(vi.fn()),
174+
};
175+
const pointer = (clientX: number, clientY: number) => ({
176+
clientX,
177+
clientY,
178+
pointerId: 1,
179+
button: 0,
180+
shiftKey: false,
181+
preventDefault() {},
182+
stopPropagation() {},
183+
currentTarget: { setPointerCapture() {} },
184+
});
185+
186+
const handlers = createDomEditOverlayGestureHandlers(opts as never);
187+
expect(handlers.startGesture("rotate", pointer(25, -20) as never)).toBe(true);
188+
expect(opts.gestureRef.current?.plainRotation).toEqual({
189+
property: "rotate",
190+
before: "",
191+
after: "",
192+
share: 0,
193+
sign: 1,
194+
inline: false,
195+
});
196+
expect(opts.gestureRef.current?.actualRotation).toBeCloseTo(30);
197+
handlers.onPointerMove(pointer(60, 20) as never);
198+
199+
expect(element.style.getPropertyValue("rotate")).toMatch(/deg$/);
200+
expect(element.style.getPropertyValue("rotate")).not.toBe("30deg");
201+
expect(getProperty).not.toHaveBeenCalled();
202+
expect(set).not.toHaveBeenCalled();
203+
});
204+
});
205+
206+
describe("a rotate press on an element a GSAP tween turns", () => {
207+
it.each(["rotation", "rotate", "rotateZ"])("reads its base from GSAP (%s)", (channel) => {
208+
const getProperty = vi.fn(() => 40);
209+
const element = document.createElement("div");
210+
document.body.append(element);
211+
const tween = { targets: () => [element], vars: { [channel]: 40 }, duration: () => 2 };
212+
const timelines = { main: { getChildren: () => [tween] } };
213+
Object.assign(window, { gsap: { getProperty, set: vi.fn() }, __timelines: timelines });
214+
const ref = <T>(current: T) => ({ current });
215+
const selection = { element, capabilities: { canApplyManualRotation: true } };
216+
const opts = {
217+
selectionRef: ref(selection as unknown as DomEditSelection),
218+
overlayRectRef: ref({ left: 0, top: 0, width: 50, height: 40, editScaleX: 1, editScaleY: 1 }),
219+
boxRef: ref(document.createElement("div")),
220+
overlayRef: ref(null),
221+
iframeRef: ref(null),
222+
gestureRef: ref<GestureState | null>(null),
223+
rafPausedRef: ref(false),
224+
};
225+
const press = {
226+
clientX: 25,
227+
clientY: -20,
228+
pointerId: 1,
229+
button: 0,
230+
preventDefault() {},
231+
stopPropagation() {},
232+
currentTarget: { setPointerCapture() {} },
233+
};
234+
const handlers = createDomEditOverlayGestureHandlers(opts as never);
235+
expect(handlers.startGesture("rotate", press as never)).toBe(true);
236+
expect(opts.gestureRef.current?.plainRotation).toBeNull();
237+
expect(opts.gestureRef.current?.actualRotation).toBe(40);
238+
expect(getProperty).toHaveBeenCalledWith(element, "rotation");
239+
});
240+
});

‎packages/studio/src/components/editor/domEditOverlayStartGesture.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@ import { type DomEditSelection } from "./domEditing";
66
import {
77
applyManualOffsetDragDraft,
88
createManualOffsetDragMember,
9-
readGsapRotation,
109
restoreManualOffsetDragMembers,
1110
type ManualOffsetDragMember,
1211
} from "./manualOffsetDrag";
12+
import { readCssRotationTarget, readRotationBase } from "./rotationDraft";
1313
import {
1414
beginStudioManualEditGesture,
1515
captureStudioBoxSize,
1616
captureStudioPathOffset,
1717
captureStudioRotation,
1818
readStudioBoxSize,
19-
readStudioRotation,
2019
} from "./manualEdits";
2120
import {
2221
type OverlayRect,
@@ -32,6 +31,7 @@ import {
3231
type UseDomEditOverlayGesturesOptions,
3332
} from "./domEditOverlayGestures";
3433
import { collectSnapContext, buildExcludeElements } from "./snapTargetCollection";
34+
import { gsapWritesRotation } from "../../hooks/gsapRuntimeKeyframes";
3535
import { logResize, resetResizeMoveLog } from "../../utils/resizeDebug";
3636
import { logDrag, readDragPositions, resetDragMoveLog } from "../../utils/dragDebug";
3737

@@ -219,10 +219,11 @@ export function startGesture(
219219
}
220220
}
221221

222-
// Rotation base = GSAP's rotation plus the legacy `--hf-studio-rotation` var. A plain-translate
223-
// move never asks GSAP: reading a property makes it bake the CSS translate into its transform.
224-
const gsapRotation = pathOffsetMember?.plainTranslate ? 0 : readGsapRotation(sel.element);
225-
const rotation = { angle: gsapRotation + readStudioRotation(sel.element).angle };
222+
// Rotation base: the angle the element shows. An element GSAP does not turn, or a plain-translate
223+
// move, never asks GSAP: reading a property makes it bake the CSS into its transform.
224+
const plain = !!pathOffsetMember?.plainTranslate || !gsapWritesRotation(sel.element);
225+
const plainRotation = plain && kind === "rotate" ? readCssRotationTarget(sel.element) : null;
226+
const rotation = { angle: readRotationBase(sel.element, plain) };
226227
const overlayBounds = overlayEl?.getBoundingClientRect();
227228
const centerX = (overlayBounds?.left ?? 0) + rect.left + rect.width / 2;
228229
const centerY = (overlayBounds?.top ?? 0) + rect.top + rect.height / 2;
@@ -270,6 +271,7 @@ export function startGesture(
270271
actualWidth,
271272
actualHeight,
272273
actualRotation: rotation.angle,
274+
plainRotation,
273275
editScaleX: rect.editScaleX,
274276
editScaleY: rect.editScaleY,
275277
contentScaleX,

‎packages/studio/src/components/editor/manualEdits.test.ts‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
applyStudioPathOffset,
1111
applyStudioPathOffsetDraft,
1212
applyStudioRotation,
13-
applyStudioRotationDraft,
1413
beginStudioManualEditGesture,
1514
captureStudioBoxSize,
1615
captureStudioRotation,
@@ -210,16 +209,11 @@ describe("studio manual edits", () => {
210209
expect(card.style.getPropertyValue("rotate")).toContain(STUDIO_ROTATION_PROP);
211210
expect(card.style.getPropertyValue("transform-origin")).toBe("center center");
212211

213-
applyStudioRotationDraft(card, { angle: -12.2604 });
214-
expect(readStudioRotation(card)).toEqual({ angle: -12.26 });
215-
expect(card.style.getPropertyValue("rotate")).toBe("calc(8deg + -12.26deg)");
216-
expect(card.style.getPropertyValue("transform-origin")).toBe("center center");
217-
218212
const snapshot = captureStudioRotation(card);
219-
applyStudioRotationDraft(card, { angle: 45 });
213+
applyStudioRotation(card, { angle: 45 });
220214
restoreStudioRotation(card, snapshot);
221-
expect(readStudioRotation(card)).toEqual({ angle: -12.26 });
222-
expect(card.style.getPropertyValue("rotate")).toBe("calc(8deg + -12.26deg)");
215+
expect(readStudioRotation(card)).toEqual({ angle: 24.247 });
216+
expect(card.style.getPropertyValue(STUDIO_ROTATION_PROP)).toBe("24.247deg");
223217
expect(card.style.getPropertyValue("transform-origin")).toBe("center center");
224218
});
225219

‎packages/studio/src/components/editor/manualEdits.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export {
2929
applyStudioBoxSize,
3030
applyStudioBoxSizeDraft,
3131
applyStudioRotation,
32-
applyStudioRotationDraft,
3332
} from "./manualEditsDom";
3433

3534
export { reapplyPositionEditsAfterSeek } from "./manualEditsSeekReapply";

‎packages/studio/src/components/editor/manualEditsDom.ts‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -538,13 +538,3 @@ export function applyStudioRotation(element: HTMLElement, rotation: { angle: num
538538
composeStudioRotationValue(element, `var(${STUDIO_ROTATION_PROP}, 0deg)`),
539539
);
540540
}
541-
542-
export function applyStudioRotationDraft(element: HTMLElement, rotation: { angle: number }): void {
543-
promoteInlineForTransform(element);
544-
writeStudioRotationVars(element, rotation, { updateBase: false });
545-
element.setAttribute(STUDIO_ROTATION_DRAFT_ATTR, "true");
546-
element.style.setProperty(
547-
"rotate",
548-
composeStudioRotationValue(element, `${roundTo3(rotation.angle)}deg`),
549-
);
550-
}

‎packages/studio/src/components/editor/manualEditsDomPatches.test.ts‎

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import {
4646
buildClearPathOffsetPatches,
4747
buildBoxSizePatches,
4848
buildClearBoxSizePatches,
49-
buildRotationPatches,
5049
buildClearRotationPatches,
5150
buildMotionPatches,
5251
buildClearMotionPatches,
@@ -335,45 +334,7 @@ describe("anchored-corner combined patch: [...buildBoxSizePatches, ...buildPathO
335334

336335
/* ── Rotation ────────────────────────────────────────────────────────────── */
337336

338-
describe("buildRotationPatches / buildClearRotationPatches", () => {
339-
function populatedRotEl(): HTMLElement {
340-
const e = div();
341-
e.style.setProperty(STUDIO_ROTATION_PROP, "45");
342-
e.style.setProperty("rotate", "45deg");
343-
e.style.setProperty("transform-origin", "left center");
344-
e.style.setProperty("display", "block");
345-
e.setAttribute(STUDIO_ORIGINAL_ROTATE_ATTR, "0deg");
346-
e.setAttribute(STUDIO_ORIGINAL_INLINE_ROTATE_ATTR, "0deg");
347-
e.setAttribute(STUDIO_ORIGINAL_ROTATION_TRANSFORM_ORIGIN_ATTR, "center center");
348-
e.setAttribute(STUDIO_ORIGINAL_TRANSFORM_DISPLAY_ATTR, "flex");
349-
return e;
350-
}
351-
352-
it("populated: captures rotation styles, attrs, and transform-display marker in declaration order", () => {
353-
const ops = buildRotationPatches(populatedRotEl());
354-
expect(ops).toEqual([
355-
{ type: "inline-style", property: STUDIO_ROTATION_PROP, value: "45" },
356-
{ type: "inline-style", property: "rotate", value: "45deg" },
357-
{ type: "inline-style", property: "transform-origin", value: "left center" },
358-
{ type: "inline-style", property: "display", value: "block" },
359-
{ type: "attribute", property: STUDIO_ROTATION_ATTR, value: "true" },
360-
{ type: "attribute", property: STUDIO_ORIGINAL_ROTATE_ATTR, value: "0deg" },
361-
{ type: "attribute", property: STUDIO_ORIGINAL_INLINE_ROTATE_ATTR, value: "0deg" },
362-
{
363-
type: "attribute",
364-
property: STUDIO_ORIGINAL_ROTATION_TRANSFORM_ORIGIN_ATTR,
365-
value: "center center",
366-
},
367-
{ type: "attribute", property: STUDIO_ORIGINAL_TRANSFORM_DISPLAY_ATTR, value: "flex" },
368-
]);
369-
});
370-
371-
it("empty: bare element yields only the rotation marker", () => {
372-
expect(buildRotationPatches(div())).toEqual([
373-
{ type: "attribute", property: STUDIO_ROTATION_ATTR, value: "true" },
374-
]);
375-
});
376-
337+
describe("buildClearRotationPatches", () => {
377338
it("clear: restores rotate and transform-origin from orig attrs, nulls draft attr", () => {
378339
const e = div();
379340
e.setAttribute(STUDIO_ORIGINAL_INLINE_ROTATE_ATTR, "30deg");
@@ -405,11 +366,6 @@ describe("buildRotationPatches / buildClearRotationPatches", () => {
405366
const ops = buildClearRotationPatches(e);
406367
expect(ops.find((o) => o.property === "rotate")?.value).toBeNull();
407368
});
408-
409-
it("build/clear symmetry: clear addresses every {type,property} key that build emits", () => {
410-
const e = populatedRotEl();
411-
assertClearCoversKeys(buildRotationPatches(e), buildClearRotationPatches(e));
412-
});
413369
});
414370

415371
/* ── Motion ──────────────────────────────────────────────────────────────── */

‎packages/studio/src/components/editor/manualEditsDomPatches.ts‎

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -185,28 +185,6 @@ export function buildClearBoxSizePatches(element: HTMLElement): PatchOperation[]
185185

186186
/* ── Rotation patches ────────────────────────────────────────────── */
187187

188-
const ROTATION_STYLE_PROPS = [
189-
STUDIO_ROTATION_PROP,
190-
"rotate",
191-
"transform-origin",
192-
"display",
193-
] as const;
194-
195-
const ROTATION_ORIG_ATTRS = [
196-
STUDIO_ORIGINAL_ROTATE_ATTR,
197-
STUDIO_ORIGINAL_INLINE_ROTATE_ATTR,
198-
STUDIO_ORIGINAL_ROTATION_TRANSFORM_ORIGIN_ATTR,
199-
STUDIO_ORIGINAL_TRANSFORM_DISPLAY_ATTR,
200-
] as const;
201-
202-
export function buildRotationPatches(element: HTMLElement): PatchOperation[] {
203-
const ops: PatchOperation[] = [];
204-
collectInlineStyleOps(element, ROTATION_STYLE_PROPS, ops);
205-
ops.push({ type: "attribute", property: STUDIO_ROTATION_ATTR, value: "true" });
206-
collectAttributeOps(element, ROTATION_ORIG_ATTRS, ops);
207-
return ops;
208-
}
209-
210188
export function buildClearRotationPatches(element: HTMLElement): PatchOperation[] {
211189
const origInlineRotate = element.getAttribute(STUDIO_ORIGINAL_INLINE_ROTATE_ATTR);
212190
const origRotationTransformOrigin = element.getAttribute(

0 commit comments

Comments
 (0)