feat: dynamic zoom limit on previewer

pull/1353/head
Ramires Viana 2021-03-25 19:36:53 +00:00
parent 87f1881b42
commit e410272e6b
1 changed files with 17 additions and 12 deletions

View File

@ -29,14 +29,6 @@ export default {
type: Number, type: Number,
default: () => 200, default: () => 200,
}, },
maxScale: {
type: Number,
default: () => 4,
},
minScale: {
type: Number,
default: () => 0.25,
},
classList: { classList: {
type: Array, type: Array,
default: () => [], default: () => [],
@ -45,10 +37,6 @@ export default {
type: Number, type: Number,
default: () => 0.25, default: () => 0.25,
}, },
autofill: {
type: Boolean,
default: () => false,
},
}, },
data() { data() {
return { return {
@ -64,6 +52,8 @@ export default {
center: { x: 0, y: 0 }, center: { x: 0, y: 0 },
relative: { x: 0, y: 0 }, relative: { x: 0, y: 0 },
}, },
maxScale: 4,
minScale: 0.25,
}; };
}, },
mounted() { mounted() {
@ -126,6 +116,21 @@ export default {
img.classList.add("image-ex-img-ready"); img.classList.add("image-ex-img-ready");
document.addEventListener("mouseup", this.onMouseUp); document.addEventListener("mouseup", this.onMouseUp);
let realSize = img.naturalWidth;
let displaySize = img.offsetWidth;
// Image is in portrait orientation
if (img.naturalHeight > img.naturalWidth) {
realSize = img.naturalHeight;
displaySize = img.offsetHeight;
}
// Scale needed to display the image on full size
const fullScale = realSize / displaySize;
// Full size plus additional zoom
this.maxScale = fullScale + 4;
}, },
onMouseUp() { onMouseUp() {
this.inDrag = false; this.inDrag = false;