Skip to content

Commit acaae5c

Browse files
Image: Start the lightbox zoom from a rotated image's place
A rotation turns the figure around its centre, which its bounding box keeps. The zoom now places the unrotated image from that centre and the image's layout offset, instead of from the larger rotated bounding box.
1 parent 316992a commit acaae5c

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

  • packages/block-library/src/image

‎packages/block-library/src/image/view.js‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,8 +748,20 @@ const { state, actions, callbacks } = store(
748748
offsetWidth: originalWidth,
749749
offsetHeight: originalHeight,
750750
} = state.selectedImage.imageRef;
751-
let { x: screenPosX, y: screenPosY } =
752-
state.selectedImage.imageRef.getBoundingClientRect();
751+
// A rotation turns the figure around its centre, which its
752+
// bounding box keeps, so place the unrotated image from there.
753+
const figure = state.selectedImage.imageRef.offsetParent;
754+
const figureRect = figure.getBoundingClientRect();
755+
let screenPosX =
756+
figureRect.x +
757+
( figureRect.width - figure.offsetWidth ) / 2 +
758+
figure.clientLeft +
759+
state.selectedImage.imageRef.offsetLeft;
760+
let screenPosY =
761+
figureRect.y +
762+
( figureRect.height - figure.offsetHeight ) / 2 +
763+
figure.clientTop +
764+
state.selectedImage.imageRef.offsetTop;
753765

754766
// Natural ratio of the image clicked to open the lightbox.
755767
const naturalRatio = naturalWidth / naturalHeight;

0 commit comments

Comments
 (0)