Skip to content

Commit dbe5ef7

Browse files
committed
Fix incorrect min zoom and center point calculation
Center point calculation was broken by 00dd125. Also increased step precision of zoom slider to match Croppie (previously changed in 7bcc4f5). Closes #6
1 parent 1f1cb57 commit dbe5ef7

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/cropt.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function setZoomerVal(value: number, zoomer: HTMLInputElement) {
5656
const zMin = parseFloat(zoomer.min);
5757
const zMax = parseFloat(zoomer.max);
5858

59-
zoomer.value = Math.max(zMin, Math.min(zMax, value)).toFixed(3);
59+
zoomer.value = Math.max(zMin, Math.min(zMax, value)).toFixed(4);
6060
}
6161

6262
function loadImage(src: string): Promise<HTMLImageElement> {
@@ -177,7 +177,7 @@ export class Cropt {
177177
this.elements.boundary.appendChild(this.elements.overlay);
178178

179179
this.elements.zoomer.type = "range";
180-
this.elements.zoomer.step = "0.001";
180+
this.elements.zoomer.step = "0.0001";
181181
this.elements.zoomer.value = "1";
182182
this.elements.zoomer.setAttribute("aria-label", "zoom");
183183

@@ -644,6 +644,7 @@ export class Cropt {
644644
}
645645

646646
#updateCenterPoint(transform: Transform) {
647+
this.elements.preview.style.transform = transform.toString();
647648
const vpData = this.elements.viewport.getBoundingClientRect();
648649
const data = this.elements.preview.getBoundingClientRect();
649650
const curPos = new TransformOrigin(this.elements.preview);
@@ -675,8 +676,9 @@ export class Cropt {
675676
maxZoom += minZoom;
676677
}
677678

678-
this.elements.zoomer.min = minZoom.toFixed(3);
679-
this.elements.zoomer.max = maxZoom.toFixed(3);
679+
// min zoom cannot be rounded, or large images won't match the viewport size when zoomed out
680+
this.elements.zoomer.min = minZoom.toString();
681+
this.elements.zoomer.max = maxZoom.toString();
680682
let zoom = this.#boundZoom;
681683

682684
if (zoom === null) {

0 commit comments

Comments
 (0)