@@ -15,6 +15,7 @@ import { getPhrase } from "WoltLabSuite/Core/Language";
1515import WoltlabCoreDialogElement from "WoltLabSuite/Core/Element/woltlab-core-dialog" ;
1616import * as ExifUtil from "WoltLabSuite/Core/Image/ExifUtil" ;
1717import ExifReader from "exifreader" ;
18+ import DomUtil from "WoltLabSuite/Core/Dom/Util" ;
1819
1920export interface CropperConfiguration {
2021 aspectRatio : number ;
@@ -27,8 +28,8 @@ export interface CropperConfiguration {
2728
2829function inSelection ( selection : Selection , maxSelection : Selection ) : boolean {
2930 return (
30- selection . x >= maxSelection . x &&
31- selection . y >= maxSelection . y &&
31+ Math . ceil ( selection . x ) >= maxSelection . x &&
32+ Math . ceil ( selection . y ) >= maxSelection . y &&
3233 Math . ceil ( selection . x + selection . width ) <= Math . ceil ( maxSelection . x + maxSelection . width ) &&
3334 Math . ceil ( selection . y + selection . height ) <= Math . ceil ( maxSelection . y + maxSelection . height )
3435 ) ;
@@ -83,6 +84,21 @@ abstract class ImageCropper {
8384
8485 this . createCropper ( ) ;
8586
87+ const resize = ( ) => {
88+ this . centerSelection ( ) ;
89+ } ;
90+
91+ window . addEventListener ( "resize" , resize , { passive : true } ) ;
92+ this . dialog . addEventListener (
93+ "afterClose" ,
94+ ( ) => {
95+ window . removeEventListener ( "resize" , resize ) ;
96+ } ,
97+ {
98+ once : true ,
99+ } ,
100+ ) ;
101+
86102 return new Promise < File > ( ( resolve , reject ) => {
87103 this . dialog ! . addEventListener ( "primary" , ( ) => {
88104 void this . getCanvas ( )
@@ -371,6 +387,12 @@ class MinMaxImageCropper extends ImageCropper {
371387 }
372388
373389 protected centerSelection ( ) : void {
390+ // Reset to get the maximum available height
391+ this . cropperCanvas ! . style . height = "" ;
392+
393+ const dimensions = DomUtil . outerDimensions ( this . cropperCanvas ! . parentElement ! ) ;
394+ this . cropperCanvas ! . style . height = `${ dimensions . height } px` ;
395+
374396 this . cropperImage ! . $center ( "contain" ) ;
375397 this . #cropperCanvasRect = this . cropperImage ! . getBoundingClientRect ( ) ;
376398
0 commit comments