Skip to content

fix(studio): a cropped layer's outline is cut at the layer's own scale, sealed or not - #8496

Merged
miguel-heygen merged 4 commits into
mainfrom
fix/sealed-crop-outline-scale
Nov 22, 2026
Merged

miguel-heygen merged 4 commits into
mainfrom
fix/sealed-crop-outline-scale

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

What

A cropped layer that is scaled (by GSAP or CSS) now has its outlines cut at its visible edge, in a sealed preview and an unsealed one alike. This covers its outline in a group, as a child outline, in the hover and snap and marquee boxes, and the selection box's crop hug. Before, every one of these cut the crop at the editor's zoom alone, so a layer scaled up by 1.25 had its outline drawn past its visible edge, and one scaled down had it drawn short.

Why

A crop (clip-path: inset(...)) is in the layer's own CSS px, before its transform. To draw it on screen, Studio has to scale it by everything between the layer and the screen, the layer's own scale included. The one function that cut outlines to a crop (hugRectForClipPath) used the editor zoom only, and useCropOverlay kept its own copy of the same arithmetic.

In an unsealed preview Studio could read the layer's size from the element. In a sealed one it could not: the frame's geometry reply carried only the layer's on-screen box.

Related work

Follows #8468 (merged: the same layer's resize corners after a sealed Layers pick) and #8451 (the crop frame's insets at the layer's scale). #8451's press and selection read of the layer's size (gesture-start) could later come from this geometry reply instead.

How

  • Core (editingGeometry.ts): each geometry box carries the layer's own size, layout (offsetWidth/offsetHeight, 0 where there is none). gesture-start already sent that value and now takes it from the same boxOf, so there is one copy.
  • Studio:
    • The crop is scaled by the layer's own scale along its own edges (overlay px per CSS px), never by its axis-aligned box, which a turn widens.
      • Sealed: from the frame's reply, the length of the layer's transformed top and left edges (its corners) over its own size; an untransformed layer's box is its own box (previewOverlayRects.ts, carried as ownScale).
      • Unsealed: read off the live element only when it has a crop to cut, the same edges over its own size (liveOwnScale), so hover and snap rects of uncropped layers measure nothing extra.
    • hugRectForClipPath falls back to the zoom when the scale is unknown, as for a union of several layers.
    • useCropOverlay now uses it rather than its own arithmetic.
    • previewElements checks layout on every box; gesture-start no longer checks it separately.
  • Core (watchGeometry.ts): the per-frame geometry stream parses each element against an exact field list. Without layout in that list, every streamed element from the frame would be refused now that geometry carries it. The list takes layout with exact keys and each side a finite number from 0 to MAX_DRAFT_PX, the bound Studio's own geometry reader uses. MAX_DRAFT_PX moves to editingElement.ts beside the other shared limits (the stream module cannot import editingPort.ts, which imports it); editingPort.ts re-exports it.

Before

A cropped layer (clip-path: inset(0 150px 0 0)) that GSAP scales to 1.25, grouped with a plain square, in a sealed preview at main. The yellow layer's outline and the group box run past its visible right edge.

before, sealed

After

The same, with this change: the outline and the group box stop at the visible edge, sealed and unsealed alike.

after, sealed after, unsealed

Test plan

  • fails without the fix: packages/studio/src/components/editor/previewOverlayRects.test.ts ("cuts a scaled layer's crop at its own scale, the same in both"). It checks a layer shown at twice its own size, through a scriptable frame and through a sealed one running the real editing agent. With main's product code under the new tests, it fails: the member is not the 150 px wide its own scale makes it.
  • fails without the fix: packages/studio/src/hooks/useCropOverlay.test.ts ("a layer shown at twice its own size hugs its crop at that scale", sealed and unsealed). With main's product code: expected 150 to be 300.
  • fails without the fix: packages/core/src/runtime/editing/watchGeometry.test.ts ("takes what the frame measures, and a gone element as null"): with the geometry change but not the stream's, a measured element is refused (expected null). Refusal rows were added for a malformed layout: negative, over the bound, a string, an extra key, and missing.
  • On a Linux machine: the named tests pass 3 runs in a row; the 68 covering test files in core and studio pass; tsc --noEmit in core and studio, Fallow and pre-push are clean.
  • Real Studio from each commit's CLI build on a Linux machine (main sealed; this branch at d395ca39, sealed and unsealed; sealed confirmed by the frame's origin null), the walk above. The layer measures 300 px on screen for 240 of its own, so its visible part is 113 frame px, 19.6 overlay px at that zoom. Its outline in the group is 26 px wide at main sealed and 19 px with this change in both modes. The captures were taken at d395ca39; the same walk at f67c979 (the scale from the layer's own edges) measures the same 19 px in both modes.
  • fails without the fix: previewOverlayRects.test.ts ("cuts a turned, scaled layer's crop at its own scale, not its upright box's, the same in both"): a layer turned 30 degrees and scaled 2x with a 50 px right crop. Scaling by its upright box cut 167.4 px wide where its own edges make 173.2 (expected 167.40 to be close to 173.21).
  • The existing opaque-vs-scriptable cases compare every drawn field; the own scale is left out of that comparison, as a live rect works it out only when it cuts a crop.

Not exercised: macOS and Safari (Chrome on Linux only); a turned cropped layer in real Studio (covered by the test above through both kinds of frame); an SVG child, whose size reads 0 and falls back to the zoom as before.

  • Unit tests added/updated
  • Manual testing performed
  • Documentation updated (if applicable)
  • Comments follow CONTRIBUTING.md "Comments": they say why, not what, and a bug fix says what the code must do and how to reproduce the bug

@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Edit accuracy: accurate 271 (base branch 271), smooth 54 of those

The gate passes.
Smoothness is reported in the artifact, not gated. A case fails only if it fails 2 of 3 runs.

Quarantined, measured but not gated (0)

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes at 2d95ec27. The scaled case is fixed, but rotated cropped layers get a deeper wrong cut in two places.

Blocker: snap targets and marquee hit tests on rotated cropped layers.

  • hugScale (domEditOverlayCrop.ts) divides the rect's width by layout.width. frameRectToOverlay now attaches layout to the axis-aligned box, both in toOverlayRect (unsealed) and in baseRect (sealed).
  • For a rotated layer, that box is its bounding box, so the ratio picks up the turn as if it were scale.
  • Two paths hug that axis-aligned box:
    • toVisibleOverlayRect, used by snapTargetCollection.ts and marqueeCommit.ts:91;
    • flatVisibleRect, used by previewGestureStartRead.ts:87 for snap boxes and previewOverlayRects.ts:133.
  • Probe, run through hugRectForClipPath directly: a 200×200 layer turned 45° at zoom 1, with inset(0 100px 0 0). Its bounding box is 282.8 wide.
    • Main (zoom only) hugs to 182.8.
    • This head (with layout) hugs to 141.4.
    • The visible half's real bounding-box width is 212.1.
  • So snap edges and marquee hits now cut roughly a third of the visible part away, where main cut a seventh.
  • The body says "a rotated cropped layer's outline (its box is the rotated one, cut the same way as before)". That holds for the oriented paths (orientOverlayRect measures width from the corners), but not for these axis-aligned ones.
  • Suggested fix, smallest first:
    • attach layout only where the rect's width is the layer's own edge: in orientOverlayRect, or in frameRectToOverlay only when the box's angle is 0;
    • or have hugScale use the corner edge lengths when there are corners.
  • Please add a test row with a turned layer for flatVisibleRect and toVisibleOverlayRect.

What I checked and found fine

  • The scaled case. Shown size over own size covers the layer's own scale and any ancestor scale. offsetWidth and the bounding rect are both border-box, which is what inset() is measured from.
  • Fallbacks. SVG children (offsetWidth undefined → 0), unions and member rects (no layout) fall back to the zoom.
  • layout is checked on both sides. In watchGeometry it must have exactly the keys width,height, each finite and within 0..MAX_DRAFT_PX. In previewElements it is now part of isBox. gesture-start reads it from boxOf instead of keeping its own copy, and MAX_DRAFT_PX moving to editingElement.ts keeps the stream module off editingPort.ts.
  • useCropOverlay. It now derives its inset from hugRectForElement. The hug !== overlayRect identity check is right, because hugRectForClipPath returns the same rect when there is no crop.
  • Red first. With main's product code under the new tests, previewOverlayRects "cuts a scaled layer's crop at its own scale…" and both useCropOverlay "twice its own size" rows fail.
  • Tests at this head: core watchGeometry, editingGeometry, editingGestureStart and editingPort pass 42/42. Studio overlay, crop, geometry, preview-elements, marquee and off-canvas files pass 107/107.

Need: yes · Size: ok · Reuse: good (useCropOverlay drops its copy of the arithmetic, one layout source) · Simpler: yes · Structure: fine
Risk: medium. Every hugged outline goes through the new scale, including the axis-aligned rects of rotated layers.

— Rames (hf-review)

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve at f67c979d. The blocker from my last review is fixed.

Need ✅ · Size ✅ · Reuse ✅ (elementCornerPoints, cornerEdgeLength, one hugRectForClipPath) · Simpler ✅ · Structure ✅
Risk: low. The change touches only the overlay drawing, and a layer with no known size falls back to the zoom as before.

Blocker resolved: rotation is no longer counted as scale. The crop is now scaled by overlay px per CSS px along the layer's own edges:

  • Sealed: ownScaleOf takes the corner edge lengths over layout.
  • Unsealed: liveOwnScale reads the live element, and only when it has a crop to cut. On an oriented rect it divides the rect's own size by its offset* size. On a box aligned to the screen axes it divides the corner edges by getBoundingClientRect and scales that back to the overlay. Both come out in overlay px per CSS px.

What I checked:

  • Fails without the fix: I put the three product files back to the previous head 2d95ec27. The new turned-layer test fails (expected 167.40 to be close to 173.21), and so do both useCropOverlay rows.
  • At the head: 74/74 pass across previewOverlayRects, useCropOverlay and the domEditOverlay* tests. tsc --noEmit in studio is clean, and merge-tree against current main is clean.

Note (P2, already true on main, not this PR): for a turned layer, a box aligned to the screen axes is cut along screen axes by the crop scaled to the layer's own edges. The hover, snap and marquee boxes therefore come out a little narrower than the true box around the visible part. For a 45° 200×200 layer cut by inset(0 100px 0 0), the box is about 183 wide against a true 212, the same as main. The selection outline uses the oriented rect and is exact. A follow-up could cut the oriented rect first and then take its box.

— Rames (hf-review)

…ne-scale

# Conflicts:
#	packages/core/src/runtime/editingGestureStart.ts
#	packages/studio/src/player/lib/previewElements.ts

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-stamp at 6289e60e (merge of main into f67c979d, which I approved earlier).

Need ✅ · Size ✅ · Reuse ✅ · Simpler ✅ · Structure ✅
Risk: low. The only changes since my last approval are the two conflict resolutions.

  • Parents: f67c979d and main 45674e84. Running git merge-tree on those two conflicts in exactly editingGestureStart.ts and previewElements.ts. All other files merge on their own.
  • editingGestureStart.ts: keeps this PR's geometry.layout (no separate layout field, and measureGrowResponse(element, geometry.layout)) and keeps main's rotation/cssRotation read. Nothing still reads the dropped layout field.
  • previewElements.ts: isLayout stays inside isBox (this PR), and readGestureStart keeps main's cssRotation destructure and its kept(..., isCssRotation(...)) check.
  • Checks: tsc is clean for core and studio. Core editing tests: 422 pass. Studio overlay, crop and player/lib tests: 403 pass.

— Rames (hf-review)

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 22, 2026
Merged via the queue into main with commit 2b1495f Nov 22, 2026
101 checks passed
@miguel-heygen
miguel-heygen deleted the fix/sealed-crop-outline-scale branch November 22, 2026 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants