@playcanvas/pcui-graph
Version:
A PCUI plugin for creating node-based graphs
1 lines • 592 kB
JavaScript
import{Observer as t}from"@playcanvas/observer";import{Menu as e,Container as n,Label as i,VectorInput as r,NumericInput as o,BooleanInput as s,TextInput as a,Element as l}from"@playcanvas/pcui";const u={ADD_NODE:"EVENT_ADD_NODE",DELETE_NODE:"EVENT_DELETE_NODE",SELECT_NODE:"EVENT_SELECT_NODE",UPDATE_NODE_POSITION:"EVENT_UPDATE_NODE_POSITION",UPDATE_NODE_ATTRIBUTE:"EVENT_UPDATE_NODE_ATTRIBUTE",ADD_EDGE:"EVENT_ADD_EDGE",DELETE_EDGE:"EVENT_DELETE_EDGE",SELECT_EDGE:"EVENT_SELECT_EDGE",DESELECT_ITEM:"EVENT_DESELECT_ITEM",UPDATE_TRANSLATE:"EVENT_UPDATE_TRANSLATE",UPDATE_SCALE:"EVENT_UPDATE_SCALE"},c={readOnly:!1,passiveUIEvents:!1,incrementNodeNames:!1,restrictTranslate:!1,edgeHoverEffect:!0,includeFonts:!0,useGlobalPCUI:!1,adjustVertices:!1,defaultStyles:{initialScale:1,initialPosition:{x:0,y:0},background:{color:"#20292B",gridSize:10},node:{fill:"#2c393c",fillSecondary:"#364346",stroke:"#293538",strokeSelected:"#F60",strokeHover:"rgba(255, 102, 0, 0.32)",textColor:"#FFFFFF",textColorSecondary:"#b1b8ba",includeIcon:!0,icon:"",iconColor:"#F60",baseHeight:28,baseWidth:226,textAlignMiddle:!1,lineHeight:12},edge:{stroke:"rgb(3, 121, 238)",strokeSelected:"#F60",strokeWidth:2,strokeWidthSelected:2,targetMarker:!0,connectionStyle:"default"}}};var h="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function d(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var f,p={exports:{}};function g(){return f||(f=1,function(t){var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:void 0!==h?h:"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},r=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")(),o=function(t){try{return!!t()}catch(t){return!0}},s=!o(function(){return 7!=Object.defineProperty({},1,{get:function(){return 7}})[1]}),a={}.propertyIsEnumerable,l=Object.getOwnPropertyDescriptor,u={f:l&&!a.call({1:2},1)?function(t){var e=l(this,t);return!!e&&e.enumerable}:a},c=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,g=o(function(){return!Object("z").propertyIsEnumerable(0)})?function(t){return"String"==f(t)?p.call(t,""):Object(t)}:Object,m=function(t){if(null==t)throw TypeError("Can't call method on "+t);return t},v=function(t){return g(m(t))},y=function(t){return"object"==typeof t?null!==t:"function"==typeof t},b=function(t,e){if(!y(t))return t;var n,i;if(e&&"function"==typeof(n=t.toString)&&!y(i=n.call(t)))return i;if("function"==typeof(n=t.valueOf)&&!y(i=n.call(t)))return i;if(!e&&"function"==typeof(n=t.toString)&&!y(i=n.call(t)))return i;throw TypeError("Can't convert object to primitive value")},w={}.hasOwnProperty,x=function(t,e){return w.call(t,e)},_=r.document,E=y(_)&&y(_.createElement),A=function(t){return E?_.createElement(t):{}},T=!s&&!o(function(){return 7!=Object.defineProperty(A("div"),"a",{get:function(){return 7}}).a}),P=Object.getOwnPropertyDescriptor,S={f:s?P:function(t,e){if(t=v(t),e=b(e,!0),T)try{return P(t,e)}catch(t){}if(x(t,e))return c(!u.f.call(t,e),t[e])}},C=function(t){if(!y(t))throw TypeError(String(t)+" is not an object");return t},L=Object.defineProperty,k={f:s?L:function(t,e,n){if(C(t),e=b(e,!0),C(n),T)try{return L(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}},N=s?function(t,e,n){return k.f(t,e,c(1,n))}:function(t,e,n){return t[e]=n,t},M=function(t,e){try{N(r,t,e)}catch(n){r[t]=e}return e},O="__core-js_shared__",I=r[O]||M(O,{}),V=Function.toString;"function"!=typeof I.inspectSource&&(I.inspectSource=function(t){return V.call(t)});var D,R,B,F=I.inspectSource,j=r.WeakMap,z="function"==typeof j&&/native code/.test(F(j)),G=n(function(t){(t.exports=function(t,e){return I[t]||(I[t]=void 0!==e?e:{})})("versions",[]).push({version:"3.8.3",mode:"global",copyright:"© 2021 Denis Pushkarev (zloirock.ru)"})}),U=0,$=Math.random(),H=function(t){return"Symbol("+String(void 0===t?"":t)+")_"+(++U+$).toString(36)},q=G("keys"),W=function(t){return q[t]||(q[t]=H(t))},Y={},X=r.WeakMap,Z=function(t){return B(t)?R(t):D(t,{})},J=function(t){return function(e){var n;if(!y(e)||(n=R(e)).type!==t)throw TypeError("Incompatible receiver, "+t+" required");return n}};if(z){var K=I.state||(I.state=new X),Q=K.get,tt=K.has,et=K.set;D=function(t,e){return e.facade=t,et.call(K,t,e),e},R=function(t){return Q.call(K,t)||{}},B=function(t){return tt.call(K,t)}}else{var nt=W("state");Y[nt]=!0,D=function(t,e){return e.facade=t,N(t,nt,e),e},R=function(t){return x(t,nt)?t[nt]:{}},B=function(t){return x(t,nt)}}var it,rt={set:D,get:R,has:B,enforce:Z,getterFor:J},ot=n(function(t){var e=rt.get,n=rt.enforce,i=String(String).split("String");(t.exports=function(t,e,o,s){var a,l=!!s&&!!s.unsafe,u=!!s&&!!s.enumerable,c=!!s&&!!s.noTargetGet;"function"==typeof o&&("string"!=typeof e||x(o,"name")||N(o,"name",e),(a=n(o)).source||(a.source=i.join("string"==typeof e?e:""))),t!==r?(l?!c&&t[e]&&(u=!0):delete t[e],u?t[e]=o:N(t,e,o)):u?t[e]=o:M(e,o)})(Function.prototype,"toString",function(){return"function"==typeof this&&e(this).source||F(this)})}),st=r,at=function(t){return"function"==typeof t?t:void 0},lt=function(t,e){return arguments.length<2?at(st[t])||at(r[t]):st[t]&&st[t][e]||r[t]&&r[t][e]},ut=Math.ceil,ct=Math.floor,ht=function(t){return isNaN(t=+t)?0:(t>0?ct:ut)(t)},dt=Math.min,ft=function(t){return t>0?dt(ht(t),9007199254740991):0},pt=Math.max,gt=Math.min,mt=function(t,e){var n=ht(t);return n<0?pt(n+e,0):gt(n,e)},vt=function(t){return function(e,n,i){var r,o=v(e),s=ft(o.length),a=mt(i,s);if(t&&n!=n){for(;s>a;)if((r=o[a++])!=r)return!0}else for(;s>a;a++)if((t||a in o)&&o[a]===n)return t||a||0;return!t&&-1}},yt={includes:vt(!0),indexOf:vt(!1)},bt=yt.indexOf,wt=function(t,e){var n,i=v(t),r=0,o=[];for(n in i)!x(Y,n)&&x(i,n)&&o.push(n);for(;e.length>r;)x(i,n=e[r++])&&(~bt(o,n)||o.push(n));return o},xt=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],_t=xt.concat("length","prototype"),Et={f:Object.getOwnPropertyNames||function(t){return wt(t,_t)}},At={f:Object.getOwnPropertySymbols},Tt=lt("Reflect","ownKeys")||function(t){var e=Et.f(C(t)),n=At.f;return n?e.concat(n(t)):e},Pt=function(t,e){for(var n=Tt(e),i=k.f,r=S.f,o=0;o<n.length;o++){var s=n[o];x(t,s)||i(t,s,r(e,s))}},St=/#|\.prototype\./,Ct=function(t,e){var n=kt[Lt(t)];return n==Mt||n!=Nt&&("function"==typeof e?o(e):!!e)},Lt=Ct.normalize=function(t){return String(t).replace(St,".").toLowerCase()},kt=Ct.data={},Nt=Ct.NATIVE="N",Mt=Ct.POLYFILL="P",Ot=Ct,It=S.f,Vt=function(t,e){var n,i,o,s,a,l=t.target,u=t.global,c=t.stat;if(n=u?r:c?r[l]||M(l,{}):(r[l]||{}).prototype)for(i in e){if(s=e[i],o=t.noTargetGet?(a=It(n,i))&&a.value:n[i],!Ot(u?i:l+(c?".":"#")+i,t.forced)&&void 0!==o){if(typeof s==typeof o)continue;Pt(s,o)}(t.sham||o&&o.sham)&&N(s,"sham",!0),ot(n,i,s,t)}},Dt=!!Object.getOwnPropertySymbols&&!o(function(){return!String(Symbol())}),Rt=Dt&&!Symbol.sham&&"symbol"==typeof Symbol.iterator,Bt=G("wks"),Ft=r.Symbol,jt=Rt?Ft:Ft&&Ft.withoutSetter||H,zt=function(t){return x(Bt,t)||(Dt&&x(Ft,t)?Bt[t]=Ft[t]:Bt[t]=jt("Symbol."+t)),Bt[t]},Gt=Object.keys||function(t){return wt(t,xt)},Ut=s?Object.defineProperties:function(t,e){C(t);for(var n,i=Gt(e),r=i.length,o=0;r>o;)k.f(t,n=i[o++],e[n]);return t},$t=lt("document","documentElement"),Ht=">",qt="<",Wt="prototype",Yt="script",Xt=W("IE_PROTO"),Zt=function(){},Jt=function(t){return qt+Yt+Ht+t+qt+"/"+Yt+Ht},Kt=function(t){t.write(Jt("")),t.close();var e=t.parentWindow.Object;return t=null,e},Qt=function(){var t,e=A("iframe"),n="java"+Yt+":";return e.style.display="none",$t.appendChild(e),e.src=String(n),(t=e.contentWindow.document).open(),t.write(Jt("document.F=Object")),t.close(),t.F},te=function(){try{it=document.domain&&new ActiveXObject("htmlfile")}catch(t){}te=it?Kt(it):Qt();for(var t=xt.length;t--;)delete te[Wt][xt[t]];return te()};Y[Xt]=!0;var ee=Object.create||function(t,e){var n;return null!==t?(Zt[Wt]=C(t),n=new Zt,Zt[Wt]=null,n[Xt]=t):n=te(),void 0===e?n:Ut(n,e)},ne=zt("unscopables"),ie=Array.prototype;null==ie[ne]&&k.f(ie,ne,{configurable:!0,value:ee(null)});var re=function(t){ie[ne][t]=!0},oe=Object.defineProperty,se={},ae=function(t){throw t},le=function(t,e){if(x(se,t))return se[t];e||(e={});var n=[][t],i=!!x(e,"ACCESSORS")&&e.ACCESSORS,r=x(e,0)?e[0]:ae,a=x(e,1)?e[1]:void 0;return se[t]=!!n&&!o(function(){if(i&&!s)return!0;var t={length:-1};i?oe(t,1,{enumerable:!0,get:ae}):t[1]=1,n.call(t,r,a)})},ue=yt.includes,ce=le("indexOf",{ACCESSORS:!0,1:0});Vt({target:"Array",proto:!0,forced:!ce},{includes:function(t){return ue(this,t,arguments.length>1?arguments[1]:void 0)}}),re("includes");var he=function(t){if("function"!=typeof t)throw TypeError(String(t)+" is not a function");return t},de=function(t,e,n){if(he(t),void 0===e)return t;switch(n){case 0:return function(){return t.call(e)};case 1:return function(n){return t.call(e,n)};case 2:return function(n,i){return t.call(e,n,i)};case 3:return function(n,i,r){return t.call(e,n,i,r)}}return function(){return t.apply(e,arguments)}},fe=Function.call,pe=function(t,e,n){return de(fe,r[t].prototype[e],n)};pe("Array","includes");var ge=function(t){return Object(m(t))},me=Array.isArray||function(t){return"Array"==f(t)},ve=zt("species"),ye=function(t,e){var n;return me(t)&&("function"!=typeof(n=t.constructor)||n!==Array&&!me(n.prototype)?y(n)&&null===(n=n[ve])&&(n=void 0):n=void 0),new(void 0===n?Array:n)(0===e?0:e)},be=[].push,we=function(t){var e=1==t,n=2==t,i=3==t,r=4==t,o=6==t,s=7==t,a=5==t||o;return function(l,u,c,h){for(var d,f,p=ge(l),m=g(p),v=de(u,c,3),y=ft(m.length),b=0,w=h||ye,x=e?w(l,y):n||s?w(l,0):void 0;y>b;b++)if((a||b in m)&&(f=v(d=m[b],b,p),t))if(e)x[b]=f;else if(f)switch(t){case 3:return!0;case 5:return d;case 6:return b;case 2:be.call(x,d)}else switch(t){case 4:return!1;case 7:be.call(x,d)}return o?-1:i||r?r:x}},xe={find:we(5),findIndex:we(6)},_e=xe.find,Ee="find",Ae=!0,Te=le(Ee);Ee in[]&&Array(1)[Ee](function(){Ae=!1}),Vt({target:"Array",proto:!0,forced:Ae||!Te},{find:function(t){return _e(this,t,arguments.length>1?arguments[1]:void 0)}}),re(Ee),pe("Array","find");var Pe,Se,Ce,Le,ke={charAt:(Le=!0,function(t,e){var n,i,r=String(m(t)),o=ht(e),s=r.length;return o<0||o>=s?Le?"":void 0:(n=r.charCodeAt(o))<55296||n>56319||o+1===s||(i=r.charCodeAt(o+1))<56320||i>57343?Le?r.charAt(o):n:Le?r.slice(o,o+2):i-56320+(n-55296<<10)+65536})},Ne=!o(function(){function t(){}return t.prototype.constructor=null,Object.getPrototypeOf(new t)!==t.prototype}),Me=W("IE_PROTO"),Oe=Object.prototype,Ie=Ne?Object.getPrototypeOf:function(t){return t=ge(t),x(t,Me)?t[Me]:"function"==typeof t.constructor&&t instanceof t.constructor?t.constructor.prototype:t instanceof Object?Oe:null},Ve=zt("iterator"),De=!1,Re=function(){return this};[].keys&&("next"in(Ce=[].keys())?(Se=Ie(Ie(Ce)))!==Object.prototype&&(Pe=Se):De=!0),(null==Pe||o(function(){var t={};return Pe[Ve].call(t)!==t}))&&(Pe={}),x(Pe,Ve)||N(Pe,Ve,Re);var Be={IteratorPrototype:Pe,BUGGY_SAFARI_ITERATORS:De},Fe=k.f,je=zt("toStringTag"),ze=function(t,e,n){t&&!x(t=n?t:t.prototype,je)&&Fe(t,je,{configurable:!0,value:e})},Ge={},Ue=Be.IteratorPrototype,$e=function(){return this},He=function(t,e,n){var i=e+" Iterator";return t.prototype=ee(Ue,{next:c(1,n)}),ze(t,i,!1),Ge[i]=$e,t},qe=function(t){if(!y(t)&&null!==t)throw TypeError("Can't set "+String(t)+" as a prototype");return t},We=Object.setPrototypeOf||("__proto__"in{}?function(){var t,e=!1,n={};try{(t=Object.getOwnPropertyDescriptor(Object.prototype,"__proto__").set).call(n,[]),e=n instanceof Array}catch(t){}return function(n,i){return C(n),qe(i),e?t.call(n,i):n.__proto__=i,n}}():void 0),Ye=Be.IteratorPrototype,Xe=Be.BUGGY_SAFARI_ITERATORS,Ze=zt("iterator"),Je="keys",Ke="values",Qe="entries",tn=function(){return this},en=function(t,e,n,i,r,o,s){He(n,e,i);var a,l,u=function(t){if(f)return f;if(!Xe&&t in h)return h[t];switch(t){case Je:case Ke:case Qe:return function(){return new n(this,t)}}return function(){return new n(this)}},c=e+" Iterator",h=t.prototype,d=h[Ze]||h["@@iterator"]||r,f=!Xe&&d||u(r);return d&&(a=Ie(d.call(new t)),Ye!==Object.prototype&&a.next&&(Ie(a)!==Ye&&(We?We(a,Ye):"function"!=typeof a[Ze]&&N(a,Ze,tn)),ze(a,c,!0))),h[Ze]!==f&&N(h,Ze,f),Ge[e]=f,l},nn=ke.charAt,rn="String Iterator",on=rt.set,sn=rt.getterFor(rn);en(String,"String",function(t){on(this,{type:rn,string:String(t),index:0})},function(){var t,e=sn(this),n=e.string,i=e.index;return i>=n.length?{value:void 0,done:!0}:(t=nn(n,i),e.index+=t.length,{value:t,done:!1})});var an=function(t){var e=t.return;if(void 0!==e)return C(e.call(t)).value},ln=function(t,e,n,i){try{return i?e(C(n)[0],n[1]):e(n)}catch(e){throw an(t),e}},un=zt("iterator"),cn=Array.prototype,hn=function(t){return void 0!==t&&(Ge.Array===t||cn[un]===t)},dn=function(t,e,n){var i=b(e);i in t?k.f(t,i,c(0,n)):t[i]=n},fn=zt("toStringTag"),pn={};pn[fn]="z";var gn="[object z]"===String(pn),mn=zt("toStringTag"),vn="Arguments"==f(function(){return arguments}()),yn=function(t,e){try{return t[e]}catch(t){}},bn=gn?f:function(t){var e,n,i;return void 0===t?"Undefined":null===t?"Null":"string"==typeof(n=yn(e=Object(t),mn))?n:vn?f(e):"Object"==(i=f(e))&&"function"==typeof e.callee?"Arguments":i},wn=zt("iterator"),xn=function(t){if(null!=t)return t[wn]||t["@@iterator"]||Ge[bn(t)]},_n=function(t){var e,n,i,r,o,s,a=ge(t),l="function"==typeof this?this:Array,u=arguments.length,c=u>1?arguments[1]:void 0,h=void 0!==c,d=xn(a),f=0;if(h&&(c=de(c,u>2?arguments[2]:void 0,2)),null==d||l==Array&&hn(d))for(n=new l(e=ft(a.length));e>f;f++)s=h?c(a[f],f):a[f],dn(n,f,s);else for(o=(r=d.call(a)).next,n=new l;!(i=o.call(r)).done;f++)s=h?ln(r,c,[i.value,f],!0):i.value,dn(n,f,s);return n.length=f,n},En=zt("iterator"),An=!1;try{var Tn=0,Pn={next:function(){return{done:!!Tn++}},return:function(){An=!0}};Pn[En]=function(){return this},Array.from(Pn,function(){throw 2})}catch(t){}var Sn=!function(t){if(!An)return!1;var e=!1;try{var n={};n[En]=function(){return{next:function(){return{done:e=!0}}}},t(n)}catch(t){}return e}(function(t){Array.from(t)});Vt({target:"Array",stat:!0,forced:Sn},{from:_n}),st.Array.from;var Cn=xe.findIndex,Ln="findIndex",kn=!0,Nn=le(Ln);Ln in[]&&Array(1)[Ln](function(){kn=!1}),Vt({target:"Array",proto:!0,forced:kn||!Nn},{findIndex:function(t){return Cn(this,t,arguments.length>1?arguments[1]:void 0)}}),re(Ln),pe("Array","findIndex"),n(function(t,e){!function(){var t=e,n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";function i(t){this.message=t}i.prototype=new Error,i.prototype.name="InvalidCharacterError",t.btoa||(t.btoa=function(t){for(var e,r,o=String(t),s=0,a=n,l="";o.charAt(0|s)||(a="=",s%1);l+=a.charAt(63&e>>8-s%1*8)){if((r=o.charCodeAt(s+=3/4))>255)throw new i("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");e=e<<8|r}return l}),t.atob||(t.atob=function(t){var e=String(t).replace(/=+$/,"");if(e.length%4==1)throw new i("'atob' failed: The string to be decoded is not correctly encoded.");for(var r,o,s=0,a=0,l="";o=e.charAt(a++);~o&&(r=s%4?64*r+o:o,s++%4)?l+=String.fromCharCode(255&r>>(-2*s&6)):0)o=n.indexOf(o);return l})}()}),Vt({target:"Number",stat:!0},{isNaN:function(t){return t!=t}}),st.Number.isNaN;var Mn=r.isFinite,On=Number.isFinite||function(t){return"number"==typeof t&&Mn(t)};Vt({target:"Number",stat:!0},{isFinite:On}),st.Number.isFinite;var In=zt("match"),Vn=function(t){var e;return y(t)&&(void 0!==(e=t[In])?!!e:"RegExp"==f(t))},Dn=function(t){if(Vn(t))throw TypeError("The method doesn't accept regular expressions");return t},Rn=zt("match"),Bn=function(t){var e=/./;try{"/./"[t](e)}catch(n){try{return e[Rn]=!1,"/./"[t](e)}catch(t){}}return!1};Vt({target:"String",proto:!0,forced:!Bn("includes")},{includes:function(t){return!!~String(m(this)).indexOf(Dn(t),arguments.length>1?arguments[1]:void 0)}}),pe("String","includes");var Fn,jn=S.f,zn="".startsWith,Gn=Math.min,Un=Bn("startsWith"),$n=!(Un||(Fn=jn(String.prototype,"startsWith"),!Fn||Fn.writable));Vt({target:"String",proto:!0,forced:!$n&&!Un},{startsWith:function(t){var e=String(m(this));Dn(t);var n=ft(Gn(arguments.length>1?arguments[1]:void 0,e.length)),i=String(t);return zn?zn.call(e,i,n):e.slice(n,n+i.length)===i}}),pe("String","startsWith"),function(){function t(t,e){return this.slice(t,e)}function e(t,e){arguments.length<2&&(e=0);for(var n=0,i=t.length;n<i;++n,++e)this[e]=255&t[n]}function n(n){var i;if("number"==typeof n){i=new Array(n);for(var r=0;r<n;++r)i[r]=0}else i=n.slice(0);return i.subarray=t,i.buffer=i,i.byteLength=i.length,i.set=e,"object"==typeof n&&n.buffer&&(i.buffer=n.buffer),i}"undefined"==typeof Uint8Array&&"undefined"!=typeof window&&(window.Uint8Array=n,window.Uint32Array=n,window.Int32Array=n)}();const{round:Hn,floor:qn,PI:Wn}=Math,Yn={linear:function(t,e,n){var i=t[1]-t[0],r=e[1]-e[0];return(n-t[0])/i*r+e[0]||0}},Xn=function(t){return t%360+(t<0?360:0)},Zn=function(t,e){return e*Hn(t/e)},Jn=function(t){return 180*t/Wn%360},Kn=function(t,e){return(t=(e=e||!1)?t:t%360)*Wn/180},Qn=function(t,e){if(void 0===e)e=void 0===t?1:t,t=0;else if(e<t){const n=t;t=e,e=n}return qn(Math.random()*(e-t+1)+t)},{cos:ti,sin:ei,atan2:ni}=Math,ii=function(t,e){var n=Kn(t.y),i=Kn(e.y),r=t.x,o=e.x,s=Kn(o-r),a=ei(s)*ti(i),l=ti(n)*ei(i)-ei(n)*ti(i)*ti(s),u=Jn(ni(a,l))-22.5;return u<0&&(u+=360),["NE","E","SE","S","SW","W","NW","N"][u=parseInt(u/45)]},ri=function(t,e){var n=t.x,i=t.y;return(n-=e.x)*n+(i-=e.y)*i},oi=function(t,e){return Math.sqrt(ri(t,e))},si={Point:1,Line:2,Ellipse:3,Rect:4,Polyline:5,Polygon:6,Curve:7,Path:8},{abs:ai,cos:li,sin:ui,sqrt:ci,min:hi,max:di,atan2:fi,round:pi,pow:gi,PI:mi}=Math,vi=function(t,e){if(!(this instanceof vi))return new vi(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};vi.fromPolar=function(t,e,n){n=new vi(n);var i=ai(t*li(e)),r=ai(t*ui(e)),o=Xn(Jn(e));return o<90?r=-r:o<180?(i=-i,r=-r):o<270&&(i=-i),new vi(n.x+i,n.y+r)},vi.random=function(t,e,n,i){return new vi(Qn(t,e),Qn(n,i))},vi.prototype={type:si.Point,chooseClosest:function(t){var e=t.length;if(1===e)return new vi(t[0]);for(var n=null,i=1/0,r=0;r<e;r++){var o=new vi(t[r]),s=this.squaredDistance(o);s<i&&(n=o,i=s)}return n},adhereToRect:function(t){return t.containsPoint(this)||(this.x=hi(di(this.x,t.x),t.x+t.width),this.y=hi(di(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 ii(this,t)},changeInAngle:function(t,e,n){return this.clone().offset(-t,-e).theta(n)-this.theta(n)},clone:function(){return new vi(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 vi(this.x-(t||0),this.y-(e||0))},distance:function(t){return oi(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 vi((1-e)*n+e*t.x,(1-e)*i+e*t.y)},magnitude:function(){return ci(this.x*this.x+this.y*this.y)||.01},manhattanDistance:function(t){return ai(t.x-this.x)+ai(t.y-this.y)},move:function(t,e){var n=Kn(new vi(t).theta(this));return this.offset(li(n)*e,-ui(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 vi(t).move(this,this.distance(t))},rotate:function(t,e){if(0===e)return this;t=t||new vi(0,0),e=Kn(Xn(-e));var n=li(e),i=ui(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){let e=1;if(t)switch(t){case 1:e=10;break;case 2:e=100;break;case 3:e=1e3;break;default:e=gi(10,t)}return this.x=pi(this.x*e)/e,this.y=pi(this.y*e)/e,this},scale:function(t,e,n){return n=n&&new vi(n)||new vi(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=Zn(this.x,t),this.y=Zn(this.y,e||t),this},squaredDistance:function(t){return ri(this,t)},theta:function(t){var e=-((t=new vi(t)).y-this.y),n=t.x-this.x,i=fi(e,n);return i<0&&(i=2*mi+i),180*i/mi},toJSON:function(){return{x:this.x,y:this.y}},toPolar:function(t){t=t&&new vi(t)||new vi(0,0);var e=this.x,n=this.y;return this.x=ci((e-t.x)*(e-t.x)+(n-t.y)*(n-t.y)),this.y=Kn(t.theta(new vi(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 vi(0,0).angleBetween(this,t)}},vi.prototype.translate=vi.prototype.offset;const yi=vi,{max:bi,min:wi}=Math,xi=function(t,e){return this instanceof xi?t instanceof xi?new xi(t.start,t.end):(this.start=new vi(t),void(this.end=new vi(e))):new xi(t,e)};xi.prototype={type:si.Line,angle:function(){var t=new vi(this.start.x+1,this.start.y);return this.start.angleBetween(this.end,t)},bbox:function(){var t=wi(this.start.x,this.end.x),e=wi(this.start.y,this.end.y),n=bi(this.start.x,this.end.x),i=bi(this.start.y,this.end.y);return new Vi(t,e,n-t,i-e)},bearing:function(){return ii(this.start,this.end)},clone:function(){return new xi(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 xi(this.start,t).vector()),n=wi(1,bi(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 xi(e,t).length()>i||new xi(t,n).length()>i)},divideAt:function(t){var e=this.pointAt(t);return[new xi(this.start,e),new xi(e,this.end)]},divideAtLength:function(t){var e=this.pointAtLength(t);return[new xi(this.start,e),new xi(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 xi&&(n=n[0]),n}return null},intersectionWithLine:function(t){var e=new vi(this.end.x-this.start.x,this.end.y-this.start.y),n=new vi(t.end.x-t.start.x,t.end.y-t.start.y),i=e.x*n.y-e.y*n.x,r=new vi(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(i>0){if(o>i||s>i)return null}else if(o<i||s<i)return null;return[new vi(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 oi(this.start,this.end)},midpoint:function(){return new vi((this.start.x+this.end.x)/2,(this.start.y+this.end.y)/2)},parallel:function(t){const e=this.clone();if(!this.isDifferentiable())return e;const{start:n,end:i}=e,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():t>=1?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 t>=r?i?n.clone():e.clone():this.pointAt((i?t:r-t)/r)},pointOffset:function(t){t=new vi(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 ri(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 xi(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 xi(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 vi(this.end.x-this.start.x,this.end.y-this.start.y)}},xi.prototype.intersection=xi.prototype.intersect;const _i=xi,{sqrt:Ei,round:Ai,pow:Ti}=Math,Pi=function(t,e,n){return this instanceof Pi?t instanceof Pi?new Pi(new vi(t.x,t.y),t.a,t.b):(t=new vi(t),this.x=t.x,this.y=t.y,this.a=e,void(this.b=n)):new Pi(t,e,n)};Pi.fromRect=function(t){return t=new Vi(t),new Pi(t.center(),t.width/2,t.height/2)},Pi.prototype={type:si.Ellipse,bbox:function(){return new Vi(this.x-this.a,this.y-this.b,2*this.a,2*this.b)},center:function(){return new vi(this.x,this.y)},clone:function(){return new Pi(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 vi(this)),l=new vi(s.x/(r*r),s.y/(o*o)),u=new vi(a.x/(r*r),a.y/(o*o)),c=s.dot(l),h=s.dot(u),d=h*h-c*(a.dot(u)-1);if(d<0)return null;if(d>0){var f=Ei(d),p=(-h-f)/c,g=(-h+f)/c;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 m=-h/c;if(!(0<=m&&m<=1))return null;e.push(n.lerp(i,m))}return e},intersectionWithLineFromCenterToPoint:function(t,e){t=new vi(t),e&&t.rotate(new vi(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 vi(this.x,this.y),-e):n;var o=r/i,s=o*o,a=this.a*this.a,l=this.b*this.b,u=Ei(1/(1/a+s/l)),c=o*(u=i<0?-u:u);return n=new vi(this.x+u,this.y+c),e?n.rotate(new vi(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){let e=1;if(t)switch(t){case 1:e=10;break;case 2:e=100;break;case 3:e=1e3;break;default:e=Ti(10,t)}return this.x=Ai(this.x*e)/e,this.y=Ai(this.y*e)/e,this.a=Ai(this.a*e)/e,this.b=Ai(this.b*e)/e,this},tangentTheta:function(t){var e,n,i=30,r=t.x,o=t.y,s=this.a,a=this.b,l=this.bbox().center(),u=l.x,c=l.y,h=r>l.x+s/2,d=r<l.x-s/2;return h||d?n=s*s/(r-u)-s*s*(o-c)*((e=r>l.x?o-i:o+i)-c)/(a*a*(r-u))+u:e=a*a/(o-c)-a*a*(r-u)*((n=o>l.y?r+i:r-i)-u)/(s*s*(o-c))+c,new vi(n,e).theta(t)},toString:function(){return new vi(this.x,this.y).toString()+" "+this.a+" "+this.b}};const Si=Pi,{abs:Ci,cos:Li,sin:ki,min:Ni,max:Mi,round:Oi,pow:Ii}=Math,Vi=function(t,e,n,i){if(!(this instanceof Vi))return new Vi(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};Vi.fromEllipse=function(t){return t=new Pi(t),new Vi(t.x-t.a,t.y-t.b,2*t.a,2*t.b)},Vi.fromPointUnion=function(...t){if(0===t.length)return null;const e=new vi;let n,i,r,o;n=i=1/0,r=o=-1/0;for(let s=0;s<t.length;s++){e.update(t[s]);const a=e.x,l=e.y;a<n&&(n=a),a>r&&(r=a),l<i&&(i=l),l>o&&(o=l)}return new Vi(n,i,r-n,o-i)},Vi.fromRectUnion=function(...t){if(0===t.length)return null;const e=new Vi;let n,i,r,o;n=i=1/0,r=o=-1/0;for(let s=0;s<t.length;s++){e.update(t[s]);const a=e.x,l=e.y,u=a+e.width,c=l+e.height;a<n&&(n=a),u>r&&(r=u),l<i&&(i=l),c>o&&(o=c)}return new Vi(n,i,r-n,o-i)},Vi.prototype={type:si.Rect,bbox:function(t){return this.clone().rotateAroundCenter(t)},rotateAroundCenter:function(t){if(!t)return this;const{width:e,height:n}=this,i=Kn(t),r=Ci(ki(i)),o=Ci(Li(i)),s=e*o+n*r,a=e*r+n*o;return this.x+=(e-s)/2,this.y+=(n-a)/2,this.width=s,this.height=a,this},bottomLeft:function(){return new vi(this.x,this.y+this.height)},bottomLine:function(){return new xi(this.bottomLeft(),this.bottomRight())},bottomMiddle:function(){return new vi(this.x+this.width/2,this.y+this.height)},center:function(){return new vi(this.x+this.width/2,this.y+this.height/2)},clone:function(){return new Vi(this)},containsPoint:function(t,e){let n,i;return t&&"string"!=typeof t?({x:n=0,y:i=0}=t):({x:n,y:i}=new vi(t)),e&&e.strict?n>this.x&&n<this.x+this.width&&i>this.y&&i<this.y+this.height:n>=this.x&&n<=this.x+this.width&&i>=this.y&&i<=this.y+this.height},containsRect:function(t){var e=new Vi(this).normalize(),n=new Vi(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,l=e.y,u=n.x,c=n.y;return o+=u,i+=a,s+=c,r+=l,a<=u&&o<=i&&l<=c&&s<=r},corner:function(){return new vi(this.x+this.width,this.y+this.height)},equals:function(t){var e=new Vi(this).normalize(),n=new Vi(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=Mi(e.x,i.x),s=Mi(e.y,i.y);return new Vi(o,s,Ni(n.x,r.x)-o,Ni(n.y,r.y)-s)},intersectionWithLine:function(t){var e,n,i=this,r=[i.topLine(),i.rightLine(),i.bottomLine(),i.leftLine()],o=[],s=[],a=r.length;for(n=0;n<a;n++)null!==(e=t.intersect(r[n]))&&s.indexOf(e.toString())<0&&(o.push(e),s.push(e.toString()));return o.length>0?o:null},intersectionWithLineFromCenterToPoint:function(t,e){t=new vi(t);var n,i=new vi(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 xi(i,t),s=r.length-1;s>=0;--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 xi(this.topLeft(),this.bottomLeft())},leftMiddle:function(){return new vi(this.x,this.y+this.height/2)},maxRectScaleToFit:function(t,e){var n,i,r,o,s,a,l,u;t=new Vi(t),e||(e=t.center());var c=e.x,h=e.y;n=i=r=o=s=a=l=u=1/0;var d=t.topLeft();d.x<c&&(n=(this.x-c)/(d.x-c)),d.y<h&&(s=(this.y-h)/(d.y-h));var f=t.bottomRight();f.x>c&&(i=(this.x+this.width-c)/(f.x-c)),f.y>h&&(a=(this.y+this.height-h)/(f.y-h));var p=t.topRight();p.x>c&&(r=(this.x+this.width-c)/(p.x-c)),p.y<h&&(l=(this.y-h)/(p.y-h));var g=t.bottomLeft();return g.x<c&&(o=(this.x-c)/(g.x-c)),g.y>h&&(u=(this.y+this.height-h)/(g.y-h)),{sx:Ni(n,i,r,o),sy:Ni(s,a,l,u)}},maxRectUniformScaleToFit:function(t,e){var n=this.maxRectScaleToFit(t,e);return Ni(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},moveAroundPoint:function(t,e){const n=this.center().rotate(t,e);return this.x=n.x-this.width/2,this.y=n.y-this.height/2,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 vi.prototype.offset.call(this,t,e)},origin:function(){return new vi(this.x,this.y)},pointNearestToPoint:function(t){if(t=new vi(t),this.containsPoint(t))switch(this.sideNearestToPoint(t)){case"right":return new vi(this.x+this.width,t.y);case"left":return new vi(this.x,t.y);case"bottom":return new vi(t.x,this.y+this.height);case"top":return new vi(t.x,this.y)}return t.adhereToRect(this)},rightLine:function(){return new xi(this.topRight(),this.bottomRight())},rightMiddle:function(){return new vi(this.x+this.width,this.y+this.height/2)},round:function(t){let e=1;if(t)switch(t){case 1:e=10;break;case 2:e=100;break;case 3:e=1e3;break;default:e=Ii(10,t)}return this.x=Oi(this.x*e)/e,this.y=Oi(this.y*e)/e,this.width=Oi(this.width*e)/e,this.height=Oi(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 vi(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 xi(this.topLeft(),this.topRight())},topMiddle:function(){return new vi(this.x+this.width/2,this.y)},topRight:function(){return new vi(this.x+this.width,this.y)},toString:function(){return this.origin().toString()+" "+this.corner().toString()},union:function(t){return Vi.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}},Vi.prototype.bottomRight=Vi.prototype.corner,Vi.prototype.topLeft=Vi.prototype.origin,Vi.prototype.translate=Vi.prototype.offset;const Di=Vi;function Ri(t){const e=t.trim();if(""===e)return[];const n=[],i=e.split(/\b\s*,\s*|,\s*|\s+/),r=i.length;for(let t=0;t<r;t+=2)n.push({x:+i[t],y:+i[t+1]});return n}function Bi(t){const e=t.length;if(0===e)return[];const n=[];for(let i=0;i<e;i++){const e=t[i].clone();n.push(e)}return n}function Fi(t){const{abs:e}=Math;var n,i,r,o=t.length;if(0===o)return[];for(n=0;n<o;n++)(void 0===r||t[n].y<r.y||t[n].y===r.y&&t[n].x>r.x)&&(r=t[n]);var s=[];for(n=0;n<o;n++){var a=r.theta(t[n]);0===a&&(a=360);var l=[t[n],n,a];s.push(l)}if(s.sort(function(t,e){var n=t[2]-e[2];return 0===n&&(n=e[1]-t[1]),n}),s.length>2){var u=s[s.length-1];s.unshift(u)}for(var c,h,d,f,p,g,m,v={},y=[];0!==s.length;)if(h=(c=s.pop())[0],!v.hasOwnProperty(c[0]+"@@"+c[1]))for(var b=!1;!b;)if(y.length<2)y.push(c),b=!0;else{f=(d=y.pop())[0];var w=(g=(p=y.pop())[0]).cross(f,h);if(w<0)y.push(p),y.push(d),y.push(c),b=!0;else if(0===w){var x=1e-10,_=f.angleBetween(g,h);e(_-180)<x||f.equals(h)||g.equals(f)?(v[d[0]+"@@"+d[1]]=f,y.push(p)):e((_+1)%360-1)<x&&(y.push(p),s.push(d))}else v[d[0]+"@@"+d[1]]=f,y.push(p)}y.length>2&&y.pop();var E=-1;for(i=y.length,n=0;n<i;n++){var A=y[n][1];(void 0===m||A<m)&&(m=A,E=n)}var T=[];if(E>0){var P=y.slice(E),S=y.slice(0,E);T=P.concat(S)}else T=y;var C=[];for(i=T.length,n=0;n<i;n++)C.push(T[n][0]);return C}const ji=function(t){return this instanceof ji?"string"==typeof t?new ji.parse(t):void(this.points=Array.isArray(t)?t.map(vi):[]):new ji(t)};ji.parse=function(t){return new ji(Ri(t))},ji.fromRect=function(t){return new ji([t.topLeft(),t.topRight(),t.bottomRight(),t.bottomLeft(),t.topLeft()])},ji.prototype={type:si.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 s=0;s<o;s++){var a=r[s],l=a.x,u=a.y;l<t&&(t=l),l>e&&(e=l),u<n&&(n=u),u>i&&(i=u)}return new Vi(t,n,e-t,i-n)},clone:function(){return new ji(Bi(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,s=i-1,a=0;a<s;a++){var l=new xi(n[a],n[a+1]),u=l.length(),c=l.closestPointNormalizedLength(t),h=l.pointAt(c).squaredDistance(t);h<r&&(r=h,e=o+c*u),o+=u}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,l=new xi,u=new xi,c=new vi;s<n;s++){var h=e[o],d=e[s];if(t.equals(h))return!0;if(l.start=h,l.end=d,l.containsPoint(t))return!0;if(r<=h.y&&r>d.y||r>h.y&&r<=d.y){var f=h.x-i>d.x-i?h.x-i:d.x-i;f>=0&&(c.x=i+f,c.y=r,u.start=t,u.end=c,l.intersect(u)&&a++)}o=s}return a%2==1},close:function(){const{start:t,end:e,points:n}=this;return t&&e&&!t.equals(e)&&n.push(t.clone()),this},lengthPoints:function(){return this.points},convexHull:function(){return new ji(Fi(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],s=t.points[r];if(!o.equals(s))return!1}return!0},intersectionWithLine:function(t){for(var e=new xi(t),n=[],i=this.lengthPoints(),r=new xi,o=0,s=i.length-1;o<s;o++){r.start=i[o],r.end=i[o+1];var a=e.intersectionWithLine(r);a&&n.push(a[0])}return n.length>0?n:null},isDifferentiable:function(){var t=this.points,e=t.length;if(0===e)return!1;for(var n=new xi,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(t>=1)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,s=0;s<o;s++){var a=i?s:o-1-s,l=e[a],u=e[a+1],c=new xi(l,u),h=l.distance(u);if(t<=r+h)return c.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={}){const e=this.points;if(e.length<3)return this;const n=t.threshold||1e-10;let i=0;for(;e[i+2];){const t=i+1,r=i+2,o=e[i],s=e[t],a=e[r];new xi(o,a).closestPoint(s).distance(s)<=n?e.splice(t,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),t>1&&(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,s=n-1,a=0;a<s;a++){var l=r?a:s-1-a,u=e[l],c=e[l+1],h=new xi(u,c),d=u.distance(c);if(h.isDifferentiable()){if(t<=o+d)return h.tangentAtLength((r?1:-1)*(t-o));i=h}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(ji.prototype,"start",{configurable:!0,enumerable:!0,get:function(){return 0===this.points.length?null:this.points[0]}}),Object.defineProperty(ji.prototype,"end",{configurable:!0,enumerable:!0,get:function(){var t=this.points.length;return 0===t?null:this.points[t-1]}});const{abs:zi,sqrt:Gi,min:Ui,max:$i,pow:Hi}=Math,qi=function(t,e,n,i){return this instanceof qi?t instanceof qi?new qi(t.start,t.controlPoint1,t.controlPoint2,t.end):(this.start=new vi(t),this.controlPoint1=new vi(e),this.controlPoint2=new vi(n),void(this.end=new vi(i))):new qi(t,e,n,i)};function Wi(t){var e,n,i=[];for(n=arguments.length,e=1;e<n;e++)i.push(arguments[e]);if(!t)throw new Error("Missing a parent object.");var r=Object.create(t);for(n=i.length,e=0;e<n;e++){var o,s,a=i[e];for(s in a)a.hasOwnProperty(s)&&(delete r[s],o=Object.getOwnPropertyDescriptor(a,s),Object.defineProperty(r,s,o))}return r}qi.throughPoints=function(){function t(t){var n,i=[],r=[],o=t.length-1;if(1==o)return i[0]=new vi((2*t[0].x+t[1].x)/3,(2*t[0].y+t[1].y)/3),r[0]=new vi(2*i[0].x-t[0].x,2*i[0].y-t[0].y),[i,r];var s=[];for(n=1;n<o-1;n++)s[n]=4*t[n].x+2*t[n+1].x;s[0]=t[0].x+2*t[1].x,s[o-1]=(8*t[o-1].x+t[o].x)/2;var a=e(s);for(n=1;n<o-1;++n)s[n]=4*t[n].y+2*t[n+1].y;s[0]=t[0].y+2*t[1].y,s[o-1]=(8*t[o-1].y+t[o].y)/2;var l=e(s);for(n=0;n<o;n++)i.push(new vi(a[n],l[n])),n<o-1?r.push(new vi(2*t[n+1].x-a[n+1],2*t[n+1].y-l[n+1])):r.push(new vi((t[o].x+a[o-1])/2,(t[o].y+l[o-1])/2));return[i,r]}function e(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(e){if(!e||Array.isArray(e)&&e.length<2)throw new Error("At least 2 points are required");for(var n=t(e),i=[],r=n[0].length,o=0;o<r;o++){var s=new vi(n[0][o].x,n[0][o].y),a=new vi(n[1][o].x,n[1][o].y);i.push(new qi(e[o],s,a,e[o+1]))}return i}}(),qi.prototype={type:si.Curve,bbox:function(){for(var t,e,n,i,r,o,s,a,l=this.start,u=this.controlPoint1,c=this.controlPoint2,h=this.end,d=l.x,f=l.y,p=u.x,g=u.y,m=c.x,v=c.y,y=h.x,b=h.y,w=new Array,x=new Array,_=[new Array,new Array],E=0;E<2;++E)if(0===E?(e=6*d-12*p+6*m,t=-3*d+9*p-9*m+3*y,n=3*p-3*d):(e=6*f-12*g+6*v,t=-3*f+9*g-9*v+3*b,n=3*g-3*f),zi(t)<1e-12){if(zi(e)<1e-12)continue;0<(i=-n/e)&&i<1&&x.push(i)}else a=Gi(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 A,T,P,S=x.length,C=S;S--;)T=(A=1-(i=x[S]))*A*A*d+3*A*A*i*p+3*A*i*i*m+i*i*i*y,_[0][S]=T,P=A*A*A*f+3*A*A*i*g+3*A*i*i*v+i*i*i*b,_[1][S]=P,w[S]={X:T,Y:P};x[C]=0,x[C+1]=1,w[C]={X:d,Y:f},w[C+1]={X:y,Y:b},_[0][C]=d,_[1][C]=f,_[0][C+1]=y,_[1][C+1]=b,x.length=C+2,_[0].length=C+2,_[1].length=C+2,w.length=C+2;var L=Ui.apply(null,_[0]),k=Ui.apply(null,_[1]),N=$i.apply(null,_[0]),M=$i.apply(null,_[1]);return new Vi(L,k,N-L,M-k)},clone:function(){return new qi(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,l,u=void 0===(e=e||{}).precision?this.PRECISION:e.precision,c=void 0===e.subdivisions?this.getSubdivisions({precision:u}):e.subdivisions,h=c.length,d=h?1/h:0,f=0;f<h;f++){var p=c[f],g=p.start.distance(t),m=p.end.distance(t),v=g+m;(!l||v<l)&&(n=p,i=f*d,r=(f+1)*d,o=g,s=m,a=p.start.distance(p.end),l=v)}for(var y=Hi(10,-u);;){var b=o?zi(o-s)/o:0,w=s?zi(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 _=x[0].start.distance(t),E=x[0].end.distance(t),A=_+E,T=x[1].start.distance(t),P=x[1].end.distance(t);A<=T+P?(n=x[0],r-=d,o=_,s=E):(n=x[1],i+=d,o=T,s=P)}},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(t>=1)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 qi(e,e,e,e),new qi(e,n,i,r)];if(t>=1)return[new qi(e,n,i,r),new qi(r,r,r,r)];var o=this.getSkeletonPoints(t),s=o.startControlPoint1,a=o.startControlPoint2,l=o.divider,u=o.dividerControlPoint1,c=o.dividerControlPoint2;return[new qi(e,s,a,l),new qi(l,u,c,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(t>=1)return{startControlPoint1:n.clone(),startControlPoint2:i.clone(),divider:r.clone(),dividerControlPoint1:r.clone(),dividerControlPoint2:r.clone()};var o=new xi(e,n).pointAt(t),s=new xi(n,i).pointAt(t),a=new xi(i,r).pointAt(t),l=new xi(o,s).pointAt(t),u=new xi(s,a).pointAt(t);return{startControlPoint1:o,startControlPoint2:l,divider:new xi(l,u).pointAt(t),dividerControlPoint1:u,dividerControlPoint2:a}},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,s=[new qi(n,i,r,o)];if(0===e)return s;if(!this.isDifferentiable())return s;var a=this.endpointDistance(),l=Hi(10,-e),u=2;0===i.cross(n,o)&&0===r.cross(n,o)&&(u=2*e);for(var c=0;;){c+=1;for(var h=[],d=s.length,f=0;f<d;f++){var p=s[f].divide(.5);h.push(p[0],p[1])}for(var g=0,m=h.length,v=0;v<m;v++)g+=h[v].endpointDistance();if(c>=u&&(0!==g?(g-a)/g:0)<l)return h;s=h,a=g}},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(t>=1)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():t>=1?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:t>1&&(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:t>1&&(t=1);var e=this.getSkeletonPoints(t),n=e.startControlPoint2,i=e.dividerControlPoint1,r=e.divider,o=new xi(n,i);return o.translate(r.x-n.x,r.y-n.y),o},tAt:function(t,e){if(t<=0)return 0;if(t>=1)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,l=void 0===(e=e||{}).precision?this.PRECISION:e.precision,u=void 0===e.subdivisions?this.getSubdivisions({precision:l}):e.subdivisions,c={precision:l,subdivisions:u},h=0,d=u.length,f=1/d,p=0;p<d;p++){var g=n?p:d-1-p,m=u[p],v=m.endpointDistance();if(t<=h+v){i=m,r=g*f,o=(g+1)*f,s=n?t-h:v+h-t,a=n?v+h-t:t-h;break}h+=v}if(!i)return n?1:0;for(var y=this.length(c),b=Hi(10,-l);;){var w,x;if((0!==y?s/y:0)<b)return r;if((0!==y?a/y:0)<b)return o;var _=i.divide(.5);f/=2;var E=_[0].endpointDistance(),A=_[1].endpointDistance();s<=E?(i=_[0],o-=f,x=E-(w=s)):(i=_[1],r+=f,x=A-(w=s-E)),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 ji(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}},qi.prototype.divide=qi.prototype.divideAtT;const Yi=function(t){if(!(this instanceof Yi))return new Yi(t);if("string"==typeof t)return new Yi.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 xi||o instanceof qi))throw new Error("Cannot construct a path segment from the provided object.");0===e&&this.appendSegment(Yi.createSegment("M",o.start)),r&&!r.end.equals(o.start)&&this.appendSegment(Yi.createSegment("M",o.start)),o instanceof xi?this.appendSegment(Yi.createSegment("L",o.end)):o instanceof qi&&this.appendSegment(Yi.createSegment("C",o.controlPoint1,o.controlPoint2,o.end)),r=o}}else if(t.isSegment)this.appendSegment(t);else if(t instanceof xi)this.appendSegment(Yi.createSegment("M",t.start)),this.appendSegment(Yi.createSegment("L",t.end));else if(t instanceof qi)this.appendSegment(Yi.createSegment("M",t.start)),this.appendSegment(Yi.createSegment("C",t.controlPoint1,t.controlPoint2,t.end));else{if(!(t instanceof ji))throw new Error("Cannot construct a path from the provid