diff --git a/packages/block-library/src/media-text/edit.js b/packages/block-library/src/media-text/edit.js index 8ea6752c62663..f41b0309d0024 100644 --- a/packages/block-library/src/media-text/edit.js +++ b/packages/block-library/src/media-text/edit.js @@ -168,7 +168,7 @@ function MediaTextEdit( { attributes, isSelected, setAttributes } ) { const imperativeFocalPointPreview = ( value ) => { const { style } = refMediaContainer.current.resizable; const { x, y } = value; - style.backgroundPosition = `${ x * 100 }% ${ y * 100 }%`; + style.objectPosition = `${ x * 100 }% ${ y * 100 }%`; }; const [ temporaryMediaWidth, setTemporaryMediaWidth ] = useState( null ); @@ -252,7 +252,7 @@ function MediaTextEdit( { attributes, isSelected, setAttributes } ) { } /> ) } - { imageFill && mediaUrl && mediaType === 'image' && ( + { imageFill && mediaUrl && ( {}; -export function imageFillStyles( url, focalPoint ) { - return url - ? { - backgroundImage: `url(${ url })`, - backgroundPosition: focalPoint - ? `${ Math.round( focalPoint.x * 100 ) }% ${ Math.round( - focalPoint.y * 100 - ) }%` - : `50% 50%`, - } - : {}; +export function imageFillStyles( focalPoint ) { + return { + objectPosition: focalPoint + ? `${ Math.round( focalPoint.x * 100 ) }% ${ Math.round( + focalPoint.y * 100 + ) }%` + : `50% 50%`, + }; +} + +export function focalPosition( { x, y } = DEFAULT_FOCAL_POINT ) { + return `${ Math.round( x * 100 ) }% ${ Math.round( y * 100 ) }%`; } const ResizableBoxContainer = forwardRef( @@ -132,14 +134,15 @@ function MediaContainer( props, ref ) { left: enableResize && mediaPosition === 'right', }; - const backgroundStyles = - mediaType === 'image' && imageFill - ? imageFillStyles( mediaUrl, focalPoint ) - : {}; + const mediaStyles = imageFill ? imageFillStyles( focalPoint ) : {}; const mediaTypeRenderers = { - image: () => {, - video: () =>