UNPKG

jointjs

Version:

JavaScript diagramming library

8 lines (6 loc) 336 kB
/*! JointJS v3.4.4 (2021-09-27) - JavaScript diagramming library This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. */ if(function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("backbone"),require("lodash"),require("jquery")):"function"==typeof define&&define.amd?define(["exports","backbone","lodash","jquery"],e):e((t=t||self).joint={},t.Backbone,t._,t.$)}(this,function(t,s,n,T){"use strict";s=s&&s.hasOwnProperty("default")?s.default:s,n=n&&n.hasOwnProperty("default")?n.default:n,T=T&&T.hasOwnProperty("default")?T.default:T;var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function i(t,e){return t(e={exports:{}},e.exports),e.exports}var r=function(t){return t&&t.Math==Math&&t},u=r("object"==typeof globalThis&&globalThis)||r("object"==typeof window&&window)||r("object"==typeof self&&self)||r("object"==typeof e&&e)||function(){return this}()||Function("return this")(),a=function(t){try{return!!t()}catch(t){return!0}},h=!a(function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]}),o={}.propertyIsEnumerable,l=Object.getOwnPropertyDescriptor,c={f:l&&!o.call({1:2},1)?function(t){var e=l(this,t);return!!e&&e.enumerable}:o},w=function(t,e){return{enumerable:!(1&t),configurable:!(2&t),writable:!(4&t),value:e}},d={}.toString,f=function(t){return d.call(t).slice(8,-1)},p="".split,x=a(function(){return!Object("z").propertyIsEnumerable(0)})?function(t){return"String"==f(t)?p.call(t,""):Object(t)}:Object,g=function(t){if(null==t)throw TypeError("Can't call method on "+t);return t},v=function(t){return x(g(t))},m=function(t){return"object"==typeof t?null!==t:"function"==typeof t},y=function(t,e){if(!m(t))return t;var n,i;if(e&&"function"==typeof(n=t.toString)&&!m(i=n.call(t)))return i;if("function"==typeof(n=t.valueOf)&&!m(i=n.call(t)))return i;if(!e&&"function"==typeof(n=t.toString)&&!m(i=n.call(t)))return i;throw TypeError("Can't convert object to primitive value")},b={}.hasOwnProperty,A=function(t,e){return b.call(t,e)},S=u.document,P=m(S)&&m(S.createElement),E=function(t){return P?S.createElement(t):{}},k=!h&&!a(function(){return 7!=Object.defineProperty(E("div"),"a",{get:function(){return 7}}).a}),C=Object.getOwnPropertyDescriptor,L={f:h?C:function(t,e){if(t=v(t),e=y(e,!0),k)try{return C(t,e)}catch(t){}if(A(t,e))return w(!c.f.call(t,e),t[e])}},M=function(t){if(!m(t))throw TypeError(String(t)+" is not an object");return t},N=Object.defineProperty,_={f:h?N:function(t,e,n){if(M(t),e=y(e,!0),M(n),k)try{return N(t,e,n)}catch(t){}if("get"in n||"set"in n)throw TypeError("Accessors not supported");return"value"in n&&(t[e]=n.value),t}},R=h?function(t,e,n){return _.f(t,e,w(1,n))}:function(t,e,n){return t[e]=n,t},O=function(e,n){try{R(u,e,n)}catch(t){u[e]=n}return n},V="__core-js_shared__",F=u[V]||O(V,{}),B=Function.toString;"function"!=typeof F.inspectSource&&(F.inspectSource=function(t){return B.call(t)});var D,I,z,j=F.inspectSource,G=u.WeakMap,U="function"==typeof G&&/native code/.test(j(G)),q=i(function(t){(t.exports=function(t,e){return F[t]||(F[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.8.3",mode:"global",copyright:"\xa9 2021 Denis Pushkarev (zloirock.ru)"})}),H=0,Y=Math.random(),$=function(t){return"Symbol("+String(void 0===t?"":t)+")_"+(++H+Y).toString(36)},X=q("keys"),W=function(t){return X[t]||(X[t]=$(t))},Z={},J=u.WeakMap;if(U){var K=F.state||(F.state=new J),Q=K.get,tt=K.has,et=K.set;D=function(t,e){return e.facade=t,et.call(K,t,e),e},I=function(t){return Q.call(K,t)||{}},z=function(t){return tt.call(K,t)}}else{var nt=W("state");Z[nt]=!0,D=function(t,e){return e.facade=t,R(t,nt,e),e},I=function(t){return A(t,nt)?t[nt]:{}},z=function(t){return A(t,nt)}}var it,rt={set:D,get:I,has:z,enforce:function(t){return z(t)?I(t):D(t,{})},getterFor:function(n){return function(t){var e;if(!m(t)||(e=I(t)).type!==n)throw TypeError("Incompatible receiver, "+n+" required");return e}}},ot=i(function(t){var e=rt.get,h=rt.enforce,l=String(String).split("String");(t.exports=function(t,e,n,i){var r,o=!!i&&!!i.unsafe,s=!!i&&!!i.enumerable,a=!!i&&!!i.noTargetGet;"function"==typeof n&&("string"!=typeof e||A(n,"name")||R(n,"name",e),(r=h(n)).source||(r.source=l.join("string"==typeof e?e:""))),t!==u?(o?!a&&t[e]&&(s=!0):delete t[e],s?t[e]=n:R(t,e,n)):s?t[e]=n:O(e,n)})(Function.prototype,"toString",function(){return"function"==typeof this&&e(this).source||j(this)})}),st=u,at=function(t){return"function"==typeof t?t:void 0},ht=function(t,e){return arguments.length<2?at(st[t])||at(u[t]):st[t]&&st[t][e]||u[t]&&u[t][e]},lt=Math.ceil,ut=Math.floor,ct=function(t){return isNaN(t=+t)?0:(0<t?ut:lt)(t)},dt=Math.min,ft=function(t){return 0<t?dt(ct(t),9007199254740991):0},pt=Math.max,gt=Math.min,vt=function(l){return function(t,e,n){var i,r,o,s=v(t),a=ft(s.length),h=(i=a,(r=ct(n))<0?pt(r+i,0):gt(r,i));if(l&&e!=e){for(;h<a;)if((o=s[h++])!=o)return!0}else for(;h<a;h++)if((l||h in s)&&s[h]===e)return l||h||0;return!l&&-1}},mt={includes:vt(!0),indexOf:vt(!1)},yt=mt.indexOf,bt=function(t,e){var n,i=v(t),r=0,o=[];for(n in i)!A(Z,n)&&A(i,n)&&o.push(n);for(;e.length>r;)A(i,n=e[r++])&&(~yt(o,n)||o.push(n));return o},wt=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],xt=wt.concat("length","prototype"),At={f:Object.getOwnPropertyNames||function(t){return bt(t,xt)}},St={f:Object.getOwnPropertySymbols},Pt=ht("Reflect","ownKeys")||function(t){var e=At.f(M(t)),n=St.f;return n?e.concat(n(t)):e},Et=function(t,e){for(var n=Pt(e),i=_.f,r=L.f,o=0;o<n.length;o++){var s=n[o];A(t,s)||i(t,s,r(e,s))}},kt=/#|\.prototype\./,Tt=function(t,e){var n=Lt[Ct(t)];return n==Nt||n!=Mt&&("function"==typeof e?a(e):!!e)},Ct=Tt.normalize=function(t){return String(t).replace(kt,".").toLowerCase()},Lt=Tt.data={},Mt=Tt.NATIVE="N",Nt=Tt.POLYFILL="P",_t=Tt,Rt=L.f,Ot=function(t,e){var n,i,r,o,s,a=t.target,h=t.global,l=t.stat;if(n=h?u:l?u[a]||O(a,{}):(u[a]||{}).prototype)for(i in e){if(o=e[i],r=t.noTargetGet?(s=Rt(n,i))&&s.value:n[i],!_t(h?i:a+(l?".":"#")+i,t.forced)&&void 0!==r){if(typeof o==typeof r)continue;Et(o,r)}(t.sham||r&&r.sham)&&R(o,"sham",!0),ot(n,i,o,t)}},Vt=!!Object.getOwnPropertySymbols&&!a(function(){return!String(Symbol())}),Ft=Vt&&!Symbol.sham&&"symbol"==typeof Symbol.iterator,Bt=q("wks"),Dt=u.Symbol,It=Ft?Dt:Dt&&Dt.withoutSetter||$,zt=function(t){return A(Bt,t)||(Vt&&A(Dt,t)?Bt[t]=Dt[t]:Bt[t]=It("Symbol."+t)),Bt[t]},jt=Object.keys||function(t){return bt(t,wt)},Gt=h?Object.defineProperties:function(t,e){M(t);for(var n,i=jt(e),r=i.length,o=0;o<r;)_.f(t,n=i[o++],e[n]);return t},Ut=ht("document","documentElement"),qt="prototype",Ht="script",Yt=W("IE_PROTO"),$t=function(){},Xt=function(t){return"<script>"+t+"</"+Ht+">"},Wt=function(){try{it=document.domain&&new ActiveXObject("htmlfile")}catch(t){}var t,e;Wt=it?function(t){t.write(Xt("")),t.close();var e=t.parentWindow.Object;return t=null,e}(it):((e=E("iframe")).style.display="none",Ut.appendChild(e),e.src=String("javascript:"),(t=e.contentWindow.document).open(),t.write(Xt("document.F=Object")),t.close(),t.F);for(var n=wt.length;n--;)delete Wt[qt][wt[n]];return Wt()};Z[Yt]=!0;var Zt=Object.create||function(t,e){var n;return null!==t?($t[qt]=M(t),n=new $t,$t[qt]=null,n[Yt]=t):n=Wt(),void 0===e?n:Gt(n,e)},Jt=zt("unscopables"),Kt=Array.prototype;null==Kt[Jt]&&_.f(Kt,Jt,{configurable:!0,value:Zt(null)});var Qt=function(t){Kt[Jt][t]=!0},te=Object.defineProperty,ee={},ne=function(t){throw t},ie=function(t,e){if(A(ee,t))return ee[t];e||(e={});var n=[][t],i=!!A(e,"ACCESSORS")&&e.ACCESSORS,r=A(e,0)?e[0]:ne,o=A(e,1)?e[1]:void 0;return ee[t]=!!n&&!a(function(){if(i&&!h)return!0;var t={length:-1};i?te(t,1,{enumerable:!0,get:ne}):t[1]=1,n.call(t,r,o)})},re=mt.includes,oe=ie("indexOf",{ACCESSORS:!0,1:0});Ot({target:"Array",proto:!0,forced:!oe},{includes:function(t){return re(this,t,1<arguments.length?arguments[1]:void 0)}}),Qt("includes");var se=function(i,r,t){if(function(t){if("function"!=typeof t)throw TypeError(String(t)+" is not a function")}(i),void 0===r)return i;switch(t){case 0:return function(){return i.call(r)};case 1:return function(t){return i.call(r,t)};case 2:return function(t,e){return i.call(r,t,e)};case 3:return function(t,e,n){return i.call(r,t,e,n)}}return function(){return i.apply(r,arguments)}},ae=Function.call,he=function(t,e,n){return se(ae,u[t].prototype[e],n)},le=(he("Array","includes"),function(t){return Object(g(t))}),ue=Array.isArray||function(t){return"Array"==f(t)},ce=zt("species"),de=function(t,e){var n;return ue(t)&&("function"!=typeof(n=t.constructor)||n!==Array&&!ue(n.prototype)?m(n)&&null===(n=n[ce])&&(n=void 0):n=void 0),new(void 0===n?Array:n)(0===e?0:e)},fe=[].push,pe=function(f){var p=1==f,g=2==f,v=3==f,m=4==f,y=6==f,b=7==f,w=5==f||y;return function(t,e,n,i){for(var r,o,s=le(t),a=x(s),h=se(e,n,3),l=ft(a.length),u=0,c=i||de,d=p?c(t,l):g||b?c(t,0):void 0;u<l;u++)if((w||u in a)&&(o=h(r=a[u],u,s),f))if(p)d[u]=o;else if(o)switch(f){case 3:return!0;case 5:return r;case 6:return u;case 2:fe.call(d,r)}else switch(f){case 4:return!1;case 7:fe.call(d,r)}return y?-1:v||m?m:d}},ge={forEach:pe(0),map:pe(1),filter:pe(2),some:pe(3),every:pe(4),find:pe(5),findIndex:pe(6),filterOut:pe(7)},ve=ge.find,me="find",ye=!0,be=ie(me);me in[]&&Array(1)[me](function(){ye=!1}),Ot({target:"Array",proto:!0,forced:ye||!be},{find:function(t){return ve(this,t,1<arguments.length?arguments[1]:void 0)}}),Qt(me);he("Array","find");var we,xe,Ae,Se=function(a){return function(t,e){var n,i,r=String(g(t)),o=ct(e),s=r.length;return o<0||s<=o?a?"":void 0:(n=r.charCodeAt(o))<55296||56319<n||o+1===s||(i=r.charCodeAt(o+1))<56320||57343<i?a?r.charAt(o):n:a?r.slice(o,o+2):i-56320+(n-55296<<10)+65536}},Pe={codeAt:Se(!1),charAt:Se(!0)},Ee=!a(function(){function t(){}return t.prototype.constructor=null,Object.getPrototypeOf(new t)!==t.prototype}),ke=W("IE_PROTO"),Te=Object.prototype,Ce=Ee?Object.getPrototypeOf:function(t){return t=le(t),A(t,ke)?t[ke]:"function"==typeof t.constructor&&t instanceof t.constructor?t.constructor.prototype:t instanceof Object?Te:null},Le=zt("iterator"),Me=!1;[].keys&&("next"in(Ae=[].keys())?(xe=Ce(Ce(Ae)))!==Object.prototype&&(we=xe):Me=!0),(null==we||a(function(){var t={};return we[Le].call(t)!==t}))&&(we={}),A(we,Le)||R(we,Le,function(){return this});var Ne={IteratorPrototype:we,BUGGY_SAFARI_ITERATORS:Me},_e=_.f,Re=zt("toStringTag"),Oe=function(t,e,n){t&&!A(t=n?t:t.prototype,Re)&&_e(t,Re,{configurable:!0,value:e})},Ve={},Fe=Ne.IteratorPrototype,Be=function(){return this},De=Object.setPrototypeOf||("__proto__"in{}?function(){var n,i=!1,t={};try{(n=Object.getOwnPropertyDescriptor(Object.prototype,"__proto__").set).call(t,[]),i=t instanceof Array}catch(t){}return function(t,e){return M(t),function(t){if(!m(t)&&null!==t)throw TypeError("Can't set "+String(t)+" as a prototype")}(e),i?n.call(t,e):t.__proto__=e,t}}():void 0),Ie=Ne.IteratorPrototype,ze=Ne.BUGGY_SAFARI_ITERATORS,je=zt("iterator"),Ge="values",Ue="entries",qe=function(){return this},He=Pe.charAt,Ye="String Iterator",$e=rt.set,Xe=rt.getterFor(Ye);!function(t,e,n,i,r,o,s){var a,h,l;h=i,l=e+" Iterator",(a=n).prototype=Zt(Fe,{next:w(1,h)}),Oe(a,l,!1),Ve[l]=Be;var u,c,d,f=function(t){if(t===r&&y)return y;if(!ze&&t in v)return v[t];switch(t){case"keys":case Ge:case Ue:return function(){return new n(this,t)}}return function(){return new n(this)}},p=e+" Iterator",g=!1,v=t.prototype,m=v[je]||v["@@iterator"]||r&&v[r],y=!ze&&m||f(r),b="Array"==e&&v.entries||m;if(b&&(u=Ce(b.call(new t)),Ie!==Object.prototype&&u.next&&(Ce(u)!==Ie&&(De?De(u,Ie):"function"!=typeof u[je]&&R(u,je,qe)),Oe(u,p,!0))),r==Ge&&m&&m.name!==Ge&&(g=!0,y=function(){return m.call(this)}),v[je]!==y&&R(v,je,y),Ve[e]=y,r)if(c={values:f(Ge),keys:o?y:f("keys"),entries:f(Ue)},s)for(d in c)!ze&&!g&&d in v||ot(v,d,c[d]);else Ot({target:e,proto:!0,forced:ze||g},c)}(String,"String",function(t){$e(this,{type:Ye,string:String(t),index:0})},function(){var t,e=Xe(this),n=e.string,i=e.index;return i>=n.length?{value:void 0,done:!0}:(t=He(n,i),e.index+=t.length,{value:t,done:!1})});var We=function(e,t,n,i){try{return i?t(M(n)[0],n[1]):t(n)}catch(t){throw function(t){var e=t.return;if(void 0!==e)M(e.call(t)).value}(e),t}},Ze=zt("iterator"),Je=Array.prototype,Ke=function(t,e,n){var i=y(e);i in t?_.f(t,i,w(0,n)):t[i]=n},Qe={};Qe[zt("toStringTag")]="z";var tn="[object z]"===String(Qe),en=zt("toStringTag"),nn="Arguments"==f(function(){return arguments}()),rn=tn?f:function(t){var e,n,i;return void 0===t?"Undefined":null===t?"Null":"string"==typeof(n=function(t,e){try{return t[e]}catch(t){}}(e=Object(t),en))?n:nn?f(e):"Object"==(i=f(e))&&"function"==typeof e.callee?"Arguments":i},on=zt("iterator"),sn=zt("iterator"),an=!1;try{var hn=0,ln={next:function(){return{done:!!hn++}},return:function(){an=!0}};ln[sn]=function(){return this},Array.from(ln,function(){throw 2})}catch(t){}var un=!function(t,e){if(!e&&!an)return!1;var n=!1;try{var i={};i[sn]=function(){return{next:function(){return{done:n=!0}}}},t(i)}catch(t){}return n}(function(t){Array.from(t)});Ot({target:"Array",stat:!0,forced:un},{from:function(t){var e,n,i,r,o,s,a,h=le(t),l="function"==typeof this?this:Array,u=arguments.length,c=1<u?arguments[1]:void 0,d=void 0!==c,f=function(t){if(null!=t)return t[on]||t["@@iterator"]||Ve[rn(t)]}(h),p=0;if(d&&(c=se(c,2<u?arguments[2]:void 0,2)),null!=f&&(l!=Array||void 0===(a=f)||Ve.Array!==a&&Je[Ze]!==a))for(o=(r=f.call(h)).next,n=new l;!(i=o.call(r)).done;p++)s=d?We(r,c,[i.value,p],!0):i.value,Ke(n,p,s);else for(n=new l(e=ft(h.length));p<e;p++)s=d?c(h[p],p):h[p],Ke(n,p,s);return n.length=p,n}});st.Array.from;var cn=ge.findIndex,dn="findIndex",fn=!0,pn=ie(dn);dn in[]&&Array(1)[dn](function(){fn=!1}),Ot({target:"Array",proto:!0,forced:fn||!pn},{findIndex:function(t){return cn(this,t,1<arguments.length?arguments[1]:void 0)}}),Qt(dn);he("Array","findIndex"),i(function(t,e){!function(){var t=e,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";function h(t){this.message=t}(h.prototype=new Error).name="InvalidCharacterError",t.btoa||(t.btoa=function(t){for(var e,n,i=String(t),r=0,o=a,s="";i.charAt(0|r)||(o="=",r%1);s+=o.charAt(63&e>>8-r%1*8)){if(255<(n=i.charCodeAt(r+=.75)))throw new h("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");e=e<<8|n}return s}),t.atob||(t.atob=function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new h("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,i,r=0,o=0,s="";i=e.charAt(o++);~i&&(n=r%4?64*n+i:i,r++%4)?s+=String.fromCharCode(255&n>>(-2*r&6)):0)i=a.indexOf(i);return s})}()});Ot({target:"Number",stat:!0},{isNaN:function(t){return t!=t}});st.Number.isNaN;var gn=u.isFinite,vn=Number.isFinite||function(t){return"number"==typeof t&&gn(t)};Ot({target:"Number",stat:!0},{isFinite:vn});st.Number.isFinite;var mn=zt("match"),yn=function(t){if(m(e=t)&&(void 0!==(n=e[mn])?n:"RegExp"==f(e)))throw TypeError("The method doesn't accept regular expressions");var e,n;return t},bn=zt("match"),wn=function(e){var n=/./;try{"/./"[e](n)}catch(t){try{return n[bn]=!1,"/./"[e](n)}catch(t){}}return!1};Ot({target:"String",proto:!0,forced:!wn("includes")},{includes:function(t){return!!~String(g(this)).indexOf(yn(t),1<arguments.length?arguments[1]:void 0)}});he("String","includes");var xn,An=L.f,Sn="".startsWith,Pn=Math.min,En=wn("startsWith"),kn=!(En||(!(xn=An(String.prototype,"startsWith"))||xn.writable));Ot({target:"String",proto:!0,forced:!kn&&!En},{startsWith:function(t){var e=String(g(this));yn(t);var n=ft(Pn(1<arguments.length?arguments[1]:void 0,e.length)),i=String(t);return Sn?Sn.call(e,i,n):e.slice(n,n+i.length)===i}});he("String","startsWith");!function(){function i(t,e){return this.slice(t,e)}function r(t,e){arguments.length<2&&(e=0);for(var n=0,i=t.length;n<i;++n,++e)this[e]=255&t[n]}function t(t){var e;if("number"==typeof t){e=new Array(t);for(var n=0;n<t;++n)e[n]=0}else e=t.slice(0);return e.subarray=i,(e.buffer=e).byteLength=e.length,e.set=r,"object"==typeof t&&t.buffer&&(e.buffer=t.buffer),e}"undefined"==typeof Uint8Array&&"undefined"!=typeof window&&(window.Uint8Array=t,window.Uint32Array=t,window.Int32Array=t)}();var Tn=Math.round,Cn=Math.floor,Ln=Math.PI,Mn=function(t){return t%360+(t<0?360:0)},Nn=function(t,e){return e*Tn(t/e)},_n=function(t){return 180*t/Ln%360},Rn=function(t,e){return(t=(e=e||!1)?t:t%360)*Ln/180},On=function(t,e){if(void 0===e)e=void 0===t?1:t,t=0;else if(e<t){var n=t;t=e,e=n}return Cn(Math.random()*(e-t+1)+t)},Vn=Math.cos,Fn=Math.sin,Bn=Math.atan2,Dn=function(t,e){var n=Rn(t.y),i=Rn(e.y),r=t.x,o=e.x,s=Rn(o-r),a=Fn(s)*Vn(i),h=Vn(n)*Fn(i)-Fn(n)*Vn(i)*Vn(s),l=_n(Bn(a,h))-22.5;return l<0&&(l+=360),["NE","E","SE","S","SW","W","NW","N"][l=parseInt(l/45)]},In=function(t,e){var n=t.x,i=t.y;return(n-=e.x)*n+(i-=e.y)*i},zn=function(t,e){return Math.sqrt(In(t,e))},jn=Math.abs,Gn=Math.cos,Un=Math.sin,qn=Math.sqrt,Hn=Math.min,Yn=Math.max,$n=Math.atan2,Xn=Math.round,Wn=Math.pow,Zn=Math.PI,Jn=function(t,e){if(!(this instanceof Jn))return new Jn(t,e);if("string"==typeof t){var n=t.split(-1===t.indexOf("@")?" ":"@");t=parseFloat(n[0]),e=parseFloat(n[1])}else Object(t)===t&&(e=t.y,t=t.x);this.x=void 0===t?0:t,this.y=void 0===e?0:e};Jn.fromPolar=function(t,e,n){n=new Jn(n);var i=jn(t*Gn(e)),r=jn(t*Un(e)),o=Mn(_n(e));return o<90?r=-r:o<180?(i=-i,r=-r):o<270&&(i=-i),new Jn(n.x+i,n.y+r)},Jn.random=function(t,e,n,i){return new Jn(On(t,e),On(n,i))},Jn.prototype={chooseClosest:function(t){var e=t.length;if(1===e)return new Jn(t[0]);for(var n=null,i=1/0,r=0;r<e;r++){var o=new Jn(t[r]),s=this.squaredDistance(o);s<i&&(n=o,i=s)}return n},adhereToRect:function(t){return t.containsPoint(this)||(this.x=Hn(Yn(this.x,t.x),t.x+t.width),this.y=Hn(Yn(this.y,t.y),t.y+t.height)),this},angleBetween:function(t,e){var n=this.equals(t)||this.equals(e)?NaN:this.theta(e)-this.theta(t);return n<0&&(n+=360),n},bearing:function(t){return Dn(this,t)},changeInAngle:function(t,e,n){return this.clone().offset(-t,-e).theta(n)-this.theta(n)},clone:function(){return new Jn(this)},cross:function(t,e){return t&&e?(e.x-this.x)*(t.y-this.y)-(e.y-this.y)*(t.x-this.x):NaN},difference:function(t,e){return Object(t)===t&&(e=t.y,t=t.x),new Jn(this.x-(t||0),this.y-(e||0))},distance:function(t){return zn(this,t)},dot:function(t){return t?this.x*t.x+this.y*t.y:NaN},equals:function(t){return!!t&&this.x===t.x&&this.y===t.y},lerp:function(t,e){var n=this.x,i=this.y;return new Jn((1-e)*n+e*t.x,(1-e)*i+e*t.y)},magnitude:function(){return qn(this.x*this.x+this.y*this.y)||.01},manhattanDistance:function(t){return jn(t.x-this.x)+jn(t.y-this.y)},move:function(t,e){var n=Rn(new Jn(t).theta(this));return this.offset(Gn(n)*e,-Un(n)*e)},normalize:function(t){var e=(t||1)/this.magnitude();return this.scale(e,e)},offset:function(t,e){return Object(t)===t&&(e=t.y,t=t.x),this.x+=t||0,this.y+=e||0,this},reflection:function(t){return new Jn(t).move(this,this.distance(t))},rotate:function(t,e){if(0===e)return this;t=t||new Jn(0,0),e=Rn(Mn(-e));var n=Gn(e),i=Un(e),r=n*(this.x-t.x)-i*(this.y-t.y)+t.x,o=i*(this.x-t.x)+n*(this.y-t.y)+t.y;return this.x=r,this.y=o,this},round:function(t){var e=1;if(t)switch(t){case 1:e=10;break;case 2:e=100;break;case 3:e=1e3;break;default:e=Wn(10,t)}return this.x=Xn(this.x*e)/e,this.y=Xn(this.y*e)/e,this},scale:function(t,e,n){return n=n&&new Jn(n)||new Jn(0,0),this.x=n.x+t*(this.x-n.x),this.y=n.y+e*(this.y-n.y),this},snapToGrid:function(t,e){return this.x=Nn(this.x,t),this.y=Nn(this.y,e||t),this},squaredDistance:function(t){return In(this,t)},theta:function(t){var e=-((t=new Jn(t)).y-this.y),n=t.x-this.x,i=$n(e,n);return i<0&&(i=2*Zn+i),180*i/Zn},toJSON:function(){return{x:this.x,y:this.y}},toPolar:function(t){t=t&&new Jn(t)||new Jn(0,0);var e=this.x,n=this.y;return this.x=qn((e-t.x)*(e-t.x)+(n-t.y)*(n-t.y)),this.y=Rn(t.theta(new Jn(e,n))),this},toString:function(){return this.x+"@"+this.y},serialize:function(){return this.x+","+this.y},update:function(t,e){return Object(t)===t&&(e=t.y,t=t.x),this.x=t||0,this.y=e||0,this},vectorAngle:function(t){return new Jn(0,0).angleBetween(this,t)}},Jn.prototype.translate=Jn.prototype.offset;var Kn=Jn,Qn=Math.max,ti=Math.min,ei=function(t,e){return this instanceof ei?t instanceof ei?new ei(t.start,t.end):(this.start=new Jn(t),void(this.end=new Jn(e))):new ei(t,e)};ei.prototype={angle:function(){var t=new Jn(this.start.x+1,this.start.y);return this.start.angleBetween(this.end,t)},bbox:function(){var t=ti(this.start.x,this.end.x),e=ti(this.start.y,this.end.y),n=Qn(this.start.x,this.end.x),i=Qn(this.start.y,this.end.y);return new gi(t,e,n-t,i-e)},bearing:function(){return Dn(this.start,this.end)},clone:function(){return new ei(this.start,this.end)},closestPoint:function(t){return this.pointAt(this.closestPointNormalizedLength(t))},closestPointLength:function(t){return this.closestPointNormalizedLength(t)*this.length()},closestPointNormalizedLength:function(t){var e=this.vector().dot(new ei(this.start,t).vector()),n=ti(1,Qn(0,e/this.squaredLength()));return n!=n?0:n},closestPointTangent:function(t){return this.tangentAt(this.closestPointNormalizedLength(t))},containsPoint:function(t){var e=this.start,n=this.end;if(0!==e.cross(t,n))return!1;var i=this.length();return!(new ei(e,t).length()>i)&&!(new ei(t,n).length()>i)},divideAt:function(t){var e=this.pointAt(t);return[new ei(this.start,e),new ei(e,this.end)]},divideAtLength:function(t){var e=this.pointAtLength(t);return[new ei(this.start,e),new ei(e,this.end)]},equals:function(t){return!!t&&this.start.x===t.start.x&&this.start.y===t.start.y&&this.end.x===t.end.x&&this.end.y===t.end.y},intersect:function(t,e){if(t&&t.intersectionWithLine){var n=t.intersectionWithLine(this,e);return n&&t instanceof ei&&(n=n[0]),n}return null},intersectionWithLine:function(t){var e=new Jn(this.end.x-this.start.x,this.end.y-this.start.y),n=new Jn(t.end.x-t.start.x,t.end.y-t.start.y),i=e.x*n.y-e.y*n.x,r=new Jn(t.start.x-this.start.x,t.start.y-this.start.y),o=r.x*n.y-r.y*n.x,s=r.x*e.y-r.y*e.x;if(0===i||o*i<0||s*i<0)return null;if(0<i){if(i<o||i<s)return null}else if(o<i||s<i)return null;return[new Jn(this.start.x+o*e.x/i,this.start.y+o*e.y/i)]},isDifferentiable:function(){return!this.start.equals(this.end)},length:function(){return zn(this.start,this.end)},midpoint:function(){return new Jn((this.start.x+this.end.x)/2,(this.start.y+this.end.y)/2)},parallel:function(t){var e=this.clone();if(!this.isDifferentiable())return e;var n=e.start,i=e.end,r=n.clone().rotate(i,270),o=i.clone().rotate(n,90);return n.move(o,t),i.move(r,t),e},pointAt:function(t){var e=this.start,n=this.end;return t<=0?e.clone():1<=t?n.clone():e.lerp(n,t)},pointAtLength:function(t){var e=this.start,n=this.end,i=!0;t<0&&(i=!1,t=-t);var r=this.length();return r<=t?i?n.clone():e.clone():this.pointAt((i?t:r-t)/r)},pointOffset:function(t){t=new Jn(t);var e=this.start,n=this.end;return((n.x-e.x)*(t.y-e.y)-(n.y-e.y)*(t.x-e.x))/this.length()},rotate:function(t,e){return this.start.rotate(t,e),this.end.rotate(t,e),this},round:function(t){return this.start.round(t),this.end.round(t),this},scale:function(t,e,n){return this.start.scale(t,e,n),this.end.scale(t,e,n),this},setLength:function(t){var e=this.length();if(!e)return this;var n=t/e;return this.scale(n,n,this.start)},squaredLength:function(){return In(this.start,this.end)},tangentAt:function(t){if(!this.isDifferentiable())return null;var e=this.start,n=this.end,i=this.pointAt(t),r=new ei(e,n);return r.translate(i.x-e.x,i.y-e.y),r},tangentAtLength:function(t){if(!this.isDifferentiable())return null;var e=this.start,n=this.end,i=this.pointAtLength(t),r=new ei(e,n);return r.translate(i.x-e.x,i.y-e.y),r},toString:function(){return this.start.toString()+" "+this.end.toString()},serialize:function(){return this.start.serialize()+" "+this.end.serialize()},translate:function(t,e){return this.start.translate(t,e),this.end.translate(t,e),this},vector:function(){return new Jn(this.end.x-this.start.x,this.end.y-this.start.y)}},ei.prototype.intersection=ei.prototype.intersect;var ni=ei,ii=Math.sqrt,ri=Math.round,oi=Math.pow,si=function(t,e,n){return this instanceof si?t instanceof si?new si(new Jn(t.x,t.y),t.a,t.b):(t=new Jn(t),this.x=t.x,this.y=t.y,this.a=e,void(this.b=n)):new si(t,e,n)};si.fromRect=function(t){return t=new gi(t),new si(t.center(),t.width/2,t.height/2)},si.prototype={bbox:function(){return new gi(this.x-this.a,this.y-this.b,2*this.a,2*this.b)},center:function(){return new Jn(this.x,this.y)},clone:function(){return new si(this)},containsPoint:function(t){return this.normalizedDistance(t)<=1},equals:function(t){return!!t&&t.x===this.x&&t.y===this.y&&t.a===this.a&&t.b===this.b},inflate:function(t,e){return void 0===t&&(t=0),void 0===e&&(e=t),this.a+=2*t,this.b+=2*e,this},intersectionWithLine:function(t){var e=[],n=t.start,i=t.end,r=this.a,o=this.b,s=t.vector(),a=n.difference(new Jn(this)),h=new Jn(s.x/(r*r),s.y/(o*o)),l=new Jn(a.x/(r*r),a.y/(o*o)),u=s.dot(h),c=s.dot(l),d=c*c-u*(a.dot(l)-1);if(d<0)return null;if(0<d){var f=ii(d),p=(-c-f)/u,g=(-c+f)/u;if((p<0||1<p)&&(g<0||1<g))return null;0<=p&&p<=1&&e.push(n.lerp(i,p)),0<=g&&g<=1&&e.push(n.lerp(i,g))}else{var v=-c/u;if(!(0<=v&&v<=1))return null;e.push(n.lerp(i,v))}return e},intersectionWithLineFromCenterToPoint:function(t,e){t=new Jn(t),e&&t.rotate(new Jn(this.x,this.y),e);var n,i=t.x-this.x,r=t.y-this.y;if(0===i)return n=this.bbox().pointNearestToPoint(t),e?n.rotate(new Jn(this.x,this.y),-e):n;var o=r/i,s=o*o,a=this.a*this.a,h=this.b*this.b,l=ii(1/(1/a+s/h)),u=o*(l=i<0?-l:l);return n=new Jn(this.x+l,this.y+u),e?n.rotate(new Jn(this.x,this.y),-e):n},normalizedDistance:function(t){var e=t.x,n=t.y,i=this.a,r=this.b,o=this.x,s=this.y;return(e-o)*(e-o)/(i*i)+(n-s)*(n-s)/(r*r)},round:function(t){var e=1;if(t)switch(t){case 1:e=10;break;case 2:e=100;break;case 3:e=1e3;break;default:e=oi(10,t)}return this.x=ri(this.x*e)/e,this.y=ri(this.y*e)/e,this.a=ri(this.a*e)/e,this.b=ri(this.b*e)/e,this},tangentTheta:function(t){var e,n,i=t.x,r=t.y,o=this.a,s=this.b,a=this.bbox().center(),h=a.x,l=a.y,u=i>a.x+o/2,c=i<a.x-o/2;return u||c?n=o*o/(i-h)-o*o*(r-l)*((e=i>a.x?r-30:r+30)-l)/(s*s*(i-h))+h:e=s*s/(r-l)-s*s*(i-h)*((n=r>a.y?i+30:i-30)-h)/(o*o*(r-l))+l,new Jn(n,e).theta(t)},toString:function(){return new Jn(this.x,this.y).toString()+" "+this.a+" "+this.b}};var ai=si,hi=Math.abs,li=Math.cos,ui=Math.sin,ci=Math.min,di=Math.max,fi=Math.round,pi=Math.pow,gi=function(t,e,n,i){if(!(this instanceof gi))return new gi(t,e,n,i);Object(t)===t&&(e=t.y,n=t.width,i=t.height,t=t.x),this.x=void 0===t?0:t,this.y=void 0===e?0:e,this.width=void 0===n?0:n,this.height=void 0===i?0:i};gi.fromEllipse=function(t){return t=new si(t),new gi(t.x-t.a,t.y-t.b,2*t.a,2*t.b)},gi.fromPointUnion=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];if(0===t.length)return null;var n,i,r,o,s=new Jn;n=i=1/0,r=o=-1/0;for(var a=0;a<t.length;a++){s.update(t[a]);var h=s.x,l=s.y;h<n&&(n=h),r<h&&(r=h),l<i&&(i=l),o<l&&(o=l)}return new gi(n,i,r-n,o-i)},gi.fromRectUnion=function(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];if(0===t.length)return null;var n,i,r,o,s=new gi;n=i=1/0,r=o=-1/0;for(var a=0;a<t.length;a++){s.update(t[a]);var h=s.x,l=s.y,u=h+s.width,c=l+s.height;h<n&&(n=h),r<u&&(r=u),l<i&&(i=l),o<c&&(o=c)}return new gi(n,i,r-n,o-i)},gi.prototype={bbox:function(t){if(!t)return this.clone();var e=Rn(t),n=hi(ui(e)),i=hi(li(e)),r=this.width*i+this.height*n,o=this.width*n+this.height*i;return new gi(this.x+(this.width-r)/2,this.y+(this.height-o)/2,r,o)},bottomLeft:function(){return new Jn(this.x,this.y+this.height)},bottomLine:function(){return new ei(this.bottomLeft(),this.bottomRight())},bottomMiddle:function(){return new Jn(this.x+this.width/2,this.y+this.height)},center:function(){return new Jn(this.x+this.width/2,this.y+this.height/2)},clone:function(){return new gi(this)},containsPoint:function(t){return(t=new Jn(t)).x>=this.x&&t.x<=this.x+this.width&&t.y>=this.y&&t.y<=this.y+this.height},containsRect:function(t){var e=new gi(this).normalize(),n=new gi(t).normalize(),i=e.width,r=e.height,o=n.width,s=n.height;if(!(i&&r&&o&&s))return!1;var a=e.x,h=e.y,l=n.x,u=n.y;return o+=l,i+=a,s+=u,r+=h,a<=l&&o<=i&&h<=u&&s<=r},corner:function(){return new Jn(this.x+this.width,this.y+this.height)},equals:function(t){var e=new gi(this).normalize(),n=new gi(t).normalize();return e.x===n.x&&e.y===n.y&&e.width===n.width&&e.height===n.height},inflate:function(t,e){return void 0===t&&(t=0),void 0===e&&(e=t),this.x-=t,this.y-=e,this.width+=2*t,this.height+=2*e,this},intersect:function(t){var e=this.origin(),n=this.corner(),i=t.origin(),r=t.corner();if(r.x<=e.x||r.y<=e.y||i.x>=n.x||i.y>=n.y)return null;var o=di(e.x,i.x),s=di(e.y,i.y);return new gi(o,s,ci(n.x,r.x)-o,ci(n.y,r.y)-s)},intersectionWithLine:function(t){var e,n,i=[this.topLine(),this.rightLine(),this.bottomLine(),this.leftLine()],r=[],o=[],s=i.length;for(n=0;n<s;n++)null!==(e=t.intersect(i[n]))&&o.indexOf(e.toString())<0&&(r.push(e),o.push(e.toString()));return 0<r.length?r:null},intersectionWithLineFromCenterToPoint:function(t,e){t=new Jn(t);var n,i=new Jn(this.x+this.width/2,this.y+this.height/2);e&&t.rotate(i,e);for(var r=[this.topLine(),this.rightLine(),this.bottomLine(),this.leftLine()],o=new ei(i,t),s=r.length-1;0<=s;--s){var a=r[s].intersection(o);if(null!==a){n=a;break}}return n&&e&&n.rotate(i,-e),n},leftLine:function(){return new ei(this.topLeft(),this.bottomLeft())},leftMiddle:function(){return new Jn(this.x,this.y+this.height/2)},maxRectScaleToFit:function(t,e){var n,i,r,o,s,a,h,l;t=new gi(t),e||(e=t.center());var u=e.x,c=e.y;n=i=r=o=s=a=h=l=1/0;var d=t.topLeft();d.x<u&&(n=(this.x-u)/(d.x-u)),d.y<c&&(s=(this.y-c)/(d.y-c));var f=t.bottomRight();f.x>u&&(i=(this.x+this.width-u)/(f.x-u)),f.y>c&&(a=(this.y+this.height-c)/(f.y-c));var p=t.topRight();p.x>u&&(r=(this.x+this.width-u)/(p.x-u)),p.y<c&&(h=(this.y-c)/(p.y-c));var g=t.bottomLeft();return g.x<u&&(o=(this.x-u)/(g.x-u)),g.y>c&&(l=(this.y+this.height-c)/(g.y-c)),{sx:ci(n,i,r,o),sy:ci(s,a,h,l)}},maxRectUniformScaleToFit:function(t,e){var n=this.maxRectScaleToFit(t,e);return ci(n.sx,n.sy)},moveAndExpand:function(t){return this.x+=t.x||0,this.y+=t.y||0,this.width+=t.width||0,this.height+=t.height||0,this},normalize:function(){var t=this.x,e=this.y,n=this.width,i=this.height;return this.width<0&&(t=this.x+this.width,n=-this.width),this.height<0&&(e=this.y+this.height,i=-this.height),this.x=t,this.y=e,this.width=n,this.height=i,this},offset:function(t,e){return Jn.prototype.offset.call(this,t,e)},origin:function(){return new Jn(this.x,this.y)},pointNearestToPoint:function(t){if(t=new Jn(t),this.containsPoint(t))switch(this.sideNearestToPoint(t)){case"right":return new Jn(this.x+this.width,t.y);case"left":return new Jn(this.x,t.y);case"bottom":return new Jn(t.x,this.y+this.height);case"top":return new Jn(t.x,this.y)}return t.adhereToRect(this)},rightLine:function(){return new ei(this.topRight(),this.bottomRight())},rightMiddle:function(){return new Jn(this.x+this.width,this.y+this.height/2)},round:function(t){var e=1;if(t)switch(t){case 1:e=10;break;case 2:e=100;break;case 3:e=1e3;break;default:e=pi(10,t)}return this.x=fi(this.x*e)/e,this.y=fi(this.y*e)/e,this.width=fi(this.width*e)/e,this.height=fi(this.height*e)/e,this},scale:function(t,e,n){return n=this.origin().scale(t,e,n),this.x=n.x,this.y=n.y,this.width*=t,this.height*=e,this},sideNearestToPoint:function(t){var e=(t=new Jn(t)).x-this.x,n=this.x+this.width-t.x,i=t.y-this.y,r=e,o="left";return n<r&&(r=n,o="right"),i<r&&(r=i,o="top"),this.y+this.height-t.y<r&&(o="bottom"),o},snapToGrid:function(t,e){var n=this.origin().snapToGrid(t,e),i=this.corner().snapToGrid(t,e);return this.x=n.x,this.y=n.y,this.width=i.x-n.x,this.height=i.y-n.y,this},toJSON:function(){return{x:this.x,y:this.y,width:this.width,height:this.height}},topLine:function(){return new ei(this.topLeft(),this.topRight())},topMiddle:function(){return new Jn(this.x+this.width/2,this.y)},topRight:function(){return new Jn(this.x+this.width,this.y)},toString:function(){return this.origin().toString()+" "+this.corner().toString()},union:function(t){return gi.fromRectUnion(this,t)},update:function(t,e,n,i){return Object(t)===t&&(e=t.y,n=t.width,i=t.height,t=t.x),this.x=t||0,this.y=e||0,this.width=n||0,this.height=i||0,this}},gi.prototype.bottomRight=gi.prototype.corner,gi.prototype.topLeft=gi.prototype.origin,gi.prototype.translate=gi.prototype.offset;var vi=gi,mi=Math.abs,yi=function(t){return this instanceof yi?"string"==typeof t?new yi.parse(t):void(this.points=Array.isArray(t)?t.map(Jn):[]):new yi(t)};yi.parse=function(t){if(""===(t=t.trim()))return new yi;for(var e=[],n=t.split(/\s*,\s*|\s+/),i=n.length,r=0;r<i;r+=2)e.push({x:+n[r],y:+n[r+1]});return new yi(e)},yi.prototype={bbox:function(){var t=1/0,e=-1/0,n=1/0,i=-1/0,r=this.points,o=r.length;if(0===o)return null;for(var s=0;s<o;s++){var a=r[s],h=a.x,l=a.y;h<t&&(t=h),e<h&&(e=h),l<n&&(n=l),i<l&&(i=l)}return new gi(t,n,e-t,i-n)},clone:function(){var t=this.points,e=t.length;if(0===e)return new yi;for(var n=[],i=0;i<e;i++){var r=t[i].clone();n.push(r)}return new yi(n)},closestPoint:function(t){var e=this.closestPointLength(t);return this.pointAtLength(e)},closestPointLength:function(t){var e,n=this.points,i=n.length;if(0===i)return 0;if(1===i)return 0;for(var r=1/0,o=0,s=i-1,a=0;a<s;a++){var h=new ei(n[a],n[a+1]),l=h.length(),u=h.closestPointNormalizedLength(t),c=h.pointAt(u).squaredDistance(t);c<r&&(r=c,e=o+u*l),o+=l}return e},closestPointNormalizedLength:function(t){var e=this.closestPointLength(t);if(0===e)return 0;var n=this.length();return 0===n?0:e/n},closestPointTangent:function(t){var e=this.closestPointLength(t);return this.tangentAtLength(e)},containsPoint:function(t){var e=this.points,n=e.length;if(0===n)return!1;for(var i=t.x,r=t.y,o=n-1,s=0,a=0;s<n;s++){var h=e[o],l=e[s];if(t.equals(h))return!0;var u=new ei(h,l);if(u.containsPoint(t))return!0;if(r<=h.y&&r>l.y||r>h.y&&r<=l.y){var c=h.x-i>l.x-i?h.x-i:l.x-i;if(0<=c){var d=new Jn(i+c,r),f=new ei(t,d);u.intersect(f)&&a++}}o=s}return a%2==1},convexHull:function(){var t,e,n,i=this.points,r=i.length;if(0===r)return new yi;for(t=0;t<r;t++)void 0===n?n=i[t]:i[t].y<n.y?n=i[t]:i[t].y===n.y&&i[t].x>n.x&&(n=i[t]);var o=[];for(t=0;t<r;t++){var s=n.theta(i[t]);0===s&&(s=360);var a=[i[t],t,s];o.push(a)}if(o.sort(function(t,e){var n=t[2]-e[2];return 0===n&&(n=e[1]-t[1]),n}),2<o.length){var h=o[o.length-1];o.unshift(h)}for(var l,u,c,d,f,p,g,v={},m=[];0!==o.length;)if(u=(l=o.pop())[0],!v.hasOwnProperty(l[0]+"@@"+l[1]))for(var y=!1;!y;)if(m.length<2)m.push(l),y=!0;else{d=(c=m.pop())[0];var b=(p=(f=m.pop())[0]).cross(d,u);if(b<0)m.push(f),m.push(c),m.push(l),y=!0;else if(0===b){var w=d.angleBetween(p,u);mi(w-180)<1e-10?(v[c[0]+"@@"+c[1]]=d,m.push(f)):d.equals(u)||p.equals(d)?(v[c[0]+"@@"+c[1]]=d,m.push(f)):mi((w+1)%360-1)<1e-10&&(m.push(f),o.push(c))}else v[c[0]+"@@"+c[1]]=d,m.push(f)}2<m.length&&m.pop();var x=-1;for(e=m.length,t=0;t<e;t++){var A=m[t][1];(void 0===g||A<g)&&(g=A,x=t)}var S=[];if(0<x){var P=m.slice(x),E=m.slice(0,x);S=P.concat(E)}else S=m;var k=[];for(e=S.length,t=0;t<e;t++)k.push(S[t][0]);return new yi(k)},equals:function(t){if(!t)return!1;var e=this.points,n=t.points,i=e.length;if(n.length!==i)return!1;for(var r=0;r<i;r++){var o=e[r],s=t.points[r];if(!o.equals(s))return!1}return!0},intersectionWithLine:function(t){for(var e=new ei(t),n=[],i=this.points,r=0,o=i.length-1;r<o;r++){var s=i[r],a=i[r+1],h=new ei(s,a),l=e.intersectionWithLine(h);l&&n.push(l[0])}return 0<n.length?n:null},isDifferentiable:function(){var t=this.points,e=t.length;if(0===e)return!1;for(var n=e-1,i=0;i<n;i++){var r=t[i],o=t[i+1];if(new ei(r,o).isDifferentiable())return!0}return!1},length:function(){var t=this.points,e=t.length;if(0===e)return 0;for(var n=0,i=e-1,r=0;r<i;r++)n+=t[r].distance(t[r+1]);return n},pointAt:function(t){var e=this.points,n=e.length;if(0===n)return null;if(1===n)return e[0].clone();if(t<=0)return e[0].clone();if(1<=t)return e[n-1].clone();var i=this.length()*t;return this.pointAtLength(i)},pointAtLength:function(t){var e=this.points,n=e.length;if(0===n)return null;if(1===n)return e[0].clone();var i=!0;t<0&&(i=!1,t=-t);for(var r=0,o=n-1,s=0;s<o;s++){var a=i?s:o-1-s,h=e[a],l=e[a+1],u=new ei(h,l),c=h.distance(l);if(t<=r+c)return u.pointAtLength((i?1:-1)*(t-r));r+=c}return(i?e[n-1]:e[0]).clone()},round:function(t){for(var e=this.points,n=e.length,i=0;i<n;i++)e[i].round(t);return this},scale:function(t,e,n){for(var i=this.points,r=i.length,o=0;o<r;o++)i[o].scale(t,e,n);return this},simplify:function(t){void 0===t&&(t={});var e=this.points;if(e.length<3)return this;for(var n=t.threshold||0,i=0;e[i+2];){var r=i+1,o=i+2,s=e[i],a=e[r],h=e[o];new ei(s,h).closestPoint(a).distance(a)<=n?e.splice(r,1):i+=1}return this},tangentAt:function(t){var e=this.points.length;if(0===e)return null;if(1===e)return null;t<0&&(t=0),1<t&&(t=1);var n=this.length()*t;return this.tangentAtLength(n)},tangentAtLength:function(t){var e=this.points,n=e.length;if(0===n)return null;if(1===n)return null;var i,r=!0;t<0&&(r=!1,t=-t);for(var o=0,s=n-1,a=0;a<s;a++){var h=r?a:s-1-a,l=e[h],u=e[h+1],c=new ei(l,u),d=l.distance(u);if(c.isDifferentiable()){if(t<=o+d)return c.tangentAtLength((r?1:-1)*(t-o));i=c}o+=d}if(i){var f=r?1:0;return i.tangentAt(f)}return null},toString:function(){return this.points+""},translate:function(t,e){for(var n=this.points,i=n.length,r=0;r<i;r++)n[r].translate(t,e);return this},serialize:function(){var t=this.points,e=t.length;if(0===e)return"";for(var n="",i=0;i<e;i++){var r=t[i];n+=r.x+","+r.y+" "}return n.trim()}},Object.defineProperty(yi.prototype,"start",{configurable:!0,enumerable:!0,get:function(){return 0===this.points.length?null:this.points[0]}}),Object.defineProperty(yi.prototype,"end",{configurable:!0,enumerable:!0,get:function(){var t=this.points.length;return 0===t?null:this.points[t-1]}});var bi=Math.abs,wi=Math.sqrt,xi=Math.min,Ai=Math.max,Si=Math.pow,Pi=function(t,e,n,i){return this instanceof Pi?t instanceof Pi?new Pi(t.start,t.controlPoint1,t.controlPoint2,t.end):(this.start=new Jn(t),this.controlPoint1=new Jn(e),this.controlPoint2=new Jn(n),void(this.end=new Jn(i))):new Pi(t,e,n,i)};Pi.throughPoints=function(){function h(t){var e=t.length,n=[],i=[],r=2;n[0]=t[0]/r;for(var o=1;o<e;o++)i[o]=1/r,r=(o<e-1?4:3.5)-i[o],n[o]=(t[o]-n[o-1])/r;for(o=1;o<e;o++)n[e-o-1]-=i[e-o]*n[e-o];return n}return function(t){if(!t||Array.isArray(t)&&t.length<2)throw new Error("At least 2 points are required");for(var e=function(t){var e,n=[],i=[],r=t.length-1;if(1==r)return n[0]=new Jn((2*t[0].x+t[1].x)/3,(2*t[0].y+t[1].y)/3),i[0]=new Jn(2*n[0].x-t[0].x,2*n[0].y-t[0].y),[n,i];var o=[];for(e=1;e<r-1;e++)o[e]=4*t[e].x+2*t[e+1].x;o[0]=t[0].x+2*t[1].x,o[r-1]=(8*t[r-1].x+t[r].x)/2;var s=h(o);for(e=1;e<r-1;++e)o[e]=4*t[e].y+2*t[e+1].y;o[0]=t[0].y+2*t[1].y,o[r-1]=(8*t[r-1].y+t[r].y)/2;var a=h(o);for(e=0;e<r;e++)n.push(new Jn(s[e],a[e])),e<r-1?i.push(new Jn(2*t[e+1].x-s[e+1],2*t[e+1].y-a[e+1])):i.push(new Jn((t[r].x+s[r-1])/2,(t[r].y+a[r-1])/2));return[n,i]}(t),n=[],i=e[0].length,r=0;r<i;r++){var o=new Jn(e[0][r].x,e[0][r].y),s=new Jn(e[1][r].x,e[1][r].y);n.push(new Pi(t[r],o,s,t[r+1]))}return n}}(),Pi.prototype={bbox:function(){for(var t,e,n,i,r,o,s,a,h=this.start,l=this.controlPoint1,u=this.controlPoint2,c=this.end,d=h.x,f=h.y,p=l.x,g=l.y,v=u.x,m=u.y,y=c.x,b=c.y,w=new Array,x=new Array,A=[new Array,new Array],S=0;S<2;++S)if(n=0===S?(e=6*d-12*p+6*v,t=-3*d+9*p-9*v+3*y,3*p-3*d):(e=6*f-12*g+6*m,t=-3*f+9*g-9*m+3*b,3*g-3*f),bi(t)<1e-12){if(bi(e)<1e-12)continue;0<(i=-n/e)&&i<1&&x.push(i)}else a=wi(s=e*e-4*n*t),s<0||(0<(r=(-e+a)/(2*t))&&r<1&&x.push(r),0<(o=(-e-a)/(2*t))&&o<1&&x.push(o));for(var P,E,k,T=x.length,C=T;T--;)E=(P=1-(i=x[T]))*P*P*d+3*P*P*i*p+3*P*i*i*v+i*i*i*y,A[0][T]=E,k=P*P*P*f+3*P*P*i*g+3*P*i*i*m+i*i*i*b,A[1][T]=k,w[T]={X:E,Y:k};x[C]=0,x[C+1]=1,w[C]={X:d,Y:f},w[C+1]={X:y,Y:b},A[0][C]=d,A[1][C]=f,A[0][C+1]=y,A[1][C+1]=b,x.length=C+2,A[0].length=C+2,A[1].length=C+2,w.length=C+2;var L=xi.apply(null,A[0]),M=xi.apply(null,A[1]),N=Ai.apply(null,A[0]),_=Ai.apply(null,A[1]);return new gi(L,M,N-L,_-M)},clone:function(){return new Pi(this.start,this.controlPoint1,this.controlPoint2,this.end)},closestPoint:function(t,e){return this.pointAtT(this.closestPointT(t,e))},closestPointLength:function(t,e){var n=void 0===(e=e||{}).precision?this.PRECISION:e.precision,i={precision:n,subdivisions:void 0===e.subdivisions?this.getSubdivisions({precision:n}):e.subdivisions};return this.lengthAtT(this.closestPointT(t,i),i)},closestPointNormalizedLength:function(t,e){var n=void 0===(e=e||{}).precision?this.PRECISION:e.precision,i={precision:n,subdivisions:void 0===e.subdivisions?this.getSubdivisions({precision:n}):e.subdivisions},r=this.closestPointLength(t,i);if(!r)return 0;var o=this.length(i);return 0===o?0:r/o},closestPointT:function(t,e){for(var n,i,r,o,s,a,h,l=void 0===(e=e||{}).precision?this.PRECISION:e.precision,u=void 0===e.subdivisions?this.getSubdivisions({precision:l}):e.subdivisions,c=u.length,d=c?1/c:0,f=0;f<c;f++){var p=u[f],g=p.start.distance(t),v=p.end.distance(t),m=g+v;(!h||m<h)&&(i=f*d,r=(f+1)*d,o=g,s=v,a=(n=p).start.distance(p.end),h=m)}for(var y=Si(10,-l);;){var b=o?bi(o-s)/o:0,w=s?bi(o-s)/s:0;if(b<y||w<y||(!o||o<a*y||(!s||s<a*y)))return o<=s?i:r;var x=n.divide(.5);d/=2;var A=x[0].start.distance(t),S=x[0].end.distance(t),P=A+S,E=x[1].start.distance(t),k=x[1].end.distance(t);s=P<=E+k?(n=x[0],r-=d,o=A,S):(n=x[1],i+=d,o=E,k)}},closestPointTangent:function(t,e){return this.tangentAtT(this.closestPointT(t,e))},containsPoint:function(t,e){return this.toPolyline(e).containsPoint(t)},divideAt:function(t,e){if(t<=0)return this.divideAtT(0);if(1<=t)return this.divideAtT(1);var n=this.tAt(t,e);return this.divideAtT(n)},divideAtLength:function(t,e){var n=this.tAtLength(t,e);return this.divideAtT(n)},divideAtT:function(t){var e=this.start,n=this.controlPoint1,i=this.controlPoint2,r=this.end;if(t<=0)return[new Pi(e,e,e,e),new Pi(e,n,i,r)];if(1<=t)return[new Pi(e,n,i,r),new Pi(r,r,r,r)];var o=this.getSkeletonPoints(t),s=o.startControlPoint1,a=o.startControlPoint2,h=o.divider,l=o.dividerControlPoint1,u=o.dividerControlPoint2;return[new Pi(e,s,a,h),new Pi(h,l,u,r)]},endpointDistance:function(){return this.start.distance(this.end)},equals:function(t){return!!t&&this.start.x===t.start.x&&this.start.y===t.start.y&&this.controlPoint1.x===t.controlPoint1.x&&this.controlPoint1.y===t.controlPoint1.y&&this.controlPoint2.x===t.controlPoint2.x&&this.controlPoint2.y===t.controlPoint2.y&&this.end.x===t.end.x&&this.end.y===t.end.y},getSkeletonPoints:function(t){var e=this.start,n=this.controlPoint1,i=this.controlPoint2,r=this.end;if(t<=0)return{startControlPoint1:e.clone(),startControlPoint2:e.clone(),divider:e.clone(),dividerControlPoint1:n.clone(),dividerControlPoint2:i.clone()};if(1<=t)return{startControlPoint1:n.clone(),startControlPoint2:i.clone(),divider:r.clone(),dividerControlPoint1:r.clone(),dividerControlPoint2:r.clone()};var o=new ei(e,n).pointAt(t),s=new ei(n,i).pointAt(t),a=new ei(i,r).pointAt(t),h=new ei(o,s).pointAt(t),l=new ei(s,a).pointAt(t);return{startControlPoint1:o,startControlPoint2:h,divider:new ei(h,l).pointAt(t),dividerControlPoint1:l,dividerControlPoint2:a}},getSubdivisions:function(t){var e=void 0===(t=t||{}).precision?this.PRECISION:t.precision,n=[new Pi(this.start,this.controlPoint1,this.controlPoint2,this.end)];if(0===e)return n;for(var i=this.endpointDistance(),r=Si(10,-e),o=0;;){o+=1;for(var s=[],a=n.length,h=0;h<a;h++){var l=n[h].divide(.5);s.push(l[0],l[1])}for(var u=0,c=s.length,d=0;d<c;d++){u+=s[d].endpointDistance()}if(1<o&&(0!==u?(u-i)/u:0)<r)return s;n=s,i=u}},isDifferentiable:function(){var t=this.start,e=this.controlPoint1,n=this.controlPoint2,i=this.end;return!(t.equals(e)&&e.equals(n)&&n.equals(i))},length:function(t){for(var e=void 0===(t=t||{}).precision?this.PRECISION:t.precision,n=void 0===t.subdivisions?this.getSubdivisions({precision:e}):t.subdivisions,i=0,r=n.length,o=0;o<r;o++){i+=n[o].endpointDistance()}return i},lengthAtT:function(t,e){if(t<=0)return 0;var n=void 0===(e=e||{}).precision?this.PRECISION:e.precision;return this.divide(t)[0].length({precision:n})},pointAt:function(t,e){if(t<=0)return this.start.clone();if(1<=t)return this.end.clone();var n=this.tAt(t,e);return this.pointAtT(n)},pointAtLength:function(t,e){var n=this.tAtLength(t,e);return this.pointAtT(n)},pointAtT:function(t){return t<=0?this.start.clone():1<=t?this.end.clone():this.getSkeletonPoints(t).divider},PRECISION:3,round:function(t){return this.start.round(t),this.controlPoint1.round(t),this.controlPoint2.round(t),this.end.round(t),this},scale:function(t,e,n){return this.start.scale(t,e,n),this.controlPoint1.scale(t,e,n),this.controlPoint2.scale(t,e,n),this.end.scale(t,e,n),this},tangentAt:function(t,e){if(!this.isDifferentiable())return null;t<0?t=0:1<t&&(t=1);var n=this.tAt(t,e);return this.tangentAtT(n)},tangentAtLength:function(t,e){if(!this.isDifferentiable())return null;var n=this.tAtLength(t,e);return this.tangentAtT(n)},tangentAtT:function(t){if(!this.isDifferentiable())return null;t<0?t=0:1<t&&(t=1);var e=this.getSkeletonPoints(t),n=e.startControlPoint2,i=e.dividerControlPoint1,r=e.divider,o=new ei(n,i);return o.translate(r.x-n.x,r.y-n.y),o},tAt:function(t,e){if(t<=0)return 0;if(1<=t)return 1;var n=void 0===(e=e||{}).precision?this.PRECISION:e.precision,i={precision:n,subdivisions:void 0===e.subdivisions?this.getSubdivisions({precision:n}):e.subdivisions},r=this.length(i)*t;return this.tAtLength(r,i)},tAtLength:function(t,e){var n=!0;t<0&&(n=!1,t=-t);for(var i,r,o,s,a,h=void 0===(e=e||{}).precision?this.PRECISION:e.precision,l=void 0===e.subdivisions?this.getSubdivisions({precision:h}):e.subdivisions,u={precision:h,subdivisions:l},c=0,d=l.length,f=1/d,p=0;p<d;p++){var g=n?p:d-1-p,v=l[p],m=v.endpointDistance();if(t<=c+m){i=v,r=g*f,o=(g+1)*f,s=n?t-c:m+c-t,a=n?m+c-t:t-c;break}c+=m}if(!i)return n?1:0;for(var y=this.length(u),b=Si(10,-h);;){var w,x;if((0!==y?s/y:0)<b)return r;if((0!==y?a/y:0)<b)return o;var A=i.divide(.5);f/=2;var S=A[0].endpointDistance(),P=A[1].endpointDistance();x=s<=S?(i=A[0],o-=f,S-(w=s)):(i=A[1],r+=f,P-(w=s-S)),s=w,a=x}},toPoints:function(t){for(var e=void 0===(t=t||{}).precision?this.PRECISION:t.precision,n=void 0===t.subdivisions?this.getSubdivisions({precision:e}):t.subdivisions,i=[n[0].start.clone()],r=n.length,o=0;o<r;o++){var s=n[o];i.push(s.end.clone())}return i},toPolyline:function(t){return new yi(this.toPoints(t))},toString:function(){return this.start+" "+this.controlPoint1+" "+this.controlPoint2+" "+this.end},translate:function(t,e){return this.start.translate(t,e),this.controlPoint1.translate(t,e),this.controlPoint2.translate(t,e),this.end.translate(t,e),this}},Pi.prototype.divide=Pi.prototype.divideAtT;var Ei=function(t){if(!(this instanceof Ei))return new Ei(t);if("string"==typeof t)return new Ei.parse(t);var e,n;if(this.segments=[],t)if(Array.isArray(t)&&0!==t.length)if(n=(t=t.reduce(function(t,e){return t.concat(e)},[])).length,t[0].isSegment)for(e=0;e<n;e++){var i=t[e];this.appendSegment(i)}else{var r=null;for(e=0;e<n;e++){var o=t[e];if(!(o instanceof ei||o instanceof Pi))throw new Error("Cannot construct a path segment from the provided object.");0===e&&this.appendSegment(Ei.createSegment("M",o.start)),r&&!r.end.equals(o.start)&&this.appendSegment(Ei.createSegment("M",o.start)),o instanceof ei?this.appendSegment(Ei.createSegment("L",o.end)):o instanceof Pi&&this.appendSegment(Ei.createSegment("C",o.controlPoint1,o.controlPoint2,o.end)),r=o}}else if(t.isSegment)this.appendSegment(t);else if(t instanceof ei)this.appendSegment(Ei.createSegment("M",t.start)),this.appendSegment(Ei.createSegment("L",t.end));else if(t instanceof Pi)this.appendSegment(Ei.createSegment("M",t.start)),this.appendSegment(Ei.createSegment("C",t.controlPoint1,t.controlPoint2,t.end));else{if(!(t instanceof yi))throw new Error("Cannot construct a path from the provided object.");if(!t.points||0===t.points.length)return;for(n=t.points.length,e=0;e<n;e++){var s=t.points[e];0===e?this.appendSegment(Ei.createSegment("M",s)):this.appendSegment(Ei.createSegment("L",s))}}else;};function ki(t,e){return e.unshift(null),new(Function.prototype.bind.apply(t,e))}function Ti(t){var e,n,i=arguments,r=[];for(n=arguments.length,e=1;e<n;e++)r.push(i[e]);if(!t)throw new Error("Missing a parent object.");var o=Object.create(t);for(n=r.length,e=0;e<n;e++){var s,a,h=r[e];for(a in h)h.hasOwnProperty(a)&&(delete o[a],s=Object.getOwnPropertyDescriptor(h,a),Object.defineProperty(o,a,s))}return o}Ei.parse=function(t){if(!t)return new Ei;for(var e=new Ei,n=t.match(/(?:[a-zA-Z] *)(?:(?:-?\d+(?:\.\d+)?(?:e[-+]?\d+)? *,? *)|(?:-?\.\d+ *,? *))+|(?:[a-zA-Z] *)(?! |\d|-|\.)/g),i=n.length,r=0;r<i;r++){var o=n[r].match(/(?:[a-zA-Z])|(?:(?:-?\d+(?:\.\d+)?(?:e[-+]?\d+)?))|(?:(?:-?\.\d+))/g),s=Ei.createSegment.apply(this,o);e.appendSegment(s)}return e},Ei.createSegment=function(t){var e=arguments;if(!t)throw new Error("Type must be provided.");var n=Ei.segmentTypes[t];if(!n)throw new Error(t+" is not a recognized path segment type.");for(var i=[],r=arguments.length,o=1;o<r;o++)i.push(e[o]);return ki(n,i)},Ei.prototype={appendSegment:function(t){var e,n=this.segments,i=n.length,r=0!==i?n[i-1]:null;if(Array.isArray(t)){if(!(t=t.reduce(function(t,e){return t.concat(e)},[]))[0].isSegment)throw new Error("Segments required.");for(var o=t.length,s=0;s<o;s++){var a=t[s];e=this.prepareSegment(a,r,null),n.push(e),r=e}}else{if(!t||!t.isSegment)throw new Error("Segment required.");e=this.prepareSegment(t,r,null),n.push(e)}},bbox:function(){var t,e=this.segments,n=e.length;if(0===n)return null;for(var i=0;i<n;i++){var r=e[i];if(r.isVisible){var o=r.bbox();t=t?t.union(o):o}}if(t)return t;var s=e[n-1];return new gi(s.end.x,s.end.y,0,0)},clone:function(){for(var t=this.segments,e=t.length,n=new Ei,i=0;i<e;i++){var r=t[i].clone();n.appendSegment(r)}