mirror of
https://github.com/zadam/trilium.git
synced 2024-11-13 19:26:28 +08:00
2 lines
9.3 KiB
JavaScript
2 lines
9.3 KiB
JavaScript
|
(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 n=Math.abs;function a(a){var b=a.getBoundingClientRect(),c=document,d=c.body,e=c.documentElement,f=window.pageYOffset||e.scrollTop||d.scrollTop,g=window.pageXOffset||e.scrollLeft||d.scrollLeft,h=e.clientTop||d.clientTop||0,i=e.clientLeft||d.clientLeft||0,j=b.top+f-h,k=b.left+g-i;return{top:j,left:k}}function b(a,b){if(a&&b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}function c(a,b,c){var d=!!(3<arguments.length&&void 0!==arguments[3])&&arguments[3];a.addEventListener(b,c,d)}function d(a,b,c){var d=!!(3<arguments.length&&void 0!==arguments[3])&&arguments[3];a.removeEventListener(b,c,d)}function e(){return"ontouchstart"in window||0<navigator.MaxTouchPoints||0<navigator.msMaxTouchPoints}function f(a){return"wheel"===a.type||"mousedown"===a.type||"mousemove"===a.type||"mouseup"===a.type?a.clientX:a.changedTouches[0].clientX}function g(a){return"wheel"===a.type||"mousedown"===a.type||"mousemove"===a.type||"mouseup"===a.type?a.clientY:a.changedTouches[0].clientY}function h(a,d){var f=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};this._dropHandler=this._dropHandler.bind(this),this._grabHandler=this._grabHandler.bind(this),this._moveHandler=this._moveHandler.bind(this),this.options=b({smoothExtinction:!1,onGrab:null,onMove:null,onDrop:null},f),this.isTouch=e(),this.events=this.isTouch?{grab:"touchstart",move:"touchmove",drop:"touchend"}:{grab:"mousedown",move:"mousemove",drop:"mouseup"},this.events.options=!!this.isTouch&&{passive:!0},this.window=a,this.content=d,c(this.content.$element,this.events.grab,this._grabHandler,this.events.options)}function i(a,b){var c=b.left,d=b.top,e=b.scale;a.style.transform="translate3d(".concat(c,"px, ").concat(d,"px, 0px) scale(").concat(e,")")}function j(a){var d=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};this._init=this._init.bind(this),this._prepare=this._prepare.bind(this),this._computeNewScale=this._computeNewScale.bind(this),this._computeNewPosition=this._computeNewPosition.bind(this),this._transform=this._transform.bind(this),this._wheelHandler=k.bind(this),this._downHandler=l.bind(this),this._upHandler=m.bind(this),this.content={},this.window={},this.isTouch=!1,this.events=null,this.direction=1,this.options=null,this.dragScrollable=null,this.clickExpired=!0;if(this.content.$element=document.querySelector(a),this.isTouch=e(),this.events=this.isTouch?{down:"touchstart",up:"touchend"}:{down:"mousedown",up:"mouseup"},this.events.options=!!this.isTouch&&{passive:!0},this.content.$element)if(this.options=b({type:"image",width:null,height:null,dragScrollable:!0,dragScrollableOptions:{},minScale:null,maxScale:1,speed:50,zoomOnClick:!0,watchImageChange:!0},d),this.options.minScale&&this.options.minScale>=this.options.maxScale&&(this.options.minScale=null),this.window.$element=this.content.$element.parentNode,"image"===this.options.type){var f=!1;this.content.$element.complete&&(this._init(),f=!0),f&&!0!==this.options.watchImageChange||c(this.content.$element,"load",this._init,!this.options.watchImageChange&&{once:!0})}else this._init()}function k(a){a.preventDefault(),this._transform(this._computeNewPosition(this._computeNewScale(a.deltaY),{x:f(a),y:g(a)}))}function l(a){var b=this;(this.isTouch&&1===a.touches.length||1===a.buttons)&&(this.clickExpired=!1,setTimeout(function(){return b.clickExpired=!0},150))}function m(a){this.clickExpired||(this._transform(this._computeNewPosition(1===this.direction?this.content.maxScale:this.content.minScale,{x:f(a),y:g(a)})),this.direction*=-1)}return h.prototype={constructor:h,window:null,content:null,isTouch:!1,isGrab:!1,events:null,moveTimer:null,options:{},coordinates:null,speed:null,_grabHandler:function(a){(this.isTouch&&1===a.touches.length||1===a.buttons)&&(!this.isTouch&&a.preventDefault(),this.isGrab=!0,this.coordinates={left:f(a),top:g(a)},this.speed={x:0,y:0},c(document,this.e
|