diff --git a/packages/block-editor/src/components/iframe/content.scss b/packages/block-editor/src/components/iframe/content.scss index 66e7e1071c5261..e23512a9ac12e7 100644 --- a/packages/block-editor/src/components/iframe/content.scss +++ b/packages/block-editor/src/components/iframe/content.scss @@ -22,7 +22,6 @@ } .block-editor-iframe__html { - border: 0 solid $gray-300; transform-origin: top center; @include editor-canvas-resize-animation; } @@ -38,14 +37,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 3e022cf95ae556..92c66f954704e3 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 new file mode 100644 index 00000000000000..dcddcdf0950a45 --- /dev/null +++ b/packages/block-editor/src/components/iframe/style.scss @@ -0,0 +1,17 @@ +.block-editor-iframe__container { + width: 100%; + height: 100%; + overflow-x: hidden; +} + +.block-editor-iframe__scale-container { + height: 100%; +} + +.block-editor-iframe__scale-container.is-zoomed-out { + $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); +}