3 lines
4.7 KiB
JavaScript
3 lines
4.7 KiB
JavaScript
/*! @svgdotjs/svg.panzoom.js v2.1.2 MIT*/;
|
|
!function(D){"use strict";function G(t){return t.touches||[{clientX:t.clientX,clientY:t.clientY}]}D.extend(D.Svg,{panZoom:function(t){var n,e,i,o,a,l,h,s,c,E,u,V=this;if(this.off(".panZoom"),!1===t)return this;function m(t){if(!_)return t;var n=_.top,e=_.left,i=_.bottom,o=_.right,a=V.attr(["width","height"]),l=a.width,h=a.height,s=V.node.preserveAspectRatio.baseVal,c=0,E=0,u=0,m=0;if(s.align!==s.SVG_PRESERVEASPECTRATIO_NONE){var p=l/h,r=x.width/x.height;if(r!=p){var S=s.meetOrSlice!==s.SVG_MEETORSLICE_SLICE,R=r<p?"width":"height",M="width"==R,A=S&&M||!S&&!M,v=A?p/r:r/p,f=t[R]-t[R]*v;A?s.align===s.SVG_PRESERVEASPECTRATIO_XMIDYMIN||s.align===s.SVG_PRESERVEASPECTRATIO_XMIDYMID||s.align===s.SVG_PRESERVEASPECTRATIO_XMIDYMAX?(c=f/2,E=-f/2):s.align===s.SVG_PRESERVEASPECTRATIO_XMINYMIN||s.align===s.SVG_PRESERVEASPECTRATIO_XMINYMID||s.align===s.SVG_PRESERVEASPECTRATIO_XMINYMAX?E=-f:s.align!==s.SVG_PRESERVEASPECTRATIO_XMAXYMIN&&s.align!==s.SVG_PRESERVEASPECTRATIO_XMAXYMID&&s.align!==s.SVG_PRESERVEASPECTRATIO_XMAXYMAX||(c=f):s.align===s.SVG_PRESERVEASPECTRATIO_XMINYMID||s.align===s.SVG_PRESERVEASPECTRATIO_XMIDYMID||s.align===s.SVG_PRESERVEASPECTRATIO_XMAXYMID?(u=f/2,m=-f/2):s.align===s.SVG_PRESERVEASPECTRATIO_XMINYMIN||s.align===s.SVG_PRESERVEASPECTRATIO_XMIDYMIN||s.align===s.SVG_PRESERVEASPECTRATIO_XMAXYMIN?m=-f:s.align!==s.SVG_PRESERVEASPECTRATIO_XMINYMAX&&s.align!==s.SVG_PRESERVEASPECTRATIO_XMIDYMAX&&s.align!==s.SVG_PRESERVEASPECTRATIO_XMAXYMAX||(u=f)}}var d=x.width+x.x-e-c,I=x.x+o-t.width-E,X=x.height+x.y-n-u,P=x.y+i-t.height-m;return t.x=Math.min(d,Math.max(I,t.x)),t.y=Math.min(X,Math.max(P,t.y)),t}function p(t){(S=G(t)).length<2?d&&X&&Z.call(this,t):(d&&X&&O.call(this,t),t.preventDefault(),this.dispatch("pinchZoomStart",{event:t}).defaultPrevented||(this.off("touchstart.panZoom",p),Y=!0,D.on(document,"touchmove.panZoom",w,this,{passive:!1}),D.on(document,"touchend.panZoom",g,this,{passive:!1})))}var r,S,R=null!=(n=(t=null!=t?t:{}).zoomFactor)?n:2,M=null!=(e=t.zoomMin)?e:Number.MIN_VALUE,A=null!=(i=t.zoomMax)?i:Number.MAX_VALUE,v=null==(o=t.wheelZoom)||o,f=null==(a=t.pinchZoom)||a,d=null==(l=t.panning)||l,I=null!=(h=t.panButton)?h:0,X=null!=(s=t.oneFingerPan)&&s,_=null!=(c=t.margins)&&c,P=null!=(E=t.wheelZoomDeltaModeLinePixels)?E:17,T=null!=(u=t.wheelZoomDeltaModeScreenPixels)?u:53,Y=!1,x=this.viewbox(),g=function t(n){n.preventDefault();var e=G(n);1<e.length||(Y=!1,this.dispatch("pinchZoomEnd",{event:n}),D.off(document,"touchmove.panZoom",w),D.off(document,"touchend.panZoom",t),this.on("touchstart.panZoom",p),e.length&&d&&X&&Z.call(this,n))},w=function(t){t.preventDefault();var n=G(t),e=this.zoom(),i=Math.sqrt(Math.pow(S[0].clientX-S[1].clientX,2)+Math.pow(S[0].clientY-S[1].clientY,2))/Math.sqrt(Math.pow(n[0].clientX-n[1].clientX,2)+Math.pow(n[0].clientY-n[1].clientY,2));(e<M&&1<i||A<e&&i<1)&&(i=1);var o={x:n[0].clientX+.5*(n[1].clientX-n[0].clientX),y:n[0].clientY+.5*(n[1].clientY-n[0].clientY)},a=S[0].clientX+.5*(S[1].clientX-S[0].clientX),l=S[0].clientY+.5*(S[1].clientY-S[0].clientY),h=this.point(o.x,o.y),s=this.point(2*o.x-a,2*o.y-l),c=new D.Box(this.viewbox()).transform((new D.Matrix).translate(-s.x,-s.y).scale(i,0,0).translate(h.x,h.y));m(c),this.viewbox(c),S=n,this.dispatch("zoom",{box:c,focus:s})},Z=function t(n){-1<n.type.indexOf("mouse")&&n.button!==I&&n.which!==I+1||(n.preventDefault(),this.off("mousedown.panZoom",t),S=G(n),Y||(this.dispatch("panStart",{event:n}),r={x:S[0].clientX,y:S[0].clientY},D.on(document,"touchmove.panZoom mousemove.panZoom",C,this,{passive:!1}),D.on(document,"touchend.panZoom mouseup.panZoom",O,this,{passive:!1})))},O=function t(n){n.preventDefault(),D.off(document,"touchmove.panZoom mousemove.panZoom",C),D.off(document,"touchend.panZoom mouseup.panZoom",t),this.on("mousedown.panZoom",Z),this.dispatch("panEnd",{event:n})},C=function(t){t.preventDefault();var n=G(t),e={x:n[0].clientX,y:n[0].clientY},i=this.point(e.x,e.y),o=this.point(r.x,r.y),a=[o.x-i.x,o.y-i.y];if(a[0]||a[1]){var l=new D.Box(this.viewbox()).transform((new D.Matrix).translate(a[0],a[1]));r=e,m(l),this.dispatch("panning",{box:l,event:t}).defaultPrevented||this.viewbox(l)}};return v&&this.on("wheel.panZoom",function(t){var n;switch(t.preventDefault(),t.deltaMode){case 1:n=t.deltaY*P;break;case 2:n=t.deltaY*T;break;default:n=t.deltaY}var e=Math.pow(1+R,-1*n/100)*this.zoom(),i=this.point(t.clientX,t.clientY);if(A<e&&(e=A),e<M&&(e=M),this.dispatch("zoom",{level:e,focus:i}).defaultPrevented)return this;if(this.zoom(e,i),_){var o=m(this.viewbox());this.viewbox(o)}},this,{passive:!1}),f&&this.on("touchstart.panZoom",p,this,{passive:!1}),d&&this.on("mousedown.panZoom",Z,this,{passive:!1}),this}})}(SVG);
|
|
//# sourceMappingURL=svg.panzoom.min.js.map
|