Skip to content

Commit

Permalink
Calculation in CSS
Browse files Browse the repository at this point in the history
  • Loading branch information
ajlende committed Oct 9, 2024
1 parent 6a247d6 commit 38de9fc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
6 changes: 6 additions & 0 deletions packages/block-editor/src/components/iframe/content.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@
$inner-height: var(--wp-block-editor-iframe-zoom-out-inner-height);
$content-height: var(--wp-block-editor-iframe-zoom-out-content-height);
$prev-container-width: var(--wp-block-editor-iframe-zoom-out-prev-container-width);
$container-width: var(--wp-block-editor-iframe-zoom-out-container-width, 100vw);
$max-width: 750px;

transform: scale(#{$scale});

&.is-default-scale {
transform: scale( calc( ( min( #{$container-width}, #{$max-width} ) - 2 * #{$frame-size} ) / #{$prev-container-width} ) );
}

background-color: $gray-300;

// Chrome seems to respect that transform scale shouldn't affect the layout size of the element,
Expand Down
14 changes: 8 additions & 6 deletions packages/block-editor/src/components/iframe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,13 @@ function Iframe( {

iframeDocument.documentElement.classList.add( 'is-zoomed-out' );

const maxWidth = 750;
if ( scale === 'default' ) {
iframeDocument.documentElement.classList.add( 'is-default-scale' );
}

iframeDocument.documentElement.style.setProperty(
'--wp-block-editor-iframe-zoom-out-scale',
scale === 'default'
? ( Math.min( containerWidth, maxWidth ) -
parseInt( frameSize ) * 2 ) /
prevContainerWidthRef.current
: scale
scale
);
iframeDocument.documentElement.style.setProperty(
'--wp-block-editor-iframe-zoom-out-frame-size',
Expand Down Expand Up @@ -356,6 +355,9 @@ function Iframe( {
iframeDocument.documentElement.style.removeProperty(
'--wp-block-editor-iframe-zoom-out-prev-container-width'
);
iframeDocument.documentElement.classList.remove(
'is-default-scale'
);
};
}, [
scale,
Expand Down

0 comments on commit 38de9fc

Please sign in to comment.