!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).panzoom=e()}}(function(){return function(){return function e(t,n,o){function r(a,c){if(!n[a]){if(!t[a]){var u="function"==typeof require&&require;if(!c&&u)return u(a,!0);if(i)return i(a,!0);var f=new Error("Cannot find module '"+a+"'");throw f.code="MODULE_NOT_FOUND",f}var s=n[a]={exports:{}};t[a][0].call(s.exports,function(e){return r(t[a][1][e]||e)},s,s.exports,e,t,n,o)}return n[a].exports}for(var i="function"==typeof require&&require,a=0;a<o.length;a++)r(o[a]);return r}}()({1:[function(e,t,n){"use strict";var o=e("wheel"),r=e("amator"),i=e("ngraph.events"),a=e("./lib/kinetic.js"),c=e("./lib/createTextSelectionInterceptor.js"),u=c(),f=c(!0),s=e("./lib/transform.js"),l=e("./lib/svgController.js"),m=e("./lib/domController.js"),d=1,h=1.75,p=300;function v(e,t){var n=(t=t||{}).controller;if(n||(l.canAttach(e)?n=l(e,t):m.canAttach(e)&&(n=m(e,t))),!n)throw new Error("Cannot create panzoom for the current type of dom element");var c=n.getOwner(),v={x:0,y:0},g=!1,E=new s;n.initTransform&&n.initTransform(E);var C,A="function"==typeof t.filterKey?t.filterKey:w,S="number"==typeof t.pinchSpeed?t.pinchSpeed:1,T=t.bounds,M="number"==typeof t.maxZoom?t.maxZoom:Number.POSITIVE_INFINITY,k="number"==typeof t.minZoom?t.minZoom:0,j="number"==typeof t.boundsPadding?t.boundsPadding:.05,F="number"==typeof t.zoomDoubleClickSpeed?t.zoomDoubleClickSpeed:h,L=t.beforeWheel||w,B=t.beforeMouseDown||w,O="number"==typeof t.zoomSpeed?t.zoomSpeed:d,D=y(t.transformOrigin),z=t.enableTextSelection?f:u;!function(e){var t=typeof e;if("undefined"===t||"boolean"===t)return;if(!(x(e.left)&&x(e.top)&&x(e.bottom)&&x(e.right)))throw new Error("Bounds object is not valid. It can be: undefined, boolean (true|false) or an object {left, top, right, bottom}")}(T),t.autocenter&&function(){var e,t,o=0,r=0,i=$();if(i)o=i.left,r=i.top,e=i.right-i.left,t=i.bottom-i.top;else{var a=c.getBoundingClientRect();e=a.width,t=a.height}var u=n.getBBox();if(0===u.width||0===u.height)return;var f=t/u.height,s=e/u.width,l=Math.min(s,f);E.x=-(u.left+u.width/2)*l+e/2+o,E.y=-(u.top+u.height/2)*l+t/2+r,E.scale=l}();var q,N,I,Z,P,R,V,W,Y=0,G=!1,K=!1;P="smoothScroll"in t&&!t.smoothScroll?{start:w,stop:w,cancel:w}:a(function(){return{x:E.x,y:E.y}},function(e,t){Ae(),H(e,t)},t.smoothScroll);var U=!1;re();var X={dispose:function(){ie()},moveBy:oe,moveTo:H,centerOn:function(e){var t=e.ownerSVGElement;if(!t)throw new Error("ui element is required to be within the scene");var n=e.getBoundingClientRect(),o=n.left+n.width/2,r=n.top+n.height/2,i=t.getBoundingClientRect(),a=i.width/2-o,c=i.height/2-r;oe(a,c,!0)},zoomTo:Ce,zoomAbs:ne,smoothZoom:be,smoothZoomAbs:function(e,t,n){var o={scale:E.scale},i={scale:n};P.cancel(),Ae(),V=r(o,i,{step:function(n){ne(e,t,n.scale)}})},showRectangle:function(e){var t=c.getBoundingClientRect(),n=_(t.width,t.height),o=e.right-e.left,r=e.bottom-e.top;if(!Number.isFinite(o)||!Number.isFinite(r))throw new Error("Invalid rectangle");var i=n.x/o,a=n.y/r,u=Math.min(i,a);E.x=-(e.left+o/2)*u+n.x/2,E.y=-(e.top+r/2)*u+n.y/2,E.scale=u},pause:function(){ie(),U=!0},resume:function(){U&&(re(),U=!1)},isPaused:function(){return U},getTransform:function(){return E},getMinZoom:function(){return k},setMinZoom:function(e){k=e},getMaxZoom:function(){return M},setMaxZoom:function(e){M=e},getTransformOrigin:function(){return D},setTransformOrigin:function(e){D=y(e)},getZoomSpeed:function(){return O},setZoomSpeed:function(e){if(!Number.isFinite(e))throw new Error("Zoom speed should be a number");O=e}};return i(X),X;function _(e,t){if(n.getScreenCTM){var o=n.getScreenCTM(),r=o.a,i=o.d,a=o.e,c=o.f;v.x=e*r-a,v.y=t*i-c}else v.x=e,v.y=t;return v}function H(e,t){E.x=e,E.y=t,Q(),je("pan"),ee()}function J(e,t){H(E.x+e,E.y+t)}function Q(){var e=$();if(e){var t,o,r,i,a=!1,c=(t=n.getBBox(),r=t.left,i=t.top,{left:(o={x:r*E.scale+E.x,y:i*E.scale+E.y}).x,top:o.y,right:t.width*E.scale+o.x,bottom:t.height*E.scale+o.y}),u=e.left-c.right;return u>0&&(E.x+=u,a=!0),(u=e.right-c.left)<0&&(E.x+=u,a=!0),(u=e.top-c.bottom)>0&&(E.y+=u,a=!0),(u=e.bottom-c.top)<0&&(E.y+=u,a=!0),a}}function $(){if(T){if("boolean"==typeof T){var e=c.getBoundingClientRect(),t=e.width,n=e.height;return{left:t*j,top:n*j,right:t*(1-j),bottom:n*(1-j)}}return T}}function ee(){g=!0,C=window.requestAnimationFrame(ae)}function te(e,t,n){if(b(e)||b(t)||b(n))throw new Error("zoom requires valid numbers");var o=E.scale*n;if(o<k){if(E.scale===k)return;n=k/E.scale}if(o>M){if(E.scale===M)return;n=M/E.scale}var r=_(e,t);(E.x=r.x-n*(r.x-E.x),E.y=r.y-n*(r.y-E.y),T&&1===j&&1===k)?(E.scale*=n,Q()):Q()||(E.scale*=n);je("zoom"),ee()}function ne(e,t,n){te(e,t,n/E.scale)}function oe(e,t,n){if(!n)return J(e,t);R&&R.cancel();var o=0,i=0;R=r({x:0,y:0},{x:e,y:t},{step:function(e){J(e.x-o,e.y-i),o=e.x,i=e.y}})}function re(){c.addEventListener("mousedown",he,{passive:!1}),c.addEventListener("dblclick",de,{passive:!1}),c.addEventListener("touchstart",ue,{passive:!1}),c.addEventListener("keydown",ce,{passive:!1}),o.addWheelListener(c,we,{passive:!1}),ee()}function ie(){o.removeWheelListener(c,we),c.removeEventListener("mousedown",he),c.removeEventListener("keydown",ce),c.removeEventListener("dblclick",de),c.removeEventListener("touchstart",ue),C&&(window.cancelAnimationFrame(C),C=0),P.cancel(),ye(),ge(),z.release(),Me()}function ae(){g&&(g=!1,n.applyTransform(E),je("transform"),C=0)}function ce(e){var t=0,n=0,o=0;if(38===e.keyCode?n=1:40===e.keyCode?n=-1:37===e.keyCode?t=1:39===e.keyCode?t=-1:189===e.keyCode||109===e.keyCode?o=1:187!==e.keyCode&&107!==e.keyCode||(o=-1),!A(e,t,n,o)){if(t||n){e.preventDefault(),e.stopPropagation();var r=c.getBoundingClientRect();oe(.05*(i=Math.min(r.width,r.height))*t,.05*i*n)}if(o){var i,a=Se(100*o);Ce((i=D?Ee():{x:(u=c.getBoundingClientRect()).width/2,y:u.height/2}).x,i.y,a)}var u}}function ue(e){if(function(e){if(t.onTouch&&!t.onTouch(e))return;e.stopPropagation(),e.preventDefault()}(e),1===e.touches.length)return function(e){var t=xe(e.touches[0]);q=t;var n=_(t.x,t.y);N=n.x,I=n.y,P.cancel(),fe()}(e,e.touches[0]);2===e.touches.length&&(Z=me(e.touches[0],e.touches[1]),W=!0,fe())}function fe(){G||(G=!0,document.addEventListener("touchmove",se),document.addEventListener("touchend",le),document.addEventListener("touchcancel",le))}function se(e){if(1===e.touches.length){e.stopPropagation();var t=_((s=xe(e.touches[0])).x,s.y),n=t.x-N,o=t.y-I;0!==n&&0!==o&&Te(),N=t.x,I=t.y,oe(n,o)}else if(2===e.touches.length){W=!0;var r=e.touches[0],i=e.touches[1],a=me(r,i),c=1+(a/Z-1)*S,u=xe(r),f=xe(i);if(N=(u.x+f.x)/2,I=(u.y+f.y)/2,D){var s=Ee();N=s.x,I=s.y}Ce(N,I,c),Z=a,e.stopPropagation(),e.preventDefault()}}function le(e){if(e.touches.length>0){var t=_((n=xe(e.touches[0])).x,n.y);N=t.x,I=t.y}else{var n,o=new Date;if(o-Y<p)if(D)be((n=Ee()).x,n.y,F);else be(q.x,q.y,F);Y=o,Me(),ge()}}function me(e,t){var n=e.clientX-t.clientX,o=e.clientY-t.clientY;return Math.sqrt(n*n+o*o)}function de(e){if(!function(e){return!(!t.onDoubleClick||t.onDoubleClick(e))||(e.preventDefault(),e.stopPropagation(),!1)}(e)){var n=xe(e);D&&(n=Ee()),be(n.x,n.y,F)}}function he(e){if(!B(e)){if(G)return e.stopPropagation(),!1;if(1===e.button&&null!==window.event||0===e.button){P.cancel();var t=xe(e),n=_(t.x,t.y);return N=n.x,I=n.y,document.addEventListener("mousemove",pe),document.addEventListener("mouseup",ve),z.capture(e.target||e.srcElement),!1}}}function pe(e){if(!G){Te();var t=xe(e),n=_(t.x,t.y),o=n.x-N,r=n.y-I;N=n.x,I=n.y,oe(o,r)}}function ve(){z.release(),Me(),ye()}function ye(){document.removeEventListener("mousemove",pe),document.removeEventListener("mouseup",ve),K=!1}function ge(){document.removeEventListener("touchmove",se),document.removeEventListener("touchend",le),document.removeEventListener("touchcancel",le),K=!1,W=!1,G=!1}function we(e){if(!L(e)){P.cancel();var t=e.deltaY;e.deltaMode>0&&(t*=100);var n=Se(t);if(1!==n){var o=D?Ee():xe(e);Ce(o.x,o.y,n),e.preventDefault()}}}function xe(e){var t=c.getBoundingClientRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}function be(e,t,n){var o=E.scale,i={scale:o},a={scale:n*o};P.cancel(),Ae(),V=r(i,a,{step:function(n){ne(e,t,n.scale)},done:ke})}function Ee(){var e=c.getBoundingClientRect();return{x:e.width*D.x,y:e.height*D.y}}function Ce(e,t,n){return P.cancel(),Ae(),te(e,t,n)}function Ae(){V&&(V.cancel(),V=null)}function Se(e){return 1-Math.sign(e)*Math.min(.25,Math.abs(O*e/128))}function Te(){K||(je("panstart"),K=!0,P.start())}function Me(){K&&(W||P.stop(),je("panend"))}function ke(){je("zoomend")}function je(e){X.fire(e,X)}}function y(e){if(e)return"object"==typeof e?(x(e.x)&&x(e.y)||g(e),e):void g()}function g(e){throw console.error(e),new Error(["Cannot parse transform origin.","Some good examples:",'  "center center" can be achieved with {x: 0.5, y: 0.5}','  "top center" can be achieved with {x: 0.5, y: 0}','  "bottom right" can be achieved with {x: 1, y: 1}'].join("\n"))}function w(){}function x(e){return Number.isFinite(e)}function b(e){return Number.isNaN?Number.isNaN(e):e!=e}t.exports=v,function(){if("undefined"!=typeof document){var e=document.getElementsByTagName("script");if(e){for(var t,n=0;n<e.length;++n){var o=e[n];if(o.src&&o.src.match(/\bpanzoom(\.min)?\.js/)){t=o;break}}if(t){var r=t.getAttribute("query");if(r){var i=t.getAttribute("name")||"pz",a=Date.now();!function e(){var n=document.querySelector(r);if(!n){var o=Date.now(),u=o-a;return u<2e3?void setTimeout(e,100):void console.error("Cannot find the panzoom element",i)}var f=function(e){for(var t=e.attributes,n={},o=0;o<t.length;++o){var r=t[o],i=c(r);i&&(n[i.name]=i.value)}return n}(t);console.log(f),window[i]=v(n,f)}()}}}}function c(e){if(e.name&&"p"===e.name[0]&&"z"===e.name[1]&&"-"===e.name[2])return{name:e.name.substr(3),value:JSON.parse(e.value)}}}()},{"./lib/createTextSelectionInterceptor.js":2,"./lib/domController.js":3,"./lib/kinetic.js":4,"./lib/svgController.js":5,"./lib/transform.js":6,amator:7,"ngraph.events":9,wheel:10}],2:[function(e,t,n){function o(e){return e.stopPropagation(),!1}function r(){}t.exports=function(e){if(e)return{capture:r,release:r};var t,n,i,a=!1;return{capture:function(e){a=!0,n=window.document.onselectstart,i=window.document.ondragstart,window.document.onselectstart=o,(t=e).ondragstart=o},release:function(){if(!a)return;a=!1,window.document.onselectstart=n,t&&(t.ondragstart=i)}}}},{}],3:[function(e,t,n){function o(e){return e&&e.parentElement&&e.style}t.exports=function(e,t){if(!o(e))throw new Error("panzoom requires DOM element to be attached to the DOM tree");var n=e.parentElement;e.scrollTop=0,t.disableKeyboardInteraction||n.setAttribute("tabindex",0);return{getBBox:function(){return{left:0,top:0,width:e.clientWidth,height:e.clientHeight}},getOwner:function(){return n},applyTransform:function(t){e.style.transformOrigin="0 0 0",e.style.transform="matrix("+t.scale+", 0, 0, "+t.scale+", "+t.x+", "+t.y+")"}}},t.exports.canAttach=o},{}],4:[function(e,t,n){function o(){return"function"==typeof cancelAnimationFrame?cancelAnimationFrame:clearTimeout}function r(){return"function"==typeof requestAnimationFrame?requestAnimationFrame:function(e){return setTimeout(e,16)}}t.exports=function(e,t,n){"object"!=typeof n&&(n={});var i,a,c,u,f,s,l,m,d,h,p="number"==typeof n.minVelocity?n.minVelocity:5,v="number"==typeof n.amplitude?n.amplitude:.25,y="function"==typeof n.cancelAnimationFrame?n.cancelAnimationFrame:o(),g="function"==typeof n.requestAnimationFrame?n.requestAnimationFrame:r(),w=342;return{start:function(){i=e(),s=d=u=l=0,a=new Date,y(c),y(h),c=g(x)},stop:function(){y(c),y(h);var t=e();f=t.x,m=t.y,a=Date.now(),(u<-p||u>p)&&(f+=s=v*u);(l<-p||l>p)&&(m+=d=v*l);h=g(b)},cancel:function(){y(c),y(h)}};function x(){var t=Date.now(),n=t-a;a=t;var o=e(),r=o.x-i.x,f=o.y-i.y;i=o;var s=1e3/(1+n);u=.8*r*s+.2*u,l=.8*f*s+.2*l,c=g(x)}function b(){var e=Date.now()-a,n=!1,o=0,r=0;s&&((o=-s*Math.exp(-e/w))>.5||o<-.5?n=!0:o=s=0),d&&((r=-d*Math.exp(-e/w))>.5||r<-.5?n=!0:r=d=0),n&&(t(f+o,m+r),h=g(b))}}},{}],5:[function(e,t,n){function o(e){return e&&e.ownerSVGElement&&e.getCTM}t.exports=function(e,t){if(!o(e))throw new Error("svg element is required for svg.panzoom to work");var n=e.ownerSVGElement;if(!n)throw new Error("Do not apply panzoom to the root <svg> element. Use its child instead (e.g. <g></g>). As of March 2016 only FireFox supported transform on the root element");t.disableKeyboardInteraction||n.setAttribute("tabindex",0);return{getBBox:function(){var t=e.getBBox();return{left:t.x,top:t.y,width:t.width,height:t.height}},getScreenCTM:function(){var e=n.getCTM();if(!e)return n.getScreenCTM();return e},getOwner:function(){return n},applyTransform:function(t){e.setAttribute("transform","matrix("+t.scale+" 0 0 "+t.scale+" "+t.x+" "+t.y+")")},initTransform:function(t){var o=e.getCTM();null===o&&(o=document.createElementNS("http://www.w3.org/2000/svg","svg").createSVGMatrix());t.x=o.e,t.y=o.f,t.scale=o.a,n.removeAttributeNS(null,"viewBox")}}},t.exports.canAttach=o},{}],6:[function(e,t,n){t.exports=function(){this.x=0,this.y=0,this.scale=1}},{}],7:[function(e,t,n){var o=e("bezier-easing"),r={ease:o(.25,.1,.25,1),easeIn:o(.42,0,1,1),easeOut:o(0,0,.58,1),easeInOut:o(.42,0,.58,1),linear:o(0,0,1,1)};function i(){}function a(){var e=new Set,t=new Set,n=0;return{next:o,cancel:o,clearAll:function(){e.clear(),t.clear(),cancelAnimationFrame(n),n=0}};function o(e){t.add(e),n||(n=requestAnimationFrame(r))}function r(){n=0;var o=t;t=e,(e=o).forEach(function(e){e()}),e.clear()}}t.exports=function(e,t,n){var o=Object.create(null),a=Object.create(null),c="function"==typeof(n=n||{}).easing?n.easing:r[n.easing];c||(n.easing&&console.warn("Unknown easing function in amator: "+n.easing),c=r.ease);var u="function"==typeof n.step?n.step:i,f="function"==typeof n.done?n.done:i,s=function(e){if(!e){var t="undefined"!=typeof window&&window.requestAnimationFrame;return t?{next:window.requestAnimationFrame.bind(window),cancel:window.cancelAnimationFrame.bind(window)}:{next:function(e){return setTimeout(e,1e3/60)},cancel:function(e){return clearTimeout(e)}}}if("function"!=typeof e.next)throw new Error("Scheduler is supposed to have next(cb) function");if("function"!=typeof e.cancel)throw new Error("Scheduler is supposed to have cancel(handle) function");return e}(n.scheduler),l=Object.keys(t);l.forEach(function(n){o[n]=e[n],a[n]=t[n]-e[n]});var m,d="number"==typeof n.duration?n.duration:400,h=Math.max(1,.06*d),p=0;return m=s.next(function t(){var n=c(p/h);p+=1,function(t){l.forEach(function(n){e[n]=a[n]*t+o[n]})}(n),p<=h?(m=s.next(t),u(e)):(m=0,setTimeout(function(){f(e)},0))}),{cancel:function(){s.cancel(m),m=0}}},t.exports.makeAggregateRaf=a,t.exports.sharedScheduler=a()},{"bezier-easing":8}],8:[function(e,t,n){var o=4,r=.001,i=1e-7,a=10,c=11,u=1/(c-1),f="function"==typeof Float32Array;function s(e,t){return 1-3*t+3*e}function l(e,t){return 3*t-6*e}function m(e){return 3*e}function d(e,t,n){return((s(t,n)*e+l(t,n))*e+m(t))*e}function h(e,t,n){return 3*s(t,n)*e*e+2*l(t,n)*e+m(t)}function p(e){return e}t.exports=function(e,t,n,s){if(!(0<=e&&e<=1&&0<=n&&n<=1))throw new Error("bezier x values must be in [0, 1] range");if(e===t&&n===s)return p;for(var l=f?new Float32Array(c):new Array(c),m=0;m<c;++m)l[m]=d(m*u,e,n);function v(t){for(var f=0,s=1,m=c-1;s!==m&&l[s]<=t;++s)f+=u;var p=f+(t-l[--s])/(l[s+1]-l[s])*u,v=h(p,e,n);return v>=r?function(e,t,n,r){for(var i=0;i<o;++i){var a=h(t,n,r);if(0===a)return t;t-=(d(t,n,r)-e)/a}return t}(t,p,e,n):0===v?p:function(e,t,n,o,r){var c,u,f=0;do{(c=d(u=t+(n-t)/2,o,r)-e)>0?n=u:t=u}while(Math.abs(c)>i&&++f<a);return u}(t,f,f+u,e,n)}return function(e){return 0===e?0:1===e?1:d(v(e),t,s)}}},{}],9:[function(e,t,n){t.exports=function(e){!function(e){if(!e)throw new Error("Eventify cannot use falsy object as events subject");for(var t=["on","fire","off"],n=0;n<t.length;++n)if(e.hasOwnProperty(t[n]))throw new Error("Subject cannot be eventified, since it already has property '"+t[n]+"'")}(e);var t=function(e){var t=Object.create(null);return{on:function(n,o,r){if("function"!=typeof o)throw new Error("callback is expected to be a function");var i=t[n];return i||(i=t[n]=[]),i.push({callback:o,ctx:r}),e},off:function(n,o){var r=void 0===n;if(r)return t=Object.create(null),e;if(t[n]){var i="function"!=typeof o;if(i)delete t[n];else for(var a=t[n],c=0;c<a.length;++c)a[c].callback===o&&a.splice(c,1)}return e},fire:function(n){var o,r=t[n];if(!r)return e;arguments.length>1&&(o=Array.prototype.splice.call(arguments,1));for(var i=0;i<r.length;++i){var a=r[i];a.callback.apply(a.ctx,o)}return e}}}(e);return e.on=t.on,e.off=t.off,e.fire=t.fire,e}},{}],10:[function(e,t,n){function o(e,t,n){e.addEventListener("wheel",t,n)}t.exports=o,t.exports.addWheelListener=o,t.exports.removeWheelListener=function(e,t,n){e.removeEventListener("wheel",t,n)}},{}]},{},[1])(1)});
