Repository navigation
fix(studio): a turned layer's cropped box is the bounds of its cut corners - #8502
Conversation
…rries its layout size
…ne-scale # Conflicts: # packages/core/src/runtime/editingGestureStart.ts # packages/studio/src/player/lib/previewElements.ts
terencecho
left a comment
There was a problem hiding this comment.
Two parity regressions in the cropped bounds:
- [P2] Opposing insets can cross in
cutCornersBounds. The min/max step then turns the crossed corners into a positive box. In a focused parity probe, a 200 px layer withinset(0px 120px 0px 120px)produced a 20 px-wide box in the scriptable preview at 0.5x and zero width in the sealed preview. CSS reduces opposing insets proportionally when their sum exceeds the reference dimension. Normalize them in the layer’s own space before projecting the corners. CSS Shapes inset rules - [P2] Reflections can have a reported angle of zero. A layer with
scaleX(-1)and a 50 px right inset now cuts the visual left edge in the scriptable preview. The sealed preview still cuts the visual right edge becauseboxOfsends corners only when the angle is nonzero. The same probe measured a 25 px difference in the overlay’s left edge. Provide equivalent corner data for zero-angle reflections, or preserve parity for them until both paths can use those corners.
The two existing focused test files passed, 40 tests total. Both additional parity probes failed on the reviewed head.
— tai (automated review)
…ge in both previews
…ygen-com/hyperframes into fix/turned-crop-box-bounds
terencecho
left a comment
There was a problem hiding this comment.
P2 — Preserve the painted size of upright layers with the CSS scale property. In domEditOverlayCrop.ts:298, the scriptable path uses reconstructed corners whenever a matrix snapshot exists. The transform walk only includes transform and rotate, so it reconstructs the unscaled corners of a layer with scale: 2. The sealed path uses the measured box for this case.
I ran the existing two-preview fixture with a 200 × 100 CSS box, scale: 2, and inset(0px 50px 0px 0px). At the fixture’s half-size preview, the width is 75 px scriptable and 150 px sealed. The base gives 175 px scriptable, so using the reconstructed corners introduces a further 100 px shrink. Use the measured box for a positive upright scale, or account for the individual scale before passing corners to the crop helper. Please cover the individual property as well as the existing transform: matrix(...) case.
All 46 existing targeted tests passed, including crossed insets and the mirror case.
— tai (automated review)
terencecho
left a comment
There was a problem hiding this comment.
[P2] A depth-only scale drops previously correct planar crop bounds. packages/core/src/runtime/elementTransform.ts:69 returns null for scale: 1 1 2, so the whole transform walk loses its rotation. For a flat 200×100 layer with transform: rotate(45deg) and a 50 px right inset, Chromium measures the same painted box with or without that depth scale. The overlay nevertheless falls back to cutting the axis-aligned box. Adding that single declaration to the existing rotated fixture produces 79.55×106.07 px at this head instead of 88.39×88.39 px. The same fixture passes in both preview modes with the previous transform walk. Preserve the planar transform when the Z scale has no effect on the geometry the overlay measures, and cover the case in the parity test.
The 47 existing focused overlay tests passed.
— tai (automated review)
terencecho
left a comment
There was a problem hiding this comment.
[P2] Nested 3D rotations ignore the browser’s default flattening. packages/core/src/runtime/elementTransform.ts multiplies the ancestor and child matrices as if they shared one 3D context. A parent with rotate: x 60deg and its child with rotate: x -60deg cancel in that product. With default transform-style: flat, Chrome instead paints the 200×100 child at 200×25. Adding this fixture to overlayTransform.browser.test.ts returned 200×100 for the measured corners and 200×25 for Chrome’s painted bounds. Carry flattening through the transform walk or fall back to measured bounds when the projection cannot be represented. The existing depth-only scale case passes in real Chrome, and all 43 focused tests passed before the added probe.
This head also conflicts with main in four editor overlay files. The required regression check reports cancelled shards.
— tai (automated review)
…ounds # Conflicts: # packages/studio/src/components/editor/domEditOverlayCrop.ts # packages/studio/src/components/editor/domEditOverlayGeometry.ts # packages/studio/src/components/editor/previewOverlayRects.test.ts # packages/studio/src/components/editor/previewOverlayRects.ts
Edit accuracy: accurate 271 (base branch 271), smooth 70 of thoseThe gate passes. Quarantined, measured but not gated (0) |
terencecho
left a comment
There was a problem hiding this comment.
P2 — Check planarity after composing the transform chain. In packages/core/src/runtime/elementTransform.ts, each matrix can pass the local planar check even when their product projects the child. In Chrome, a parent with transform: perspective(500px); transform-style: preserve-3d and a 200 × 100 child with transform: translateZ(100px) rotate(30deg) passes the walk. The returned corners span 223.2 × 186.6, while the browser paints 279.0 × 233.3. The crop code also dropped its former perspective check in this revision. Keep the per-node rejection for flattening and reject a projected composed result before returning corners, so it gets the documented painted-box fallback.
The 57 existing focused tests passed, including the nested-rotation fixture. The projected case fails in the same Chrome fixture.
— tai (automated review)
terencecho
left a comment
There was a problem hiding this comment.
P2 — The projected-box fallback still misses CSS's perspective property. In packages/core/src/runtime/elementTransform.ts, the transform walk reads the ancestor's rotate, scale, and transform, so neither planar check sees the projection from perspective: 500px. I kept the committed Chrome fixture's rotated, depth-translated child and used the perspective property on its parent. The overlay returned 223.2 × 186.6 while Chrome painted 279.0 × 233.3. Treat perspective established by an ancestor property as a reason to use the documented browser-box fallback.
All 57 committed focused tests passed, including the nested x-turn and transform: perspective(...) cases. The required regression gate is red after change detection was cancelled. CI
— tai (automated review)
terencecho
left a comment
There was a problem hiding this comment.
The 3D-context fallback resolves the perspective-property case. The real Chrome fixture verifies that both perspective spellings and preserved 3D fall back to the painted box, while the planar cases still use their transformed corners. All 79 focused Studio and core tests passed, and required CI is green.
— tai (automated review)
What
A turned, cropped layer's axis-aligned boxes (its outline in a group, its snap target and its marquee hit box) are now the bounds of the layer after its crop is cut along its own edges. Before, the crop was cut out of the axis-aligned box itself, so a turned layer's box came out the wrong size in both kinds of preview: a 200 x 100 layer turned 45 degrees with a 50 px right crop drew 81.1 x 106.1 overlay px where its cut shape spans 88.4 x 88.4.
Why
A crop (
clip-path: inset(...)) cuts the layer in its own space, before its transform. For a turned layer, its axis-aligned box is the bounds of its turned corners, so cutting insets straight off that box's sides removes the wrong amount from the wrong sides. The right box is: move each of the layer's own corners in by the insets along its own edges, then take the bounds of those four points. The selection's own box is already drawn turned with the layer and keeps cutting the turned box as before.How
cropRectFromInsets(domEditOverlayCrop.ts): the insets, in the layer's own CSS px times its own scale, cut along its own edges, and the result is the bounds of the four cut corners. Without corners its own edges are the box's, so an upright layer is cut as before.inset(), so a crop wider than its layer is a zero-width line at the same place in both previews.boxOf,editingGeometry.ts). Before, it sent them only for a nonzero angle, and a mirror reports angle 0. A plain positive scale still sends none, since its corners say nothing its box doesn't;liveOwnScale), mapped onto the axis-aligned rect.angle) keeps cutting its own turned box.elementTransform.ts): each node's matrix isnew DOMMatrix("<rotate> <scale> <transform>"). Its computedrotateandscaleare written as the CSS functions they stand for (x 30degbecomesrotateX(30deg),1 1 2becomesscale3d(1, 1, 2)), followed by its computedtransform, in the order CSS applies them. The browser does all the composing, 3D included. Corners in both previews and the crop frame's angle and scale (which readsa, b, c, doff the same matrix) come from it. The hand-written 2D algebra and the rotate and scale parsers are deleted.m13,m23,m14,m24nonzero, orm44not 1). CSS flattens such a layer into its parent, which a product of matrices does not reproduce. The check runs on each node and on the chain composed so far, so a perspective parent and a depth-moved child, flat on their own, fall back too; the crop frame's own perspective check folds into it. A layer inside any 3D context, meaning its parent has aperspectiveproperty ortransform-style: preserve-3d, falls back as well: those project children in ways the matrix walk does not see.matrix3dfor a flat spin and a depth-onlyscale: 1 1 2, since planarity is read from the values rather than fromDOMMatrix.is2D(false for anymatrix3dorscale3dform).translateis left out: it moves a box without changing its shape, corners are re-anchored to the measured box, andDOMMatrixthrows ontranslate(50%)(checked in Chrome 158), which a centered layer commonly carries.Test plan
packages/studio/src/components/editor/previewOverlayRects.test.ts("bounds a turned layer's cropped box by its cut corners, the same in both"): the 45 degree case through a scriptable frame and through a sealed one running the real editing agent. On the base it is 81.1 x 106.1 instead of 88.4 x 88.4.previewOverlayRects.test.ts("cuts a turned, scaled layer's crop at its own scale, along its own edges, the same in both"): 30 degrees, scaled 2x. On the base the width is 173.2 where the cut's bounds are 179.9 (and 167.4 before fix(studio): a cropped layer's outline is cut at the layer's own scale, sealed or not #8496).previewOverlayRects.test.ts("shrinks crossed insets until they meet, as CSS does, the same in both"): a half-scaled 200 px layer withinset(0 300px 0 100px). On the base the scriptable preview drew a 50 px box.previewOverlayRects.test.ts("cuts a mirrored layer's right inset off its visual left, the same in both"):scaleX(-1)with a 50 px right inset, measured against the same layer unmirrored. On the base one preview cut the visual right edge (offset 0 where 25 is right).packages/studio/src/components/editor/overlayTransform.browser.test.ts("reads every layer's painted corners as Chrome paints them"), in real Chrome. Each probe is a real CSS layer:transform: rotate(45deg); scale: 1 1 2,scale: 2,rotate: 45deg; scale: 2, a matrix, a mirror plusrotate,translate: 50%plusrotate,rotate: x 60deg, a nested pair turned about x, a flat spin written asmatrix3d, and a scaled, turned child of a turned parent. The corners must span what Chrome'sgetBoundingClientRectpaints, and the layer's own edges must have the expected scaled size. Layers turned out of their plane,rotate: x 60deg, a child turnedx -60deginside a parent turnedx 60deg, a child movedtranslateZ(100px)under aperspective(500px)parent that preserves 3D, the same child under a parent'sperspective: 500pxproperty, and a flat turned child of apreserve-3dparent, must be declined so callers use the painted box. Without the planar checks the nested pair cancels to 200 x 100 where Chrome paints 200 x 25, and the projected pair measures 223 x 187 where Chrome paints 279 x 233; the test fails at each. An earlier walk failed it at the depth-scaled layer, which it could not read at all.packages/core/src/runtime/elementTransform.test.ts: each computedrotateandscaleform Chrome serializes, as its CSS function.matrix/matrix3dcases (domEditOverlayCrop.test.ts) now run through the same matrix; their stand-in parses only those two forms, the only ones a computedtransformtakes.tsc --noEmitin core and studio, Fallow and pre-push are clean. The unturned scaled case ("cuts a scaled layer's crop at its own scale") is unchanged.null): the layer's box in the group measures 29 x 61 px on fix(studio): a cropped layer's outline is cut at the layer's own scale, sealed or not #8496 in both kinds of preview, and 38 x 38 with this change in both (walked at 0cae8fa; the later commit changes only crossed insets and mirrored layers, neither in this walk).Before
A cropped layer (
clip-path: inset(0 150px 0 0)) scaled to 1.25 by GSAP and turned 45 degrees (rotate: 45deg), grouped with a plain square, in a sealed preview on #8496. The layer's box is a tall, narrow pill: the visible yellow shape sticks out past its right side, and the group box runs far below it.After
The same, with this change: the layer's box wraps the visible turned shape, and the group box with it, sealed and unsealed alike.
Related work
Stacked on #8496 (a scaled layer's crop at its own scale), which this extends to turned layers.