fix(core): a sealed scale resize shows its new scale once saved, not the old one (#8554)

* test(core): a sealed draft's cancel leaves a transform it never drew to GSAP

* fix(core): a sealed scale resize shows its new scale once saved, not the old one
This commit is contained in:
Miguel Ángel
2026-11-23 02:52:23 +00:00
committed by GitHub
parent 9ec93615ef
commit a50baed348
2 changed files with 20 additions and 3 deletions
@@ -104,6 +104,18 @@ describe("drafts", () => {
expect(element.style.translate).toBe("-50% -50%");
});
// fails without the fix: a sealed scale resize's cancel of its size draft put back the transform GSAP had at the
// gesture's start, so the new scale and position GSAP drew were wiped and the box showed off its drop until a reload.
it("leaves a transform it never drew to GSAP when it puts the rest back", () => {
const { element, handle } = card("transform: translate(10px, 0px); width: 50px");
drawDrafts([{ handle, translate: { x: 5, y: 0 }, size: { width: 80, height: 40 } }]);
element.style.transform = "translate(30px, 0px) scale(1.5, 1.5)";
drawDrafts([{ handle, end: "restore" }]);
expect(element.style.transform).toBe("translate(30px, 0px) scale(1.5, 1.5)");
expect(element.style.width).toBe("50px");
expect(element.style.translate).toBe("");
});
it("puts back only the part a draft stops drawing", () => {
const { element, handle } = card("height: 30px");
drawDrafts([{ handle, translate: { x: 1, y: 2 }, size: { width: 10, height: 10 } }]);
+8 -3
View File
@@ -26,6 +26,7 @@ interface Before {
translate: string[];
/** GSAP's rotation before the first GSAP turn drawn, to put back on "restore". */
gsapRotation?: number;
drewTransform?: boolean;
}
type Gsap = {
@@ -99,8 +100,9 @@ function beforeOf(element: Styled): Before {
}
function restore(element: Styled, names: readonly string[]): void {
for (const [name, value, priority] of before.get(element)?.inline ?? []) {
if (!names.includes(name)) continue;
const saved = before.get(element);
for (const [name, value, priority] of saved?.inline ?? []) {
if (!names.includes(name) || (name === "transform" && !saved?.drewTransform)) continue;
if (value) element.style.setProperty(name, value, priority);
else element.style.removeProperty(name);
}
@@ -142,11 +144,14 @@ function drawRotate(element: Styled, rotate: EditingDraftRotate | null): void {
const saved = beforeOf(element);
if (!rotate) {
restore(element, ["rotate", "transform"]);
saved.drewTransform = false;
return restoreGsapRotation(element);
}
if (rotate.route === "css") return void element.style.setProperty("rotate", `${rotate.angle}deg`);
if (rotate.route === "transform")
if (rotate.route === "transform") {
saved.drewTransform = true;
return void element.style.setProperty("transform", rotate.value);
}
const gsap = frameGsap();
saved.gsapRotation ??= Number(gsap?.getProperty?.(element, "rotation")) || 0;
element.style.setProperty("rotate", "none");