Skip to content

Commit 98bff63

Browse files
committed
Simplify the constraints check
We can use the much simpler check for the canvas because it is guaranteed to be of the same size. Also we do not need to manually check for the size (and introduce rounding errors) because this is already performed by the cropper itself. See https://www.woltlab.com/community/thread/315990/
1 parent 44dd8d5 commit 98bff63

2 files changed

Lines changed: 0 additions & 45 deletions

File tree

  • ts/WoltLabSuite/Core/Component/Image
  • wcfsetup/install/files/js/WoltLabSuite/Core/Component/Image

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

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -204,31 +204,6 @@ abstract class ImageCropper {
204204
const selection = event.detail as Selection;
205205
this.cropperCanvasRect = this.cropperCanvas!.getBoundingClientRect();
206206

207-
// Calculate the scaling ratio because the lower and upper boundary are
208-
// defined in absolute values but the cropper will implicitly scale to fit
209-
// onto the available screen space. The cropper will preserve the aspect
210-
// ratio thus we only need to check the width.
211-
const scalingRatio = this.cropperCanvasRect.width / this.width;
212-
213-
// Enforce the upper and lower boundary of the dimensions. Any changes to
214-
// the position are also ignored at this point because we support
215-
// adjustments to the positions only as long as the dimensions are not
216-
// violated in either direction.
217-
const minWidth = this.minSize.width * scalingRatio;
218-
const maxWidth = Math.floor(Math.min(this.maxSize.width * scalingRatio, this.cropperCanvasRect.width));
219-
const minHeight = this.minSize.height * scalingRatio;
220-
const maxHeight = Math.floor(Math.min(this.maxSize.height * scalingRatio, this.cropperCanvasRect.height));
221-
if (
222-
selection.width < minWidth ||
223-
selection.width > maxWidth ||
224-
selection.height < minHeight ||
225-
selection.height > maxHeight
226-
) {
227-
event.preventDefault();
228-
229-
return;
230-
}
231-
232207
// Check if the position of the selection violates any of the boundaries
233208
// and move it accordingly.
234209
// See https://fengyuanchen.github.io/cropperjs/v2/api/cropper-selection.html#limit-boundaries

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

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

0 commit comments

Comments
 (0)