|
8 | 8 | import type { GsapAnimation, PropertyGroupName } from "@hyperframes/core/gsap-parser"; |
9 | 9 | import type { DomEditSelection } from "../components/editor/domEditingTypes"; |
10 | 10 | import { clearStudioBoxSize } from "../components/editor/manualEdits"; |
| 11 | +import { |
| 12 | + STUDIO_ORIGINAL_BOX_HEIGHT_ATTR, |
| 13 | + STUDIO_ORIGINAL_BOX_WIDTH_ATTR, |
| 14 | +} from "../components/editor/manualEditsTypes"; |
11 | 15 | import { setElementGsapPosition } from "../utils/elementGsap"; |
12 | 16 | import { usePlayerStore } from "../player/store/playerStore"; |
13 | 17 | import { readAllAnimatedProperties, readGsapProperty } from "./gsapRuntimeReaders"; |
@@ -49,6 +53,26 @@ function synthesizeIdentityProps( |
49 | 53 | return id; |
50 | 54 | } |
51 | 55 |
|
| 56 | +/** |
| 57 | + * The element's box before the resize draft ran, in CSS pixels. |
| 58 | + * |
| 59 | + * Prefers the measurement the draft recorded. Falls back to the inline style it |
| 60 | + * saved for restoring, which is a real value for the elements that carry one, |
| 61 | + * and null when neither says anything. |
| 62 | + */ |
| 63 | +function originalBoxSize( |
| 64 | + el: HTMLElement | null, |
| 65 | + measuredAttr: string, |
| 66 | + inlineProperty: "width" | "height", |
| 67 | +): number | null { |
| 68 | + const measured = Number.parseFloat(el?.getAttribute(measuredAttr) ?? ""); |
| 69 | + if (Number.isFinite(measured) && measured > 0) return measured; |
| 70 | + const inline = Number.parseFloat( |
| 71 | + el?.getAttribute(`data-hf-studio-original-${inlineProperty}`) ?? "", |
| 72 | + ); |
| 73 | + return Number.isFinite(inline) && inline > 0 ? inline : null; |
| 74 | +} |
| 75 | + |
52 | 76 | // ── Resize intercept ────────────────────────────────────────────────────── |
53 | 77 |
|
54 | 78 | // fallow-ignore-next-line complexity |
@@ -162,10 +186,15 @@ export async function tryGsapResizeIntercept( |
162 | 186 | const el = iframe?.contentDocument?.querySelector(selector ?? "") as HTMLElement | null; |
163 | 187 | // The resize draft modifies el.style.width/height, so read the ORIGINAL |
164 | 188 | // dimensions saved by the draft system before it ran. |
165 | | - const origW = Number.parseFloat(el?.getAttribute("data-hf-studio-original-width") ?? ""); |
166 | | - const origH = Number.parseFloat(el?.getAttribute("data-hf-studio-original-height") ?? ""); |
167 | | - const cssW = Number.isFinite(origW) && origW > 0 ? origW : 200; |
168 | | - const cssH = Number.isFinite(origH) && origH > 0 ? origH : cssW; |
| 189 | + // |
| 190 | + // The measured box first, then the inline one. The inline attributes exist |
| 191 | + // to restore an inline style and are empty for anything sized by a |
| 192 | + // stylesheet, which is how compositions are written, so reading them alone |
| 193 | + // sent almost every element to the fallback below: a 630px chip scaled by |
| 194 | + // 630/200, landing over three times the size it was dropped at, and worse |
| 195 | + // on the next drag because the wrong scale then counted as its live one. |
| 196 | + const cssW = originalBoxSize(el, STUDIO_ORIGINAL_BOX_WIDTH_ATTR, "width") ?? 200; |
| 197 | + const cssH = originalBoxSize(el, STUDIO_ORIGINAL_BOX_HEIGHT_ATTR, "height") ?? cssW; |
169 | 198 | // `size` is the draft's CSS box; on screen it is multiplied by the element's |
170 | 199 | // LIVE scale (the draft divides the cursor delta by it — see |
171 | 200 | // resolveDomEditResizeGesture). The committed keyframe REPLACES that live |
|
0 commit comments