Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Iframe: scale html instead of iframe el for zoom out
  • Loading branch information
ellatrix committed Feb 24, 2024
commit a08499b087e66cf2a389b7b17635387c4d5a8f8e
31 changes: 17 additions & 14 deletions packages/block-editor/src/components/iframe/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ function Iframe( {
tabIndex = 0,
scale = 1,
frameSize = 0,
expand = false,
readonly,
forwardedRef: ref,
...props
Expand Down Expand Up @@ -241,6 +240,22 @@ function Iframe( {
// top or bottom margin is 0.55 / 2 ((1 - scale) / 2).
const marginFromScaling = ( contentHeight * ( 1 - scale ) ) / 2;

useEffect( () => {
if ( iframeDocument && scale !== 1 ) {
iframeDocument.documentElement.style.transform = `scale( ${ scale } )`;
iframeDocument.documentElement.style.transformOrigin = 'top center';
iframeDocument.documentElement.style.marginTop = `${ frameSize }px`;
iframeDocument.documentElement.style.marginBottom = `${
-marginFromScaling * 2 + frameSize
}px`;
return () => {
iframeDocument.documentElement.style.transform = '';
iframeDocument.documentElement.style.marginTop = '';
iframeDocument.documentElement.style.marginBottom = '';
};
}
}, [ scale, frameSize, marginFromScaling, iframeDocument ] );

return (
<>
{ tabIndex >= 0 && before }
Expand All @@ -250,19 +265,7 @@ function Iframe( {
style={ {
border: 0,
...props.style,
height: expand ? contentHeight : props.style?.height,
marginTop:
scale !== 1
? -marginFromScaling + frameSize
: props.style?.marginTop,
marginBottom:
scale !== 1
? -marginFromScaling + frameSize
: props.style?.marginBottom,
transform:
scale !== 1
? `scale( ${ scale } )`
: props.style?.transform,
height: props.style?.height,
transition: 'all .3s',
} }
ref={ useMergeRefs( [ ref, setRef ] ) }
Expand Down