diff --git a/packages/block-editor/src/components/iframe/content.scss b/packages/block-editor/src/components/iframe/content.scss index 9e908da09c84f..206f1adf32946 100644 --- a/packages/block-editor/src/components/iframe/content.scss +++ b/packages/block-editor/src/components/iframe/content.scss @@ -3,7 +3,6 @@ } .block-editor-iframe__html { - border: 0 solid $gray-300; transform-origin: top center; @include editor-canvas-resize-animation; } @@ -19,14 +18,17 @@ background-color: $gray-300; - padding: calc(#{$frame-size} / #{$scale}) 0; - // Chrome seems to respect that transform scale shouldn't affect the layout size of the element, // so we need to adjust the height of the content to match the scale by using negative margins. $extra-content-height: calc(#{$content-height} * (1 - #{$scale})); - $total-frame-height: calc(2 * #{$frame-size}); + $total-frame-height: calc(2 * #{$frame-size} / #{$scale}); $total-height: calc(#{$extra-content-height} + #{$total-frame-height} + 2px); margin-bottom: calc(-1 * #{$total-height}); + // Add the top/bottom frame size. We use scaling to account for the left/right, as + // the padding left/right causes the contents to reflow, which breaks the 1:1 scaling + // of the content. + padding-top: calc(#{$frame-size} / #{$scale}); + padding-bottom: calc(#{$frame-size} / #{$scale}); body { min-height: calc((#{$inner-height} - #{$total-frame-height}) / #{$scale}); diff --git a/packages/block-editor/src/components/iframe/index.js b/packages/block-editor/src/components/iframe/index.js index fa7ce26526f41..d234339909a5c 100644 --- a/packages/block-editor/src/components/iframe/index.js +++ b/packages/block-editor/src/components/iframe/index.js @@ -306,13 +306,19 @@ function Iframe( { iframeDocument.documentElement.classList.add( 'is-zoomed-out' ); const maxWidth = 750; + // This scaling calculation has to happen within the JS because CSS calc() can + // only divide and multiply by a unitless value. I.e. calc( 100px / 2 ) is valid + // but calc( 100px / 2px ) is not. iframeDocument.documentElement.style.setProperty( '--wp-block-editor-iframe-zoom-out-scale', scale === 'default' - ? Math.min( containerWidth, maxWidth ) / + ? ( Math.min( containerWidth, maxWidth ) - + parseInt( frameSize ) * 2 ) / prevContainerWidthRef.current : scale ); + + // frameSize has to be a px value for the scaling and frame size to be computed correctly. iframeDocument.documentElement.style.setProperty( '--wp-block-editor-iframe-zoom-out-frame-size', typeof frameSize === 'number' ? `${ frameSize }px` : frameSize diff --git a/packages/block-editor/src/components/iframe/style.scss b/packages/block-editor/src/components/iframe/style.scss index e460df3ab3e0a..dcddcdf0950a4 100644 --- a/packages/block-editor/src/components/iframe/style.scss +++ b/packages/block-editor/src/components/iframe/style.scss @@ -12,5 +12,6 @@ $container-width: var(--wp-block-editor-iframe-zoom-out-container-width, 100vw); $prev-container-width: var(--wp-block-editor-iframe-zoom-out-prev-container-width, 100vw); width: $prev-container-width; + // This is to offset the movement of the iframe when we open sidebars margin-left: calc(-1 * (#{$prev-container-width} - #{$container-width}) / 2); }