(function(a,b){"object"==typeof exports&&"undefined"!=typeof module?module.exports=b():"function"==typeof define&&define.amd?define(b):(a="undefined"==typeof globalThis?a||self:globalThis,a.WZoom=b())})(this,function(){'use strict';var x=Math.min,y=Math.abs;function a(a,e){return b(a)||c(a,e)||d(a,e)||f()}function b(a){if(Array.isArray(a))return a}function c(a,b){var c=null==a?null:"undefined"!=typeof Symbol&&a[Symbol.iterator]||a["@@iterator"];if(null!=c){var d,e,f=[],g=!0,h=!1;try{for(c=c.call(a);!(g=(d=c.next()).done)&&(f.push(d.value),!(b&&f.length===b));g=!0);}catch(a){h=!0,e=a}finally{try{g||null==c["return"]||c["return"]()}finally{if(h)throw e}}return f}}function d(a,b){if(a){if("string"==typeof a)return e(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?e(a,b):void 0}}function e(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c=this.options.maxScale&&(this.options.minScale=null),this.window.$element=this.content.$element.parentNode,"image"===this.options.type){var d=!1;this.content.$element.complete&&(this._init(),d=!0),d&&!0!==this.options.watchImageChange||i(this.content.$element,"load",this._init,!this.options.watchImageChange&&{once:!0})}else this._init()}function q(a){this.options.disableWheelZoom||(a.preventDefault(),this._transform(this._computeNewPosition(this._computeNewScale(a.deltaY),{x:l(a),y:m(a)})))}function r(a){(this.isTouch&&1===a.touches.length||1===a.buttons)&&(this.coordsOnMouseDown={x:l(a),y:m(a)})}function s(a){this.coordsOnMouseDown&&this.coordsOnMouseDown.x===l(a)&&this.coordsOnMouseDown.y===m(a)&&(this._transform(this._computeNewPosition(1===this.direction?this.content.maxScale:this.content.minScale,{x:l(a),y:m(a)})),this.direction*=-1),this.coordsOnMouseDown=null}function t(a){var b=Math.round,c=Math.sqrt,d=Math.pow;if(2===a.targetTouches.length){var e=a.targetTouches[0].clientX,f=a.targetTouches[0].clientY,g=a.targetTouches[1].clientX,h=a.targetTouches[1].clientY,i=b(c(d(y(e-g),2)+d(y(f-h),2))),j=0;if(i>this.fingersHypot+5&&(j=-1),ia?1:-1;var b=this.content,c=b.minScale,d=b.maxScale,e=b.currentScale,f=e+this.direction/this.options.speed;return fd&&(this.direction=-1),fd?d:f},_computeNewPosition:function(a,b){var c=b.x,d=b.y,e=this.window,f=this.content,g=f.originalWidth*a,h=f.originalHeight*a,i=document,j=i.body,k=i.documentElement,l=e.pageXOffset||k.scrollLeft||j.scrollLeft,m=e.pageYOffset||k.scrollTop||j.scrollTop,n=c+l-e.positionLeft,o=e.originalWidth/2-n,p=o+f.currentLeft,q=p*(g/f.currentWidth)-p+f.currentLeft;if(-1===this.direction)switch(this.options.alignContent){case"left":g/2-qq?-1:1;q=((g-e.originalWidth)/2+f.correctX)*r}}var s=d+m-e.positionTop,t=e.originalHeight/2-s,u=t+f.currentTop,v=u*(h/f.currentHeight)-u+f.currentTop;switch(this.options.alignContent){case"top":h/2-vv?-1:1;v=((h-e.originalHeight)/2+f.correctY)*w}}a===this.content.minScale&&(q=this.content.alignPointX,v=this.content.alignPointY);var x={currentLeft:f.currentLeft,newLeft:q,currentTop:f.currentTop,newTop:v,currentScale:f.currentScale,newScale:a};return f.currentWidth=g,f.currentHeight=h,f.currentLeft=q,f.currentTop=v,f.currentScale=a,x},_transform:function(a){a.currentLeft;var b=a.newLeft;a.currentTop;var c=a.newTop;a.currentScale;var d=a.newScale;this.options.smoothExtinction?this.content.$element.style.transition="transform ".concat(this.options.smoothExtinction,"s"):this.content.$element.style.removeProperty("transition"),this.content.$element.style.transform="translate3d(".concat(b,"px, ").concat(c,"px, 0px) scale(").concat(d,")"),"function"==typeof this.options.rescale&&this.options.rescale()},_zoom:function(a){var b=g(this.window.$element),c=this.window,d=document,e=d.body,f=d.documentElement,h=c.pageXOffset||f.scrollLeft||e.scrollLeft,i=c.pageYOffset||f.scrollTop||e.scrollTop;this._transform(this._computeNewPosition(a,{x:b.left+this.window.originalWidth/2-h,y:b.top+this.window.originalHeight/2-i}))},prepare:function(){this._prepare()},zoomUp:function(){this._zoom(this._computeNewScale(-1))},zoomDown:function(){this._zoom(this._computeNewScale(1))},maxZoomUp:function(){this._zoom(this.content.maxScale)},maxZoomDown:function(){this._zoom(this.content.minScale)},setDragScrollable:function(a){this.dragScrollable=a},destroy:function(){for(var a in this.content.$element.style.transform="","image"===this.options.type&&j(this.content.$element,"load",this._init),this.isTouch&&(j(this.content.$element,"touchmove",this._zoomTwoFingers_TouchmoveHandler),j(this.content.$element,"touchend",this._zoomTwoFingers_TouchendHandler)),j(this.content.$element,"wheel",this._wheelHandler),this.options.zoomOnClick&&(j(this.content.$element,this.events.down,this._downHandler,this.events.options),j(this.content.$element,this.events.up,this._upHandler,this.events.options)),this.dragScrollable&&this.dragScrollable.destroy(),this)this.hasOwnProperty(a)&&(this[a]=null)}},p.create=function(a,b){return new p(a,b)},p});