Skip to content

Commit 89143be

Browse files
committed
Merge branch 'file-upload-image-crop' into 6.2-user-coverphoto
2 parents 663c9a6 + 243135e commit 89143be

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

ts/WoltLabSuite/Core/Component/Image/Cropper.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { getPhrase } from "WoltLabSuite/Core/Language";
1515
import WoltlabCoreDialogElement from "WoltLabSuite/Core/Element/woltlab-core-dialog";
1616
import * as ExifUtil from "WoltLabSuite/Core/Image/ExifUtil";
1717
import ExifReader from "exifreader";
18+
import DomUtil from "WoltLabSuite/Core/Dom/Util";
1819

1920
export interface CropperConfiguration {
2021
aspectRatio: number;
@@ -27,8 +28,8 @@ export interface CropperConfiguration {
2728

2829
function 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

wcfsetup/install/files/js/WoltLabSuite/Core/Component/Image/Cropper.js

Lines changed: 17 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wcfsetup/install/files/style/ui/dialog.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,3 +465,13 @@ html[data-color-scheme="dark"] .dialog::backdrop {
465465
min-width: 0;
466466
}
467467
}
468+
469+
.dialog cropper-canvas {
470+
margin-left: auto;
471+
margin-right: auto;
472+
}
473+
474+
/* If the height of the image is many times greater than the width, a white area would be displayed at the bottom and/or top. */
475+
.dialog cropper-shade {
476+
outline-width: max(100vh, 100vw) !important;
477+
}

0 commit comments

Comments
 (0)