fix(studio): a layer with a min(), max() or clamp() translate moves from where it really is - #4832
Merged
Merged
Conversation
…ithout a jump at press
Edit accuracy: 494 passing here, 494 on the base branchThe gate passes. |
…ve percent against the transform box
… offset it already read
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes
A layer without GSAP whose CSS
translateusesmin(),max()orclamp()now moves from where it really is. That includes a layer that has atransformtransition.To read such a translate, main wrote a temporary inline
transformonto the layer and read it back. If the layer hastransition: transform ..., the browser reports the transition's starting value instead, so main read the layer's offset as 0,0. The drag then started off by the layer's own translate: 46.65 px fortranslate: clamp(0px, 10%, 30px) min(40px, 25%)on a 240x160 box. The drop landed that far off, and the file got the wrong translate. Without a transition, main's temporary write is removed in the same step of code and no frame shows it. Measured in the built Studio, both main and this branch then have a press jump of 0 px.How
readTranslatePx(plainTranslate.ts) now evaluates the computedtranslateitself: px, %,calc(),min(),max(),clamp(), parentheses and+ - * /. It reads the computed value first, where Chrome has already resolvedem,vw,vh,var()and simplifiable functions such asabs(-10%), so only % is left to work out. % resolves against the boxtransform-boxnames: the content box forcontent-boxandfill-box, otherwise the border box. The temporary-transform reader is deleted.Anything outside that grammar, such as
abs(10% - 50px)orround(10%, 7px), which Chrome keeps unresolved, evaluates to NaN rather than to a guess. Studio then refuses to move the layer, says why, and leaves the layer as it was:Checked in headless Chrome 152 against the layer's real on-screen movement, including padding and border, for eleven values:
em,vwandvhinside them;calc(50% / 3);abs(-10%).All eleven match to 0.0001 px.
Tests
plainTranslate.test.ts:plainTranslate.tsin place, 9 of the original 18 fail, the MutationObserver one included.manualOffsetDrag.test.ts: "refuses a translate it can't read instead of guessing". It fails with the guard removed.previewReadOnly.overlay.test.tsx: "refuses a drag and an arrow nudge out loud, and commits nothing". It fails if the reason isn't passed on.propertyPanelTransformCommit.test.ts: the X/Y fields "are disabled" and "commit nothing and say why". The latter fails with the panel guard removed.Before
Main, a layer without GSAP with
translate: clamp(0px, 10%, 30px) min(40px, 25%)andtransition: transform 0.4s, dragged +90/+60. The layer is off by 46.65 px (its own translate) from the first move to the drop, and the file savestranslate: 90px 60pxinstead of114px 100px. The dashed outline and cross mark where it was released.After
Same layer and gesture on this branch. It is 0 px off at every step and at the drop, and the file saves
translate: 114px 100px.