summaryrefslogtreecommitdiffstats
path: root/dist/svg.min.js
blob: 0b5e35c236f91d5281b3bed8aaad2db7eee13122 (plain)
1
2
3
/*! svg.js v3.0.0 MIT*/;!function(t,e){"function"==typeof define&&define.amd?define(function(){return e(t,t.document)}):"object"==typeof exports?module.exports=t.document?e(t,t.document):function(t){return e(t,t.document)}:t.SVG=e(t,t.document)}("undefined"!=typeof window?window:this,function(t,e){function n(t){return s(t)||r(t)||i()}function i(){throw new TypeError("Invalid attempt to spread non-iterable instance")}function r(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}function s(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);e<t.length;e++)n[e]=t[e];return n}}function o(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function a(t,e,n){return e&&o(t.prototype,e),n&&o(t,n),t}function h(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function u(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{},i=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(n).filter(function(t){return Object.getOwnPropertyDescriptor(n,t).enumerable}))),i.forEach(function(e){l(t,e,n[e])})}return t}function l(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function c(t){return(c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function f(t,n){if(t instanceof q.Element)return t;if("object"===c(t))return q.adopt(t);if(null==t)return new q.Doc;if("string"==typeof t&&"<"!==t.charAt(0))return q.adopt(e.querySelector(t));var i=q.create("svg");return i.innerHTML=t,t=q.adopt(i.firstElementChild)}function d(t){return!(t.w||t.h||t.x||t.y)}function p(t){return(e.documentElement.contains||function(t){for(;t.parentNode;)t=t.parentNode;return t===e}).call(e.documentElement,t)}function m(t,e,n,i){return n+i.replace(q.regex.dots," .")}function v(t){for(var e=t.slice(0),n=e.length;n--;)Array.isArray(e[n])&&(e[n]=v(e[n]));return e}function y(t,e){return t instanceof e}function x(t,e){return(t.matches||t.matchesSelector||t.msMatchesSelector||t.mozMatchesSelector||t.webkitMatchesSelector||t.oMatchesSelector).call(t,e)}function g(t){return t.toLowerCase().replace(/-(.)/g,function(t,e){return e.toUpperCase()})}function w(t){return t.charAt(0).toUpperCase()+t.slice(1)}function b(t){return 4===t.length?["#",t.substring(1,2),t.substring(1,2),t.substring(2,3),t.substring(2,3),t.substring(3,4),t.substring(3,4)].join(""):t}function _(t){var e=t.toString(16);return 1===e.length?"0"+e:e}function A(t,e,n){if(null==e||null==n){var i=t.bbox();null==e?e=i.width/i.height*n:null==n&&(n=i.height/i.width*e)}return{width:e,height:n}}function M(t){return{a:t[0],b:t[1],c:t[2],d:t[3],e:t[4],f:t[5]}}function P(t){for(var e=0,n=t.length,i="";e<n;e++)i+=t[e][0],null!=t[e][1]&&(i+=t[e][1],null!=t[e][2]&&(i+=" ",i+=t[e][2],null!=t[e][3]&&(i+=" ",i+=t[e][3],i+=" ",i+=t[e][4],null!=t[e][5]&&(i+=" ",i+=t[e][5],i+=" ",i+=t[e][6],null!=t[e][7]&&(i+=" ",i+=t[e][7])))));return i+" "}function N(t){for(var e=t.children.length-1;e>=0;e--)N(t.children[e]);return t.id?q.adopt(t).id(q.eid(t.nodeName)):q.adopt(t)}function E(t){return null==t.x&&(t.x=0,t.y=0,t.width=0,t.height=0),t.w=t.width,t.h=t.height,t.x2=t.x+t.width,t.y2=t.y+t.height,t.cx=t.x+t.width/2,t.cy=t.y+t.height/2,t}function O(t){var e=(t||"").toString().match(q.regex.reference);if(e)return e[1]}function T(t,e,n){return Math.abs(e-t)<(n||1e-6)}function k(t){return null!=t.a||null!=t.b||null!=t.c||null!=t.d||null!=t.e||null!=t.f}function C(t){var e="both"===t.flip||!0===t.flip,n=t.flip&&(e||"x"===t.flip)?-1:1,i=t.flip&&(e||"y"===t.flip)?-1:1,r=t.skew&&t.skew.length?t.skew[0]:isFinite(t.skew)?t.skew:isFinite(t.skewX)?t.skewX:0,s=t.skew&&t.skew.length?t.skew[1]:isFinite(t.skew)?t.skew:isFinite(t.skewY)?t.skewY:0,o=t.scale&&t.scale.length?t.scale[0]*n:isFinite(t.scale)?t.scale*n:isFinite(t.scaleX)?t.scaleX*n:n,a=t.scale&&t.scale.length?t.scale[1]*i:isFinite(t.scale)?t.scale*i:isFinite(t.scaleY)?t.scaleY*i:i,h=t.shear||0,u=t.rotate||t.theta||0,l=new q.Point(t.origin||t.around||t.ox||t.originX,t.oy||t.originY),c=l.x,f=l.y,d=new q.Point(t.position||t.px||t.positionX,t.py||t.positionY),p=d.x,m=d.y,v=new q.Point(t.translate||t.tx||t.translateX,t.ty||t.translateY),y=v.x,x=v.y,g=new q.Point(t.relative||t.rx||t.relativeX,t.ry||t.relativeY);return{scaleX:o,scaleY:a,skewX:r,skewY:s,shear:h,theta:u,rx:g.x,ry:g.y,tx:y,ty:x,ox:c,oy:f,px:p,py:m}}function S(t,e,n){var i=t.a*e.a+t.c*e.b,r=t.b*e.a+t.d*e.b,s=t.a*e.c+t.c*e.d,o=t.b*e.c+t.d*e.d,a=t.e+t.a*e.e+t.c*e.f,h=t.f+t.b*e.e+t.d*e.f;return n.a=i,n.b=r,n.c=s,n.d=o,n.e=a,n.f=h,n}function j(t,e){var n,i,r=t.origin;if("string"==typeof r||null==r){var s=(r||"center").toLowerCase().trim(),o=e.bbox(),a=o.height,h=o.width,u=o.x,l=o.y,c=s.includes("left")?u:s.includes("right")?u+h:u+h/2,f=s.includes("top")?l:s.includes("bottom")?l+a:l+a/2;n=null!=t.ox?t.ox:c,i=null!=t.oy?t.oy:f}else n=r[0],i=r[1];return[n,i]}function D(){var t=this._transformationRunners.runners,e=t.map(V).reduce(G,new q.Matrix);this.transform(e),this._transformationRunners.merge(),1===this._transformationRunners.length()&&(this._frameId=null)}function R(t,e){return function(n){return null==n?this[n]:(this[t]=n,e&&e.call(this),this)}}function I(){var t=(this._duration||500)/1e3,e=this._overshoot||0,n=Math.PI,i=Math.log(e/100+1e-10),r=-i/Math.sqrt(n*n+i*i),s=3.9/(r*t);this.d=2*r*s,this.k=s*s}if(!e.createElementNS||!e.createElementNS("http://www.w3.org/2000/svg","svg").createSVGRect)return{supported:!1};var q=t.SVG=function(t){if(q.supported)return t=f(t)};q.supported=!0,q.ns="http://www.w3.org/2000/svg",q.xmlns="http://www.w3.org/2000/xmlns/",q.xlink="http://www.w3.org/1999/xlink",q.svgjs="http://svgjs.com/svgjs",q.did=1e3,q.eid=function(t){return"Svgjs"+w(t)+q.did++},q.create=function(t){return e.createElementNS(this.ns,t)},q.extend=function(t,e){var n,i;for(t=Array.isArray(t)?t:[t],i=t.length-1;i>=0;i--)if(t[i])for(n in e)t[i].prototype[n]=e[n]},q.invent=function(t){var e="function"==typeof t.create?t.create:function(e){t.inherit.call(this,e||q.create(t.create))};return t.inherit&&(e.prototype=new t.inherit,e.prototype.constructor=e),t.extend&&q.extend(e,t.extend),t.construct&&q.extend(t.parent||q.Container,t.construct),e},q.adopt=function(e){if(!e)return null;if(e.instance instanceof q.Element)return e.instance;if(!(e instanceof t.SVGElement))return new q.HtmlNode(e);return"svg"===e.nodeName?new q.Doc(e):"linearGradient"===e.nodeName||"radialGradient"===e.nodeName?new q.Gradient(e):q[w(e.nodeName)]?new(q[w(e.nodeName)])(e):new q.Parent(e)},q.regex={numberAndUnit:/^([+-]?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?)([a-z%]*)$/i,hex:/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i,rgb:/rgb\((\d+),(\d+),(\d+)\)/,reference:/#([a-z0-9\-_]+)/i,transforms:/\)\s*,?\s*/,whitespace:/\s/g,isHex:/^#[a-f0-9]{3,6}$/i,isRgb:/^rgb\(/,isCss:/[^:]+:[^;]+;?/,isBlank:/^(\s+)?$/,isNumber:/^[+-]?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,isPercent:/^-?[\d.]+%$/,isImage:/\.(jpg|jpeg|png|gif|svg)(\?[^=]+.*)?/i,delimiter:/[\s,]+/,hyphen:/([^e])-/gi,pathLetters:/[MLHVCSQTAZ]/gi,isPathLetter:/[MLHVCSQTAZ]/i,numbersWithDots:/((\d?\.\d+(?:e[+-]?\d+)?)((?:\.\d+(?:e[+-]?\d+)?)+))+/gi,dots:/\./g},q.utils={map:function(t,e){var n,i=t.length,r=[];for(n=0;n<i;n++)r.push(e(t[n]));return r},filter:function(t,e){var n,i=t.length,r=[];for(n=0;n<i;n++)e(t[n])&&r.push(t[n]);return r},radians:function(t){return t%360*Math.PI/180},degrees:function(t){return 180*t/Math.PI%360},filterSVGElements:function(e){return this.filter(e,function(e){return e instanceof t.SVGElement})}},q.void=function(){},q.defaults={timeline:{duration:400,ease:">",delay:0},attrs:{"fill-opacity":1,"stroke-opacity":1,"stroke-width":0,"stroke-linejoin":"miter","stroke-linecap":"butt",fill:"#000000",stroke:"#000000",opacity:1,x:0,y:0,cx:0,cy:0,width:0,height:0,r:0,rx:0,ry:0,offset:0,"stop-opacity":1,"stop-color":"#000000","font-size":16,"font-family":"Helvetica, Arial, sans-serif","text-anchor":"start"}},q.Queue=q.invent({create:function(){this._first=null,this._last=null},extend:{push:function(t){var e=t.next?t:{value:t,next:null,prev:null};return this._last?(e.prev=this._last,this._last.next=e,this._last=e):(this._last=e,this._first=e),e},shift:function(){var t=this._first;return t?(this._first=t.next,this._first&&(this._first.prev=null),this._last=this._first?this._last:null,t.value):null},first:function(){return this._first&&this._first.value},last:function(){return this._last&&this._last.value},remove:function(t){t.prev&&(t.prev.next=t.next),t.next&&(t.next.prev=t.prev),t===this._last&&(this._last=t.prev),t===this._first&&(this._first=t.next),t.prev=null,t.next=null}}}),q.Color=function(t,e,n){var i;this.r=0,this.g=0,this.b=0,t&&("string"==typeof t?q.regex.isRgb.test(t)?(i=q.regex.rgb.exec(t.replace(q.regex.whitespace,"")),this.r=parseInt(i[1]),this.g=parseInt(i[2]),this.b=parseInt(i[3])):q.regex.isHex.test(t)&&(i=q.regex.hex.exec(b(t)),this.r=parseInt(i[1],16),this.g=parseInt(i[2],16),this.b=parseInt(i[3],16)):Array.isArray(t)?(this.r=t[0],this.g=t[1],this.b=t[2]):"object"===c(t)?(this.r=t.r,this.g=t.g,this.b=t.b):3===arguments.length&&(this.r=t,this.g=e,this.b=n))},q.extend(q.Color,{toString:function(){return this.toHex()},toArray:function(){return[this.r,this.g,this.b]},fromArray:function(t){return new q.Color(t)},toHex:function(){return"#"+_(Math.round(this.r))+_(Math.round(this.g))+_(Math.round(this.b))},toRgb:function(){return"rgb("+[this.r,this.g,this.b].join()+")"},brightness:function(){return this.r/255*.3+this.g/255*.59+this.b/255*.11},morph:function(t){return this.destination=new q.Color(t),this},at:function(t){return this.destination?(t=t<0?0:t>1?1:t,new q.Color({r:~~(this.r+(this.destination.r-this.r)*t),g:~~(this.g+(this.destination.g-this.g)*t),b:~~(this.b+(this.destination.b-this.b)*t)})):this}}),q.Color.test=function(t){return t+="",q.regex.isHex.test(t)||q.regex.isRgb.test(t)},q.Color.isRgb=function(t){return t&&"number"==typeof t.r&&"number"==typeof t.g&&"number"==typeof t.b},q.Color.isColor=function(t){return q.Color.isRgb(t)||q.Color.test(t)},q.Array=function(t,e){t=(t||[]).valueOf(),0===t.length&&e&&(t=e.valueOf()),this.value=this.parse(t)},q.extend(q.Array,{morph:function(t){if(this.destination=this.parse(t),this.value.length!==this.destination.length){for(var e=this.value[this.value.length-1],n=this.destination[this.destination.length-1];this.value.length>this.destination.length;)this.destination.push(n);for(;this.value.length<this.destination.length;)this.value.push(e)}return this},settle:function(){for(var t=0,e=this.value.length,n=[];t<e;t++)-1===n.indexOf(this.value[t])&&n.push(this.value[t]);return this.value=n,n},at:function(t){if(!this.destination)return this;for(var e=0,n=this.value.length,i=[];e<n;e++)i.push(this.value[e]+(this.destination[e]-this.value[e])*t);return new q.Array(i)},toArray:function(){return this.value},toString:function(){return this.value.join(" ")},valueOf:function(){return this.value},parse:function(t){return t=t.valueOf(),Array.isArray(t)?t:t.trim().split(q.regex.delimiter).map(parseFloat)},reverse:function(){return this.value.reverse(),this},clone:function(){var t=new this.constructor;return t.value=v(this.value),t}}),q.PointArray=function(t,e){q.Array.call(this,t,e||[[0,0]])},q.PointArray.prototype=new q.Array,q.PointArray.prototype.constructor=q.PointArray,q.extend(q.PointArray,{toString:function(){for(var t=0,e=this.value.length,n=[];t<e;t++)n.push(this.value[t].join(","));return n.join(" ")},toArray:function(){return this.value.reduce(function(t,e){return[].concat.call(t,e)},[])},toLine:function(){return{x1:this.value[0][0],y1:this.value[0][1],x2:this.value[1][0],y2:this.value[1][1]}},at:function(t){if(!this.destination)return this;for(var e=0,n=this.value.length,i=[];e<n;e++)i.push([this.value[e][0]+(this.destination[e][0]-this.value[e][0])*t,this.value[e][1]+(this.destination[e][1]-this.value[e][1])*t]);return new q.PointArray(i)},parse:function(t){var e=[];if(t=t.valueOf(),Array.isArray(t)){if(Array.isArray(t[0]))return t}else t=t.trim().split(q.regex.delimiter).map(parseFloat);t.length%2!=0&&t.pop();for(var n=0,i=t.length;n<i;n+=2)e.push([t[n],t[n+1]]);return e},move:function(t,e){var n=this.bbox();if(t-=n.x,e-=n.y,!isNaN(t)&&!isNaN(e))for(var i=this.value.length-1;i>=0;i--)this.value[i]=[this.value[i][0]+t,this.value[i][1]+e];return this},size:function(t,e){var n,i=this.bbox();for(n=this.value.length-1;n>=0;n--)i.width&&(this.value[n][0]=(this.value[n][0]-i.x)*t/i.width+i.x),i.height&&(this.value[n][1]=(this.value[n][1]-i.y)*e/i.height+i.y);return this},bbox:function(){var t=-1/0,e=-1/0,n=1/0,i=1/0;return this.value.forEach(function(r){t=Math.max(r[0],t),e=Math.max(r[1],e),n=Math.min(r[0],n),i=Math.min(r[1],i)}),{x:n,y:i,width:t-n,height:e-i}}});for(var B={M:function(t,e,n){return e.x=n.x=t[0],e.y=n.y=t[1],["M",e.x,e.y]},L:function(t,e){return e.x=t[0],e.y=t[1],["L",t[0],t[1]]},H:function(t,e){return e.x=t[0],["H",t[0]]},V:function(t,e){return e.y=t[0],["V",t[0]]},C:function(t,e){return e.x=t[4],e.y=t[5],["C",t[0],t[1],t[2],t[3],t[4],t[5]]},S:function(t,e){return e.x=t[2],e.y=t[3],["S",t[0],t[1],t[2],t[3]]},Q:function(t,e){return e.x=t[2],e.y=t[3],["Q",t[0],t[1],t[2],t[3]]},T:function(t,e){return e.x=t[0],e.y=t[1],["T",t[0],t[1]]},Z:function(t,e,n){return e.x=n.x,e.y=n.y,["Z"]},A:function(t,e){return e.x=t[5],e.y=t[6],["A",t[0],t[1],t[2],t[3],t[4],t[5],t[6]]}},L="mlhvqtcsaz".split(""),F=0,z=L.length;F<z;++F)B[L[F]]=function(t){return function(e,n,i){if("H"===t)e[0]=e[0]+n.x;else if("V"===t)e[0]=e[0]+n.y;else if("A"===t)e[5]=e[5]+n.x,e[6]=e[6]+n.y;else for(var r=0,s=e.length;r<s;++r)e[r]=e[r]+(r%2?n.y:n.x);return B[t](e,n,i)}}(L[F].toUpperCase());q.PathArray=function(t,e){q.Array.call(this,t,e||[["M",0,0]])},q.PathArray.prototype=new q.Array,q.PathArray.prototype.constructor=q.PathArray,q.extend(q.PathArray,{toString:function(){return P(this.value)},toArray:function(){return this.value.reduce(function(t,e){return[].concat.call(t,e)},[])},move:function(t,e){var n=this.bbox();if(t-=n.x,e-=n.y,!isNaN(t)&&!isNaN(e))for(var i,r=this.value.length-1;r>=0;r--)i=this.value[r][0],"M"===i||"L"===i||"T"===i?(this.value[r][1]+=t,this.value[r][2]+=e):"H"===i?this.value[r][1]+=t:"V"===i?this.value[r][1]+=e:"C"===i||"S"===i||"Q"===i?(this.value[r][1]+=t,this.value[r][2]+=e,this.value[r][3]+=t,this.value[r][4]+=e,"C"===i&&(this.value[r][5]+=t,this.value[r][6]+=e)):"A"===i&&(this.value[r][6]+=t,this.value[r][7]+=e);return this},size:function(t,e){var n,i,r=this.bbox();for(n=this.value.length-1;n>=0;n--)i=this.value[n][0],"M"===i||"L"===i||"T"===i?(this.value[n][1]=(this.value[n][1]-r.x)*t/r.width+r.x,this.value[n][2]=(this.value[n][2]-r.y)*e/r.height+r.y):"H"===i?this.value[n][1]=(this.value[n][1]-r.x)*t/r.width+r.x:"V"===i?this.value[n][1]=(this.value[n][1]-r.y)*e/r.height+r.y:"C"===i||"S"===i||"Q"===i?(this.value[n][1]=(this.value[n][1]-r.x)*t/r.width+r.x,this.value[n][2]=(this.value[n][2]-r.y)*e/r.height+r.y,this.value[n][3]=(this.value[n][3]-r.x)*t/r.width+r.x,this.value[n][4]=(this.value[n][4]-r.y)*e/r.height+r.y,"C"===i&&(this.value[n][5]=(this.value[n][5]-r.x)*t/r.width+r.x,this.value[n][6]=(this.value[n][6]-r.y)*e/r.height+r.y)):"A"===i&&(this.value[n][1]=this.value[n][1]*t/r.width,this.value[n][2]=this.value[n][2]*e/r.height,this.value[n][6]=(this.value[n][6]-r.x)*t/r.width+r.x,this.value[n][7]=(this.value[n][7]-r.y)*e/r.height+r.y);return this},equalCommands:function(t){var e,n,i;for(t=new q.PathArray(t),i=this.value.length===t.value.length,e=0,n=this.value.length;i&&e<n;e++)i=this.value[e][0]===t.value[e][0];return i},morph:function(t){return t=new q.PathArray(t),this.equalCommands(t)?this.destination=t:this.destination=null,this},at:function(t){if(!this.destination)return this;var e,n,i,r,s=this.value,o=this.destination.value,a=[],h=new q.PathArray;for(e=0,n=s.length;e<n;e++){for(a[e]=[s[e][0]],i=1,r=s[e].length;i<r;i++)a[e][i]=s[e][i]+(o[e][i]-s[e][i])*t;"A"===a[e][0]&&(a[e][4]=+(0!==a[e][4]),a[e][5]=+(0!==a[e][5]))}return h.value=a,h},parse:function(t){if(t instanceof q.PathArray)return t.valueOf();var e,n={M:2,L:2,H:1,V:1,C:6,S:4,Q:4,T:2,A:7,Z:0};t="string"==typeof t?t.replace(q.regex.numbersWithDots,m).replace(q.regex.pathLetters," $& ").replace(q.regex.hyphen,"$1 -").trim().split(q.regex.delimiter):t.reduce(function(t,e){return[].concat.call(t,e)},[]);var i=[],r=new q.Point,s=new q.Point,o=0,a=t.length;do{q.regex.isPathLetter.test(t[o])?(e=t[o],++o):"M"===e?e="L":"m"===e&&(e="l"),i.push(B[e].call(null,t.slice(o,o+=n[e.toUpperCase()]).map(parseFloat),r,s))}while(a>o);return i},bbox:function(){return q.parser().path.setAttribute("d",this.toString()),q.parser.nodes.path.getBBox()}}),q.Number=q.invent({create:function(t,e){e=Array.isArray(t)?t[1]:e,t=Array.isArray(t)?t[0]:t,this.value=0,this.unit=e||"","number"==typeof t?this.value=isNaN(t)?0:isFinite(t)?t:t<0?-3.4e38:3.4e38:"string"==typeof t?(e=t.match(q.regex.numberAndUnit))&&(this.value=parseFloat(e[1]),"%"===e[5]?this.value/=100:"s"===e[5]&&(this.value*=1e3),this.unit=e[5]):t instanceof q.Number&&(this.value=t.valueOf(),this.unit=t.unit)},extend:{toString:function(){return("%"===this.unit?~~(1e8*this.value)/1e6:"s"===this.unit?this.value/1e3:this.value)+this.unit},toJSON:function(){return this.toString()},toArray:function(){return[this.value,this.unit]},valueOf:function(){return this.value},plus:function(t){return t=new q.Number(t),new q.Number(this+t,this.unit||t.unit)},minus:function(t){return t=new q.Number(t),new q.Number(this-t,this.unit||t.unit)},times:function(t){return t=new q.Number(t),new q.Number(this*t,this.unit||t.unit)},divide:function(t){return t=new q.Number(t),new q.Number(this/t,this.unit||t.unit)},to:function(t){var e=new q.Number(this);return"string"==typeof t&&(e.unit=t),e},morph:function(t){return this.destination=new q.Number(t),t.relative&&(this.destination.value+=this.value),this},at:function(t){return this.destination?new q.Number(this.destination).minus(this).times(t).plus(this):this}}}),q.EventTarget=q.invent({create:function(){},extend:{on:function(t,e,n,i){return q.on(this,t,e,n,i),this},off:function(t,e){return q.off(this,t,e),this},dispatch:function(t,e){return q.dispatch(this,t,e)},fire:function(t,e){return this.dispatch(t,e),this}}}),q.HtmlNode=q.invent({inherit:q.EventTarget,create:function(t){this.node=t},extend:{add:function(t,e){return t=f(t),t.node!==this.node.children[e]&&this.node.insertBefore(t.node,this.node.children[e]||null),this},put:function(t,e){return this.add(t,e),t},getEventTarget:function(){return this.node}}}),q.Element=q.invent({inherit:q.EventTarget,create:function(t){this.events={},this.dom={},this.node=t,this.node&&(this.type=t.nodeName,this.node.instance=this,this.events=t.events||{},t.hasAttribute("svgjs:data")&&this.setData(JSON.parse(t.getAttribute("svgjs:data"))||{}))},extend:{x:function(t){return this.attr("x",t)},y:function(t){return this.attr("y",t)},cx:function(t){return null==t?this.x()+this.width()/2:this.x(t-this.width()/2)},cy:function(t){return null==t?this.y()+this.height()/2:this.y(t-this.height()/2)},move:function(t,e){return this.x(t).y(e)},center:function(t,e){return this.cx(t).cy(e)},width:function(t){return this.attr("width",t)},height:function(t){return this.attr("height",t)},size:function(t,e){var n=A(this,t,e);return this.width(new q.Number(n.width)).height(new q.Number(n.height))},clone:function(t){this.writeDataToDom();var e=N(this.node.cloneNode(!0));return t?t.add(e):this.after(e),e},remove:function(){return this.parent()&&this.parent().removeElement(this),this},replace:function(t){return this.after(t).remove(),t},addTo:function(t){return f(t).put(this)},putIn:function(t){return f(t).add(this)},id:function(t){return void 0!==t||this.node.id||(this.node.id=q.eid(this.type)),this.attr("id",t)},inside:function(t,e){var n=this.bbox();return t>n.x&&e>n.y&&t<n.x+n.width&&e<n.y+n.height},show:function(){return this.css("display","")},hide:function(){return this.css("display","none")},visible:function(){return"none"!==this.css("display")},toString:function(){return this.id()},classes:function(){var t=this.attr("class");return null==t?[]:t.trim().split(q.regex.delimiter)},hasClass:function(t){return-1!==this.classes().indexOf(t)},addClass:function(t){if(!this.hasClass(t)){var e=this.classes();e.push(t),this.attr("class",e.join(" "))}return this},removeClass:function(t){return this.hasClass(t)&&this.attr("class",this.classes().filter(function(e){return e!==t}).join(" ")),this},toggleClass:function(t){return this.hasClass(t)?this.removeClass(t):this.addClass(t)},reference:function(t){return q.get(this.attr(t))},parent:function(e){var n=this;if(!n.node.parentNode)return null;if(n=q.adopt(n.node.parentNode),!e)return n;for(;n&&n.node instanceof t.SVGElement;){if("string"==typeof e?n.matches(e):n instanceof e)return n;n=q.adopt(n.node.parentNode)}},doc:function(){var t=this.parent(q.Doc);return t&&t.doc()},defs:function(){return this.doc().defs()},parents:function(t){var e=[],n=this;do{if(!(n=n.parent(t))||!n.node)break;e.push(n)}while(n.parent);return e},matches:function(t){return x(this.node,t)},native:function(){return this.node},svg:function(t){var n,i;if(!(t&&this instanceof q.Parent))return this.writeDataToDom(),this.node.outerHTML;for(n=e.createElementNS(q.ns,"svg"),n.innerHTML=t,i=n.children.length;i--;)this.node.appendChild(n.firstElementChild);return this},writeDataToDom:function(){return this.is(q.Parent)&&this.each(function(){this.writeDataToDom()}),this.node.removeAttribute("svgjs:data"),Object.keys(this.dom).length&&this.node.setAttribute("svgjs:data",JSON.stringify(this.dom)),this},setData:function(t){return this.dom=t,this},is:function(t){return y(this,t)},getEventTarget:function(){return this.node}}}),["click","dblclick","mousedown","mouseup","mouseover","mouseout","mousemove","mouseenter","mouseleave","touchstart","touchmove","touchleave","touchend","touchcancel"].forEach(function(t){q.Element.prototype[t]=function(e){return null===e?q.off(this,t):q.on(this,t,e),this}}),q.listenerId=0,q.on=function(t,e,n,i,r){var s=n.bind(i||t),o=t instanceof q.EventTarget?t.getEventTarget():t;e=Array.isArray(e)?e:e.split(q.regex.delimiter),o.instance=o.instance||{events:{}};var a=o.instance.events;n._svgjsListenerId||(n._svgjsListenerId=++q.listenerId),e.forEach(function(t){var e=t.split(".")[0],i=t.split(".")[1]||"*";a[e]=a[e]||{},a[e][i]=a[e][i]||{},a[e][i][n._svgjsListenerId]=s,o.addEventListener(e,s,r||!1)})},q.off=function(t,e,n,i){var r=t instanceof q.EventTarget?t.getEventTarget():t;if(r.instance&&("function"!=typeof n||(n=n._svgjsListenerId))){var s=r.instance.events;e=Array.isArray(e)?e:(e||"").split(q.regex.delimiter),e.forEach(function(t){var e,o,a=t&&t.split(".")[0],h=t&&t.split(".")[1];if(n)s[a]&&s[a][h||"*"]&&(r.removeEventListener(a,s[a][h||"*"][n],i||!1),delete s[a][h||"*"][n]);else if(a&&h){if(s[a]&&s[a][h]){for(o in s[a][h])q.off(r,[a,h].join("."),o);delete s[a][h]}}else if(h)for(t in s)for(e in s[t])h===e&&q.off(r,[t,h].join("."));else if(a){if(s[a]){for(e in s[a])q.off(r,[a,e].join("."));delete s[a]}}else{for(t in s)q.off(r,t);r.instance.events={}}})}},q.dispatch=function(e,n,i){var r=e instanceof q.EventTarget?e.getEventTarget():e;return n instanceof t.Event?r.dispatchEvent(n):(n=new t.CustomEvent(n,{detail:i,cancelable:!0}),r.dispatchEvent(n)),n},q.Matrix=q.invent({create:function(t){var e=M([1,0,0,1,0,0]);t=t instanceof q.Element?t.matrixify():"string"==typeof t?M(t.split(q.regex.delimiter).map(parseFloat)):Array.isArray(t)?M(t):"object"===c(t)&&k(t)?t:"object"===c(t)?(new q.Matrix).transform(t):6===arguments.length?M([].slice.call(arguments)):e,this.a=null!=t.a?t.a:e.a,this.b=null!=t.b?t.b:e.b,this.c=null!=t.c?t.c:e.c,this.d=null!=t.d?t.d:e.d,this.e=null!=t.e?t.e:e.e,this.f=null!=t.f?t.f:e.f},extend:{clone:function(){return new q.Matrix(this)},transform:function(t){if(k(t)){return new q.Matrix(t).multiplyO(this)}var e=C(t),n=this,i=new q.Point(e.ox,e.oy).transform(n),r=i.x,s=i.y,o=(new q.Matrix).translateO(e.rx,e.ry).lmultiplyO(n).translateO(-r,-s).scaleO(e.scaleX,e.scaleY).skewO(e.skewX,e.skewY).shearO(e.shear).rotateO(e.theta).translateO(r,s);if(isFinite(e.px)||isFinite(e.py)){var a=new q.Point(r,s).transform(o),h=e.px?e.px-a.x:0,u=e.py?e.py-a.y:0;o.translateO(h,u)}return o.translateO(e.tx,e.ty),o},compose:function(t){t.origin&&(t.originX=t.origin[0],t.originY=t.origin[1]);var e=t.originX||0,n=t.originY||0,i=t.scaleX||1,r=t.scaleY||1,s=t.shear||0,o=t.rotate||0,a=t.translateX||0,h=t.translateY||0;return(new q.Matrix).translateO(-e,-n).scaleO(i,r).shearO(s).rotateO(o).translateO(a,h).lmultiplyO(this).translateO(e,n)},decompose:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=this.a,i=this.b,r=this.c,s=this.d,o=this.e,a=this.f,h=n*s-i*r,u=h>0?1:-1,l=u*Math.sqrt(n*n+i*i),c=Math.atan2(u*i,u*n),f=180/Math.PI*c,d=Math.cos(c),p=Math.sin(c),m=(n*r+i*s)/h,v=r*l/(m*n-i)||s*l/(m*i+n);return{scaleX:l,scaleY:v,shear:m,rotate:f,translateX:o-t+t*d*l+e*(m*d*l-p*v),translateY:a-e+t*p*l+e*(m*p*l+d*v),originX:t,originY:e,a:this.a,b:this.b,c:this.c,d:this.d,e:this.e,f:this.f}},morph:function(t){return this.destination=new q.Matrix(t),this},at:function(t){return this.destination?new q.Matrix({a:this.a+(this.destination.a-this.a)*t,b:this.b+(this.destination.b-this.b)*t,c:this.c+(this.destination.c-this.c)*t,d:this.d+(this.destination.d-this.d)*t,e:this.e+(this.destination.e-this.e)*t,f:this.f+(this.destination.f-this.f)*t}):this},multiply:function(t){return this.clone().multiplyO(t)},multiplyO:function(t){return S(this,t instanceof q.Matrix?t:new q.Matrix(t),this)},lmultiply:function(t){return this.clone().lmultiplyO(t)},lmultiplyO:function(t){var e=this;return S(t instanceof q.Matrix?t:new q.Matrix(t),e,this)},inverseO:function(){var t=this.a,e=this.b,n=this.c,i=this.d,r=this.e,s=this.f,o=t*i-e*n;if(!o)throw new Error("Cannot invert "+this);var a=i/o,h=-e/o,u=-n/o,l=t/o,c=-(a*r+u*s),f=-(h*r+l*s);return this.a=a,this.b=h,this.c=u,this.d=l,this.e=c,this.f=f,this},inverse:function(){return this.clone().inverseO()},translate:function(t,e){return this.clone().translateO(t,e)},translateO:function(t,e){return this.e+=t||0,this.f+=e||0,this},scale:function(t,e,n,i){var r;return(r=this.clone()).scaleO.apply(r,arguments)},scaleO:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;3===arguments.length&&(i=n,n=e,e=t);var r=this.a,s=this.b,o=this.c,a=this.d,h=this.e,u=this.f;return this.a=r*t,this.b=s*e,this.c=o*t,this.d=a*e,this.e=h*t-n*t+n,this.f=u*e-i*e+i,this},rotate:function(t,e,n){return this.clone().rotateO(t,e,n)},rotateO:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;t=q.utils.radians(t);var i=Math.cos(t),r=Math.sin(t),s=this.a,o=this.b,a=this.c,h=this.d,u=this.e,l=this.f;return this.a=s*i-o*r,this.b=o*i+s*r,this.c=a*i-h*r,this.d=h*i+a*r,this.e=u*i-l*r+n*r-e*i+e,this.f=l*i+u*r-e*r-n*i+n,this},flip:function(t,e){return this.clone().flipO(t,e)},flipO:function(t,e){return"x"===t?this.scaleO(-1,1,e,0):"y"===t?this.scaleO(1,-1,0,e):this.scaleO(-1,-1,t,e||t)},shear:function(t,e,n){return this.clone().shearO(t,e,n)},shearO:function(t){var e=(arguments.length>1&&void 0!==arguments[1]&&arguments[1],arguments.length>2&&void 0!==arguments[2]?arguments[2]:0),n=this.a,i=this.b,r=this.c,s=this.d,o=this.e,a=this.f;return this.a=n+i*t,this.c=r+s*t,this.e=o+a*t-e*t,this},skew:function(t,e,n,i){var r;return(r=this.clone()).skewO.apply(r,arguments)},skewO:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0;3===arguments.length&&(i=n,n=e,e=t),t=q.utils.radians(t),e=q.utils.radians(e);var r=Math.tan(t),s=Math.tan(e),o=this.a,a=this.b,h=this.c,u=this.d,l=this.e,c=this.f;return this.a=o+a*r,this.b=a+o*s,this.c=h+u*r,this.d=u+h*s,this.e=l+c*r-i*r,this.f=c+l*s-n*s,this},skewX:function(t,e,n){return this.skew(t,0,e,n)},skewXO:function(t,e,n){return this.skewO(t,0,e,n)},skewY:function(t,e,n){return this.skew(0,t,e,n)},skewYO:function(t,e,n){return this.skewO(0,t,e,n)},aroundO:function(t,e,n){var i=t||0,r=e||0;return this.translateO(-i,-r).lmultiplyO(n).translateO(i,r)},around:function(t,e,n){return this.clone().aroundO(t,e,n)},native:function(){for(var t=q.parser.nodes.svg.node.createSVGMatrix(),e=Y.length-1;e>=0;e--)t[Y[e]]=this[Y[e]];return t},equals:function(t){var e=new q.Matrix(t);return T(this.a,e.a)&&T(this.b,e.b)&&T(this.c,e.c)&&T(this.d,e.d)&&T(this.e,e.e)&&T(this.f,e.f)},toString:function(){return"matrix("+this.a+","+this.b+","+this.c+","+this.d+","+this.e+","+this.f+")"},toArray:function(){return[this.a,this.b,this.c,this.d,this.e,this.f]},valueOf:function(){return{a:this.a,b:this.b,c:this.c,d:this.d,e:this.e,f:this.f}}},parent:q.Element,construct:{ctm:function(){return new q.Matrix(this.node.getCTM())},screenCTM:function(){if(this instanceof q.Doc&&!this.isRoot()){var t=this.rect(1,1),e=t.node.getScreenCTM();return t.remove(),new q.Matrix(e)}return new q.Matrix(this.node.getScreenCTM())}}}),q.Point=q.invent({create:function(t,e,n){var i;n=n||{x:0,y:0},i=Array.isArray(t)?{x:t[0],y:t[1]}:"object"===c(t)?{x:t.x,y:t.y}:{x:t,y:e},this.x=null==i.x?n.x:i.x,this.y=null==i.y?n.y:i.y},extend:{clone:function(){return new q.Point(this)},morph:function(t,e){return this.destination=new q.Point(t,e),this},at:function(t){return this.destination?new q.Point({x:this.x+(this.destination.x-this.x)*t,y:this.y+(this.destination.y-this.y)*t}):this},native:function(){var t=q.parser.nodes.svg.node.createSVGPoint();return t.x=this.x,t.y=this.y,t},transform:function(t){var e=t.a*this.x+t.c*this.y+t.e,n=t.b*this.x+t.d*this.y+t.f;return new q.Point(e,n)}}}),q.extend(q.Element,{point:function(t,e){return new q.Point(t,e).transform(this.screenCTM().inverse())}}),q.extend(q.Element,{attr:function(t,e,n){if(null==t){for(t={},e=this.node.attributes,n=e.length-1;n>=0;n--)t[e[n].nodeName]=q.regex.isNumber.test(e[n].nodeValue)?parseFloat(e[n].nodeValue):e[n].nodeValue;return t}if("object"===c(t))for(e in t)this.attr(e,t[e]);else if(null===e)this.node.removeAttribute(t);else{if(null==e)return e=this.node.getAttribute(t),null==e?q.defaults.attrs[t]:q.regex.isNumber.test(e)?parseFloat(e):e;"fill"!==t&&"stroke"!==t||(q.regex.isImage.test(e)&&(e=this.doc().defs().image(e)),e instanceof q.Image&&(e=this.doc().defs().pattern(0,0,function(){this.add(e)}))),"number"==typeof e?e=new q.Number(e):q.Color.isColor(e)?e=new q.Color(e):Array.isArray(e)&&(e=new q.Array(e)),"leading"===t?this.leading&&this.leading(e):"string"==typeof n?this.node.setAttributeNS(n,t,e.toString()):this.node.setAttribute(t,e.toString()),!this.rebuild||"font-size"!==t&&"x"!==t||this.rebuild(t,e)}return this}}),q.extend(q.Element,{untransform:function(){return this.attr("transform",null)},matrixify:function(){return(this.attr("transform")||"").split(q.regex.transforms).slice(0,-1).map(function(t){var e=t.trim().split("(");return[e[0],e[1].split(q.regex.delimiter).map(function(t){return parseFloat(t)})]}).reverse().reduce(function(t,e){return"matrix"===e[0]?t.lmultiply(M(e[1])):t[e[0]].apply(t,e[1])},new q.Matrix)},toParent:function(t){if(this===t)return this;var e=this.screenCTM(),n=t.screenCTM().inverse();return this.addTo(t).untransform().transform(n.multiply(e)),this},toDoc:function(){return this.toParent(this.doc())}}),q.extend(q.Element,{transform:function(t,e){if(null==t||"string"==typeof t){var n=new q.Matrix(this).decompose();return n[t]||n}k(t)||(t=u({},t,{
origin:j(t,this)}));var i=!0===e?this:e||!1,r=new q.Matrix(i).transform(t);return this.attr("transform",r)}}),q.extend(q.Element,{css:function(t,e){var n,i,r={};if(0===arguments.length)return this.node.style.cssText.split(/\s*;\s*/).filter(function(t){return!!t.length}).forEach(function(t){n=t.split(/\s*:\s*/),r[n[0]]=n[1]}),r;if(arguments.length<2){if(Array.isArray(t)){for(i=t.length;i--;)r[g(t[i])]=this.node.style[g(t[i])];return r}if("string"==typeof t)return this.node.style[g(t)];if("object"===c(t))for(i in t)this.node.style[g(i)]=null==t[i]||q.regex.isBlank.test(t[i])?"":t[i]}return 2===arguments.length&&(this.node.style[g(t)]=null==e||q.regex.isBlank.test(e)?"":e),this}}),q.Parent=q.invent({create:function(t){q.Element.call(this,t)},inherit:q.Element,extend:{children:function(){return q.utils.map(this.node.children,function(t){return q.adopt(t)})},add:function(t,e){return t=f(t),t.node!==this.node.children[e]&&this.node.insertBefore(t.node,this.node.children[e]||null),this},put:function(t,e){return this.add(t,e),t.instance||t},has:function(t){return this.index(t)>=0},index:function(t){return[].slice.call(this.node.children).indexOf(t.node)},get:function(t){return q.adopt(this.node.children[t])},first:function(){return this.get(0)},last:function(){return this.get(this.node.children.length-1)},each:function(t,e){var n,i,r=this.children();for(n=0,i=r.length;n<i;n++)r[n]instanceof q.Element&&t.apply(r[n],[n,r]),e&&r[n]instanceof q.Parent&&r[n].each(t,e);return this},removeElement:function(t){return this.node.removeChild(t.node),this},clear:function(){for(;this.node.hasChildNodes();)this.node.removeChild(this.node.lastChild);return delete this._defs,this}}}),q.extend(q.Parent,{flatten:function(t){return this instanceof q.G||this instanceof q.Doc?(t=t||(this instanceof q.Doc&&this.isRoot()?this:this.parent(q.Parent)),this.each(function(){return this instanceof q.Defs?this:this instanceof q.Parent?this.flatten(t):this.toParent(t)}),this.node.firstElementChild||this.remove(),this):this},ungroup:function(t){return this instanceof q.G||this instanceof q.Doc&&!this.isRoot()?(t=t||this.parent(q.Parent),this.each(function(){return this.toParent(t)}),this.remove(),this):this}}),q.Container=q.invent({create:function(t){q.Element.call(this,t)},inherit:q.Parent}),q.Defs=q.invent({create:"defs",inherit:q.Container}),q.G=q.invent({create:"g",inherit:q.Container,extend:{},construct:{group:function(){return this.put(new q.G)}}}),q.extend(q.Element,{siblings:function(){return this.parent().children()},position:function(){return this.parent().index(this)},next:function(){return this.siblings()[this.position()+1]},prev:function(){return this.siblings()[this.position()-1]},forward:function(){var t=this.position()+1,e=this.parent();return e.removeElement(this).add(this,t),e instanceof q.Doc&&e.node.appendChild(e.defs().node),this},backward:function(){var t=this.position();return t>0&&this.parent().removeElement(this).add(this,t-1),this},front:function(){var t=this.parent();return t.node.appendChild(this.node),t instanceof q.Doc&&t.node.appendChild(t.defs().node),this},back:function(){return this.position()>0&&this.parent().removeElement(this).add(this,0),this},before:function(t){t.remove();var e=this.position();return this.parent().add(t,e),this},after:function(t){t.remove();var e=this.position();return this.parent().add(t,e+1),this}}),q.Mask=q.invent({create:"mask",inherit:q.Container,extend:{remove:function(){return this.targets().forEach(function(t){t.unmask()}),q.Element.prototype.remove.call(this)},targets:function(){return q.select('svg [mask*="'+this.id()+'"]')}},construct:{mask:function(){return this.defs().put(new q.Mask)}}}),q.extend(q.Element,{maskWith:function(t){var e=t instanceof q.Mask?t:this.parent().mask().add(t);return this.attr("mask",'url("#'+e.id()+'")')},unmask:function(){return this.attr("mask",null)},masker:function(){return this.reference("mask")}}),q.ClipPath=q.invent({create:"clipPath",inherit:q.Container,extend:{remove:function(){return this.targets().forEach(function(t){t.unclip()}),q.Element.prototype.remove.call(this)},targets:function(){return q.select('svg [clip-path*="'+this.id()+'"]')}},construct:{clip:function(){return this.defs().put(new q.ClipPath)}}}),q.extend(q.Element,{clipWith:function(t){var e=t instanceof q.ClipPath?t:this.parent().clip().add(t);return this.attr("clip-path",'url("#'+e.id()+'")')},unclip:function(){return this.attr("clip-path",null)},clipper:function(){return this.reference("clip-path")}}),q.Gradient=q.invent({create:function(t){q.Element.call(this,"object"===c(t)?t:q.create(t+"Gradient"))},inherit:q.Container,extend:{stop:function(t,e,n){return this.put(new q.Stop).update(t,e,n)},update:function(t){return this.clear(),"function"==typeof t&&t.call(this,this),this},url:function(){return"url(#"+this.id()+")"},toString:function(){return this.url()},attr:function(t,e,n){return"transform"===t&&(t="gradientTransform"),q.Container.prototype.attr.call(this,t,e,n)}},construct:{gradient:function(t,e){return this.defs().gradient(t,e)}}}),q.extend([q.Gradient,q.Timeline],{from:function(t,e){return"radialGradient"===(this._target||this).type?this.attr({fx:new q.Number(t),fy:new q.Number(e)}):this.attr({x1:new q.Number(t),y1:new q.Number(e)})},to:function(t,e){return"radialGradient"===(this._target||this).type?this.attr({cx:new q.Number(t),cy:new q.Number(e)}):this.attr({x2:new q.Number(t),y2:new q.Number(e)})}}),q.extend(q.Defs,{gradient:function(t,e){return this.put(new q.Gradient(t)).update(e)}}),q.Stop=q.invent({create:"stop",inherit:q.Element,extend:{update:function(t){return("number"==typeof t||t instanceof q.Number)&&(t={offset:arguments[0],color:arguments[1],opacity:arguments[2]}),null!=t.opacity&&this.attr("stop-opacity",t.opacity),null!=t.color&&this.attr("stop-color",t.color),null!=t.offset&&this.attr("offset",new q.Number(t.offset)),this}}}),q.Pattern=q.invent({create:"pattern",inherit:q.Container,extend:{url:function(){return"url(#"+this.id()+")"},update:function(t){return this.clear(),"function"==typeof t&&t.call(this,this),this},toString:function(){return this.url()},attr:function(t,e,n){return"transform"===t&&(t="patternTransform"),q.Container.prototype.attr.call(this,t,e,n)}},construct:{pattern:function(t,e,n){return this.defs().pattern(t,e,n)}}}),q.extend(q.Defs,{pattern:function(t,e,n){return this.put(new q.Pattern).update(n).attr({x:0,y:0,width:t,height:e,patternUnits:"userSpaceOnUse"})}}),q.Doc=q.invent({create:function(t){q.Element.call(this,t||q.create("svg")),this.namespace()},inherit:q.Container,extend:{isRoot:function(){return!(this.node.parentNode&&this.node.parentNode instanceof t.SVGElement&&"#document"!==this.node.parentNode.nodeName)},doc:function(){return this.isRoot()?this:q.Element.prototype.doc.call(this)},namespace:function(){return this.isRoot()?this.attr({xmlns:q.ns,version:"1.1"}).attr("xmlns:xlink",q.xlink,q.xmlns).attr("xmlns:svgjs",q.svgjs,q.xmlns):this.doc().namespace()},defs:function(){return this.isRoot()?q.adopt(this.node.getElementsByTagName("defs")[0])||this.put(new q.Defs):this.doc().defs()},parent:function(t){return this.isRoot()?"#document"===this.node.parentNode.nodeName?null:this.node.parentNode:q.Element.prototype.parent.call(this,t)},remove:function(){return this.isRoot()?(this.parent()&&this.parent().removeChild(this.node),this):q.Element.prototype.remove.call(this)},clear:function(){for(;this.node.hasChildNodes();)this.node.removeChild(this.node.lastChild);return this}},construct:{nested:function(){return this.put(new q.Doc)}}}),q.Shape=q.invent({create:function(t){q.Element.call(this,t)},inherit:q.Element}),q.Bare=q.invent({create:function(t,e){if(q.Element.call(this,q.create(t)),e)for(var n in e.prototype)"function"==typeof e.prototype[n]&&(this[n]=e.prototype[n])},inherit:q.Element,extend:{words:function(t){for(;this.node.hasChildNodes();)this.node.removeChild(this.node.lastChild);return this.node.appendChild(e.createTextNode(t)),this}}}),q.extend(q.Parent,{element:function(t,e){return this.put(new q.Bare(t,e))}}),q.Symbol=q.invent({create:"symbol",inherit:q.Container,construct:{symbol:function(){return this.put(new q.Symbol)}}}),q.Use=q.invent({create:"use",inherit:q.Shape,extend:{element:function(t,e){return this.attr("href",(e||"")+"#"+t,q.xlink)}},construct:{use:function(t,e){return this.put(new q.Use).element(t,e)}}}),q.Rect=q.invent({create:"rect",inherit:q.Shape,construct:{rect:function(t,e){return this.put(new q.Rect).size(t,e)}}}),q.Circle=q.invent({create:"circle",inherit:q.Shape,construct:{circle:function(t){return this.put(new q.Circle).rx(new q.Number(t).divide(2)).move(0,0)}}}),q.extend([q.Circle,q.Timeline],{rx:function(t){return this.attr("r",t)},ry:function(t){return this.rx(t)}}),q.Ellipse=q.invent({create:"ellipse",inherit:q.Shape,construct:{ellipse:function(t,e){return this.put(new q.Ellipse).size(t,e).move(0,0)}}}),q.extend([q.Ellipse,q.Rect,q.Timeline],{rx:function(t){return this.attr("rx",t)},ry:function(t){return this.attr("ry",t)}}),q.extend([q.Circle,q.Ellipse],{x:function(t){return null==t?this.cx()-this.rx():this.cx(t+this.rx())},y:function(t){return null==t?this.cy()-this.ry():this.cy(t+this.ry())},cx:function(t){return null==t?this.attr("cx"):this.attr("cx",t)},cy:function(t){return null==t?this.attr("cy"):this.attr("cy",t)},width:function(t){return null==t?2*this.rx():this.rx(new q.Number(t).divide(2))},height:function(t){return null==t?2*this.ry():this.ry(new q.Number(t).divide(2))},size:function(t,e){var n=A(this,t,e);return this.rx(new q.Number(n.width).divide(2)).ry(new q.Number(n.height).divide(2))}}),q.Line=q.invent({create:"line",inherit:q.Shape,extend:{array:function(){return new q.PointArray([[this.attr("x1"),this.attr("y1")],[this.attr("x2"),this.attr("y2")]])},plot:function(t,e,n,i){return null==t?this.array():(t=void 0!==e?{x1:t,y1:e,x2:n,y2:i}:new q.PointArray(t).toLine(),this.attr(t))},move:function(t,e){return this.attr(this.array().move(t,e).toLine())},size:function(t,e){var n=A(this,t,e);return this.attr(this.array().size(n.width,n.height).toLine())}},construct:{line:function(t,e,n,i){return q.Line.prototype.plot.apply(this.put(new q.Line),null!=t?[t,e,n,i]:[0,0,0,0])}}}),q.Polyline=q.invent({create:"polyline",inherit:q.Shape,construct:{polyline:function(t){return this.put(new q.Polyline).plot(t||new q.PointArray)}}}),q.Polygon=q.invent({create:"polygon",inherit:q.Shape,construct:{polygon:function(t){return this.put(new q.Polygon).plot(t||new q.PointArray)}}}),q.extend([q.Polyline,q.Polygon],{array:function(){return this._array||(this._array=new q.PointArray(this.attr("points")))},plot:function(t){return null==t?this.array():this.clear().attr("points","string"==typeof t?t:this._array=new q.PointArray(t))},clear:function(){return delete this._array,this},move:function(t,e){return this.attr("points",this.array().move(t,e))},size:function(t,e){var n=A(this,t,e);return this.attr("points",this.array().size(n.width,n.height))}}),q.extend([q.Line,q.Polyline,q.Polygon],{MorphArray:q.PointArray,x:function(t){return null==t?this.bbox().x:this.move(t,this.bbox().y)},y:function(t){return null==t?this.bbox().y:this.move(this.bbox().x,t)},width:function(t){var e=this.bbox();return null==t?e.width:this.size(t,e.height)},height:function(t){var e=this.bbox();return null==t?e.height:this.size(e.width,t)}}),q.Path=q.invent({create:"path",inherit:q.Shape,extend:{MorphArray:q.PathArray,array:function(){return this._array||(this._array=new q.PathArray(this.attr("d")))},plot:function(t){return null==t?this.array():this.clear().attr("d","string"==typeof t?t:this._array=new q.PathArray(t))},clear:function(){return delete this._array,this},move:function(t,e){return this.attr("d",this.array().move(t,e))},x:function(t){return null==t?this.bbox().x:this.move(t,this.bbox().y)},y:function(t){return null==t?this.bbox().y:this.move(this.bbox().x,t)},size:function(t,e){var n=A(this,t,e);return this.attr("d",this.array().size(n.width,n.height))},width:function(t){return null==t?this.bbox().width:this.size(t,this.bbox().height)},height:function(t){return null==t?this.bbox().height:this.size(this.bbox().width,t)}},construct:{path:function(t){return this.put(new q.Path).plot(t||new q.PathArray)}}}),q.Image=q.invent({create:"image",inherit:q.Shape,extend:{load:function(e,n){if(!e)return this;var i=new t.Image;return q.on(i,"load",function(t){var r=this.parent(q.Pattern);0===this.width()&&0===this.height()&&this.size(i.width,i.height),r instanceof q.Pattern&&0===r.width()&&0===r.height()&&r.size(this.width(),this.height()),"function"==typeof n&&n.call(this,{width:i.width,height:i.height,ratio:i.width/i.height,url:e})},this),q.on(i,"load error",function(){q.off(i)}),this.attr("href",i.src=e,q.xlink)}},construct:{image:function(t,e){return this.put(new q.Image).size(0,0).load(t,e)}}}),q.Text=q.invent({create:function(t){q.Element.call(this,t||q.create("text")),this.dom.leading=new q.Number(1.3),this._rebuild=!0,this._build=!1,this.attr("font-family",q.defaults.attrs["font-family"])},inherit:q.Parent,extend:{x:function(t){return null==t?this.attr("x"):this.attr("x",t)},y:function(t){var e=this.attr("y"),n="number"==typeof e?e-this.bbox().y:0;return null==t?"number"==typeof e?e-n:e:this.attr("y","number"==typeof t?t+n:t)},cx:function(t){return null==t?this.bbox().cx:this.x(t-this.bbox().width/2)},cy:function(t){return null==t?this.bbox().cy:this.y(t-this.bbox().height/2)},text:function(t){if(void 0===t){var e=this.node.childNodes,n=0;t="";for(var i=0,r=e.length;i<r;++i)"textPath"!==e[i].nodeName?(i!==n&&3!==e[i].nodeType&&!0===q.adopt(e[i]).dom.newLined&&(t+="\n"),t+=e[i].textContent):0===i&&(n=1);return t}if(this.clear().build(!0),"function"==typeof t)t.call(this,this);else{t=t.split("\n");for(var s=0,o=t.length;s<o;s++)this.tspan(t[s]).newLine()}return this.build(!1).rebuild()},leading:function(t){return null==t?this.dom.leading:(this.dom.leading=new q.Number(t),this.rebuild())},rebuild:function(t){if("boolean"==typeof t&&(this._rebuild=t),this._rebuild){var e=this,n=0,i=this.dom.leading*new q.Number(this.attr("font-size"));this.each(function(){this.dom.newLined&&(this.attr("x",e.attr("x")),"\n"===this.text()?n+=i:(this.attr("dy",i+n),n=0))}),this.fire("rebuild")}return this},build:function(t){return this._build=!!t,this},setData:function(t){return this.dom=t,this.dom.leading=new q.Number(t.leading||1.3),this}},construct:{text:function(t){return this.put(new q.Text).text(t)},plain:function(t){return this.put(new q.Text).plain(t)}}}),q.Tspan=q.invent({create:"tspan",inherit:q.Parent,extend:{text:function(t){return null==t?this.node.textContent+(this.dom.newLined?"\n":""):("function"==typeof t?t.call(this,this):this.plain(t),this)},dx:function(t){return this.attr("dx",t)},dy:function(t){return this.attr("dy",t)},newLine:function(){var t=this.parent(q.Text);return this.dom.newLined=!0,this.dy(t.dom.leading*t.attr("font-size")).attr("x",t.x())}}}),q.extend([q.Text,q.Tspan],{plain:function(t){return!1===this._build&&this.clear(),this.node.appendChild(e.createTextNode(t)),this},tspan:function(t){var e=new q.Tspan;return this._build||this.clear(),this.node.appendChild(e.node),e.text(t)},length:function(){return this.node.getComputedTextLength()}}),q.TextPath=q.invent({create:"textPath",inherit:q.Text,parent:q.Parent,extend:{MorphArray:q.PathArray,array:function(){var t=this.track();return t?t.array():null},plot:function(t){var e=this.track(),n=null;return e&&(n=e.plot(t)),null==t?n:this},track:function(){return this.reference("href")}},construct:{textPath:function(t,e){return this.defs().path(e).text(t).addTo(this)}}}),q.extend([q.Text],{path:function(t){var e=new q.TextPath;return t instanceof q.Path||(t=this.doc().defs().path(t)),e.attr("href","#"+t,q.xlink),this.put(e)},textPath:function(){return this.select("textPath")}}),q.extend([q.Path],{text:function(t){if(t instanceof q.Text){var e=t.text();return t.clear().path(this).text(e)}return this.parent().put(new q.Text).path(this).text(t)}}),q.A=q.invent({create:"a",inherit:q.Container,extend:{to:function(t){return this.attr("href",t,q.xlink)},target:function(t){return this.attr("target",t)}},construct:{link:function(t){return this.put(new q.A).to(t)}}}),q.extend(q.Element,{linkTo:function(t){var e=new q.A;return"function"==typeof t?t.call(e,e):e.to(t),this.parent().put(e).put(this)}}),q.Marker=q.invent({create:"marker",inherit:q.Container,extend:{width:function(t){return this.attr("markerWidth",t)},height:function(t){return this.attr("markerHeight",t)},ref:function(t,e){return this.attr("refX",t).attr("refY",e)},update:function(t){return this.clear(),"function"==typeof t&&t.call(this,this),this},toString:function(){return"url(#"+this.id()+")"}},construct:{marker:function(t,e,n){return this.defs().marker(t,e,n)}}}),q.extend(q.Defs,{marker:function(t,e,n){return this.put(new q.Marker).size(t,e).ref(t/2,e/2).viewbox(0,0,t,e).attr("orient","auto").update(n)}}),q.extend([q.Line,q.Polyline,q.Polygon,q.Path],{marker:function(t,e,n,i){var r=["marker"];return"all"!==t&&r.push(t),r=r.join("-"),t=arguments[1]instanceof q.Marker?arguments[1]:this.doc().marker(e,n,i),this.attr(r,t)}});var X={stroke:["color","width","opacity","linecap","linejoin","miterlimit","dasharray","dashoffset"],fill:["color","opacity","rule"],prefix:function(t,e){return"color"===e?t:t+"-"+e}};["fill","stroke"].forEach(function(t){var e,n={};n[t]=function(n){if(void 0===n)return this;if("string"==typeof n||q.Color.isRgb(n)||n&&"function"==typeof n.fill)this.attr(t,n);else for(e=X[t].length-1;e>=0;e--)null!=n[X[t][e]]&&this.attr(X.prefix(t,X[t][e]),n[X[t][e]]);return this},q.extend([q.Element,q.Timeline],n)}),q.extend([q.Element,q.Timeline],{matrix:function(t,e,n,i,r,s){return null==t?new q.Matrix(this):this.attr("transform",new q.Matrix(t,e,n,i,r,s))},rotate:function(t,e,n){return this.transform({rotate:t,ox:e,oy:n},!0)},skew:function(t,e,n,i){return 1===arguments.length||3===arguments.length?this.transform({skew:t,ox:e,oy:n},!0):this.transform({skew:[t,e],ox:n,oy:i},!0)},shear:function(t,e,n){return this.transform({shear:t,ox:e,oy:n},!0)},scale:function(t,e,n,i){return 1===arguments.length||3===arguments.length?this.transform({scale:t,ox:e,oy:n},!0):this.transform({scale:[t,e],ox:n,oy:i},!0)},translate:function(t,e){return this.transform({translate:[t,e]},!0)},relative:function(t,e){return this.transform({relative:[t,e]},!0)},flip:function(t,e){var n="string"==typeof t?t:(isFinite(t),"both"),i="both"===t&&isFinite(e)?[e,e]:"x"===t?[e,0]:"y"===t?[0,e]:isFinite(t)?[t,t]:[0,0];this.transform({flip:n,origin:i},!0)},opacity:function(t){return this.attr("opacity",t)},dx:function(t){return this.x(new q.Number(t).plus(this instanceof q.Timeline?0:this.x()),!0)},dy:function(t){return this.y(new q.Number(t).plus(this instanceof q.Timeline?0:this.y()),!0)},dmove:function(t,e){return this.dx(t).dy(e)}}),q.extend([q.Rect,q.Ellipse,q.Circle,q.Gradient,q.Timeline],{radius:function(t,e){var n=(this._target||this).type;return"radialGradient"===n||"radialGradient"===n?this.attr("r",new q.Number(t)):this.rx(t).ry(null==e?t:e)}}),q.extend(q.Path,{length:function(){return this.node.getTotalLength()},pointAt:function(t){return new q.Point(this.node.getPointAtLength(t))}}),q.extend([q.Parent,q.Text,q.Tspan,q.Timeline],{font:function(t,e){if("object"===c(t))for(e in t)this.font(e,t[e]);return"leading"===t?this.leading(e):"anchor"===t?this.attr("text-anchor",e):"size"===t||"family"===t||"weight"===t||"stretch"===t||"variant"===t||"style"===t?this.attr("font-"+t,e):this.attr(t,e)}}),q.extend(q.Element,{data:function(t,e,n){if("object"===c(t))for(e in t)this.data(e,t[e]);else if(arguments.length<2)try{return JSON.parse(this.attr("data-"+t))}catch(e){return this.attr("data-"+t)}else this.attr("data-"+t,null===e?null:!0===n||"string"==typeof e||"number"==typeof e?e:JSON.stringify(e));return this}}),q.extend(q.Element,{remember:function(t,e){if("object"===c(arguments[0]))for(var n in t)this.remember(n,t[n]);else{if(1===arguments.length)return this.memory()[t];this.memory()[t]=e}return this},forget:function(){if(0===arguments.length)this._memory={};else for(var t=arguments.length-1;t>=0;t--)delete this.memory()[arguments[t]];return this},memory:function(){return this._memory||(this._memory={})}}),q.get=function(t){var n=e.getElementById(O(t)||t);return q.adopt(n)},q.select=function(t,n){return q.utils.map((n||e).querySelectorAll(t),function(t){return q.adopt(t)})},q.$$=function(t,n){return q.utils.map((n||e).querySelectorAll(t),function(t){return q.adopt(t)})},q.$=function(t,n){return q.adopt((n||e).querySelector(t))},q.extend(q.Parent,{select:function(t){return q.select(t,this.node)}});var Y="abcdef".split("");q.Box=q.invent({create:function(t){var e=[0,0,0,0];t="string"==typeof t?t.split(q.regex.delimiter).map(parseFloat):Array.isArray(t)?t:"object"===c(t)?[null!=t.left?t.left:t.x,null!=t.top?t.top:t.y,t.width,t.height]:4===arguments.length?[].slice.call(arguments):e,this.x=t[0],this.y=t[1],this.width=t[2],this.height=t[3],E(this)},extend:{merge:function(t){var e=Math.min(this.x,t.x),n=Math.min(this.y,t.y);return new q.Box(e,n,Math.max(this.x+this.width,t.x+t.width)-e,Math.max(this.y+this.height,t.y+t.height)-n)},transform:function(t){var e=1/0,n=-1/0,i=1/0,r=-1/0;return[new q.Point(this.x,this.y),new q.Point(this.x2,this.y),new q.Point(this.x,this.y2),new q.Point(this.x2,this.y2)].forEach(function(s){s=s.transform(t),e=Math.min(e,s.x),n=Math.max(n,s.x),i=Math.min(i,s.y),r=Math.max(r,s.y)}),new q.Box(e,i,n-e,r-i)},addOffset:function(){return this.x+=t.pageXOffset,this.y+=t.pageYOffset,this},toString:function(){return this.x+" "+this.y+" "+this.width+" "+this.height},toArray:function(){return[this.x,this.y,this.width,this.height]},morph:function(t,e,n,i){return this.destination=new q.Box(t,e,n,i),this},at:function(t){return this.destination?new q.Box(this.x+(this.destination.x-this.x)*t,this.y+(this.destination.y-this.y)*t,this.width+(this.destination.width-this.width)*t,this.height+(this.destination.height-this.height)*t):this}},parent:q.Element,construct:{bbox:function(){var t;try{if(t=this.node.getBBox(),d(t)&&!p(this.node))throw new Exception("Element not in the dom")}catch(n){try{var e=this.clone(q.parser().svg).show();t=e.node.getBBox(),e.remove()}catch(t){console.warn("Getting a bounding box of this element is not possible")}}return new q.Box(t)},rbox:function(t){try{var e=new q.Box(this.node.getBoundingClientRect());return t?e.transform(t.screenCTM().inverse()):e.addOffset()}catch(t){return new q.Box}}}}),q.extend([q.Doc,q.Symbol,q.Image,q.Pattern,q.Marker,q.ForeignObject,q.View],{viewbox:function(t,e,n,i){return null==t?new q.Box(this.attr("viewBox")):this.attr("viewBox",new q.Box(t,e,n,i))}}),q.parser=function(){var t;return q.parser.nodes.svg.node.parentNode||(t=e.body||e.documentElement,q.parser.nodes.svg.addTo(t)),q.parser.nodes},q.parser.nodes={svg:q().size(2,0).css({opacity:0,position:"absolute",left:"-100%",top:"-100%",overflow:"hidden"})},q.parser.nodes.path=q.parser.nodes.svg.path().node,q.Animator={nextDraw:null,frames:new q.Queue,timeouts:new q.Queue,timer:t.performance||t.Date,transforms:[],frame:function(t){var e=q.Animator.frames.push({run:t});return null===q.Animator.nextDraw&&(q.Animator.nextDraw=requestAnimationFrame(q.Animator._draw)),e},transform_frame:function(t,e){q.Animator.transforms[e]=t},timeout:function(t,e){e=e||0;var n=q.Animator.timer.now()+e,i=q.Animator.timeouts.push({run:t,time:n});return null===q.Animator.nextDraw&&(q.Animator.nextDraw=requestAnimationFrame(q.Animator._draw)),i},cancelFrame:function(t){q.Animator.frames.remove(t)},clearTimeout:function(t){q.Animator.timeouts.remove(t)},_draw:function(t){for(var e=null,n=q.Animator.timeouts.last();(e=q.Animator.timeouts.shift())&&(t>=e.time?e.run():q.Animator.timeouts.push(e),e!==n););for(var i=null,r=q.Animator.frames.last();i!==r&&(i=q.Animator.frames.shift());)i.run();q.Animator.transforms.forEach(function(t){t()}),q.Animator.nextDraw=q.Animator.timeouts.first()||q.Animator.frames.first()?requestAnimationFrame(q.Animator._draw):null}},q.Morphable=q.invent({create:function(t){this._stepper=t||new q.Ease("-"),this._from=null,this._to=null,this._type=null,this._context=null,this._morphObj=null},extend:{from:function(t){return null==t?this._from:(this._from=this._set(t),this)},to:function(t){return null==t?this._to:(this._to=this._set(t),this)},type:function(t){return null==t?this._type:(this._type=t,this)},_set:function(t){if(!this._type){var e=c(t);"number"===e?this.type(q.Number):"string"===e?q.Color.isColor(t)?this.type(q.Color):q.regex.delimiter.test(t)?this.type(q.regex.pathLetters.test(t)?q.PathArray:q.Array):q.regex.numberAndUnit.test(t)?this.type(q.Number):this.type(q.Morphable.NonMorphable):q.MorphableTypes.indexOf(t.constructor)>-1?this.type(t.constructor):Array.isArray(t)?this.type(q.Array):"object"===e?this.type(q.Morphable.ObjectBag):this.type(q.Morphable.NonMorphable)}var n=new this._type(t).toArray();return this._morphObj=this._morphObj||new this._type,this._context=this._context||Array.apply(null,Array(n.length)).map(Object),n},stepper:function(t){return null==t?this._stepper:(this._stepper=t,this)},done:function(){return this._context.map(this._stepper.done).reduce(function(t,e){return t&&e},!0)},at:function(t){var e=this;return this._morphObj.fromArray(this._from.map(function(n,i){return e._stepper.step(n,e._to[i],t,e._context[i],e._context)}))}}}),q.Morphable.NonMorphable=q.invent({create:function(t){t=Array.isArray(t)?t[0]:t,this.value=t},extend:{valueOf:function(){return this.value},toArray:function(){return[this.value]}}}),q.Morphable.TransformBag=q.invent({create:function(t){Array.isArray(t)&&(t={scaleX:t[0],scaleY:t[1],shear:t[2],rotate:t[3],translateX:t[4],translateY:t[5],originX:t[6],originY:t[7]}),Object.assign(this,q.Morphable.TransformBag.defaults,t)},extend:{toArray:function(){var t=this;return[t.scaleX,t.scaleY,t.shear,t.rotate,t.translateX,t.translateY,t.originX,t.originY]}}}),q.Morphable.TransformBag.defaults={scaleX:1,scaleY:1,shear:0,rotate:0,translateX:0,translateY:0,originX:0,originY:0},q.Morphable.ObjectBag=q.invent({create:function(t){if(this.values=[],Array.isArray(t))return void(this.values=t);var e=Object.entries(t||{}).sort(function(t,e){return t[0]-e[0]});this.values=e.reduce(function(t,e){return t.concat(e)},[])},extend:{valueOf:function(){for(var t={},e=this.values,n=0,i=e.length;n<i;n+=2)t[e[n]]=e[n+1];return t},toArray:function(){return this.values}}}),q.MorphableTypes=[q.Number,q.Color,q.Box,q.Matrix,q.Array,q.PointArray,q.PathArray,q.Morphable.NonMorphable,q.Morphable.TransformBag,q.Morphable.ObjectBag],q.extend(q.MorphableTypes,{to:function(t,e){return(new q.Morphable).type(this.constructor).from(this.valueOf()).to(t,e)},fromArray:function(t){return this.constructor(t),this}}),q.easing={"-":function(t){return t},"<>":function(t){return-Math.cos(t*Math.PI)/2+.5},">":function(t){return Math.sin(t*Math.PI/2)},"<":function(t){return 1-Math.cos(t*Math.PI/2)}},q.Runner=q.invent({parent:q.Element,create:function(t){this.id=q.Runner.id++,t=null==t?q.defaults.timeline.duration:t,t="function"==typeof t?new q.Controller(t):t,this._element=null,this._timeline=null,this.done=!1,this._queue=[],this._duration="number"==typeof t&&t,this._isDeclarative=t instanceof q.Controller,this._stepper=this._isDeclarative?t:new q.Ease,this._history={},this.enabled=!0,this._time=0,this._last=0,this.tags={},this.transforms=new q.Matrix,this.transformId=1,this._haveReversed=!1,this._reverse=!1,this._loopsDone=0,this._swing=!1,this._wait=0,this._times=1},construct:{animate:function(t,e,n){var i=q.Runner.sanitise(t,e,n),r=this.timeline();return new q.Runner(i.duration).loop(i).element(this).timeline(r).schedule(e,n)},delay:function(t,e){return this.animate(0,t,e)}},extend:{element:function(t){return null==t?this._element:(this._element=t,t._prepareRunner(),this)},timeline:function(t){return void 0===t?this._timeline:(this._timeline=t,this)},animate:function(t,e,n){var i=q.Runner.sanitise(t,e,n),r=new q.Runner(i.duration);return this._timeline&&r.timeline(this._timeline),this._element&&r.element(this._element),r.loop(i).schedule(e,n)},schedule:function(t,e,n){if(t instanceof q.Timeline||(n=e,e=t,t=this.timeline()),!t)throw Error("Runner cannot be scheduled without timeline");return t.schedule(this,e,n),this},unschedule:function(){var t=this.timeline();return t&&t.unschedule(this),this},loop:function(t,e,n){return"object"===c(t)&&(e=t.swing,n=t.wait,t=t.times),this._times=t||1/0,this._swing=e||!1,this._wait=n||0,this},delay:function(t){return this.animate(0,t)},queue:function(t,e,n){return this._queue.push({initialiser:t||q.void,runner:e||q.void,isTransform:n,initialised:!1,finished:!1}),this.timeline()&&this.timeline()._continue(),this},during:function(t){return this.queue(null,t)},after:function(t){return this.on("finish",t)},time:function(t){if(null==t)return this._time;var e=t-this._time;return this.step(e),this},duration:function(){return this._times*(this._wait+this._duration)-this._wait},loops:function(t){var e=this._duration+this._wait;if(null==t){var n=Math.floor(this._time/e),i=this._time-n*e,r=i/this._duration;return Math.min(n+r,this._times)}var s=Math.floor(t),o=t%1,a=e*s+this._duration*o;return this.time(a)},position:function(t){var e,n=this._time,i=this._duration,r=this._wait,s=this._times,o=this._swing,a=this._reverse;if(null==t){var h=function(t){var e=o*Math.floor(t%(2*(r+i))/(r+i)),n=e&&!a||!e&&a,s=Math.pow(-1,n)*(t%(r+i))/i+n;return Math.max(Math.min(s,1),0)},u=s*(r+i)-r;return e=n<=0?Math.round(h(1e-5)):n<u?h(n):Math.round(h(u-1e-5)),e}var l=Math.floor(this.loops()),c=o&&l%2==0;return e=l+(c&&!a||a&&c?t:1-t),this.loops(e)},progress:function(t){return null==t?Math.min(1,this._time/this.duration()):this.time(t*this.duration())},step:function(t){if(!this.enabled)return this;t=null==t?16:t,this._time+=t;var e=this.position(),n=this._lastPosition!==e&&this._time>=0;this._lastPosition=e;var i=this.duration(),r=(this._lastTime<0&&this._time,this._lastTime<this._time&&this.time>i);this._lastTime=this._time;var s=this._isDeclarative;if(this.done=!s&&!r&&this._time>=i,n||s){this._initialise(n),this.transforms=new q.Matrix;var o=this._run(s?t:e)}return this.done=this.done||o&&s,this},finish:function(){return this.step(1/0)},reverse:function(t){return this._reverse=null==t?!this._reverse:t,this},ease:function(t){return this._stepper=new q.Ease(t),this},active:function(t){return null==t?this.enabled:(this.enabled=t,this)},tag:function(t){if(null==t)return Object.keys(this.tags);t=Array.isArray(t)?t:[t];for(var e=t.length;e--;)this.tags[t[e]]=!0;return this},untag:function(t){t=Array.isArray(t)?t:[t];for(var e=t.length;e--;)delete this.tags[t[e]];return this},getEventTarget:function(){return this._dispatcher},_rememberMorpher:function(t,e){this._history[t]={morpher:e,caller:this._queue[this._queue.length-1]}},_tryRetarget:function(t,e){if(this._history[t]){if(!this._history[t].caller.initialised){var n=this._queue.indexOf(this._history[t].caller);return this._queue.splice(n,1),!1}this._history[t].caller.isTransform?this._history[t].caller.isTransform(e):this._history[t].morpher.to(e),this._history[t].caller.finished=!1;var i=this.timeline();return i&&i._continue(),!0}return!1},_initialise:function(t){if(t||this._isDeclarative)for(var e=0,n=this._queue.length;e<n;++e){var i=this._queue[e],r=this._isDeclarative||!i.initialised&&t;t=!i.finished,r&&t&&(i.initialiser.call(this),i.initialised=!0)}},_run:function(t){for(var e=!0,n=0,i=this._queue.length;n<i;++n){var r=this._queue[n],s=r.runner.call(this,t);r.finished=r.finished||!0===s,e=e&&r.finished}return e},addTransform:function(t,e){return this.transforms.lmultiplyO(t),this},clearTransform:function(){return this.transforms=new q.Matrix,this}}}),q.Runner.id=0,q.Runner.sanitise=function(t,e,n){var i=1,r=!1,s=0;return t=t||q.defaults.timeline.duration,e=e||q.defaults.timeline.delay,n=n||"last","object"!==c(t)||t instanceof q.Stepper||(e=t.delay||e,
n=t.when||n,r=t.swing||r,i=t.times||i,s=t.wait||s,t=t.duration||q.defaults.timeline.duration),{duration:t,delay:e,swing:r,times:i,wait:s,when:n}},q.FakeRunner=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new q.Matrix,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:-1,i=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];h(this,t),this.transforms=e,this.id=n,this.done=i}return t}(),q.extend([q.Runner,q.FakeRunner],{mergeWith:function(t){return new q.FakeRunner(t.transforms.lmultiply(this.transforms),t.id)}});var G=function(t,e){return t.lmultiplyO(e)},V=function(t){return t.transforms},H=function(){function t(){h(this,t),this.runners=[],this.ids=[]}return a(t,[{key:"add",value:function(t){if(!this.runners.includes(t)){var e=t.id+1,n=this.ids.reduce(function(t,n){return n>t&&n<e?n:t},0),i=this.ids.indexOf(n)+1;return this.ids.splice(i,0,e),this.runners.splice(i,0,t),this}}},{key:"getByID",value:function(t){return this.runners[this.ids.indexOf(t+1)]}},{key:"remove",value:function(t){var e=this.ids.indexOf(t+1);return this.ids.splice(e,1),this.runners.splice(e,1),this}},{key:"merge",value:function(){var t=this,e=null;return this.runners.forEach(function(n,i){e&&n.done&&e.done&&(t.remove(n.id),t.edit(e.id,n.mergeWith(e))),e=n}),this}},{key:"edit",value:function(t,e){var n=this.ids.indexOf(t+1);return this.ids.splice(n,1,t),this.runners.splice(n,1,e),this}},{key:"length",value:function(){return this.ids.length}},{key:"clearBefore",value:function(t){var e=this.ids.indexOf(t+1)||1;return this.ids.splice(0,e,0),this.runners.splice(0,e,new q.FakeRunner),this}}]),t}();q.extend(q.Element,{_clearTransformRunnersBefore:function(t){this._transformationRunners.clearBefore(t.id)},_currentTransform:function(t){return this._transformationRunners.runners.filter(function(e){return e.id<=t.id}).map(V).reduce(G,new q.Matrix)},addRunner:function(t){this._transformationRunners.add(t),q.Animator.transform_frame(D.bind(this),this._frameId)},_prepareRunner:function(){null==this._frameId&&(this._transformationRunners=(new H).add(new q.FakeRunner(new q.Matrix(this))),this._frameId=q.Element.frameId++)}}),q.Element.frameId=0,q.extend(q.Runner,{attr:function(t,e){return this.styleAttr("attr",t,e)},css:function(t,e){return this.styleAttr("css",t,e)},styleAttr:function(t,e,n){if("object"===c(e))for(var i in n)this.styleAttr(t,i,n[i]);var r=new q.Morphable(this._stepper).to(n);return this.queue(function(){r=r.from(this.element()[t](e))},function(n){return this.element()[t](e,r.at(n)),r.done()}),this},zoom:function(t,e){var n=new q.Morphable(this._stepper).to(new q.Number(t));return this.queue(function(){n=n.from(this.zoom())},function(t){return this.element().zoom(n.at(t),e),n.done()}),this},transform:function(t,e,i){function r(){l=l||this.element(),h=h||j(t,l),d=new q.Matrix(e?void 0:l),l.addRunner(this),e||l._clearTransformRunnersBefore(this)}function s(r){e||this.clearTransform();var s=new q.Point(h).transform(l._currentTransform(this)),o=s.x,m=s.y,v=new q.Matrix(u({},t,{origin:[o,m]})),y=this._isDeclarative&&c?c:d;if(i){v=v.decompose(o,m),y=y.decompose(o,m);var x=v.rotate,g=y.rotate,w=[x-360,x,x+360],b=w.map(function(t){return Math.abs(t-g)}),_=Math.min.apply(Math,n(b)),A=b.indexOf(_);v.rotate=w[A]}e&&(a||(v.rotate=t.rotate||0),this._isDeclarative&&f&&(y.rotate=f)),p.from(y),p.to(v);var M=p.at(r);return f=M.rotate,c=new q.Matrix(M),this.addTransform(c),p.done()}function o(e){(e.origin||"center").toString()!==(t.origin||"center").toString()&&(h=j(t,l)),t=u({},e,{origin:h})}if(e=t.relative||e,this._isDeclarative&&!e&&this._tryRetarget("transform",t))return this;var a=k(t);i=null!=t.affine?t.affine:null!=i?i:!a;var h,l,c,f,d,p=(new q.Morphable).type(i?q.Morphable.TransformBag:q.Matrix).stepper(this._stepper);return this.queue(r,s,o),this._isDeclarative&&this._rememberMorpher("transform",p),this},x:function(t,e){return this._queueNumber("x",t)},y:function(t){return this._queueNumber("y",t)},dx:function(t){return this._queueNumberDelta("dx",t)},dy:function(t){return this._queueNumberDelta("dy",t)},_queueNumberDelta:function(t,e){if(e=new q.Number(e),this._tryRetargetDelta(t,e))return this;var n=new q.Morphable(this._stepper).to(e);return this.queue(function(){var i=this.element()[t]();n.from(i),n.to(i+e)},function(e){return this.element()[t](n.at(e)),n.done()}),this._rememberMorpher(t,n),this},_queueObject:function(t,e){if(this._tryRetarget(t,e))return this;var n=new q.Morphable(this._stepper).to(e);return this.queue(function(){n.from(this.element()[t]())},function(e){return this.element()[t](n.at(e)),n.done()}),this._rememberMorpher(t,n),this},_queueNumber:function(t,e){return this._queueObject(t,new q.Number(e))},cx:function(t){return this._queueNumber("cx",t)},cy:function(t){return this._queueNumber("cy",t)},move:function(t,e){return this.x(t).y(e)},center:function(t,e){return this.cx(t).cy(e)},size:function(t,e){var n;return t&&e||(n=this._element.bbox()),t||(t=n.width/n.height*e),e||(e=n.height/n.width*t),this.width(t).height(e)},width:function(t){return this._queueNumber("width",t)},height:function(t){return this._queueNumber("height",t)},plot:function(t,e,n,i){return 4===arguments.length?this.plot([t,e,n,i]):this._queueObject("plot",new this._element.MorphArray(t))},leading:function(t){return this._queueNumber("leading",t)},viewbox:function(t,e,n,i){return this._queueObject("viewbox",new q.Box(t,e,n,i))},update:function(t){return"object"!==c(t)?this.update({offset:arguments[0],color:arguments[1],opacity:arguments[2]}):(null!=t.opacity&&this.attr("stop-opacity",t.opacity),null!=t.color&&this.attr("stop-color",t.color),null!=t.offset&&this.attr("offset",t.offset),this)}}),q.easing={"-":function(t){return t},"<>":function(t){return-Math.cos(t*Math.PI)/2+.5},">":function(t){return Math.sin(t*Math.PI/2)},"<":function(t){return 1-Math.cos(t*Math.PI/2)}};var U=t.performance||Date,$=function(t){var e=t.start,n=t.runner.duration();return{start:e,duration:n,end:e+n,runner:t.runner}};return q.Timeline=q.invent({inherit:q.EventTarget,create:function(){this._timeSource=function(){return U.now()},this._dispatcher=e.createElement("div"),this._startTime=0,this._speed=1,this._reverse=!1,this._persist=0,this._nextFrame=null,this._paused=!1,this._runners=[],this._order=[],this._time=0,this._lastSourceTime=0,this._lastStepTime=0},extend:{getEventTarget:function(){return this._dispatcher},schedule:function(t,e,n){if(null==t)return this._runners.map($).sort(function(t,e){return t.start-e.start||t.duration-e.duration});this.active()||(this._step(),null==n&&(n="now"));var i=0;if(e=e||0,null==n||"last"===n||"after"===n)i=this._startTime;else if("absolute"===n||"start"===n)i=e,e=0;else if("now"===n)i=this._time;else{if("relative"!==n)throw new Error('Invalid value for the "when" parameter');var r=this._runners[t.id];r&&(i=r.start+e,e=0)}return t.unschedule(),t.timeline(this),t.time(-e),this._startTime=i+t.duration()+e,this._runners[t.id]={persist:this.persist(),runner:t,start:i},this._order.push(t.id),this._continue(),this},unschedule:function(t){var e=this._order.indexOf(t.id);return e<0?this:(delete this._runners[t.id],this._order.splice(e,1),t.timeline(null),this)},play:function(){return this._paused=!1,this._continue()},pause:function(){return this._nextFrame=null,this._paused=!0,this},stop:function(){return this.seek(-this._time),this.pause()},finish:function(){return this.seek(1/0),this.pause()},speed:function(t){return null==t?this._speed:(this._speed=t,this)},reverse:function(t){var e=this.speed();if(null==t)return this.speed(-e);var n=Math.abs(e);return this.speed(t?n:-n)},seek:function(t){return this._time+=t,this._continue()},time:function(t){return null==t?this._time:(this._time=t,this)},persist:function(t){return null==t?this._persist:(this._persist=t,this)},source:function(t){return null==t?this._timeSource:(this._timeSource=t,this)},_step:function(){if(!this._paused){var t=this._timeSource(),e=t-this._lastSourceTime,n=this._speed*e+(this._time-this._lastStepTime);this._lastSourceTime=t,this._time+=n,this._lastStepTime=this._time;for(var i=!1,r=0,s=this._order.length;r<s;r++){var o=this._runners[this._order[r]],a=o.runner,h=n,u=this._time-o.start;if(u<0)i=!0;else if(u<h&&(h=u),a.active()){var l=a.step(h).done;if(l){if(!0!==o.persist){var c=a.duration()-a.time()+this._time;c+this._persist<this._time&&(delete this._runners[this._order[r]],this._order.splice(r--,1)&&--s,a.timeline(null))}}else i=!0}}return this._nextFrame=i?q.Animator.frame(this._step.bind(this)):null,this}},_continue:function(){return this._paused?this:(this._nextFrame||(this._nextFrame=q.Animator.frame(this._step.bind(this))),this)},active:function(){return!!this._nextFrame}},parent:q.Element,construct:{timeline:function(){return this._timeline=this._timeline||new q.Timeline,this._timeline}}}),q.Stepper=q.invent({create:function(){}}),q.Ease=q.invent({inherit:q.Stepper,create:function(t){q.Stepper.call(this,t),this.ease=q.easing[t||q.defaults.timeline.ease]||t},extend:{step:function(t,e,n){return"number"!=typeof t?n<1?t:e:t+(e-t)*this.ease(n)},done:function(t,e){return!1}}}),q.easing={"-":function(t){return t},"<>":function(t){return-Math.cos(t*Math.PI)/2+.5},">":function(t){return Math.sin(t*Math.PI/2)},"<":function(t){return 1-Math.cos(t*Math.PI/2)},bezier:function(t,e,n,i){return function(t){}}},q.Controller=q.invent({inherit:q.Stepper,create:function(t){q.Stepper.call(this,t),this.stepper=t},extend:{step:function(t,e,n,i){return this.stepper(t,e,n,i)},done:function(t){return t.done}}}),q.Spring=q.invent({inherit:q.Controller,create:function(t,e){this.duration(t||500).overshoot(e||0)},extend:{step:function(t,e,n,i){if("string"==typeof t)return t;if(i.done=n===1/0,n===1/0)return e;if(0===n)return t;n>100&&(n=16),n/=1e3;var r=i.velocity||0,s=-this.d*r-this.k*(t-e),o=t+r*n+s*n*n/2;return i.velocity=r+s*n,i.done=Math.abs(e-o)+Math.abs(r)<.002,i.done?e:o},duration:R("_duration",I),overshoot:R("_overshoot",I)}}),q.PID=q.invent({inherit:q.Controller,create:function(t,e,n,i){q.Controller.call(this),t=null==t?.1:t,e=null==e?.01:e,n=null==n?0:n,i=null==i?1e3:i,this.p(t).i(e).d(n).windup(i)},extend:{step:function(t,e,n,i){if("string"==typeof t)return t;if(i.done=n===1/0,n===1/0)return e;if(0===n)return t;var r=e-t,s=(i.integral||0)+r*n,o=(r-(i.error||0))/n,a=this.windup;return!1!==a&&(s=Math.max(-a,Math.min(s,a))),i.error=r,i.integral=s,i.done=Math.abs(r)<.001,i.done?e:t+(this.P*r+this.I*s+this.D*o)},windup:R("windup"),p:R("P"),i:R("I"),d:R("D")}}),q});