UNPKG

jointjs

Version:

JavaScript diagramming library

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